-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(electron): update to v4 and fix scripts + also add migration (#86)
- Loading branch information
1 parent
e8f870b
commit 885af21
Showing
5 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters