@fgv/ts-res-cli 5.0.0-3 → 5.0.0-30
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/README.md +50 -2
- package/eslint.config.js +16 -0
- package/lib/cli.d.ts +4 -0
- package/lib/cli.js +68 -2
- package/lib/compiler.d.ts +5 -0
- package/lib/compiler.js +34 -0
- package/lib/options.d.ts +1 -1
- package/package.json +18 -17
- 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 -504
- 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 -533
- package/test/unit/cli.test.ts +0 -413
- package/test/unit/compiler.test.ts +0 -1084
- package/tsconfig.json +0 -8
package/src/compiler.ts
DELETED
|
@@ -1,504 +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 { Result, succeed, fail, FileTree } from '@fgv/ts-utils';
|
|
24
|
-
import { JsonObject } from '@fgv/ts-json-base';
|
|
25
|
-
import * as TsRes from '@fgv/ts-res';
|
|
26
|
-
import { ICompileOptions } from './options';
|
|
27
|
-
import { DEFAULT_SYSTEM_CONFIGURATION } from './defaultConfiguration';
|
|
28
|
-
import { promises as fs } from 'fs';
|
|
29
|
-
import * as path from 'path';
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Information about compiled resources
|
|
33
|
-
*/
|
|
34
|
-
export interface IResourceInfo {
|
|
35
|
-
totalResources: number;
|
|
36
|
-
totalCandidates: number;
|
|
37
|
-
filteredResources: number;
|
|
38
|
-
filteredCandidates: number;
|
|
39
|
-
resourceTypes: string[];
|
|
40
|
-
qualifiers: string[];
|
|
41
|
-
context?: JsonObject;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface IFilteredManager {
|
|
45
|
-
original: TsRes.Resources.ResourceManagerBuilder;
|
|
46
|
-
manager: TsRes.Resources.ResourceManagerBuilder;
|
|
47
|
-
context?: JsonObject;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Compiled resource blob
|
|
52
|
-
*/
|
|
53
|
-
export interface IResourceBlob {
|
|
54
|
-
resources?: TsRes.ResourceJson.Json.IResourceCollectionDecl;
|
|
55
|
-
compiledCollection?: TsRes.ResourceJson.Compiled.ICompiledResourceCollection;
|
|
56
|
-
metadata?: IResourceInfo;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Main resource compiler class
|
|
61
|
-
*/
|
|
62
|
-
export class ResourceCompiler {
|
|
63
|
-
private readonly _options: ICompileOptions;
|
|
64
|
-
private _systemConfiguration?: TsRes.Config.Model.ISystemConfiguration;
|
|
65
|
-
|
|
66
|
-
public constructor(options: ICompileOptions) {
|
|
67
|
-
this._options = options;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Compiles resources according to the configured options
|
|
72
|
-
*/
|
|
73
|
-
public async compile(): Promise<Result<IResourceBlob>> {
|
|
74
|
-
try {
|
|
75
|
-
if (this._options.debug) {
|
|
76
|
-
console.error('Starting resource compilation...');
|
|
77
|
-
console.error('Options:', JSON.stringify(this._options, null, 2));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Load and validate configuration
|
|
81
|
-
const config = (await this._loadConfiguration()).orThrow(
|
|
82
|
-
(err) => `Failed to load configuration: ${err}`
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
if (this._options.debug) {
|
|
86
|
-
console.error('Configuration loaded successfully');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Load resources from input
|
|
90
|
-
const original = (await this._loadResources(config)).orThrow(
|
|
91
|
-
(err) => `Failed to load resources: ${err}`
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
if (this._options.verbose) {
|
|
95
|
-
console.error(`Loaded ${original.numResources} resources with ${original.numCandidates} candidates`);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Apply context filtering if specified
|
|
99
|
-
const filtered = this._applyFilters(original).orThrow(
|
|
100
|
-
(err) => `Failed to apply context filtering: ${err}`
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
if (this._options.verbose && filtered.manager !== filtered.original) {
|
|
104
|
-
console.error(
|
|
105
|
-
`After context filtering: ${filtered.manager.numResources} resources, ${filtered.manager.numCandidates} candidates`
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Generate output blob
|
|
110
|
-
const blob = (await this._generateBlob(filtered)).orThrow(
|
|
111
|
-
(err) => `Failed to generate output blob: ${err}`
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
if (this._options.debug) {
|
|
115
|
-
console.error(`Generated ${this._options.format} format output blob`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Write output
|
|
119
|
-
(await this._writeOutput(blob)).orThrow((err) => `Failed to write output: ${err}`);
|
|
120
|
-
|
|
121
|
-
if (this._options.debug) {
|
|
122
|
-
console.error(`Output written to: ${this._options.output}`);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return succeed(blob);
|
|
126
|
-
} catch (error) {
|
|
127
|
-
return fail(`Compilation failed: ${error}`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Validates resources without compilation
|
|
133
|
-
*/
|
|
134
|
-
public async validate(): Promise<Result<TsRes.Resources.ResourceManagerBuilder>> {
|
|
135
|
-
try {
|
|
136
|
-
// Load and validate configuration
|
|
137
|
-
const config = (await this._loadConfiguration()).orThrow(
|
|
138
|
-
(err) => `Failed to load configuration: ${err}`
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const manager = (await this._loadResources(config)).orThrow(
|
|
142
|
-
(err) => `Failed to load resources: ${err}`
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const filtered = this._applyFilters(manager).orThrow(
|
|
146
|
-
(err) => `Failed to apply context filtering: ${err}`
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
// Build all resources to trigger validation
|
|
150
|
-
return filtered.manager.build().onSuccess((manager) => {
|
|
151
|
-
if (this._options.verbose) {
|
|
152
|
-
console.error(
|
|
153
|
-
`Resource validation successful with ${manager.numResources} resources and ${manager.numCandidates} candidates`
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
return succeed(manager);
|
|
157
|
-
});
|
|
158
|
-
} catch (error) {
|
|
159
|
-
return fail(`Validation failed: ${error}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Gets information about the resources
|
|
165
|
-
*/
|
|
166
|
-
public async getInfo(): Promise<Result<IResourceInfo>> {
|
|
167
|
-
try {
|
|
168
|
-
// Load and validate configuration
|
|
169
|
-
const config = (await this._loadConfiguration()).orThrow(
|
|
170
|
-
(err) => `Failed to load configuration: ${err}`
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
const manager = (await this._loadResources(config)).orThrow(
|
|
174
|
-
(err) => `Failed to load resources: ${err}`
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
const filtered = this._applyFilters(manager).orThrow(
|
|
178
|
-
(err) => `Failed to apply context filtering: ${err}`
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
return succeed(this._generateResourceInfo(filtered));
|
|
182
|
-
} catch (error) {
|
|
183
|
-
return fail(`Failed to get resource info: ${error}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Loads and validates the system configuration
|
|
189
|
-
*/
|
|
190
|
-
private async _loadConfiguration(): Promise<Result<TsRes.Config.Model.ISystemConfiguration>> {
|
|
191
|
-
try {
|
|
192
|
-
if (this._options.config) {
|
|
193
|
-
// Check if it's a predefined configuration name
|
|
194
|
-
const predefinedNames: TsRes.Config.PredefinedSystemConfiguration[] = [
|
|
195
|
-
'default',
|
|
196
|
-
'language-priority',
|
|
197
|
-
'territory-priority',
|
|
198
|
-
'extended-example'
|
|
199
|
-
];
|
|
200
|
-
if (predefinedNames.includes(this._options.config as TsRes.Config.PredefinedSystemConfiguration)) {
|
|
201
|
-
const predefinedResult = TsRes.Config.getPredefinedDeclaration(
|
|
202
|
-
this._options.config as TsRes.Config.PredefinedSystemConfiguration
|
|
203
|
-
);
|
|
204
|
-
if (predefinedResult.isSuccess()) {
|
|
205
|
-
this._systemConfiguration = predefinedResult.value;
|
|
206
|
-
if (this._options.verbose) {
|
|
207
|
-
console.error(`Using predefined configuration: ${this._systemConfiguration.name}`);
|
|
208
|
-
}
|
|
209
|
-
return succeed(this._systemConfiguration);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// If not a predefined config, try to load as file path
|
|
214
|
-
try {
|
|
215
|
-
const configPath = path.resolve(this._options.config);
|
|
216
|
-
if (this._options.debug) {
|
|
217
|
-
console.error(`Loading configuration from: ${configPath}`);
|
|
218
|
-
}
|
|
219
|
-
const configContent = await fs.readFile(configPath, 'utf-8');
|
|
220
|
-
const configData = JSON.parse(configContent);
|
|
221
|
-
|
|
222
|
-
// Validate the configuration using ts-res converter
|
|
223
|
-
const configResult = TsRes.Config.Convert.systemConfiguration.convert(configData);
|
|
224
|
-
if (configResult.isFailure()) {
|
|
225
|
-
return fail(`Invalid configuration file: ${configResult.message}`);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
this._systemConfiguration = configResult.value;
|
|
229
|
-
if (this._options.verbose) {
|
|
230
|
-
console.error(`Using custom configuration: ${this._systemConfiguration.name}`);
|
|
231
|
-
}
|
|
232
|
-
} catch (fileError) {
|
|
233
|
-
return fail(
|
|
234
|
-
`Configuration '${this._options.config}' is not a predefined configuration name and failed to load as file: ${fileError}`
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
} else {
|
|
238
|
-
// Use default predefined configuration
|
|
239
|
-
const defaultResult = TsRes.Config.getPredefinedDeclaration('default');
|
|
240
|
-
if (defaultResult.isSuccess()) {
|
|
241
|
-
this._systemConfiguration = defaultResult.value;
|
|
242
|
-
} else {
|
|
243
|
-
// Fallback to hardcoded default if predefined default is not available
|
|
244
|
-
this._systemConfiguration = DEFAULT_SYSTEM_CONFIGURATION;
|
|
245
|
-
}
|
|
246
|
-
if (this._options.verbose) {
|
|
247
|
-
console.error(`Using default configuration: ${this._systemConfiguration.name}`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return succeed(this._systemConfiguration);
|
|
252
|
-
} catch (error) {
|
|
253
|
-
return fail(`Failed to load configuration: ${error}`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Loads resources from the input path using the configured system
|
|
259
|
-
*/
|
|
260
|
-
private async _loadResources(
|
|
261
|
-
config: TsRes.Config.Model.ISystemConfiguration
|
|
262
|
-
): Promise<Result<TsRes.Resources.ResourceManagerBuilder>> {
|
|
263
|
-
try {
|
|
264
|
-
if (!this._systemConfiguration) {
|
|
265
|
-
return fail('System configuration not loaded');
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// Parse qualifier defaults if provided
|
|
269
|
-
let qualifierDefaultValues: Record<string, string | null> | undefined;
|
|
270
|
-
if (this._options.qualifierDefaults) {
|
|
271
|
-
// We need to create a temporary system configuration first to parse defaults
|
|
272
|
-
const tempSystemConfigResult = TsRes.Config.SystemConfiguration.create(this._systemConfiguration);
|
|
273
|
-
if (tempSystemConfigResult.isFailure()) {
|
|
274
|
-
return fail(`Failed to create temporary system configuration: ${tempSystemConfigResult.message}`);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const tokens = new TsRes.Qualifiers.QualifierDefaultValueTokens(
|
|
278
|
-
tempSystemConfigResult.value.qualifiers
|
|
279
|
-
);
|
|
280
|
-
const defaultsResult = tokens.qualifierDefaultValuesTokenToDecl(this._options.qualifierDefaults);
|
|
281
|
-
if (defaultsResult.isFailure()) {
|
|
282
|
-
return fail(`Failed to parse qualifier defaults: ${defaultsResult.message}`);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
qualifierDefaultValues = defaultsResult.value;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Create system configuration and ts-res system
|
|
289
|
-
const systemConfigResult = TsRes.Config.SystemConfiguration.create(
|
|
290
|
-
this._systemConfiguration,
|
|
291
|
-
qualifierDefaultValues ? { qualifierDefaultValues } : undefined
|
|
292
|
-
);
|
|
293
|
-
if (systemConfigResult.isFailure()) {
|
|
294
|
-
return fail(`Failed to create system configuration: ${systemConfigResult.message}`);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const systemConfig = systemConfigResult.value;
|
|
298
|
-
|
|
299
|
-
// Create resource manager from system configuration
|
|
300
|
-
const manager = TsRes.Resources.ResourceManagerBuilder.create({
|
|
301
|
-
qualifiers: systemConfig.qualifiers,
|
|
302
|
-
resourceTypes: systemConfig.resourceTypes
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
if (manager.isFailure()) {
|
|
306
|
-
return fail(`Failed to create resource manager: ${manager.message}`);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Load resources from input path
|
|
310
|
-
const importResult = await this._importResources(manager.value);
|
|
311
|
-
if (importResult.isFailure()) {
|
|
312
|
-
return fail(`Failed to import resources: ${importResult.message}`);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
return succeed(manager.value);
|
|
316
|
-
} catch (error) {
|
|
317
|
-
return fail(`Failed to load resources: ${error}`);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Imports resources from the input path using ImportManager
|
|
323
|
-
*/
|
|
324
|
-
private async _importResources(manager: TsRes.Resources.ResourceManagerBuilder): Promise<Result<void>> {
|
|
325
|
-
try {
|
|
326
|
-
const inputPath = path.resolve(this._options.input);
|
|
327
|
-
|
|
328
|
-
// Create FileTree for file system operations
|
|
329
|
-
const fileTree = FileTree.forFilesystem();
|
|
330
|
-
if (fileTree.isFailure()) {
|
|
331
|
-
return fail(`Failed to create file tree: ${fileTree.message}`);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Create ImportManager with the resource manager and file tree
|
|
335
|
-
const importManager = TsRes.Import.ImportManager.create({
|
|
336
|
-
resources: manager,
|
|
337
|
-
fileTree: fileTree.value
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
if (importManager.isFailure()) {
|
|
341
|
-
return fail(`Failed to create import manager: ${importManager.message}`);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// Use ImportManager to handle both files and directories automatically
|
|
345
|
-
if (this._options.debug) {
|
|
346
|
-
console.error(`Importing resources from: ${inputPath}`);
|
|
347
|
-
}
|
|
348
|
-
const importResult = importManager.value.importFromFileSystem(inputPath);
|
|
349
|
-
if (importResult.isFailure()) {
|
|
350
|
-
return fail(`Failed to import from ${inputPath}: ${importResult.message}`);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
if (this._options.verbose) {
|
|
354
|
-
console.error(`Successfully imported resources from: ${inputPath}`);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return succeed(undefined);
|
|
358
|
-
} catch (error) {
|
|
359
|
-
return fail(`Failed to import resources: ${error}`);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Applies filters to imported resources
|
|
365
|
-
*/
|
|
366
|
-
private _applyFilters(original: TsRes.Resources.ResourceManagerBuilder): Result<IFilteredManager> {
|
|
367
|
-
if (this._options.contextFilter) {
|
|
368
|
-
const tokens = new TsRes.Context.ContextTokens(original.qualifiers);
|
|
369
|
-
return tokens.contextTokenToPartialContext(this._options.contextFilter).onSuccess((context) => {
|
|
370
|
-
return original
|
|
371
|
-
.clone({
|
|
372
|
-
filterForContext: context,
|
|
373
|
-
reduceQualifiers: this._options.reduceQualifiers
|
|
374
|
-
})
|
|
375
|
-
.onSuccess((manager) => {
|
|
376
|
-
return succeed({ original, manager, context });
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
return succeed({ original, manager: original });
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Generates the output blob
|
|
385
|
-
*/
|
|
386
|
-
private async _generateBlob(filtered: IFilteredManager): Promise<Result<IResourceBlob>> {
|
|
387
|
-
try {
|
|
388
|
-
if (this._options.format === 'compiled') {
|
|
389
|
-
return this._generateCompiledBlob(filtered);
|
|
390
|
-
} else {
|
|
391
|
-
return this._generateSourceBlob(filtered);
|
|
392
|
-
}
|
|
393
|
-
} catch (error) {
|
|
394
|
-
return fail(`Failed to generate blob: ${error}`);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Generates a compiled resource collection blob
|
|
400
|
-
*/
|
|
401
|
-
private _generateCompiledBlob(filtered: IFilteredManager): Result<IResourceBlob> {
|
|
402
|
-
// Build all resources to ensure they're ready for compilation
|
|
403
|
-
return filtered.manager.getCompiledResourceCollection().onSuccess((compiled) => {
|
|
404
|
-
const blob: IResourceBlob = {
|
|
405
|
-
compiledCollection: compiled
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
if (this._options.includeMetadata) {
|
|
409
|
-
blob.metadata = this._generateResourceInfo(filtered);
|
|
410
|
-
}
|
|
411
|
-
return succeed(blob);
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Generates a source format blob (legacy format)
|
|
417
|
-
*/
|
|
418
|
-
private _generateSourceBlob(filtered: IFilteredManager): Result<IResourceBlob> {
|
|
419
|
-
return filtered.manager.getResourceCollectionDecl().onSuccess((resources) => {
|
|
420
|
-
const blob: IResourceBlob = { resources };
|
|
421
|
-
|
|
422
|
-
if (this._options.includeMetadata) {
|
|
423
|
-
blob.metadata = this._generateResourceInfo(filtered);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
return succeed(blob);
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Generates resource information
|
|
432
|
-
*/
|
|
433
|
-
private _generateResourceInfo(filtered: IFilteredManager): IResourceInfo {
|
|
434
|
-
const resourceTypes = Array.from(
|
|
435
|
-
new Set(
|
|
436
|
-
filtered.manager
|
|
437
|
-
.getAllCandidates()
|
|
438
|
-
.map((c) => c.resourceType?.key)
|
|
439
|
-
.filter(Boolean)
|
|
440
|
-
)
|
|
441
|
-
) as string[];
|
|
442
|
-
|
|
443
|
-
const qualifiers = Array.from(filtered.manager.qualifiers.keys());
|
|
444
|
-
|
|
445
|
-
const info: IResourceInfo = {
|
|
446
|
-
totalResources: filtered.original.numResources,
|
|
447
|
-
totalCandidates: filtered.original.numCandidates,
|
|
448
|
-
filteredResources: filtered.manager.numResources,
|
|
449
|
-
filteredCandidates: filtered.manager.numCandidates,
|
|
450
|
-
resourceTypes,
|
|
451
|
-
qualifiers,
|
|
452
|
-
...(filtered.context ? { context: filtered.context } : undefined)
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
return info;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Writes the output blob to the specified output path
|
|
460
|
-
*/
|
|
461
|
-
private async _writeOutput(blob: IResourceBlob): Promise<Result<void>> {
|
|
462
|
-
try {
|
|
463
|
-
const outputPath = path.resolve(this._options.output);
|
|
464
|
-
const outputDir = path.dirname(outputPath);
|
|
465
|
-
|
|
466
|
-
// Ensure output directory exists
|
|
467
|
-
await fs.mkdir(outputDir, { recursive: true });
|
|
468
|
-
|
|
469
|
-
let content: string;
|
|
470
|
-
|
|
471
|
-
switch (this._options.format) {
|
|
472
|
-
case 'compiled':
|
|
473
|
-
// If metadata is included, write the full blob; otherwise, write just the compiled collection
|
|
474
|
-
const compiledData = this._options.includeMetadata ? blob : blob.compiledCollection;
|
|
475
|
-
content = JSON.stringify(compiledData, null, 2);
|
|
476
|
-
break;
|
|
477
|
-
case 'source':
|
|
478
|
-
content = JSON.stringify(blob, null, 2);
|
|
479
|
-
break;
|
|
480
|
-
case 'js':
|
|
481
|
-
const jsData = blob.compiledCollection || blob;
|
|
482
|
-
content = `module.exports = ${JSON.stringify(jsData, null, 2)};`;
|
|
483
|
-
break;
|
|
484
|
-
case 'ts':
|
|
485
|
-
const tsData = blob.compiledCollection || blob;
|
|
486
|
-
content = `export const resources = ${JSON.stringify(tsData, null, 2)} as const;`;
|
|
487
|
-
break;
|
|
488
|
-
case 'binary':
|
|
489
|
-
// For binary format, we could use a more efficient serialization
|
|
490
|
-
// For now, use JSON as a placeholder
|
|
491
|
-
const binaryData = blob.compiledCollection || blob;
|
|
492
|
-
content = JSON.stringify(binaryData);
|
|
493
|
-
break;
|
|
494
|
-
default:
|
|
495
|
-
return fail(`Unsupported output format: ${this._options.format}`);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
await fs.writeFile(outputPath, content, 'utf-8');
|
|
499
|
-
return succeed(undefined);
|
|
500
|
-
} catch (error) {
|
|
501
|
-
return fail(`Failed to write output: ${error}`);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
@@ -1,78 +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 * as TsRes from '@fgv/ts-res';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Default system configuration for ts-res CLI tool
|
|
27
|
-
* This matches the configuration used in the ts-res-browser tool
|
|
28
|
-
*/
|
|
29
|
-
export const DEFAULT_SYSTEM_CONFIGURATION: TsRes.Config.Model.ISystemConfiguration = {
|
|
30
|
-
name: 'Default CLI Configuration',
|
|
31
|
-
description: 'Built-in default configuration for ts-res CLI tool',
|
|
32
|
-
qualifierTypes: [
|
|
33
|
-
{
|
|
34
|
-
name: 'language',
|
|
35
|
-
systemType: 'language',
|
|
36
|
-
configuration: {}
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: 'territory',
|
|
40
|
-
systemType: 'territory',
|
|
41
|
-
configuration: {}
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: 'role',
|
|
45
|
-
systemType: 'literal',
|
|
46
|
-
configuration: {
|
|
47
|
-
enumeratedValues: ['admin', 'user', 'guest']
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
qualifiers: [
|
|
52
|
-
{
|
|
53
|
-
name: 'language',
|
|
54
|
-
typeName: 'language',
|
|
55
|
-
token: 'language',
|
|
56
|
-
defaultPriority: 600
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: 'territory',
|
|
60
|
-
typeName: 'territory',
|
|
61
|
-
token: 'territory',
|
|
62
|
-
defaultPriority: 500
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: 'role',
|
|
66
|
-
typeName: 'role',
|
|
67
|
-
token: 'role',
|
|
68
|
-
tokenIsOptional: true,
|
|
69
|
-
defaultPriority: 400
|
|
70
|
-
}
|
|
71
|
-
],
|
|
72
|
-
resourceTypes: [
|
|
73
|
-
{
|
|
74
|
-
name: 'json',
|
|
75
|
-
typeName: 'json'
|
|
76
|
-
}
|
|
77
|
-
]
|
|
78
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,25 +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
|
-
export * from './cli';
|
|
24
|
-
export * from './compiler';
|
|
25
|
-
export * from './options';
|
package/src/options.ts
DELETED
|
@@ -1,101 +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
|
-
/**
|
|
24
|
-
* Output format options for resource compilation
|
|
25
|
-
*/
|
|
26
|
-
export type OutputFormat = 'compiled' | 'source' | 'js' | 'ts' | 'binary';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Options for resource compilation
|
|
30
|
-
*/
|
|
31
|
-
export interface ICompileOptions {
|
|
32
|
-
/**
|
|
33
|
-
* Input file or directory path
|
|
34
|
-
*/
|
|
35
|
-
input: string;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Output file path
|
|
39
|
-
*/
|
|
40
|
-
output: string;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* System configuration file path (JSON file in ISystemConfiguration format)
|
|
44
|
-
*/
|
|
45
|
-
config?: string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Context filter token (pipe-separated qualifier=value pairs, e.g., 'language=en-US|territory=US')
|
|
49
|
-
*/
|
|
50
|
-
contextFilter?: string;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Qualifier default values token (pipe-separated qualifier=value pairs, e.g., 'language=en-US,en-CA|territory=US')
|
|
54
|
-
*/
|
|
55
|
-
qualifierDefaults?: string;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Output format
|
|
59
|
-
*/
|
|
60
|
-
format: OutputFormat;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Whether to include debug information
|
|
64
|
-
*/
|
|
65
|
-
debug: boolean;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Whether to run in verbose mode
|
|
69
|
-
*/
|
|
70
|
-
verbose: boolean;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Whether to run in quiet mode
|
|
74
|
-
*/
|
|
75
|
-
quiet: boolean;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Whether to validate resources during compilation
|
|
79
|
-
*/
|
|
80
|
-
validate: boolean;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Whether to include resource metadata in output
|
|
84
|
-
*/
|
|
85
|
-
includeMetadata: boolean;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Resource type filter (e.g., 'json,other')
|
|
89
|
-
*/
|
|
90
|
-
resourceTypes?: string;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Maximum distance for language matching
|
|
94
|
-
*/
|
|
95
|
-
maxDistance?: number;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Whether to reduce qualifiers when filtering by context
|
|
99
|
-
*/
|
|
100
|
-
reduceQualifiers?: boolean;
|
|
101
|
-
}
|