@ng-shangjc/cli 1.0.0 → 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 +104 -21
- package/package.json +3 -2
- package/src/commands/install.ts +124 -22
package/dist/commands/install.js
CHANGED
|
@@ -71,30 +71,24 @@ const COMPONENT_DEPENDENCIES = {
|
|
|
71
71
|
};
|
|
72
72
|
const COMPONENT_FILES = {
|
|
73
73
|
button: [
|
|
74
|
-
'button.component.ts'
|
|
75
|
-
'button.metadata.ts'
|
|
74
|
+
'button.component.ts'
|
|
76
75
|
],
|
|
77
76
|
input: [
|
|
78
|
-
'input.component.ts'
|
|
79
|
-
'input.metadata.ts'
|
|
77
|
+
'input.component.ts'
|
|
80
78
|
],
|
|
81
79
|
card: [
|
|
82
|
-
'card.component.ts'
|
|
83
|
-
'card.metadata.ts'
|
|
80
|
+
'card.component.ts'
|
|
84
81
|
],
|
|
85
82
|
switch: [
|
|
86
|
-
'switch.component.ts'
|
|
87
|
-
'switch.metadata.ts'
|
|
83
|
+
'switch.component.ts'
|
|
88
84
|
],
|
|
89
85
|
dialog: [
|
|
90
86
|
'dialog.component.ts',
|
|
91
|
-
'dialog.service.ts'
|
|
92
|
-
'dialog.metadata.ts'
|
|
87
|
+
'dialog.service.ts'
|
|
93
88
|
],
|
|
94
89
|
tooltip: [
|
|
95
90
|
'tooltip.component.ts',
|
|
96
|
-
'tooltip.directive.ts'
|
|
97
|
-
'tooltip.metadata.ts'
|
|
91
|
+
'tooltip.directive.ts'
|
|
98
92
|
],
|
|
99
93
|
select: [
|
|
100
94
|
'select.component.ts'
|
|
@@ -181,11 +175,13 @@ async function installComponent(componentName, options) {
|
|
|
181
175
|
if (dependencies.includes('utils')) {
|
|
182
176
|
await installUtils();
|
|
183
177
|
}
|
|
178
|
+
// Install the component package itself
|
|
179
|
+
await installComponentPackage(componentName);
|
|
184
180
|
// Create destination directory
|
|
185
181
|
const destDir = path.join(process.cwd(), componentsPath, componentName);
|
|
186
182
|
await fs.ensureDir(destDir);
|
|
187
|
-
// Get source directory
|
|
188
|
-
const sourceDir = path.join(
|
|
183
|
+
// Get source directory from installed npm package
|
|
184
|
+
const sourceDir = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'src', 'lib');
|
|
189
185
|
// Copy component files
|
|
190
186
|
const files = COMPONENT_FILES[componentName];
|
|
191
187
|
for (const file of files) {
|
|
@@ -203,22 +199,21 @@ async function installComponent(componentName, options) {
|
|
|
203
199
|
const indexContent = generateIndexFile(componentName, files, config.componentType);
|
|
204
200
|
await fs.writeFile(path.join(destDir, 'index.ts'), indexContent);
|
|
205
201
|
console.log(`✅ Created index.ts`);
|
|
206
|
-
// Copy README
|
|
207
|
-
const readmePath = path.join(__dirname, '..', '..', '..', 'packages', componentName, 'README.md');
|
|
208
|
-
if (await fs.pathExists(readmePath)) {
|
|
209
|
-
await fs.copy(readmePath, path.join(destDir, 'README.md'));
|
|
210
|
-
console.log(`✅ Copied README.md`);
|
|
211
|
-
}
|
|
212
202
|
// Update configuration
|
|
213
203
|
if (!config.installedComponents.includes(componentName)) {
|
|
214
204
|
config.installedComponents.push(componentName);
|
|
215
205
|
await fs.writeJson(configPath, config, { spaces: 2 });
|
|
216
206
|
console.log(`✅ Updated shangjc.config.json`);
|
|
217
207
|
}
|
|
208
|
+
// Create/update barrel index.ts in the main ui/shangjc folder
|
|
209
|
+
await createOrUpdateBarrelIndex(config.componentsPath, config.installedComponents);
|
|
218
210
|
console.log(`🎉 Successfully installed ${componentName} component!`);
|
|
219
211
|
console.log(`\n📁 Files installed to: ${destDir}`);
|
|
220
212
|
console.log(`\n📖 Usage:`);
|
|
213
|
+
console.log(`// Individual import:`);
|
|
221
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}';`);
|
|
222
217
|
}
|
|
223
218
|
catch (error) {
|
|
224
219
|
console.error('❌ Installation failed:', error);
|
|
@@ -232,7 +227,7 @@ async function installUtils() {
|
|
|
232
227
|
const utilsPath = path.join(process.cwd(), 'node_modules', '@ng-shangjc', 'utils');
|
|
233
228
|
if (!fs.existsSync(utilsPath)) {
|
|
234
229
|
console.log('Installing @ng-shangjc/utils...');
|
|
235
|
-
(0, child_process_1.execSync)('npm install @ng-shangjc/utils', { stdio: 'inherit' });
|
|
230
|
+
(0, child_process_1.execSync)('npm install --save-dev @ng-shangjc/utils', { stdio: 'inherit' });
|
|
236
231
|
}
|
|
237
232
|
else {
|
|
238
233
|
console.log('✅ @ng-shangjc/utils already installed');
|
|
@@ -243,6 +238,73 @@ async function installUtils() {
|
|
|
243
238
|
throw error;
|
|
244
239
|
}
|
|
245
240
|
}
|
|
241
|
+
async function installComponentPackage(componentName) {
|
|
242
|
+
console.log(`📦 Installing ${componentName} package...`);
|
|
243
|
+
try {
|
|
244
|
+
// Check if component is already installed in node_modules
|
|
245
|
+
const componentPath = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName);
|
|
246
|
+
if (!fs.existsSync(componentPath)) {
|
|
247
|
+
console.log(`Installing @ng-shangjc/${componentName}...`);
|
|
248
|
+
(0, child_process_1.execSync)(`npm install --save-dev @ng-shangjc/${componentName}`, { stdio: 'inherit' });
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
console.log(`✅ @ng-shangjc/${componentName} already installed`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
console.error(`❌ Failed to install ${componentName} package:`, error);
|
|
256
|
+
console.log(`🔄 Attempting to download files directly...`);
|
|
257
|
+
// Fallback: try to download files directly from npm registry
|
|
258
|
+
try {
|
|
259
|
+
await downloadComponentFiles(componentName);
|
|
260
|
+
console.log(`✅ Successfully downloaded ${componentName} files directly`);
|
|
261
|
+
}
|
|
262
|
+
catch (downloadError) {
|
|
263
|
+
console.error(`❌ Failed to download ${componentName} files:`, downloadError);
|
|
264
|
+
throw new Error(`Failed to install ${componentName}: Package installation and direct download both failed`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async function downloadComponentFiles(componentName) {
|
|
269
|
+
const https = require('https');
|
|
270
|
+
const tar = require('tar');
|
|
271
|
+
return new Promise((resolve, reject) => {
|
|
272
|
+
const packageUrl = `https://registry.npmjs.org/@ng-shangjc/${componentName}/-/${componentName}-1.0.0.tgz`;
|
|
273
|
+
const tempDir = path.join(process.cwd(), '.ng-shangjc-temp');
|
|
274
|
+
// Ensure temp directory exists
|
|
275
|
+
fs.ensureDirSync(tempDir);
|
|
276
|
+
const file = fs.createWriteStream(path.join(tempDir, `${componentName}.tgz`));
|
|
277
|
+
https.get(packageUrl, (response) => {
|
|
278
|
+
if (response.statusCode !== 200) {
|
|
279
|
+
reject(new Error(`Failed to download package: ${response.statusCode}`));
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
response.pipe(file);
|
|
283
|
+
file.on('finish', () => {
|
|
284
|
+
file.close();
|
|
285
|
+
// Extract the tarball
|
|
286
|
+
fs.createReadStream(path.join(tempDir, `${componentName}.tgz`))
|
|
287
|
+
.pipe(tar.extract({
|
|
288
|
+
cwd: tempDir,
|
|
289
|
+
strip: 1 // Remove the package folder
|
|
290
|
+
}))
|
|
291
|
+
.on('finish', () => {
|
|
292
|
+
// Copy the extracted files to node_modules structure
|
|
293
|
+
const sourceDir = path.join(tempDir, 'src', 'lib');
|
|
294
|
+
const targetDir = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'src', 'lib');
|
|
295
|
+
fs.ensureDirSync(path.dirname(targetDir));
|
|
296
|
+
if (fs.existsSync(sourceDir)) {
|
|
297
|
+
fs.copySync(sourceDir, targetDir);
|
|
298
|
+
}
|
|
299
|
+
// Clean up temp files
|
|
300
|
+
fs.removeSync(tempDir);
|
|
301
|
+
resolve();
|
|
302
|
+
})
|
|
303
|
+
.on('error', reject);
|
|
304
|
+
});
|
|
305
|
+
}).on('error', reject);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
246
308
|
function generateIndexFile(componentName, files, mode) {
|
|
247
309
|
const exports = files
|
|
248
310
|
.filter(file => file.endsWith('.ts'))
|
|
@@ -261,3 +323,24 @@ ${exports}
|
|
|
261
323
|
function getComponentClassName(componentName) {
|
|
262
324
|
return componentName.charAt(0).toUpperCase() + componentName.slice(1) + 'Component';
|
|
263
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-shangjc/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-beta",
|
|
4
4
|
"bin": {
|
|
5
5
|
"ng-shangjc": "./dist/index.js"
|
|
6
6
|
},
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"commander": "^11.0.0",
|
|
13
13
|
"fs-extra": "^11.0.0",
|
|
14
|
-
"inquirer": "^9.0.0"
|
|
14
|
+
"inquirer": "^9.0.0",
|
|
15
|
+
"tar": "^6.0.0"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@types/fs-extra": "^11.0.0",
|
package/src/commands/install.ts
CHANGED
|
@@ -49,30 +49,24 @@ const COMPONENT_DEPENDENCIES = {
|
|
|
49
49
|
|
|
50
50
|
const COMPONENT_FILES = {
|
|
51
51
|
button: [
|
|
52
|
-
'button.component.ts'
|
|
53
|
-
'button.metadata.ts'
|
|
52
|
+
'button.component.ts'
|
|
54
53
|
],
|
|
55
54
|
input: [
|
|
56
|
-
'input.component.ts'
|
|
57
|
-
'input.metadata.ts'
|
|
55
|
+
'input.component.ts'
|
|
58
56
|
],
|
|
59
57
|
card: [
|
|
60
|
-
'card.component.ts'
|
|
61
|
-
'card.metadata.ts'
|
|
58
|
+
'card.component.ts'
|
|
62
59
|
],
|
|
63
60
|
switch: [
|
|
64
|
-
'switch.component.ts'
|
|
65
|
-
'switch.metadata.ts'
|
|
61
|
+
'switch.component.ts'
|
|
66
62
|
],
|
|
67
63
|
dialog: [
|
|
68
64
|
'dialog.component.ts',
|
|
69
|
-
'dialog.service.ts'
|
|
70
|
-
'dialog.metadata.ts'
|
|
65
|
+
'dialog.service.ts'
|
|
71
66
|
],
|
|
72
67
|
tooltip: [
|
|
73
68
|
'tooltip.component.ts',
|
|
74
|
-
'tooltip.directive.ts'
|
|
75
|
-
'tooltip.metadata.ts'
|
|
69
|
+
'tooltip.directive.ts'
|
|
76
70
|
],
|
|
77
71
|
select: [
|
|
78
72
|
'select.component.ts'
|
|
@@ -174,12 +168,15 @@ export async function installComponent(
|
|
|
174
168
|
await installUtils();
|
|
175
169
|
}
|
|
176
170
|
|
|
171
|
+
// Install the component package itself
|
|
172
|
+
await installComponentPackage(componentName);
|
|
173
|
+
|
|
177
174
|
// Create destination directory
|
|
178
175
|
const destDir = path.join(process.cwd(), componentsPath, componentName);
|
|
179
176
|
await fs.ensureDir(destDir);
|
|
180
177
|
|
|
181
|
-
// Get source directory
|
|
182
|
-
const sourceDir = path.join(
|
|
178
|
+
// Get source directory from installed npm package
|
|
179
|
+
const sourceDir = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'src', 'lib');
|
|
183
180
|
|
|
184
181
|
// Copy component files
|
|
185
182
|
const files = COMPONENT_FILES[componentName as keyof typeof COMPONENT_FILES];
|
|
@@ -201,13 +198,6 @@ export async function installComponent(
|
|
|
201
198
|
await fs.writeFile(path.join(destDir, 'index.ts'), indexContent);
|
|
202
199
|
console.log(`✅ Created index.ts`);
|
|
203
200
|
|
|
204
|
-
// Copy README
|
|
205
|
-
const readmePath = path.join(__dirname, '..', '..', '..', 'packages', componentName, 'README.md');
|
|
206
|
-
if (await fs.pathExists(readmePath)) {
|
|
207
|
-
await fs.copy(readmePath, path.join(destDir, 'README.md'));
|
|
208
|
-
console.log(`✅ Copied README.md`);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
201
|
// Update configuration
|
|
212
202
|
if (!config.installedComponents.includes(componentName)) {
|
|
213
203
|
config.installedComponents.push(componentName);
|
|
@@ -215,10 +205,16 @@ export async function installComponent(
|
|
|
215
205
|
console.log(`✅ Updated shangjc.config.json`);
|
|
216
206
|
}
|
|
217
207
|
|
|
208
|
+
// Create/update barrel index.ts in the main ui/shangjc folder
|
|
209
|
+
await createOrUpdateBarrelIndex(config.componentsPath, config.installedComponents);
|
|
210
|
+
|
|
218
211
|
console.log(`🎉 Successfully installed ${componentName} component!`);
|
|
219
212
|
console.log(`\n📁 Files installed to: ${destDir}`);
|
|
220
213
|
console.log(`\n📖 Usage:`);
|
|
214
|
+
console.log(`// Individual import:`);
|
|
221
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}';`);
|
|
222
218
|
|
|
223
219
|
} catch (error) {
|
|
224
220
|
console.error('❌ Installation failed:', error);
|
|
@@ -235,7 +231,7 @@ async function installUtils() {
|
|
|
235
231
|
|
|
236
232
|
if (!fs.existsSync(utilsPath)) {
|
|
237
233
|
console.log('Installing @ng-shangjc/utils...');
|
|
238
|
-
execSync('npm install @ng-shangjc/utils', { stdio: 'inherit' });
|
|
234
|
+
execSync('npm install --save-dev @ng-shangjc/utils', { stdio: 'inherit' });
|
|
239
235
|
} else {
|
|
240
236
|
console.log('✅ @ng-shangjc/utils already installed');
|
|
241
237
|
}
|
|
@@ -245,6 +241,86 @@ async function installUtils() {
|
|
|
245
241
|
}
|
|
246
242
|
}
|
|
247
243
|
|
|
244
|
+
async function installComponentPackage(componentName: string) {
|
|
245
|
+
console.log(`📦 Installing ${componentName} package...`);
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
// Check if component is already installed in node_modules
|
|
249
|
+
const componentPath = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName);
|
|
250
|
+
|
|
251
|
+
if (!fs.existsSync(componentPath)) {
|
|
252
|
+
console.log(`Installing @ng-shangjc/${componentName}...`);
|
|
253
|
+
execSync(`npm install --save-dev @ng-shangjc/${componentName}`, { stdio: 'inherit' });
|
|
254
|
+
} else {
|
|
255
|
+
console.log(`✅ @ng-shangjc/${componentName} already installed`);
|
|
256
|
+
}
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error(`❌ Failed to install ${componentName} package:`, error);
|
|
259
|
+
console.log(`🔄 Attempting to download files directly...`);
|
|
260
|
+
|
|
261
|
+
// Fallback: try to download files directly from npm registry
|
|
262
|
+
try {
|
|
263
|
+
await downloadComponentFiles(componentName);
|
|
264
|
+
console.log(`✅ Successfully downloaded ${componentName} files directly`);
|
|
265
|
+
} catch (downloadError) {
|
|
266
|
+
console.error(`❌ Failed to download ${componentName} files:`, downloadError);
|
|
267
|
+
throw new Error(`Failed to install ${componentName}: Package installation and direct download both failed`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function downloadComponentFiles(componentName: string) {
|
|
273
|
+
const https = require('https');
|
|
274
|
+
const tar = require('tar');
|
|
275
|
+
|
|
276
|
+
return new Promise<void>((resolve, reject) => {
|
|
277
|
+
const packageUrl = `https://registry.npmjs.org/@ng-shangjc/${componentName}/-/${componentName}-1.0.0.tgz`;
|
|
278
|
+
const tempDir = path.join(process.cwd(), '.ng-shangjc-temp');
|
|
279
|
+
|
|
280
|
+
// Ensure temp directory exists
|
|
281
|
+
fs.ensureDirSync(tempDir);
|
|
282
|
+
|
|
283
|
+
const file = fs.createWriteStream(path.join(tempDir, `${componentName}.tgz`));
|
|
284
|
+
|
|
285
|
+
https.get(packageUrl, (response: any) => {
|
|
286
|
+
if (response.statusCode !== 200) {
|
|
287
|
+
reject(new Error(`Failed to download package: ${response.statusCode}`));
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
response.pipe(file);
|
|
292
|
+
|
|
293
|
+
file.on('finish', () => {
|
|
294
|
+
file.close();
|
|
295
|
+
|
|
296
|
+
// Extract the tarball
|
|
297
|
+
fs.createReadStream(path.join(tempDir, `${componentName}.tgz`))
|
|
298
|
+
.pipe(tar.extract({
|
|
299
|
+
cwd: tempDir,
|
|
300
|
+
strip: 1 // Remove the package folder
|
|
301
|
+
}))
|
|
302
|
+
.on('finish', () => {
|
|
303
|
+
// Copy the extracted files to node_modules structure
|
|
304
|
+
const sourceDir = path.join(tempDir, 'src', 'lib');
|
|
305
|
+
const targetDir = path.join(process.cwd(), 'node_modules', '@ng-shangjc', componentName, 'src', 'lib');
|
|
306
|
+
|
|
307
|
+
fs.ensureDirSync(path.dirname(targetDir));
|
|
308
|
+
|
|
309
|
+
if (fs.existsSync(sourceDir)) {
|
|
310
|
+
fs.copySync(sourceDir, targetDir);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Clean up temp files
|
|
314
|
+
fs.removeSync(tempDir);
|
|
315
|
+
|
|
316
|
+
resolve();
|
|
317
|
+
})
|
|
318
|
+
.on('error', reject);
|
|
319
|
+
});
|
|
320
|
+
}).on('error', reject);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
248
324
|
function generateIndexFile(componentName: string, files: string[], mode: string): string {
|
|
249
325
|
const exports = files
|
|
250
326
|
.filter(file => file.endsWith('.ts'))
|
|
@@ -264,4 +340,30 @@ ${exports}
|
|
|
264
340
|
|
|
265
341
|
function getComponentClassName(componentName: string): string {
|
|
266
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}`);
|
|
267
369
|
}
|