@unisphere/nx 3.24.0 â 4.0.0
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/README.md +195 -0
- package/dist/generators/add-application/add-application.d.ts.map +1 -1
- package/dist/generators/add-application/add-application.js +29 -0
- package/dist/generators/add-application/schema.json +7 -24
- package/dist/generators/add-documentation/add-documentation.d.ts.map +1 -1
- package/dist/generators/add-documentation/add-documentation.js +27 -24
- package/dist/generators/add-package/add-package.d.ts.map +1 -1
- package/dist/generators/add-package/add-package.js +37 -0
- package/dist/generators/add-package/schema.json +4 -53
- package/dist/generators/add-runtime/add-runtime.d.ts.map +1 -1
- package/dist/generators/add-runtime/add-runtime.js +33 -70
- package/dist/generators/add-runtime/schema.d.ts +1 -1
- package/dist/generators/add-runtime/schema.json +9 -34
- package/dist/generators/add-runtime/templates/new-runtime/src/lib/runtime.tsx.template +1 -1
- package/dist/generators/add-visual/add-visual.d.ts.map +1 -1
- package/dist/generators/add-visual/add-visual.js +41 -49
- package/dist/generators/add-visual/schema.json +18 -2
- package/dist/generators/change-package-scope/change-package-scope.d.ts.map +1 -1
- package/dist/generators/change-package-scope/change-package-scope.js +29 -0
- package/dist/generators/change-package-scope/schema.json +2 -4
- package/dist/generators/remove/remove.d.ts.map +1 -1
- package/dist/generators/remove/remove.js +11 -0
- package/dist/generators/remove/schema.json +1 -2
- package/dist/generators/rename-package/rename-package.d.ts.map +1 -1
- package/dist/generators/rename-package/rename-package.js +23 -0
- package/dist/generators/rename-package/schema.json +2 -4
- package/dist/generators/utils/index.d.ts +2 -0
- package/dist/generators/utils/index.d.ts.map +1 -0
- package/dist/generators/utils/index.js +4 -0
- package/dist/generators/utils/validation.d.ts +9 -0
- package/dist/generators/utils/validation.d.ts.map +1 -0
- package/dist/generators/utils/validation.js +38 -0
- package/dist/migrations/3-24-0/add-server-runtimes-setup.d.ts +11 -0
- package/dist/migrations/3-24-0/add-server-runtimes-setup.d.ts.map +1 -0
- package/dist/migrations/3-24-0/add-server-runtimes-setup.js +160 -0
- package/dist/migrations/3-24-0/remove-runtime-js-patch.d.ts +9 -0
- package/dist/migrations/3-24-0/remove-runtime-js-patch.d.ts.map +1 -0
- package/dist/migrations/3-24-0/remove-runtime-js-patch.js +29 -0
- package/dist/migrations/3-24-0/update-runtime-logger-call.d.ts +9 -0
- package/dist/migrations/3-24-0/update-runtime-logger-call.d.ts.map +1 -0
- package/dist/migrations/3-24-0/update-runtime-logger-call.js +44 -0
- package/migrations.json +24 -0
- package/package.json +1 -1
|
@@ -7,50 +7,25 @@
|
|
|
7
7
|
"name": {
|
|
8
8
|
"type": "string",
|
|
9
9
|
"description": "The name of the runtime to create",
|
|
10
|
-
"pattern": "^[a-zA-Z][a-zA-Z0-9\\-\\s]*$"
|
|
11
|
-
"x-prompt": "What's the runtime name? (letters, numbers, dashes and spaces allowed)"
|
|
10
|
+
"pattern": "^[a-zA-Z][a-zA-Z0-9\\-\\s]*$"
|
|
12
11
|
},
|
|
13
12
|
"consumer": {
|
|
14
13
|
"type": "string",
|
|
15
14
|
"description": "Is this runtime loaded from within the same experience or by an external consumer?",
|
|
16
|
-
"
|
|
17
|
-
"message": "Is this runtime loaded from within the same experience or by an external consumer?",
|
|
18
|
-
"type": "list",
|
|
19
|
-
"items": [
|
|
20
|
-
{
|
|
21
|
-
"value": "external",
|
|
22
|
-
"label": "Loaded by an external consumer"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"value": "internal",
|
|
26
|
-
"label": "Loaded by another runtime or application within this experience"
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
}
|
|
15
|
+
"enum": ["external", "internal"]
|
|
30
16
|
},
|
|
31
17
|
"dependencies": {
|
|
32
18
|
"type": "array",
|
|
33
|
-
"description": "
|
|
19
|
+
"description": "Packages to install (react, ds, or mui)",
|
|
34
20
|
"items": {
|
|
35
21
|
"type": "string",
|
|
36
|
-
"enum": [
|
|
37
|
-
"react",
|
|
38
|
-
"ds",
|
|
39
|
-
"mui"
|
|
40
|
-
]
|
|
22
|
+
"enum": ["react", "ds", "mui"]
|
|
41
23
|
},
|
|
42
|
-
"default": []
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"items": [
|
|
48
|
-
{
|
|
49
|
-
"value": "react",
|
|
50
|
-
"label": "React - UI library for building components"
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
}
|
|
24
|
+
"default": []
|
|
25
|
+
},
|
|
26
|
+
"analyticsAppId": {
|
|
27
|
+
"type": "number",
|
|
28
|
+
"description": "Analytics app ID (optional, can be set later in runtime constructor)"
|
|
54
29
|
}
|
|
55
30
|
},
|
|
56
31
|
"required": [
|
|
@@ -46,7 +46,7 @@ export class Runtime
|
|
|
46
46
|
|
|
47
47
|
const analyticsAppId: null | number = <%= analyticsAppId ? analyticsAppId : 'null' %>;
|
|
48
48
|
if (!analyticsAppId) {
|
|
49
|
-
this._logger.
|
|
49
|
+
this._logger.log(`missing kaltura analytics app id, skip application registration to analytics service`)
|
|
50
50
|
} else {
|
|
51
51
|
const service = this._options
|
|
52
52
|
.getWorkspace()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-visual.d.ts","sourceRoot":"","sources":["../../../src/generators/add-visual/add-visual.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,IAAI,EAAE,MAAM,YAAY,CAAC;AAsB9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"add-visual.d.ts","sourceRoot":"","sources":["../../../src/generators/add-visual/add-visual.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,IAAI,EAAE,MAAM,YAAY,CAAC;AAsB9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAmapD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,GAAG,CAAC,CA2Fd;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -7,53 +7,37 @@ const path = tslib_1.__importStar(require("path"));
|
|
|
7
7
|
const ts_morph_1 = require("ts-morph");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const visual_utils_1 = require("./visual-utils");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return existingRuntimeName;
|
|
10
|
+
function validateOptions(options) {
|
|
11
|
+
if (!options.runtimeName || options.runtimeName.trim() === '') {
|
|
12
|
+
throw new Error(`Missing required option: 'runtimeName'\n` +
|
|
13
|
+
` Description: The name of the runtime to add the visual to\n` +
|
|
14
|
+
` Type: string\n` +
|
|
15
|
+
` Pattern: ^[a-zA-Z][a-zA-Z0-9\\-\\s]*$\n` +
|
|
16
|
+
` Example: nx g @unisphere/nx:add-visual --runtimeName=my-runtime --visualName=my-visual`);
|
|
18
17
|
}
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const namePattern = /^[a-zA-Z][a-zA-Z0-9\-\s]*$/;
|
|
19
|
+
if (!namePattern.test(options.runtimeName)) {
|
|
20
|
+
throw new Error(`Invalid value '${options.runtimeName}' for option 'runtimeName'\n` +
|
|
21
|
+
` Pattern: ^[a-zA-Z][a-zA-Z0-9\\-\\s]*$\n` +
|
|
22
|
+
` Received: ${options.runtimeName}`);
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
return response.runtimeName;
|
|
33
|
-
}
|
|
34
|
-
async function promptForVisualName(existingVisualName) {
|
|
35
|
-
if (existingVisualName) {
|
|
36
|
-
return existingVisualName;
|
|
24
|
+
if (!options.visualName || options.visualName.trim() === '') {
|
|
25
|
+
throw new Error(`Missing required option: 'visualName'\n` +
|
|
26
|
+
` Description: The name of the visual to create\n` +
|
|
27
|
+
` Type: string\n` +
|
|
28
|
+
` Pattern: ^[a-zA-Z][a-zA-Z0-9\\-\\s]*$\n` +
|
|
29
|
+
` Example: nx g @unisphere/nx:add-visual --runtimeName=my-runtime --visualName=my-visual`);
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (existingValue !== undefined) {
|
|
48
|
-
return existingValue;
|
|
31
|
+
if (!namePattern.test(options.visualName)) {
|
|
32
|
+
throw new Error(`Invalid value '${options.visualName}' for option 'visualName'\n` +
|
|
33
|
+
` Pattern: ^[a-zA-Z][a-zA-Z0-9\\-\\s]*$\n` +
|
|
34
|
+
` Received: ${options.visualName}`);
|
|
35
|
+
}
|
|
36
|
+
if (options.isSingleOccurrence !== undefined && typeof options.isSingleOccurrence !== 'boolean') {
|
|
37
|
+
throw new Error(`Invalid value for option 'isSingleOccurrence'\n` +
|
|
38
|
+
` Type: boolean\n` +
|
|
39
|
+
` Received: ${options.isSingleOccurrence}`);
|
|
49
40
|
}
|
|
50
|
-
const prompt = await getEnquirerPrompt();
|
|
51
|
-
const response = await prompt({
|
|
52
|
-
type: 'confirm',
|
|
53
|
-
name: 'isSingleOccurrence',
|
|
54
|
-
message: 'Is this visual limited to single occurrence?',
|
|
55
|
-
});
|
|
56
|
-
return response.isSingleOccurrence;
|
|
57
41
|
}
|
|
58
42
|
/**
|
|
59
43
|
* Adds necessary imports (runtimeVisualSettings, runtimeVisualSchema) to the runtime file.
|
|
@@ -285,14 +269,22 @@ export const ${schemaName}: ValidatorSchema = {
|
|
|
285
269
|
* Nx generator to create a new visual within a specified runtime.
|
|
286
270
|
*/
|
|
287
271
|
async function addVisualGenerator(tree, options) {
|
|
272
|
+
validateOptions(options);
|
|
288
273
|
// Validate and read .unisphere configuration first
|
|
289
274
|
const unisphereConfig = (0, utils_1.validateUnisphereConfig)(tree);
|
|
290
|
-
//
|
|
291
|
-
const runtimeName =
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
275
|
+
// After validation, these are guaranteed to be strings
|
|
276
|
+
const runtimeName = options.runtimeName;
|
|
277
|
+
const visualName = options.visualName;
|
|
278
|
+
// Validate that the runtime exists
|
|
279
|
+
if (!unisphereConfig.runtimes[runtimeName]) {
|
|
280
|
+
const availableRuntimes = Object.keys(unisphereConfig.runtimes);
|
|
281
|
+
throw new Error(`Runtime '${runtimeName}' not found in .unisphere configuration.\n` +
|
|
282
|
+
(availableRuntimes.length > 0
|
|
283
|
+
? ` Available runtimes: ${availableRuntimes.join(', ')}\n`
|
|
284
|
+
: ` No runtimes found. Please create a runtime first using: nx generate @unisphere/nx:add-runtime\n`) +
|
|
285
|
+
` Example: nx g @unisphere/nx:add-visual --runtimeName=${availableRuntimes[0] || 'my-runtime'} --visualName=my-visual`);
|
|
286
|
+
}
|
|
287
|
+
const isSingleOccurrence = options.isSingleOccurrence ?? false;
|
|
296
288
|
// Extract environment variables
|
|
297
289
|
const widgetName = unisphereConfig.name;
|
|
298
290
|
// Validate runtime existence and get source root path.
|
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
"$id": "AddVisual",
|
|
4
4
|
"title": "Add Visual Generator",
|
|
5
5
|
"type": "object",
|
|
6
|
-
"properties": {
|
|
7
|
-
|
|
6
|
+
"properties": {
|
|
7
|
+
"runtimeName": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "The name of the runtime to add the visual to",
|
|
10
|
+
"pattern": "^[a-zA-Z][a-zA-Z0-9\\-\\s]*$"
|
|
11
|
+
},
|
|
12
|
+
"visualName": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The name of the visual to create",
|
|
15
|
+
"pattern": "^[a-zA-Z][a-zA-Z0-9\\-\\s]*$"
|
|
16
|
+
},
|
|
17
|
+
"isSingleOccurrence": {
|
|
18
|
+
"type": "boolean",
|
|
19
|
+
"description": "Whether this visual is limited to single occurrence",
|
|
20
|
+
"default": false
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"required": ["runtimeName", "visualName"]
|
|
8
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change-package-scope.d.ts","sourceRoot":"","sources":["../../../src/generators/change-package-scope/change-package-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,IAAI,EAIL,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"change-package-scope.d.ts","sourceRoot":"","sources":["../../../src/generators/change-package-scope/change-package-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,IAAI,EAIL,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;AAwY7D,wBAAsB,2BAA2B,CAC/C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,iCAAiC,iBAuH3C;AAED,eAAe,2BAA2B,CAAC"}
|
|
@@ -23,6 +23,33 @@ const devkit_1 = require("@nx/devkit");
|
|
|
23
23
|
const generators_1 = require("@nx/workspace/generators");
|
|
24
24
|
const utils_1 = require("../utils");
|
|
25
25
|
const utils_2 = require("./utils");
|
|
26
|
+
function validateOptions(options) {
|
|
27
|
+
if (!options.packageJsonName || options.packageJsonName.trim() === '') {
|
|
28
|
+
throw new Error(`Missing required option: 'packageJsonName'\n` +
|
|
29
|
+
` Description: The full package.json name\n` +
|
|
30
|
+
` Type: string\n` +
|
|
31
|
+
` Pattern: ^@[a-z0-9-]+/[a-z0-9-]+$\n` +
|
|
32
|
+
` Example: nx g @unisphere/nx:change-package-scope --packageJsonName=@kaltura-corp/unisphere-my-package --newScope=kaltura-sdk`);
|
|
33
|
+
}
|
|
34
|
+
const namePattern = /^@[a-z0-9-]+\/[a-z0-9-]+$/;
|
|
35
|
+
if (!namePattern.test(options.packageJsonName)) {
|
|
36
|
+
throw new Error(`Invalid value '${options.packageJsonName}' for option 'packageJsonName'\n` +
|
|
37
|
+
` Pattern: ^@[a-z0-9-]+/[a-z0-9-]+$\n` +
|
|
38
|
+
` Received: ${options.packageJsonName}`);
|
|
39
|
+
}
|
|
40
|
+
if (!options.newScope) {
|
|
41
|
+
throw new Error(`Missing required option: 'newScope'\n` +
|
|
42
|
+
` Description: The target scope for the package\n` +
|
|
43
|
+
` Allowed values: unisphere, kaltura-corp, kaltura-sdk, kaltura-apps, kaltura-ui, local\n` +
|
|
44
|
+
` Example: nx g @unisphere/nx:change-package-scope --packageJsonName=@kaltura-corp/unisphere-my-package --newScope=kaltura-sdk`);
|
|
45
|
+
}
|
|
46
|
+
const allowedScopes = ['unisphere', 'kaltura-corp', 'kaltura-sdk', 'kaltura-apps', 'kaltura-ui', 'local'];
|
|
47
|
+
if (!allowedScopes.includes(options.newScope)) {
|
|
48
|
+
throw new Error(`Invalid value '${options.newScope}' for option 'newScope'\n` +
|
|
49
|
+
` Allowed values: ${allowedScopes.join(', ')}\n` +
|
|
50
|
+
` Received: ${options.newScope}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
26
53
|
/**
|
|
27
54
|
* Finds a package in .unisphere config by matching the package.json name.
|
|
28
55
|
* Extracts package information needed for scope change.
|
|
@@ -256,6 +283,8 @@ function escapeRegExp(string) {
|
|
|
256
283
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
257
284
|
}
|
|
258
285
|
async function changePackageScopeGenerator(tree, options) {
|
|
286
|
+
// Validate options
|
|
287
|
+
validateOptions(options);
|
|
259
288
|
devkit_1.logger.info('');
|
|
260
289
|
devkit_1.logger.info('đ Starting package scope change...');
|
|
261
290
|
devkit_1.logger.info('');
|
|
@@ -7,14 +7,12 @@
|
|
|
7
7
|
"packageJsonName": {
|
|
8
8
|
"type": "string",
|
|
9
9
|
"description": "The full package.json name (e.g., @kaltura-corp/unisphere-rtc-avatar)",
|
|
10
|
-
"pattern": "^@[a-z0-9-]+/[a-z0-9-]+$"
|
|
11
|
-
"x-prompt": "What is the full package.json name? (from the package's package.json)"
|
|
10
|
+
"pattern": "^@[a-z0-9-]+/[a-z0-9-]+$"
|
|
12
11
|
},
|
|
13
12
|
"newScope": {
|
|
14
13
|
"type": "string",
|
|
15
14
|
"description": "The target scope for the package",
|
|
16
|
-
"enum": ["unisphere", "kaltura-corp", "kaltura-sdk", "kaltura-apps", "kaltura-ui", "local"]
|
|
17
|
-
"x-prompt": "What scope should the package move to?"
|
|
15
|
+
"enum": ["unisphere", "kaltura-corp", "kaltura-sdk", "kaltura-apps", "kaltura-ui", "local"]
|
|
18
16
|
}
|
|
19
17
|
},
|
|
20
18
|
"required": [
|
|
@@ -1 +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;
|
|
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;AA6RjD,wBAAsB,eAAe,CACnC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,qBAAqB,iBAwF/B;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -20,6 +20,15 @@ const generators_1 = require("@nx/workspace/generators");
|
|
|
20
20
|
const utils_1 = require("../utils");
|
|
21
21
|
const remove_utils_1 = require("./remove-utils");
|
|
22
22
|
const VALID_ELEMENT_TYPES = ['package', 'runtime', 'application'];
|
|
23
|
+
function validateOptions(options) {
|
|
24
|
+
if (!options.element || options.element.trim() === '') {
|
|
25
|
+
throw new Error(`Missing required option: 'element'\n` +
|
|
26
|
+
` Description: The element to remove in format 'type:name'\n` +
|
|
27
|
+
` Type: string\n` +
|
|
28
|
+
` Format: type:name (e.g., runtime:admin, package:shared, application:my-app)\n` +
|
|
29
|
+
` Example: nx g @unisphere/nx:remove runtime:admin`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
23
32
|
/**
|
|
24
33
|
* Parse the element string in format "type:name"
|
|
25
34
|
*/
|
|
@@ -214,6 +223,8 @@ function removeFromPackageLock(tree, sourceRoot) {
|
|
|
214
223
|
}
|
|
215
224
|
}
|
|
216
225
|
async function removeGenerator(tree, options) {
|
|
226
|
+
// Validate options
|
|
227
|
+
validateOptions(options);
|
|
217
228
|
// Validate .unisphere exists
|
|
218
229
|
(0, utils_1.validateUnisphereConfig)(tree);
|
|
219
230
|
// Parse element string (format: "type:name")
|
|
@@ -1 +1 @@
|
|
|
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;AAEpB,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;
|
|
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;AAEpB,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AA2cxD,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,4BAA4B,iBA8GtC;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -20,6 +20,27 @@ exports.renamePackageGenerator = renamePackageGenerator;
|
|
|
20
20
|
const devkit_1 = require("@nx/devkit");
|
|
21
21
|
const generators_1 = require("@nx/workspace/generators");
|
|
22
22
|
const utils_1 = require("../utils");
|
|
23
|
+
function validateOptions(options) {
|
|
24
|
+
if (!options.oldPackageName || options.oldPackageName.trim() === '') {
|
|
25
|
+
throw new Error(`Missing required option: 'oldPackageName'\n` +
|
|
26
|
+
` Description: The current name of the package to rename\n` +
|
|
27
|
+
` Type: string\n` +
|
|
28
|
+
` Example: nx g @unisphere/nx:rename-package --oldPackageName=old-name --newPackageName=new-name`);
|
|
29
|
+
}
|
|
30
|
+
if (!options.newPackageName || options.newPackageName.trim() === '') {
|
|
31
|
+
throw new Error(`Missing required option: 'newPackageName'\n` +
|
|
32
|
+
` Description: The new name for the package\n` +
|
|
33
|
+
` Type: string\n` +
|
|
34
|
+
` Pattern: ^[a-zA-Z][a-zA-Z0-9\\-\\s]*$\n` +
|
|
35
|
+
` Example: nx g @unisphere/nx:rename-package --oldPackageName=old-name --newPackageName=new-name`);
|
|
36
|
+
}
|
|
37
|
+
const namePattern = /^[a-zA-Z][a-zA-Z0-9\-\s]*$/;
|
|
38
|
+
if (!namePattern.test(options.newPackageName)) {
|
|
39
|
+
throw new Error(`Invalid value '${options.newPackageName}' for option 'newPackageName'\n` +
|
|
40
|
+
` Pattern: ^[a-zA-Z][a-zA-Z0-9\\-\\s]*$\n` +
|
|
41
|
+
` Received: ${options.newPackageName}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
23
44
|
/**
|
|
24
45
|
* Reserved package names that cannot be renamed.
|
|
25
46
|
* These packages have special meaning in Unisphere and renaming them would break functionality.
|
|
@@ -330,6 +351,8 @@ function updatePackageLock(tree, oldPath, newPath) {
|
|
|
330
351
|
}
|
|
331
352
|
}
|
|
332
353
|
async function renamePackageGenerator(tree, options) {
|
|
354
|
+
// Validate options
|
|
355
|
+
validateOptions(options);
|
|
333
356
|
devkit_1.logger.info('');
|
|
334
357
|
devkit_1.logger.info('đ Starting package rename...');
|
|
335
358
|
devkit_1.logger.info('');
|
|
@@ -6,14 +6,12 @@
|
|
|
6
6
|
"properties": {
|
|
7
7
|
"oldPackageName": {
|
|
8
8
|
"type": "string",
|
|
9
|
-
"description": "The current name of the package to rename"
|
|
10
|
-
"x-prompt": "What is the current package name?"
|
|
9
|
+
"description": "The current name of the package to rename"
|
|
11
10
|
},
|
|
12
11
|
"newPackageName": {
|
|
13
12
|
"type": "string",
|
|
14
13
|
"description": "The new name for the package",
|
|
15
|
-
"pattern": "^[a-zA-Z][a-zA-Z0-9\\-\\s]*$"
|
|
16
|
-
"x-prompt": "What should the new package name be? (alphanumeric with dashes and spaces allowed)"
|
|
14
|
+
"pattern": "^[a-zA-Z][a-zA-Z0-9\\-\\s]*$"
|
|
17
15
|
}
|
|
18
16
|
},
|
|
19
17
|
"required": [
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generators/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ValidationConfig {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
allowedValues?: string[];
|
|
5
|
+
pattern?: string;
|
|
6
|
+
type?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function validateRequired(options: Record<string, any>, config: ValidationConfig): void;
|
|
9
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/generators/utils/validation.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,MAAM,EAAE,gBAAgB,GACvB,IAAI,CAyCN"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRequired = validateRequired;
|
|
4
|
+
function validateRequired(options, config) {
|
|
5
|
+
const value = options[config.name];
|
|
6
|
+
// Check if value is missing
|
|
7
|
+
if (value === undefined || value === null || value === '') {
|
|
8
|
+
let message = `Missing required option: '${config.name}'\n`;
|
|
9
|
+
message += ` Description: ${config.description}\n`;
|
|
10
|
+
if (config.allowedValues) {
|
|
11
|
+
message += ` Allowed values: ${config.allowedValues.join(', ')}\n`;
|
|
12
|
+
}
|
|
13
|
+
if (config.type) {
|
|
14
|
+
message += ` Type: ${config.type}\n`;
|
|
15
|
+
}
|
|
16
|
+
if (config.pattern) {
|
|
17
|
+
message += ` Pattern: ${config.pattern}\n`;
|
|
18
|
+
}
|
|
19
|
+
throw new Error(message.trim());
|
|
20
|
+
}
|
|
21
|
+
// Check pattern if provided
|
|
22
|
+
if (config.pattern && typeof value === 'string') {
|
|
23
|
+
const regex = new RegExp(config.pattern);
|
|
24
|
+
if (!regex.test(value)) {
|
|
25
|
+
let message = `Invalid value '${value}' for option '${config.name}'\n`;
|
|
26
|
+
message += ` Pattern: ${config.pattern}\n`;
|
|
27
|
+
message += ` Received: ${value}`;
|
|
28
|
+
throw new Error(message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Check enum if provided
|
|
32
|
+
if (config.allowedValues && !config.allowedValues.includes(value)) {
|
|
33
|
+
let message = `Invalid value '${value}' for option '${config.name}'\n`;
|
|
34
|
+
message += ` Allowed values: ${config.allowedValues.join(', ')}\n`;
|
|
35
|
+
message += ` Received: ${value}`;
|
|
36
|
+
throw new Error(message);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration: Add local runtimes setup
|
|
3
|
+
*
|
|
4
|
+
* For each local application (sourceRoot containing '/server'):
|
|
5
|
+
* 1. Creates setup-local-runtimes.ts with experience name from .unisphere
|
|
6
|
+
* 2. Imports and calls setupLocalRuntimes() in main.tsx
|
|
7
|
+
* 3. Adds LOCAL_RUNTIMES env var to webpack DefinePlugin
|
|
8
|
+
*/
|
|
9
|
+
import { Tree } from '@nx/devkit';
|
|
10
|
+
export default function update(tree: Tree): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=add-server-runtimes-setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-server-runtimes-setup.d.ts","sourceRoot":"","sources":["../../../src/migrations/3-24-0/add-server-runtimes-setup.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAiC,MAAM,YAAY,CAAC;AA2GjE,wBAA8B,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CA4E9D"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Migration: Add local runtimes setup
|
|
4
|
+
*
|
|
5
|
+
* For each local application (sourceRoot containing '/server'):
|
|
6
|
+
* 1. Creates setup-local-runtimes.ts with experience name from .unisphere
|
|
7
|
+
* 2. Imports and calls setupLocalRuntimes() in main.tsx
|
|
8
|
+
* 3. Adds LOCAL_RUNTIMES env var to webpack DefinePlugin
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.default = update;
|
|
12
|
+
const devkit_1 = require("@nx/devkit");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
function generateSetupLocalRuntimes(experienceName) {
|
|
15
|
+
return `export function setupLocalRuntimes() {
|
|
16
|
+
if (!process.env.LOCAL_RUNTIMES) return;
|
|
17
|
+
|
|
18
|
+
const runtimes: Record<string, { token: string; baseEnvName: string }> = {};
|
|
19
|
+
process.env.LOCAL_RUNTIMES.split(',').forEach((entry) => {
|
|
20
|
+
const [name, port] = entry.split('@');
|
|
21
|
+
if (name && port) {
|
|
22
|
+
runtimes[name] = { token: port, baseEnvName: '' };
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const overrides = {
|
|
27
|
+
baseEnvName: '',
|
|
28
|
+
mode: 'integration',
|
|
29
|
+
options: { verbose: 'inherit' },
|
|
30
|
+
baseEnvScope: { core: 'inherit', presets: 'inherit' },
|
|
31
|
+
runtimes: {
|
|
32
|
+
'${experienceName}': runtimes,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
(window as any).unisphereRuntimeOverrides = btoa(JSON.stringify(overrides));
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
function addImportToMainTsx(content) {
|
|
41
|
+
const importLine = "import { setupLocalRuntimes } from './setup-local-runtimes';";
|
|
42
|
+
const callLine = 'setupLocalRuntimes();';
|
|
43
|
+
if (content.includes('setupLocalRuntimes')) {
|
|
44
|
+
return content;
|
|
45
|
+
}
|
|
46
|
+
// Find the last import statement
|
|
47
|
+
const lines = content.split('\n');
|
|
48
|
+
let lastImportIndex = -1;
|
|
49
|
+
for (let i = 0; i < lines.length; i++) {
|
|
50
|
+
if (lines[i].startsWith('import ')) {
|
|
51
|
+
lastImportIndex = i;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (lastImportIndex === -1) {
|
|
55
|
+
// No imports found, add at the top
|
|
56
|
+
return `${importLine}\n\n${callLine}\n\n${content}`;
|
|
57
|
+
}
|
|
58
|
+
// Insert after the last import
|
|
59
|
+
lines.splice(lastImportIndex + 1, 0, importLine, '', callLine);
|
|
60
|
+
return lines.join('\n');
|
|
61
|
+
}
|
|
62
|
+
function addLocalRuntimesToDefinePlugin(content) {
|
|
63
|
+
const entry = "'process.env.LOCAL_RUNTIMES': JSON.stringify(process.env.LOCAL_RUNTIMES),";
|
|
64
|
+
if (content.includes('LOCAL_RUNTIMES')) {
|
|
65
|
+
return content;
|
|
66
|
+
}
|
|
67
|
+
// Find the DefinePlugin block and add before its closing })
|
|
68
|
+
const definePluginMatch = content.match(/new DefinePlugin\(\{/);
|
|
69
|
+
if (!definePluginMatch || definePluginMatch.index === undefined) {
|
|
70
|
+
return content;
|
|
71
|
+
}
|
|
72
|
+
// Find the closing }) of DefinePlugin
|
|
73
|
+
const startIndex = definePluginMatch.index;
|
|
74
|
+
let braceCount = 0;
|
|
75
|
+
let closingIndex = -1;
|
|
76
|
+
for (let i = startIndex; i < content.length; i++) {
|
|
77
|
+
if (content[i] === '{')
|
|
78
|
+
braceCount++;
|
|
79
|
+
if (content[i] === '}') {
|
|
80
|
+
braceCount--;
|
|
81
|
+
if (braceCount === 0) {
|
|
82
|
+
closingIndex = i;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (closingIndex === -1) {
|
|
88
|
+
return content;
|
|
89
|
+
}
|
|
90
|
+
const indent = ' ';
|
|
91
|
+
// Insert the new entry before the closing }
|
|
92
|
+
return content.substring(0, closingIndex).trimEnd() + '\n' +
|
|
93
|
+
`${indent}${entry}\n` +
|
|
94
|
+
' ' + content.substring(closingIndex);
|
|
95
|
+
}
|
|
96
|
+
async function update(tree) {
|
|
97
|
+
devkit_1.logger.info('đ Adding local runtimes setup to local applications...');
|
|
98
|
+
if (!tree.exists('.unisphere')) {
|
|
99
|
+
devkit_1.logger.warn('â ī¸ No .unisphere file found, skipping');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const config = (0, devkit_1.readJson)(tree, '.unisphere');
|
|
103
|
+
const experienceName = `unisphere.${config.type}.${config.name}`;
|
|
104
|
+
const applications = config.elements?.applications;
|
|
105
|
+
if (!applications || Object.keys(applications).length === 0) {
|
|
106
|
+
devkit_1.logger.info('âšī¸ No applications found, skipping');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
let updatedCount = 0;
|
|
110
|
+
for (const [appName, appConfig] of Object.entries(applications)) {
|
|
111
|
+
const { sourceRoot } = appConfig;
|
|
112
|
+
// Only process server applications
|
|
113
|
+
if (!sourceRoot.includes('/server/')) {
|
|
114
|
+
devkit_1.logger.info(`âšī¸ ${appName}: Not a server application, local was already migrated. skipping`);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const setupFilePath = (0, path_1.join)(sourceRoot, 'src', 'setup-local-runtimes.ts');
|
|
118
|
+
const mainTsxPath = (0, path_1.join)(sourceRoot, 'src', 'main.tsx');
|
|
119
|
+
const webpackPath = (0, path_1.join)(sourceRoot, 'webpack.config.js');
|
|
120
|
+
// 1. Create setup-local-runtimes.ts
|
|
121
|
+
if (tree.exists(setupFilePath)) {
|
|
122
|
+
devkit_1.logger.info(`âšī¸ ${appName}: setup-local-runtimes.ts already exists, skipping`);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
tree.write(setupFilePath, generateSetupLocalRuntimes(experienceName));
|
|
126
|
+
devkit_1.logger.info(`â
${appName}: Created setup-local-runtimes.ts`);
|
|
127
|
+
}
|
|
128
|
+
// 2. Modify main.tsx
|
|
129
|
+
if (!tree.exists(mainTsxPath)) {
|
|
130
|
+
devkit_1.logger.warn(`â ī¸ ${appName}: No main.tsx found, skipping`);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const mainContent = tree.read(mainTsxPath, 'utf-8') || '';
|
|
134
|
+
const updatedMain = addImportToMainTsx(mainContent);
|
|
135
|
+
if (updatedMain !== mainContent) {
|
|
136
|
+
tree.write(mainTsxPath, updatedMain);
|
|
137
|
+
devkit_1.logger.info(`â
${appName}: Added setupLocalRuntimes import to main.tsx`);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
devkit_1.logger.info(`âšī¸ ${appName}: main.tsx already has setupLocalRuntimes`);
|
|
141
|
+
}
|
|
142
|
+
// 3. Modify webpack.config.js
|
|
143
|
+
if (!tree.exists(webpackPath)) {
|
|
144
|
+
devkit_1.logger.warn(`â ī¸ ${appName}: No webpack.config.js found, skipping`);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const webpackContent = tree.read(webpackPath, 'utf-8') || '';
|
|
148
|
+
const updatedWebpack = addLocalRuntimesToDefinePlugin(webpackContent);
|
|
149
|
+
if (updatedWebpack !== webpackContent) {
|
|
150
|
+
tree.write(webpackPath, updatedWebpack);
|
|
151
|
+
devkit_1.logger.info(`â
${appName}: Added LOCAL_RUNTIMES to DefinePlugin`);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
devkit_1.logger.info(`âšī¸ ${appName}: webpack.config.js already has LOCAL_RUNTIMES`);
|
|
155
|
+
}
|
|
156
|
+
updatedCount++;
|
|
157
|
+
}
|
|
158
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
159
|
+
devkit_1.logger.info(`\nâ
Done: ${updatedCount} local application(s) updated with local runtimes setup (experience: ${experienceName})`);
|
|
160
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration: Remove outdated @unisphere+runtime-js patch file
|
|
3
|
+
*
|
|
4
|
+
* Removes any patches/@unisphere+runtime-js+{version}.patch file if it exists.
|
|
5
|
+
* Migration succeeds whether file exists or not.
|
|
6
|
+
*/
|
|
7
|
+
import { Tree } from '@nx/devkit';
|
|
8
|
+
export default function update(tree: Tree): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=remove-runtime-js-patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-runtime-js-patch.d.ts","sourceRoot":"","sources":["../../../src/migrations/3-24-0/remove-runtime-js-patch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAU,MAAM,YAAY,CAAC;AAE1C,wBAA8B,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB9D"}
|