|
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 |
| - let output; |
29 |
| - try { |
30 |
| - output = require("@nrwl/workspace").output; |
31 |
| - } catch (e) { |
32 |
| - console.warn( |
33 |
| - "Angular CLI could not be decorated to enable computation caching. Please ensure @nrwl/workspace is installed." |
34 |
| - ); |
35 |
| - process.exit(0); |
36 |
| - } |
| 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("@nx/workspace").output; |
| 31 | +} catch (e) { |
| 32 | + console.warn( |
| 33 | + "Angular CLI could not be decorated to enable computation caching. Please ensure @nx/workspace is installed." |
| 34 | + ); |
| 35 | + process.exit(0); |
| 36 | +} |
37 | 37 |
|
38 |
| - /** |
39 |
| - * Symlink of ng to nx, so you can keep using `ng build/test/lint` and still |
40 |
| - * invoke the Nx CLI and get the benefits of computation caching. |
41 |
| - */ |
42 |
| - function symlinkNgCLItoNxCLI() { |
43 |
| - try { |
44 |
| - const ngPath = "./node_modules/.bin/ng"; |
45 |
| - const nxPath = "./node_modules/.bin/nx"; |
46 |
| - if (isWindows) { |
47 |
| - /** |
48 |
| - * This is the most reliable way to create symlink-like behavior on Windows. |
49 |
| - * Such that it works in all shells and works with npx. |
50 |
| - */ |
51 |
| - ["", ".cmd", ".ps1"].forEach((ext) => { |
52 |
| - if (fs.existsSync(nxPath + ext)) |
53 |
| - fs.writeFileSync(ngPath + ext, fs.readFileSync(nxPath + ext)); |
54 |
| - }); |
55 |
| - } else { |
56 |
| - // If unix-based, symlink |
57 |
| - cp.execSync(`ln -sf ./nx ${ngPath}`); |
58 |
| - } |
59 |
| - } catch (e) { |
60 |
| - output.error({ |
61 |
| - title: |
62 |
| - "Unable to create a symlink from the Angular CLI to the Nx CLI:" + |
63 |
| - e.message, |
64 |
| - }); |
65 |
| - throw e; |
66 |
| - } |
67 |
| - } |
| 38 | +/** |
| 39 | + * Symlink of ng to nx, so you can keep using `ng build/test/lint` and still |
| 40 | + * invoke the Nx CLI and get the benefits of computation caching. |
| 41 | + */ |
| 42 | +function symlinkNgCLItoNxCLI() { |
| 43 | + try { |
| 44 | + const ngPath = "./node_modules/.bin/ng"; |
| 45 | + const nxPath = "./node_modules/.bin/nx"; |
| 46 | + if (isWindows) { |
| 47 | + /** |
| 48 | + * This is the most reliable way to create symlink-like behavior on Windows. |
| 49 | + * Such that it works in all shells and works with npx. |
| 50 | + */ |
| 51 | + ["", ".cmd", ".ps1"].forEach((ext) => { |
| 52 | + if (fs.existsSync(nxPath + ext)) |
| 53 | + fs.writeFileSync(ngPath + ext, fs.readFileSync(nxPath + ext)); |
| 54 | + }); |
| 55 | + } else { |
| 56 | + // If unix-based, symlink |
| 57 | + cp.execSync(`ln -sf ./nx ${ngPath}`); |
| 58 | + } |
| 59 | + } catch (e) { |
| 60 | + output.error({ |
| 61 | + title: |
| 62 | + "Unable to create a symlink from the Angular CLI to the Nx CLI:" + |
| 63 | + e.message, |
| 64 | + }); |
| 65 | + throw e; |
| 66 | + } |
| 67 | +} |
68 | 68 |
|
69 |
| - try { |
70 |
| - symlinkNgCLItoNxCLI(); |
71 |
| - require("@nrwl/cli/lib/decorate-cli").decorateCli(); |
72 |
| - output.log({ |
73 |
| - title: "Angular CLI has been decorated to enable computation caching.", |
74 |
| - }); |
75 |
| - } catch (e) { |
76 |
| - output.error({ |
77 |
| - title: "Decoration of the Angular CLI did not complete successfully", |
78 |
| - }); |
79 |
| - } |
| 69 | +try { |
| 70 | + symlinkNgCLItoNxCLI(); |
| 71 | + require("@nrwl/cli/lib/decorate-cli").decorateCli(); |
| 72 | + output.log({ |
| 73 | + title: "Angular CLI has been decorated to enable computation caching.", |
| 74 | + }); |
| 75 | +} catch (e) { |
| 76 | + output.error({ |
| 77 | + title: "Decoration of the Angular CLI did not complete successfully", |
| 78 | + }); |
| 79 | +} |
0 commit comments