@unisphere/nx 2.2.1 → 3.2.3
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/dist/generators/add-application/add-application.d.ts.map +1 -1
- package/dist/generators/add-application/add-application.js +77 -55
- package/dist/generators/add-application/schema.d.ts +3 -1
- package/dist/generators/add-application/schema.json +4 -8
- package/dist/generators/add-application/templates/default/.env-template +6 -0
- package/dist/generators/add-application/templates/default/.eslintrc.json +1 -1
- package/dist/generators/add-application/templates/default/jest.config.ts +3 -3
- package/dist/generators/add-application/templates/default/project.json.template +2 -2
- package/dist/generators/add-application/templates/default/readme.md.template +11 -0
- package/dist/generators/add-application/templates/default/src/app/app.tsx.template +77 -77
- package/dist/generators/add-application/templates/default/tsconfig.json +1 -1
- package/dist/generators/add-application/templates/default/webpack.config.js.template +6 -1
- package/dist/generators/add-package/README.md +2 -2
- package/dist/generators/add-package/add-package.d.ts.map +1 -1
- package/dist/generators/add-package/add-package.js +11 -23
- package/dist/generators/add-package/schema.d.ts +1 -1
- package/dist/generators/add-package/schema.json +27 -19
- package/dist/generators/add-package/templates/new-package/.eslintrc.json +1 -1
- package/dist/generators/add-package/templates/new-package/package.json.template +0 -1
- package/dist/generators/add-package/templates/new-package/project.json.template +4 -4
- package/dist/generators/add-package/templates/new-package/rollup.config.js +1 -1
- package/dist/generators/add-package/templates/new-package/tsconfig.json +1 -1
- package/dist/generators/add-package/templates/new-package/tsconfig.lib.json.template +1 -1
- package/dist/generators/add-package/templates/new-package/tsconfig.spec.json +1 -1
- package/dist/generators/add-runtime/add-runtime.d.ts.map +1 -1
- package/dist/generators/add-runtime/add-runtime.js +62 -9
- package/dist/generators/add-runtime/schema.d.ts +1 -0
- package/dist/generators/add-runtime/schema.json +1 -9
- package/dist/generators/add-runtime/templates/new-runtime/src/lib/create-factory.tsx.template +4 -4
- package/dist/generators/add-runtime/templates/new-runtime/src/lib/runtime.tsx.template +26 -2
- package/dist/generators/add-visual/add-visual.d.ts +1 -1
- package/dist/generators/add-visual/add-visual.d.ts.map +1 -1
- package/dist/generators/add-visual/add-visual.js +108 -15
- package/dist/generators/add-visual/schema.d.ts +3 -3
- package/dist/generators/add-visual/schema.json +2 -24
- package/dist/generators/dependency-config.d.ts.map +1 -1
- package/dist/generators/dependency-config.js +1 -0
- package/dist/generators/internal-dev-runner/generator.d.ts +3 -0
- package/dist/generators/internal-dev-runner/generator.d.ts.map +1 -0
- package/dist/generators/internal-dev-runner/generator.js +45 -0
- package/dist/generators/internal-dev-runner/schema.json +9 -0
- package/dist/generators/remove/remove.d.ts +19 -0
- package/dist/generators/remove/remove.d.ts.map +1 -0
- package/dist/generators/remove/remove.js +270 -0
- package/dist/generators/remove/schema.d.ts +4 -0
- package/dist/generators/remove/schema.json +38 -0
- package/dist/generators/rename-package/rename-package.d.ts +3 -0
- package/dist/generators/rename-package/rename-package.d.ts.map +1 -1
- package/dist/generators/rename-package/rename-package.js +139 -20
- package/dist/generators/utils.d.ts +30 -1
- package/dist/generators/utils.d.ts.map +1 -1
- package/dist/generators/utils.js +258 -7
- package/dist/migrations/1-22-0/patches/@changesets+cli+2.29.7.patch +36 -4
- package/dist/migrations/1-22-2/templates/_publish-artifacts.template +5 -5
- package/dist/migrations/1-24-2/templates/_publish-artifacts.template +5 -5
- package/dist/migrations/2-1-0/replace-readme-md.d.ts.map +1 -1
- package/dist/migrations/2-1-0/replace-readme-md.js +2 -3
- package/dist/migrations/2-2-0/templates/_publish-artifacts.template +5 -5
- package/dist/migrations/3-0-0/add-define-plugin-to-webpack.d.ts +3 -0
- package/dist/migrations/3-0-0/add-define-plugin-to-webpack.d.ts.map +1 -0
- package/dist/migrations/3-0-0/add-define-plugin-to-webpack.js +233 -0
- package/dist/migrations/3-0-0/add-env-to-application-gitignore.d.ts +3 -0
- package/dist/migrations/3-0-0/add-env-to-application-gitignore.d.ts.map +1 -0
- package/dist/migrations/3-0-0/add-env-to-application-gitignore.js +117 -0
- package/dist/migrations/3-0-0/fix-vite-config-cache-paths.d.ts +10 -0
- package/dist/migrations/3-0-0/fix-vite-config-cache-paths.d.ts.map +1 -0
- package/dist/migrations/3-0-0/fix-vite-config-cache-paths.js +66 -0
- package/dist/migrations/3-0-0/patches/@changesets+cli+2.29.7.patch +88 -0
- package/dist/migrations/3-0-0/post-cleanup-empty-directories.d.ts +12 -0
- package/dist/migrations/3-0-0/post-cleanup-empty-directories.d.ts.map +1 -0
- package/dist/migrations/3-0-0/post-cleanup-empty-directories.js +62 -0
- package/dist/migrations/3-0-0/pre-cleanup-empty-directories.d.ts +14 -0
- package/dist/migrations/3-0-0/pre-cleanup-empty-directories.d.ts.map +1 -0
- package/dist/migrations/3-0-0/pre-cleanup-empty-directories.js +105 -0
- package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.d.ts +3 -0
- package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.d.ts.map +1 -0
- package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.js +21 -0
- package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.d.ts +9 -0
- package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.d.ts.map +1 -0
- package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.js +88 -0
- package/dist/migrations/3-0-0/remove-publish-config-from-packages.d.ts +9 -0
- package/dist/migrations/3-0-0/remove-publish-config-from-packages.d.ts.map +1 -0
- package/dist/migrations/3-0-0/remove-publish-config-from-packages.js +45 -0
- package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.d.ts +15 -0
- package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.d.ts.map +1 -0
- package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.js +563 -0
- package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.d.ts +23 -0
- package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.d.ts.map +1 -0
- package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.js +645 -0
- package/dist/migrations/3-0-0/replace-github-workflow.d.ts +3 -0
- package/dist/migrations/3-0-0/replace-github-workflow.d.ts.map +1 -0
- package/dist/migrations/3-0-0/replace-github-workflow.js +48 -0
- package/dist/migrations/3-0-0/sync-package-lock.d.ts +10 -0
- package/dist/migrations/3-0-0/sync-package-lock.d.ts.map +1 -0
- package/dist/migrations/3-0-0/sync-package-lock.js +26 -0
- package/dist/migrations/3-0-0/templates/_publish-artifacts.template +363 -0
- package/dist/migrations/3-0-0/templates/cicd.template +89 -0
- package/dist/migrations/3-0-0/update-changeset-patch.d.ts +3 -0
- package/dist/migrations/3-0-0/update-changeset-patch.d.ts.map +1 -0
- package/dist/migrations/3-0-0/update-changeset-patch.js +31 -0
- package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.d.ts +21 -0
- package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.d.ts.map +1 -0
- package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.js +105 -0
- package/dist/migrations/utils/has-react-dependency.d.ts +14 -0
- package/dist/migrations/utils/has-react-dependency.d.ts.map +1 -0
- package/dist/migrations/utils/has-react-dependency.js +72 -0
- package/dist/shared.d.ts +6 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +9 -0
- package/generators.json +12 -1
- package/migrations.json +117 -0
- package/package.json +3 -2
- package/dist/generators/add-application/templates/local-dev-playground/.babelrc +0 -11
- package/dist/generators/add-application/templates/local-dev-playground/.eslintrc.json +0 -22
- package/dist/generators/add-application/templates/local-dev-playground/jest.config.ts +0 -11
- package/dist/generators/add-application/templates/local-dev-playground/package.json +0 -6
- package/dist/generators/add-application/templates/local-dev-playground/project.json +0 -9
- package/dist/generators/add-application/templates/local-dev-playground/src/app/app.tsx.template +0 -212
- package/dist/generators/add-application/templates/local-dev-playground/src/app/components/header.tsx.template +0 -123
- package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings-buttons.tsx +0 -57
- package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings-form.tsx +0 -108
- package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings.tsx +0 -74
- package/dist/generators/add-application/templates/local-dev-playground/src/app/configuration-provider.tsx +0 -163
- package/dist/generators/add-application/templates/local-dev-playground/src/app/definitions.ts +0 -25
- package/dist/generators/add-application/templates/local-dev-playground/src/app/utils/merge-deep.ts +0 -31
- package/dist/generators/add-application/templates/local-dev-playground/src/favicon.ico +0 -0
- package/dist/generators/add-application/templates/local-dev-playground/src/index.html +0 -17
- package/dist/generators/add-application/templates/local-dev-playground/src/main.tsx +0 -13
- package/dist/generators/add-application/templates/local-dev-playground/src/styles.css +0 -0
- package/dist/generators/add-application/templates/local-dev-playground/tsconfig.app.json +0 -24
- package/dist/generators/add-application/templates/local-dev-playground/tsconfig.json +0 -20
- package/dist/generators/add-application/templates/local-dev-playground/tsconfig.spec.json +0 -25
- package/dist/generators/add-application/templates/local-dev-playground/webpack.config.js +0 -33
- /package/dist/generators/add-runtime/templates/{core-templates → types-templates}/__runtimeName__-runtime/index.ts.template +0 -0
- /package/dist/generators/add-runtime/templates/{core-templates → types-templates}/__runtimeName__-runtime/runtime-types.ts.template +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = testMigrationGenerator;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Import the migrations to test
|
|
6
|
+
// import addEnvToGitignore from '../../migrations/3-0-0/add-env-to-application-gitignore';
|
|
7
|
+
// import addDefinePluginToWebpack from '../../migrations/3-0-0/add-define-plugin-to-webpack';
|
|
8
|
+
// import upgradeCliToV2 from '../../migrations/3-0-0/upgrade-cli-to-v2';
|
|
9
|
+
// import preCleanupEmptyDirectories from '../../migrations/3-0-0/pre-cleanup-empty-directories';
|
|
10
|
+
// import reorganizePackagesByDistributionChannel from '../../migrations/3-0-0/reorganize-packages-by-distribution-channel';
|
|
11
|
+
// import reorganizeApplicationsByDistributionChannel from '../../migrations/3-0-0/reorganize-applications-by-distribution-channel';
|
|
12
|
+
// import upgradeSchemaTo2 from '../../migrations/3-0-0/upgrade-schema-to-2-0-0';
|
|
13
|
+
// import postCleanupEmptyDirectories from '../../migrations/3-0-0/post-cleanup-empty-directories';
|
|
14
|
+
const remove_private_from_applications_and_runtimes_1 = tslib_1.__importDefault(require("../../migrations/3-0-0/remove-private-from-applications-and-runtimes"));
|
|
15
|
+
async function testMigrationGenerator(tree) {
|
|
16
|
+
// Collect all callbacks to run after all migrations complete
|
|
17
|
+
// const callbacks: (() => void)[] = [];
|
|
18
|
+
// Upgrade CLI to v2 first (needed for other migrations)
|
|
19
|
+
// const upgradeCliCallback = await upgradeCliToV2(tree);
|
|
20
|
+
// if (upgradeCliCallback) {
|
|
21
|
+
// callbacks.push(upgradeCliCallback);
|
|
22
|
+
// }
|
|
23
|
+
// Pre-cleanup: Remove empty directories before reorganization
|
|
24
|
+
// await preCleanupEmptyDirectories(tree);
|
|
25
|
+
// Reorganize packages by distribution channel (also handles core->types rename and -react suffix)
|
|
26
|
+
// await reorganizePackagesByDistributionChannel(tree);
|
|
27
|
+
// // Reorganize applications by distribution channel
|
|
28
|
+
// await reorganizeApplicationsByDistributionChannel(tree);
|
|
29
|
+
// Upgrade schema to 2.0.0 and remove distributionChannel from packages
|
|
30
|
+
// await upgradeSchemaTo2(tree);
|
|
31
|
+
// Remove private field from applications, runtimes, and packages
|
|
32
|
+
await (0, remove_private_from_applications_and_runtimes_1.default)(tree);
|
|
33
|
+
// Post-cleanup: Remove empty directories after reorganization
|
|
34
|
+
// const postCleanupCallback = await postCleanupEmptyDirectories(tree);
|
|
35
|
+
// if (postCleanupCallback) {
|
|
36
|
+
// callbacks.push(postCleanupCallback);
|
|
37
|
+
// }
|
|
38
|
+
// Run all callbacks at the end
|
|
39
|
+
// Note: In Nx generators, Tree changes are written when the generator completes.
|
|
40
|
+
// These callbacks run after all migrations but before the generator finishes.
|
|
41
|
+
// For file system operations (like npm install), they should work correctly.
|
|
42
|
+
// for (const callback of callbacks) {
|
|
43
|
+
// callback();
|
|
44
|
+
// }
|
|
45
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove Generator
|
|
3
|
+
*
|
|
4
|
+
* This generator removes a Unisphere element (package, runtime, or application) by:
|
|
5
|
+
* 1. Validating the element exists in .unisphere configuration
|
|
6
|
+
* 2. Using Nx's built-in remove generator to delete the project
|
|
7
|
+
* 3. Performing Unisphere-specific cleanup:
|
|
8
|
+
* - Removing from .unisphere configuration
|
|
9
|
+
* - For runtimes: removing types from types/core package and updating index.ts exports
|
|
10
|
+
* - Updating tsconfig.base.json path mappings
|
|
11
|
+
* - Updating package-lock.json
|
|
12
|
+
*
|
|
13
|
+
* Usage: nx g @unisphere/nx:remove runtime:admin
|
|
14
|
+
*/
|
|
15
|
+
import { Tree } from '@nx/devkit';
|
|
16
|
+
import { RemoveGeneratorSchema } from './schema';
|
|
17
|
+
export declare function removeGenerator(tree: Tree, options: RemoveGeneratorSchema): Promise<void>;
|
|
18
|
+
export default removeGenerator;
|
|
19
|
+
//# sourceMappingURL=remove.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../../../src/generators/remove/remove.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,IAAI,EAKL,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAmQjD,wBAAsB,eAAe,CACnC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,qBAAqB,iBA6E/B;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Remove Generator
|
|
4
|
+
*
|
|
5
|
+
* This generator removes a Unisphere element (package, runtime, or application) by:
|
|
6
|
+
* 1. Validating the element exists in .unisphere configuration
|
|
7
|
+
* 2. Using Nx's built-in remove generator to delete the project
|
|
8
|
+
* 3. Performing Unisphere-specific cleanup:
|
|
9
|
+
* - Removing from .unisphere configuration
|
|
10
|
+
* - For runtimes: removing types from types/core package and updating index.ts exports
|
|
11
|
+
* - Updating tsconfig.base.json path mappings
|
|
12
|
+
* - Updating package-lock.json
|
|
13
|
+
*
|
|
14
|
+
* Usage: nx g @unisphere/nx:remove runtime:admin
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.removeGenerator = removeGenerator;
|
|
18
|
+
const devkit_1 = require("@nx/devkit");
|
|
19
|
+
const generators_1 = require("@nx/workspace/generators");
|
|
20
|
+
const utils_1 = require("../utils");
|
|
21
|
+
const VALID_ELEMENT_TYPES = ['package', 'runtime', 'application'];
|
|
22
|
+
/**
|
|
23
|
+
* Parse the element string in format "type:name"
|
|
24
|
+
*/
|
|
25
|
+
function parseElement(element) {
|
|
26
|
+
const parts = element.split(':');
|
|
27
|
+
if (parts.length !== 2) {
|
|
28
|
+
throw new Error(`Invalid element format: "${element}"\n` +
|
|
29
|
+
`Expected format: type:name (e.g., runtime:admin, package:shared, application:my-app)`);
|
|
30
|
+
}
|
|
31
|
+
const [type, name] = parts;
|
|
32
|
+
if (!VALID_ELEMENT_TYPES.includes(type)) {
|
|
33
|
+
throw new Error(`Invalid element type: "${type}"\n` +
|
|
34
|
+
`Valid types: ${VALID_ELEMENT_TYPES.join(', ')}`);
|
|
35
|
+
}
|
|
36
|
+
if (!name || name.trim() === '') {
|
|
37
|
+
throw new Error(`Element name is required.\n` +
|
|
38
|
+
`Expected format: type:name (e.g., runtime:admin)`);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
elementType: type,
|
|
42
|
+
name: name.trim(),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the configuration key for element type in .unisphere
|
|
47
|
+
*/
|
|
48
|
+
function getElementsConfigKey(elementType) {
|
|
49
|
+
const mapping = {
|
|
50
|
+
package: 'packages',
|
|
51
|
+
runtime: 'runtimes',
|
|
52
|
+
application: 'applications',
|
|
53
|
+
};
|
|
54
|
+
return mapping[elementType];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the Nx project name prefix for element type
|
|
58
|
+
*/
|
|
59
|
+
function getNxProjectPrefix(elementType) {
|
|
60
|
+
const mapping = {
|
|
61
|
+
package: 'unisphere-package',
|
|
62
|
+
runtime: 'unisphere-runtime',
|
|
63
|
+
application: 'unisphere-application',
|
|
64
|
+
};
|
|
65
|
+
return mapping[elementType];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Validates that the element exists in .unisphere configuration
|
|
69
|
+
*/
|
|
70
|
+
function validateElementExists(tree, elementType, elementName) {
|
|
71
|
+
const unisphereConfig = (0, devkit_1.readJson)(tree, '.unisphere');
|
|
72
|
+
const normalizedName = (0, devkit_1.names)(elementName).fileName;
|
|
73
|
+
const configKey = getElementsConfigKey(elementType);
|
|
74
|
+
const elementConfig = unisphereConfig.elements?.[configKey]?.[normalizedName];
|
|
75
|
+
if (!elementConfig) {
|
|
76
|
+
const availableElements = Object.keys(unisphereConfig.elements?.[configKey] || {});
|
|
77
|
+
throw new Error(`${elementType.charAt(0).toUpperCase() + elementType.slice(1)} "${normalizedName}" not found in .unisphere configuration.\n` +
|
|
78
|
+
`Available ${configKey}: ${availableElements.length > 0 ? availableElements.join(', ') : '(none)'}`);
|
|
79
|
+
}
|
|
80
|
+
if (!elementConfig.sourceRoot) {
|
|
81
|
+
throw new Error(`${elementType.charAt(0).toUpperCase() + elementType.slice(1)} "${normalizedName}" exists but has no sourceRoot configured in .unisphere`);
|
|
82
|
+
}
|
|
83
|
+
return elementConfig.sourceRoot;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Remove element from .unisphere configuration
|
|
87
|
+
*/
|
|
88
|
+
function removeFromUnisphereConfig(tree, elementType, elementName) {
|
|
89
|
+
const unisphereConfig = (0, devkit_1.readJson)(tree, '.unisphere');
|
|
90
|
+
const configKey = getElementsConfigKey(elementType);
|
|
91
|
+
const normalizedName = (0, devkit_1.names)(elementName).fileName;
|
|
92
|
+
if (unisphereConfig.elements?.[configKey]?.[normalizedName]) {
|
|
93
|
+
delete unisphereConfig.elements[configKey][normalizedName];
|
|
94
|
+
(0, devkit_1.writeJson)(tree, '.unisphere', unisphereConfig);
|
|
95
|
+
devkit_1.logger.info(`Removed "${normalizedName}" from .unisphere configuration`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Remove runtime types from types/core package
|
|
100
|
+
*/
|
|
101
|
+
function removeRuntimeTypes(tree, runtimeName) {
|
|
102
|
+
const typesPackageInfo = (0, utils_1.findTypesOrCorePackageInfo)(tree);
|
|
103
|
+
const normalizedName = (0, devkit_1.names)(runtimeName).fileName;
|
|
104
|
+
// Remove the runtime types directory
|
|
105
|
+
const runtimeTypesDir = `${typesPackageInfo.basePath}/src/lib/${normalizedName}-runtime`;
|
|
106
|
+
if (tree.exists(runtimeTypesDir)) {
|
|
107
|
+
// Delete all files in the directory
|
|
108
|
+
tree.children(runtimeTypesDir).forEach(child => {
|
|
109
|
+
tree.delete(`${runtimeTypesDir}/${child}`);
|
|
110
|
+
});
|
|
111
|
+
devkit_1.logger.info(`Removed runtime types directory: ${runtimeTypesDir}`);
|
|
112
|
+
}
|
|
113
|
+
// Update the index.ts to remove the export
|
|
114
|
+
const indexPath = `${typesPackageInfo.basePath}/src/index.ts`;
|
|
115
|
+
if (tree.exists(indexPath)) {
|
|
116
|
+
const content = tree.read(indexPath, 'utf-8');
|
|
117
|
+
if (content) {
|
|
118
|
+
const exportLine = `export * from './lib/${normalizedName}-runtime';`;
|
|
119
|
+
const exportLineWithNewline = `\n${exportLine}`;
|
|
120
|
+
let updatedContent = content;
|
|
121
|
+
// Remove the export line (handle both with and without leading newline)
|
|
122
|
+
if (content.includes(exportLineWithNewline)) {
|
|
123
|
+
updatedContent = content.replace(exportLineWithNewline, '');
|
|
124
|
+
}
|
|
125
|
+
else if (content.includes(exportLine)) {
|
|
126
|
+
updatedContent = content.replace(exportLine + '\n', '');
|
|
127
|
+
updatedContent = updatedContent.replace(exportLine, '');
|
|
128
|
+
}
|
|
129
|
+
if (updatedContent !== content) {
|
|
130
|
+
tree.write(indexPath, updatedContent);
|
|
131
|
+
devkit_1.logger.info(`Removed runtime export from ${indexPath}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Remove path mapping from tsconfig.base.json
|
|
138
|
+
*/
|
|
139
|
+
function removeTsConfigPath(tree, elementType, elementName) {
|
|
140
|
+
const tsconfigPath = 'tsconfig.base.json';
|
|
141
|
+
if (!tree.exists(tsconfigPath)) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const tsconfig = (0, devkit_1.readJson)(tree, tsconfigPath);
|
|
145
|
+
const normalizedName = (0, devkit_1.names)(elementName).fileName;
|
|
146
|
+
if (!tsconfig.compilerOptions?.paths) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// Determine the path key based on element type
|
|
150
|
+
let pathKeyPattern;
|
|
151
|
+
switch (elementType) {
|
|
152
|
+
case 'runtime':
|
|
153
|
+
pathKeyPattern = `unisphere-runtime-${normalizedName}`;
|
|
154
|
+
break;
|
|
155
|
+
case 'package':
|
|
156
|
+
// Packages may have various path patterns, we'll search for matching paths
|
|
157
|
+
pathKeyPattern = normalizedName;
|
|
158
|
+
break;
|
|
159
|
+
case 'application':
|
|
160
|
+
pathKeyPattern = `unisphere-application-${normalizedName}`;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
let removed = false;
|
|
164
|
+
const pathsToRemove = [];
|
|
165
|
+
// Find all matching paths
|
|
166
|
+
for (const [key, paths] of Object.entries(tsconfig.compilerOptions.paths)) {
|
|
167
|
+
if (Array.isArray(paths)) {
|
|
168
|
+
const matchesPath = paths.some((p) => p.includes(`/${normalizedName}/`) || p.includes(`/${normalizedName}-`));
|
|
169
|
+
if (key.includes(pathKeyPattern) || matchesPath) {
|
|
170
|
+
pathsToRemove.push(key);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// Remove the paths
|
|
175
|
+
for (const key of pathsToRemove) {
|
|
176
|
+
delete tsconfig.compilerOptions.paths[key];
|
|
177
|
+
removed = true;
|
|
178
|
+
}
|
|
179
|
+
if (removed) {
|
|
180
|
+
(0, devkit_1.writeJson)(tree, tsconfigPath, tsconfig);
|
|
181
|
+
devkit_1.logger.info(`Removed path mapping(s) from tsconfig.base.json`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Remove entry from package-lock.json
|
|
186
|
+
*/
|
|
187
|
+
function removeFromPackageLock(tree, sourceRoot) {
|
|
188
|
+
const packageLockPath = 'package-lock.json';
|
|
189
|
+
if (!tree.exists(packageLockPath)) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const packageLock = (0, devkit_1.readJson)(tree, packageLockPath);
|
|
193
|
+
let updated = false;
|
|
194
|
+
if (packageLock.packages) {
|
|
195
|
+
if (packageLock.packages[sourceRoot]) {
|
|
196
|
+
delete packageLock.packages[sourceRoot];
|
|
197
|
+
updated = true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (updated) {
|
|
201
|
+
(0, devkit_1.writeJson)(tree, packageLockPath, packageLock);
|
|
202
|
+
devkit_1.logger.info(`Removed entry from package-lock.json`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async function removeGenerator(tree, options) {
|
|
206
|
+
// Validate .unisphere exists
|
|
207
|
+
(0, utils_1.validateUnisphereConfig)(tree);
|
|
208
|
+
// Parse element string (format: "type:name")
|
|
209
|
+
const { elementType, name } = parseElement(options.element);
|
|
210
|
+
const normalizedName = (0, devkit_1.names)(name).fileName;
|
|
211
|
+
// Validate element exists and get sourceRoot
|
|
212
|
+
const sourceRoot = validateElementExists(tree, elementType, normalizedName);
|
|
213
|
+
// Verify the directory exists
|
|
214
|
+
if (!tree.exists(sourceRoot)) {
|
|
215
|
+
devkit_1.logger.warn(`Directory not found at ${sourceRoot}. The .unisphere configuration may be out of sync.`);
|
|
216
|
+
}
|
|
217
|
+
const nxProjectName = `${getNxProjectPrefix(elementType)}-${normalizedName}`;
|
|
218
|
+
devkit_1.logger.info('');
|
|
219
|
+
devkit_1.logger.info(`Removing ${elementType}: ${normalizedName}`);
|
|
220
|
+
devkit_1.logger.info(` Location: ${sourceRoot}`);
|
|
221
|
+
devkit_1.logger.info('');
|
|
222
|
+
// Step 1: For runtimes, remove types first (before directory is deleted)
|
|
223
|
+
if (elementType === 'runtime') {
|
|
224
|
+
removeRuntimeTypes(tree, normalizedName);
|
|
225
|
+
}
|
|
226
|
+
// Step 2: Run Nx's built-in remove generator
|
|
227
|
+
try {
|
|
228
|
+
await (0, generators_1.removeGenerator)(tree, {
|
|
229
|
+
projectName: nxProjectName,
|
|
230
|
+
forceRemove: options.forceRemove || false,
|
|
231
|
+
skipFormat: false,
|
|
232
|
+
});
|
|
233
|
+
devkit_1.logger.info(`Removed Nx project "${nxProjectName}"`);
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
// If Nx remove fails (e.g., project not in project.json), continue with cleanup
|
|
237
|
+
devkit_1.logger.warn(`Nx remove failed: ${error}`);
|
|
238
|
+
devkit_1.logger.info('Continuing with Unisphere cleanup...');
|
|
239
|
+
// Manually delete the directory if it exists
|
|
240
|
+
if (tree.exists(sourceRoot)) {
|
|
241
|
+
// Delete all files recursively
|
|
242
|
+
const deleteRecursively = (dirPath) => {
|
|
243
|
+
if (tree.isFile(dirPath)) {
|
|
244
|
+
tree.delete(dirPath);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
tree.children(dirPath).forEach(child => {
|
|
248
|
+
deleteRecursively(`${dirPath}/${child}`);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
deleteRecursively(sourceRoot);
|
|
253
|
+
devkit_1.logger.info(`Manually deleted ${sourceRoot}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// Step 3: Remove from .unisphere configuration
|
|
257
|
+
removeFromUnisphereConfig(tree, elementType, normalizedName);
|
|
258
|
+
// Step 4: Remove path mapping from tsconfig.base.json
|
|
259
|
+
removeTsConfigPath(tree, elementType, normalizedName);
|
|
260
|
+
// Step 5: Remove entry from package-lock.json
|
|
261
|
+
removeFromPackageLock(tree, sourceRoot);
|
|
262
|
+
devkit_1.logger.info('');
|
|
263
|
+
devkit_1.logger.info(`${elementType.charAt(0).toUpperCase() + elementType.slice(1)} "${normalizedName}" removed successfully!`);
|
|
264
|
+
devkit_1.logger.info('');
|
|
265
|
+
devkit_1.logger.info('Next steps:');
|
|
266
|
+
devkit_1.logger.info(' 1. Run: npm install');
|
|
267
|
+
devkit_1.logger.info(' 2. Run: npm run build');
|
|
268
|
+
devkit_1.logger.info('');
|
|
269
|
+
}
|
|
270
|
+
exports.default = removeGenerator;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "Remove",
|
|
4
|
+
"title": "Remove Unisphere Element",
|
|
5
|
+
"description": "Remove a Unisphere element (package, runtime, or application) from the workspace",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"examples": [
|
|
8
|
+
{
|
|
9
|
+
"command": "nx g @unisphere/nx:remove package:my-package",
|
|
10
|
+
"description": "Remove a package named 'my-package'"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"command": "nx g @unisphere/nx:remove runtime:my-runtime",
|
|
14
|
+
"description": "Remove a runtime named 'my-runtime'"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"command": "nx g @unisphere/nx:remove application:my-app",
|
|
18
|
+
"description": "Remove an application named 'my-app'"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"properties": {
|
|
22
|
+
"element": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"description": "The element to remove in format 'type:name' (e.g., runtime:admin, package:shared, application:my-app)",
|
|
25
|
+
"$default": {
|
|
26
|
+
"$source": "argv",
|
|
27
|
+
"index": 0
|
|
28
|
+
},
|
|
29
|
+
"x-prompt": "Enter element to remove (format: type:name, e.g., runtime:admin):"
|
|
30
|
+
},
|
|
31
|
+
"forceRemove": {
|
|
32
|
+
"type": "boolean",
|
|
33
|
+
"description": "Force removal even if the element is still in use",
|
|
34
|
+
"default": false
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"required": ["element"]
|
|
38
|
+
}
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* - Updating .unisphere configuration
|
|
11
11
|
* - Ensuring package.json name matches Unisphere conventions
|
|
12
12
|
* - Updating package-lock.json path keys (Nx doesn't handle this)
|
|
13
|
+
* - Updating vite.config.ts cache directory paths
|
|
14
|
+
* - Updating project.json lintFilePatterns and comments (Nx updates root/sourceRoot but not options strings)
|
|
15
|
+
* - Updating README.md with new package name
|
|
13
16
|
*/
|
|
14
17
|
import { Tree } from '@nx/devkit';
|
|
15
18
|
import { RenamePackageGeneratorSchema } from './schema';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename-package.d.ts","sourceRoot":"","sources":["../../../src/generators/rename-package/rename-package.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"rename-package.d.ts","sourceRoot":"","sources":["../../../src/generators/rename-package/rename-package.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,IAAI,EAKL,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAgZxD,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,4BAA4B,uBAmHtC;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
* - Updating .unisphere configuration
|
|
12
12
|
* - Ensuring package.json name matches Unisphere conventions
|
|
13
13
|
* - Updating package-lock.json path keys (Nx doesn't handle this)
|
|
14
|
+
* - Updating vite.config.ts cache directory paths
|
|
15
|
+
* - Updating project.json lintFilePatterns and comments (Nx updates root/sourceRoot but not options strings)
|
|
16
|
+
* - Updating README.md with new package name
|
|
14
17
|
*/
|
|
15
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
19
|
exports.renamePackageGenerator = renamePackageGenerator;
|
|
@@ -30,7 +33,13 @@ function validateOldPackageExists(tree, oldPackageName) {
|
|
|
30
33
|
Object.keys(unisphereConfig.elements?.packages || {}).join(', '));
|
|
31
34
|
}
|
|
32
35
|
const packageConfig = unisphereConfig.elements.packages[normalizedOldName];
|
|
33
|
-
|
|
36
|
+
// Use the actual sourceRoot from .unisphere (supports both old and new directory structures)
|
|
37
|
+
const sourceRoot = packageConfig.sourceRoot;
|
|
38
|
+
if (!sourceRoot) {
|
|
39
|
+
throw new Error(`Package "${normalizedOldName}" exists but has no sourceRoot configured in .unisphere`);
|
|
40
|
+
}
|
|
41
|
+
const oldPath = sourceRoot;
|
|
42
|
+
const subdirectory = (0, utils_1.extractSubdirectoryFromSourceRoot)(sourceRoot);
|
|
34
43
|
// Verify the directory exists
|
|
35
44
|
if (!tree.exists(oldPath)) {
|
|
36
45
|
throw new Error(`Package directory not found at ${oldPath}.\n` +
|
|
@@ -46,24 +55,27 @@ function validateOldPackageExists(tree, oldPackageName) {
|
|
|
46
55
|
const packageJsonName = packageJson.name;
|
|
47
56
|
return {
|
|
48
57
|
packageJsonName,
|
|
49
|
-
distributionChannel: packageConfig.distributionChannel || 'none',
|
|
50
58
|
scope: packageConfig.scope || 'widget',
|
|
51
|
-
sourceRoot
|
|
59
|
+
sourceRoot,
|
|
60
|
+
subdirectory,
|
|
52
61
|
oldPath,
|
|
53
|
-
newPath: `unisphere/packages/${normalizedOldName}`,
|
|
54
62
|
};
|
|
55
63
|
}
|
|
56
64
|
/**
|
|
57
65
|
* Validates that the new package name doesn't already exist
|
|
66
|
+
* Checks in the same subdirectory as the old package (rename keeps the package in the same location)
|
|
58
67
|
*/
|
|
59
|
-
function validateNewPackageDoesNotExist(tree, newPackageName) {
|
|
68
|
+
function validateNewPackageDoesNotExist(tree, newPackageName, subdirectory) {
|
|
60
69
|
const unisphereConfig = (0, devkit_1.readJson)(tree, '.unisphere');
|
|
61
70
|
const normalizedNewName = (0, devkit_1.names)(newPackageName).fileName;
|
|
62
71
|
if (unisphereConfig.elements?.packages?.[normalizedNewName]) {
|
|
63
72
|
throw new Error(`Package "${normalizedNewName}" already exists in .unisphere configuration.\n` +
|
|
64
73
|
'Please choose a different package name.');
|
|
65
74
|
}
|
|
66
|
-
|
|
75
|
+
// Build the new path using the same subdirectory as the old package
|
|
76
|
+
const newPath = subdirectory
|
|
77
|
+
? `unisphere/packages/${subdirectory}/${normalizedNewName}`
|
|
78
|
+
: `unisphere/packages/${normalizedNewName}`;
|
|
67
79
|
if (tree.exists(newPath)) {
|
|
68
80
|
throw new Error(`Package directory already exists at ${newPath}.\n` +
|
|
69
81
|
'Please choose a different package name or remove the existing directory.');
|
|
@@ -77,15 +89,22 @@ function calculateNewPackageJsonName(tree, newPackageName, oldPackageJsonName) {
|
|
|
77
89
|
const experienceName = unisphereConfig.name;
|
|
78
90
|
const normalizedNewName = (0, devkit_1.names)(newPackageName).fileName;
|
|
79
91
|
// Determine the prefix from the old package name
|
|
92
|
+
// Order matters - check more specific prefixes first
|
|
80
93
|
let prefix;
|
|
81
|
-
if (oldPackageJsonName.startsWith('@unisphere/')) {
|
|
94
|
+
if (oldPackageJsonName.startsWith('@unisphere-corp/')) {
|
|
95
|
+
prefix = '@unisphere-corp/';
|
|
96
|
+
}
|
|
97
|
+
else if (oldPackageJsonName.startsWith('@local/')) {
|
|
98
|
+
prefix = '@local/';
|
|
99
|
+
}
|
|
100
|
+
else if (oldPackageJsonName.startsWith('@unisphere/')) {
|
|
82
101
|
prefix = '@unisphere/';
|
|
83
102
|
}
|
|
84
103
|
else if (oldPackageJsonName.startsWith('@kaltura/unisphere-')) {
|
|
85
104
|
prefix = '@kaltura/unisphere-';
|
|
86
105
|
}
|
|
87
106
|
else {
|
|
88
|
-
//
|
|
107
|
+
// Truly private package with no standard prefix
|
|
89
108
|
return normalizedNewName;
|
|
90
109
|
}
|
|
91
110
|
// Calculate new package name
|
|
@@ -100,6 +119,7 @@ function calculateNewPackageJsonName(tree, newPackageName, oldPackageJsonName) {
|
|
|
100
119
|
}
|
|
101
120
|
/**
|
|
102
121
|
* Update .unisphere configuration
|
|
122
|
+
* Preserves the subdirectory structure (package stays in same subdirectory after rename)
|
|
103
123
|
*/
|
|
104
124
|
function updateUnisphereConfiguration(tree, oldPackageName, newPackageName, packageInfo) {
|
|
105
125
|
const unisphereConfig = (0, devkit_1.readJson)(tree, '.unisphere');
|
|
@@ -107,8 +127,10 @@ function updateUnisphereConfiguration(tree, oldPackageName, newPackageName, pack
|
|
|
107
127
|
const normalizedOldName = (0, devkit_1.names)(oldPackageName).fileName;
|
|
108
128
|
// Get the old package config
|
|
109
129
|
const oldPackageConfig = unisphereConfig.elements.packages[normalizedOldName];
|
|
110
|
-
//
|
|
111
|
-
const newSourceRoot =
|
|
130
|
+
// Build new sourceRoot preserving the subdirectory structure
|
|
131
|
+
const newSourceRoot = packageInfo.subdirectory
|
|
132
|
+
? `unisphere/packages/${packageInfo.subdirectory}/${normalizedNewName}`
|
|
133
|
+
: `unisphere/packages/${normalizedNewName}`;
|
|
112
134
|
// Preserve package order by rebuilding the packages object
|
|
113
135
|
const newPackages = {};
|
|
114
136
|
Object.keys(unisphereConfig.elements.packages).forEach((key) => {
|
|
@@ -145,20 +167,108 @@ function updatePackageJson(tree, packagePath, newPackageJsonName) {
|
|
|
145
167
|
devkit_1.logger.info(`✅ Updated package.json name to "${newPackageJsonName}"`);
|
|
146
168
|
}
|
|
147
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Update vite.config.ts to rename cache directory paths
|
|
172
|
+
* Nx's move generator doesn't update arbitrary string literals in code files
|
|
173
|
+
*/
|
|
174
|
+
function updateViteConfig(tree, newPath, oldNormalizedName, newNormalizedName) {
|
|
175
|
+
const viteConfigPath = `${newPath}/vite.config.ts`;
|
|
176
|
+
if (!tree.exists(viteConfigPath)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
let content = tree.read(viteConfigPath, 'utf-8');
|
|
180
|
+
if (!content) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const oldPattern = `package-${oldNormalizedName}`;
|
|
184
|
+
const newPattern = `package-${newNormalizedName}`;
|
|
185
|
+
if (content.includes(oldPattern)) {
|
|
186
|
+
content = content.replace(new RegExp(oldPattern, 'g'), newPattern);
|
|
187
|
+
tree.write(viteConfigPath, content);
|
|
188
|
+
devkit_1.logger.info(`✅ Updated vite.config.ts cache directories`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Update project.json to fix lintFilePatterns and comments
|
|
193
|
+
* Nx's move generator updates root/sourceRoot but not arbitrary strings in options
|
|
194
|
+
*/
|
|
195
|
+
function updateProjectJson(tree, newPath, oldPath, oldNxProjectName, newNxProjectName) {
|
|
196
|
+
const projectJsonPath = `${newPath}/project.json`;
|
|
197
|
+
if (!tree.exists(projectJsonPath)) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
let content = tree.read(projectJsonPath, 'utf-8');
|
|
201
|
+
if (!content) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let updated = false;
|
|
205
|
+
// Update lintFilePatterns that still reference the old path
|
|
206
|
+
if (content.includes(oldPath)) {
|
|
207
|
+
content = content.replace(new RegExp(escapeRegExp(oldPath), 'g'), newPath);
|
|
208
|
+
updated = true;
|
|
209
|
+
}
|
|
210
|
+
// Update the "// targets" comment that contains the old project name
|
|
211
|
+
if (content.includes(oldNxProjectName)) {
|
|
212
|
+
content = content.replace(new RegExp(escapeRegExp(oldNxProjectName), 'g'), newNxProjectName);
|
|
213
|
+
updated = true;
|
|
214
|
+
}
|
|
215
|
+
if (updated) {
|
|
216
|
+
tree.write(projectJsonPath, content);
|
|
217
|
+
devkit_1.logger.info(`✅ Updated project.json paths and comments`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Update README.md to reflect the new package name
|
|
222
|
+
* Nx's move generator doesn't update documentation files
|
|
223
|
+
*/
|
|
224
|
+
function updateReadme(tree, newPath, oldNormalizedName, newNormalizedName) {
|
|
225
|
+
const readmePath = `${newPath}/README.md`;
|
|
226
|
+
if (!tree.exists(readmePath)) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
let content = tree.read(readmePath, 'utf-8');
|
|
230
|
+
if (!content) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
let updated = false;
|
|
234
|
+
// Convert to human readable format (capitalize first letter of each word)
|
|
235
|
+
const toHumanReadable = (name) => name
|
|
236
|
+
.replace(/[-_]/g, ' ')
|
|
237
|
+
.replace(/\b\w/g, (l) => l.toUpperCase());
|
|
238
|
+
const oldHumanReadable = toHumanReadable(oldNormalizedName);
|
|
239
|
+
const newHumanReadable = toHumanReadable(newNormalizedName);
|
|
240
|
+
// Update human readable name (e.g., "Package My Package" -> "Package New Name")
|
|
241
|
+
if (content.includes(oldHumanReadable)) {
|
|
242
|
+
content = content.replace(new RegExp(escapeRegExp(oldHumanReadable), 'g'), newHumanReadable);
|
|
243
|
+
updated = true;
|
|
244
|
+
}
|
|
245
|
+
// Update kebab-case name references
|
|
246
|
+
if (content.includes(oldNormalizedName)) {
|
|
247
|
+
content = content.replace(new RegExp(escapeRegExp(oldNormalizedName), 'g'), newNormalizedName);
|
|
248
|
+
updated = true;
|
|
249
|
+
}
|
|
250
|
+
if (updated) {
|
|
251
|
+
tree.write(readmePath, content);
|
|
252
|
+
devkit_1.logger.info(`✅ Updated README.md`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Escape special regex characters in a string
|
|
257
|
+
*/
|
|
258
|
+
function escapeRegExp(string) {
|
|
259
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
260
|
+
}
|
|
148
261
|
/**
|
|
149
262
|
* Update package-lock.json to rename the package path keys
|
|
150
263
|
* Nx's move generator doesn't handle package-lock.json updates
|
|
264
|
+
* Uses actual paths from packageInfo to support subdirectories
|
|
151
265
|
*/
|
|
152
|
-
function updatePackageLock(tree,
|
|
266
|
+
function updatePackageLock(tree, oldPath, newPath) {
|
|
153
267
|
const packageLockPath = 'package-lock.json';
|
|
154
268
|
if (!tree.exists(packageLockPath)) {
|
|
155
269
|
return;
|
|
156
270
|
}
|
|
157
271
|
const packageLock = (0, devkit_1.readJson)(tree, packageLockPath);
|
|
158
|
-
const normalizedOldName = (0, devkit_1.names)(oldPackageName).fileName;
|
|
159
|
-
const normalizedNewName = (0, devkit_1.names)(newPackageName).fileName;
|
|
160
|
-
const oldPath = `unisphere/packages/${normalizedOldName}`;
|
|
161
|
-
const newPath = `unisphere/packages/${normalizedNewName}`;
|
|
162
272
|
let updated = false;
|
|
163
273
|
if (packageLock.packages) {
|
|
164
274
|
const packagesEntries = Object.entries(packageLock.packages);
|
|
@@ -203,13 +313,16 @@ async function renamePackageGenerator(tree, options) {
|
|
|
203
313
|
const normalizedNewName = (0, devkit_1.names)(options.newPackageName).fileName;
|
|
204
314
|
// Validate old package exists
|
|
205
315
|
const packageInfo = validateOldPackageExists(tree, normalizedOldName);
|
|
206
|
-
// Validate new package doesn't exist
|
|
207
|
-
validateNewPackageDoesNotExist(tree, normalizedNewName);
|
|
316
|
+
// Validate new package doesn't exist (checks in same subdirectory)
|
|
317
|
+
validateNewPackageDoesNotExist(tree, normalizedNewName, packageInfo.subdirectory);
|
|
208
318
|
// Calculate new package.json name
|
|
209
319
|
const newPackageJsonName = calculateNewPackageJsonName(tree, normalizedNewName, packageInfo.packageJsonName);
|
|
210
320
|
const oldNxProjectName = `unisphere-package-${normalizedOldName}`;
|
|
211
321
|
const newNxProjectName = `unisphere-package-${normalizedNewName}`;
|
|
212
|
-
|
|
322
|
+
// Build new path preserving subdirectory structure
|
|
323
|
+
const newPath = packageInfo.subdirectory
|
|
324
|
+
? `unisphere/packages/${packageInfo.subdirectory}/${normalizedNewName}`
|
|
325
|
+
: `unisphere/packages/${normalizedNewName}`;
|
|
213
326
|
devkit_1.logger.info(`📦 Old package name: ${normalizedOldName}`);
|
|
214
327
|
devkit_1.logger.info(`📦 New package name: ${normalizedNewName}`);
|
|
215
328
|
devkit_1.logger.info(`🏷️ Old package.json name: ${packageInfo.packageJsonName}`);
|
|
@@ -240,14 +353,20 @@ async function renamePackageGenerator(tree, options) {
|
|
|
240
353
|
// Step 3: Update package.json name to match Unisphere conventions
|
|
241
354
|
updatePackageJson(tree, newPath, newPackageJsonName);
|
|
242
355
|
// Step 4: Update package-lock.json path keys (Nx doesn't handle this)
|
|
243
|
-
updatePackageLock(tree,
|
|
356
|
+
updatePackageLock(tree, packageInfo.oldPath, newPath);
|
|
357
|
+
// Step 5: Update vite.config.ts cache directories (Nx doesn't handle this)
|
|
358
|
+
updateViteConfig(tree, newPath, normalizedOldName, normalizedNewName);
|
|
359
|
+
// Step 6: Update project.json lintFilePatterns and comments (Nx doesn't handle these)
|
|
360
|
+
updateProjectJson(tree, newPath, packageInfo.oldPath, oldNxProjectName, newNxProjectName);
|
|
361
|
+
// Step 7: Update README.md (Nx doesn't handle documentation)
|
|
362
|
+
updateReadme(tree, newPath, normalizedOldName, normalizedNewName);
|
|
244
363
|
devkit_1.logger.info('');
|
|
245
364
|
devkit_1.logger.info('✅ Package renamed successfully!');
|
|
246
365
|
devkit_1.logger.info('');
|
|
247
366
|
devkit_1.logger.info('📋 Summary:');
|
|
248
367
|
devkit_1.logger.info(` • Old name: ${normalizedOldName}`);
|
|
249
368
|
devkit_1.logger.info(` • New name: ${normalizedNewName}`);
|
|
250
|
-
devkit_1.logger.info(` • Old location: ${packageInfo.
|
|
369
|
+
devkit_1.logger.info(` • Old location: ${packageInfo.sourceRoot}`);
|
|
251
370
|
devkit_1.logger.info(` • New location: ${newPath}`);
|
|
252
371
|
devkit_1.logger.info(` • Package.json name: ${newPackageJsonName}`);
|
|
253
372
|
devkit_1.logger.info('');
|