@trackunit/nx-utils 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +2 -3
- package/src/ast/astUtils.js +35 -1
- package/src/ast/astUtils.js.map +1 -1
- package/src/index.js +8 -0
- package/src/index.js.map +1 -1
- package/src/nxTestUtils.js +1 -0
- package/src/nxTestUtils.js.map +1 -1
- package/src/projectUtils.js +30 -1
- package/src/projectUtils.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.0.8](https://github.com/Trackunit/manager/compare/nx-utils/0.0.7...nx-utils/0.0.8) (2023-04-14)
|
|
6
|
+
|
|
7
|
+
## [0.0.7](https://github.com/Trackunit/manager/compare/nx-utils/0.0.6...nx-utils/0.0.7) (2023-04-14)
|
|
8
|
+
|
|
5
9
|
## [0.0.6](https://github.com/Trackunit/manager/compare/nx-utils/0.0.5...nx-utils/0.0.6) (2023-04-11)
|
|
6
10
|
|
|
7
11
|
## [0.0.5](https://github.com/Trackunit/manager/compare/nx-utils/0.0.4...nx-utils/0.0.5) (2023-04-09)
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/nx-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"main": "src/lib/index.ts",
|
|
5
5
|
"repository": "https://github.com/Trackunit/manager",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
7
|
-
"types": "./src/index.d.ts",
|
|
8
7
|
"dependencies": {
|
|
9
8
|
"@phenomnomnominal/tsquery": "4.2.0",
|
|
10
9
|
"tslib": "2.4.1"
|
|
11
10
|
},
|
|
12
|
-
"
|
|
11
|
+
"types": "./src/index.d.ts"
|
|
13
12
|
}
|
package/src/ast/astUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removePropertyWithName = void 0;
|
|
3
|
+
exports.addPropertyWithName = exports.removePropertyWithName = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
6
6
|
const ts = tslib_1.__importStar(require("typescript"));
|
|
@@ -28,4 +28,38 @@ function removePropertyWithName(fileContent, propertyName) {
|
|
|
28
28
|
return ts.createPrinter().printFile(updatedSourceFile);
|
|
29
29
|
}
|
|
30
30
|
exports.removePropertyWithName = removePropertyWithName;
|
|
31
|
+
/**
|
|
32
|
+
* This function adds a new property with a given name and value to an object literal
|
|
33
|
+
* provided as a text string.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} fileContent - the source code as text
|
|
36
|
+
* @param {string} propertyName - the name of the property to add
|
|
37
|
+
* @param {string | string[]} propertyValue - the value of the property to add
|
|
38
|
+
*/
|
|
39
|
+
function addPropertyWithName(fileContent, propertyName, propertyValue) {
|
|
40
|
+
const sourceFile = tsquery_1.tsquery.ast(fileContent);
|
|
41
|
+
const updatedSourceFile = tsquery_1.tsquery.map(sourceFile, "ObjectLiteralExpression", node => {
|
|
42
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
43
|
+
// Add a new property to the object literal
|
|
44
|
+
let updatedProperties;
|
|
45
|
+
if (typeof propertyValue === "string") {
|
|
46
|
+
updatedProperties = [
|
|
47
|
+
...node.properties,
|
|
48
|
+
ts.factory.createPropertyAssignment(ts.factory.createIdentifier(propertyName), ts.factory.createStringLiteral(propertyValue)),
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
else if (Array.isArray(propertyValue)) {
|
|
52
|
+
const arrayLiteral = ts.factory.createArrayLiteralExpression(propertyValue.map(value => ts.factory.createStringLiteral(value)));
|
|
53
|
+
updatedProperties = [
|
|
54
|
+
...node.properties,
|
|
55
|
+
ts.factory.createPropertyAssignment(ts.factory.createIdentifier(propertyName), arrayLiteral),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
return ts.factory.createObjectLiteralExpression(updatedProperties, true);
|
|
59
|
+
}
|
|
60
|
+
return node;
|
|
61
|
+
});
|
|
62
|
+
return ts.createPrinter().printFile(updatedSourceFile);
|
|
63
|
+
}
|
|
64
|
+
exports.addPropertyWithName = addPropertyWithName;
|
|
31
65
|
//# sourceMappingURL=astUtils.js.map
|
package/src/ast/astUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astUtils.js","sourceRoot":"","sources":["../../../../../../libs/nx/utils/src/ast/astUtils.ts"],"names":[],"mappings":";;;;AAAA,uDAAoD;AACpD,uDAAiC;AAEjC;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAAC,WAAmB,EAAE,YAAoB;IAC9E,MAAM,UAAU,GAAG,iBAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC5C,MAAM,iBAAiB,GAAG,iBAAO,CAAC,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,IAAI,CAAC,EAAE;QAClF,IAAI,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE;YACtC,gCAAgC;YAChC,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;gBAC1D,OAAO,CAAC,CACN,EAAE,CAAC,oBAAoB,CAAC,QAAQ,CAAC;oBACjC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC;oBAC9B,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,CACpC,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,OAAO,EAAE,CAAC,OAAO,CAAC,6BAA6B,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;SAC1E;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;AACzD,CAAC;AAjBD,wDAiBC","sourcesContent":["import { tsquery } from \"@phenomnomnominal/tsquery\";\nimport * as ts from \"typescript\";\n\n/**\n * This function removes a property with a given name from an object literal\n * provided as a text string.\n *\n * @param {string} fileContent - the source code as text\n * @param {string} propertyName - the property to remove from the source code\n */\nexport function removePropertyWithName(fileContent: string, propertyName: string) {\n const sourceFile = tsquery.ast(fileContent);\n const updatedSourceFile = tsquery.map(sourceFile, \"ObjectLiteralExpression\", node => {\n if (ts.isObjectLiteralExpression(node)) {\n // Filter out the given property\n const updatedProperties = node.properties.filter(property => {\n return !(\n ts.isPropertyAssignment(property) &&\n ts.isIdentifier(property.name) &&\n property.name.text === propertyName\n );\n });\n return ts.factory.createObjectLiteralExpression(updatedProperties, true);\n }\n return node;\n });\n return ts.createPrinter().printFile(updatedSourceFile);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"astUtils.js","sourceRoot":"","sources":["../../../../../../libs/nx/utils/src/ast/astUtils.ts"],"names":[],"mappings":";;;;AAAA,uDAAoD;AACpD,uDAAiC;AAEjC;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAAC,WAAmB,EAAE,YAAoB;IAC9E,MAAM,UAAU,GAAG,iBAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC5C,MAAM,iBAAiB,GAAG,iBAAO,CAAC,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,IAAI,CAAC,EAAE;QAClF,IAAI,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE;YACtC,gCAAgC;YAChC,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;gBAC1D,OAAO,CAAC,CACN,EAAE,CAAC,oBAAoB,CAAC,QAAQ,CAAC;oBACjC,EAAE,CAAC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AG;oBAClB,GAAG,IAAI,CAAC,UAAU;oBAClB,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;iBAC7F,CAAC;aACH;YACD,OAAO,EAAE,CAAC,OAAO,CAAC,6BAA6B,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;SAC1E;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;AACzD,CAAC;AA5BD,kDA4BC","sourcesContent":["import { tsquery } from \"@phenomnomnominal/tsquery\";\nimport * as ts from \"typescript\";\n\n/**\n * This function removes a property with a given name from an object literal\n * provided as a text string.\n *\n * @param {string} fileContent - the source code as text\n * @param {string} propertyName - the property to remove from the source code\n */\nexport function removePropertyWithName(fileContent: string, propertyName: string) {\n const sourceFile = tsquery.ast(fileContent);\n const updatedSourceFile = tsquery.map(sourceFile, \"ObjectLiteralExpression\", node => {\n if (ts.isObjectLiteralExpression(node)) {\n // Filter out the given property\n const updatedProperties = node.properties.filter(property => {\n return !(\n ts.isPropertyAssignment(property) &&\n ts.isIdentifier(property.name) &&\n property.name.text === propertyName\n );\n });\n return ts.factory.createObjectLiteralExpression(updatedProperties, true);\n }\n return node;\n });\n return ts.createPrinter().printFile(updatedSourceFile);\n}\n\n/**\n * This function adds a new property with a given name and value to an object literal\n * provided as a text string.\n *\n * @param {string} fileContent - the source code as text\n * @param {string} propertyName - the name of the property to add\n * @param {string | string[]} propertyValue - the value of the property to add\n */\nexport function addPropertyWithName(fileContent: string, propertyName: string, propertyValue: string | string[]) {\n const sourceFile = tsquery.ast(fileContent);\n const updatedSourceFile = tsquery.map(sourceFile, \"ObjectLiteralExpression\", node => {\n if (ts.isObjectLiteralExpression(node)) {\n // Add a new property to the object literal\n let updatedProperties;\n if (typeof propertyValue === \"string\") {\n updatedProperties = [\n ...node.properties,\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(propertyName),\n ts.factory.createStringLiteral(propertyValue)\n ),\n ];\n } else if (Array.isArray(propertyValue)) {\n const arrayLiteral = ts.factory.createArrayLiteralExpression(\n propertyValue.map(value => ts.factory.createStringLiteral(value))\n );\n updatedProperties = [\n ...node.properties,\n ts.factory.createPropertyAssignment(ts.factory.createIdentifier(propertyName), arrayLiteral),\n ];\n }\n return ts.factory.createObjectLiteralExpression(updatedProperties, true);\n }\n return node;\n });\n return ts.createPrinter().printFile(updatedSourceFile);\n}\n"]}
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateFile = exports.uniq = exports.readJson = exports.readFile = exports.checkFilesExist = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
// eslint-disable-next-line no-restricted-imports
|
|
6
|
+
var testing_1 = require("@nrwl/nx-plugin/testing");
|
|
7
|
+
Object.defineProperty(exports, "checkFilesExist", { enumerable: true, get: function () { return testing_1.checkFilesExist; } });
|
|
8
|
+
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return testing_1.readFile; } });
|
|
9
|
+
Object.defineProperty(exports, "readJson", { enumerable: true, get: function () { return testing_1.readJson; } });
|
|
10
|
+
Object.defineProperty(exports, "uniq", { enumerable: true, get: function () { return testing_1.uniq; } });
|
|
11
|
+
Object.defineProperty(exports, "updateFile", { enumerable: true, get: function () { return testing_1.updateFile; } });
|
|
4
12
|
tslib_1.__exportStar(require("./ast/astUtils"), exports);
|
|
5
13
|
tslib_1.__exportStar(require("./nxTestUtils"), exports);
|
|
6
14
|
tslib_1.__exportStar(require("./projectUtils"), exports);
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/index.ts"],"names":[],"mappings":";;;;AAAA,iDAAiD;AACjD,mDAAgG;AAAvF,0GAAA,eAAe,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,+FAAA,IAAI,OAAA;AAAE,qGAAA,UAAU,OAAA;AAC9D,yDAA+B;AAC/B,wDAA8B;AAC9B,yDAA+B","sourcesContent":["// eslint-disable-next-line no-restricted-imports\nexport { checkFilesExist, readFile, readJson, uniq, updateFile } from \"@nrwl/nx-plugin/testing\";\nexport * from \"./ast/astUtils\";\nexport * from \"./nxTestUtils\";\nexport * from \"./projectUtils\";\n"]}
|
package/src/nxTestUtils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureNxProject = void 0;
|
|
4
|
+
// eslint-disable-next-line no-restricted-imports
|
|
4
5
|
const testing_1 = require("@nrwl/nx-plugin/testing");
|
|
5
6
|
const child_process_1 = require("child_process");
|
|
6
7
|
const fs_1 = require("fs");
|
package/src/nxTestUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nxTestUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/nxTestUtils.ts"],"names":[],"mappings":";;;AAAA,qDAMiC;AACjC,iDAAyC;AACzC,2BAAmD;AACnD,+BAA+B;AAE/B,MAAM,OAAO,GAAG,IAAA,qBAAW,GAAE,CAAC;AAE9B,MAAM,eAAe,GAAG,CAAC,IAAa,EAAE,MAAgB,EAAE,EAAE;IAC1D,MAAM,WAAW,GAAG,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IACrC,OAAO,IAAA,wBAAQ,EACb,QAAQ,OAAO,CAAC,OAAO,CACrB,IAAI,CACL,iCAAiC,WAAW,gGAC3C,IAAI,IA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W,gGAC3C,IAAI,IAAI,EACV,EAAE,kBAEA,GAAG,EAAE,WAAW,IACb,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAExE,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACI,MAAM,eAAe,GAAG,CAAC,cAAsB,EAAE,cAAsB,EAAE,EAAE;IAChF,IAAI,IAAA,eAAU,EAAC,OAAO,CAAC,EAAE;QACvB,IAAA,WAAM,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;KACtC;IACD,IAAA,cAAS,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,IAAA,iBAAO,GAAE,CAAC;IACV,eAAe,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC;IAChD,IAAA,mCAAyB,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IAC1D,IAAA,oBAAU,EAAC,OAAO,GAAG,WAAW,EAAE,EAAE,CAAC,CAAC;IACtC,IAAA,kCAAwB,GAAE,CAAC;AAC7B,CAAC,CAAC;AAVW,QAAA,eAAe,mBAU1B","sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport {\n cleanup,\n patchPackageJsonForPlugin,\n runPackageManagerInstall,\n tmpProjPath,\n updateFile,\n} from \"@nrwl/nx-plugin/testing\";\nimport { execSync } from \"child_process\";\nimport { existsSync, mkdirSync, rmSync } from \"fs\";\nimport { dirname } from \"path\";\n\nconst tmpPath = tmpProjPath();\n\nconst runNxNewCommand = (args?: string, silent?: boolean) => {\n const localTmpDir = dirname(tmpPath);\n return execSync(\n `node ${require.resolve(\n \"nx\"\n )} new proj --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=empty ${\n args || \"\"\n }`,\n {\n cwd: localTmpDir,\n ...(silent && false ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n }\n );\n};\n\n/**\n * Ensures that a project has been setup in the e2e directory\n * It will also copy `@nrwl` packages to the e2e directory\n * When yarn install works in nx-plugin we can replace this file.\n * - https://github.com/nrwl/nx/issues/15263\n */\nexport const ensureNxProject = (npmPackageName: string, pluginDistPath: string) => {\n if (existsSync(tmpPath)) {\n rmSync(tmpPath, { recursive: true });\n }\n mkdirSync(tmpPath, { recursive: true });\n cleanup();\n runNxNewCommand(\"--package-manager=yarn\", true);\n patchPackageJsonForPlugin(npmPackageName, pluginDistPath);\n updateFile(tmpPath + \"yarn.lock\", \"\");\n runPackageManagerInstall();\n};\n"]}
|
package/src/projectUtils.js
CHANGED
|
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ensureNxProjects = exports.runNxCommandAsync = exports.runCommandAsync = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nrwl/devkit");
|
|
6
|
+
// eslint-disable-next-line no-restricted-imports
|
|
6
7
|
const testing_1 = require("@nrwl/nx-plugin/testing");
|
|
7
8
|
const child_process_1 = require("child_process");
|
|
8
9
|
const fs = tslib_1.__importStar(require("fs"));
|
|
9
10
|
const path_1 = require("path");
|
|
10
11
|
const runNxNewCommand = (nxRoot, args, silent) => {
|
|
11
12
|
const localTmpDir = (0, testing_1.tmpProjPath)();
|
|
12
|
-
return (0, child_process_1.execSync)(`node ${require.resolve("@nrwl/tao")} new ${nxRoot} --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=
|
|
13
|
+
return (0, child_process_1.execSync)(`node ${require.resolve("@nrwl/tao")} new ${nxRoot} --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=ts ${args || ""}`, Object.assign({ cwd: localTmpDir }, (silent && false ? { stdio: ["ignore", "ignore", "ignore"] } : {})));
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
16
|
* Run a command asynchronously inside the e2e directory.
|
|
@@ -26,6 +27,12 @@ function runCommandAsync(command, projectName, opts = {
|
|
|
26
27
|
cwd: (0, testing_1.tmpProjPath)(projectName),
|
|
27
28
|
env: Object.assign(Object.assign({}, process.env), opts.env),
|
|
28
29
|
}, (err, stdout, stderr) => {
|
|
30
|
+
if (command.includes("--verbose") || (stderr === null || stderr === void 0 ? void 0 : stderr.length) > 0) {
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.log(`Stdout for cmd: ${command}:\n`, stdout);
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.log(`Stderr for cmd: ${command}:\n`, stderr);
|
|
35
|
+
}
|
|
29
36
|
if (!opts.silenceError && err) {
|
|
30
37
|
reject(err);
|
|
31
38
|
}
|
|
@@ -57,6 +64,7 @@ function runNxCommandAsync(command, projectName, opts = {
|
|
|
57
64
|
exports.runNxCommandAsync = runNxCommandAsync;
|
|
58
65
|
const newNxProject = (nxRootDir, nxRootPath, dependencies, devDependencies, packageManager) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
59
66
|
runNxNewCommand(nxRootDir, `--package-manager=${packageManager}`, true);
|
|
67
|
+
updateWorkspaceLayout(nxRootPath);
|
|
60
68
|
patchDistProjects(dependencies, "dependencies");
|
|
61
69
|
patchDistProjects(devDependencies, "devDependencies");
|
|
62
70
|
patchDistProjects(dependencies, "peerDependencies");
|
|
@@ -69,6 +77,7 @@ const newNxProject = (nxRootDir, nxRootPath, dependencies, devDependencies, pack
|
|
|
69
77
|
patchMainPackageJson(nxRootPath, devDependencies, "dependencies");
|
|
70
78
|
patchMainPackageJson(nxRootPath, devDependencies, "devDependencies");
|
|
71
79
|
patchMainPackageJson(nxRootPath, devDependencies, "peerDependencies");
|
|
80
|
+
updatePackageJson(nxRootPath);
|
|
72
81
|
yield runCommandAsync("yarn", nxRootDir);
|
|
73
82
|
});
|
|
74
83
|
function getAbsPath(distPath) {
|
|
@@ -83,6 +92,8 @@ const ensureNxProjects = (dependencies, devDependencies, nxRootDir, packageManag
|
|
|
83
92
|
fs.rmSync(nxRootPath, { recursive: true });
|
|
84
93
|
}
|
|
85
94
|
fs.mkdirSync(nxRootPath, { recursive: true });
|
|
95
|
+
// eslint-disable-next-line no-console
|
|
96
|
+
console.log("Using NX root dir:", nxRootPath);
|
|
86
97
|
yield newNxProject(nxRootDir, nxRootPath, dependencies, devDependencies, packageManager);
|
|
87
98
|
});
|
|
88
99
|
exports.ensureNxProjects = ensureNxProjects;
|
|
@@ -132,4 +143,22 @@ const patchDistProjects = (paths, type) => {
|
|
|
132
143
|
(0, devkit_1.writeJsonFile)(absPackageJson, newPackageJson);
|
|
133
144
|
}
|
|
134
145
|
};
|
|
146
|
+
const updateWorkspaceLayout = (nxRootPath) => {
|
|
147
|
+
const nxJsonPath = (0, path_1.join)(nxRootPath, "nx.json");
|
|
148
|
+
const nxJson = (0, devkit_1.readJsonFile)(nxJsonPath);
|
|
149
|
+
nxJson.workspaceLayout = {
|
|
150
|
+
appsDir: "apps",
|
|
151
|
+
libsDir: "libs",
|
|
152
|
+
};
|
|
153
|
+
(0, devkit_1.writeJsonFile)(nxJsonPath, nxJson);
|
|
154
|
+
};
|
|
155
|
+
const updatePackageJson = (nxRootPath) => {
|
|
156
|
+
const absPackageJson = (0, path_1.join)(nxRootPath, "package.json");
|
|
157
|
+
const newNxPackageJson = (0, devkit_1.readJsonFile)(absPackageJson);
|
|
158
|
+
const managerPackageJsonPath = (0, path_1.join)(__dirname, "..", "..", "..", "..", "package.json");
|
|
159
|
+
const managerPackageJson = (0, devkit_1.readJsonFile)(managerPackageJsonPath);
|
|
160
|
+
newNxPackageJson.engines = managerPackageJson.engines;
|
|
161
|
+
newNxPackageJson.volta = managerPackageJson.volta;
|
|
162
|
+
(0, devkit_1.writeJsonFile)(absPackageJson, newNxPackageJson);
|
|
163
|
+
};
|
|
135
164
|
//# sourceMappingURL=projectUtils.js.map
|
package/src/projectUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,qDAAkE;AAClE,iDAA+C;AAC/C,+CAAyB;AACzB,+BAA4B;AAM5B,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,IAAa,EAAE,MAAgB,EAAE,EAAE;IAC1E,MAAM,WAAW,GAAG,IAAA,qBAAW,GAAE,CAAC;IAClC,OAAO,IAAA,wBAAQ,EACb,QAAQ,OAAO,CAAC,OAAO,CACrB,WAAW,CACZ,QAAQ,MAAM,wBAAwB,WAAW,gGAChD,IAAI,IAAI,EACV,EAAE,kBAEA,GAAG,EAAE,WAAW,IACb,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAExE,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,OAAe,EACf,WAAmB,EACnB,OAA4D;IAC1D,YAAY,EAAE,KAAK;CACpB;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAA,oBAAI,EACF,OAAO,EACP;YACE,GAAG,EAAE,IAAA,qBAAW,EAAC,WAAW,CAAC;YAC7B,GAAG,kCAAO,OAAO,CAAC,GAAG,GAAK,IAAI,CAAC,GAAG,CAAE;SACrC,EACD,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YACtB,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,GAAG,EAAE;gBAC7B,MAAM,CAAC,GAAG,CAAC,CAAC;aACb;YACD,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAA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,IAAA,qBAAY,EAAC,cAAc,CAAC,CAAC;QACjD,MAAM,WAAW,GAAG,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,IAAI,CAAC,KAAI,EAAE,CAAC;QAE9C,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;YACvB,MAAM,WAAW,GAAG,SAAS,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,WAAW,EAAE;gBACxE,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,OAAO,cAAc,GAAG,CAAC,OAAO,OAAO,WAAW,EAAE,CAAC,CAAC;gBAC9E,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC;aACxC;SACF;QACD,MAAM,cAAc,qBAAQ,WAAW,CAAE,CAAC;QAC1C,cAAc,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;QACnC,IAAA,sBAAa,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;KAC/C;AACH,CAAC,CAAC","sourcesContent":["import { readJsonFile, writeJsonFile } from \"@nrwl/devkit\";\nimport { fileExists, tmpProjPath } from \"@nrwl/nx-plugin/testing\";\nimport { exec, execSync } from \"child_process\";\nimport * as fs from \"fs\";\nimport { join } from \"path\";\nexport interface ProjectDistPath {\n package: string;\n path: string;\n}\n\nconst runNxNewCommand = (nxRoot: string, args?: string, silent?: boolean) => {\n const localTmpDir = tmpProjPath();\n return execSync(\n `node ${require.resolve(\n \"@nrwl/tao\"\n )} new ${nxRoot} --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=empty ${\n args || \"\"\n }`,\n {\n cwd: localTmpDir,\n ...(silent && false ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n }\n );\n};\n\n/**\n * Run a command asynchronously inside the e2e directory.\n *\n * @param command command to run\n * @param projectName the name of the project in e2e directory\n * @param opts options\n */\nexport function runCommandAsync(\n command: string,\n projectName: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n exec(\n command,\n {\n cwd: tmpProjPath(projectName),\n env: { ...process.env, ...opts.env },\n },\n (err, stdout, stderr) => {\n if (!opts.silenceError && err) {\n reject(err);\n }\n resolve({ stdout, stderr });\n }\n );\n });\n}\n\n/**\n * Run a nx command asynchronously inside the e2e directory\n *\n * @param command command to run\n * @param projectName the name of the project in e2e directory\n * @param opts options\n */\nexport function runNxCommandAsync(\n command: string,\n projectName: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n if (fileExists(tmpProjPath(join(projectName, \"package.json\")))) {\n return runCommandAsync(`yarn nx ${command}`, projectName, opts);\n } else if (process.platform === \"win32\") {\n return runCommandAsync(`./nx.bat ${command}`, projectName, opts);\n } else {\n return runCommandAsync(`./nx ${command}`, projectName, opts);\n }\n}\n\nconst newNxProject = async (\n nxRootDir: string,\n nxRootPath: string,\n dependencies: ProjectDistPath[],\n devDependencies: ProjectDistPath[],\n packageManager: string\n) => {\n runNxNewCommand(nxRootDir, `--package-manager=${packageManager}`, true);\n patchDistProjects(dependencies, \"dependencies\");\n patchDistProjects(devDependencies, \"devDependencies\");\n\n patchDistProjects(dependencies, \"peerDependencies\");\n patchDistProjects(devDependencies, \"peerDependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"dependencies\", true);\n\n patchMainPackageJson(nxRootPath, devDependencies, \"devDependencies\", true);\n\n patchMainPackageJson(nxRootPath, dependencies, \"dependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"devDependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"peerDependencies\");\n\n patchMainPackageJson(nxRootPath, devDependencies, \"dependencies\");\n patchMainPackageJson(nxRootPath, devDependencies, \"devDependencies\");\n patchMainPackageJson(nxRootPath, devDependencies, \"peerDependencies\");\n await runCommandAsync(\"yarn\", nxRootDir);\n};\n\nfunction getAbsPath(distPath: string) {\n return join(process.cwd(), distPath);\n}\n\n/**\n * Ensure nx projects are in package.json in tmp nxRootDir\n */\nexport const ensureNxProjects = async (\n dependencies: ProjectDistPath[],\n devDependencies: ProjectDistPath[],\n nxRootDir: string,\n packageManager = \"yarn\"\n) => {\n const nxRootPath = tmpProjPath(nxRootDir);\n if (fs.existsSync(nxRootPath)) {\n fs.rmSync(nxRootPath, { recursive: true });\n }\n fs.mkdirSync(nxRootPath, { recursive: true });\n await newNxProject(nxRootDir, nxRootPath, dependencies, devDependencies, packageManager);\n};\n\n/**\n *\n * @param paths paths\n * @param type type\n * @param forceAdd force it\n */\nconst patchMainPackageJson = (\n testDir: string,\n paths: ProjectDistPath[],\n type: \"dependencies\" | \"devDependencies\" | \"peerDependencies\",\n forceAdd = false\n) => {\n const absPackageJson = join(testDir, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n const newPackageJson = { ...packageJson };\n\n for (const pkg of paths) {\n const absDistPath = `file:/${getAbsPath(pkg.path)}`;\n if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {\n // eslint-disable-next-line no-console\n console.log(`Update ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n } else if (forceAdd) {\n // eslint-disable-next-line no-console\n console.log(`Added ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n }\n }\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n};\n\nconst patchDistProjects = (paths: ProjectDistPath[], type: \"dependencies\" | \"devDependencies\" | \"peerDependencies\") => {\n for (const path of paths) {\n const absDistPath1 = getAbsPath(path.path);\n const absPackageJson = join(absDistPath1, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n for (const pkg of paths) {\n const absDistPath = `file:/${getAbsPath(pkg.path)}`;\n if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {\n // eslint-disable-next-line no-console\n console.log(` In ${path.package} => Update ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n }\n }\n const newPackageJson = { ...packageJson };\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n }\n};\n"]}
|
|
1
|
+
{"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,iDAAiD;AACjD,qDAAkE;AAClE,iDAA+C;AAC/C,+CAAyB;AACzB,+BAA4B;AAM5B,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,IAAa,EAAE,MAAgB,EAAE,EAAE;IAC1E,MAAM,WAAW,GAAG,IAAA,qBAAW,GAAE,CAAC;IAClC,OAAO,IAAA,wBAAQ,EACb,QAAQ,OAAO,CAAC,OAAO,CACrB,WAAW,CACZ,QAAQ,MAAM,wBAAwB,WAAW,6FAChD,IAAI,IAAI,EACV,EAAE,kBAEA,GAAG,EAAE,WAAW,IACb,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAExE,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,OAAe,EACf,WAAmB,EACnB,OAA4D;IAC1D,YAAY,EAAE,KAAK;CACpB;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAA,oBAAI,EACF,OAAO,EACP;YACE,GAAG,EAAE,IAAA,qBAAW,EAAC,WAAW,CAAC;YAC7B,GAA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CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC;aACxC;SACF;QACD,MAAM,cAAc,qBAAQ,WAAW,CAAE,CAAC;QAC1C,cAAc,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;QACnC,IAAA,sBAAa,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;KAC/C;AACH,CAAC,CAAC;AACF,MAAM,qBAAqB,GAAG,CAAC,UAAkB,EAAE,EAAE;IACnD,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,IAAA,qBAAY,EAAC,UAAU,CAAC,CAAC;IACxC,MAAM,CAAC,eAAe,GAAG;QACvB,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,MAAM;KAChB,CAAC;IACF,IAAA,sBAAa,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC,CAAC;AACF,MAAM,iBAAiB,GAAG,CAAC,UAAkB,EAAE,EAAE;IAC/C,MAAM,cAAc,GAAG,IAAA,WAAI,EAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACxD,MAAM,gBAAgB,GAAG,IAAA,qBAAY,EAAC,cAAc,CAAC,CAAC;IACtD,MAAM,sBAAsB,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;IACvF,MAAM,kBAAkB,GAAG,IAAA,qBAAY,EAAC,sBAAsB,CAAC,CAAC;IAChE,gBAAgB,CAAC,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC;IACtD,gBAAgB,CAAC,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC;IAClD,IAAA,sBAAa,EAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;AAClD,CAAC,CAAC","sourcesContent":["import { readJsonFile, writeJsonFile } from \"@nrwl/devkit\";\n// eslint-disable-next-line no-restricted-imports\nimport { fileExists, tmpProjPath } from \"@nrwl/nx-plugin/testing\";\nimport { exec, execSync } from \"child_process\";\nimport * as fs from \"fs\";\nimport { join } from \"path\";\nexport interface ProjectDistPath {\n package: string;\n path: string;\n}\n\nconst runNxNewCommand = (nxRoot: string, args?: string, silent?: boolean) => {\n const localTmpDir = tmpProjPath();\n return execSync(\n `node ${require.resolve(\n \"@nrwl/tao\"\n )} new ${nxRoot} --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=ts ${\n args || \"\"\n }`,\n {\n cwd: localTmpDir,\n ...(silent && false ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n }\n );\n};\n\n/**\n * Run a command asynchronously inside the e2e directory.\n *\n * @param command command to run\n * @param projectName the name of the project in e2e directory\n * @param opts options\n */\nexport function runCommandAsync(\n command: string,\n projectName: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n exec(\n command,\n {\n cwd: tmpProjPath(projectName),\n env: { ...process.env, ...opts.env },\n },\n (err, stdout, stderr) => {\n if (command.includes(\"--verbose\") || stderr?.length > 0) {\n // eslint-disable-next-line no-console\n console.log(`Stdout for cmd: ${command}:\\n`, stdout);\n // eslint-disable-next-line no-console\n console.log(`Stderr for cmd: ${command}:\\n`, stderr);\n }\n if (!opts.silenceError && err) {\n reject(err);\n }\n resolve({ stdout, stderr });\n }\n );\n });\n}\n\n/**\n * Run a nx command asynchronously inside the e2e directory\n *\n * @param command command to run\n * @param projectName the name of the project in e2e directory\n * @param opts options\n */\nexport function runNxCommandAsync(\n command: string,\n projectName: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n if (fileExists(tmpProjPath(join(projectName, \"package.json\")))) {\n return runCommandAsync(`yarn nx ${command}`, projectName, opts);\n } else if (process.platform === \"win32\") {\n return runCommandAsync(`./nx.bat ${command}`, projectName, opts);\n } else {\n return runCommandAsync(`./nx ${command}`, projectName, opts);\n }\n}\n\nconst newNxProject = async (\n nxRootDir: string,\n nxRootPath: string,\n dependencies: ProjectDistPath[],\n devDependencies: ProjectDistPath[],\n packageManager: string\n) => {\n runNxNewCommand(nxRootDir, `--package-manager=${packageManager}`, true);\n updateWorkspaceLayout(nxRootPath);\n patchDistProjects(dependencies, \"dependencies\");\n patchDistProjects(devDependencies, \"devDependencies\");\n\n patchDistProjects(dependencies, \"peerDependencies\");\n patchDistProjects(devDependencies, \"peerDependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"dependencies\", true);\n\n patchMainPackageJson(nxRootPath, devDependencies, \"devDependencies\", true);\n\n patchMainPackageJson(nxRootPath, dependencies, \"dependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"devDependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"peerDependencies\");\n\n patchMainPackageJson(nxRootPath, devDependencies, \"dependencies\");\n patchMainPackageJson(nxRootPath, devDependencies, \"devDependencies\");\n patchMainPackageJson(nxRootPath, devDependencies, \"peerDependencies\");\n\n updatePackageJson(nxRootPath);\n\n await runCommandAsync(\"yarn\", nxRootDir);\n};\n\nfunction getAbsPath(distPath: string) {\n return join(process.cwd(), distPath);\n}\n\n/**\n * Ensure nx projects are in package.json in tmp nxRootDir\n */\nexport const ensureNxProjects = async (\n dependencies: ProjectDistPath[],\n devDependencies: ProjectDistPath[],\n nxRootDir: string,\n packageManager = \"yarn\"\n) => {\n const nxRootPath = tmpProjPath(nxRootDir);\n if (fs.existsSync(nxRootPath)) {\n fs.rmSync(nxRootPath, { recursive: true });\n }\n fs.mkdirSync(nxRootPath, { recursive: true });\n // eslint-disable-next-line no-console\n console.log(\"Using NX root dir:\", nxRootPath);\n await newNxProject(nxRootDir, nxRootPath, dependencies, devDependencies, packageManager);\n};\n\n/**\n *\n * @param paths paths\n * @param type type\n * @param forceAdd force it\n */\nconst patchMainPackageJson = (\n testDir: string,\n paths: ProjectDistPath[],\n type: \"dependencies\" | \"devDependencies\" | \"peerDependencies\",\n forceAdd = false\n) => {\n const absPackageJson = join(testDir, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n const newPackageJson = { ...packageJson };\n\n for (const pkg of paths) {\n const absDistPath = `file:/${getAbsPath(pkg.path)}`;\n if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {\n // eslint-disable-next-line no-console\n console.log(`Update ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n } else if (forceAdd) {\n // eslint-disable-next-line no-console\n console.log(`Added ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n }\n }\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n};\n\nconst patchDistProjects = (paths: ProjectDistPath[], type: \"dependencies\" | \"devDependencies\" | \"peerDependencies\") => {\n for (const path of paths) {\n const absDistPath1 = getAbsPath(path.path);\n const absPackageJson = join(absDistPath1, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n for (const pkg of paths) {\n const absDistPath = `file:/${getAbsPath(pkg.path)}`;\n if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {\n // eslint-disable-next-line no-console\n console.log(` In ${path.package} => Update ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n }\n }\n const newPackageJson = { ...packageJson };\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n }\n};\nconst updateWorkspaceLayout = (nxRootPath: string) => {\n const nxJsonPath = join(nxRootPath, \"nx.json\");\n const nxJson = readJsonFile(nxJsonPath);\n nxJson.workspaceLayout = {\n appsDir: \"apps\",\n libsDir: \"libs\",\n };\n writeJsonFile(nxJsonPath, nxJson);\n};\nconst updatePackageJson = (nxRootPath: string) => {\n const absPackageJson = join(nxRootPath, \"package.json\");\n const newNxPackageJson = readJsonFile(absPackageJson);\n const managerPackageJsonPath = join(__dirname, \"..\", \"..\", \"..\", \"..\", \"package.json\");\n const managerPackageJson = readJsonFile(managerPackageJsonPath);\n newNxPackageJson.engines = managerPackageJson.engines;\n newNxPackageJson.volta = managerPackageJson.volta;\n writeJsonFile(absPackageJson, newNxPackageJson);\n};\n"]}
|