Skip to content

Commit

Permalink
Fix(electron): make npx cap open electron run electron app (#1666)
Browse files Browse the repository at this point in the history
* Fix(electron): make npx cap open electron run electron app

* document change
  • Loading branch information
jcesarmobile authored Jun 14, 2019
1 parent cf09bb4 commit 5252f8f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
27 changes: 27 additions & 0 deletions cli/src/electron/open.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { exec } from 'child_process';
import { Config } from '../config';
import { logInfo } from '../common';
import { existsAsync } from '../util/fs';
import { resolve } from 'path';

export async function openElectron(config: Config) {

const dir = config.electron.platformDir;

logInfo(`Opening Electron project at ${dir}`);

if (!await existsAsync(resolve(config.app.rootDir, dir))) {
throw new Error('Electron project does not exist. Create one with "npx cap add electron"');
}

return new Promise(async (resolve, reject) => {
exec(`npm run electron:start`, {cwd: dir}, (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});

}
3 changes: 3 additions & 0 deletions cli/src/tasks/open.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Config } from '../config';
import { logFatal, logInfo, runTask } from '../common';
import { openAndroid } from '../android/open';
import { openElectron } from '../electron/open';
import { openIOS } from '../ios/open';

export async function openCommand(config: Config, selectedPlatform: string) {
Expand Down Expand Up @@ -33,6 +34,8 @@ export async function open(config: Config, platformName: string) {
return openAndroid(config);
} else if (platformName === config.web.name) {
return Promise.resolve();
} else if (platformName === config.electron.name) {
return openElectron(config);
} else {
throw `Platform ${platformName} is not valid.`;
}
Expand Down
5 changes: 2 additions & 3 deletions site/docs-md/electron/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ Run this after making any modifications to your web app.

## Running your App

To run your app, cd into it and use the npm script provided by Capacitor:
To run your app, use

```bash
cd electron/
npm run electron:start
npx cap open electron
```

This will launch an Electron instance running your app.
Expand Down

0 comments on commit 5252f8f

Please sign in to comment.