@fgv/ts-res-cli 5.0.0-9 → 5.0.1-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/CHANGELOG.json +23 -0
- package/eslint.config.js +16 -0
- package/lib/cli.d.ts +4 -0
- package/lib/cli.js +66 -0
- package/lib/compiler.js +2 -1
- package/package.json +19 -18
- package/.eslintrc.js +0 -9
- package/.rush/temp/chunked-rush-logs/ts-res-cli.build.chunks.jsonl +0 -6
- package/.rush/temp/operation/build/log-chunks.jsonl +0 -6
- package/.rush/temp/operation/build/state.json +0 -3
- package/.rush/temp/shrinkwrap-deps.json +0 -649
- package/config/jest.config.json +0 -9
- package/config/rig.json +0 -16
- package/lib/cli.d.ts.map +0 -1
- package/lib/cli.js.map +0 -1
- package/lib/compiler.d.ts.map +0 -1
- package/lib/compiler.js.map +0 -1
- package/lib/defaultConfiguration.d.ts.map +0 -1
- package/lib/defaultConfiguration.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/options.d.ts.map +0 -1
- package/lib/options.js.map +0 -1
- package/src/cli.ts +0 -607
- package/src/compiler.ts +0 -545
- package/src/defaultConfiguration.ts +0 -78
- package/src/index.ts +0 -25
- package/src/options.ts +0 -101
- package/test/integration/cli-configuration.test.ts +0 -419
- package/test/integration/cli-context-filter-working.test.ts +0 -341
- package/test/integration/cli-integration.test.ts +0 -581
- package/test/unit/cli.test.ts +0 -413
- package/test/unit/compiler.test.ts +0 -1084
- package/tsconfig.json +0 -8
package/test/unit/cli.test.ts
DELETED
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import '@fgv/ts-utils-jest';
|
|
24
|
-
import { TsResCliApp } from '../../src/cli';
|
|
25
|
-
import { promises as fs } from 'fs';
|
|
26
|
-
import * as path from 'path';
|
|
27
|
-
|
|
28
|
-
describe('TsResCliApp', () => {
|
|
29
|
-
let app: TsResCliApp;
|
|
30
|
-
let originalConsoleError: typeof console.error;
|
|
31
|
-
let originalProcessExit: typeof process.exit;
|
|
32
|
-
let originalStderrWrite: typeof process.stderr.write;
|
|
33
|
-
let consoleErrorSpy: jest.SpyInstance;
|
|
34
|
-
let processExitSpy: jest.SpyInstance;
|
|
35
|
-
let stderrWriteSpy: jest.SpyInstance;
|
|
36
|
-
let tempDir: string;
|
|
37
|
-
|
|
38
|
-
beforeEach(async () => {
|
|
39
|
-
app = new TsResCliApp();
|
|
40
|
-
|
|
41
|
-
// Mock console.error, process.exit, and stderr.write to prevent test output
|
|
42
|
-
originalConsoleError = console.error;
|
|
43
|
-
originalProcessExit = process.exit;
|
|
44
|
-
originalStderrWrite = process.stderr.write;
|
|
45
|
-
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
46
|
-
processExitSpy = jest.spyOn(process, 'exit').mockImplementation(() => undefined as never);
|
|
47
|
-
stderrWriteSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
48
|
-
|
|
49
|
-
// Create temporary directory for test files
|
|
50
|
-
tempDir = await fs.mkdtemp(path.join(__dirname, '../../temp/test-temp-cli-'));
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterEach(async () => {
|
|
54
|
-
// Restore original functions
|
|
55
|
-
console.error = originalConsoleError;
|
|
56
|
-
process.exit = originalProcessExit;
|
|
57
|
-
process.stderr.write = originalStderrWrite;
|
|
58
|
-
consoleErrorSpy.mockRestore();
|
|
59
|
-
processExitSpy.mockRestore();
|
|
60
|
-
stderrWriteSpy.mockRestore();
|
|
61
|
-
|
|
62
|
-
// Clean up temporary directory
|
|
63
|
-
await fs.rm(tempDir, { recursive: true, force: true });
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('creates a CLI application', () => {
|
|
67
|
-
expect(app).toBeDefined();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('command parsing', () => {
|
|
71
|
-
test('handles help command', async () => {
|
|
72
|
-
const originalWrite = process.stdout.write;
|
|
73
|
-
let helpOutput = '';
|
|
74
|
-
process.stdout.write = jest.fn((chunk: string | Uint8Array) => {
|
|
75
|
-
helpOutput += chunk.toString();
|
|
76
|
-
return true;
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
await app.run(['node', 'ts-res-compile', '--help']);
|
|
81
|
-
} catch (error) {
|
|
82
|
-
// Commander calls process.exit() for help, which our mock prevents
|
|
83
|
-
} finally {
|
|
84
|
-
process.stdout.write = originalWrite;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
expect(helpOutput).toMatch(/Compile and optimize ts-res resources/);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test('handles version command', async () => {
|
|
91
|
-
const originalWrite = process.stdout.write;
|
|
92
|
-
let versionOutput = '';
|
|
93
|
-
process.stdout.write = jest.fn((chunk: string | Uint8Array) => {
|
|
94
|
-
versionOutput += chunk.toString();
|
|
95
|
-
return true;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
await app.run(['node', 'ts-res-compile', '--version']);
|
|
100
|
-
} catch (error) {
|
|
101
|
-
// Commander calls process.exit() for version, which our mock prevents
|
|
102
|
-
} finally {
|
|
103
|
-
process.stdout.write = originalWrite;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
expect(versionOutput.trim()).toBe('1.0.0');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('handles compile command help', async () => {
|
|
110
|
-
const originalWrite = process.stdout.write;
|
|
111
|
-
let helpOutput = '';
|
|
112
|
-
process.stdout.write = jest.fn((chunk: string | Uint8Array) => {
|
|
113
|
-
helpOutput += chunk.toString();
|
|
114
|
-
return true;
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
await app.run(['node', 'ts-res-compile', 'compile', '--help']);
|
|
119
|
-
} catch (error) {
|
|
120
|
-
// Commander calls process.exit() for help, which our mock prevents
|
|
121
|
-
} finally {
|
|
122
|
-
process.stdout.write = originalWrite;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
expect(helpOutput).toMatch(/Compile resources from input to output format/);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe('compile command', () => {
|
|
130
|
-
let inputFile: string;
|
|
131
|
-
let outputFile: string;
|
|
132
|
-
|
|
133
|
-
beforeEach(async () => {
|
|
134
|
-
inputFile = path.join(tempDir, 'input.json');
|
|
135
|
-
outputFile = path.join(tempDir, 'output.json');
|
|
136
|
-
|
|
137
|
-
// Create test input file in ResourceCollection format
|
|
138
|
-
const testResources = {
|
|
139
|
-
resources: [
|
|
140
|
-
{
|
|
141
|
-
id: 'test.message',
|
|
142
|
-
resourceTypeName: 'json',
|
|
143
|
-
candidates: [
|
|
144
|
-
{
|
|
145
|
-
json: { text: 'Hello' },
|
|
146
|
-
conditions: { language: 'en' }
|
|
147
|
-
}
|
|
148
|
-
]
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
};
|
|
152
|
-
await fs.writeFile(inputFile, JSON.stringify(testResources, null, 2));
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test('handles missing required options', async () => {
|
|
156
|
-
await app.run(['node', 'ts-res-compile', 'compile']);
|
|
157
|
-
|
|
158
|
-
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
159
|
-
expect(consoleErrorSpy).toHaveBeenCalled();
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test('compiles resources successfully', async () => {
|
|
163
|
-
const originalConsoleLog = console.log;
|
|
164
|
-
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
165
|
-
|
|
166
|
-
try {
|
|
167
|
-
await app.run(['node', 'ts-res-compile', 'compile', '--input', inputFile, '--output', outputFile]);
|
|
168
|
-
|
|
169
|
-
// Should not exit with error
|
|
170
|
-
expect(processExitSpy).not.toHaveBeenCalledWith(1);
|
|
171
|
-
|
|
172
|
-
// Should print success message
|
|
173
|
-
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
174
|
-
expect.stringContaining('Successfully compiled resources')
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
// Output file should exist
|
|
178
|
-
const outputExists = await fs.stat(outputFile).then(
|
|
179
|
-
() => true,
|
|
180
|
-
() => false
|
|
181
|
-
);
|
|
182
|
-
expect(outputExists).toBe(true);
|
|
183
|
-
} finally {
|
|
184
|
-
console.log = originalConsoleLog;
|
|
185
|
-
consoleLogSpy.mockRestore();
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test('handles quiet mode', async () => {
|
|
190
|
-
const originalConsoleLog = console.log;
|
|
191
|
-
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
192
|
-
|
|
193
|
-
try {
|
|
194
|
-
await app.run([
|
|
195
|
-
'node',
|
|
196
|
-
'ts-res-compile',
|
|
197
|
-
'compile',
|
|
198
|
-
'--input',
|
|
199
|
-
inputFile,
|
|
200
|
-
'--output',
|
|
201
|
-
outputFile,
|
|
202
|
-
'--quiet'
|
|
203
|
-
]);
|
|
204
|
-
|
|
205
|
-
// Should not print success message in quiet mode
|
|
206
|
-
expect(consoleLogSpy).not.toHaveBeenCalledWith(
|
|
207
|
-
expect.stringContaining('Successfully compiled resources')
|
|
208
|
-
);
|
|
209
|
-
} finally {
|
|
210
|
-
console.log = originalConsoleLog;
|
|
211
|
-
consoleLogSpy.mockRestore();
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
test('handles compilation errors', async () => {
|
|
216
|
-
await app.run([
|
|
217
|
-
'node',
|
|
218
|
-
'ts-res-compile',
|
|
219
|
-
'compile',
|
|
220
|
-
'--input',
|
|
221
|
-
'/nonexistent/file.json',
|
|
222
|
-
'--output',
|
|
223
|
-
outputFile,
|
|
224
|
-
'--quiet'
|
|
225
|
-
]);
|
|
226
|
-
|
|
227
|
-
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
228
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('Error:'));
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test('handles invalid format option', async () => {
|
|
232
|
-
await app.run([
|
|
233
|
-
'node',
|
|
234
|
-
'ts-res-compile',
|
|
235
|
-
'compile',
|
|
236
|
-
'--input',
|
|
237
|
-
inputFile,
|
|
238
|
-
'--output',
|
|
239
|
-
outputFile,
|
|
240
|
-
'--format',
|
|
241
|
-
'invalid',
|
|
242
|
-
'--quiet'
|
|
243
|
-
]);
|
|
244
|
-
|
|
245
|
-
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
246
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('Invalid format'));
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
test('handles context option', async () => {
|
|
250
|
-
const originalConsoleLog = console.log;
|
|
251
|
-
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
252
|
-
|
|
253
|
-
try {
|
|
254
|
-
await app.run([
|
|
255
|
-
'node',
|
|
256
|
-
'ts-res-compile',
|
|
257
|
-
'compile',
|
|
258
|
-
'--input',
|
|
259
|
-
inputFile,
|
|
260
|
-
'--output',
|
|
261
|
-
outputFile,
|
|
262
|
-
'--context',
|
|
263
|
-
'{"language": "en"}',
|
|
264
|
-
'--quiet'
|
|
265
|
-
]);
|
|
266
|
-
|
|
267
|
-
expect(processExitSpy).not.toHaveBeenCalledWith(1);
|
|
268
|
-
} finally {
|
|
269
|
-
console.log = originalConsoleLog;
|
|
270
|
-
consoleLogSpy.mockRestore();
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
describe('validate command', () => {
|
|
276
|
-
let inputFile: string;
|
|
277
|
-
|
|
278
|
-
beforeEach(async () => {
|
|
279
|
-
inputFile = path.join(tempDir, 'input.json');
|
|
280
|
-
|
|
281
|
-
// Create test input file in ResourceCollection format
|
|
282
|
-
const testResources = {
|
|
283
|
-
resources: [
|
|
284
|
-
{
|
|
285
|
-
id: 'test.message',
|
|
286
|
-
resourceTypeName: 'json',
|
|
287
|
-
candidates: [
|
|
288
|
-
{
|
|
289
|
-
json: { text: 'Hello' },
|
|
290
|
-
conditions: { language: 'en' }
|
|
291
|
-
}
|
|
292
|
-
]
|
|
293
|
-
}
|
|
294
|
-
]
|
|
295
|
-
};
|
|
296
|
-
await fs.writeFile(inputFile, JSON.stringify(testResources, null, 2));
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
test('validates resources successfully', async () => {
|
|
300
|
-
const originalConsoleLog = console.log;
|
|
301
|
-
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
302
|
-
|
|
303
|
-
try {
|
|
304
|
-
await app.run(['node', 'ts-res-compile', 'validate', '--input', inputFile]);
|
|
305
|
-
|
|
306
|
-
expect(processExitSpy).not.toHaveBeenCalledWith(1);
|
|
307
|
-
expect(consoleLogSpy).toHaveBeenCalledWith('Resources validated successfully');
|
|
308
|
-
} finally {
|
|
309
|
-
console.log = originalConsoleLog;
|
|
310
|
-
consoleLogSpy.mockRestore();
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
test('handles validation errors', async () => {
|
|
315
|
-
// Create invalid resource file
|
|
316
|
-
const invalidResources = [
|
|
317
|
-
{
|
|
318
|
-
id: 'invalid resource id', // Invalid ID with spaces
|
|
319
|
-
json: { text: 'Hello' },
|
|
320
|
-
conditions: { language: 'en' },
|
|
321
|
-
resourceTypeName: 'json'
|
|
322
|
-
}
|
|
323
|
-
];
|
|
324
|
-
await fs.writeFile(inputFile, JSON.stringify(invalidResources));
|
|
325
|
-
|
|
326
|
-
await app.run(['node', 'ts-res-compile', 'validate', '--input', inputFile, '--quiet']);
|
|
327
|
-
|
|
328
|
-
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
329
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('Validation failed'));
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
describe('info command', () => {
|
|
334
|
-
let inputFile: string;
|
|
335
|
-
|
|
336
|
-
beforeEach(async () => {
|
|
337
|
-
inputFile = path.join(tempDir, 'input.json');
|
|
338
|
-
|
|
339
|
-
// Create test input file with multiple resources in ResourceCollection format
|
|
340
|
-
const testResources = {
|
|
341
|
-
resources: [
|
|
342
|
-
{
|
|
343
|
-
id: 'test.message',
|
|
344
|
-
resourceTypeName: 'json',
|
|
345
|
-
candidates: [
|
|
346
|
-
{
|
|
347
|
-
json: { text: 'Hello' },
|
|
348
|
-
conditions: { language: 'en' }
|
|
349
|
-
},
|
|
350
|
-
{
|
|
351
|
-
json: { text: 'Hola' },
|
|
352
|
-
conditions: { language: 'es' }
|
|
353
|
-
}
|
|
354
|
-
]
|
|
355
|
-
}
|
|
356
|
-
]
|
|
357
|
-
};
|
|
358
|
-
await fs.writeFile(inputFile, JSON.stringify(testResources, null, 2));
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
test('displays resource information', async () => {
|
|
362
|
-
const originalConsoleLog = console.log;
|
|
363
|
-
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
364
|
-
|
|
365
|
-
try {
|
|
366
|
-
await app.run(['node', 'ts-res-compile', 'info', '--input', inputFile]);
|
|
367
|
-
|
|
368
|
-
expect(processExitSpy).not.toHaveBeenCalledWith(1);
|
|
369
|
-
expect(consoleLogSpy).toHaveBeenCalled();
|
|
370
|
-
|
|
371
|
-
const infoOutput = consoleLogSpy.mock.calls[0][0];
|
|
372
|
-
const info = JSON.parse(infoOutput);
|
|
373
|
-
|
|
374
|
-
expect(info).toHaveProperty('totalResources');
|
|
375
|
-
expect(info).toHaveProperty('totalCandidates');
|
|
376
|
-
expect(info.totalResources).toBeGreaterThan(0);
|
|
377
|
-
expect(info.totalCandidates).toBeGreaterThan(0);
|
|
378
|
-
} finally {
|
|
379
|
-
console.log = originalConsoleLog;
|
|
380
|
-
consoleLogSpy.mockRestore();
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
test('displays filtered resource information', async () => {
|
|
385
|
-
const originalConsoleLog = console.log;
|
|
386
|
-
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
387
|
-
|
|
388
|
-
try {
|
|
389
|
-
await app.run([
|
|
390
|
-
'node',
|
|
391
|
-
'ts-res-compile',
|
|
392
|
-
'info',
|
|
393
|
-
'--input',
|
|
394
|
-
inputFile,
|
|
395
|
-
'--context-filter',
|
|
396
|
-
'language=en'
|
|
397
|
-
]);
|
|
398
|
-
|
|
399
|
-
expect(processExitSpy).not.toHaveBeenCalledWith(1);
|
|
400
|
-
expect(consoleLogSpy).toHaveBeenCalled();
|
|
401
|
-
|
|
402
|
-
const infoOutput = consoleLogSpy.mock.calls[0][0];
|
|
403
|
-
const info = JSON.parse(infoOutput);
|
|
404
|
-
|
|
405
|
-
expect(info).toHaveProperty('context');
|
|
406
|
-
expect(info.context).toEqual({ language: 'en' });
|
|
407
|
-
} finally {
|
|
408
|
-
console.log = originalConsoleLog;
|
|
409
|
-
consoleLogSpy.mockRestore();
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
});
|
|
413
|
-
});
|