@fgv/ts-res-cli 1.0.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.
Files changed (43) hide show
  1. package/.eslintrc.js +9 -0
  2. package/.rush/temp/chunked-rush-logs/ts-res-cli.build.chunks.jsonl +6 -0
  3. package/.rush/temp/operation/build/log-chunks.jsonl +6 -0
  4. package/.rush/temp/operation/build/state.json +3 -0
  5. package/.rush/temp/shrinkwrap-deps.json +651 -0
  6. package/README.md +197 -0
  7. package/bin/ts-res-compile.js +40 -0
  8. package/config/jest.config.json +9 -0
  9. package/config/rig.json +16 -0
  10. package/lib/cli.d.ts +36 -0
  11. package/lib/cli.d.ts.map +1 -0
  12. package/lib/cli.js +464 -0
  13. package/lib/cli.js.map +1 -0
  14. package/lib/compiler.d.ts +86 -0
  15. package/lib/compiler.d.ts.map +1 -0
  16. package/lib/compiler.js +415 -0
  17. package/lib/compiler.js.map +1 -0
  18. package/lib/defaultConfiguration.d.ts +7 -0
  19. package/lib/defaultConfiguration.d.ts.map +1 -0
  20. package/lib/defaultConfiguration.js +79 -0
  21. package/lib/defaultConfiguration.js.map +1 -0
  22. package/lib/index.d.ts +4 -0
  23. package/lib/index.d.ts.map +1 -0
  24. package/lib/index.js +41 -0
  25. package/lib/index.js.map +1 -0
  26. package/lib/options.d.ts +66 -0
  27. package/lib/options.d.ts.map +1 -0
  28. package/lib/options.js +24 -0
  29. package/lib/options.js.map +1 -0
  30. package/package.json +59 -0
  31. package/src/cli.ts +607 -0
  32. package/src/compiler.ts +504 -0
  33. package/src/defaultConfiguration.ts +78 -0
  34. package/src/index.ts +25 -0
  35. package/src/options.ts +101 -0
  36. package/test/data/resource-collection.json +28 -0
  37. package/test/data/sample-resources.json +41 -0
  38. package/test/integration/cli-configuration.test.ts +419 -0
  39. package/test/integration/cli-context-filter-working.test.ts +341 -0
  40. package/test/integration/cli-integration.test.ts +533 -0
  41. package/test/unit/cli.test.ts +413 -0
  42. package/test/unit/compiler.test.ts +1084 -0
  43. package/tsconfig.json +8 -0
