Skip to content

Commit

Permalink
feat(electron): update to v11.1.0 and bump other dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker committed Jan 3, 2021
1 parent 058757a commit a0d71dc
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 212 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"types": ["node", "jest"]
},
"include": ["src/index.ts"]
Expand Down
14 changes: 3 additions & 11 deletions packages/electron-angular/src/schematics/application/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,13 @@ describe('app', () => {
// console.log(checkFile);
expect(checkFile.indexOf(`"name": "foo"`)).toBeGreaterThanOrEqual(0);

expect(
files.indexOf('/tools/electron/postinstall.js')
).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/tools/web/postinstall.js')).toBeGreaterThanOrEqual(
0
);

checkPath = '/package.json';
expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0);

checkFile = getFileContent(tree, checkPath);
// console.log(checkFile);
const packageData: any = jsonParse(checkFile);
expect(packageData.scripts['postinstall']).toBeDefined();
expect(packageData.scripts['postinstall.electron']).toBeDefined();
expect(packageData.scripts['postinstall.web']).toBeDefined();
expect(packageData.scripts['build.electron.foo']).toBeDefined();
expect(packageData.scripts['build.electron.foo.local']).toBeDefined();
expect(packageData.scripts['build.electron.foo.linux']).toBeDefined();
Expand Down Expand Up @@ -94,6 +85,9 @@ describe('app', () => {
checkFile.indexOf(`./app/app.electron.module`)
).toBeGreaterThanOrEqual(0);

checkPath = '/apps/web-viewer/tsconfig.electron.json';
expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0);

