Skip to content

Commit

Permalink
fix(electron): update to v4 and fix scripts + also add migration (#86)
Browse files Browse the repository at this point in the history
closes #57
closes #84
  • Loading branch information
NathanWalker authored Feb 24, 2019
1 parent e8f870b commit 885af21
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nstudio/schematics",
"version": "7.3.0",
"version": "7.3.1",
"description": "Cross-platform (xplat) tools for Nx workspaces.",
"readmeFilename": "README.md",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions src/app.electron/_files/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"experimentalDecorators": true,
"esModuleInterop": true,
"target": "es5",
"types": [
"jasmine"
],
"typeRoots": [
"../../node_modules/@types"
],
Expand Down
5 changes: 5 additions & 0 deletions src/migrations/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
"version": "7.1.0",
"description": "Update NativeScript 5.1.0 and support for Angular 7.1.0",
"factory": "./update-7-1-0/update-7-1-0"
},
"update-to-7.3.1": {
"version": "7.3.1",
"description": "Update Electron to v4 and fix scripts",
"factory": "./update-7-3-1/update-7-3-1"
}
}
}
79 changes: 79 additions & 0 deletions src/migrations/update-7-3-1/update-7-3-1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
chain,
Rule,
SchematicContext,
Tree
} from "@angular-devkit/schematics";
import { join } from 'path';
import * as fs from 'fs';

import { getJsonFromFile, updateJsonFile, createOrUpdate, updateJsonInTree } from '../../utils';

function updateElectronApps(tree: Tree, context: SchematicContext) {
const appsDir = tree.getDir('apps');
const appFolders = appsDir.subdirs;
const cwd = process.cwd();
const tsConfigPath = join(cwd, 'node_modules/@nstudio/schematics/src/app.electron/_files/tsconfig.json');
// console.log('tsConfigPath:', tsConfigPath);
const tsConfig = fs.readFileSync(tsConfigPath, 'UTF-8');
// console.log('tsConfig:',tsConfig);

// update electron apps
for (const dir of appFolders) {
// console.log(dir);
if (dir.indexOf('electron-') === 0 || dir.indexOf('-electron') > -1) {
const appDir = `${appsDir.path}/${dir}`;
// console.log('appDir:', appDir);

createOrUpdate(
tree,
`${appDir}/tsconfig.json`,
tsConfig
);
}
}
return tree;
}

function updateRootPackage(tree: Tree, context: SchematicContext) {
return updateJsonInTree("package.json", json => {
json.scripts = json.scripts || {};
json.dependencies = json.dependencies || {};
const angularVersion = json.dependencies['@angular/core'];
// electron dep check looks for @angular/http so adding to make sure not a problem
json.dependencies = {
...json.dependencies,
"@angular/http": angularVersion
}
json.devDependencies = json.devDependencies || {};
json.devDependencies = {
...json.devDependencies,
"electron": "^4.0.5",
"electron-builder": "^20.38.4",
"electron-rebuild": "~1.8.4",
"electron-installer-dmg": "~2.0.0",
"electron-packager": "~13.1.0",
"electron-reload": "~1.4.0",
"electron-store": "~2.0.0",
"electron-updater": "~4.0.6",
"wait-on": "~3.2.0"
}

const appsDir = tree.getDir('apps');
const appFolders = appsDir.subdirs;

for (const dir of appFolders) {
if (dir.indexOf('electron-') === 0 || dir.indexOf('-electron') > -1) {
json.scripts[
`postinstall`
] = `electron-rebuild install-app-deps`;
}
}

return json;
})(tree, context);
}

export default function(): Rule {
return chain([updateElectronApps, updateRootPackage]);
}
23 changes: 15 additions & 8 deletions src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,49 +369,56 @@ export function addRootDeps(
if (targetPlatforms.electron) {
dep = {
name: "electron",
version: "2.0.8",
version: "^4.0.5",
type: "devDependency"
};
deps.push(dep);

dep = {
name: "electron-builder",
version: "20.28.4",
version: "^20.38.4",
type: "devDependency"
};
deps.push(dep);

dep = {
name: "electron-rebuild",
version: "~1.8.4",
type: "devDependency"
};
deps.push(dep);

dep = {
name: "electron-installer-dmg",
version: "1.0.0",
version: "~2.0.0",
type: "devDependency"
};
deps.push(dep);

dep = {
name: "electron-packager",
version: "12.1.0",
version: "~13.1.0",
type: "devDependency"
};
deps.push(dep);

dep = {
name: "electron-reload",
version: "1.2.5",
version: "~1.4.0",
type: "devDependency"
};
deps.push(dep);

dep = {
name: "electron-store",
version: "2.0.0",
version: "~2.0.0",
type: "devDependency"
};
deps.push(dep);

dep = {
name: "electron-updater",
version: "3.1.2",
version: "~4.0.6",
type: "devDependency"
};
deps.push(dep);
Expand All @@ -432,7 +439,7 @@ export function addRootDeps(

dep = {
name: "wait-on",
version: "2.1.0",
version: "~3.2.0",
type: "devDependency"
};
deps.push(dep);
Expand Down

0 comments on commit 885af21

Please sign in to comment.