-
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.
feat(nativescript): 6.3 and scoping updates (#177)
- Loading branch information
1 parent
f9b9cbf
commit dd54238
Showing
22 changed files
with
336 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
{ | ||
"schematics": {} | ||
"schematics": { | ||
"update-to-8.1.2": { | ||
"version": "8.1.2", | ||
"description": "Migrate Electron apps to 7", | ||
"factory": "./migrations/update-8-1-2/update-8-1-2" | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
packages/electron-angular/migrations/update-8-1-2/update-8-1-2.ts
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,83 @@ | ||
import { | ||
chain, | ||
Rule, | ||
SchematicContext, | ||
Tree | ||
} from '@angular-devkit/schematics'; | ||
import { join } from 'path'; | ||
import * as fs from 'fs'; | ||
import { updateJsonInTree, createOrUpdate } from '@nrwl/workspace'; | ||
import { getJsonFromFile, updateJsonFile, output } from '@nstudio/xplat'; | ||
import { electronBuilderVersion, electronInstallerDmgVersion, electronPackagerVersion, electronRebuildVersion, electronReloadVersion, electronStoreVersion, electronUpdaterVersion, electronVersion, npmRunAllVersion, waitOnVersion } from '@nstudio/electron'; | ||
|
||
function updateElectronApps(tree: Tree, context: SchematicContext) { | ||
const nxConfigPath = `nx.json`; | ||
const nxJson = getJsonFromFile(tree, nxConfigPath); | ||
const npmScope = nxJson.npmScope; | ||
|
||
const appsDir = tree.getDir('apps'); | ||
const appFolders = appsDir.subdirs; | ||
const cwd = process.cwd(); | ||
const indexPath = join( | ||
cwd, | ||
'node_modules/@nstudio/electron-angular/src/schematics/application/_files/src/index.ts__tmpl__' | ||
); | ||
// console.log('webpackConfigPath:', webpackConfigPath); | ||
const indexContent = fs.readFileSync(indexPath, 'UTF-8'); | ||
const servicePath = join( | ||
cwd, | ||
'node_modules/@nstudio/electron-angular/src/schematics/xplat/_files/core/services/electron.service.ts__tmpl__' | ||
); | ||
// console.log('webpackConfigPath:', webpackConfigPath); | ||
let electronService = fs.readFileSync(servicePath, 'UTF-8'); | ||
electronService = electronService.replace(/<%= npmScope %>/ig, npmScope); | ||
|
||
const appsNames = []; | ||
// update electron apps and configs | ||
for (const dir of appFolders) { | ||
// console.log(dir); | ||
if ( | ||
dir.indexOf('nativescript-') === 0 || | ||
dir.indexOf('-nativescript') === 0 | ||
) { | ||
const appDir = `${appsDir.path}/${dir}`; | ||
// console.log('appDir:', appDir); | ||
appsNames.push(dir); | ||
|
||
createOrUpdate(tree, `${appDir}/src/index.ts`, indexContent); | ||
createOrUpdate(tree, `xplat/electron/core/services/electron.service.ts`, electronService); | ||
} | ||
output.log({ | ||
title: 'Migration Note:', | ||
bodyLines: [ | ||
`The following Electron apps have been updated to 7: ${appsNames}.` | ||
] | ||
}); | ||
} | ||
return tree; | ||
} | ||
|
||
function updateRootPackage(tree: Tree, context: SchematicContext) { | ||
return updateJsonInTree('package.json', json => { | ||
json.devDependencies = json.devDependencies || {}; | ||
json.devDependencies = { | ||
...json.devDependencies, | ||
electron: electronVersion, | ||
'electron-builder': electronBuilderVersion, | ||
'electron-rebuild': electronRebuildVersion, | ||
'electron-installer-dmg': electronInstallerDmgVersion, | ||
'electron-packager': electronPackagerVersion, | ||
'electron-reload': electronReloadVersion, | ||
'electron-store': electronStoreVersion, | ||
'electron-updater': electronUpdaterVersion, | ||
'npm-run-all': npmRunAllVersion, | ||
'wait-on': waitOnVersion | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './versions'; | ||
export * from './xplat'; |
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
97 changes: 97 additions & 0 deletions
97
packages/nativescript-angular/migrations/update-8-1-2/update-8-1-2.ts
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,97 @@ | ||
import { | ||
chain, | ||
Rule, | ||
SchematicContext, | ||
Tree | ||
} from '@angular-devkit/schematics'; | ||
import { join } from 'path'; | ||
import * as fs from 'fs'; | ||
import { updateJsonInTree, createOrUpdate } from '@nrwl/workspace'; | ||
import { getJsonFromFile, updateJsonFile, output } from '@nstudio/xplat'; | ||
import { nsNgVersion, nsCoreVersion, terserWebpackVersion } from '../../src/utils/versions'; | ||
|
||
function updateNativeScriptApps(tree: Tree, context: SchematicContext) { | ||
const appsDir = tree.getDir('apps'); | ||
const appFolders = appsDir.subdirs; | ||
const cwd = process.cwd(); | ||
const webpackConfigPath = join( | ||
cwd, | ||
'node_modules/@nstudio/nativescript-angular/src/schematics/application/_files/webpack.config.js' | ||
); | ||
// console.log('webpackConfigPath:', webpackConfigPath); | ||
const webpackConfig = fs.readFileSync(webpackConfigPath, 'UTF-8'); | ||
const srcPackagePath = join( | ||
cwd, | ||
'node_modules/@nstudio/nativescript-angular/src/schematics/application/_files/src/package.json' | ||
); | ||
// console.log('webpackConfigPath:', webpackConfigPath); | ||
const srcPackage = fs.readFileSync(srcPackagePath, 'UTF-8'); | ||
|
||
const appsNames = []; | ||
// update {N} apps and configs | ||
for (const dir of appFolders) { | ||
// console.log(dir); | ||
if ( | ||
dir.indexOf('nativescript-') === 0 || | ||
dir.indexOf('-nativescript') === 0 | ||
) { | ||
const appDir = `${appsDir.path}/${dir}`; | ||
// console.log('appDir:', appDir); | ||
appsNames.push(dir); | ||
|
||
createOrUpdate(tree, `${appDir}/webpack.config.js`, webpackConfig); | ||
createOrUpdate(tree, `${appDir}/src/package.json`, srcPackage); | ||
|
||
// update {N} app deps | ||
const packagePath = `${appDir}/package.json`; | ||
const packageJson = getJsonFromFile(tree, packagePath); | ||
|
||
if (packageJson) { | ||
packageJson.dependencies = packageJson.dependencies || {}; | ||
packageJson.devDependencies = packageJson.devDependencies || {}; | ||
packageJson.devDependencies = { | ||
...packageJson.devDependencies, | ||
'@angular/compiler-cli': '~8.2.0', | ||
'@ngtools/webpack': '~8.3.0', | ||
'nativescript-dev-webpack': '~1.4.0' | ||
}; | ||
|
||
// console.log('path:',path); | ||
// console.log('packageJson overwrite:', JSON.stringify(packageJson)); | ||
tree = updateJsonFile(tree, packagePath, packageJson); | ||
} | ||
} | ||
output.log({ | ||
title: 'Migration Note:', | ||
bodyLines: [ | ||
`Please ensure you have the latest NativeScript cli installed: npm i -g nativescript`, | ||
`The following NativeScript apps have been updated to 6.3: ${appsNames}. The following files in those apps have been updated: webpack.config.js, src/package.json, and package.json. You may want to check the changeset to keep any customizations you may have made.` | ||
] | ||
}); | ||
} | ||
return tree; | ||
} | ||
|
||
function updateRootPackage(tree: Tree, context: SchematicContext) { | ||
return updateJsonInTree('package.json', json => { | ||
json.scripts = json.scripts || {}; | ||
json.dependencies = json.dependencies || {}; | ||
json.dependencies = { | ||
...json.dependencies, | ||
'nativescript-angular': nsNgVersion, | ||
'tns-core-modules': nsCoreVersion | ||
}; | ||
json.devDependencies = json.devDependencies || {}; | ||
json.devDependencies = { | ||
...json.devDependencies, | ||
'terser-webpack-plugin': terserWebpackVersion, | ||
'tns-platform-declarations': nsCoreVersion | ||
}; | ||
|
||
return json; | ||
})(tree, context); | ||
} | ||
|
||
export default function(): Rule { | ||
return chain([updateNativeScriptApps, 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
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
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
Oops, something went wrong.