@unisphere/nx 2.2.2 → 3.2.4

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.
Files changed (133) hide show
  1. package/dist/generators/add-application/add-application.d.ts.map +1 -1
  2. package/dist/generators/add-application/add-application.js +186 -63
  3. package/dist/generators/add-application/schema.d.ts +3 -1
  4. package/dist/generators/add-application/schema.json +8 -8
  5. package/dist/generators/add-application/templates/default/.env-template +6 -0
  6. package/dist/generators/add-application/templates/default/.eslintrc.json +1 -1
  7. package/dist/generators/add-application/templates/default/jest.config.ts +3 -3
  8. package/dist/generators/add-application/templates/default/project.json.template +2 -2
  9. package/dist/generators/add-application/templates/default/readme.md.template +11 -0
  10. package/dist/generators/add-application/templates/default/src/app/app.tsx.template +77 -77
  11. package/dist/generators/add-application/templates/default/tsconfig.json +1 -1
  12. package/dist/generators/add-application/templates/default/webpack.config.js.template +6 -1
  13. package/dist/generators/add-package/README.md +2 -2
  14. package/dist/generators/add-package/add-package.d.ts.map +1 -1
  15. package/dist/generators/add-package/add-package.js +11 -23
  16. package/dist/generators/add-package/schema.d.ts +1 -1
  17. package/dist/generators/add-package/schema.json +27 -19
  18. package/dist/generators/add-package/templates/new-package/.eslintrc.json +1 -1
  19. package/dist/generators/add-package/templates/new-package/package.json.template +0 -1
  20. package/dist/generators/add-package/templates/new-package/project.json.template +4 -4
  21. package/dist/generators/add-package/templates/new-package/rollup.config.js +1 -1
  22. package/dist/generators/add-package/templates/new-package/tsconfig.json +1 -1
  23. package/dist/generators/add-package/templates/new-package/tsconfig.lib.json.template +1 -1
  24. package/dist/generators/add-package/templates/new-package/tsconfig.spec.json +1 -1
  25. package/dist/generators/add-runtime/add-runtime.d.ts.map +1 -1
  26. package/dist/generators/add-runtime/add-runtime.js +62 -9
  27. package/dist/generators/add-runtime/schema.d.ts +1 -0
  28. package/dist/generators/add-runtime/schema.json +1 -9
  29. package/dist/generators/add-runtime/templates/new-runtime/src/lib/create-factory.tsx.template +4 -4
  30. package/dist/generators/add-runtime/templates/new-runtime/src/lib/runtime.tsx.template +26 -2
  31. package/dist/generators/add-visual/add-visual.d.ts +1 -1
  32. package/dist/generators/add-visual/add-visual.d.ts.map +1 -1
  33. package/dist/generators/add-visual/add-visual.js +108 -15
  34. package/dist/generators/add-visual/schema.d.ts +3 -3
  35. package/dist/generators/add-visual/schema.json +2 -24
  36. package/dist/generators/dependency-config.d.ts.map +1 -1
  37. package/dist/generators/dependency-config.js +1 -0
  38. package/dist/generators/internal-dev-runner/generator.d.ts +3 -0
  39. package/dist/generators/internal-dev-runner/generator.d.ts.map +1 -0
  40. package/dist/generators/internal-dev-runner/generator.js +47 -0
  41. package/dist/generators/internal-dev-runner/schema.json +9 -0
  42. package/dist/generators/remove/remove.d.ts +19 -0
  43. package/dist/generators/remove/remove.d.ts.map +1 -0
  44. package/dist/generators/remove/remove.js +270 -0
  45. package/dist/generators/remove/schema.d.ts +4 -0
  46. package/dist/generators/remove/schema.json +38 -0
  47. package/dist/generators/rename-package/rename-package.d.ts +3 -0
  48. package/dist/generators/rename-package/rename-package.d.ts.map +1 -1
  49. package/dist/generators/rename-package/rename-package.js +139 -20
  50. package/dist/generators/utils.d.ts +30 -1
  51. package/dist/generators/utils.d.ts.map +1 -1
  52. package/dist/generators/utils.js +258 -7
  53. package/dist/migrations/1-22-0/patches/@changesets+cli+2.29.7.patch +36 -4
  54. package/dist/migrations/3-0-0/add-define-plugin-to-webpack.d.ts +3 -0
  55. package/dist/migrations/3-0-0/add-define-plugin-to-webpack.d.ts.map +1 -0
  56. package/dist/migrations/3-0-0/add-define-plugin-to-webpack.js +233 -0
  57. package/dist/migrations/3-0-0/add-env-to-application-gitignore.d.ts +3 -0
  58. package/dist/migrations/3-0-0/add-env-to-application-gitignore.d.ts.map +1 -0
  59. package/dist/migrations/3-0-0/add-env-to-application-gitignore.js +117 -0
  60. package/dist/migrations/3-0-0/fix-vite-config-cache-paths.d.ts +10 -0
  61. package/dist/migrations/3-0-0/fix-vite-config-cache-paths.d.ts.map +1 -0
  62. package/dist/migrations/3-0-0/fix-vite-config-cache-paths.js +66 -0
  63. package/dist/migrations/3-0-0/patches/@changesets+cli+2.29.7.patch +88 -0
  64. package/dist/migrations/3-0-0/post-cleanup-empty-directories.d.ts +12 -0
  65. package/dist/migrations/3-0-0/post-cleanup-empty-directories.d.ts.map +1 -0
  66. package/dist/migrations/3-0-0/post-cleanup-empty-directories.js +62 -0
  67. package/dist/migrations/3-0-0/pre-cleanup-empty-directories.d.ts +14 -0
  68. package/dist/migrations/3-0-0/pre-cleanup-empty-directories.d.ts.map +1 -0
  69. package/dist/migrations/3-0-0/pre-cleanup-empty-directories.js +105 -0
  70. package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.d.ts +3 -0
  71. package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.d.ts.map +1 -0
  72. package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.js +21 -0
  73. package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.d.ts +9 -0
  74. package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.d.ts.map +1 -0
  75. package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.js +88 -0
  76. package/dist/migrations/3-0-0/remove-publish-config-from-packages.d.ts +9 -0
  77. package/dist/migrations/3-0-0/remove-publish-config-from-packages.d.ts.map +1 -0
  78. package/dist/migrations/3-0-0/remove-publish-config-from-packages.js +45 -0
  79. package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.d.ts +15 -0
  80. package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.d.ts.map +1 -0
  81. package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.js +563 -0
  82. package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.d.ts +23 -0
  83. package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.d.ts.map +1 -0
  84. package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.js +645 -0
  85. package/dist/migrations/3-0-0/replace-github-workflow.d.ts +3 -0
  86. package/dist/migrations/3-0-0/replace-github-workflow.d.ts.map +1 -0
  87. package/dist/migrations/3-0-0/replace-github-workflow.js +48 -0
  88. package/dist/migrations/3-0-0/sync-package-lock.d.ts +10 -0
  89. package/dist/migrations/3-0-0/sync-package-lock.d.ts.map +1 -0
  90. package/dist/migrations/3-0-0/sync-package-lock.js +26 -0
  91. package/dist/migrations/3-0-0/templates/_publish-artifacts.template +363 -0
  92. package/dist/migrations/3-0-0/templates/cicd.template +89 -0
  93. package/dist/migrations/3-0-0/update-changeset-patch.d.ts +3 -0
  94. package/dist/migrations/3-0-0/update-changeset-patch.d.ts.map +1 -0
  95. package/dist/migrations/3-0-0/update-changeset-patch.js +31 -0
  96. package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.d.ts +21 -0
  97. package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.d.ts.map +1 -0
  98. package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.js +105 -0
  99. package/dist/migrations/3-1-0/fix-workspaces-pattern.d.ts +23 -0
  100. package/dist/migrations/3-1-0/fix-workspaces-pattern.d.ts.map +1 -0
  101. package/dist/migrations/3-1-0/fix-workspaces-pattern.js +72 -0
  102. package/dist/migrations/utils/has-react-dependency.d.ts +14 -0
  103. package/dist/migrations/utils/has-react-dependency.d.ts.map +1 -0
  104. package/dist/migrations/utils/has-react-dependency.js +72 -0
  105. package/dist/shared.d.ts +6 -0
  106. package/dist/shared.d.ts.map +1 -0
  107. package/dist/shared.js +9 -0
  108. package/generators.json +12 -1
  109. package/migrations.json +125 -0
  110. package/package.json +3 -2
  111. package/dist/generators/add-application/templates/local-dev-playground/.babelrc +0 -11
  112. package/dist/generators/add-application/templates/local-dev-playground/.eslintrc.json +0 -22
  113. package/dist/generators/add-application/templates/local-dev-playground/jest.config.ts +0 -11
  114. package/dist/generators/add-application/templates/local-dev-playground/package.json +0 -6
  115. package/dist/generators/add-application/templates/local-dev-playground/project.json +0 -9
  116. package/dist/generators/add-application/templates/local-dev-playground/src/app/app.tsx.template +0 -212
  117. package/dist/generators/add-application/templates/local-dev-playground/src/app/components/header.tsx.template +0 -123
  118. package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings-buttons.tsx +0 -57
  119. package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings-form.tsx +0 -108
  120. package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings.tsx +0 -74
  121. package/dist/generators/add-application/templates/local-dev-playground/src/app/configuration-provider.tsx +0 -163
  122. package/dist/generators/add-application/templates/local-dev-playground/src/app/definitions.ts +0 -25
  123. package/dist/generators/add-application/templates/local-dev-playground/src/app/utils/merge-deep.ts +0 -31
  124. package/dist/generators/add-application/templates/local-dev-playground/src/favicon.ico +0 -0
  125. package/dist/generators/add-application/templates/local-dev-playground/src/index.html +0 -17
  126. package/dist/generators/add-application/templates/local-dev-playground/src/main.tsx +0 -13
  127. package/dist/generators/add-application/templates/local-dev-playground/src/styles.css +0 -0
  128. package/dist/generators/add-application/templates/local-dev-playground/tsconfig.app.json +0 -24
  129. package/dist/generators/add-application/templates/local-dev-playground/tsconfig.json +0 -20
  130. package/dist/generators/add-application/templates/local-dev-playground/tsconfig.spec.json +0 -25
  131. package/dist/generators/add-application/templates/local-dev-playground/webpack.config.js +0 -33
  132. /package/dist/generators/add-runtime/templates/{core-templates → types-templates}/__runtimeName__-runtime/index.ts.template +0 -0
  133. /package/dist/generators/add-runtime/templates/{core-templates → types-templates}/__runtimeName__-runtime/runtime-types.ts.template +0 -0
