Skip to content

Commit

Permalink
feat: rename example app folder (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Sep 19, 2024
1 parent 5bd9576 commit b53438c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You can also try the following methods to use this package:

### Example Apps

As of the `0.8.0` release, example apps for testing are included when initializing a new plugin. To use these templates, you can open the `npx cap open android` or `npx cap open ios` command for Android and iOS respectively. Anything in the `example` folder will be excluded when publishing to npm.
As of the `0.8.0` release, example apps for testing are included when initializing a new plugin. To use these templates, you can open the `npx cap open android` or `npx cap open ios` command for Android and iOS respectively. Anything in the `example-app` folder will be excluded when publishing to npm.

### Options

Expand Down
2 changes: 1 addition & 1 deletion assets/plugin-template/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build
dist
example
example-app
2 changes: 1 addition & 1 deletion assets/plugin-template/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build
dist
example
example-app
4 changes: 2 additions & 2 deletions assets/www-template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<main>
<h1>Capacitor Test Plugin Project</h1>
<p>
This project can be used to test out the functionality of your plugin. Nothing in the <em>example/</em> folder
will be published to npm when using this template, so you can create away!
This project can be used to test out the functionality of your plugin. Nothing in the
<em>example-app/</em> folder will be published to npm when using this template, so you can create away!
</p>
<label for="echoInput">Echo Text:</label>
<input type="text" id="echoInput" name="echoInput" value="Hello World!" />
Expand Down
22 changes: 11 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,52 +69,52 @@ export const run = async (): Promise<void> => {
try {
await runSubprocess(
'npm',
['init', '@capacitor/app@latest', 'example', '--', '--name', 'example', '--app-id', 'com.example.plugin'],
['init', '@capacitor/app@latest', 'example-app', '--', '--name', 'example-app', '--app-id', 'com.example.plugin'],
opts,
);

// Add newly created plugin to example app
const appPackageJsonStr = readFileSync(resolve(details.dir, 'example', 'package.json'), 'utf8');
const appPackageJsonStr = readFileSync(resolve(details.dir, 'example-app', 'package.json'), 'utf8');
const appPackageJsonObj = JSON.parse(appPackageJsonStr);
appPackageJsonObj.dependencies[details.name] = 'file:..';
appPackageJsonObj.dependencies['@capacitor/ios'] = CAPACITOR_VERSION;
appPackageJsonObj.dependencies['@capacitor/android'] = CAPACITOR_VERSION;

writeFileSync(resolve(details.dir, 'example', 'package.json'), JSON.stringify(appPackageJsonObj, null, 2));
writeFileSync(resolve(details.dir, 'example-app', 'package.json'), JSON.stringify(appPackageJsonObj, null, 2));

// Install packages and add ios and android apps
await runSubprocess('npm', ['install', '--no-package-lock', '--prefix', 'example'], opts);
await runSubprocess('npm', ['install', '--no-package-lock', '--prefix', 'example-app'], opts);

// Build newly created plugin and move into the example folder
// Build newly created plugin and move into the example-app folder
await runSubprocess('npm', ['run', 'build'], opts);

// remove existing web example
const wwwDir = resolve(dir, 'example', 'src');
// remove existing web example-app
const wwwDir = resolve(dir, 'example-app', 'src');
rmSync(resolve(wwwDir), { recursive: true, force: true });

// Use www template
await extractTemplate(wwwDir, details, 'WWW_TEMPLATE');

await runSubprocess('npm', ['run', 'build'], {
cwd: resolve(opts.cwd, 'example'),
cwd: resolve(opts.cwd, 'example-app'),
stdio: opts.stdio,
});

await runSubprocess('npx', ['cap', 'copy'], {
cwd: resolve(opts.cwd, 'example'),
cwd: resolve(opts.cwd, 'example-app'),
stdio: opts.stdio,
});

// Add iOS
await runSubprocess('npx', ['cap', 'add', 'ios'], {
...opts,
cwd: resolve(details.dir, 'example'),
cwd: resolve(details.dir, 'example-app'),
});

// Add Android
await runSubprocess('npx', ['cap', 'add', 'android'], {
...opts,
cwd: resolve(details.dir, 'example'),
cwd: resolve(details.dir, 'example-app'),
});
} catch (e: any) {
process.stderr.write(`WARN: Could not create test application: ${e.message ?? e.stack ?? e}\n`);
Expand Down

0 comments on commit b53438c

Please sign in to comment.