-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schematics): Add ability to ng update from Nx 1.x
- Loading branch information
1 parent
f78889e
commit 8de81d6
Showing
39 changed files
with
949 additions
and
57 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...tics/migrations/20171129-change-schema.ts → ...gacy-migrations/20171129-change-schema.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
2 changes: 1 addition & 1 deletion
2
...tics/migrations/20171202-change-schema.ts → ...gacy-migrations/20171202-change-schema.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
2 changes: 1 addition & 1 deletion
2
...171205-remove-npmscope-from-tslintjson.ts → ...171205-remove-npmscope-from-tslintjson.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
4 changes: 2 additions & 2 deletions
4
...ns/20171211-create-tsconfigapp-per-app.ts → ...ns/20171211-create-tsconfigapp-per-app.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
2 changes: 1 addition & 1 deletion
2
...13-update-tsconfig-spec-to-exclude-e2e.ts → ...13-update-tsconfig-spec-to-exclude-e2e.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
2 changes: 1 addition & 1 deletion
2
...rations/20171219-add-affected-commands.ts → ...rations/20171219-add-affected-commands.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
2 changes: 1 addition & 1 deletion
2
...s/20180103-update-command-line-scripts.ts → ...s/20180103-update-command-line-scripts.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
2 changes: 1 addition & 1 deletion
2
...command-line-scripts-to-use-nx-command.ts → ...command-line-scripts-to-use-nx-command.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
2 changes: 1 addition & 1 deletion
2
...cs/migrations/20180120-update-prettier.ts → ...cy-migrations/20180120-update-prettier.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
2 changes: 1 addition & 1 deletion
2
...ics/migrations/20180121-update-angular.ts → ...acy-migrations/20180121-update-angular.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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...tions/20180122-add-angular-devkit-core.ts → ...tions/20180122-add-angular-devkit-core.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
2 changes: 1 addition & 1 deletion
2
.../20180130-add-migration-check-and-skip.ts → .../20180130-add-migration-check-and-skip.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
2 changes: 1 addition & 1 deletion
2
...cs/migrations/20180130-add-postinstall.ts → ...cy-migrations/20180130-add-postinstall.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
2 changes: 1 addition & 1 deletion
2
...ons/20180130-angular-devkit-schematics.ts → ...ons/20180130-angular-devkit-schematics.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
2 changes: 1 addition & 1 deletion
2
...cs/migrations/20180225-switch-to-cli17.ts → ...cy-migrations/20180225-switch-to-cli17.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
2 changes: 1 addition & 1 deletion
2
...cs/migrations/20180227-cleanup-scripts.ts → ...cy-migrations/20180227-cleanup-scripts.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
4 changes: 2 additions & 2 deletions
4
...80309-create-or-update-prettierrc-file.ts → ...80309-create-or-update-prettierrc-file.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
2 changes: 1 addition & 1 deletion
2
...chematics/migrations/20180313-add-tags.ts → ...ns/legacy-migrations/20180313-add-tags.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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...matics/migrations/20180328-add-nx-lint.ts → ...legacy-migrations/20180328-add-nx-lint.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
2 changes: 1 addition & 1 deletion
2
...s/migrations/20180404-adding-dep-graph.ts → ...y-migrations/20180404-adding-dep-graph.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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...180405-add-workspace-schematic-command.ts → ...180405-add-workspace-schematic-command.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
2 changes: 1 addition & 1 deletion
2
.../migrations/20180412-nx-update-scripts.ts → ...-migrations/20180412-nx-update-scripts.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
File renamed without changes.
46 changes: 46 additions & 0 deletions
46
packages/schematics/migrations/legacy-migrations/20180507-create-nx-json.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,46 @@ | ||
import { existsSync, writeFileSync } from 'fs'; | ||
import { dependencies } from '../../src/command-line/affected-apps'; | ||
import { | ||
readJsonFile, | ||
serializeJson, | ||
updateJsonFile | ||
} from '../../src/utils/fileutils'; | ||
import { stripIndents } from '@angular-devkit/core/src/utils/literals'; | ||
|
||
export default { | ||
description: `Create nx.json before migrating to Angular CLI 6.`, | ||
run: () => { | ||
if (!existsSync('.angular-cli.json') && existsSync('angular.json')) { | ||
console.warn(stripIndents` | ||
You have already upgraded to Angular CLI 6. | ||
We will not be able to recover information about your project's tags for you. | ||
`); | ||
return; | ||
} | ||
|
||
const angularJson = readJsonFile('.angular-cli.json'); | ||
const projects = angularJson.apps.reduce((projects, app) => { | ||
if (app.name === '$workspaceRoot') { | ||
return projects; | ||
} | ||
const normalizedName = app.name.replace(new RegExp('/', 'g'), '-'); | ||
projects[normalizedName] = { | ||
tags: app.tags | ||
}; | ||
if (app.root.startsWith('apps/')) { | ||
projects[`${normalizedName}-e2e`] = { | ||
tags: [] | ||
}; | ||
} | ||
|
||
return projects; | ||
}, {}); | ||
writeFileSync( | ||
'nx.json', | ||
serializeJson({ | ||
npmScope: angularJson.project.npmScope, | ||
projects: projects | ||
}) | ||
); | ||
} | ||
}; |
62 changes: 62 additions & 0 deletions
62
packages/schematics/migrations/legacy-migrations/20180515-switch-to-nx6.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,62 @@ | ||
import { existsSync, writeFileSync } from 'fs'; | ||
import { dependencies } from '../../src/command-line/affected-apps'; | ||
import { | ||
readJsonFile, | ||
serializeJson, | ||
updateJsonFile | ||
} from '../../src/utils/fileutils'; | ||
import { stripIndents } from '@angular-devkit/core/src/utils/literals'; | ||
import { execSync } from 'child_process'; | ||
|
||
export default { | ||
description: `Switch to Nx 6.0`, | ||
run: () => { | ||
if (!existsSync('.angular-cli.json') && existsSync('angular.json')) { | ||
console.warn(stripIndents` | ||
You have already upgraded to Angular CLI 6. | ||
We will not be able to recover information about your project's tags for you. | ||
`); | ||
return; | ||
} | ||
|
||
updateJsonFile('package.json', json => { | ||
json.devDependencies['@angular/cli'] = '6.0.1'; | ||
}); | ||
|
||
updateJsonFile('package.json', json => { | ||
delete json.scripts.postinstall; | ||
}); | ||
|
||
try { | ||
if (existsSync('yarn.lock')) { | ||
execSync('yarn install', { stdio: [0, 1, 2] }); | ||
} else { | ||
execSync('npm install', { stdio: [0, 1, 2] }); | ||
} | ||
|
||
execSync('ng update @angular/cli@6.0.1', { stdio: [0, 1, 2] }); | ||
execSync('ng update @nrwl/schematics@6.0.0', { stdio: [0, 1, 2] }); | ||
} catch (e) { | ||
console.warn(stripIndents` | ||
The automatic upgrade to Nx 6 has failed with the following error: ${e}. | ||
You can upgrade it manually by running: | ||
* yarn install or npm install | ||
* ng update @angular/cli@6.0.1 | ||
* ng update @nrwl/schematics@6.0.0 | ||
The upgrade process creates a test target for every library. If you have a library | ||
that does not have specs, either set failOnEmptyTestSuite to false in karma.conf.js of the library, | ||
or remove the test target in angular.json. | ||
`); | ||
throw e; | ||
} | ||
|
||
console.log(stripIndents` | ||
The upgrade process creates a test target for every library. If you have a library | ||
that does not have specs, either set failOnEmptyTestSuite to false in karma.conf.js of the library, | ||
or remove the test target in angular.json. | ||
`); | ||
} | ||
}; |
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,9 @@ | ||
{ | ||
"schematics": { | ||
"update-to-6.0.0": { | ||
"version": "6", | ||
"description": " ", | ||
"factory": "./update-6-0-0/update-6-0-0" | ||
} | ||
} | ||
} |
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,94 @@ | ||
import * as ts from 'typescript'; | ||
|
||
export function findFunctionCallExpressionStatement( | ||
nodes: ts.Node[], | ||
functionName: string | ||
): ts.ExpressionStatement { | ||
return nodes.find( | ||
node => | ||
ts.isExpressionStatement(node) && | ||
ts.isCallExpression(node.expression) && | ||
ts.isIdentifier(node.expression.expression) && | ||
node.expression.expression.escapedText === functionName | ||
) as ts.ExpressionStatement; | ||
} | ||
|
||
export function findFunctionCalls( | ||
sourceFile: ts.SourceFile, | ||
functionName: string | ||
) { | ||
return sourceFile.statements.filter(statement => { | ||
if (!ts.isVariableStatement(statement)) { | ||
return false; | ||
} | ||
const declarations = statement.declarationList.declarations; | ||
|
||
return declarations.some(declaration => { | ||
if ( | ||
!ts.isCallExpression(declaration.initializer) || | ||
!ts.isIdentifier(declaration.initializer.expression) | ||
) { | ||
return false; | ||
} | ||
|
||
return declaration.initializer.expression.text === functionName; | ||
}); | ||
}) as ts.VariableStatement[]; | ||
} | ||
|
||
export function findRequireStatement(nodes: ts.Node[]): ts.VariableStatement { | ||
return nodes.find(node => { | ||
if (!ts.isVariableStatement(node)) { | ||
return false; | ||
} | ||
|
||
const requireDeclaration = node.declarationList.declarations.find( | ||
declaration => { | ||
if (!ts.isCallExpression(declaration.initializer)) { | ||
return false; | ||
} | ||
|
||
const callExpression = declaration.initializer; | ||
if ( | ||
ts.isIdentifier(callExpression.expression) && | ||
callExpression.expression.escapedText === 'require' && | ||
ts.isStringLiteral(callExpression.arguments[0]) | ||
) { | ||
const argument = callExpression.arguments[0] as ts.StringLiteral; | ||
return ( | ||
argument.text === '@nrwl/schematics/src/utils/cli-config-utils' | ||
); | ||
} | ||
return false; | ||
} | ||
) as ts.VariableDeclaration; | ||
|
||
return !!requireDeclaration; | ||
}) as ts.VariableStatement; | ||
} | ||
|
||
export function findSpecDeclaration(nodes: ts.Node[]) { | ||
return nodes.find( | ||
node => | ||
ts.isPropertyAssignment(node) && | ||
ts.isIdentifier(node.name) && | ||
node.name.text === 'specs' && | ||
ts.isArrayLiteralExpression(node.initializer) | ||
) as ts.PropertyAssignment; | ||
} | ||
|
||
export function findTsNodeRegisterExpression(nodes: ts.Node[]) { | ||
return nodes.find( | ||
node => | ||
ts.isCallExpression(node) && | ||
ts.isPropertyAccessExpression(node.expression) && | ||
ts.isIdentifier(node.expression.name) && | ||
node.expression.name.text === 'register' && | ||
ts.isCallExpression(node.expression.expression) && | ||
ts.isIdentifier(node.expression.expression.expression) && | ||
node.expression.expression.expression.text === 'require' && | ||
ts.isStringLiteral(node.expression.expression.arguments[0]) && | ||
(node.expression.expression.arguments[0] as ts.StringLiteral).text === | ||
'ts-node' | ||
) as ts.CallExpression; | ||
} |
Oops, something went wrong.