package/README.md ADDED
@@ -0,0 +1,197 @@
1
+ # @fgv/ts-res-cli
2
+
3
+ Command-line interface for compiling and managing ts-res resources with contextual filtering and optimization.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # From the monorepo root
9
+ rush install
10
+ rushx build --to @fgv/ts-res-cli
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Compile Resources
16
+
17
+ ```bash
18
+ ts-res-compile compile -i ./resources -o ./dist/resources.json
19
+ ```
20
+
21
+ ### Advanced Compilation
22
+
23
+ ```bash
24
+ # Compile with context filtering
25
+ ts-res-compile compile \
26
+ -i ./resources \
27
+ -o ./dist/resources.json \
28
+ --context '{"language": "en-US", "territory": "US"}' \
29
+ --format json
30
+ # Compile for production with TypeScript output
31
+ ts-res-compile compile \
32
+ -i ./resources \
33
+ -o ./dist/resources.ts \
34
+ --format ts \
35
+ --include-metadata
36
+ ```
37
+
38
+ ### Validate Resources
39
+
40
+ ```bash
41
+ # Validate resource files
42
+ ts-res-compile validate -i ./resources
43
+ ```
44
+
45
+ ### Get Resource Information
46
+
47
+ ```bash
48
+ # Get basic resource information
49
+ ts-res-compile info -i ./resources
50
+
51
+ # Get filtered information
52
+ ts-res-compile info \
53
+ -i ./resources \
54
+ --context '{"language": "en"}' \
55
+ ```
56
+
57
+ ## Commands
58
+
59
+ ### `compile`
60
+
61
+ Compiles resources from input to output format.
62
+
63
+ **Required Options:**
64
+ - `-i, --input <path>` - Input file or directory path
65
+ - `-o, --output <path>` - Output file path
66
+
67
+ **Optional Options:**
68
+ - `-c, --context <json>` - Context filter for resources (JSON string)
69
+ - `-f, --format <format>` - Output format (json, js, ts, binary) [default: json]
70
+ - `--debug` - Include debug information [default: false]
71
+ - `-v, --verbose` - Verbose output [default: false]
72
+ - `-q, --quiet` - Quiet output [default: false]
73
+ - `--validate` - Validate resources during compilation [default: true]
74
+ - `--include-metadata` - Include resource metadata in output [default: false]
75
+ - `--resource-types <types>` - Resource type filter (comma-separated)
76
+ - `--max-distance <number>` - Maximum distance for language matching
77
+
78
+ ### `validate`
79
+
80
+ Validates resources without compilation.
81
+
82
+ **Required Options:**
83
+ - `-i, --input <path>` - Input file or directory path
84
+
85
+ **Optional Options:**
86
+ - `-v, --verbose` - Verbose output [default: false]
87
+ - `-q, --quiet` - Quiet output [default: false]
88
+
89
+ ### `info`
90
+
91
+ Shows information about resources.
92
+
93
+ **Required Options:**
94
+ - `-i, --input <path>` - Input file or directory path
95
+
96
+ **Optional Options:**
97
+ - `-c, --context <json>` - Context filter for resources (JSON string)
98
+ - `--resource-types <types>` - Resource type filter (comma-separated)
99
+ - `--max-distance <number>` - Maximum distance for language matching
100
+
101
+ ## Input Formats
102
+
103
+ The CLI supports the following input formats:
104
+
105
+ ### Resource Candidate Array
106
+ ```json
107
+ [
108
+ {
109
+ "id": "welcome.message",
110
+ "json": { "text": "Welcome!" },
111
+ "conditions": { "language": "en" },
112
+ "resourceTypeName": "json"
113
+ }
114
+ ]
115
+ ```
116
+
117
+ ### Resource Collection
118
+ ```json
119
+ {
120
+ "resources": [
121
+ {
122
+ "id": "welcome.message",
123
+ "resourceTypeName": "json",
124
+ "candidates": [
125
+ {
126
+ "json": { "text": "Welcome!" },
127
+ "conditions": { "language": "en" }
128
+ }
129
+ ]
130
+ }
131
+ ]
132
+ }
133
+ ```
134
+
135
+ ## Output Formats
136
+
137
+ ### JSON (default)
138
+ ```json
139
+ {
140
+ "resources": {
141
+ "welcome.message": {
142
+ "default": { "text": "Welcome!" }
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ ### JavaScript
149
+ ```javascript
150
+ module.exports = {
151
+ "resources": {
152
+ "welcome.message": {
153
+ "default": { "text": "Welcome!" }
154
+ }
155
+ }
156
+ };
157
+ ```
158
+
159
+ ### TypeScript
160
+ ```typescript
161
+ export const resources = {
162
+ "resources": {
163
+ "welcome.message": {
164
+ "default": { "text": "Welcome!" }
165
+ }
166
+ }
167
+ } as const;
168
+ ```
169
+
170
+ ## Context Filtering
171
+
172
+ Context filtering allows you to compile only resources that match specific conditions:
173
+
174
+ ```bash
175
+ # Only resources for English language
176
+ ts-res-compile compile -i ./resources -o ./en.json \
177
+ --context '{"language": "en"}'
178
+
179
+ ## Examples
180
+
181
+ See the `examples/` directory for sample resource files and compilation scenarios.
182
+
183
+ ## Development
184
+
185
+ ```bash
186
+ # Build the CLI
187
+ rushx build
188
+
189
+ # Run tests
190
+ rushx test
191
+
192
+ # Run linting
193
+ rushx lint
194
+
195
+ # Generate documentation
196
+ rushx build-docs
197
+ ```
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+
3
+ /*
4
+ * Copyright (c) 2025 Erik Fortune
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const { TsResCliApp } = require('../lib/cli');
26
+
27
+ async function main() {
28
+ try {
29
+ const app = new TsResCliApp();
30
+ await app.run(process.argv);
31
+ } catch (error) {
32
+ console.error('Fatal error:', error.message);
33
+ process.exit(1);
34
+ }
35
+ }
36
+
37
+ main().catch((error) => {
38
+ console.error('Unhandled error:', error);
39
+ process.exit(1);
40
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "testMatch": ["<rootDir>/src/test/**/*.test.ts", "<rootDir>/test/**/*.test.ts"],
3
+ "preset": "ts-jest",
4
+ "testEnvironment": "node",
5
+ "extensionsToTreatAsEsm": [],
6
+ "transform": {
7
+ "^.+\\.ts$": "ts-jest"
8
+ }
9
+ }
@@ -0,0 +1,16 @@
1
+ // The "rig.json" file directs tools to look for their config files in an external package.
2
+ // Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
3
+ {
4
+ "$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
5
+ /**
6
+ * (Required) The name of the rig package to inherit from.
7
+ * It should be an NPM package name with the "-rig" suffix.
8
+ */
9
+ "rigPackageName": "@rushstack/heft-node-rig"
10
+ /**
11
+ * (Optional) Selects a config profile from the rig package. The name must consist of
12
+ * lowercase alphanumeric words separated by hyphens, for example "sample-profile".
13
+ * If omitted, then the "default" profile will be used."
14
+ */
15
+ // "rigProfile": "your-profile-name"
16
+ }
package/lib/cli.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Main CLI class for ts-res-compile
3
+ */
4
+ export declare class TsResCliApp {
5
+ private readonly _program;
6
+ constructor();
7
+ /**
8
+ * Runs the CLI with the provided arguments
9
+ */
10
+ run(argv: string[]): Promise<void>;
11
+ /**
12
+ * Sets up the CLI commands and options
13
+ */
14
+ private _setupCommands;
15
+ /**
16
+ * Handles the compile command
17
+ */
18
+ private _handleCompileCommand;
19
+ /**
20
+ * Handles the validate command
21
+ */
22
+ private _handleValidateCommand;
23
+ /**
24
+ * Handles the info command
25
+ */
26
+ private _handleInfoCommand;
27
+ /**
28
+ * Handles the config command
29
+ */
30
+ private _handleConfigCommand;
31
+ /**
32
+ * Parses and validates compile options
33
+ */
34
+ private _parseCompileOptions;
35
+ }
36
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AA0FA;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;;IAOnC;;OAEG;IACU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C;;OAEG;IACH,OAAO,CAAC,cAAc;IAkHtB;;OAEG;YACW,qBAAqB;IAoBnC;;OAEG;YACW,sBAAsB;IA6CpC;;OAEG;YACW,kBAAkB;IA6ChC;;OAEG;YACW,oBAAoB;IAoNlC;;OAEG;IACH,OAAO,CAAC,oBAAoB;CA4C7B"}