@ng-shangjc/cli 1.0.0-beta → 1.0.1-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 +26 -12
- package/package.json +1 -1
- package/src/commands/install.ts +32 -15
package/dist/commands/install.js
CHANGED
|
@@ -199,22 +199,21 @@ async function installComponent(componentName, options) {
|
|
|
199
199
|
const indexContent = generateIndexFile(componentName, files, config.componentType);
|
|
200
200
|
await fs.writeFile(path.join(destDir, 'index.ts'), indexContent);
|
|
201
201
|
console.log(`✅ Created index.ts`);
|
|
202
|
-
// Copy README
|
|
203
|
-
const readmePath = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'README.md');
|
|
204
|
-
if (await fs.pathExists(readmePath)) {
|
|
205
|
-
await fs.copy(readmePath, path.join(destDir, 'README.md'));
|
|
206
|
-
console.log(`✅ Copied README.md`);
|
|
207
|
-
}
|
|
208
202
|
// Update configuration
|
|
209
203
|
if (!config.installedComponents.includes(componentName)) {
|
|
210
204
|
config.installedComponents.push(componentName);
|
|
211
205
|
await fs.writeJson(configPath, config, { spaces: 2 });
|
|
212
206
|
console.log(`✅ Updated shangjc.config.json`);
|
|
213
207
|
}
|
|
208
|
+
// Create/update barrel index.ts in the main ui/shangjc folder
|
|
209
|
+
await createOrUpdateBarrelIndex(config.componentsPath, config.installedComponents);
|
|
214
210
|
console.log(`🎉 Successfully installed ${componentName} component!`);
|
|
215
211
|
console.log(`\n📁 Files installed to: ${destDir}`);
|
|
216
212
|
console.log(`\n📖 Usage:`);
|
|
213
|
+
console.log(`// Individual import:`);
|
|
217
214
|
console.log(`import { ${getComponentClassName(componentName)} } from './${componentsPath}/${componentName}';`);
|
|
215
|
+
console.log(`// Or barrel import (if multiple components):`);
|
|
216
|
+
console.log(`import { ${getComponentClassName(componentName)} } from './${componentsPath}';`);
|
|
218
217
|
}
|
|
219
218
|
catch (error) {
|
|
220
219
|
console.error('❌ Installation failed:', error);
|
|
@@ -297,12 +296,6 @@ async function downloadComponentFiles(componentName) {
|
|
|
297
296
|
if (fs.existsSync(sourceDir)) {
|
|
298
297
|
fs.copySync(sourceDir, targetDir);
|
|
299
298
|
}
|
|
300
|
-
// Copy README if exists
|
|
301
|
-
const readmeSource = path.join(tempDir, 'README.md');
|
|
302
|
-
const readmeTarget = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'README.md');
|
|
303
|
-
if (fs.existsSync(readmeSource)) {
|
|
304
|
-
fs.copySync(readmeSource, readmeTarget);
|
|
305
|
-
}
|
|
306
299
|
// Clean up temp files
|
|
307
300
|
fs.removeSync(tempDir);
|
|
308
301
|
resolve();
|
|
@@ -330,3 +323,24 @@ ${exports}
|
|
|
330
323
|
function getComponentClassName(componentName) {
|
|
331
324
|
return componentName.charAt(0).toUpperCase() + componentName.slice(1) + 'Component';
|
|
332
325
|
}
|
|
326
|
+
async function createOrUpdateBarrelIndex(componentsPath, installedComponents) {
|
|
327
|
+
const barrelDir = path.join(process.cwd(), componentsPath);
|
|
328
|
+
const barrelPath = path.join(barrelDir, 'index.ts');
|
|
329
|
+
// Ensure the directory exists
|
|
330
|
+
await fs.ensureDir(barrelDir);
|
|
331
|
+
// Generate barrel content
|
|
332
|
+
const exports = installedComponents
|
|
333
|
+
.sort() // Sort for consistent ordering
|
|
334
|
+
.map(component => {
|
|
335
|
+
const className = getComponentClassName(component);
|
|
336
|
+
return `export { ${className} } from './${component}';`;
|
|
337
|
+
})
|
|
338
|
+
.join('\n');
|
|
339
|
+
const barrelContent = `// Generated by ng-shangjc CLI
|
|
340
|
+
// Barrel exports for all installed components
|
|
341
|
+
|
|
342
|
+
${exports}
|
|
343
|
+
`;
|
|
344
|
+
await fs.writeFile(barrelPath, barrelContent);
|
|
345
|
+
console.log(`✅ Updated barrel index.ts at ${componentsPath}`);
|
|
346
|
+
}
|
package/package.json
CHANGED
package/src/commands/install.ts
CHANGED
|
@@ -198,13 +198,6 @@ export async function installComponent(
|
|
|
198
198
|
await fs.writeFile(path.join(destDir, 'index.ts'), indexContent);
|
|
199
199
|
console.log(`✅ Created index.ts`);
|
|
200
200
|
|
|
201
|
-
// Copy README
|
|
202
|
-
const readmePath = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'README.md');
|
|
203
|
-
if (await fs.pathExists(readmePath)) {
|
|
204
|
-
await fs.copy(readmePath, path.join(destDir, 'README.md'));
|
|
205
|
-
console.log(`✅ Copied README.md`);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
201
|
// Update configuration
|
|
209
202
|
if (!config.installedComponents.includes(componentName)) {
|
|
210
203
|
config.installedComponents.push(componentName);
|
|
@@ -212,10 +205,16 @@ export async function installComponent(
|
|
|
212
205
|
console.log(`✅ Updated shangjc.config.json`);
|
|
213
206
|
}
|
|
214
207
|
|
|
208
|
+
// Create/update barrel index.ts in the main ui/shangjc folder
|
|
209
|
+
await createOrUpdateBarrelIndex(config.componentsPath, config.installedComponents);
|
|
210
|
+
|
|
215
211
|
console.log(`🎉 Successfully installed ${componentName} component!`);
|
|
216
212
|
console.log(`\n📁 Files installed to: ${destDir}`);
|
|
217
213
|
console.log(`\n📖 Usage:`);
|
|
214
|
+
console.log(`// Individual import:`);
|
|
218
215
|
console.log(`import { ${getComponentClassName(componentName)} } from './${componentsPath}/${componentName}';`);
|
|
216
|
+
console.log(`// Or barrel import (if multiple components):`);
|
|
217
|
+
console.log(`import { ${getComponentClassName(componentName)} } from './${componentsPath}';`);
|
|
219
218
|
|
|
220
219
|
} catch (error) {
|
|
221
220
|
console.error('❌ Installation failed:', error);
|
|
@@ -311,14 +310,6 @@ async function downloadComponentFiles(componentName: string) {
|
|
|
311
310
|
fs.copySync(sourceDir, targetDir);
|
|
312
311
|
}
|
|
313
312
|
|
|
314
|
-
// Copy README if exists
|
|
315
|
-
const readmeSource = path.join(tempDir, 'README.md');
|
|
316
|
-
const readmeTarget = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'README.md');
|
|
317
|
-
|
|
318
|
-
if (fs.existsSync(readmeSource)) {
|
|
319
|
-
fs.copySync(readmeSource, readmeTarget);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
313
|
// Clean up temp files
|
|
323
314
|
fs.removeSync(tempDir);
|
|
324
315
|
|
|
@@ -349,4 +340,30 @@ ${exports}
|
|
|
349
340
|
|
|
350
341
|
function getComponentClassName(componentName: string): string {
|
|
351
342
|
return componentName.charAt(0).toUpperCase() + componentName.slice(1) + 'Component';
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function createOrUpdateBarrelIndex(componentsPath: string, installedComponents: string[]) {
|
|
346
|
+
const barrelDir = path.join(process.cwd(), componentsPath);
|
|
347
|
+
const barrelPath = path.join(barrelDir, 'index.ts');
|
|
348
|
+
|
|
349
|
+
// Ensure the directory exists
|
|
350
|
+
await fs.ensureDir(barrelDir);
|
|
351
|
+
|
|
352
|
+
// Generate barrel content
|
|
353
|
+
const exports = installedComponents
|
|
354
|
+
.sort() // Sort for consistent ordering
|
|
355
|
+
.map(component => {
|
|
356
|
+
const className = getComponentClassName(component);
|
|
357
|
+
return `export { ${className} } from './${component}';`;
|
|
358
|
+
})
|
|
359
|
+
.join('\n');
|
|
360
|
+
|
|
361
|
+
const barrelContent = `// Generated by ng-shangjc CLI
|
|
362
|
+
// Barrel exports for all installed components
|
|
363
|
+
|
|
364
|
+
${exports}
|
|
365
|
+
`;
|
|
366
|
+
|
|
367
|
+
await fs.writeFile(barrelPath, barrelContent);
|
|
368
|
+
console.log(`✅ Updated barrel index.ts at ${componentsPath}`);
|
|
352
369
|
}
|