@nx/workspace 16.6.0 → 16.7.0-beta.1
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/generators.json +10 -0
- package/package.json +29 -29
- package/src/generators/convert-to-monorepo/convert-to-monorepo.d.ts +4 -0
- package/src/generators/convert-to-monorepo/convert-to-monorepo.js +41 -0
- package/src/generators/convert-to-monorepo/schema.json +16 -0
- package/src/generators/move/lib/create-project-configuration-in-new-destination.js +33 -2
- package/src/generators/move/lib/extract-base-configs.d.ts +4 -0
- package/src/generators/move/lib/extract-base-configs.js +52 -0
- package/src/generators/move/lib/move-project-files.js +39 -1
- package/src/generators/move/lib/update-cypress-config.js +3 -1
- package/src/generators/move/lib/update-eslintrc-json.js +1 -1
- package/src/generators/move/lib/update-project-root-files.d.ts +2 -0
- package/src/generators/move/lib/update-project-root-files.js +47 -3
- package/src/generators/move/move.js +9 -1
package/generators.json
CHANGED
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"aliases": ["rm"],
|
|
15
15
|
"description": "Remove an application or library."
|
|
16
16
|
},
|
|
17
|
+
"convert-to-monorepo": {
|
|
18
|
+
"factory": "./src/generators/convert-to-monorepo/convert-to-monorepo#monorepoSchematic",
|
|
19
|
+
"schema": "./src/generators/convert-to-monorepo/schema.json",
|
|
20
|
+
"description": "Convert a Nx project to a monorepo."
|
|
21
|
+
},
|
|
17
22
|
"workspace-generator": {
|
|
18
23
|
"factory": "./src/generators/workspace-generator/workspace-generator",
|
|
19
24
|
"schema": "./src/generators/workspace-generator/schema.json",
|
|
@@ -53,6 +58,11 @@
|
|
|
53
58
|
"aliases": ["rm"],
|
|
54
59
|
"description": "Remove an application or library."
|
|
55
60
|
},
|
|
61
|
+
"convert-to-monorepo": {
|
|
62
|
+
"factory": "./src/generators/convert-to-monorepo/convert-to-monorepo",
|
|
63
|
+
"schema": "./src/generators/convert-to-monorepo/schema.json",
|
|
64
|
+
"description": "Convert a Nx project to a monorepo."
|
|
65
|
+
},
|
|
56
66
|
"new": {
|
|
57
67
|
"factory": "./src/generators/new/new#newGenerator",
|
|
58
68
|
"schema": "./src/generators/new/schema.json",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/workspace",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.7.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.",
|
|
6
6
|
"repository": {
|
|
@@ -33,39 +33,39 @@
|
|
|
33
33
|
"requirements": {},
|
|
34
34
|
"migrations": "./migrations.json",
|
|
35
35
|
"packageGroup": {
|
|
36
|
-
"@nrwl/js": "16.
|
|
37
|
-
"@nrwl/jest": "16.
|
|
38
|
-
"@nrwl/linter": "16.
|
|
39
|
-
"@nrwl/angular": "16.
|
|
40
|
-
"@nrwl/cypress": "16.
|
|
41
|
-
"@nrwl/detox": "16.
|
|
42
|
-
"@nrwl/devkit": "16.
|
|
43
|
-
"@nrwl/esbuild": "16.
|
|
44
|
-
"@nrwl/eslint-plugin-nx": "16.
|
|
45
|
-
"@nrwl/expo": "16.
|
|
46
|
-
"@nrwl/express": "16.
|
|
47
|
-
"@nrwl/nest": "16.
|
|
48
|
-
"@nrwl/next": "16.
|
|
49
|
-
"@nrwl/node": "16.
|
|
36
|
+
"@nrwl/js": "16.7.0-beta.1",
|
|
37
|
+
"@nrwl/jest": "16.7.0-beta.1",
|
|
38
|
+
"@nrwl/linter": "16.7.0-beta.1",
|
|
39
|
+
"@nrwl/angular": "16.7.0-beta.1",
|
|
40
|
+
"@nrwl/cypress": "16.7.0-beta.1",
|
|
41
|
+
"@nrwl/detox": "16.7.0-beta.1",
|
|
42
|
+
"@nrwl/devkit": "16.7.0-beta.1",
|
|
43
|
+
"@nrwl/esbuild": "16.7.0-beta.1",
|
|
44
|
+
"@nrwl/eslint-plugin-nx": "16.7.0-beta.1",
|
|
45
|
+
"@nrwl/expo": "16.7.0-beta.1",
|
|
46
|
+
"@nrwl/express": "16.7.0-beta.1",
|
|
47
|
+
"@nrwl/nest": "16.7.0-beta.1",
|
|
48
|
+
"@nrwl/next": "16.7.0-beta.1",
|
|
49
|
+
"@nrwl/node": "16.7.0-beta.1",
|
|
50
50
|
"nx-cloud": "latest",
|
|
51
|
-
"@nrwl/nx-plugin": "16.
|
|
52
|
-
"@nrwl/react-native": "16.
|
|
53
|
-
"@nrwl/react": "16.
|
|
54
|
-
"@nrwl/rollup": "16.
|
|
55
|
-
"@nrwl/storybook": "16.
|
|
56
|
-
"@nrwl/tao": "16.
|
|
57
|
-
"@nrwl/vite": "16.
|
|
58
|
-
"@nrwl/web": "16.
|
|
59
|
-
"@nrwl/webpack": "16.
|
|
60
|
-
"nx": "16.
|
|
51
|
+
"@nrwl/nx-plugin": "16.7.0-beta.1",
|
|
52
|
+
"@nrwl/react-native": "16.7.0-beta.1",
|
|
53
|
+
"@nrwl/react": "16.7.0-beta.1",
|
|
54
|
+
"@nrwl/rollup": "16.7.0-beta.1",
|
|
55
|
+
"@nrwl/storybook": "16.7.0-beta.1",
|
|
56
|
+
"@nrwl/tao": "16.7.0-beta.1",
|
|
57
|
+
"@nrwl/vite": "16.7.0-beta.1",
|
|
58
|
+
"@nrwl/web": "16.7.0-beta.1",
|
|
59
|
+
"@nrwl/webpack": "16.7.0-beta.1",
|
|
60
|
+
"nx": "16.7.0-beta.1"
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@nrwl/workspace": "16.
|
|
65
|
-
"@nx/devkit": "16.
|
|
64
|
+
"@nrwl/workspace": "16.7.0-beta.1",
|
|
65
|
+
"@nx/devkit": "16.7.0-beta.1",
|
|
66
66
|
"chalk": "^4.1.0",
|
|
67
67
|
"ignore": "^5.0.4",
|
|
68
|
-
"nx": "16.
|
|
68
|
+
"nx": "16.7.0-beta.1",
|
|
69
69
|
"rxjs": "^7.8.0",
|
|
70
70
|
"tslib": "^2.3.0",
|
|
71
71
|
"yargs-parser": "21.1.1"
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"access": "public"
|
|
75
75
|
},
|
|
76
76
|
"types": "./index.d.ts",
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "50a145bb64edcf76985184a9a83d1449dcd4f3d9"
|
|
78
78
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.monorepoSchematic = exports.monorepoGenerator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const move_1 = require("../move/move");
|
|
7
|
+
function monorepoGenerator(tree, options) {
|
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
10
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
11
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
12
|
+
let rootProject;
|
|
13
|
+
const projectsToMove = [];
|
|
14
|
+
// Need to determine libs vs packages directory base on the type of root project.
|
|
15
|
+
for (const [, project] of projects) {
|
|
16
|
+
if (project.root === '.')
|
|
17
|
+
rootProject = project;
|
|
18
|
+
projectsToMove.push(project);
|
|
19
|
+
}
|
|
20
|
+
// Currently, Nx only handles apps+libs or packages. You cannot mix and match them.
|
|
21
|
+
// If the standalone project is an app (React, Angular, etc), then use apps+libs.
|
|
22
|
+
// Otherwise, for TS standalone (lib), use packages.
|
|
23
|
+
const isRootProjectApp = rootProject.projectType === 'application';
|
|
24
|
+
const appsDir = isRootProjectApp ? 'apps' : 'packages';
|
|
25
|
+
const libsDir = isRootProjectApp ? 'libs' : 'packages';
|
|
26
|
+
for (const project of projectsToMove) {
|
|
27
|
+
yield (0, move_1.moveGenerator)(tree, {
|
|
28
|
+
projectName: project.name,
|
|
29
|
+
newProjectName: project.name,
|
|
30
|
+
destination: project.projectType === 'application'
|
|
31
|
+
? (0, devkit_1.joinPathFragments)(appsDir, project.name)
|
|
32
|
+
: (0, devkit_1.joinPathFragments)(libsDir, project.name),
|
|
33
|
+
destinationRelativeToRoot: true,
|
|
34
|
+
updateImportPath: project.projectType === 'library',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.monorepoGenerator = monorepoGenerator;
|
|
40
|
+
exports.default = monorepoGenerator;
|
|
41
|
+
exports.monorepoSchematic = (0, devkit_1.convertNxGenerator)(monorepoGenerator);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "NxWorkspaceConvertToMonorepo",
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Nx Convert to Monorepo",
|
|
6
|
+
"description": "Convert an Nx project to a monorepo.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"command": "nx g @nx/workspace:monorepo",
|
|
11
|
+
"description": "Convert an Nx standalone project to a monorepo."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"properties": {},
|
|
15
|
+
"required": []
|
|
16
|
+
}
|
|
@@ -4,13 +4,44 @@ exports.createProjectConfigurationInNewDestination = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
function createProjectConfigurationInNewDestination(tree, schema, projectConfig) {
|
|
7
|
+
var _a;
|
|
7
8
|
projectConfig.name = schema.newProjectName;
|
|
9
|
+
const isRootProject = projectConfig.root === '.';
|
|
8
10
|
// Subtle bug if project name === path, where the updated name was being overrideen.
|
|
9
11
|
const { name } = projectConfig, rest = tslib_1.__rest(projectConfig, ["name"]);
|
|
10
12
|
// replace old root path with new one
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
let newProjectString = JSON.stringify(rest);
|
|
14
|
+
if (isRootProject) {
|
|
15
|
+
// Don't replace . with new root since it'll match all characters.
|
|
16
|
+
// Only look for "./" and replace with new root.
|
|
17
|
+
newProjectString = newProjectString.replace(/\.\//g, schema.relativeToRootDestination + '/');
|
|
18
|
+
newProjectString = newProjectString.replace(/"((tsconfig|jest|webpack|vite)\..*?\.(ts|js|json))"/g, `"${schema.relativeToRootDestination}/$1"`);
|
|
19
|
+
newProjectString = newProjectString.replace(/"(\.\/)?src\/(.*?)"/g, `"${schema.relativeToRootDestination}/src/$2"`);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
newProjectString = newProjectString.replace(new RegExp(projectConfig.root, 'g'), schema.relativeToRootDestination);
|
|
23
|
+
}
|
|
13
24
|
const newProject = Object.assign({ name }, JSON.parse(newProjectString));
|
|
25
|
+
newProject.root = schema.relativeToRootDestination;
|
|
26
|
+
// Correct "e2e" target and config since part of the rename will be wrong unless we make the project name "e2e" more unique.
|
|
27
|
+
// e.g. my-app-e2e is safer to search and replace than "e2e".
|
|
28
|
+
if (projectConfig.name === 'e2e') {
|
|
29
|
+
for (const [targetName, targetConfig] of Object.entries(newProject.targets)) {
|
|
30
|
+
const wrongName = schema.relativeToRootDestination;
|
|
31
|
+
if (targetName !== wrongName)
|
|
32
|
+
continue;
|
|
33
|
+
if (((_a = targetConfig.options) === null || _a === void 0 ? void 0 : _a.testingType) === wrongName) {
|
|
34
|
+
targetConfig.options.testingType = 'e2e';
|
|
35
|
+
}
|
|
36
|
+
newProject.targets['e2e'] = targetConfig;
|
|
37
|
+
delete newProject.targets[targetName];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Original sourceRoot is typically 'src' or 'app', but it could be any folder.
|
|
41
|
+
// Make sure it is updated to be under the new destination.
|
|
42
|
+
if (isRootProject && projectConfig.sourceRoot) {
|
|
43
|
+
newProject.sourceRoot = (0, devkit_1.joinPathFragments)(schema.relativeToRootDestination, projectConfig.sourceRoot);
|
|
44
|
+
}
|
|
14
45
|
// Create a new project with the root replaced
|
|
15
46
|
(0, devkit_1.addProjectConfiguration)(tree, schema.newProjectName, newProject);
|
|
16
47
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ProjectConfiguration, Tree } from '@nx/devkit';
|
|
2
|
+
export declare function maybeExtractTsConfigBase(tree: Tree): void;
|
|
3
|
+
export declare function maybeExtractJestConfigBase(tree: Tree): Promise<void>;
|
|
4
|
+
export declare function maybeExtractEslintConfigIfRootProject(tree: Tree, rootProject: ProjectConfiguration): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maybeExtractEslintConfigIfRootProject = exports.maybeExtractJestConfigBase = exports.maybeExtractTsConfigBase = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
function maybeExtractTsConfigBase(tree) {
|
|
7
|
+
let extractTsConfigBase;
|
|
8
|
+
try {
|
|
9
|
+
extractTsConfigBase = require('@nx/' + 'js').extractTsConfigBase;
|
|
10
|
+
}
|
|
11
|
+
catch (_a) {
|
|
12
|
+
// Not installed, skip
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
extractTsConfigBase(tree);
|
|
16
|
+
}
|
|
17
|
+
exports.maybeExtractTsConfigBase = maybeExtractTsConfigBase;
|
|
18
|
+
function maybeExtractJestConfigBase(tree) {
|
|
19
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
let jestInitGenerator;
|
|
21
|
+
try {
|
|
22
|
+
jestInitGenerator = require('@nx/' + 'jest').jestInitGenerator;
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
// Not installed, skip
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
yield jestInitGenerator(tree, {});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.maybeExtractJestConfigBase = maybeExtractJestConfigBase;
|
|
32
|
+
function maybeExtractEslintConfigIfRootProject(tree, rootProject) {
|
|
33
|
+
if (rootProject.root !== '.')
|
|
34
|
+
return;
|
|
35
|
+
if (tree.exists('.eslintrc.base.json'))
|
|
36
|
+
return;
|
|
37
|
+
let migrateConfigToMonorepoStyle;
|
|
38
|
+
try {
|
|
39
|
+
migrateConfigToMonorepoStyle = require('@nx/' +
|
|
40
|
+
'linter/src/generators/init/init-migration').migrateConfigToMonorepoStyle;
|
|
41
|
+
}
|
|
42
|
+
catch (_a) {
|
|
43
|
+
// linter not install
|
|
44
|
+
}
|
|
45
|
+
// Only need to handle migrating the root rootProject.
|
|
46
|
+
// If other libs/apps exist, then this migration is already done by `@nx/linter:lint-rootProject` generator.
|
|
47
|
+
migrateConfigToMonorepoStyle === null || migrateConfigToMonorepoStyle === void 0 ? void 0 : migrateConfigToMonorepoStyle([rootProject.name], tree, tree.exists((0, devkit_1.joinPathFragments)(rootProject.root, 'jest.config.ts')) ||
|
|
48
|
+
tree.exists((0, devkit_1.joinPathFragments)(rootProject.root, 'jest.config.js'))
|
|
49
|
+
? 'jest'
|
|
50
|
+
: 'none');
|
|
51
|
+
}
|
|
52
|
+
exports.maybeExtractEslintConfigIfRootProject = maybeExtractEslintConfigIfRootProject;
|
|
@@ -9,11 +9,49 @@ const path_1 = require("path");
|
|
|
9
9
|
* @param schema The options provided to the schematic
|
|
10
10
|
*/
|
|
11
11
|
function moveProjectFiles(tree, schema, project) {
|
|
12
|
+
// We don't want to move configuration files and other folders that we don't know about.
|
|
13
|
+
// Moving the wrong files is worse than not moving them, because there might be
|
|
14
|
+
// a lot of work to undo it.
|
|
15
|
+
const knownRootProjectFiles = [
|
|
16
|
+
// Config files
|
|
17
|
+
'project.json',
|
|
18
|
+
'tsconfig.json',
|
|
19
|
+
'tsconfig.app.json',
|
|
20
|
+
'tsconfig.lib.json',
|
|
21
|
+
'tsconfig.spec.json',
|
|
22
|
+
'.babelrc',
|
|
23
|
+
'.eslintrc.json',
|
|
24
|
+
/^jest\.config\.(app|lib)\.[jt]s$/,
|
|
25
|
+
'vite.config.ts',
|
|
26
|
+
/^webpack.*\.js$/,
|
|
27
|
+
'index.html', // Vite
|
|
28
|
+
];
|
|
29
|
+
const knownRootProjectFolders = [
|
|
30
|
+
'src',
|
|
31
|
+
'app',
|
|
32
|
+
'pages',
|
|
33
|
+
'public', // Vite, Remix, Next.js
|
|
34
|
+
];
|
|
35
|
+
const isKnownRootProjectFile = (file) => {
|
|
36
|
+
const baseDir = (0, path_1.dirname)(file).split(path_1.sep)[0];
|
|
37
|
+
if (baseDir === '.') {
|
|
38
|
+
// Not nested, check file matches
|
|
39
|
+
return knownRootProjectFiles.some((stringOrRegex) => typeof stringOrRegex === 'string'
|
|
40
|
+
? file === stringOrRegex
|
|
41
|
+
: stringOrRegex.test(file));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// Nested, check base dir matches
|
|
45
|
+
return knownRootProjectFolders.includes(baseDir);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
12
48
|
(0, devkit_1.visitNotIgnoredFiles)(tree, project.root, (file) => {
|
|
49
|
+
if (project.root === '.' && !isKnownRootProjectFile(file))
|
|
50
|
+
return;
|
|
13
51
|
// This is a rename but Angular Devkit isn't capable of writing to a file after it's renamed so this is a workaround
|
|
14
|
-
const content = tree.read(file);
|
|
15
52
|
const relativeFromOriginalSource = (0, path_1.relative)(project.root, file);
|
|
16
53
|
const newFilePath = (0, path_1.join)(schema.relativeToRootDestination, relativeFromOriginalSource);
|
|
54
|
+
const content = tree.read(file);
|
|
17
55
|
tree.write(newFilePath, content);
|
|
18
56
|
tree.delete(file);
|
|
19
57
|
});
|
|
@@ -25,7 +25,9 @@ function updateCypressConfig(tree, schema, project) {
|
|
|
25
25
|
return tree;
|
|
26
26
|
}
|
|
27
27
|
const cypressConfigPath = path.join(schema.relativeToRootDestination, 'cypress.config.ts');
|
|
28
|
-
|
|
28
|
+
// Search and replace for "e2e" directory is not safe, and will result in an invalid config file.
|
|
29
|
+
// Leave it and let users fix the config if needed.
|
|
30
|
+
if (project.root !== 'e2e' && tree.exists(cypressConfigPath)) {
|
|
29
31
|
const oldContent = tree.read(cypressConfigPath, 'utf-8');
|
|
30
32
|
const findName = new RegExp(`'${schema.projectName}'`, 'g');
|
|
31
33
|
const findDir = new RegExp(project.root, 'g');
|
|
@@ -28,7 +28,7 @@ function updateEslintrcJson(tree, schema, project) {
|
|
|
28
28
|
if (typeof eslintRcJson.extends === 'string') {
|
|
29
29
|
eslintRcJson.extends = offsetFilePath(project, eslintRcJson.extends, offset);
|
|
30
30
|
}
|
|
31
|
-
else {
|
|
31
|
+
else if (eslintRcJson.extends) {
|
|
32
32
|
eslintRcJson.extends = eslintRcJson.extends.map((extend) => offsetFilePath(project, extend, offset));
|
|
33
33
|
}
|
|
34
34
|
(_a = eslintRcJson.overrides) === null || _a === void 0 ? void 0 : _a.forEach((o) => {
|
|
@@ -8,3 +8,5 @@ import { NormalizedSchema } from '../schema';
|
|
|
8
8
|
* @param schema The options provided to the schematic
|
|
9
9
|
*/
|
|
10
10
|
export declare function updateProjectRootFiles(tree: Tree, schema: NormalizedSchema, project: ProjectConfiguration): void;
|
|
11
|
+
export declare function updateFilesForRootProjects(tree: Tree, schema: NormalizedSchema, project: ProjectConfiguration): void;
|
|
12
|
+
export declare function updateFilesForNonRootProjects(tree: Tree, schema: NormalizedSchema, project: ProjectConfiguration): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateProjectRootFiles = void 0;
|
|
3
|
+
exports.updateFilesForNonRootProjects = exports.updateFilesForRootProjects = exports.updateProjectRootFiles = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -13,6 +13,47 @@ const allowedExt = ['.ts', '.js', '.json'];
|
|
|
13
13
|
* @param schema The options provided to the schematic
|
|
14
14
|
*/
|
|
15
15
|
function updateProjectRootFiles(tree, schema, project) {
|
|
16
|
+
if (project.root === '.') {
|
|
17
|
+
// Need to handle root project differently since replacing '.' with 'dir',
|
|
18
|
+
// for example, // will change '../../' to 'dirdir/dirdir/'.
|
|
19
|
+
updateFilesForRootProjects(tree, schema, project);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
updateFilesForNonRootProjects(tree, schema, project);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.updateProjectRootFiles = updateProjectRootFiles;
|
|
26
|
+
function updateFilesForRootProjects(tree, schema, project) {
|
|
27
|
+
// Skip updating "path" and "extends" for tsconfig files since they are mostly
|
|
28
|
+
// relative to the project root. The only exception is tsconfig.json that
|
|
29
|
+
// should extend from ../../tsconfig.base.json. We'll handle this separately.
|
|
30
|
+
const regex = /(?<!"path".+)(?<!"extends".+)(?<=['"])\.\/(?=[a-zA-Z0-9])/g;
|
|
31
|
+
const newRelativeRoot =
|
|
32
|
+
// Normalize separators
|
|
33
|
+
path
|
|
34
|
+
.relative(path.join(devkit_1.workspaceRoot, schema.relativeToRootDestination), devkit_1.workspaceRoot)
|
|
35
|
+
.split(path.sep)
|
|
36
|
+
// Include trailing slash because the regex matches the trailing slash in "./"
|
|
37
|
+
.join('/') + '/';
|
|
38
|
+
for (const file of tree.children(schema.relativeToRootDestination)) {
|
|
39
|
+
const ext = (0, path_1.extname)(file);
|
|
40
|
+
if (!allowedExt.includes(ext)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (file === '.eslintrc.json') {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const oldContent = tree.read((0, path_1.join)(schema.relativeToRootDestination, file), 'utf-8');
|
|
47
|
+
let newContent = oldContent.replace(regex, newRelativeRoot);
|
|
48
|
+
if (file === 'tsconfig.json') {
|
|
49
|
+
// Since we skipped updating "extends" earlier, need to point to the base config.
|
|
50
|
+
newContent = newContent.replace(`./tsconfig.base.json`, newRelativeRoot + `tsconfig.base.json`);
|
|
51
|
+
}
|
|
52
|
+
tree.write((0, path_1.join)(schema.relativeToRootDestination, file), newContent);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.updateFilesForRootProjects = updateFilesForRootProjects;
|
|
56
|
+
function updateFilesForNonRootProjects(tree, schema, project) {
|
|
16
57
|
const newRelativeRoot = path
|
|
17
58
|
.relative(path.join(devkit_1.workspaceRoot, schema.relativeToRootDestination), devkit_1.workspaceRoot)
|
|
18
59
|
.split(path.sep)
|
|
@@ -36,8 +77,11 @@ function updateProjectRootFiles(tree, schema, project) {
|
|
|
36
77
|
continue;
|
|
37
78
|
}
|
|
38
79
|
const oldContent = tree.read((0, path_1.join)(schema.relativeToRootDestination, file), 'utf-8');
|
|
39
|
-
|
|
80
|
+
let newContent = oldContent.replace(regex, newRelativeRoot);
|
|
81
|
+
if (file == 'tsconfig.json') {
|
|
82
|
+
newContent = newContent.replace('tsconfig.json', 'tsconfig.base.json');
|
|
83
|
+
}
|
|
40
84
|
tree.write((0, path_1.join)(schema.relativeToRootDestination, file), newContent);
|
|
41
85
|
}
|
|
42
86
|
}
|
|
43
|
-
exports.
|
|
87
|
+
exports.updateFilesForNonRootProjects = updateFilesForNonRootProjects;
|
|
@@ -18,11 +18,19 @@ const update_package_json_1 = require("./lib/update-package-json");
|
|
|
18
18
|
const update_project_root_files_1 = require("./lib/update-project-root-files");
|
|
19
19
|
const update_readme_1 = require("./lib/update-readme");
|
|
20
20
|
const update_storybook_config_1 = require("./lib/update-storybook-config");
|
|
21
|
+
const extract_base_configs_1 = require("./lib/extract-base-configs");
|
|
21
22
|
function moveGenerator(tree, rawSchema) {
|
|
22
23
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
|
|
24
|
+
let projectConfig = (0, devkit_1.readProjectConfiguration)(tree, rawSchema.projectName);
|
|
24
25
|
(0, check_destination_1.checkDestination)(tree, rawSchema, projectConfig);
|
|
25
26
|
const schema = (0, normalize_schema_1.normalizeSchema)(tree, rawSchema, projectConfig);
|
|
27
|
+
if (projectConfig.root === '.') {
|
|
28
|
+
(0, extract_base_configs_1.maybeExtractTsConfigBase)(tree);
|
|
29
|
+
yield (0, extract_base_configs_1.maybeExtractJestConfigBase)(tree);
|
|
30
|
+
(0, extract_base_configs_1.maybeExtractEslintConfigIfRootProject)(tree, projectConfig);
|
|
31
|
+
// Reload config since it has been updated after extracting base configs
|
|
32
|
+
projectConfig = (0, devkit_1.readProjectConfiguration)(tree, rawSchema.projectName);
|
|
33
|
+
}
|
|
26
34
|
(0, devkit_1.removeProjectConfiguration)(tree, schema.projectName);
|
|
27
35
|
(0, move_project_files_1.moveProjectFiles)(tree, schema, projectConfig);
|
|
28
36
|
(0, create_project_configuration_in_new_destination_1.createProjectConfigurationInNewDestination)(tree, schema, projectConfig);
|