// make sure start script is correct
checkPath = '/package.json';
checkFile = getFileContent(tree, checkPath);
Expand Down Expand Up @@ -176,8 +170,6 @@ describe('app', () => {
const tree = await runSchematic('app', options, appTree);
// const files = tree.files;
// console.log(files);
expect(tree.exists('/tools/electron/postinstall.js')).toBeTruthy();
expect(tree.exists('/tools/web/postinstall.js')).toBeTruthy();

// should *not* create this
expect(tree.exists('/apps/web-viewer/src/main.electron.ts')).toBeFalsy();
Expand Down
45 changes: 22 additions & 23 deletions packages/electron-angular/src/schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,6 @@ export default function (options: XplatElectrontHelpers.SchemaApp) {
);
}

const packageHandling = [];
if (options.isTesting) {
packageHandling.push(
externalSchematic('@nstudio/electron', 'tools', {
...options,
})
);
} else {
// TODO: find a way to unit test schematictask runners with install tasks
packageHandling.push((tree: Tree, context: SchematicContext) => {
const installPackageTask = context.addTask(new NodePackageInstallTask());

// console.log('packagesToRunXplat:', packagesToRunXplat);
context.addTask(
new RunSchematicTask('@nstudio/electron', 'tools', options),
[installPackageTask]
);
});
}

return chain([
prerun(options),
XplatHelpers.applyAppNamingConvention(options, 'electron'),
Expand All @@ -95,7 +75,6 @@ export default function (options: XplatElectrontHelpers.SchemaApp) {
(tree: Tree, context: SchematicContext) =>
addAppFiles(options, options.name)(tree, context),
XplatElectronAngularHelpers.updateRootDeps(options),
...packageHandling,
XplatElectrontHelpers.addNpmScripts(options),
(tree: Tree, context: SchematicContext) => {
// grab the target app configuration
Expand Down Expand Up @@ -124,6 +103,9 @@ export default function (options: XplatElectrontHelpers.SchemaApp) {
projects[
electronAppName
].architect.build.options.main = `apps/${fullTargetAppName}/src/main.electron.ts`;
projects[
electronAppName
].architect.build.options.tsConfig = `apps/${fullTargetAppName}/tsconfig.electron.json`;
}
projects[electronAppName].architect.build.options.assets.push({
glob: '**/*',
Expand Down Expand Up @@ -191,17 +173,21 @@ function adjustAppFiles(options: XplatElectrontHelpers.SchemaApp, tree: Tree) {
if (!tree.exists(electronMainPath)) {
tree.create(electronMainPath, electronMain());
}
const electronTsConfigPath = `/apps/${fullTargetAppName}/tsconfig.electron.json`;
if (!tree.exists(electronTsConfigPath)) {
tree.create(electronTsConfigPath, electronTsConfig());
}
return tree;
}

function electronModule() {
return `import { NgModule } from '@angular/core';
import { ${stringUtils.classify(
getPrefix()
)}ElectronCoreModule } from '@${getNpmScope()}/${XplatHelpers.getXplatFoldername(
)}ElectronCoreModule } from '@${getNpmScope()}/xplat/${XplatHelpers.getXplatFoldername(
'electron',
'angular'
)}';
)}/core';
import { AppModule } from './app.module';
import { AppComponent } from './app.component';
Expand Down Expand Up @@ -231,3 +217,16 @@ function electronMain() {
.catch(err => console.log(err));
`;
}

function electronTsConfig() {
return `{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": []
},
"files": ["src/main.electron.ts", "src/polyfills.ts"],
"include": ["src/**/*.d.ts"],
"exclude": ["src/test-setup.ts", "**/*.spec.ts"]
}`;
}
6 changes: 0 additions & 6 deletions packages/electron/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
"schema": "./src/schematics/xplat/schema.json",
"description": "Add xplat for Electron.",
"hidden": true
},
"tools": {
"factory": "./src/schematics/tools",
"schema": "./src/schematics/tools/schema.json",
"description": "Tools for @angular-devkit.",
"hidden": true
}
}
}
9 changes: 0 additions & 9 deletions packages/electron/src/schematics/application/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,13 @@ describe('app', () => {
// console.log(checkFile);
expect(checkFile.indexOf(`"name": "foo"`)).toBeGreaterThanOrEqual(0);

// expect(
// files.indexOf('/tools/electron/postinstall.js')
// ).toBeGreaterThanOrEqual(0);
// expect(files.indexOf('/tools/web/postinstall.js')).toBeGreaterThanOrEqual(
// 0
// );

checkPath = '/package.json';
expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0);

checkFile = getFileContent(tree, checkPath);
// console.log(checkFile);
const packageData: any = jsonParse(checkFile);
expect(packageData.scripts['postinstall']).toBeDefined();
expect(packageData.scripts['postinstall.electron']).toBeDefined();
expect(packageData.scripts['postinstall.web']).toBeDefined();
expect(packageData.scripts['build.electron.foo']).toBeDefined();
expect(packageData.scripts['build.electron.foo.local']).toBeDefined();
expect(packageData.scripts['build.electron.foo.linux']).toBeDefined();
Expand Down
21 changes: 0 additions & 21 deletions packages/electron/src/schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,12 @@ export default function (options: XplatElectrontHelpers.SchemaApp) {
);
}

const packageHandling = [];
if (options.isTesting) {
packageHandling.push(
externalSchematic('@nstudio/electron', 'tools', {
...options,
})
);
} else {
// TODO: find a way to unit test schematictask runners with install tasks
packageHandling.push((tree: Tree, context: SchematicContext) => {
const installPackageTask = context.addTask(new NodePackageInstallTask());

// console.log('packagesToRunXplat:', packagesToRunXplat);
context.addTask(
new RunSchematicTask('@nstudio/electron', 'tools', options),
[installPackageTask]
);
});
}

return chain([
prerun(options),
XplatHelpers.applyAppNamingConvention(options, 'electron'),
(tree: Tree, context: SchematicContext) =>
addAppFiles(options, options.name)(tree, context),
XplatElectrontHelpers.updateRootDeps(options),
...packageHandling,
XplatElectrontHelpers.addNpmScripts(options),
(tree: Tree, context: SchematicContext) => {
// grab the target app configuration
Expand Down

This file was deleted.

18 changes: 0 additions & 18 deletions packages/electron/src/schematics/tools/_files/web/postinstall.js

This file was deleted.

26 changes: 0 additions & 26 deletions packages/electron/src/schematics/tools/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/electron/src/schematics/tools/schema.json

This file was deleted.

14 changes: 7 additions & 7 deletions packages/electron/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const xplatVersion = '*';
export const electronVersion = '^7.0.1';
export const electronBuilderVersion = '^20.44.4';
export const electronRebuildVersion = '~1.8.6';
export const electronVersion = '^11.1.0';
export const electronBuilderVersion = '^22.9.1';
export const electronRebuildVersion = '~2.3.4';
export const electronInstallerDmgVersion = '~3.0.0';
export const electronPackagerVersion = '~14.1.0';
export const electronPackagerVersion = '~15.2.0';
export const electronReloadVersion = '~1.5.0';
export const electronStoreVersion = '~5.1.0';
export const electronUpdaterVersion = '~4.2.0';
export const electronStoreVersion = '~6.0.1';
export const electronUpdaterVersion = '~4.3.5';
export const npmRunAllVersion = '^4.1.5';
export const waitOnVersion = '~3.3.0';
export const waitOnVersion = '~5.2.1';
56 changes: 1 addition & 55 deletions packages/electron/src/utils/xplat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ export namespace XplatElectrontHelpers {
} else {
scripts['postinstall'] = postinstall;
}
scripts['postinstall.electron'] = 'node tools/electron/postinstall';
scripts['postinstall.web'] = 'node tools/web/postinstall';
scripts[
`build.${platformApp}`
] = `npm run prepare.${platformApp} && ng build ${options.name} --prod --base-href ./`;
Expand All @@ -112,7 +110,7 @@ export namespace XplatElectrontHelpers {
] = `npm run build.${platformApp} && cd dist/apps/${options.name} && npx electron-builder build --mac`;
scripts[
`prepare.${platformApp}`
] = `npm run postinstall.electron && tsc -p apps/${options.name}/tsconfig.json`;
] = `tsc -p apps/${options.name}/tsconfig.json`;
scripts[`serve.${platformApp}.target`] = `nx serve ${options.name}`;
scripts[
`serve.${platformApp}`
Expand All @@ -121,58 +119,6 @@ export namespace XplatElectrontHelpers {
`start.${platformApp}`
] = `npm run prepare.${platformApp} && npm-run-all -p serve.${platformApp}.target serve.${platformApp}`;

// adjust web related scripts to account for postinstall hooks
const startWeb = scripts[`start.${targetAppScript}`];
const postinstallWeb = 'npm run postinstall.web';

if (startWeb) {
// prefix it
scripts[
`start.${targetAppScript}`
] = `${postinstallWeb} && ${startWeb}`;
} else {
// create to be consistent
scripts[
`start.${targetAppScript}`
] = `${postinstallWeb} && nx serve ${fullTargetAppName}`;
}
let startDefault = scripts[`start`];
if (startDefault) {
// prefix it
if (startDefault.indexOf(fullTargetAppName) === -1) {
// set target app as default
startDefault = `${startDefault} ${fullTargetAppName}`;
}
scripts[`start`] = `${postinstallWeb} && ${startDefault}`;
} else {
scripts[`start`] = `${postinstallWeb} && nx serve ${fullTargetAppName}`;
}
let buildDefault = scripts[`build`];
if (buildDefault) {
// prefix it
if (buildDefault.indexOf(fullTargetAppName) === -1) {
// set target app as default
buildDefault = `${buildDefault} ${fullTargetAppName}`;
}
scripts[`build`] = `${postinstallWeb} && ${buildDefault}`;
} else {
scripts[`build`] = `${postinstallWeb} && nx build ${fullTargetAppName}`;
}
let testDefault = scripts[`test`];
if (testDefault) {
// prefix it
scripts[`test`] = `${postinstallWeb} && ${testDefault}`;
} else {
scripts[`test`] = `${postinstallWeb} && nx test`;
}
let e2eDefault = scripts[`e2e`];
if (e2eDefault) {
// prefix it
scripts[`e2e`] = `${postinstallWeb} && ${e2eDefault}`;
} else {
scripts[`e2e`] = `${postinstallWeb} && nx e2e`;
}

return updatePackageScripts(tree, scripts);
};
}
Expand Down

0 comments on commit a0d71dc

Please sign in to comment.