@fgv/ts-res-browser-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/zipArchiver.d.ts +2 -14
- package/lib/zipArchiver.js +11 -72
- package/package.json +8 -10
- package/src/zipArchiver.ts +12 -97
package/lib/zipArchiver.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { ZipArchive } from '@fgv/ts-res';
|
|
2
3
|
export interface ZipArchiveOptions {
|
|
3
4
|
input?: string;
|
|
4
5
|
config?: string;
|
|
@@ -6,20 +7,7 @@ export interface ZipArchiveOptions {
|
|
|
6
7
|
}
|
|
7
8
|
export interface ZipArchiveResult {
|
|
8
9
|
zipPath: string;
|
|
9
|
-
manifest:
|
|
10
|
-
}
|
|
11
|
-
export interface ZipManifest {
|
|
12
|
-
timestamp: string;
|
|
13
|
-
input?: {
|
|
14
|
-
type: 'file' | 'directory';
|
|
15
|
-
originalPath: string;
|
|
16
|
-
archivePath: string;
|
|
17
|
-
};
|
|
18
|
-
config?: {
|
|
19
|
-
type: 'file';
|
|
20
|
-
originalPath: string;
|
|
21
|
-
archivePath: string;
|
|
22
|
-
};
|
|
10
|
+
manifest: ZipArchive.IZipArchiveManifest;
|
|
23
11
|
}
|
|
24
12
|
export declare class ZipArchiver {
|
|
25
13
|
/**
|
package/lib/zipArchiver.js
CHANGED
|
@@ -34,11 +34,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.zipArchiver = exports.ZipArchiver = void 0;
|
|
37
|
-
const archiver = __importStar(require("archiver"));
|
|
38
37
|
const fs = __importStar(require("fs"));
|
|
39
38
|
const path = __importStar(require("path"));
|
|
40
39
|
const os = __importStar(require("os"));
|
|
41
40
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
41
|
+
const ts_res_1 = require("@fgv/ts-res");
|
|
42
42
|
class ZipArchiver {
|
|
43
43
|
/**
|
|
44
44
|
* Create a ZIP archive containing the specified input and config files/directories
|
|
@@ -53,79 +53,18 @@ class ZipArchiver {
|
|
|
53
53
|
if (!fs.existsSync(outputDir)) {
|
|
54
54
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
56
|
+
// Create ZIP archive using the new zip-archive packlet
|
|
57
|
+
const creator = new ts_res_1.ZipArchive.ZipArchiveCreator();
|
|
58
|
+
const createResult = await creator.createFromBuffer({
|
|
59
|
+
inputPath: options.input,
|
|
60
|
+
configPath: options.config
|
|
59
61
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
timestamp: new Date().toISOString()
|
|
63
|
-
};
|
|
64
|
-
// Promise to handle async archiving
|
|
65
|
-
const archivePromise = new Promise((resolve, reject) => {
|
|
66
|
-
output.on('close', () => {
|
|
67
|
-
resolve();
|
|
68
|
-
});
|
|
69
|
-
output.on('error', (err) => {
|
|
70
|
-
reject(err);
|
|
71
|
-
});
|
|
72
|
-
archive.on('error', (err) => {
|
|
73
|
-
reject(err);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
// Pipe archive data to the file
|
|
77
|
-
archive.pipe(output);
|
|
78
|
-
// Add input files/directory
|
|
79
|
-
if (options.input) {
|
|
80
|
-
const inputPath = path.resolve(options.input);
|
|
81
|
-
if (!fs.existsSync(inputPath)) {
|
|
82
|
-
return (0, ts_utils_1.fail)(`Input path does not exist: ${inputPath}`);
|
|
83
|
-
}
|
|
84
|
-
const stats = fs.statSync(inputPath);
|
|
85
|
-
if (stats.isDirectory()) {
|
|
86
|
-
// Add entire directory recursively, preserving structure
|
|
87
|
-
const dirName = path.basename(inputPath);
|
|
88
|
-
archive.directory(inputPath, `input/${dirName}`);
|
|
89
|
-
manifest.input = {
|
|
90
|
-
type: 'directory',
|
|
91
|
-
originalPath: inputPath,
|
|
92
|
-
archivePath: `input/${dirName}`
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
else if (stats.isFile()) {
|
|
96
|
-
// Add single file
|
|
97
|
-
const fileName = path.basename(inputPath);
|
|
98
|
-
archive.file(inputPath, { name: `input/${fileName}` });
|
|
99
|
-
manifest.input = {
|
|
100
|
-
type: 'file',
|
|
101
|
-
originalPath: inputPath,
|
|
102
|
-
archivePath: `input/${fileName}`
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
// Add config file
|
|
107
|
-
if (options.config) {
|
|
108
|
-
const configPath = path.resolve(options.config);
|
|
109
|
-
if (!fs.existsSync(configPath)) {
|
|
110
|
-
return (0, ts_utils_1.fail)(`Config file does not exist: ${configPath}`);
|
|
111
|
-
}
|
|
112
|
-
const stats = fs.statSync(configPath);
|
|
113
|
-
if (!stats.isFile()) {
|
|
114
|
-
return (0, ts_utils_1.fail)(`Config path must be a file: ${configPath}`);
|
|
115
|
-
}
|
|
116
|
-
const fileName = path.basename(configPath);
|
|
117
|
-
archive.file(configPath, { name: `config/${fileName}` });
|
|
118
|
-
manifest.config = {
|
|
119
|
-
type: 'file',
|
|
120
|
-
originalPath: configPath,
|
|
121
|
-
archivePath: `config/${fileName}`
|
|
122
|
-
};
|
|
62
|
+
if (createResult.isFailure()) {
|
|
63
|
+
return (0, ts_utils_1.fail)(createResult.message);
|
|
123
64
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
await archive.finalize();
|
|
128
|
-
await archivePromise;
|
|
65
|
+
const { zipBuffer, manifest } = createResult.value;
|
|
66
|
+
// Write the ZIP buffer to disk
|
|
67
|
+
fs.writeFileSync(zipPath, zipBuffer);
|
|
129
68
|
return (0, ts_utils_1.succeed)({
|
|
130
69
|
zipPath,
|
|
131
70
|
manifest
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-res-browser-cli",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-17",
|
|
4
4
|
"description": "Command-line interface to launch ts-res-browser with specified options",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -22,13 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"commander": "^11.0.0",
|
|
25
|
-
"
|
|
26
|
-
"@
|
|
27
|
-
"@fgv/ts-
|
|
28
|
-
"@fgv/ts-json
|
|
29
|
-
"@fgv/ts-
|
|
30
|
-
"@fgv/ts-utils": "5.0.0-15",
|
|
31
|
-
"@fgv/ts-res-browser": "5.0.0-15"
|
|
25
|
+
"@fgv/ts-res": "5.0.0-17",
|
|
26
|
+
"@fgv/ts-utils": "5.0.0-17",
|
|
27
|
+
"@fgv/ts-json-base": "5.0.0-17",
|
|
28
|
+
"@fgv/ts-json": "5.0.0-17",
|
|
29
|
+
"@fgv/ts-res-browser": "5.0.0-17"
|
|
32
30
|
},
|
|
33
31
|
"devDependencies": {
|
|
34
32
|
"@rushstack/heft": "~0.74.2",
|
|
@@ -38,11 +36,11 @@
|
|
|
38
36
|
"eslint": "^8.57.0",
|
|
39
37
|
"jest": "^29.7.0",
|
|
40
38
|
"typescript": "^5.8.3",
|
|
41
|
-
"@fgv/ts-utils-jest": "5.0.0-
|
|
39
|
+
"@fgv/ts-utils-jest": "5.0.0-17"
|
|
42
40
|
},
|
|
43
41
|
"scripts": {
|
|
44
42
|
"build": "heft build --clean",
|
|
45
|
-
"test": "
|
|
43
|
+
"test": "echo 'No tests configured for ts-res-browser-cli - this is a CLI launcher tool' && exit 0",
|
|
46
44
|
"clean": "heft clean",
|
|
47
45
|
"lint": "eslint src --ext .ts",
|
|
48
46
|
"fixlint": "eslint src --ext .ts --fix"
|
package/src/zipArchiver.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as archiver from 'archiver';
|
|
2
1
|
import * as fs from 'fs';
|
|
3
2
|
import * as path from 'path';
|
|
4
3
|
import * as os from 'os';
|
|
5
4
|
import { Result, succeed, fail } from '@fgv/ts-utils';
|
|
5
|
+
import { ZipArchive } from '@fgv/ts-res';
|
|
6
6
|
|
|
7
7
|
export interface ZipArchiveOptions {
|
|
8
8
|
input?: string;
|
|
@@ -12,21 +12,7 @@ export interface ZipArchiveOptions {
|
|
|
12
12
|
|
|
13
13
|
export interface ZipArchiveResult {
|
|
14
14
|
zipPath: string;
|
|
15
|
-
manifest:
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface ZipManifest {
|
|
19
|
-
timestamp: string;
|
|
20
|
-
input?: {
|
|
21
|
-
type: 'file' | 'directory';
|
|
22
|
-
originalPath: string;
|
|
23
|
-
archivePath: string;
|
|
24
|
-
};
|
|
25
|
-
config?: {
|
|
26
|
-
type: 'file';
|
|
27
|
-
originalPath: string;
|
|
28
|
-
archivePath: string;
|
|
29
|
-
};
|
|
15
|
+
manifest: ZipArchive.IZipArchiveManifest;
|
|
30
16
|
}
|
|
31
17
|
|
|
32
18
|
export class ZipArchiver {
|
|
@@ -45,92 +31,21 @@ export class ZipArchiver {
|
|
|
45
31
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
46
32
|
}
|
|
47
33
|
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// Create manifest
|
|
54
|
-
const manifest: ZipManifest = {
|
|
55
|
-
timestamp: new Date().toISOString()
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// Promise to handle async archiving
|
|
59
|
-
const archivePromise = new Promise<void>((resolve, reject) => {
|
|
60
|
-
output.on('close', () => {
|
|
61
|
-
resolve();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
output.on('error', (err: Error) => {
|
|
65
|
-
reject(err);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
archive.on('error', (err: Error) => {
|
|
69
|
-
reject(err);
|
|
70
|
-
});
|
|
34
|
+
// Create ZIP archive using the new zip-archive packlet
|
|
35
|
+
const creator = new ZipArchive.ZipArchiveCreator();
|
|
36
|
+
const createResult = await creator.createFromBuffer({
|
|
37
|
+
inputPath: options.input,
|
|
38
|
+
configPath: options.config
|
|
71
39
|
});
|
|
72
40
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// Add input files/directory
|
|
77
|
-
if (options.input) {
|
|
78
|
-
const inputPath = path.resolve(options.input);
|
|
79
|
-
|
|
80
|
-
if (!fs.existsSync(inputPath)) {
|
|
81
|
-
return fail(`Input path does not exist: ${inputPath}`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const stats = fs.statSync(inputPath);
|
|
85
|
-
if (stats.isDirectory()) {
|
|
86
|
-
// Add entire directory recursively, preserving structure
|
|
87
|
-
const dirName = path.basename(inputPath);
|
|
88
|
-
archive.directory(inputPath, `input/${dirName}`);
|
|
89
|
-
manifest.input = {
|
|
90
|
-
type: 'directory',
|
|
91
|
-
originalPath: inputPath,
|
|
92
|
-
archivePath: `input/${dirName}`
|
|
93
|
-
};
|
|
94
|
-
} else if (stats.isFile()) {
|
|
95
|
-
// Add single file
|
|
96
|
-
const fileName = path.basename(inputPath);
|
|
97
|
-
archive.file(inputPath, { name: `input/${fileName}` });
|
|
98
|
-
manifest.input = {
|
|
99
|
-
type: 'file',
|
|
100
|
-
originalPath: inputPath,
|
|
101
|
-
archivePath: `input/${fileName}`
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Add config file
|
|
107
|
-
if (options.config) {
|
|
108
|
-
const configPath = path.resolve(options.config);
|
|
109
|
-
|
|
110
|
-
if (!fs.existsSync(configPath)) {
|
|
111
|
-
return fail(`Config file does not exist: ${configPath}`);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const stats = fs.statSync(configPath);
|
|
115
|
-
if (!stats.isFile()) {
|
|
116
|
-
return fail(`Config path must be a file: ${configPath}`);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const fileName = path.basename(configPath);
|
|
120
|
-
archive.file(configPath, { name: `config/${fileName}` });
|
|
121
|
-
manifest.config = {
|
|
122
|
-
type: 'file',
|
|
123
|
-
originalPath: configPath,
|
|
124
|
-
archivePath: `config/${fileName}`
|
|
125
|
-
};
|
|
41
|
+
if (createResult.isFailure()) {
|
|
42
|
+
return fail(createResult.message);
|
|
126
43
|
}
|
|
127
44
|
|
|
128
|
-
|
|
129
|
-
archive.append(JSON.stringify(manifest, null, 2), { name: 'manifest.json' });
|
|
45
|
+
const { zipBuffer, manifest } = createResult.value;
|
|
130
46
|
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
await archivePromise;
|
|
47
|
+
// Write the ZIP buffer to disk
|
|
48
|
+
fs.writeFileSync(zipPath, zipBuffer);
|
|
134
49
|
|
|
135
50
|
return succeed({
|
|
136
51
|
zipPath,
|