From 885af217b5b38d70a86e8b22c89840646d598991 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sun, 24 Feb 2019 12:31:24 -0800 Subject: [PATCH] fix(electron): update to v4 and fix scripts + also add migration (#86) closes https://github.com/nstudio/xplat/issues/57 closes https://github.com/nstudio/xplat/issues/84 --- package.json | 2 +- src/app.electron/_files/tsconfig.json | 3 + src/migrations/migrations.json | 5 ++ src/migrations/update-7-3-1/update-7-3-1.ts | 79 +++++++++++++++++++++ src/utils/general.ts | 23 +++--- 5 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 src/migrations/update-7-3-1/update-7-3-1.ts diff --git a/package.json b/package.json index 76e7a23e..ac84cd84 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/app.electron/_files/tsconfig.json b/src/app.electron/_files/tsconfig.json index 4c2b9028..e0acab1b 100644 --- a/src/app.electron/_files/tsconfig.json +++ b/src/app.electron/_files/tsconfig.json @@ -7,6 +7,9 @@ "experimentalDecorators": true, "esModuleInterop": true, "target": "es5", + "types": [ + "jasmine" + ], "typeRoots": [ "../../node_modules/@types" ], diff --git a/src/migrations/migrations.json b/src/migrations/migrations.json index 911ba508..a073ebb4 100644 --- a/src/migrations/migrations.json +++ b/src/migrations/migrations.json @@ -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" } } } \ No newline at end of file diff --git a/src/migrations/update-7-3-1/update-7-3-1.ts b/src/migrations/update-7-3-1/update-7-3-1.ts new file mode 100644 index 00000000..e01d185d --- /dev/null +++ b/src/migrations/update-7-3-1/update-7-3-1.ts @@ -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]); +} diff --git a/src/utils/general.ts b/src/utils/general.ts index 9b9621ce..1be84065 100644 --- a/src/utils/general.ts +++ b/src/utils/general.ts @@ -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); @@ -432,7 +439,7 @@ export function addRootDeps( dep = { name: "wait-on", - version: "2.1.0", + version: "~3.2.0", type: "devDependency" }; deps.push(dep);