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