NG-16 - migration step 1

This commit is contained in:
VitoAlbano
2024-08-02 00:10:21 +01:00
parent 8a60a26701
commit 8d66c782b9
35 changed files with 7772 additions and 6615 deletions

View File

@@ -21,35 +21,35 @@
* - Delete and reinstall your node_modules
*/
const fs = require("fs");
const os = require("os");
const cp = require("child_process");
const isWindows = os.platform() === "win32";
const fs = require('fs');
const os = require('os');
const cp = require('child_process');
const isWindows = os.platform() === 'win32';
const output = require('nx/src/utils/output').output;
/**
* Paths to files being patched
*/
const angularCLIInitPath = "node_modules/@angular/cli/lib/cli/index.js";
const angularCLIInitPath = 'node_modules/@angular/cli/lib/cli/index.js';
/**
* Patch index.js to warn you if you invoke the undecorated Angular CLI.
*/
function patchAngularCLI(initPath) {
const angularCLIInit = fs.readFileSync(initPath, "utf-8").toString();
const angularCLIInit = fs.readFileSync(initPath, 'utf-8').toString();
if (!angularCLIInit.includes("NX_CLI_SET")) {
fs.writeFileSync(
initPath,
`
if (!angularCLIInit.includes('NX_CLI_SET')) {
fs.writeFileSync(
initPath,
`
if (!process.env['NX_CLI_SET']) {
const { output } = require('@nrwl/workspace');
const { output } = require('@nx/workspace');
output.warn({ title: 'The Angular CLI was invoked instead of the Nx CLI. Use "npx ng [command]" or "nx [command]" instead.' });
}
${angularCLIInit}
`
);
}
);
}
}
/**
@@ -57,39 +57,37 @@ ${angularCLIInit}
* invoke the Nx CLI and get the benefits of computation caching.
*/
function symlinkNgCLItoNxCLI() {
try {
const ngPath = "./node_modules/.bin/ng";
const nxPath = "./node_modules/.bin/nx";
if (isWindows) {
/**
* This is the most reliable way to create symlink-like behavior on Windows.
* Such that it works in all shells and works with npx.
*/
["", ".cmd", ".ps1"].forEach(ext => {
fs.writeFileSync(ngPath + ext, fs.readFileSync(nxPath + ext));
});
} else {
// If unix-based, symlink
cp.execSync(`ln -sf ./nx ${ngPath}`);
try {
const ngPath = './node_modules/.bin/ng';
const nxPath = './node_modules/.bin/nx';
if (isWindows) {
/**
* This is the most reliable way to create symlink-like behavior on Windows.
* Such that it works in all shells and works with npx.
*/
['', '.cmd', '.ps1'].forEach((ext) => {
fs.writeFileSync(ngPath + ext, fs.readFileSync(nxPath + ext));
});
} else {
// If unix-based, symlink
cp.execSync(`ln -sf ./nx ${ngPath}`);
}
} catch (e) {
output.error({
title: 'Unable to create a symlink from the Angular CLI to the Nx CLI:' + e.message
});
throw e;
}
} catch (e) {
output.error({
title:
"Unable to create a symlink from the Angular CLI to the Nx CLI:" +
e.message
});
throw e;
}
}
try {
symlinkNgCLItoNxCLI();
patchAngularCLI(angularCLIInitPath);
output.log({
title: "Angular CLI has been decorated to enable computation caching."
});
symlinkNgCLItoNxCLI();
patchAngularCLI(angularCLIInitPath);
output.log({
title: 'Angular CLI has been decorated to enable computation caching.'
});
} catch (e) {
output.error({
title: "Decoration of the Angular CLI did not complete successfully"
});
output.error({
title: 'Decoration of the Angular CLI did not complete successfully'
});
}