@ng-shangjc/cli 1.0.1-beta → 1.0.3-beta

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.
@@ -56,7 +56,7 @@ const AVAILABLE_COMPONENTS = [
56
56
  'alert'
57
57
  ];
58
58
  const COMPONENT_DEPENDENCIES = {
59
- button: ['utils'],
59
+ button: ['utils', 'class-variance-authority'],
60
60
  input: ['utils'],
61
61
  card: ['utils'],
62
62
  switch: ['utils'],
@@ -171,12 +171,17 @@ async function installComponent(componentName, options) {
171
171
  return;
172
172
  }
173
173
  try {
174
- // Install dependencies first
174
+ // Install the component package itself first
175
+ await installComponentPackage(componentName);
176
+ // Install dependencies after component package is available
175
177
  if (dependencies.includes('utils')) {
176
178
  await installUtils();
177
179
  }
178
- // Install the component package itself
179
- await installComponentPackage(componentName);
180
+ // Install external dependencies (non-utils)
181
+ const externalDeps = dependencies.filter(dep => dep !== 'utils');
182
+ if (externalDeps.length > 0) {
183
+ await installExternalDependencies(externalDeps, componentName);
184
+ }
180
185
  // Create destination directory
181
186
  const destDir = path.join(process.cwd(), componentsPath, componentName);
182
187
  await fs.ensureDir(destDir);
@@ -238,6 +243,42 @@ async function installUtils() {
238
243
  throw error;
239
244
  }
240
245
  }
246
+ async function installExternalDependencies(dependencies, componentName) {
247
+ // Read the component's package.json to get exact versions
248
+ const componentPackagePath = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'package.json');
249
+ let componentPackage;
250
+ try {
251
+ componentPackage = await fs.readJson(componentPackagePath);
252
+ }
253
+ catch (error) {
254
+ console.error(`❌ Failed to read component package.json:`, error);
255
+ throw error;
256
+ }
257
+ for (const dependency of dependencies) {
258
+ console.log(`📦 Installing ${dependency} dependency...`);
259
+ try {
260
+ // Get the exact version from component's peerDependencies or dependencies
261
+ const version = componentPackage.peerDependencies?.[dependency] || componentPackage.dependencies?.[dependency];
262
+ if (!version) {
263
+ console.warn(`⚠️ Could not find version for ${dependency} in component package.json, installing latest...`);
264
+ }
265
+ // Check if dependency is already installed in node_modules
266
+ const depPath = path.join(process.cwd(), 'node_modules', dependency);
267
+ if (!fs.existsSync(depPath)) {
268
+ const installSpec = version ? `${dependency}@${version}` : dependency;
269
+ console.log(`Installing ${installSpec}...`);
270
+ (0, child_process_1.execSync)(`npm install ${installSpec}`, { stdio: 'inherit' });
271
+ }
272
+ else {
273
+ console.log(`✅ ${dependency} already installed`);
274
+ }
275
+ }
276
+ catch (error) {
277
+ console.error(`❌ Failed to install ${dependency}:`, error);
278
+ throw error;
279
+ }
280
+ }
281
+ }
241
282
  async function installComponentPackage(componentName) {
242
283
  console.log(`📦 Installing ${componentName} package...`);
243
284
  try {
@@ -296,6 +337,12 @@ async function downloadComponentFiles(componentName) {
296
337
  if (fs.existsSync(sourceDir)) {
297
338
  fs.copySync(sourceDir, targetDir);
298
339
  }
340
+ // Copy package.json to node_modules structure
341
+ const packageSource = path.join(tempDir, 'package.json');
342
+ const packageTarget = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'package.json');
343
+ if (fs.existsSync(packageSource)) {
344
+ fs.copySync(packageSource, packageTarget);
345
+ }
299
346
  // Clean up temp files
300
347
  fs.removeSync(tempDir);
301
348
  resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-shangjc/cli",
3
- "version": "1.0.1-beta",
3
+ "version": "1.0.3-beta",
4
4
  "bin": {
5
5
  "ng-shangjc": "./dist/index.js"
6
6
  },
@@ -33,7 +33,7 @@ const AVAILABLE_COMPONENTS = [
33
33
  ];
34
34
 
35
35
  const COMPONENT_DEPENDENCIES = {
36
- button: ['utils'],
36
+ button: ['utils', 'class-variance-authority'],
37
37
  input: ['utils'],
38
38
  card: ['utils'],
39
39
  switch: ['utils'],
@@ -163,13 +163,19 @@ export async function installComponent(
163
163
  }
164
164
 
165
165
  try {
166
- // Install dependencies first
166
+ // Install the component package itself first
167
+ await installComponentPackage(componentName);
168
+
169
+ // Install dependencies after component package is available
167
170
  if (dependencies.includes('utils')) {
168
171
  await installUtils();
169
172
  }
170
173
 
171
- // Install the component package itself
172
- await installComponentPackage(componentName);
174
+ // Install external dependencies (non-utils)
175
+ const externalDeps = dependencies.filter(dep => dep !== 'utils');
176
+ if (externalDeps.length > 0) {
177
+ await installExternalDependencies(externalDeps, componentName);
178
+ }
173
179
 
174
180
  // Create destination directory
175
181
  const destDir = path.join(process.cwd(), componentsPath, componentName);
@@ -241,6 +247,45 @@ async function installUtils() {
241
247
  }
242
248
  }
243
249
 
250
+ async function installExternalDependencies(dependencies: string[], componentName: string) {
251
+ // Read the component's package.json to get exact versions
252
+ const componentPackagePath = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'package.json');
253
+ let componentPackage: any;
254
+
255
+ try {
256
+ componentPackage = await fs.readJson(componentPackagePath);
257
+ } catch (error) {
258
+ console.error(`❌ Failed to read component package.json:`, error);
259
+ throw error;
260
+ }
261
+
262
+ for (const dependency of dependencies) {
263
+ console.log(`📦 Installing ${dependency} dependency...`);
264
+
265
+ try {
266
+ // Get the exact version from component's peerDependencies or dependencies
267
+ const version = componentPackage.peerDependencies?.[dependency] || componentPackage.dependencies?.[dependency];
268
+ if (!version) {
269
+ console.warn(`⚠️ Could not find version for ${dependency} in component package.json, installing latest...`);
270
+ }
271
+
272
+ // Check if dependency is already installed in node_modules
273
+ const depPath = path.join(process.cwd(), 'node_modules', dependency);
274
+
275
+ if (!fs.existsSync(depPath)) {
276
+ const installSpec = version ? `${dependency}@${version}` : dependency;
277
+ console.log(`Installing ${installSpec}...`);
278
+ execSync(`npm install ${installSpec}`, { stdio: 'inherit' });
279
+ } else {
280
+ console.log(`✅ ${dependency} already installed`);
281
+ }
282
+ } catch (error) {
283
+ console.error(`❌ Failed to install ${dependency}:`, error);
284
+ throw error;
285
+ }
286
+ }
287
+ }
288
+
244
289
  async function installComponentPackage(componentName: string) {
245
290
  console.log(`📦 Installing ${componentName} package...`);
246
291
 
@@ -310,6 +355,14 @@ async function downloadComponentFiles(componentName: string) {
310
355
  fs.copySync(sourceDir, targetDir);
311
356
  }
312
357
 
358
+ // Copy package.json to node_modules structure
359
+ const packageSource = path.join(tempDir, 'package.json');
360
+ const packageTarget = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'package.json');
361
+
362
+ if (fs.existsSync(packageSource)) {
363
+ fs.copySync(packageSource, packageTarget);
364
+ }
365
+
313
366
  // Clean up temp files
314
367
  fs.removeSync(tempDir);
315
368