@@ -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
- const oldPath = `unisphere/packages/${normalizedOldName}`;
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: packageConfig.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
- const newPath = `unisphere/packages/${normalizedNewName}`;
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
- // Private package, no prefix
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
- // Update sourceRoot
111
- const newSourceRoot = `unisphere/packages/${normalizedNewName}`;
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, oldPackageName, newPackageName) {
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
- const newPath = `unisphere/packages/${normalizedNewName}`;
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, normalizedOldName, normalizedNewName);
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.oldPath}`);
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('');
@@ -2,6 +2,10 @@ import { Tree } from '@nx/devkit';
2
2
  export interface UnisphereConfig {
3
3
  company: string;
4
4
  name: string;
5
+ runtimes: Record<string, {
6
+ sourceRoot: string;
7
+ visuals: string[];
8
+ }>;
5
9
  }
6
10
  export declare function validateUnisphereConfig(tree: Tree): UnisphereConfig;
7
11
  export declare function updateTsConfigPaths(tree: Tree, pathKey: string, pathValue: string): void;
@@ -16,7 +20,7 @@ export declare function findTypesPackageAlias(tree: Tree): string | null;
16
20
  export interface TypesPackageInfo {
17
21
  /** The tsconfig alias for the package (e.g., "@mycompany/types" or "@mycompany/core") */
18
22
  alias: string;
19
- /** The base path to the package (e.g., "unisphere/packages/types" or "unisphere/packages/core") */
23
+ /** The base path to the package (e.g., "unisphere/packages/types" or "unisphere/packages/public/core") */
20
24
  basePath: string;
21
25
  /** Whether the types package exists (true) or falling back to core (false) */
22
26
  hasTypesPackage: boolean;
@@ -32,5 +36,30 @@ type NameTransformations<Prefix extends string> = {
32
36
  export declare function createNameTransforms<Prefix extends string>(baseName: string, prefix: Prefix): NameTransformations<Prefix>;
33
37
  export declare function isPackageInstalled(tree: Tree, packageName: string): string | false;
34
38
  export declare function checkIfRuntimeExists(tree: Tree, runtimeName: string): boolean;
39
+ /**
40
+ * Maps package scope to subdirectory name
41
+ * @param scope - The package scope ('public', 'internal', 'none')
42
+ * @returns The subdirectory name ('unisphere', 'kaltura-corp', 'local')
43
+ */
44
+ export declare function getSubdirectoryFromScope(scope: 'public' | 'internal' | 'none' | 'kaltura-ai'): string;
45
+ /**
46
+ * Extracts the subdirectory from a package sourceRoot path
47
+ * @param sourceRoot - The sourceRoot path (e.g., "unisphere/packages/kaltura-corp/shared")
48
+ * @returns The subdirectory name ('unisphere', 'kaltura-corp', 'local') or null if flat structure
49
+ */
50
+ export declare function extractSubdirectoryFromSourceRoot(sourceRoot: string): string | null;
51
+ /**
52
+ * Extracts the package name from a package sourceRoot path
53
+ * @param sourceRoot - The sourceRoot path (e.g., "unisphere/packages/corp/shared" or "unisphere/packages/shared")
54
+ * @returns The package name
55
+ */
56
+ export declare function extractPackageNameFromSourceRoot(sourceRoot: string): string;
57
+ /**
58
+ * Adds a script to the root package.json
59
+ * @param tree - The file system tree
60
+ * @param scriptName - The name of the script (e.g., "dev:my-app")
61
+ * @param scriptCommand - The command to run (e.g., "npx unisphere application serve my-app --port 4002")
62
+ */
63
+ export declare function addScriptToRootPackageJson(tree: Tree, scriptName: string, scriptCommand: string): void;
35
64
  export {};
36
65
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceR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AAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,GACpB,IAAI,CAyBN"}
@@ -10,7 +10,90 @@ exports.findTypesOrCorePackageInfo = findTypesOrCorePackageInfo;
10
10
  exports.createNameTransforms = createNameTransforms;
11
11
  exports.isPackageInstalled = isPackageInstalled;
12
12
  exports.checkIfRuntimeExists = checkIfRuntimeExists;
13
+ exports.getSubdirectoryFromScope = getSubdirectoryFromScope;
14
+ exports.extractSubdirectoryFromSourceRoot = extractSubdirectoryFromSourceRoot;
15
+ exports.extractPackageNameFromSourceRoot = extractPackageNameFromSourceRoot;
16
+ exports.addScriptToRootPackageJson = addScriptToRootPackageJson;
13
17
  const devkit_1 = require("@nx/devkit");
18
+ /**
19
+ * Extracts visual type names from a runtime.tsx file
20
+ * Looks for visualTypes object in the constructor's super() call
21
+ * Returns empty array if file doesn't exist or parsing fails
22
+ */
23
+ function extractVisualTypesFromRuntime(tree, runtimeSourceRoot) {
24
+ const runtimeFilePath = `${runtimeSourceRoot}/src/lib/runtime.tsx`;
25
+ // Check if runtime.tsx exists
26
+ if (!tree.exists(runtimeFilePath)) {
27
+ return [];
28
+ }
29
+ try {
30
+ // Read the file content
31
+ const content = tree.read(runtimeFilePath, 'utf-8');
32
+ if (!content) {
33
+ return [];
34
+ }
35
+ // Find the start of visualTypes
36
+ const visualTypesStart = content.indexOf('visualTypes:');
37
+ if (visualTypesStart === -1) {
38
+ return [];
39
+ }
40
+ // Find the opening brace after visualTypes
41
+ const openBraceIndex = content.indexOf('{', visualTypesStart);
42
+ if (openBraceIndex === -1) {
43
+ return [];
44
+ }
45
+ // Count braces to find the matching closing brace
46
+ let braceCount = 1;
47
+ let currentIndex = openBraceIndex + 1;
48
+ let closeBraceIndex = -1;
49
+ while (currentIndex < content.length && braceCount > 0) {
50
+ if (content[currentIndex] === '{') {
51
+ braceCount++;
52
+ }
53
+ else if (content[currentIndex] === '}') {
54
+ braceCount--;
55
+ if (braceCount === 0) {
56
+ closeBraceIndex = currentIndex;
57
+ break;
58
+ }
59
+ }
60
+ currentIndex++;
61
+ }
62
+ if (closeBraceIndex === -1) {
63
+ return [];
64
+ }
65
+ // Extract the content between the braces
66
+ const visualTypesContent = content.substring(openBraceIndex + 1, closeBraceIndex);
67
+ // Find the minimum indentation level (first-level properties)
68
+ const lines = visualTypesContent.split('\n');
69
+ const indentations = [];
70
+ for (const line of lines) {
71
+ const match = line.match(/^(\s*)(\w+)\s*:/);
72
+ if (match) {
73
+ indentations.push(match[1].length);
74
+ }
75
+ }
76
+ // If no properties found, return empty array
77
+ if (indentations.length === 0) {
78
+ return [];
79
+ }
80
+ // Find minimum indentation (first-level properties)
81
+ const minIndent = Math.min(...indentations);
82
+ // Extract visual names (only first-level properties with minimum indentation)
83
+ const visuals = [];
84
+ for (const line of lines) {
85
+ const match = line.match(/^(\s*)(\w+)\s*:/);
86
+ if (match && match[1].length === minIndent) {
87
+ visuals.push(match[2]);
88
+ }
89
+ }
90
+ return visuals;
91
+ }
92
+ catch (error) {
93
+ // If any error occurs during parsing, return empty array
94
+ return [];
95
+ }
96
+ }
14
97
  function validateUnisphereConfig(tree) {
15
98
  // Check if file exists
16
99
  if (!tree.exists('.unisphere')) {
@@ -45,9 +128,24 @@ function validateUnisphereConfig(tree) {
45
128
  ' "name": "your-experience-name"\n' +
46
129
  '}');
47
130
  }
131
+ // Extract runtimes with their visual types
132
+ const runtimes = {};
133
+ if (config.elements?.runtimes) {
134
+ for (const [runtimeName, runtimeConfig] of Object.entries(config.elements.runtimes)) {
135
+ const sourceRoot = runtimeConfig.sourceRoot;
136
+ if (sourceRoot && typeof sourceRoot === 'string') {
137
+ const visuals = extractVisualTypesFromRuntime(tree, sourceRoot);
138
+ runtimes[runtimeName] = {
139
+ sourceRoot,
140
+ visuals,
141
+ };
142
+ }
143
+ }
144
+ }
48
145
  return {
49
146
  company: config.company,
50
147
  name: config.name,
148
+ runtimes,
51
149
  };
52
150
  }
53
151
  function updateTsConfigPaths(tree, pathKey, pathValue) {
@@ -124,6 +222,28 @@ function validateRuntimeExists(tree, runtimeName) {
124
222
  }
125
223
  return runtimeConfig.sourceRoot;
126
224
  }
225
+ /**
226
+ * Checks if a path matches the core package pattern
227
+ * Supports both old (unisphere/packages/core) and new (unisphere/packages/<visibility>/core) patterns
228
+ */
229
+ function isCorePackagePath(pathValue) {
230
+ // Old pattern: unisphere/packages/core/src/index.ts
231
+ // New patterns with subdirectories
232
+ const corePatterns = [
233
+ 'unisphere/packages/local/core/src/index.ts',
234
+ 'unisphere/packages/kaltura-corp/core/src/index.ts',
235
+ 'unisphere/packages/unisphere/core/src/index.ts',
236
+ 'unisphere/packages/kaltura-ai/core/src/index.ts',
237
+ ];
238
+ return corePatterns.includes(pathValue);
239
+ }
240
+ /**
241
+ * Extracts the base path from a tsconfig path value
242
+ * e.g., "unisphere/packages/public/core/src/index.ts" -> "unisphere/packages/public/core"
243
+ */
244
+ function extractBasePath(pathValue) {
245
+ return pathValue.replace('/src/index.ts', '');
246
+ }
127
247
  function findCorePackageAlias(tree) {
128
248
  if (!tree.exists('tsconfig.base.json')) {
129
249
  throw new Error('tsconfig.base.json not found in the project root.');
@@ -133,19 +253,38 @@ function findCorePackageAlias(tree) {
133
253
  if (!tsconfigBase.compilerOptions?.paths) {
134
254
  throw new Error('No paths found in tsconfig.base.json compilerOptions.');
135
255
  }
136
- // Find the key that has the value "unisphere/packages/core/src/index.ts"
256
+ // Find the key that has a core package path (supports both old and new patterns)
137
257
  for (const [key, paths] of Object.entries(tsconfigBase.compilerOptions.paths)) {
138
- if (Array.isArray(paths) && paths.includes('unisphere/packages/core/src/index.ts')) {
258
+ if (Array.isArray(paths) && paths.some(p => isCorePackagePath(p))) {
139
259
  return key;
140
260
  }
141
261
  }
142
262
  throw new Error('Core package not found in tsconfig.base.json paths. ' +
143
- 'Expected to find a key with value "unisphere/packages/core/src/index.ts"');
263
+ 'Expected to find a key with value matching "unisphere/packages/[<visibility>/]core/src/index.ts"');
144
264
  }
145
265
  catch (error) {
146
266
  throw new Error(`Failed to read tsconfig.base.json: ${error instanceof Error ? error.message : 'Unknown error'}`);
147
267
  }
148
268
  }
269
+ /**
270
+ * Checks if a path matches the types package pattern
271
+ * Supports both old (unisphere/packages/types) and new (unisphere/packages/<visibility>/types) patterns
272
+ */
273
+ function isTypesPackagePath(pathValue) {
274
+ const typesPatterns = [
275
+ 'unisphere/packages/types/src/index.ts',
276
+ // Old subdirectory names (for backwards compatibility)
277
+ 'unisphere/packages/private/types/src/index.ts',
278
+ 'unisphere/packages/corp/types/src/index.ts',
279
+ 'unisphere/packages/public/types/src/index.ts',
280
+ // New subdirectory names (v3 migration)
281
+ 'unisphere/packages/local/types/src/index.ts',
282
+ 'unisphere/packages/kaltura-corp/types/src/index.ts',
283
+ 'unisphere/packages/unisphere/types/src/index.ts',
284
+ 'unisphere/packages/kaltura-ai/types/src/index.ts',
285
+ ];
286
+ return typesPatterns.includes(pathValue);
287
+ }
149
288
  /**
150
289
  * Tries to find the types package alias in tsconfig.base.json
151
290
  * Returns null if types package is not found
@@ -159,9 +298,9 @@ function findTypesPackageAlias(tree) {
159
298
  if (!tsconfigBase.compilerOptions?.paths) {
160
299
  return null;
161
300
  }
162
- // Find the key that has the value "unisphere/packages/types/src/index.ts"
301
+ // Find the key that has a types package path (supports both old and new patterns)
163
302
  for (const [key, paths] of Object.entries(tsconfigBase.compilerOptions.paths)) {
164
- if (Array.isArray(paths) && paths.includes('unisphere/packages/types/src/index.ts')) {
303
+ if (Array.isArray(paths) && paths.some(p => isTypesPackagePath(p))) {
165
304
  return key;
166
305
  }
167
306
  }
@@ -171,6 +310,32 @@ function findTypesPackageAlias(tree) {
171
310
  return null;
172
311
  }
173
312
  }
313
+ /**
314
+ * Finds the actual base path for a package from tsconfig.base.json
315
+ */
316
+ function findPackageBasePath(tree, pathMatcher) {
317
+ if (!tree.exists('tsconfig.base.json')) {
318
+ return null;
319
+ }
320
+ try {
321
+ const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
322
+ if (!tsconfigBase.compilerOptions?.paths) {
323
+ return null;
324
+ }
325
+ for (const [, paths] of Object.entries(tsconfigBase.compilerOptions.paths)) {
326
+ if (Array.isArray(paths)) {
327
+ const matchingPath = paths.find(p => pathMatcher(p));
328
+ if (matchingPath) {
329
+ return extractBasePath(matchingPath);
330
+ }
331
+ }
332
+ }
333
+ return null;
334
+ }
335
+ catch {
336
+ return null;
337
+ }
338
+ }
174
339
  /**
175
340
  * Finds the types package if it exists, otherwise falls back to core package.
176
341
  * Returns info about which package to use for runtime types.
@@ -178,21 +343,39 @@ function findTypesPackageAlias(tree) {
178
343
  function findTypesOrCorePackageInfo(tree) {
179
344
  const typesAlias = findTypesPackageAlias(tree);
180
345
  if (typesAlias) {
346
+ const basePath = findPackageBasePath(tree, isTypesPackagePath);
347
+ if (!basePath) {
348
+ throw new Error('Types package base path not found');
349
+ }
181
350
  return {
182
351
  alias: typesAlias,
183
- basePath: 'unisphere/packages/types',
352
+ basePath,
184
353
  hasTypesPackage: true,
185
354
  };
186
355
  }
187
356
  // Fallback to core package
188
357
  const coreAlias = findCorePackageAlias(tree);
358
+ const basePath = findPackageBasePath(tree, isCorePackagePath);
359
+ if (!basePath) {
360
+ throw new Error('Core package base path not found');
361
+ }
189
362
  return {
190
363
  alias: coreAlias,
191
- basePath: 'unisphere/packages/core',
364
+ basePath,
192
365
  hasTypesPackage: false,
193
366
  };
194
367
  }
195
368
  function createNameTransforms(baseName, prefix) {
369
+ if (!baseName) {
370
+ return {
371
+ [`${prefix}`]: '',
372
+ [`${prefix}__lowerDashCase`]: '',
373
+ [`${prefix}__camelCase`]: '',
374
+ [`${prefix}__pascalCase`]: '',
375
+ [`${prefix}__constantCase`]: '',
376
+ [`${prefix}__humanReadable`]: '',
377
+ }; // Type assertion to match the defined type
378
+ }
196
379
  const nameVariants = (0, devkit_1.names)(baseName); // Assuming 'names' function is available and returns NameVariants
197
380
  const humanReadable = baseName
198
381
  .replace(/[-_]/g, ' ')
@@ -244,3 +427,71 @@ function checkIfRuntimeExists(tree, runtimeName) {
244
427
  return false;
245
428
  }
246
429
  }
430
+ /**
431
+ * Maps package scope to subdirectory name
432
+ * @param scope - The package scope ('public', 'internal', 'none')
433
+ * @returns The subdirectory name ('unisphere', 'kaltura-corp', 'local')
434
+ */
435
+ function getSubdirectoryFromScope(scope) {
436
+ const scopeToSubdirectory = {
437
+ 'public': 'unisphere',
438
+ 'internal': 'kaltura-corp',
439
+ 'none': 'local',
440
+ 'kaltura-ai': 'kaltura-ai',
441
+ };
442
+ return scopeToSubdirectory[scope];
443
+ }
444
+ /**
445
+ * Extracts the subdirectory from a package sourceRoot path
446
+ * @param sourceRoot - The sourceRoot path (e.g., "unisphere/packages/kaltura-corp/shared")
447
+ * @returns The subdirectory name ('unisphere', 'kaltura-corp', 'local') or null if flat structure
448
+ */
449
+ function extractSubdirectoryFromSourceRoot(sourceRoot) {
450
+ const parts = sourceRoot.split('/');
451
+ // Expected format: unisphere/packages/<subdirectory>/<packageName>
452
+ // Or old format: unisphere/packages/<packageName>
453
+ if (parts.length === 4 && parts[0] === 'unisphere' && parts[1] === 'packages') {
454
+ const subdirectory = parts[2];
455
+ if (['local', 'kaltura-corp', 'unisphere', 'kaltura-ai'].includes(subdirectory)) {
456
+ return subdirectory;
457
+ }
458
+ }
459
+ return null; // Flat structure
460
+ }
461
+ /**
462
+ * Extracts the package name from a package sourceRoot path
463
+ * @param sourceRoot - The sourceRoot path (e.g., "unisphere/packages/corp/shared" or "unisphere/packages/shared")
464
+ * @returns The package name
465
+ */
466
+ function extractPackageNameFromSourceRoot(sourceRoot) {
467
+ const parts = sourceRoot.split('/');
468
+ // Return the last part of the path
469
+ return parts[parts.length - 1];
470
+ }
471
+ /**
472
+ * Adds a script to the root package.json
473
+ * @param tree - The file system tree
474
+ * @param scriptName - The name of the script (e.g., "dev:my-app")
475
+ * @param scriptCommand - The command to run (e.g., "npx unisphere application serve my-app --port 4002")
476
+ */
477
+ function addScriptToRootPackageJson(tree, scriptName, scriptCommand) {
478
+ if (!tree.exists('package.json')) {
479
+ devkit_1.logger.warn('⚠️ package.json not found in root directory, cannot add script');
480
+ return;
481
+ }
482
+ try {
483
+ const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
484
+ // Ensure scripts object exists
485
+ if (!packageJson.scripts) {
486
+ packageJson.scripts = {};
487
+ }
488
+ // Only add if script doesn't already exist
489
+ if (!packageJson.scripts[scriptName]) {
490
+ packageJson.scripts[scriptName] = scriptCommand;
491
+ (0, devkit_1.writeJson)(tree, 'package.json', packageJson);
492
+ }
493
+ }
494
+ catch (error) {
495
+ devkit_1.logger.warn(`⚠️ Failed to add script to package.json: ${error instanceof Error ? error.message : 'Unknown error'}`);
496
+ }
497
+ }