@uns-kit/core 2.0.16 → 2.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/dist/tools/file-utils.d.ts +3 -0
- package/dist/tools/file-utils.d.ts.map +1 -0
- package/dist/tools/file-utils.js +25 -0
- package/dist/tools/file-utils.js.map +1 -0
- package/dist/tools/generate-uns-dictionary.d.ts +15 -0
- package/dist/tools/generate-uns-dictionary.d.ts.map +1 -1
- package/dist/tools/generate-uns-dictionary.js +35 -17
- package/dist/tools/generate-uns-dictionary.js.map +1 -1
- package/dist/tools/generate-uns-measurements.d.ts +15 -0
- package/dist/tools/generate-uns-measurements.d.ts.map +1 -1
- package/dist/tools/generate-uns-measurements.js +28 -11
- package/dist/tools/generate-uns-measurements.js.map +1 -1
- package/dist/tools/generate-uns-reference.js +10 -4
- package/dist/tools/generate-uns-reference.js.map +1 -1
- package/dist/tools/sync-uns-schema.d.ts +3 -0
- package/dist/tools/sync-uns-schema.d.ts.map +1 -0
- package/dist/tools/sync-uns-schema.js +360 -0
- package/dist/tools/sync-uns-schema.js.map +1 -0
- package/dist/uns/uns-attributes.d.ts +2 -2
- package/dist/uns/uns-attributes.d.ts.map +1 -1
- package/dist/uns/uns-dictionary.generated.d.ts +636 -129
- package/dist/uns/uns-dictionary.generated.d.ts.map +1 -1
- package/dist/uns/uns-dictionary.generated.js +696 -183
- package/dist/uns/uns-dictionary.generated.js.map +1 -1
- package/dist/uns/uns-measurements.d.ts +65 -65
- package/dist/uns/uns-measurements.generated.d.ts +329 -65
- package/dist/uns/uns-measurements.generated.d.ts.map +1 -1
- package/dist/uns/uns-measurements.generated.js +330 -66
- package/dist/uns/uns-measurements.generated.js.map +1 -1
- package/dist/uns/uns-object.d.ts +5 -4
- package/dist/uns/uns-object.d.ts.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -79,6 +79,34 @@ pnpm tsx packages/uns-core/src/tools/generate-uns-reference.ts \
|
|
|
79
79
|
--lang sl
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
### Sync canonical UNS schema from the controller
|
|
83
|
+
|
|
84
|
+
Use `sync-uns-schema` when you need to refresh the repo-maintained schema files from
|
|
85
|
+
the controller’s REST export endpoints.
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pnpm run sync-uns-schema -- \
|
|
89
|
+
--controller-url http://localhost:3200 \
|
|
90
|
+
--token <bearer-token>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- Uses `GET /api/schema/export/uns-dictionary?status=...` and `GET /api/schema/export/uns-measurements`.
|
|
94
|
+
- Sends `Authorization: Bearer <token>`.
|
|
95
|
+
- Preserves the full exported JSON document when updating:
|
|
96
|
+
- `packages/uns-cli/templates/uns-dictionary/uns-dictionary.json`
|
|
97
|
+
- `packages/uns-cli/templates/uns-measurements/uns-measurements.json`
|
|
98
|
+
- Regenerates the local TS artifacts unless you pass `--skip-generate`.
|
|
99
|
+
- Defaults dictionary sync to `--status active`.
|
|
100
|
+
- Supports environment fallbacks: `UNS_CONTROLLER_URL`, `UNS_CONTROLLER_TOKEN`, `UNS_SCHEMA_STATUS`.
|
|
101
|
+
|
|
102
|
+
Useful variants:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pnpm run sync-uns-schema -- --dry-run
|
|
106
|
+
pnpm run sync-uns-schema -- --dictionary-only
|
|
107
|
+
pnpm run sync-uns-schema -- --measurements-only --skip-generate
|
|
108
|
+
```
|
|
109
|
+
|
|
82
110
|
### Infisical secret resolution in development
|
|
83
111
|
|
|
84
112
|
- The resolver looks for `SecretResolverOptions.infisical.fetchSecret`, then `INFISICAL_TOKEN`/`INFISICAL_PERSONAL_TOKEN`, then `/run/secrets/infisical_token` (or `/var/lib/uns/secrets/infisical_token`).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-utils.d.ts","sourceRoot":"","sources":["../../src/tools/file-utils.ts"],"names":[],"mappings":"AAGA,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAWxF;AAED,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAWhG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export async function readTextFileIfExists(filePath) {
|
|
4
|
+
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
5
|
+
try {
|
|
6
|
+
return await readFile(absolutePath, "utf8");
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (error.code === "ENOENT") {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export async function writeTextFileIfChanged(filePath, content) {
|
|
16
|
+
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
17
|
+
const current = await readTextFileIfExists(absolutePath);
|
|
18
|
+
if (current === content) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
await mkdir(path.dirname(absolutePath), { recursive: true });
|
|
22
|
+
await writeFile(absolutePath, content, "utf8");
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=file-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-utils.js","sourceRoot":"","sources":["../../src/tools/file-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,QAAgB;IACzD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAE3D,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,QAAgB,EAAE,OAAe;IAC5E,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAEzD,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,MAAM,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/C,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nexport async function readTextFileIfExists(filePath: string): Promise<string | undefined> {\n const absolutePath = path.resolve(process.cwd(), filePath);\n\n try {\n return await readFile(absolutePath, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n return undefined;\n }\n throw error;\n }\n}\n\nexport async function writeTextFileIfChanged(filePath: string, content: string): Promise<boolean> {\n const absolutePath = path.resolve(process.cwd(), filePath);\n const current = await readTextFileIfExists(absolutePath);\n\n if (current === content) {\n return false;\n }\n\n await mkdir(path.dirname(absolutePath), { recursive: true });\n await writeFile(absolutePath, content, \"utf8\");\n return true;\n}\n"]}
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
type DictionaryEntry = {
|
|
3
|
+
description?: string | null;
|
|
4
|
+
descriptions?: Record<string, string | null | undefined>;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
type ObjectTypeEntry = DictionaryEntry & {
|
|
8
|
+
attributes?: string[] | null;
|
|
9
|
+
};
|
|
10
|
+
type UnsDictionary = {
|
|
11
|
+
schemaVersion?: unknown;
|
|
12
|
+
objectTypes?: Record<string, ObjectTypeEntry>;
|
|
13
|
+
attributes?: Record<string, DictionaryEntry>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
2
16
|
type CliArgs = {
|
|
3
17
|
input: string;
|
|
4
18
|
output: string;
|
|
5
19
|
lang: string;
|
|
6
20
|
};
|
|
7
21
|
export declare function generateUnsDictionary(args: Partial<CliArgs>): Promise<void>;
|
|
22
|
+
export declare function renderDictionaryTs(dictionary: UnsDictionary, lang: string): string;
|
|
8
23
|
export {};
|
|
9
24
|
//# sourceMappingURL=generate-uns-dictionary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-uns-dictionary.d.ts","sourceRoot":"","sources":["../../src/tools/generate-uns-dictionary.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"generate-uns-dictionary.d.ts","sourceRoot":"","sources":["../../src/tools/generate-uns-dictionary.ts"],"names":[],"mappings":";AAuBA,KAAK,eAAe,GAAG;IACrB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACzD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AACF,KAAK,eAAe,GAAG,eAAe,GAAG;IACvC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CAC9B,CAAC;AACF,KAAK,aAAa,GAAG;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC7C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAwDF,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAUjF;AAoBD,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAmDlF"}
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
* }
|
|
17
17
|
* }
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
19
|
+
import { readFile } from "node:fs/promises";
|
|
20
20
|
import path from "node:path";
|
|
21
|
+
import { pathToFileURL } from "node:url";
|
|
22
|
+
import { writeTextFileIfChanged } from "./file-utils.js";
|
|
21
23
|
const DEFAULT_INPUT = "uns-dictionary.json";
|
|
22
24
|
const DEFAULT_OUTPUT = path.resolve(process.cwd(), "src/uns/uns-dictionary.generated.ts");
|
|
23
25
|
async function main() {
|
|
@@ -72,8 +74,8 @@ export async function generateUnsDictionary(args) {
|
|
|
72
74
|
lang: args.lang ?? "sl",
|
|
73
75
|
};
|
|
74
76
|
const dictionary = await readDictionaryFromJson(effective.input);
|
|
75
|
-
await writeDictionaryTs(dictionary, effective.output, effective.lang);
|
|
76
|
-
console.log(`Generated dictionary -> ${effective.output}`);
|
|
77
|
+
const changed = await writeDictionaryTs(dictionary, effective.output, effective.lang);
|
|
78
|
+
console.log(`Generated dictionary -> ${effective.output}${changed ? "" : " (unchanged)"}`);
|
|
77
79
|
}
|
|
78
80
|
const resolveDescription = (entry, lang) => {
|
|
79
81
|
if (!entry)
|
|
@@ -85,19 +87,29 @@ const resolveDescription = (entry, lang) => {
|
|
|
85
87
|
return entry.description;
|
|
86
88
|
return undefined;
|
|
87
89
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
function renderDoc(description, indent) {
|
|
91
|
+
if (!description)
|
|
92
|
+
return "";
|
|
93
|
+
const normalized = description
|
|
94
|
+
.replaceAll("*/", "*\\/")
|
|
95
|
+
.split(/\r?\n/)
|
|
96
|
+
.map((line) => `${indent} * ${line}`)
|
|
97
|
+
.join("\n");
|
|
98
|
+
return `${indent}/**\n${normalized}\n${indent} */\n`;
|
|
99
|
+
}
|
|
100
|
+
export function renderDictionaryTs(dictionary, lang) {
|
|
101
|
+
const objectTypeEntries = Object.entries(dictionary.objectTypes ?? {}).sort(([left], [right]) => left.localeCompare(right));
|
|
102
|
+
const attributeEntries = Object.entries(dictionary.attributes ?? {}).sort(([left], [right]) => left.localeCompare(right));
|
|
91
103
|
const attributesByType = {};
|
|
92
104
|
for (const [name, entry] of objectTypeEntries) {
|
|
93
105
|
if (Array.isArray(entry.attributes) && entry.attributes.length > 0) {
|
|
94
|
-
attributesByType[name] = entry.attributes.filter(
|
|
106
|
+
attributesByType[name] = entry.attributes.filter((attribute) => typeof attribute === "string" && attribute.length > 0);
|
|
95
107
|
}
|
|
96
108
|
}
|
|
97
109
|
const renderRecord = (entries) => entries
|
|
98
110
|
.map(([name, entry]) => {
|
|
99
111
|
const desc = resolveDescription(entry, lang);
|
|
100
|
-
const doc = desc
|
|
112
|
+
const doc = renderDoc(desc, " ");
|
|
101
113
|
return `${doc} "${name}": "${name}",`;
|
|
102
114
|
})
|
|
103
115
|
.join("\n");
|
|
@@ -116,7 +128,7 @@ async function writeDictionaryTs(dictionary, filePath, lang) {
|
|
|
116
128
|
const lines = attrs
|
|
117
129
|
.map((attr) => {
|
|
118
130
|
const desc = resolveDescription(dictionary.attributes?.[attr], lang);
|
|
119
|
-
const doc = desc
|
|
131
|
+
const doc = renderDoc(desc, " ");
|
|
120
132
|
return `${doc} "${attr}": "${attr}",`;
|
|
121
133
|
})
|
|
122
134
|
.join("\n");
|
|
@@ -125,13 +137,19 @@ async function writeDictionaryTs(dictionary, filePath, lang) {
|
|
|
125
137
|
return blocks.join("\n");
|
|
126
138
|
};
|
|
127
139
|
const attributesByTypeConst = `const GeneratedAttributesByTypeBase = {\n${renderAttributesByType()}\n} as const;\n\nexport const GeneratedAttributesByType = GeneratedAttributesByTypeBase;`;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
return `/* Auto-generated by generate-uns-dictionary.ts. Do not edit by hand. */\n${objectTypeConst}\n\n${objectTypeDescConst}\n\nexport type GeneratedObjectTypeName = keyof typeof GeneratedObjectTypes;\n\nexport function getGeneratedObjectTypeDescription(name: string): string | undefined {\n return (GeneratedObjectTypeDescriptions as Record<string, string | undefined>)[name];\n}\n\n${attributeConst}\n\n${attributeDescConst}\n\n${attributesByTypeConst}\n\nexport type GeneratedAttributeName = keyof typeof GeneratedAttributes;\n\nexport type GeneratedAttributesFor<T extends keyof typeof GeneratedAttributesByType> = keyof typeof GeneratedAttributesByType[T];\n\nexport function getGeneratedAttributeDescription(name: string): string | undefined {\n return (GeneratedAttributeDescriptions as Record<string, string | undefined>)[name];\n}\n`;
|
|
141
|
+
}
|
|
142
|
+
async function writeDictionaryTs(dictionary, filePath, lang) {
|
|
143
|
+
const content = renderDictionaryTs(dictionary, lang);
|
|
144
|
+
return writeTextFileIfChanged(filePath, content);
|
|
145
|
+
}
|
|
146
|
+
const isDirectExecution = process.argv[1]
|
|
147
|
+
? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
|
|
148
|
+
: false;
|
|
149
|
+
if (isDirectExecution) {
|
|
150
|
+
main().catch((error) => {
|
|
151
|
+
console.error("Failed to generate UNS dictionary:", error);
|
|
152
|
+
process.exitCode = 1;
|
|
153
|
+
});
|
|
132
154
|
}
|
|
133
|
-
main().catch((error) => {
|
|
134
|
-
console.error("Failed to generate UNS dictionary:", error);
|
|
135
|
-
process.exitCode = 1;
|
|
136
|
-
});
|
|
137
155
|
//# sourceMappingURL=generate-uns-dictionary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-uns-dictionary.js","sourceRoot":"","sources":["../../src/tools/generate-uns-dictionary.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAoB7B,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAC5C,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,qCAAqC,CAAC,CAAC;AAE1F,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM,qBAAqB,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,SAAS,CAAC,IAAc;IAC/B,IAAI,KAAK,GAAG,aAAa,CAAC;IAC1B,IAAI,MAAM,GAAG,cAAc,CAAC;IAC5B,IAAI,IAAI,GAAG,IAAI,CAAC;IAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACrC,KAAK,GAAG,IAAI,CAAC,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,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * Generate a TypeScript dictionary of object types and attributes (with descriptions)\n * from a JSON file. The output is meant for IntelliSense and metadata enrichment\n * (e.g., emitting descriptions alongside topics). No GraphQL calls are performed.\n *\n * JSON shape (example):\n * {\n * \"objectTypes\": {\n * \"energy-resource\": { \"description\": \"Energy carriers (electricity/steam/gas)\" },\n * \"custom-type\": { \"description\": \"Tenant-specific thing\" }\n * },\n * \"attributes\": {\n * \"cumulative-active-energy-delivered\": { \"description\": \"kWh total\" },\n * \"status\": { \"description\": \"Generic status\" }\n * }\n * }\n */\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\ntype DictionaryEntry = {\n description?: string | null;\n descriptions?: Record<string, string | null | undefined>;\n};\ntype ObjectTypeEntry = DictionaryEntry & {\n attributes?: string[] | null;\n};\ntype UnsDictionary = {\n objectTypes?: Record<string, ObjectTypeEntry>;\n attributes?: Record<string, DictionaryEntry>;\n};\n\ntype CliArgs = {\n input: string;\n output: string;\n lang: string;\n};\n\nconst DEFAULT_INPUT = \"uns-dictionary.json\";\nconst DEFAULT_OUTPUT = path.resolve(process.cwd(), \"src/uns/uns-dictionary.generated.ts\");\n\nasync function main(): Promise<void> {\n const args = parseArgs(process.argv.slice(2));\n await generateUnsDictionary(args);\n}\n\nfunction parseArgs(argv: string[]): CliArgs {\n let input = DEFAULT_INPUT;\n let output = DEFAULT_OUTPUT;\n let lang = \"sl\";\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--input\" && argv[i + 1]) {\n input = argv[++i];\n continue;\n }\n if (arg === \"--output\" && argv[i + 1]) {\n output = argv[++i];\n continue;\n }\n if (arg === \"--lang\" && argv[i + 1]) {\n lang = argv[++i];\n continue;\n }\n if (arg === \"--help\" || arg === \"-h\") {\n printHelp();\n process.exit(0);\n }\n throw new Error(`Unknown argument: ${arg}`);\n }\n\n return { input, output, lang };\n}\n\nfunction printHelp(): void {\n console.log(`Usage: tsx packages/uns-core/src/tools/generate-uns-dictionary.ts [options]\n\nOptions:\n --input <file> Path to uns-dictionary.json (default: ${DEFAULT_INPUT})\n --output <file> Path to generated TS file (default: src/uns/uns-dictionary.generated.ts)\n --lang <code> Preferred description language code (default: \"sl\")\n --help, -h Show this help\n`);\n}\n\nasync function readDictionaryFromJson(filePath: string): Promise<UnsDictionary> {\n const absolute = path.resolve(process.cwd(), filePath);\n const raw = await readFile(absolute, \"utf8\");\n return JSON.parse(raw) as UnsDictionary;\n}\n\nexport async function generateUnsDictionary(args: Partial<CliArgs>): Promise<void> {\n const effective: CliArgs = {\n input: args.input ?? DEFAULT_INPUT,\n output: args.output ?? DEFAULT_OUTPUT,\n lang: args.lang ?? \"sl\",\n };\n\n const dictionary = await readDictionaryFromJson(effective.input);\n await writeDictionaryTs(dictionary, effective.output, effective.lang);\n console.log(`Generated dictionary -> ${effective.output}`);\n}\n\nconst resolveDescription = (entry: DictionaryEntry | undefined, lang: string): string | undefined => {\n if (!entry) return undefined;\n const byLang = entry.descriptions?.[lang];\n if (byLang && byLang.length > 0) return byLang;\n if (entry.description && entry.description.length > 0) return entry.description;\n return undefined;\n};\n\nasync function writeDictionaryTs(dictionary: UnsDictionary, filePath: string, lang: string): Promise<void> {\n const objectTypeEntries = Object.entries(dictionary.objectTypes ?? {});\n const attributeEntries = Object.entries(dictionary.attributes ?? {});\n const attributesByType: Record<string, string[]> = {};\n for (const [name, entry] of objectTypeEntries) {\n if (Array.isArray(entry.attributes) && entry.attributes.length > 0) {\n attributesByType[name] = entry.attributes.filter(Boolean) as string[];\n }\n }\n\n const renderRecord = (entries: [string, DictionaryEntry][]) =>\n entries\n .map(([name, entry]) => {\n const desc = resolveDescription(entry, lang);\n const doc = desc ? ` /** ${desc} */\\n` : \"\";\n return `${doc} \"${name}\": \"${name}\",`;\n })\n .join(\"\\n\");\n\n const renderDescriptions = (entries: [string, DictionaryEntry][]) =>\n entries\n .map(([name, value]) => ` \"${name}\": ${JSON.stringify(resolveDescription(value, lang) ?? \"\")},`)\n .join(\"\\n\");\n\n const objectTypeConst = `export const GeneratedObjectTypes = {\\n${renderRecord(objectTypeEntries)}\\n} as const;`;\n const objectTypeDescConst = `export const GeneratedObjectTypeDescriptions: Record<keyof typeof GeneratedObjectTypes, string> = {\\n${renderDescriptions(objectTypeEntries)}\\n};`;\n\n const attributeConst = `export const GeneratedAttributes = {\\n${renderRecord(attributeEntries)}\\n} as const;`;\n const attributeDescConst = `export const GeneratedAttributeDescriptions: Record<keyof typeof GeneratedAttributes, string> = {\\n${renderDescriptions(attributeEntries)}\\n};`;\n\n const renderAttributesByType = () => {\n const blocks: string[] = [];\n for (const [objectType, attrs] of Object.entries(attributesByType)) {\n if (!attrs.length) continue;\n const lines = attrs\n .map((attr) => {\n const desc = resolveDescription(dictionary.attributes?.[attr], lang);\n const doc = desc ? ` /** ${desc} */\\n` : \"\";\n return `${doc} \"${attr}\": \"${attr}\",`;\n })\n .join(\"\\n\");\n blocks.push(` \"${objectType}\": {\\n${lines}\\n },`);\n }\n return blocks.join(\"\\n\");\n };\n\n const attributesByTypeConst = `const GeneratedAttributesByTypeBase = {\\n${renderAttributesByType()}\\n} as const;\\n\\nexport const GeneratedAttributesByType = GeneratedAttributesByTypeBase;`;\n\n const content = `/* Auto-generated by generate-uns-dictionary.ts. Do not edit by hand. */\\n${objectTypeConst}\\n\\n${objectTypeDescConst}\\n\\nexport type GeneratedObjectTypeName = keyof typeof GeneratedObjectTypes;\\n\\nexport function getGeneratedObjectTypeDescription(name: string): string | undefined {\\n return (GeneratedObjectTypeDescriptions as Record<string, string | undefined>)[name];\\n}\\n\\n${attributeConst}\\n\\n${attributeDescConst}\\n\\n${attributesByTypeConst}\\n\\nexport type GeneratedAttributeName = keyof typeof GeneratedAttributes;\\n\\nexport type GeneratedAttributesFor<T extends keyof typeof GeneratedAttributesByType> = keyof typeof GeneratedAttributesByType[T];\\n\\nexport function getGeneratedAttributeDescription(name: string): string | undefined {\\n return (GeneratedAttributeDescriptions as Record<string, string | undefined>)[name];\\n}\\n`;\n\n const absolute = path.resolve(process.cwd(), filePath);\n await mkdir(path.dirname(absolute), { recursive: true });\n await writeFile(absolute, content, \"utf8\");\n}\n\nmain().catch((error) => {\n console.error(\"Failed to generate UNS dictionary:\", error);\n process.exitCode = 1;\n});\n"]}
|
|
1
|
+
{"version":3,"file":"generate-uns-dictionary.js","sourceRoot":"","sources":["../../src/tools/generate-uns-dictionary.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAuBzD,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAC5C,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,qCAAqC,CAAC,CAAC;AAE1F,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM,qBAAqB,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,SAAS,CAAC,IAAc;IAC/B,IAAI,KAAK,GAAG,aAAa,CAAC;IAC1B,IAAI,MAAM,GAAG,cAAc,CAAC;IAC5B,IAAI,IAAI,GAAG,IAAI,CAAC;IAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,CA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C,CAAC;iBACD,IAAI,CAAC,IAAI,CAAC,CAAC;YACd,MAAM,CAAC,IAAI,CAAC,MAAM,UAAU,SAAS,KAAK,QAAQ,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC;IAEF,MAAM,qBAAqB,GAAG,4CAA4C,sBAAsB,EAAE,0FAA0F,CAAC;IAE7L,OAAO,6EAA6E,eAAe,OAAO,mBAAmB,wQAAwQ,cAAc,OAAO,kBAAkB,OAAO,qBAAqB,sYAAsY,CAAC;AACj1B,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,UAAyB,EAAE,QAAgB,EAAE,IAAY;IACxF,MAAM,OAAO,GAAG,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACrD,OAAO,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;IACvE,CAAC,CAAC,KAAK,CAAC;AAEV,IAAI,iBAAiB,EAAE,CAAC;IACtB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * Generate a TypeScript dictionary of object types and attributes (with descriptions)\n * from a JSON file. The output is meant for IntelliSense and metadata enrichment\n * (e.g., emitting descriptions alongside topics). No GraphQL calls are performed.\n *\n * JSON shape (example):\n * {\n * \"objectTypes\": {\n * \"energy-resource\": { \"description\": \"Energy carriers (electricity/steam/gas)\" },\n * \"custom-type\": { \"description\": \"Tenant-specific thing\" }\n * },\n * \"attributes\": {\n * \"cumulative-active-energy-delivered\": { \"description\": \"kWh total\" },\n * \"status\": { \"description\": \"Generic status\" }\n * }\n * }\n */\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { writeTextFileIfChanged } from \"./file-utils.js\";\n\ntype DictionaryEntry = {\n description?: string | null;\n descriptions?: Record<string, string | null | undefined>;\n [key: string]: unknown;\n};\ntype ObjectTypeEntry = DictionaryEntry & {\n attributes?: string[] | null;\n};\ntype UnsDictionary = {\n schemaVersion?: unknown;\n objectTypes?: Record<string, ObjectTypeEntry>;\n attributes?: Record<string, DictionaryEntry>;\n [key: string]: unknown;\n};\n\ntype CliArgs = {\n input: string;\n output: string;\n lang: string;\n};\n\nconst DEFAULT_INPUT = \"uns-dictionary.json\";\nconst DEFAULT_OUTPUT = path.resolve(process.cwd(), \"src/uns/uns-dictionary.generated.ts\");\n\nasync function main(): Promise<void> {\n const args = parseArgs(process.argv.slice(2));\n await generateUnsDictionary(args);\n}\n\nfunction parseArgs(argv: string[]): CliArgs {\n let input = DEFAULT_INPUT;\n let output = DEFAULT_OUTPUT;\n let lang = \"sl\";\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--input\" && argv[i + 1]) {\n input = argv[++i];\n continue;\n }\n if (arg === \"--output\" && argv[i + 1]) {\n output = argv[++i];\n continue;\n }\n if (arg === \"--lang\" && argv[i + 1]) {\n lang = argv[++i];\n continue;\n }\n if (arg === \"--help\" || arg === \"-h\") {\n printHelp();\n process.exit(0);\n }\n throw new Error(`Unknown argument: ${arg}`);\n }\n\n return { input, output, lang };\n}\n\nfunction printHelp(): void {\n console.log(`Usage: tsx packages/uns-core/src/tools/generate-uns-dictionary.ts [options]\n\nOptions:\n --input <file> Path to uns-dictionary.json (default: ${DEFAULT_INPUT})\n --output <file> Path to generated TS file (default: src/uns/uns-dictionary.generated.ts)\n --lang <code> Preferred description language code (default: \"sl\")\n --help, -h Show this help\n`);\n}\n\nasync function readDictionaryFromJson(filePath: string): Promise<UnsDictionary> {\n const absolute = path.resolve(process.cwd(), filePath);\n const raw = await readFile(absolute, \"utf8\");\n return JSON.parse(raw) as UnsDictionary;\n}\n\nexport async function generateUnsDictionary(args: Partial<CliArgs>): Promise<void> {\n const effective: CliArgs = {\n input: args.input ?? DEFAULT_INPUT,\n output: args.output ?? DEFAULT_OUTPUT,\n lang: args.lang ?? \"sl\",\n };\n\n const dictionary = await readDictionaryFromJson(effective.input);\n const changed = await writeDictionaryTs(dictionary, effective.output, effective.lang);\n console.log(`Generated dictionary -> ${effective.output}${changed ? \"\" : \" (unchanged)\"}`);\n}\n\nconst resolveDescription = (entry: DictionaryEntry | undefined, lang: string): string | undefined => {\n if (!entry) return undefined;\n const byLang = entry.descriptions?.[lang];\n if (byLang && byLang.length > 0) return byLang;\n if (entry.description && entry.description.length > 0) return entry.description;\n return undefined;\n};\n\nfunction renderDoc(description: string | undefined, indent: string): string {\n if (!description) return \"\";\n const normalized = description\n .replaceAll(\"*/\", \"*\\\\/\")\n .split(/\\r?\\n/)\n .map((line) => `${indent} * ${line}`)\n .join(\"\\n\");\n return `${indent}/**\\n${normalized}\\n${indent} */\\n`;\n}\n\nexport function renderDictionaryTs(dictionary: UnsDictionary, lang: string): string {\n const objectTypeEntries = Object.entries(dictionary.objectTypes ?? {}).sort(([left], [right]) => left.localeCompare(right));\n const attributeEntries = Object.entries(dictionary.attributes ?? {}).sort(([left], [right]) => left.localeCompare(right));\n const attributesByType: Record<string, string[]> = {};\n for (const [name, entry] of objectTypeEntries) {\n if (Array.isArray(entry.attributes) && entry.attributes.length > 0) {\n attributesByType[name] = entry.attributes.filter(\n (attribute): attribute is string => typeof attribute === \"string\" && attribute.length > 0,\n );\n }\n }\n\n const renderRecord = (entries: [string, DictionaryEntry][]) =>\n entries\n .map(([name, entry]) => {\n const desc = resolveDescription(entry, lang);\n const doc = renderDoc(desc, \" \");\n return `${doc} \"${name}\": \"${name}\",`;\n })\n .join(\"\\n\");\n\n const renderDescriptions = (entries: [string, DictionaryEntry][]) =>\n entries\n .map(([name, value]) => ` \"${name}\": ${JSON.stringify(resolveDescription(value, lang) ?? \"\")},`)\n .join(\"\\n\");\n\n const objectTypeConst = `export const GeneratedObjectTypes = {\\n${renderRecord(objectTypeEntries)}\\n} as const;`;\n const objectTypeDescConst = `export const GeneratedObjectTypeDescriptions: Record<keyof typeof GeneratedObjectTypes, string> = {\\n${renderDescriptions(objectTypeEntries)}\\n};`;\n\n const attributeConst = `export const GeneratedAttributes = {\\n${renderRecord(attributeEntries)}\\n} as const;`;\n const attributeDescConst = `export const GeneratedAttributeDescriptions: Record<keyof typeof GeneratedAttributes, string> = {\\n${renderDescriptions(attributeEntries)}\\n};`;\n\n const renderAttributesByType = () => {\n const blocks: string[] = [];\n for (const [objectType, attrs] of Object.entries(attributesByType)) {\n if (!attrs.length) continue;\n const lines = attrs\n .map((attr) => {\n const desc = resolveDescription(dictionary.attributes?.[attr], lang);\n const doc = renderDoc(desc, \" \");\n return `${doc} \"${attr}\": \"${attr}\",`;\n })\n .join(\"\\n\");\n blocks.push(` \"${objectType}\": {\\n${lines}\\n },`);\n }\n return blocks.join(\"\\n\");\n };\n\n const attributesByTypeConst = `const GeneratedAttributesByTypeBase = {\\n${renderAttributesByType()}\\n} as const;\\n\\nexport const GeneratedAttributesByType = GeneratedAttributesByTypeBase;`;\n\n return `/* Auto-generated by generate-uns-dictionary.ts. Do not edit by hand. */\\n${objectTypeConst}\\n\\n${objectTypeDescConst}\\n\\nexport type GeneratedObjectTypeName = keyof typeof GeneratedObjectTypes;\\n\\nexport function getGeneratedObjectTypeDescription(name: string): string | undefined {\\n return (GeneratedObjectTypeDescriptions as Record<string, string | undefined>)[name];\\n}\\n\\n${attributeConst}\\n\\n${attributeDescConst}\\n\\n${attributesByTypeConst}\\n\\nexport type GeneratedAttributeName = keyof typeof GeneratedAttributes;\\n\\nexport type GeneratedAttributesFor<T extends keyof typeof GeneratedAttributesByType> = keyof typeof GeneratedAttributesByType[T];\\n\\nexport function getGeneratedAttributeDescription(name: string): string | undefined {\\n return (GeneratedAttributeDescriptions as Record<string, string | undefined>)[name];\\n}\\n`;\n}\n\nasync function writeDictionaryTs(dictionary: UnsDictionary, filePath: string, lang: string): Promise<boolean> {\n const content = renderDictionaryTs(dictionary, lang);\n return writeTextFileIfChanged(filePath, content);\n}\n\nconst isDirectExecution = process.argv[1]\n ? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href\n : false;\n\nif (isDirectExecution) {\n main().catch((error) => {\n console.error(\"Failed to generate UNS dictionary:\", error);\n process.exitCode = 1;\n });\n}\n"]}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
type Entry = {
|
|
3
|
+
value: string;
|
|
4
|
+
description?: string | null;
|
|
5
|
+
descriptions?: Record<string, string | null | undefined>;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
type MeasurementsJson = {
|
|
9
|
+
schemaVersion?: unknown;
|
|
10
|
+
physical?: Record<string, Entry>;
|
|
11
|
+
dataSize?: Record<string, Entry>;
|
|
12
|
+
counter?: Record<string, Entry>;
|
|
13
|
+
[category: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
export declare function renderMeasurementsTs(json: MeasurementsJson, lang: string): string;
|
|
2
16
|
export declare function generateUnsMeasurements(args: Partial<{
|
|
3
17
|
input: string;
|
|
4
18
|
output: string;
|
|
5
19
|
lang: string;
|
|
6
20
|
}>): Promise<void>;
|
|
21
|
+
export {};
|
|
7
22
|
//# sourceMappingURL=generate-uns-measurements.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-uns-measurements.d.ts","sourceRoot":"","sources":["../../src/tools/generate-uns-measurements.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"generate-uns-measurements.d.ts","sourceRoot":"","sources":["../../src/tools/generate-uns-measurements.ts"],"names":[],"mappings":";AAuBA,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACzD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AACF,KAAK,gBAAgB,GAAG;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B,CAAC;AAuFF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAMjF;AAED,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAC7D,OAAO,CAAC,IAAI,CAAC,CASf"}
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
* }
|
|
17
17
|
* }
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
19
|
+
import { readFile } from "node:fs/promises";
|
|
20
20
|
import path from "node:path";
|
|
21
|
+
import { pathToFileURL } from "node:url";
|
|
22
|
+
import { writeTextFileIfChanged } from "./file-utils.js";
|
|
21
23
|
const DEFAULT_INPUT = "uns-measurements.json";
|
|
22
24
|
const DEFAULT_OUTPUT = path.resolve(process.cwd(), "src/uns/uns-measurements.generated.ts");
|
|
23
25
|
async function main() {
|
|
@@ -79,15 +81,26 @@ function renderSection(name, entries, lang) {
|
|
|
79
81
|
if (!entries)
|
|
80
82
|
return `export const ${name} = {} as const;`;
|
|
81
83
|
const lines = Object.entries(entries)
|
|
84
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
82
85
|
.map(([key, entry]) => {
|
|
83
86
|
const desc = resolveDesc(entry, lang);
|
|
84
|
-
const doc = desc
|
|
87
|
+
const doc = renderDoc(desc, " ");
|
|
85
88
|
return `${doc} "${key}": "${entry.value}",`;
|
|
86
89
|
})
|
|
87
90
|
.join("\n");
|
|
88
91
|
return `export const ${name} = {\n${lines}\n} as const;`;
|
|
89
92
|
}
|
|
90
|
-
function
|
|
93
|
+
function renderDoc(description, indent) {
|
|
94
|
+
if (!description)
|
|
95
|
+
return "";
|
|
96
|
+
const normalized = description
|
|
97
|
+
.replaceAll("*/", "*\\/")
|
|
98
|
+
.split(/\r?\n/)
|
|
99
|
+
.map((line) => `${indent} * ${line}`)
|
|
100
|
+
.join("\n");
|
|
101
|
+
return `${indent}/**\n${normalized}\n${indent} */\n`;
|
|
102
|
+
}
|
|
103
|
+
export function renderMeasurementsTs(json, lang) {
|
|
91
104
|
const physical = renderSection("GeneratedPhysicalMeasurements", json.physical, lang);
|
|
92
105
|
const dataSize = renderSection("GeneratedDataSizeMeasurements", json.dataSize, lang);
|
|
93
106
|
const counter = renderSection("GeneratedCounterMeasurements", json.counter, lang);
|
|
@@ -98,13 +111,17 @@ export async function generateUnsMeasurements(args) {
|
|
|
98
111
|
const output = args.output ?? DEFAULT_OUTPUT;
|
|
99
112
|
const lang = args.lang ?? "sl";
|
|
100
113
|
const json = await loadJson(input);
|
|
101
|
-
const content =
|
|
102
|
-
await
|
|
103
|
-
|
|
104
|
-
|
|
114
|
+
const content = renderMeasurementsTs(json, lang);
|
|
115
|
+
const changed = await writeTextFileIfChanged(output, content);
|
|
116
|
+
console.log(`Generated measurements -> ${output}${changed ? "" : " (unchanged)"}`);
|
|
117
|
+
}
|
|
118
|
+
const isDirectExecution = process.argv[1]
|
|
119
|
+
? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
|
|
120
|
+
: false;
|
|
121
|
+
if (isDirectExecution) {
|
|
122
|
+
main().catch((err) => {
|
|
123
|
+
console.error("Failed to generate measurements:", err);
|
|
124
|
+
process.exitCode = 1;
|
|
125
|
+
});
|
|
105
126
|
}
|
|
106
|
-
main().catch((err) => {
|
|
107
|
-
console.error("Failed to generate measurements:", err);
|
|
108
|
-
process.exitCode = 1;
|
|
109
|
-
});
|
|
110
127
|
//# sourceMappingURL=generate-uns-measurements.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-uns-measurements.js","sourceRoot":"","sources":["../../src/tools/generate-uns-measurements.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAS7B,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,uCAAuC,CAAC,CAAC;AAE5F,KAAK,UAAU,IAAI;IACjB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,MAAM,uBAAuB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,SAAS,CAAC,IAAc;IAC/B,IAAI,KAAK,GAAG,aAAa,CAAC;IAC1B,IAAI,MAAM,GAAG,cAAc,CAAC;IAC5B,IAAI,IAAI,GAAG,IAA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I,CAAC,CAAC;IACrF,MAAM,QAAQ,GAAG,aAAa,CAAC,+BAA+B,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACrF,MAAM,OAAO,GAAG,aAAa,CAAC,8BAA8B,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAElF,OAAO,+EAA+E,QAAQ,OAAO,QAAQ,OAAO,OAAO,ghBAAghB,CAAC;AAC9oB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,IAA8D;IAC1G,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,aAAa,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,cAAc,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;IAE/B,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACrC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,MAAM,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,6BAA6B,MAAM,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAC;IACvD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * Generate a TypeScript helper for measurements from a JSON file.\n *\n * JSON shape (example):\n * {\n * \"physical\": {\n * \"None\": { \"value\": \"\", \"description\": \"Brez enote\" },\n * \"Celsius\": { \"value\": \"°C\", \"description\": \"Stopinje Celzija\" }\n * },\n * \"dataSize\": {\n * \"Bit\": { \"value\": \"bit\", \"description\": \"Bit\" }\n * },\n * \"counter\": {\n * \"Kilo\": { \"value\": \"k\", \"description\": \"Kilo\" }\n * }\n * }\n */\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\ntype Entry = { value: string; description?: string | null; descriptions?: Record<string, string | null | undefined> };\ntype MeasurementsJson = {\n physical?: Record<string, Entry>;\n dataSize?: Record<string, Entry>;\n counter?: Record<string, Entry>;\n};\n\nconst DEFAULT_INPUT = \"uns-measurements.json\";\nconst DEFAULT_OUTPUT = path.resolve(process.cwd(), \"src/uns/uns-measurements.generated.ts\");\n\nasync function main() {\n const { input, output, lang } = parseArgs(process.argv.slice(2));\n await generateUnsMeasurements({ input, output, lang });\n}\n\nfunction parseArgs(argv: string[]) {\n let input = DEFAULT_INPUT;\n let output = DEFAULT_OUTPUT;\n let lang = \"sl\";\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--input\" && argv[i + 1]) {\n input = argv[++i];\n continue;\n }\n if (arg === \"--output\" && argv[i + 1]) {\n output = argv[++i];\n continue;\n }\n if (arg === \"--lang\" && argv[i + 1]) {\n lang = argv[++i];\n continue;\n }\n if (arg === \"--help\" || arg === \"-h\") {\n printHelp();\n process.exit(0);\n }\n throw new Error(`Unknown argument: ${arg}`);\n }\n\n return { input, output, lang };\n}\n\nfunction printHelp(): void {\n console.log(`Usage: tsx packages/uns-core/src/tools/generate-uns-measurements.ts [options]\n\nOptions:\n --input <file> Path to uns-measurements.json (default: ${DEFAULT_INPUT})\n --output <file> Path to generated TS file (default: src/uns/uns-measurements.generated.ts)\n --lang <code> Preferred description language (default: \"sl\")\n --help, -h Show this help\n`);\n}\n\nasync function loadJson(filePath: string): Promise<MeasurementsJson> {\n const abs = path.resolve(process.cwd(), filePath);\n const raw = await readFile(abs, \"utf8\");\n return JSON.parse(raw) as MeasurementsJson;\n}\n\nconst resolveDesc = (entry: Entry | undefined, lang: string): string | undefined => {\n if (!entry) return undefined;\n const byLang = entry.descriptions?.[lang];\n if (byLang && byLang.length > 0) return byLang;\n if (entry.description && entry.description.length > 0) return entry.description;\n return undefined;\n};\n\nfunction renderSection(name: string, entries: Record<string, Entry> | undefined, lang: string): string {\n if (!entries) return `export const ${name} = {} as const;`;\n const lines = Object.entries(entries)\n .map(([key, entry]) => {\n const desc = resolveDesc(entry, lang);\n const doc = desc ? ` /** ${desc} */\\n` : \"\";\n return `${doc} \"${key}\": \"${entry.value}\",`;\n })\n .join(\"\\n\");\n return `export const ${name} = {\\n${lines}\\n} as const;`;\n}\n\nfunction renderTs(json: MeasurementsJson, lang: string): string {\n const physical = renderSection(\"GeneratedPhysicalMeasurements\", json.physical, lang);\n const dataSize = renderSection(\"GeneratedDataSizeMeasurements\", json.dataSize, lang);\n const counter = renderSection(\"GeneratedCounterMeasurements\", json.counter, lang);\n\n return `/* Auto-generated by generate-uns-measurements.ts. Do not edit by hand. */\\n${physical}\\n\\n${dataSize}\\n\\n${counter}\\n\\nexport type GeneratedPhysicalMeasurement = typeof GeneratedPhysicalMeasurements[keyof typeof GeneratedPhysicalMeasurements];\\nexport type GeneratedDataSizeMeasurement = typeof GeneratedDataSizeMeasurements[keyof typeof GeneratedDataSizeMeasurements];\\nexport type GeneratedCounterMeasurement = typeof GeneratedCounterMeasurements[keyof typeof GeneratedCounterMeasurements];\\nexport type GeneratedMeasurementUnit = GeneratedPhysicalMeasurement | GeneratedDataSizeMeasurement | GeneratedCounterMeasurement | (string & {});\\n`;\n}\n\nexport async function generateUnsMeasurements(args: Partial<{ input: string; output: string; lang: string }>): Promise<void> {\n const input = args.input ?? DEFAULT_INPUT;\n const output = args.output ?? DEFAULT_OUTPUT;\n const lang = args.lang ?? \"sl\";\n\n const json = await loadJson(input);\n const content = renderTs(json, lang);\n await mkdir(path.dirname(output), { recursive: true });\n await writeFile(output, content, \"utf8\");\n console.log(`Generated measurements -> ${output}`);\n}\n\nmain().catch((err) => {\n console.error(\"Failed to generate measurements:\", err);\n process.exitCode = 1;\n});\n"]}
|
|
1
|
+
{"version":3,"file":"generate-uns-measurements.js","sourceRoot":"","sources":["../../src/tools/generate-uns-measurements.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAgBzD,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,uCAAuC,CAAC,CAAC;AAE5F,KAAK,UAAU,IAAI;IACjB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,MAAM,uBAAuB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,SAAS,CAAC,IAAc;IAC/B,IAAI,KAAK,GAAG,aAAa,CAAC;IAC1B,IAAI,MAAM,GAAG,cAAc,CAAC;IAC5B,IAAI,IAAI,GAAG,IAAI,CAAC;IAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACrC,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;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C,CAAC,CAAC,CAAC,IAAI;IACvE,CAAC,CAAC,KAAK,CAAC;AAEV,IAAI,iBAAiB,EAAE,CAAC;IACtB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACnB,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAC;QACvD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * Generate a TypeScript helper for measurements from a JSON file.\n *\n * JSON shape (example):\n * {\n * \"physical\": {\n * \"None\": { \"value\": \"\", \"description\": \"Brez enote\" },\n * \"Celsius\": { \"value\": \"°C\", \"description\": \"Stopinje Celzija\" }\n * },\n * \"dataSize\": {\n * \"Bit\": { \"value\": \"bit\", \"description\": \"Bit\" }\n * },\n * \"counter\": {\n * \"Kilo\": { \"value\": \"k\", \"description\": \"Kilo\" }\n * }\n * }\n */\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { writeTextFileIfChanged } from \"./file-utils.js\";\n\ntype Entry = {\n value: string;\n description?: string | null;\n descriptions?: Record<string, string | null | undefined>;\n [key: string]: unknown;\n};\ntype MeasurementsJson = {\n schemaVersion?: unknown;\n physical?: Record<string, Entry>;\n dataSize?: Record<string, Entry>;\n counter?: Record<string, Entry>;\n [category: string]: unknown;\n};\n\nconst DEFAULT_INPUT = \"uns-measurements.json\";\nconst DEFAULT_OUTPUT = path.resolve(process.cwd(), \"src/uns/uns-measurements.generated.ts\");\n\nasync function main() {\n const { input, output, lang } = parseArgs(process.argv.slice(2));\n await generateUnsMeasurements({ input, output, lang });\n}\n\nfunction parseArgs(argv: string[]) {\n let input = DEFAULT_INPUT;\n let output = DEFAULT_OUTPUT;\n let lang = \"sl\";\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--input\" && argv[i + 1]) {\n input = argv[++i];\n continue;\n }\n if (arg === \"--output\" && argv[i + 1]) {\n output = argv[++i];\n continue;\n }\n if (arg === \"--lang\" && argv[i + 1]) {\n lang = argv[++i];\n continue;\n }\n if (arg === \"--help\" || arg === \"-h\") {\n printHelp();\n process.exit(0);\n }\n throw new Error(`Unknown argument: ${arg}`);\n }\n\n return { input, output, lang };\n}\n\nfunction printHelp(): void {\n console.log(`Usage: tsx packages/uns-core/src/tools/generate-uns-measurements.ts [options]\n\nOptions:\n --input <file> Path to uns-measurements.json (default: ${DEFAULT_INPUT})\n --output <file> Path to generated TS file (default: src/uns/uns-measurements.generated.ts)\n --lang <code> Preferred description language (default: \"sl\")\n --help, -h Show this help\n`);\n}\n\nasync function loadJson(filePath: string): Promise<MeasurementsJson> {\n const abs = path.resolve(process.cwd(), filePath);\n const raw = await readFile(abs, \"utf8\");\n return JSON.parse(raw) as MeasurementsJson;\n}\n\nconst resolveDesc = (entry: Entry | undefined, lang: string): string | undefined => {\n if (!entry) return undefined;\n const byLang = entry.descriptions?.[lang];\n if (byLang && byLang.length > 0) return byLang;\n if (entry.description && entry.description.length > 0) return entry.description;\n return undefined;\n};\n\nfunction renderSection(name: string, entries: Record<string, Entry> | undefined, lang: string): string {\n if (!entries) return `export const ${name} = {} as const;`;\n const lines = Object.entries(entries)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, entry]) => {\n const desc = resolveDesc(entry, lang);\n const doc = renderDoc(desc, \" \");\n return `${doc} \"${key}\": \"${entry.value}\",`;\n })\n .join(\"\\n\");\n return `export const ${name} = {\\n${lines}\\n} as const;`;\n}\n\nfunction renderDoc(description: string | undefined, indent: string): string {\n if (!description) return \"\";\n const normalized = description\n .replaceAll(\"*/\", \"*\\\\/\")\n .split(/\\r?\\n/)\n .map((line) => `${indent} * ${line}`)\n .join(\"\\n\");\n return `${indent}/**\\n${normalized}\\n${indent} */\\n`;\n}\n\nexport function renderMeasurementsTs(json: MeasurementsJson, lang: string): string {\n const physical = renderSection(\"GeneratedPhysicalMeasurements\", json.physical, lang);\n const dataSize = renderSection(\"GeneratedDataSizeMeasurements\", json.dataSize, lang);\n const counter = renderSection(\"GeneratedCounterMeasurements\", json.counter, lang);\n\n return `/* Auto-generated by generate-uns-measurements.ts. Do not edit by hand. */\\n${physical}\\n\\n${dataSize}\\n\\n${counter}\\n\\nexport type GeneratedPhysicalMeasurement = typeof GeneratedPhysicalMeasurements[keyof typeof GeneratedPhysicalMeasurements];\\nexport type GeneratedDataSizeMeasurement = typeof GeneratedDataSizeMeasurements[keyof typeof GeneratedDataSizeMeasurements];\\nexport type GeneratedCounterMeasurement = typeof GeneratedCounterMeasurements[keyof typeof GeneratedCounterMeasurements];\\nexport type GeneratedMeasurementUnit = GeneratedPhysicalMeasurement | GeneratedDataSizeMeasurement | GeneratedCounterMeasurement | (string & {});\\n`;\n}\n\nexport async function generateUnsMeasurements(\n args: Partial<{ input: string; output: string; lang: string }>,\n): Promise<void> {\n const input = args.input ?? DEFAULT_INPUT;\n const output = args.output ?? DEFAULT_OUTPUT;\n const lang = args.lang ?? \"sl\";\n\n const json = await loadJson(input);\n const content = renderMeasurementsTs(json, lang);\n const changed = await writeTextFileIfChanged(output, content);\n console.log(`Generated measurements -> ${output}${changed ? \"\" : \" (unchanged)\"}`);\n}\n\nconst isDirectExecution = process.argv[1]\n ? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href\n : false;\n\nif (isDirectExecution) {\n main().catch((err) => {\n console.error(\"Failed to generate measurements:\", err);\n process.exitCode = 1;\n });\n}\n"]}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* generate-uns-measurements.ts to make project setup simpler.
|
|
6
6
|
*/
|
|
7
7
|
import path from "node:path";
|
|
8
|
+
import { pathToFileURL } from "node:url";
|
|
8
9
|
import { generateUnsDictionary } from "./generate-uns-dictionary.js";
|
|
9
10
|
import { generateUnsMeasurements } from "./generate-uns-measurements.js";
|
|
10
11
|
const DEFAULT_DICT_INPUT = "uns-dictionary.json";
|
|
@@ -73,8 +74,13 @@ Options:
|
|
|
73
74
|
--help, -h Show this help
|
|
74
75
|
`);
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
const isDirectExecution = process.argv[1]
|
|
78
|
+
? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
|
|
79
|
+
: false;
|
|
80
|
+
if (isDirectExecution) {
|
|
81
|
+
main().catch((err) => {
|
|
82
|
+
console.error("Failed to generate UNS reference:", err);
|
|
83
|
+
process.exitCode = 1;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
80
86
|
//# sourceMappingURL=generate-uns-reference.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-uns-reference.js","sourceRoot":"","sources":["../../src/tools/generate-uns-reference.ts"],"names":[],"mappings":";AACA;;;;GAIG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAUzE,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AACjD,MAAM,mBAAmB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,qCAAqC,CAAC,CAAC;AAC/F,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AACnD,MAAM,mBAAmB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,uCAAuC,CAAC,CAAC;AAEjG,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9C,MAAM,qBAAqB,CAAC;QAC1B,KAAK,EAAE,IAAI,CAAC,UAAU;QACtB,MAAM,EAAE,IAAI,CAAC,gBAAgB;QAC7B,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CA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GAAG,KAAK,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;IACvE,CAAC,CAAC,KAAK,CAAC;AAEV,IAAI,iBAAiB,EAAE,CAAC;IACtB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACnB,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;QACxD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * Generate both UNS dictionary and measurements in one go.\n * This is a small wrapper over generate-uns-dictionary.ts and\n * generate-uns-measurements.ts to make project setup simpler.\n */\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { generateUnsDictionary } from \"./generate-uns-dictionary.js\";\nimport { generateUnsMeasurements } from \"./generate-uns-measurements.js\";\n\ntype CliArgs = {\n dictionary: string;\n dictionaryOutput: string;\n measurements: string;\n measurementsOutput: string;\n lang: string;\n};\n\nconst DEFAULT_DICT_INPUT = \"uns-dictionary.json\";\nconst DEFAULT_DICT_OUTPUT = path.resolve(process.cwd(), \"src/uns/uns-dictionary.generated.ts\");\nconst DEFAULT_MEAS_INPUT = \"uns-measurements.json\";\nconst DEFAULT_MEAS_OUTPUT = path.resolve(process.cwd(), \"src/uns/uns-measurements.generated.ts\");\n\nasync function main(): Promise<void> {\n const args = parseArgs(process.argv.slice(2));\n\n await generateUnsDictionary({\n input: args.dictionary,\n output: args.dictionaryOutput,\n lang: args.lang,\n });\n\n await generateUnsMeasurements({\n input: args.measurements,\n output: args.measurementsOutput,\n lang: args.lang,\n });\n\n console.log(\n `Generated reference -> dictionary: ${args.dictionaryOutput}, measurements: ${args.measurementsOutput}`,\n );\n}\n\nfunction parseArgs(argv: string[]): CliArgs {\n let dictionary = DEFAULT_DICT_INPUT;\n let dictionaryOutput = DEFAULT_DICT_OUTPUT;\n let measurements = DEFAULT_MEAS_INPUT;\n let measurementsOutput = DEFAULT_MEAS_OUTPUT;\n let lang = \"sl\";\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--dictionary\" && argv[i + 1]) {\n dictionary = argv[++i];\n continue;\n }\n if (arg === \"--dictionary-output\" && argv[i + 1]) {\n dictionaryOutput = argv[++i];\n continue;\n }\n if (arg === \"--measurements\" && argv[i + 1]) {\n measurements = argv[++i];\n continue;\n }\n if (arg === \"--measurements-output\" && argv[i + 1]) {\n measurementsOutput = argv[++i];\n continue;\n }\n if (arg === \"--lang\" && argv[i + 1]) {\n lang = argv[++i];\n continue;\n }\n if (arg === \"--help\" || arg === \"-h\") {\n printHelp();\n process.exit(0);\n }\n throw new Error(`Unknown argument: ${arg}`);\n }\n\n return { dictionary, dictionaryOutput, measurements, measurementsOutput, lang };\n}\n\nfunction printHelp(): void {\n console.log(`Usage: tsx packages/uns-core/src/tools/generate-uns-reference.ts [options]\n\nOptions:\n --dictionary <file> Path to uns-dictionary.json (default: ${DEFAULT_DICT_INPUT})\n --dictionary-output <file> Path to generated dictionary TS (default: ${DEFAULT_DICT_OUTPUT})\n --measurements <file> Path to uns-measurements.json (default: ${DEFAULT_MEAS_INPUT})\n --measurements-output <file> Path to generated measurements TS (default: ${DEFAULT_MEAS_OUTPUT})\n --lang <code> Preferred description language (default: \"sl\")\n --help, -h Show this help\n`);\n}\n\nconst isDirectExecution = process.argv[1]\n ? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href\n : false;\n\nif (isDirectExecution) {\n main().catch((err) => {\n console.error(\"Failed to generate UNS reference:\", err);\n process.exitCode = 1;\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-uns-schema.d.ts","sourceRoot":"","sources":["../../src/tools/sync-uns-schema.ts"],"names":[],"mappings":""}
|