@fgv/ts-res-cli 5.0.0-15 → 5.0.0-17

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/lib/cli.d.ts CHANGED
@@ -28,6 +28,10 @@ export declare class TsResCliApp {
28
28
  * Handles the config command
29
29
  */
30
30
  private _handleConfigCommand;
31
+ /**
32
+ * Handles the archive command
33
+ */
34
+ private _handleArchiveCommand;
31
35
  /**
32
36
  * Parses and validates compile options
33
37
  */
package/lib/cli.js CHANGED
@@ -142,6 +142,17 @@ class TsResCliApp {
142
142
  .action(async (options) => {
143
143
  await this._handleConfigCommand(options);
144
144
  });
145
+ this._program
146
+ .command('archive')
147
+ .description('Create ZIP archive of resources and configuration')
148
+ .option('-i, --input <path>', 'Input file or directory path')
149
+ .option('--config <path>', 'Configuration file path')
150
+ .requiredOption('-o, --output <path>', 'Output ZIP file path')
151
+ .option('-v, --verbose', 'Verbose output', false)
152
+ .option('-q, --quiet', 'Quiet output', false)
153
+ .action(async (options) => {
154
+ await this._handleArchiveCommand(options);
155
+ });
145
156
  }
146
157
  /**
147
158
  * Handles the compile command
@@ -413,6 +424,61 @@ class TsResCliApp {
413
424
  process.exit(1);
414
425
  }
415
426
  }
427
+ /**
428
+ * Handles the archive command
429
+ */
430
+ async _handleArchiveCommand(options) {
431
+ try {
432
+ // Import ZipArchive dynamically to avoid loading if not needed
433
+ const { ZipArchive } = await Promise.resolve().then(() => __importStar(require('@fgv/ts-res')));
434
+ if (!options.input && !options.config) {
435
+ console.error('Error: At least one of --input or --config must be specified');
436
+ process.exit(1);
437
+ }
438
+ if (!options.quiet) {
439
+ console.log('Creating ZIP archive...');
440
+ if (options.input)
441
+ console.log(`Input: ${options.input}`);
442
+ if (options.config)
443
+ console.log(`Config: ${options.config}`);
444
+ console.log(`Output: ${options.output}`);
445
+ }
446
+ // Create ZIP archive using the new zip-archive packlet
447
+ const creator = new ZipArchive.ZipArchiveCreator();
448
+ const createResult = await creator.createFromBuffer({
449
+ inputPath: options.input,
450
+ configPath: options.config
451
+ }, options.verbose
452
+ ? (phase, progress, message) => {
453
+ console.log(`[${phase}] ${progress}% - ${message}`);
454
+ }
455
+ : undefined);
456
+ if (createResult.isFailure()) {
457
+ console.error(`Error: Failed to create ZIP archive: ${createResult.message}`);
458
+ process.exit(1);
459
+ }
460
+ const { zipBuffer, manifest, size } = createResult.value;
461
+ // Write the ZIP buffer to the specified output file
462
+ const fs = await Promise.resolve().then(() => __importStar(require('fs'))).then((m) => m.promises);
463
+ const path = await Promise.resolve().then(() => __importStar(require('path')));
464
+ const outputPath = path.resolve(options.output);
465
+ const outputDir = path.dirname(outputPath);
466
+ // Ensure output directory exists
467
+ await fs.mkdir(outputDir, { recursive: true });
468
+ // Write ZIP file
469
+ await fs.writeFile(outputPath, zipBuffer);
470
+ if (!options.quiet) {
471
+ console.log(`ZIP archive created successfully: ${outputPath}`);
472
+ console.log(`Archive size: ${(size / 1024).toFixed(2)} KB`);
473
+ console.log(`Manifest:`);
474
+ console.log(JSON.stringify(manifest, null, 2));
475
+ }
476
+ }
477
+ catch (error) {
478
+ console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
479
+ process.exit(1);
480
+ }
481
+ }
416
482
  /**
417
483
  * Parses and validates compile options
418
484
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-res-cli",
3
- "version": "5.0.0-15",
3
+ "version": "5.0.0-17",
4
4
  "description": "Command-line interface for ts-res resource compilation and management",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -18,11 +18,11 @@
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
20
  "commander": "^11.0.0",
21
- "@fgv/ts-utils": "5.0.0-15",
22
- "@fgv/ts-json": "5.0.0-15",
23
- "@fgv/ts-res": "5.0.0-15",
24
- "@fgv/ts-json-base": "5.0.0-15",
25
- "@fgv/ts-extras": "5.0.0-15"
21
+ "@fgv/ts-res": "5.0.0-17",
22
+ "@fgv/ts-json": "5.0.0-17",
23
+ "@fgv/ts-extras": "5.0.0-17",
24
+ "@fgv/ts-json-base": "5.0.0-17",
25
+ "@fgv/ts-utils": "5.0.0-17"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@rushstack/heft": "~0.74.2",
@@ -37,7 +37,7 @@
37
37
  "jest": "^29.7.0",
38
38
  "ts-jest": "^29.4.1",
39
39
  "typescript": "^5.8.3",
40
- "@fgv/ts-utils-jest": "5.0.0-15"
40
+ "@fgv/ts-utils-jest": "5.0.0-17"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "typescript": "^5.7.3"
package/src/cli.ts CHANGED
@@ -86,6 +86,17 @@ interface IConfigCommandOptions {
86
86
  list?: boolean;
87
87
  }
88
88
 
89
+ /**
90
+ * Command-line options for the archive command
91
+ */
92
+ interface IArchiveCommandOptions {
93
+ input?: string;
94
+ config?: string;
95
+ output: string;
96
+ verbose?: boolean;
97
+ quiet?: boolean;
98
+ }
99
+
89
100
  import { ResourceCompiler } from './compiler';
90
101
 
91
102
  /**
@@ -221,6 +232,18 @@ export class TsResCliApp {
221
232
  .action(async (options) => {
222
233
  await this._handleConfigCommand(options);
223
234
  });
235
+
236
+ this._program
237
+ .command('archive')
238
+ .description('Create ZIP archive of resources and configuration')
239
+ .option('-i, --input <path>', 'Input file or directory path')
240
+ .option('--config <path>', 'Configuration file path')
241
+ .requiredOption('-o, --output <path>', 'Output ZIP file path')
242
+ .option('-v, --verbose', 'Verbose output', false)
243
+ .option('-q, --quiet', 'Quiet output', false)
244
+ .action(async (options) => {
245
+ await this._handleArchiveCommand(options);
246
+ });
224
247
  }
225
248
 
226
249
  /**
@@ -557,6 +580,71 @@ export class TsResCliApp {
557
580
  }
558
581
  }
559
582
 
583
+ /**
584
+ * Handles the archive command
585
+ */
586
+ private async _handleArchiveCommand(options: IArchiveCommandOptions): Promise<void> {
587
+ try {
588
+ // Import ZipArchive dynamically to avoid loading if not needed
589
+ const { ZipArchive } = await import('@fgv/ts-res');
590
+
591
+ if (!options.input && !options.config) {
592
+ console.error('Error: At least one of --input or --config must be specified');
593
+ process.exit(1);
594
+ }
595
+
596
+ if (!options.quiet) {
597
+ console.log('Creating ZIP archive...');
598
+ if (options.input) console.log(`Input: ${options.input}`);
599
+ if (options.config) console.log(`Config: ${options.config}`);
600
+ console.log(`Output: ${options.output}`);
601
+ }
602
+
603
+ // Create ZIP archive using the new zip-archive packlet
604
+ const creator = new ZipArchive.ZipArchiveCreator();
605
+ const createResult = await creator.createFromBuffer(
606
+ {
607
+ inputPath: options.input,
608
+ configPath: options.config
609
+ },
610
+ options.verbose
611
+ ? (phase, progress, message) => {
612
+ console.log(`[${phase}] ${progress}% - ${message}`);
613
+ }
614
+ : undefined
615
+ );
616
+
617
+ if (createResult.isFailure()) {
618
+ console.error(`Error: Failed to create ZIP archive: ${createResult.message}`);
619
+ process.exit(1);
620
+ }
621
+
622
+ const { zipBuffer, manifest, size } = createResult.value;
623
+
624
+ // Write the ZIP buffer to the specified output file
625
+ const fs = await import('fs').then((m) => m.promises);
626
+ const path = await import('path');
627
+ const outputPath = path.resolve(options.output);
628
+ const outputDir = path.dirname(outputPath);
629
+
630
+ // Ensure output directory exists
631
+ await fs.mkdir(outputDir, { recursive: true });
632
+
633
+ // Write ZIP file
634
+ await fs.writeFile(outputPath, zipBuffer);
635
+
636
+ if (!options.quiet) {
637
+ console.log(`ZIP archive created successfully: ${outputPath}`);
638
+ console.log(`Archive size: ${(size / 1024).toFixed(2)} KB`);
639
+ console.log(`Manifest:`);
640
+ console.log(JSON.stringify(manifest, null, 2));
641
+ }
642
+ } catch (error) {
643
+ console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
644
+ process.exit(1);
645
+ }
646
+ }
647
+
560
648
  /**
561
649
  * Parses and validates compile options
562
650
  */