@fgv/ts-res-browser 5.0.0-2 → 5.0.0-21
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/cli.js +132 -21
- package/dist/bundle.js +1 -1
- package/dist/bundle.js.LICENSE.txt +11 -1
- package/package.json +42 -36
- package/.rush/temp/587277bfc395406ad444e989b6c309b9698f534c.tar.log +0 -15
- package/.rush/temp/chunked-rush-logs/ts-res-browser.build.chunks.jsonl +0 -35
- package/.rush/temp/operation/build/all.log +0 -35
- package/.rush/temp/operation/build/log-chunks.jsonl +0 -35
- package/.rush/temp/operation/build/state.json +0 -3
- package/.rush/temp/shrinkwrap-deps.json +0 -1225
- package/TS_RES_BROWSER_PLAN.md +0 -689
- package/babel.config.js +0 -17
- package/config/jest.config.json +0 -13
- package/config/rig.json +0 -16
- package/postcss.config.js +0 -3
- package/public/index.html +0 -15
- package/rush-logs/ts-res-browser.build.cache.log +0 -3
- package/rush-logs/ts-res-browser.build.log +0 -35
- package/src/App.tsx +0 -274
- package/src/cli.ts +0 -44
- package/src/components/common/FileImporter.tsx +0 -143
- package/src/components/common/NavigationWarningModal.tsx +0 -62
- package/src/components/layout/AppLayout.tsx +0 -46
- package/src/components/layout/Header.tsx +0 -22
- package/src/components/layout/MessagesWindow.tsx +0 -108
- package/src/components/layout/Sidebar.tsx +0 -99
- package/src/components/tools/CompiledBrowser.tsx +0 -949
- package/src/components/tools/ConfigurationTool.tsx +0 -1405
- package/src/components/tools/FilterTool.tsx +0 -1114
- package/src/components/tools/ImportTool.tsx +0 -249
- package/src/components/tools/ResolutionViewer.tsx +0 -1672
- package/src/components/tools/SourceBrowser.tsx +0 -496
- package/src/components/tools/ZipLoader.tsx +0 -302
- package/src/hooks/useAppState.ts +0 -111
- package/src/hooks/useFileImport.ts +0 -86
- package/src/hooks/useNavigationWarning.ts +0 -67
- package/src/hooks/useResourceManager.ts +0 -295
- package/src/hooks/useUrlParams.ts +0 -56
- package/src/index.css +0 -38
- package/src/main.tsx +0 -16
- package/src/types/app.ts +0 -70
- package/src/types/fileSystemAccess.d.ts +0 -94
- package/src/utils/browserFileTreeAccessors.ts +0 -245
- package/src/utils/fileImport.ts +0 -336
- package/src/utils/fileTreeConverter.ts +0 -160
- package/src/utils/filterResources.ts +0 -677
- package/src/utils/tsResIntegration.ts +0 -467
- package/src/utils/urlParams.ts +0 -238
- package/src/utils/zip/browserZipFileTreeAccessors.ts +0 -385
- package/tailwind.config.js +0 -21
- package/test-data/README.md +0 -184
- package/test-data/config-variations/README.md +0 -64
- package/test-data/config-variations/composition-terminology.json +0 -112
- package/test-data/config-variations/enterprise-complex.json +0 -129
- package/test-data/config-variations/gaming-app.json +0 -87
- package/test-data/config-variations/high-priority-language.json +0 -65
- package/test-data/config-variations/minimal-basic.json +0 -37
- package/test-data/config-variations/qualifier-default-values.json +0 -71
- package/test-data/config-variations/territory-first.json +0 -68
- package/test-data/config-variations/territory-hierarchy-test.json +0 -31
- package/test-data/config-variations/territory-hierarchy-unconstrained.json +0 -32
- package/test-data/default-matching-test/greeting.res.json +0 -83
- package/test-data/default-matching-test/only-defaults.res.json +0 -48
- package/test-data/sample-project/package.json +0 -27
- package/test-data/sample-project/src/resources/app-config.json +0 -27
- package/test-data/sample-project/src/resources/app.json +0 -177
- package/test-data/sample-project/src/resources/config/app.env=development.json +0 -21
- package/test-data/sample-project/src/resources/config/app.json +0 -21
- package/test-data/sample-project/src/resources/config/app.platform=mobile.json +0 -23
- package/test-data/sample-project/src/resources/feature-flags.json +0 -23
- package/test-data/sample-project/src/resources/home=CA/common.json +0 -16
- package/test-data/sample-project/src/resources/images/density=hdpi.json +0 -29
- package/test-data/sample-project/src/resources/images/home.json +0 -29
- package/test-data/sample-project/src/resources/images/logout.json +0 -14
- package/test-data/sample-project/src/resources/images/settings.json +0 -14
- package/test-data/sample-project/src/resources/images/ui-icons.json +0 -29
- package/test-data/sample-project/src/resources/images/user.density=hdpi.json +0 -14
- package/test-data/sample-project/src/resources/images/user.json +0 -14
- package/test-data/sample-project/src/resources/lang=en-US/common.json +0 -15
- package/test-data/sample-project/src/resources/language=en-CA/ui-terms.json +0 -19
- package/test-data/sample-project/src/resources/language=en-GB/ui-terms.json +0 -30
- package/test-data/sample-project/src/resources/language=fr-CA/ui-terms.json +0 -25
- package/test-data/sample-project/src/resources/language=nl-BE/ui-terms.json +0 -17
- package/test-data/sample-project/src/resources/region=europe/feature-flags.json +0 -17
- package/test-data/sample-project/src/resources/region=north-america/feature-flags.json +0 -18
- package/test-data/sample-project/src/resources/strings/dashboard.home=CA,language=fr.json +0 -20
- package/test-data/sample-project/src/resources/strings/dashboard.json +0 -18
- package/test-data/sample-project/src/resources/strings/dashboard.role=admin.json +0 -23
- package/test-data/sample-project/src/resources/strings/dashboard.role=user.json +0 -21
- package/test-data/sample-project/src/resources/strings/language=en-US.json +0 -16
- package/test-data/sample-project/src/resources/strings.json +0 -78
- package/test-data/sample-project/src/resources/territory=BE/app-config.json +0 -19
- package/test-data/sample-project/src/resources/territory=CA/app-config.json +0 -21
- package/test-data/sample-project/src/resources/territory=GB/app-config.json +0 -25
- package/test-data/sample-project/src/resources/territory=NL/app-config.json +0 -25
- package/test-data/sample-project/src/resources/ui-terms.json +0 -96
- package/test-data/sample-project/src/resources-config.json +0 -111
- package/tsconfig.json +0 -27
- package/webpack.config.js +0 -60
|
@@ -1,385 +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 JSZip from 'jszip';
|
|
24
|
-
import { Result, succeed, fail, captureResult, Converter, Validator, FileTree } from '@fgv/ts-utils';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Implementation of {@link FileTree.IFileTreeFileItem} for files in a ZIP archive (browser version).
|
|
28
|
-
*/
|
|
29
|
-
export class BrowserZipFileItem implements FileTree.IFileTreeFileItem {
|
|
30
|
-
/**
|
|
31
|
-
* Indicates that this {@link FileTree.FileTreeItem} is a file.
|
|
32
|
-
*/
|
|
33
|
-
public readonly type: 'file' = 'file';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The absolute path of the file within the ZIP archive.
|
|
37
|
-
*/
|
|
38
|
-
public readonly absolutePath: string;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The name of the file
|
|
42
|
-
*/
|
|
43
|
-
public readonly name: string;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The base name of the file (without extension)
|
|
47
|
-
*/
|
|
48
|
-
public readonly baseName: string;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The extension of the file
|
|
52
|
-
*/
|
|
53
|
-
public readonly extension: string;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The pre-loaded contents of the file.
|
|
57
|
-
*/
|
|
58
|
-
private readonly _contents: string;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* The ZIP file tree accessors that created this item.
|
|
62
|
-
*/
|
|
63
|
-
private readonly _accessors: BrowserZipFileTreeAccessors;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Constructor for BrowserZipFileItem.
|
|
67
|
-
* @param zipFilePath - The path of the file within the ZIP.
|
|
68
|
-
* @param contents - The pre-loaded contents of the file.
|
|
69
|
-
* @param accessors - The ZIP file tree accessors.
|
|
70
|
-
*/
|
|
71
|
-
public constructor(zipFilePath: string, contents: string, accessors: BrowserZipFileTreeAccessors) {
|
|
72
|
-
this._contents = contents;
|
|
73
|
-
this._accessors = accessors;
|
|
74
|
-
this.absolutePath = '/' + zipFilePath;
|
|
75
|
-
this.name = accessors.getBaseName(zipFilePath);
|
|
76
|
-
this.extension = accessors.getExtension(zipFilePath);
|
|
77
|
-
this.baseName = accessors.getBaseName(zipFilePath, this.extension);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Gets the contents of the file as parsed JSON.
|
|
82
|
-
*/
|
|
83
|
-
public getContents(): Result<unknown>;
|
|
84
|
-
public getContents<T>(converter: Validator<T> | Converter<T>): Result<T>;
|
|
85
|
-
public getContents<T>(converter?: Validator<T> | Converter<T>): Result<T | unknown> {
|
|
86
|
-
return this.getRawContents()
|
|
87
|
-
.onSuccess((contents) => {
|
|
88
|
-
return captureResult(() => {
|
|
89
|
-
const parsed = JSON.parse(contents);
|
|
90
|
-
if (converter) {
|
|
91
|
-
if ('convert' in converter) {
|
|
92
|
-
return converter.convert(parsed);
|
|
93
|
-
} else {
|
|
94
|
-
return (converter as Validator<T>).validate(parsed);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return succeed(parsed);
|
|
98
|
-
}).onFailure(() => {
|
|
99
|
-
return fail(`Failed to parse JSON from file: ${this.absolutePath}`);
|
|
100
|
-
});
|
|
101
|
-
})
|
|
102
|
-
.onFailure((error) => {
|
|
103
|
-
return fail(`Failed to get contents from file: ${error}`);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Gets the raw contents of the file as a string.
|
|
109
|
-
*/
|
|
110
|
-
public getRawContents(): Result<string> {
|
|
111
|
-
return succeed(this._contents);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Implementation of {@link FileTree.IFileTreeDirectoryItem} for directories in a ZIP archive (browser version).
|
|
117
|
-
*/
|
|
118
|
-
export class BrowserZipDirectoryItem implements FileTree.IFileTreeDirectoryItem {
|
|
119
|
-
/**
|
|
120
|
-
* Indicates that this {@link FileTree.FileTreeItem} is a directory.
|
|
121
|
-
*/
|
|
122
|
-
public readonly type: 'directory' = 'directory';
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* The absolute path of the directory within the ZIP archive.
|
|
126
|
-
*/
|
|
127
|
-
public readonly absolutePath: string;
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* The name of the directory
|
|
131
|
-
*/
|
|
132
|
-
public readonly name: string;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* The ZIP file tree accessors that created this item.
|
|
136
|
-
*/
|
|
137
|
-
private readonly _accessors: BrowserZipFileTreeAccessors;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Constructor for BrowserZipDirectoryItem.
|
|
141
|
-
* @param directoryPath - The path of the directory within the ZIP.
|
|
142
|
-
* @param accessors - The ZIP file tree accessors.
|
|
143
|
-
*/
|
|
144
|
-
public constructor(directoryPath: string, accessors: BrowserZipFileTreeAccessors) {
|
|
145
|
-
this._accessors = accessors;
|
|
146
|
-
this.absolutePath = '/' + directoryPath.replace(/\/$/, ''); // Normalize path
|
|
147
|
-
this.name = accessors.getBaseName(directoryPath);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Gets the children of the directory.
|
|
152
|
-
*/
|
|
153
|
-
public getChildren(): Result<ReadonlyArray<FileTree.FileTreeItem>> {
|
|
154
|
-
return this._accessors.getChildren(this.absolutePath);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* File tree accessors for ZIP archives (browser version using JSZip).
|
|
160
|
-
*/
|
|
161
|
-
export class BrowserZipFileTreeAccessors implements FileTree.IFileTreeAccessors {
|
|
162
|
-
/**
|
|
163
|
-
* The JSZip instance containing the archive.
|
|
164
|
-
*/
|
|
165
|
-
private readonly _zip: JSZip;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Optional prefix to prepend to paths.
|
|
169
|
-
*/
|
|
170
|
-
private readonly _prefix: string;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Cache of all items in the ZIP for efficient lookups.
|
|
174
|
-
*/
|
|
175
|
-
private readonly _itemCache: Map<string, FileTree.FileTreeItem> = new Map();
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Cache of all file contents pre-loaded from the ZIP.
|
|
179
|
-
*/
|
|
180
|
-
private readonly _fileContents: Map<string, string> = new Map();
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Constructor for BrowserZipFileTreeAccessors.
|
|
184
|
-
* @param zip - The JSZip instance.
|
|
185
|
-
* @param fileContents - Pre-loaded file contents.
|
|
186
|
-
* @param prefix - Optional prefix to prepend to paths.
|
|
187
|
-
*/
|
|
188
|
-
private constructor(zip: JSZip, fileContents: Map<string, string>, prefix?: string) {
|
|
189
|
-
this._zip = zip;
|
|
190
|
-
this._fileContents = fileContents;
|
|
191
|
-
this._prefix = prefix || '';
|
|
192
|
-
this._buildItemCache();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Creates a new BrowserZipFileTreeAccessors instance from a ZIP file buffer.
|
|
197
|
-
* @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
|
|
198
|
-
* @param prefix - Optional prefix to prepend to paths.
|
|
199
|
-
* @returns Result containing the BrowserZipFileTreeAccessors instance.
|
|
200
|
-
*/
|
|
201
|
-
public static async fromBuffer(
|
|
202
|
-
zipBuffer: ArrayBuffer | Uint8Array,
|
|
203
|
-
prefix?: string
|
|
204
|
-
): Promise<Result<BrowserZipFileTreeAccessors>> {
|
|
205
|
-
try {
|
|
206
|
-
const zip = new JSZip();
|
|
207
|
-
await zip.loadAsync(zipBuffer);
|
|
208
|
-
const fileContents = new Map<string, string>();
|
|
209
|
-
|
|
210
|
-
// Pre-load all file contents
|
|
211
|
-
const promises: Promise<void>[] = [];
|
|
212
|
-
zip.forEach((relativePath, zipObject) => {
|
|
213
|
-
if (!zipObject.dir) {
|
|
214
|
-
const promise = zipObject.async('string').then((content) => {
|
|
215
|
-
fileContents.set(relativePath, content);
|
|
216
|
-
});
|
|
217
|
-
promises.push(promise);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
await Promise.all(promises);
|
|
222
|
-
return succeed(new BrowserZipFileTreeAccessors(zip, fileContents, prefix));
|
|
223
|
-
} catch (error) {
|
|
224
|
-
return fail(`Failed to load ZIP archive: ${error instanceof Error ? error.message : String(error)}`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Creates a new BrowserZipFileTreeAccessors instance from a File object (browser environment).
|
|
230
|
-
* @param file - The File object containing ZIP data.
|
|
231
|
-
* @param prefix - Optional prefix to prepend to paths.
|
|
232
|
-
* @returns Result containing the BrowserZipFileTreeAccessors instance.
|
|
233
|
-
*/
|
|
234
|
-
public static async fromFile(file: File, prefix?: string): Promise<Result<BrowserZipFileTreeAccessors>> {
|
|
235
|
-
try {
|
|
236
|
-
const arrayBuffer = await file.arrayBuffer();
|
|
237
|
-
return await BrowserZipFileTreeAccessors.fromBuffer(arrayBuffer, prefix);
|
|
238
|
-
} catch (error) {
|
|
239
|
-
return fail(`Failed to read file: ${error instanceof Error ? error.message : String(error)}`);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Builds the cache of all items in the ZIP archive.
|
|
245
|
-
*/
|
|
246
|
-
private _buildItemCache(): void {
|
|
247
|
-
const directories = new Set<string>();
|
|
248
|
-
|
|
249
|
-
// First pass: collect all directories from file paths
|
|
250
|
-
this._zip.forEach((relativePath, zipObject) => {
|
|
251
|
-
if (!zipObject.dir) {
|
|
252
|
-
// Extract directory path from file path
|
|
253
|
-
const pathParts = relativePath.split('/');
|
|
254
|
-
for (let i = 1; i < pathParts.length; i++) {
|
|
255
|
-
const dirPath = pathParts.slice(0, i).join('/');
|
|
256
|
-
directories.add(dirPath);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
// Add directory items to cache
|
|
262
|
-
directories.forEach((dirPath) => {
|
|
263
|
-
const absolutePath = this.resolveAbsolutePath(dirPath);
|
|
264
|
-
const item = new BrowserZipDirectoryItem(dirPath, this);
|
|
265
|
-
this._itemCache.set(absolutePath, item);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
// Add file items to cache
|
|
269
|
-
this._zip.forEach((relativePath, zipObject) => {
|
|
270
|
-
if (!zipObject.dir) {
|
|
271
|
-
const absolutePath = this.resolveAbsolutePath(relativePath);
|
|
272
|
-
const contents = this._fileContents.get(relativePath) || '';
|
|
273
|
-
const item = new BrowserZipFileItem(relativePath, contents, this);
|
|
274
|
-
this._itemCache.set(absolutePath, item);
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Resolves paths to an absolute path.
|
|
281
|
-
*/
|
|
282
|
-
public resolveAbsolutePath(...paths: string[]): string {
|
|
283
|
-
const joinedPath = this.joinPaths(...paths);
|
|
284
|
-
const prefixed = this._prefix ? this.joinPaths(this._prefix, joinedPath) : joinedPath;
|
|
285
|
-
return prefixed.startsWith('/') ? prefixed : '/' + prefixed;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Gets the extension of a path.
|
|
290
|
-
*/
|
|
291
|
-
public getExtension(path: string): string {
|
|
292
|
-
const name = this.getBaseName(path);
|
|
293
|
-
const lastDotIndex = name.lastIndexOf('.');
|
|
294
|
-
return lastDotIndex >= 0 ? name.substring(lastDotIndex) : '';
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Gets the base name of a path.
|
|
299
|
-
*/
|
|
300
|
-
public getBaseName(path: string, suffix?: string): string {
|
|
301
|
-
const normalizedPath = path.replace(/\/$/, ''); // Remove trailing slash
|
|
302
|
-
const parts = normalizedPath.split('/');
|
|
303
|
-
let baseName = parts[parts.length - 1] || '';
|
|
304
|
-
|
|
305
|
-
if (suffix && baseName.endsWith(suffix)) {
|
|
306
|
-
baseName = baseName.substring(0, baseName.length - suffix.length);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
return baseName;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Joins paths together.
|
|
314
|
-
*/
|
|
315
|
-
public joinPaths(...paths: string[]): string {
|
|
316
|
-
return paths
|
|
317
|
-
.filter((p) => p && p.length > 0)
|
|
318
|
-
.map((p) => p.replace(/^\/+|\/+$/g, '')) // Remove leading/trailing slashes
|
|
319
|
-
.join('/')
|
|
320
|
-
.replace(/\/+/g, '/'); // Normalize multiple slashes
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Gets an item from the file tree.
|
|
325
|
-
*/
|
|
326
|
-
public getItem(path: string): Result<FileTree.FileTreeItem> {
|
|
327
|
-
const absolutePath = this.resolveAbsolutePath(path);
|
|
328
|
-
const item = this._itemCache.get(absolutePath);
|
|
329
|
-
|
|
330
|
-
if (item) {
|
|
331
|
-
return succeed(item);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
return fail(`Item not found: ${absolutePath}`);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Gets the contents of a file in the file tree.
|
|
339
|
-
*/
|
|
340
|
-
public getFileContents(path: string): Result<string> {
|
|
341
|
-
return this.getItem(path).onSuccess((item) => {
|
|
342
|
-
if (item.type !== 'file') {
|
|
343
|
-
return fail(`Path is not a file: ${path}`);
|
|
344
|
-
}
|
|
345
|
-
return item.getRawContents();
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Gets the children of a directory in the file tree.
|
|
351
|
-
*/
|
|
352
|
-
public getChildren(path: string): Result<ReadonlyArray<FileTree.FileTreeItem>> {
|
|
353
|
-
const absolutePath = this.resolveAbsolutePath(path);
|
|
354
|
-
const children: FileTree.FileTreeItem[] = [];
|
|
355
|
-
|
|
356
|
-
// Find all items that are direct children of this directory
|
|
357
|
-
for (const [itemPath, item] of this._itemCache) {
|
|
358
|
-
if (this._isDirectChild(absolutePath, itemPath)) {
|
|
359
|
-
children.push(item);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return succeed(children);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Checks if childPath is a direct child of parentPath.
|
|
368
|
-
*/
|
|
369
|
-
private _isDirectChild(parentPath: string, childPath: string): boolean {
|
|
370
|
-
// Normalize paths
|
|
371
|
-
const normalizedParent = parentPath.replace(/\/$/, '');
|
|
372
|
-
const normalizedChild = childPath.replace(/\/$/, '');
|
|
373
|
-
|
|
374
|
-
// Child must start with parent path
|
|
375
|
-
if (!normalizedChild.startsWith(normalizedParent + '/')) {
|
|
376
|
-
return false;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// Get the relative path from parent to child
|
|
380
|
-
const relativePath = normalizedChild.substring(normalizedParent.length + 1);
|
|
381
|
-
|
|
382
|
-
// Direct child means no additional slashes in the relative path
|
|
383
|
-
return !relativePath.includes('/');
|
|
384
|
-
}
|
|
385
|
-
}
|
package/tailwind.config.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/** @type {import('tailwindcss').Config} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
content: [
|
|
4
|
-
'./src/**/*.{js,jsx,ts,tsx}',
|
|
5
|
-
'./public/index.html',
|
|
6
|
-
'./src/components/**/*.{js,jsx,ts,tsx}',
|
|
7
|
-
'./src/hooks/**/*.{js,jsx,ts,tsx}',
|
|
8
|
-
'./src/utils/**/*.{js,jsx,ts,tsx}'
|
|
9
|
-
],
|
|
10
|
-
theme: {
|
|
11
|
-
extend: {
|
|
12
|
-
colors: {
|
|
13
|
-
// Custom colors for the ts-res browser
|
|
14
|
-
'res-primary': '#2563eb',
|
|
15
|
-
'res-secondary': '#1e40af',
|
|
16
|
-
'res-accent': '#3b82f6'
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
plugins: []
|
|
21
|
-
};
|
package/test-data/README.md
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
# TS-RES Test Data
|
|
2
|
-
|
|
3
|
-
This directory contains test data for the ts-res-browser tool that demonstrates all ts-res file formats and naming conventions.
|
|
4
|
-
|
|
5
|
-
## Structure
|
|
6
|
-
|
|
7
|
-
The test data demonstrates three different JSON file formats supported by ts-res:
|
|
8
|
-
|
|
9
|
-
### 1. Simple JSON Files (Auto-converted to Resource Candidates)
|
|
10
|
-
Individual JSON files with plain resource values that the ImportManager automatically converts to resource candidates.
|
|
11
|
-
|
|
12
|
-
### 2. Resource Collection Format (`IResourceCollectionDecl`)
|
|
13
|
-
JSON files that explicitly define multiple resources with their candidates and conditions.
|
|
14
|
-
|
|
15
|
-
### 3. Resource Tree Format (`IResourceTreeRootDecl`)
|
|
16
|
-
JSON files that define hierarchical resource structures with nested organization.
|
|
17
|
-
|
|
18
|
-
## Directory Structure
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
src/resources/
|
|
22
|
-
├── strings.json # Resource Collection (common, errors resources)
|
|
23
|
-
├── app.json # Resource Tree (app.config, app.ui.dashboard, app.ui.icons.* resources)
|
|
24
|
-
├── strings/
|
|
25
|
-
│ ├── common.json # Simple JSON → "common" resource
|
|
26
|
-
│ ├── common.language=es.json # Simple JSON → "common" resource (Spanish)
|
|
27
|
-
│ ├── common.language=fr.json # Simple JSON → "common" resource (French)
|
|
28
|
-
│ ├── language=en-US.json # Simple JSON → "language" resource
|
|
29
|
-
│ ├── dashboard.json # Simple JSON → "dashboard" resource
|
|
30
|
-
│ ├── dashboard.role=user.json # Simple JSON → "dashboard" resource (user)
|
|
31
|
-
│ ├── dashboard.role=admin.json # Simple JSON → "dashboard" resource (admin)
|
|
32
|
-
│ ├── dashboard.home=CA,language=fr.json # Simple JSON → "dashboard" resource (CA+FR)
|
|
33
|
-
│ └── errors.json # Simple JSON → "errors" resource
|
|
34
|
-
├── config/
|
|
35
|
-
│ ├── app.json # Simple JSON → "app" resource
|
|
36
|
-
│ ├── app.env=development.json # Simple JSON → "app" resource (dev)
|
|
37
|
-
│ └── app.platform=mobile.json # Simple JSON → "app" resource (mobile)
|
|
38
|
-
├── images/
|
|
39
|
-
│ ├── home.json # Simple JSON → "home" resource
|
|
40
|
-
│ ├── home.density=hdpi.json # Simple JSON → "home" resource (hdpi)
|
|
41
|
-
│ ├── user.json # Simple JSON → "user" resource
|
|
42
|
-
│ ├── user.density=hdpi.json # Simple JSON → "user" resource (hdpi)
|
|
43
|
-
│ ├── settings.json # Simple JSON → "settings" resource
|
|
44
|
-
│ ├── settings.density=hdpi.json # Simple JSON → "settings" resource (hdpi)
|
|
45
|
-
│ ├── logout.json # Simple JSON → "logout" resource
|
|
46
|
-
│ └── logout.density=hdpi.json # Simple JSON → "logout" resource (hdpi)
|
|
47
|
-
├── en-US/
|
|
48
|
-
│ └── common.json # Simple JSON → "common" resource (en-US context)
|
|
49
|
-
├── home=CA/
|
|
50
|
-
│ └── common.json # Simple JSON → "common" resource (CA context)
|
|
51
|
-
└── import-config.json # TS-RES configuration
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Format Examples
|
|
55
|
-
|
|
56
|
-
### Simple JSON Format
|
|
57
|
-
```json
|
|
58
|
-
{
|
|
59
|
-
"welcome": "Welcome to the application",
|
|
60
|
-
"hello": "Hello",
|
|
61
|
-
"goodbye": "Goodbye"
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
*Auto-converted to resource candidate by ImportManager*
|
|
65
|
-
|
|
66
|
-
### Resource Collection Format
|
|
67
|
-
```json
|
|
68
|
-
{
|
|
69
|
-
"resources": [
|
|
70
|
-
{
|
|
71
|
-
"id": "common",
|
|
72
|
-
"resourceTypeName": "json",
|
|
73
|
-
"candidates": [
|
|
74
|
-
{
|
|
75
|
-
"json": {
|
|
76
|
-
"welcome": "Welcome to the application",
|
|
77
|
-
"hello": "Hello"
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
"json": {
|
|
82
|
-
"welcome": "Bienvenido a la aplicación",
|
|
83
|
-
"hello": "Hola"
|
|
84
|
-
},
|
|
85
|
-
"conditions": {
|
|
86
|
-
"language": "es"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Resource Tree Format
|
|
96
|
-
```json
|
|
97
|
-
{
|
|
98
|
-
"context": {
|
|
99
|
-
"baseId": "app"
|
|
100
|
-
},
|
|
101
|
-
"resources": {
|
|
102
|
-
"config": {
|
|
103
|
-
"resourceTypeName": "json",
|
|
104
|
-
"candidates": [
|
|
105
|
-
{
|
|
106
|
-
"json": {
|
|
107
|
-
"app_name": "Sample Application",
|
|
108
|
-
"version": "1.0.0"
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
]
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
"children": {
|
|
115
|
-
"ui": {
|
|
116
|
-
"resources": {
|
|
117
|
-
"dashboard": {
|
|
118
|
-
"resourceTypeName": "json",
|
|
119
|
-
"candidates": [
|
|
120
|
-
{
|
|
121
|
-
"json": {
|
|
122
|
-
"title": "Dashboard",
|
|
123
|
-
"overview": "Overview"
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
]
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## Resources Generated
|
|
135
|
-
|
|
136
|
-
The test data creates these resources:
|
|
137
|
-
|
|
138
|
-
### From Simple JSON Files
|
|
139
|
-
- `common` (4 candidates: base, Spanish, French, directory-based)
|
|
140
|
-
- `dashboard` (4 candidates: base, user, admin, CA+French)
|
|
141
|
-
- `errors` (1 candidate: base)
|
|
142
|
-
- `language` (1 candidate: en-US)
|
|
143
|
-
- `app` (3 candidates: base, dev, mobile)
|
|
144
|
-
- `home`, `user`, `settings`, `logout` (2 candidates each: standard, hdpi)
|
|
145
|
-
|
|
146
|
-
### From Resource Collection (strings.json)
|
|
147
|
-
- `common` (3 candidates: base, Spanish, French)
|
|
148
|
-
- `errors` (1 candidate: base)
|
|
149
|
-
|
|
150
|
-
### From Resource Tree (app.json)
|
|
151
|
-
- `app.config` (3 candidates: base, dev, mobile)
|
|
152
|
-
- `app.ui.dashboard` (3 candidates: base, user, admin)
|
|
153
|
-
- `app.ui.icons.home` (2 candidates: standard, hdpi)
|
|
154
|
-
- `app.ui.icons.user` (2 candidates: standard, hdpi)
|
|
155
|
-
|
|
156
|
-
## Qualifiers Demonstrated
|
|
157
|
-
|
|
158
|
-
- **language**: `es`, `fr`, `en-US` (language codes)
|
|
159
|
-
- **homeTerritory**: `CA` (with `home=` token, optional)
|
|
160
|
-
- **role**: `user`, `admin` (literal values)
|
|
161
|
-
- **env**: `development` (literal values)
|
|
162
|
-
- **platform**: `mobile` (literal values)
|
|
163
|
-
- **density**: `hdpi` (literal values)
|
|
164
|
-
|
|
165
|
-
## Import Configuration
|
|
166
|
-
|
|
167
|
-
The `import-config.json` file defines:
|
|
168
|
-
- **Qualifier Types**: language, territory, literal
|
|
169
|
-
- **Qualifiers**: language, homeTerritory, currentTerritory, role, env, platform, density
|
|
170
|
-
- **Resource Types**: json
|
|
171
|
-
|
|
172
|
-
## Usage
|
|
173
|
-
|
|
174
|
-
This test data demonstrates:
|
|
175
|
-
|
|
176
|
-
1. **Simple JSON Import**: Basic file-to-resource conversion
|
|
177
|
-
2. **Resource Collections**: Multiple resources with candidates in one file
|
|
178
|
-
3. **Resource Trees**: Hierarchical organization with nested resources
|
|
179
|
-
4. **Qualifier Parsing**: File-based and explicit condition formats
|
|
180
|
-
5. **Multi-condition Resources**: Complex qualifier combinations
|
|
181
|
-
6. **Directory-based Organization**: Conditional directories
|
|
182
|
-
7. **Mixed Formats**: Using different formats together
|
|
183
|
-
|
|
184
|
-
The data follows ts-res patterns and provides comprehensive examples for testing all browser tool features.
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# Configuration Variations
|
|
2
|
-
|
|
3
|
-
This directory contains various system configuration files for testing the ts-res browser tool. Each configuration demonstrates different priority schemes and use cases.
|
|
4
|
-
|
|
5
|
-
## Available Configurations
|
|
6
|
-
|
|
7
|
-
### high-priority-language.json
|
|
8
|
-
- **Use Case**: Internationalization-focused applications
|
|
9
|
-
- **Priority**: Language (900) > Territory (600/500) > Role (400) > Platform (300)
|
|
10
|
-
- **Features**: Simplified role set, basic platform types
|
|
11
|
-
|
|
12
|
-
### territory-first.json
|
|
13
|
-
- **Use Case**: Region-specific applications
|
|
14
|
-
- **Priority**: Territory (950/900) > Language (700) > Role (600) > Environment (500)
|
|
15
|
-
- **Features**: Case-sensitive roles, territory context lists enabled, non-optional home territory token
|
|
16
|
-
|
|
17
|
-
### gaming-app.json
|
|
18
|
-
- **Use Case**: Gaming applications
|
|
19
|
-
- **Priority**: Platform (850) > Language (800) > Territory (750) > Graphics (700) > Player Level (600) > Game Mode (550)
|
|
20
|
-
- **Features**: Gaming-specific qualifiers (graphics quality, player level, game mode), platform-focused hierarchy
|
|
21
|
-
|
|
22
|
-
### minimal-basic.json
|
|
23
|
-
- **Use Case**: Simple applications with basic requirements
|
|
24
|
-
- **Priority**: Language (600) > Device (500)
|
|
25
|
-
- **Features**: Only two qualifiers, minimal complexity
|
|
26
|
-
|
|
27
|
-
### qualifier-default-values.json
|
|
28
|
-
- **Use Case**: Demonstrating qualifier default values functionality
|
|
29
|
-
- **Priority**: Language (600) > Territory (500) > Device (400) > Environment (300)
|
|
30
|
-
- **Features**: All qualifiers have default values configured (language with multiple values, territory single value, device with list, environment single value)
|
|
31
|
-
- **Demonstrates**: How default values are defined and used when qualifiers are not specified in context
|
|
32
|
-
|
|
33
|
-
### enterprise-complex.json
|
|
34
|
-
- **Use Case**: Large enterprise applications with complex permissions and multi-tenancy
|
|
35
|
-
- **Priority**: Tenant (1000) > Environment (950) > Security (900) > Territory (850/800) > Language (750) > Role (700) > Department (650) > Feature Flags (600)
|
|
36
|
-
- **Features**: Multi-tenant support, security levels, department-based access, feature flags, complex role hierarchies
|
|
37
|
-
|
|
38
|
-
### composition-terminology.json
|
|
39
|
-
- **Use Case**: Demonstrating resource composition with international terminology variations plus full application context
|
|
40
|
-
- **Priority**: Home Territory (850) > Language (800) > Territory (700) > Region (600) > Role (500) > Environment (400) > Platform (300) > Density (200)
|
|
41
|
-
- **Features**: Comprehensive terminology resources showing composition with partial candidates for regional variations, plus full application qualifiers for testing existing resources
|
|
42
|
-
- **Resources**: UI terms with base English/French/Dutch candidates and partial variants for Canadian English, British English, Canadian French, Belgian Dutch; App configuration with territory-specific settings; Feature flags with regional overrides; Plus supports existing sample project resources
|
|
43
|
-
- **Demonstrates**: How partial candidates compose with base candidates to create localized terminology sets while maintaining compatibility with existing test resources
|
|
44
|
-
|
|
45
|
-
## Usage
|
|
46
|
-
|
|
47
|
-
These configurations can be loaded into the Configuration Tool to test different system setups and see how they affect resource resolution behavior.
|
|
48
|
-
|
|
49
|
-
Each configuration includes:
|
|
50
|
-
- **name**: Human-readable name for the configuration
|
|
51
|
-
- **description**: Explanation of the use case and features
|
|
52
|
-
- **qualifierTypes**: Defines the available qualifier types with their configurations
|
|
53
|
-
- **qualifiers**: Defines the actual qualifiers with their priorities and tokens
|
|
54
|
-
- **resourceTypes**: Available resource types (currently just JSON)
|
|
55
|
-
|
|
56
|
-
## Testing Different Scenarios
|
|
57
|
-
|
|
58
|
-
Use these configurations to test:
|
|
59
|
-
1. **Priority Effects**: How different priority schemes affect resource resolution
|
|
60
|
-
2. **Context Lists**: Territory and role configurations with `allowContextList` enabled
|
|
61
|
-
3. **Case Sensitivity**: Role configurations with different case sensitivity settings
|
|
62
|
-
4. **Token Usage**: Various token configurations (optional vs required)
|
|
63
|
-
5. **Default Values**: Qualifier default values for fallback behavior (see qualifier-default-values.json)
|
|
64
|
-
6. **Complexity Scaling**: From minimal (2 qualifiers) to complex (9 qualifiers)
|