@ng-shangjc/cli 1.0.1-beta → 1.0.2-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.
- package/dist/commands/install.js +48 -1
- package/package.json +1 -1
- package/src/commands/install.ts +54 -1
package/dist/commands/install.js
CHANGED
|
@@ -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'],
|
|
@@ -175,6 +175,11 @@ async function installComponent(componentName, options) {
|
|
|
175
175
|
if (dependencies.includes('utils')) {
|
|
176
176
|
await installUtils();
|
|
177
177
|
}
|
|
178
|
+
// Install external dependencies (non-utils)
|
|
179
|
+
const externalDeps = dependencies.filter(dep => dep !== 'utils');
|
|
180
|
+
if (externalDeps.length > 0) {
|
|
181
|
+
await installExternalDependencies(externalDeps, componentName);
|
|
182
|
+
}
|
|
178
183
|
// Install the component package itself
|
|
179
184
|
await installComponentPackage(componentName);
|
|
180
185
|
// Create destination directory
|
|
@@ -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
package/src/commands/install.ts
CHANGED
|
@@ -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'],
|
|
@@ -168,6 +168,12 @@ export async function installComponent(
|
|
|
168
168
|
await installUtils();
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
// Install external dependencies (non-utils)
|
|
172
|
+
const externalDeps = dependencies.filter(dep => dep !== 'utils');
|
|
173
|
+
if (externalDeps.length > 0) {
|
|
174
|
+
await installExternalDependencies(externalDeps, componentName);
|
|
175
|
+
}
|
|
176
|
+
|
|
171
177
|
// Install the component package itself
|
|
172
178
|
await installComponentPackage(componentName);
|
|
173
179
|
|
|
@@ -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
|
|