fix: using chokidar instead of npm-watch (issue #4)

This commit is contained in:
Amadou Ada DIENE
2021-07-31 14:49:31 +02:00
parent 5c11822d09
commit 2feedcefc5
17 changed files with 457 additions and 1199 deletions

1513
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -23,21 +23,12 @@
"workspaces/angular-app",
"workspaces/shared-lib"
],
"watch": {
"restart-electron-app": {
"patterns": [
"workspaces/electron-app",
"workspaces/shared-lib"
],
"extensions": "ts,tsx"
}
},
"scripts": {
"start": "npm-run-all -p start:shared-lib start:angular-app start:electron-app",
"start:shared-lib": "tsc -b workspaces/shared-lib -w",
"start:angular-app": "cd workspaces/angular-app && npm run start",
"start:electron-app": "wait-on http://localhost:4200 && npm-watch restart-electron-app",
"restart-electron-app": "electron-forge start",
"start:angular-app": "wait-on workspaces/shared-lib/.dist/index.d.ts && cd workspaces/angular-app && npm run start",
"start:electron-app": "node scripts/electron-forge-start-watch.js",
"start:electron-app:once": "wait-on http://localhost:4200 && electron-forge start",
"package": "npm run package:angular-app && npm run package:electron-app",
"package:angular-app": "cd workspaces/angular-app && npm run package",
"package:electron-app": "electron-forge package",
@@ -49,10 +40,8 @@
"start:angular-e2e": "wait-on http://localhost:4200 && cd workspaces/angular-app && npm run cypress:run",
"test:electron-e2e": "npm run package && cross-env X_NODE_ENV=e2e-test node workspaces/electron-e2e/jasmine.js",
"clean": "shx rm -rf .webpack out node_modules workspaces/shared-lib/.dist workspaces/angular-app/node_modules workspaces/angular-app/.dist",
"version": "npx conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
"prepare": "husky install",
"postinstall": "husky install && shx rm -rf .git/hooks && shx ln -s ../.husky .git/hooks",
"release": "standard-version",
"release:minor": "standard-version --release-as minor",
"release:patch": "standard-version --release-as patch",
"release:major": "standard-version --release-as major"
@@ -116,7 +105,7 @@
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"@vercel/webpack-asset-relocator-loader": "^1.6.0",
"conventional-changelog-cli": "^2.1.1",
"chokidar-cli": "^3.0.0",
"copy-webpack-plugin": "^9.0.1",
"cross-env": "^7.0.3",
"css-loader": "^5.0.0",
@@ -133,12 +122,12 @@
"lint-staged": "^11.0.1",
"node-loader": "^2.0.0",
"npm-run-all": "^4.1.5",
"npm-watch": "^0.10.0",
"prettier": "^2.3.2",
"shx": "^0.3.3",
"spectron": "^15.0.0",
"standard-version": "^9.3.1",
"style-loader": "^2.0.0",
"tree-kill": "^1.2.2",
"ts-loader": "^9.2.2",
"ts-node": "^10.1.0",
"typescript": "^4.3.5",

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env node
const spawn = require('child_process').spawn;
const chokidar = require('chokidar');
const kill = require('tree-kill');
const path = require('path');
class ElectronForgeRunner {
constructor() {
this.__init__();
}
__init__ = () => {
this.args = process.argv;
this.command = this.args[2];
this.cwd = process.cwd();
this.watchPaths = [
path.join(this.cwd, '/workspaces/electron-app/**/*.ts'),
path.join(this.cwd, '/workspaces/shared-lib/.dist/**/*.ts'),
];
this.ignoredPaths = '**/node_modules/*';
this.startWatching();
this.reload();
};
reload = () => {
if (this.childProcess) kill(this.childProcess.pid);
this.childProcess = spawn('npm run start:electron-app:once', [], {
shell: true,
stdio: 'inherit',
});
};
startWatching = () => {
chokidar
.watch(this.watchPaths, {
ignored: this.ignoredPaths,
ignoreInitial: true,
})
.on('all', (event, path) => {
this.reload();
});
};
}
new ElectronForgeRunner();

View File

@@ -31,5 +31,4 @@ if (process.env.X_NODE_ENV === 'e2e-test') {
contextBridge.exposeInMainWorld('api', windowApi);
}
console.log(typeof window);
console.log('The preload script has been injected successfully.');

View File

@@ -1,10 +0,0 @@
export declare class WindowApiConst {
/** Channel used by the renderer process to send data to the main process */
static readonly MULTIPLES_INPUT = 'getMultiplesInput';
/** Channel used by the renderer process to receive data from the main process */
static readonly MULTIPLES_OUTPUT = 'getMultiplesOutput';
/** Whitelist of the safe channels to use when sending data to the main process */
static readonly SENDING_SAFE_CHANNELS: string[];
/** Whitelist of the safe channels to use when receiving data from the main process */
static readonly RECEIVING_SAFE_CHANNELS: string[];
}

View File

@@ -1,10 +0,0 @@
export class WindowApiConst {}
/** Channel used by the renderer process to send data to the main process */
WindowApiConst.MULTIPLES_INPUT = 'getMultiplesInput';
/** Channel used by the renderer process to receive data from the main process */
WindowApiConst.MULTIPLES_OUTPUT = 'getMultiplesOutput';
/** Whitelist of the safe channels to use when sending data to the main process */
WindowApiConst.SENDING_SAFE_CHANNELS = [WindowApiConst.MULTIPLES_INPUT];
/** Whitelist of the safe channels to use when receiving data from the main process */
WindowApiConst.RECEIVING_SAFE_CHANNELS = [WindowApiConst.MULTIPLES_OUTPUT];
//# sourceMappingURL=window-api-consts.js.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"window-api-consts.js","sourceRoot":"","sources":["../../apis/window-api-consts.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAc;;AACzB,4EAA4E;AACrD,8BAAe,GAAG,mBAAmB,CAAC;AAE7D,iFAAiF;AAC1D,+BAAgB,GAAG,oBAAoB,CAAC;AAE/D,kFAAkF;AAC3D,oCAAqB,GAAG;IAC7C,cAAc,CAAC,eAAe;CAC/B,CAAC;AAEF,sFAAsF;AAC/D,sCAAuB,GAAG;IAC/C,cAAc,CAAC,gBAAgB;CAChC,CAAC"}

View File

@@ -1,14 +0,0 @@
export interface WindowApi {
/**
* This method is used by the renderer process to receive data from the main process
* @param channel used by the renderer to receive data and by the main to send them
* @param func the callback function to execute when data are available
*/
receive<Out>(channel: string, func: (output: Out) => void): void;
/**
* This method is used by the renderer process to send data to the main process
* @param channel used by the renderer to send data and by the main to receive them
* @param data the data sent by the renderer process to the main process
*/
send<In>(channel: string, input: In): void;
}

View File

@@ -1,2 +0,0 @@
export {};
//# sourceMappingURL=window-api.js.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"window-api.js","sourceRoot":"","sources":["../../apis/window-api.ts"],"names":[],"mappings":""}

View File

@@ -1,9 +0,0 @@
import { WindowApi } from './apis/window-api';
export * from './apis/window-api';
export * from './apis/window-api-consts';
export * from './models/config/app-config';
declare global {
interface Window {
api: WindowApi;
}
}

View File

@@ -1,4 +0,0 @@
export * from './apis/window-api';
export * from './apis/window-api-consts';
export * from './models/config/app-config';
//# sourceMappingURL=index.js.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC"}

View File

@@ -1,18 +0,0 @@
export interface AppConfig {
/** The configuration identifier */
configId: string;
/** The main logger output file path */
mainLogFile: string;
/** The main logger output level */
mainLogLevel: string;
/** Tells if we should try to load app icon */
isIconAvailable: boolean;
/** Tells if `nodeIntegration` webPreference is enabled */
isNodeIntegration: boolean;
/** Tells if `contextIsolation` and `worldSafeExecuteJavaScript` webPreferences are enabled */
isContextIsolation: boolean;
/** Tells if `isEnableRemoteModule` webPreference is enabled */
isEnableRemoteModule: boolean;
/** Tells if we should open dev tools */
isOpenDevTools: boolean;
}

View File

@@ -1,2 +0,0 @@
export {};
//# sourceMappingURL=app-config.js.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"app-config.js","sourceRoot":"","sources":["../../../models/config/app-config.ts"],"names":[],"mappings":""}

2
workspaces/shared-lib/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
# Generated JS files
/.dist