21
21
* - Delete and reinstall your node_modules
22
22
*/
23
23
24
- const fs = require ( "fs" ) ;
25
- const os = require ( "os" ) ;
26
- const cp = require ( "child_process" ) ;
27
- const isWindows = os . platform ( ) === "win32" ;
28
- const { output } = require ( "@nrwl/workspace" ) ;
29
-
30
- /**
31
- * Paths to files being patched
32
- */
33
- const angularCLIInitPath = "node_modules/@angular/cli/lib/cli/index.js" ;
34
-
35
- /**
36
- * Patch index.js to warn you if you invoke the undecorated Angular CLI.
37
- */
38
- function patchAngularCLI ( initPath ) {
39
- const angularCLIInit = fs . readFileSync ( initPath , "utf-8" ) . toString ( ) ;
40
-
41
- if ( ! angularCLIInit . includes ( "NX_CLI_SET" ) ) {
42
- fs . writeFileSync (
43
- initPath ,
44
- `
45
- if (!process.env['NX_CLI_SET']) {
46
- const { output } = require('@nrwl/workspace');
47
- output.warn({ title: 'The Angular CLI was invoked instead of the Nx CLI. Use "npx ng [command]" or "nx [command]" instead.' });
48
- }
49
- ${ angularCLIInit }
50
- `
51
- ) ;
52
- }
24
+ const fs = require ( 'fs' ) ;
25
+ const os = require ( 'os' ) ;
26
+ const cp = require ( 'child_process' ) ;
27
+ const isWindows = os . platform ( ) === 'win32' ;
28
+ let output ;
29
+ try {
30
+ output = require ( '@nrwl/workspace' ) . output ;
31
+ } catch ( e ) {
32
+ console . warn ( 'Angular CLI could not be decorated to enable computation caching. Please ensure @nrwl/workspace is installed.' ) ;
33
+ process . exit ( 0 ) ;
53
34
}
54
35
55
36
/**
@@ -58,39 +39,31 @@ ${angularCLIInit}
58
39
*/
59
40
function symlinkNgCLItoNxCLI ( ) {
60
41
try {
61
- const ngPath = " ./node_modules/.bin/ng" ;
62
- const nxPath = " ./node_modules/.bin/nx" ;
42
+ const ngPath = ' ./node_modules/.bin/ng' ;
43
+ const nxPath = ' ./node_modules/.bin/nx' ;
63
44
if ( isWindows ) {
64
45
/**
65
46
* This is the most reliable way to create symlink-like behavior on Windows.
66
47
* Such that it works in all shells and works with npx.
67
48
*/
68
- [ "" , ".cmd" , ".ps1" ] . forEach ( ( ext ) => {
69
- if ( fs . existsSync ( nxPath + ext ) )
70
- fs . writeFileSync ( ngPath + ext , fs . readFileSync ( nxPath + ext ) ) ;
49
+ [ '' , '.cmd' , '.ps1' ] . forEach ( ext => {
50
+ if ( fs . existsSync ( nxPath + ext ) ) fs . writeFileSync ( ngPath + ext , fs . readFileSync ( nxPath + ext ) ) ;
71
51
} ) ;
72
52
} else {
73
53
// If unix-based, symlink
74
54
cp . execSync ( `ln -sf ./nx ${ ngPath } ` ) ;
75
55
}
76
- } catch ( e ) {
77
- output . error ( {
78
- title :
79
- "Unable to create a symlink from the Angular CLI to the Nx CLI:" +
80
- e . message ,
81
- } ) ;
56
+ }
57
+ catch ( e ) {
58
+ output . error ( { title : 'Unable to create a symlink from the Angular CLI to the Nx CLI:' + e . message } ) ;
82
59
throw e ;
83
60
}
84
61
}
85
62
86
63
try {
87
64
symlinkNgCLItoNxCLI ( ) ;
88
- patchAngularCLI ( angularCLIInitPath ) ;
89
- output . log ( {
90
- title : "Angular CLI has been decorated to enable computation caching." ,
91
- } ) ;
92
- } catch ( e ) {
93
- output . error ( {
94
- title : "Decoration of the Angular CLI did not complete successfully" ,
95
- } ) ;
65
+ require ( '@nrwl/cli/lib/decorate-cli' ) . decorateCli ( ) ;
66
+ output . log ( { title : 'Angular CLI has been decorated to enable computation caching.' } ) ;
67
+ } catch ( e ) {
68
+ output . error ( { title : 'Decoration of the Angular CLI did not complete successfully' } ) ;
96
69
}
0 commit comments