@atcute/lex-cli 2.7.0 → 2.8.1
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/dist/cli.d.ts +19 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +35 -7
- package/dist/cli.js.map +1 -1
- package/dist/commands/export.d.ts +2 -8
- package/dist/commands/export.d.ts.map +1 -1
- package/dist/commands/export.js +7 -14
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/generate.d.ts +2 -8
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +61 -39
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/pull.d.ts +2 -8
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +1 -12
- package/dist/commands/pull.js.map +1 -1
- package/dist/config.d.ts +30 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +56 -12
- package/dist/config.js.map +1 -1
- package/dist/pull-sources/git.d.ts.map +1 -1
- package/dist/pull-sources/git.js +61 -58
- package/dist/pull-sources/git.js.map +1 -1
- package/package.json +6 -6
- package/src/cli.ts +65 -7
- package/src/commands/export.ts +9 -24
- package/src/commands/generate.ts +72 -50
- package/src/commands/pull.ts +2 -22
- package/src/config.ts +77 -23
- package/src/pull-sources/git.ts +64 -63
- package/dist/shared-options.d.ts +0 -6
- package/dist/shared-options.d.ts.map +0 -1
- package/dist/shared-options.js +0 -11
- package/dist/shared-options.js.map +0 -1
- package/src/shared-options.ts +0 -13
package/dist/config.js
CHANGED
|
@@ -97,23 +97,47 @@ const importMappingSchema = v.object({
|
|
|
97
97
|
.assert((patterns) => patterns.length > 0, `nsid requires at least one pattern`),
|
|
98
98
|
imports: mappingImports,
|
|
99
99
|
});
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
const modulesConfigSchema = v
|
|
101
|
+
.object({
|
|
102
|
+
importSuffix: v
|
|
103
|
+
.string()
|
|
104
|
+
.assert((value) => value.length > 0, `must not be empty`)
|
|
105
|
+
.optional(),
|
|
106
|
+
})
|
|
107
|
+
.partial();
|
|
108
|
+
const generateConfigSchema = v.object({
|
|
109
|
+
outdir: v
|
|
110
|
+
.string()
|
|
111
|
+
.assert((value) => value.length > 0, `must not be empty`)
|
|
112
|
+
.optional(),
|
|
102
113
|
files: v
|
|
103
114
|
.array(v.string().assert((value) => value.length > 0, `must not be empty`))
|
|
104
|
-
.assert((value) => value.length > 0, `must include at least one glob pattern`)
|
|
115
|
+
.assert((value) => value.length > 0, `must include at least one glob pattern`)
|
|
116
|
+
.optional(),
|
|
105
117
|
imports: v.array(v.string().assert((value) => value.length > 0, `must not be empty`)).optional(),
|
|
106
118
|
mappings: v.array(importMappingSchema).optional(),
|
|
107
|
-
modules:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
.
|
|
119
|
+
modules: modulesConfigSchema.optional(),
|
|
120
|
+
clean: v.boolean().optional(),
|
|
121
|
+
});
|
|
122
|
+
export const lexiconConfigSchema = v.object({
|
|
123
|
+
/** @deprecated moved to `generate.outdir` */
|
|
124
|
+
outdir: v
|
|
125
|
+
.string()
|
|
126
|
+
.assert((value) => value.length > 0, `must not be empty`)
|
|
127
|
+
.optional(),
|
|
128
|
+
/** @deprecated moved to `generate.files` */
|
|
129
|
+
files: v
|
|
130
|
+
.array(v.string().assert((value) => value.length > 0, `must not be empty`))
|
|
131
|
+
.assert((value) => value.length > 0, `must include at least one glob pattern`)
|
|
115
132
|
.optional(),
|
|
133
|
+
/** @deprecated moved to `generate.imports` */
|
|
134
|
+
imports: v.array(v.string().assert((value) => value.length > 0, `must not be empty`)).optional(),
|
|
135
|
+
/** @deprecated moved to `generate.mappings` */
|
|
136
|
+
mappings: v.array(importMappingSchema).optional(),
|
|
137
|
+
/** @deprecated moved to `generate.modules` */
|
|
138
|
+
modules: modulesConfigSchema.optional(),
|
|
116
139
|
formatter: formatterConfigSchema.optional(() => ({ type: 'prettier' })),
|
|
140
|
+
generate: generateConfigSchema.optional(),
|
|
117
141
|
pull: pullConfigSchema.optional(),
|
|
118
142
|
export: exportConfigSchema.optional(),
|
|
119
143
|
});
|
|
@@ -163,6 +187,26 @@ export const loadConfig = async (configPath) => {
|
|
|
163
187
|
}
|
|
164
188
|
process.exit(1);
|
|
165
189
|
}
|
|
166
|
-
|
|
190
|
+
const { outdir, files, imports, mappings, modules, generate, ...rest } = configResult.value;
|
|
191
|
+
// back-compat: top-level generate options were moved into `generate.*`. merge the legacy
|
|
192
|
+
// top-level values into `generate`, with nested `generate.*` winning on conflicts. the result
|
|
193
|
+
// is only present if at least one generate-related option was provided anywhere.
|
|
194
|
+
const hasLegacyTopLevel = outdir !== undefined ||
|
|
195
|
+
files !== undefined ||
|
|
196
|
+
imports !== undefined ||
|
|
197
|
+
mappings !== undefined ||
|
|
198
|
+
modules !== undefined;
|
|
199
|
+
let normalizedGenerate;
|
|
200
|
+
if (generate || hasLegacyTopLevel) {
|
|
201
|
+
normalizedGenerate = {
|
|
202
|
+
outdir: generate?.outdir ?? outdir,
|
|
203
|
+
files: generate?.files ?? files,
|
|
204
|
+
imports: generate?.imports ?? imports,
|
|
205
|
+
mappings: generate?.mappings ?? mappings,
|
|
206
|
+
modules: generate?.modules ?? modules,
|
|
207
|
+
clean: generate?.clean,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return { ...rest, generate: normalizedGenerate, root: configDirname };
|
|
167
211
|
};
|
|
168
212
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,MAA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iFAAiF;IACjF,MAAM,iBAAiB,GACtB,MAAM,KAAK,SAAS;QACpB,KAAK,KAAK,SAAS;QACnB,OAAO,KAAK,SAAS;QACrB,QAAQ,KAAK,SAAS;QACtB,OAAO,KAAK,SAAS,CAAC;IAEvB,IAAI,kBAA8C,CAAC;IACnD,IAAI,QAAQ,IAAI,iBAAiB,EAAE,CAAC;QACnC,kBAAkB,GAAG;YACpB,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,MAAM;YAClC,KAAK,EAAE,QAAQ,EAAE,KAAK,IAAI,KAAK;YAC/B,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,OAAO;YACrC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,IAAI,QAAQ;YACxC,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,OAAO;YACrC,KAAK,EAAE,QAAQ,EAAE,KAAK;SACtB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;AACvE,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/pull-sources/git.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAItD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,KAAK,EAAE,UAAU,EAAiB,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5E;;;;;GAKG;AACH,eAAO,MAAM,aAAa,WACjB,eAAe,oBACL,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,UAAU,CAAC,KAC5D,OAAO,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/pull-sources/git.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAItD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,KAAK,EAAE,UAAU,EAAiB,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5E;;;;;GAKG;AACH,eAAO,MAAM,aAAa,WACjB,eAAe,oBACL,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,UAAU,CAAC,KAC5D,OAAO,CAAC,UAAU,CAmFpB,CAAC"}
|
package/dist/pull-sources/git.js
CHANGED
|
@@ -13,68 +13,71 @@ export const pullGitSource = async (source, parseLexiconFile) => {
|
|
|
13
13
|
const tempParent = await fs.mkdtemp(path.join(os.tmpdir(), 'lex-cli-pull-'));
|
|
14
14
|
const cloneDir = path.join(tempParent, 'repo');
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
catch (err) {
|
|
28
|
-
if (err instanceof GitError) {
|
|
29
|
-
console.error(pc.bold(pc.red(`git clone failed for ${source.remote}:`)));
|
|
30
|
-
console.error(err.stderr || err.message);
|
|
31
|
-
process.exit(1);
|
|
16
|
+
try {
|
|
17
|
+
await runGit([
|
|
18
|
+
'clone',
|
|
19
|
+
'--filter=blob:none',
|
|
20
|
+
'--depth',
|
|
21
|
+
'1',
|
|
22
|
+
'--sparse',
|
|
23
|
+
...(source.ref ? ['--branch', source.ref, '--single-branch'] : []),
|
|
24
|
+
source.remote,
|
|
25
|
+
cloneDir,
|
|
26
|
+
], { timeoutMs: 60_000 });
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
catch (err) {
|
|
41
|
-
if (err instanceof GitError) {
|
|
42
|
-
console.error(pc.bold(pc.red(`git sparse-checkout failed for ${source.remote}:`)));
|
|
43
|
-
console.error(err.stderr || err.message);
|
|
44
|
-
process.exit(1);
|
|
28
|
+
catch (err) {
|
|
29
|
+
if (err instanceof GitError) {
|
|
30
|
+
console.error(pc.bold(pc.red(`git clone failed for ${source.remote}:`)));
|
|
31
|
+
console.error(err.stderr || err.message);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
throw err;
|
|
45
35
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const absolute = path.join(cloneDir, filename);
|
|
51
|
-
const stat = await fs.stat(absolute);
|
|
52
|
-
if (!stat.isFile()) {
|
|
53
|
-
continue;
|
|
36
|
+
try {
|
|
37
|
+
await runGit(['-C', cloneDir, 'sparse-checkout', 'set', '--no-cone', ...source.pattern], {
|
|
38
|
+
timeoutMs: 30_000,
|
|
39
|
+
});
|
|
54
40
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err instanceof GitError) {
|
|
43
|
+
console.error(pc.bold(pc.red(`git sparse-checkout failed for ${source.remote}:`)));
|
|
44
|
+
console.error(err.stderr || err.message);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
const pulled = new Map();
|
|
50
|
+
for await (const filename of fs.glob(source.pattern, { cwd: cloneDir })) {
|
|
51
|
+
const absolute = path.join(cloneDir, filename);
|
|
52
|
+
const stat = await fs.stat(absolute);
|
|
53
|
+
if (!stat.isFile()) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const location = {
|
|
57
|
+
absolutePath: absolute,
|
|
58
|
+
relativePath: filename,
|
|
59
|
+
sourceDescription: source.remote,
|
|
60
|
+
};
|
|
61
|
+
const doc = await parseLexiconFile(location);
|
|
62
|
+
pulled.set(doc.id, { nsid: doc.id, doc, location });
|
|
74
63
|
}
|
|
75
|
-
|
|
64
|
+
let rev;
|
|
65
|
+
try {
|
|
66
|
+
const result = await runGit(['-C', cloneDir, 'rev-parse', 'HEAD'], { timeoutMs: 10_000 });
|
|
67
|
+
rev = result.stdout.trim();
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
if (err instanceof GitError) {
|
|
71
|
+
console.error(pc.bold(pc.red(`git rev-parse failed for ${source.remote}:`)));
|
|
72
|
+
console.error(err.stderr || err.message);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
return { pulled, rev };
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
await fs.rm(tempParent, { recursive: true, force: true });
|
|
76
81
|
}
|
|
77
|
-
await fs.rm(tempParent, { recursive: true, force: true });
|
|
78
|
-
return { pulled, rev };
|
|
79
82
|
};
|
|
80
83
|
//# sourceMappingURL=git.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/pull-sources/git.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAIlC,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAI7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EACjC,MAAuB,EACvB,gBAA8D,EACxC,EAAE;IACxB,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,C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EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;AACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atcute/lex-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"description": "cli tool to generate type definitions for atcute",
|
|
5
5
|
"license": "0BSD",
|
|
6
6
|
"repository": {
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@badrap/valita": "^0.4.6",
|
|
28
|
-
"@optique/core": "^0.
|
|
29
|
-
"@optique/run": "^0.
|
|
28
|
+
"@optique/core": "^1.0.0",
|
|
29
|
+
"@optique/run": "^1.0.0",
|
|
30
30
|
"picocolors": "^1.1.1",
|
|
31
|
-
"prettier": "^3.8.
|
|
31
|
+
"prettier": "^3.8.3",
|
|
32
32
|
"@atcute/identity": "^1.1.4",
|
|
33
|
+
"@atcute/lexicon-resolver": "^0.1.6",
|
|
33
34
|
"@atcute/identity-resolver": "^1.2.2",
|
|
34
35
|
"@atcute/lexicon-doc": "^2.2.0",
|
|
35
|
-
"@atcute/lexicon-resolver": "^0.1.6",
|
|
36
36
|
"@atcute/lexicons": "^1.3.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^25.
|
|
39
|
+
"@types/node": "^25.6.0",
|
|
40
40
|
"tschema": "^3.2.0",
|
|
41
41
|
"@atcute/uint8array": "^1.1.1"
|
|
42
42
|
},
|
package/src/cli.ts
CHANGED
|
@@ -1,18 +1,76 @@
|
|
|
1
|
-
import { or } from '@optique/core/constructs';
|
|
1
|
+
import { merge, object, or } from '@optique/core/constructs';
|
|
2
|
+
import { message } from '@optique/core/message';
|
|
3
|
+
import { optional } from '@optique/core/modifiers';
|
|
4
|
+
import { type InferValue } from '@optique/core/parser';
|
|
5
|
+
import { command, constant, option } from '@optique/core/primitives';
|
|
2
6
|
import { run } from '@optique/run';
|
|
7
|
+
import { path as pathParser } from '@optique/run/valueparser';
|
|
3
8
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
const sharedOptions = object(`Global options`, {
|
|
10
|
+
config: optional(
|
|
11
|
+
option('-c', '--config', pathParser({ metavar: 'CONFIG' }), {
|
|
12
|
+
description: message`path to the lexicon configuration file. defaults to searching for lex.config.js or lex.config.ts in the current directory.`,
|
|
13
|
+
}),
|
|
14
|
+
),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const generateCommandSchema = command(
|
|
18
|
+
'generate',
|
|
19
|
+
merge(
|
|
20
|
+
object({
|
|
21
|
+
type: constant('generate'),
|
|
22
|
+
}),
|
|
23
|
+
sharedOptions,
|
|
24
|
+
),
|
|
25
|
+
{
|
|
26
|
+
brief: message`generate type definitions from lexicon documents`,
|
|
27
|
+
description: message`reads lexicon documents from the configured files and generates TypeScript type definitions and runtime validators.`,
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const pullCommandSchema = command(
|
|
32
|
+
'pull',
|
|
33
|
+
merge(
|
|
34
|
+
object({
|
|
35
|
+
type: constant('pull'),
|
|
36
|
+
}),
|
|
37
|
+
sharedOptions,
|
|
38
|
+
),
|
|
39
|
+
{
|
|
40
|
+
brief: message`pull lexicon documents from configured sources`,
|
|
41
|
+
description: message`fetches lexicon documents from configured git repositories and writes them to the output directory.`,
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const exportCommandSchema = command(
|
|
46
|
+
'export',
|
|
47
|
+
merge(
|
|
48
|
+
object({
|
|
49
|
+
type: constant('export'),
|
|
50
|
+
}),
|
|
51
|
+
sharedOptions,
|
|
52
|
+
),
|
|
53
|
+
{
|
|
54
|
+
brief: message`export lexicon documents as JSON files`,
|
|
55
|
+
description: message`exports lexicon documents (from JSON or builder files) to JSON format for publishing or distribution.`,
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
export type GenerateCommand = InferValue<typeof generateCommandSchema>;
|
|
60
|
+
export type PullCommand = InferValue<typeof pullCommandSchema>;
|
|
61
|
+
export type ExportCommand = InferValue<typeof exportCommandSchema>;
|
|
7
62
|
|
|
8
63
|
const parser = or(generateCommandSchema, pullCommandSchema, exportCommandSchema);
|
|
9
64
|
|
|
10
65
|
const result = run(parser, { programName: 'lex-cli', help: 'both' });
|
|
11
66
|
|
|
12
67
|
if (result.type === 'generate') {
|
|
13
|
-
await
|
|
68
|
+
const { handler } = await import('./commands/generate.ts');
|
|
69
|
+
await handler(result);
|
|
14
70
|
} else if (result.type === 'pull') {
|
|
15
|
-
await
|
|
71
|
+
const { handler } = await import('./commands/pull.ts');
|
|
72
|
+
await handler(result);
|
|
16
73
|
} else if (result.type === 'export') {
|
|
17
|
-
await
|
|
74
|
+
const { handler } = await import('./commands/export.ts');
|
|
75
|
+
await handler(result);
|
|
18
76
|
}
|
package/src/commands/export.ts
CHANGED
|
@@ -3,32 +3,12 @@ import * as path from 'node:path';
|
|
|
3
3
|
|
|
4
4
|
import type { LexiconDoc } from '@atcute/lexicon-doc';
|
|
5
5
|
|
|
6
|
-
import { merge, object } from '@optique/core/constructs';
|
|
7
|
-
import { message } from '@optique/core/message';
|
|
8
|
-
import { type InferValue } from '@optique/core/parser';
|
|
9
|
-
import { command, constant } from '@optique/core/primitives';
|
|
10
6
|
import pc from 'picocolors';
|
|
11
7
|
|
|
8
|
+
import type { ExportCommand } from '../cli.ts';
|
|
12
9
|
import { loadConfig, type ExportConfig, type NormalizedConfig } from '../config.ts';
|
|
13
10
|
import { createFormatter, type Formatter } from '../formatter.ts';
|
|
14
11
|
import { loadLexicons } from '../lexicon-loader.ts';
|
|
15
|
-
import { sharedOptions } from '../shared-options.ts';
|
|
16
|
-
|
|
17
|
-
export const exportCommandSchema = command(
|
|
18
|
-
'export',
|
|
19
|
-
merge(
|
|
20
|
-
object({
|
|
21
|
-
type: constant('export'),
|
|
22
|
-
}),
|
|
23
|
-
sharedOptions,
|
|
24
|
-
),
|
|
25
|
-
{
|
|
26
|
-
brief: message`export lexicon documents as JSON files`,
|
|
27
|
-
description: message`exports lexicon documents (from JSON or builder files) to JSON format for publishing or distribution.`,
|
|
28
|
-
},
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
export type ExportCommand = InferValue<typeof exportCommandSchema>;
|
|
32
12
|
|
|
33
13
|
/**
|
|
34
14
|
* ensures export configuration is present
|
|
@@ -64,12 +44,17 @@ const writeLexicon = async (
|
|
|
64
44
|
* runs the export command to write lexicon documents as JSON files
|
|
65
45
|
* @param args parsed command arguments
|
|
66
46
|
*/
|
|
67
|
-
export const
|
|
47
|
+
export const handler = async (args: ExportCommand): Promise<void> => {
|
|
68
48
|
const config = await loadConfig(args.config);
|
|
69
49
|
const exportConfig = ensureExportConfig(config);
|
|
70
50
|
|
|
71
|
-
// use export.files if specified, otherwise fall back to
|
|
72
|
-
const files = exportConfig.files ?? config.files;
|
|
51
|
+
// use export.files if specified, otherwise fall back to generate.files
|
|
52
|
+
const files = exportConfig.files ?? config.generate?.files;
|
|
53
|
+
if (!files || files.length === 0) {
|
|
54
|
+
console.error(pc.bold(pc.red(`export.files or generate.files must be specified`)));
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
73
58
|
const outdir = path.resolve(config.root, exportConfig.outdir);
|
|
74
59
|
const formatter = await createFormatter(config.formatter, config.root);
|
|
75
60
|
|
package/src/commands/generate.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as module from 'node:module';
|
|
2
3
|
import * as path from 'node:path';
|
|
3
4
|
|
|
4
|
-
import { merge, object } from '@optique/core/constructs';
|
|
5
|
-
import { message } from '@optique/core/message';
|
|
6
|
-
import { type InferValue } from '@optique/core/parser';
|
|
7
|
-
import { command, constant } from '@optique/core/primitives';
|
|
8
5
|
import pc from 'picocolors';
|
|
9
6
|
|
|
7
|
+
import type { GenerateCommand } from '../cli.ts';
|
|
10
8
|
import { generateLexiconApi, type ImportMapping } from '../codegen.ts';
|
|
11
|
-
import { loadConfig } from '../config.ts';
|
|
9
|
+
import { loadConfig, type GenerateConfig, type NormalizedConfig } from '../config.ts';
|
|
12
10
|
import { createFormatter } from '../formatter.ts';
|
|
13
11
|
import { loadLexicons } from '../lexicon-loader.ts';
|
|
14
12
|
import { packageJsonSchema } from '../lexicon-metadata.ts';
|
|
15
|
-
import { sharedOptions } from '../shared-options.ts';
|
|
16
13
|
|
|
17
14
|
/**
|
|
18
15
|
* resolves package imports to ImportMapping[]
|
|
@@ -22,40 +19,51 @@ const resolveImportsToMappings = async (
|
|
|
22
19
|
configDirname: string,
|
|
23
20
|
): Promise<ImportMapping[]> => {
|
|
24
21
|
const mappings: ImportMapping[] = [];
|
|
22
|
+
const require = module.createRequire(path.join(configDirname, '__lex_cli__.js'));
|
|
25
23
|
|
|
26
24
|
for (const packageName of imports) {
|
|
27
|
-
// walk up from config directory to find package in node_modules
|
|
28
25
|
let packageJson: unknown;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const entryPath = require.resolve(packageName);
|
|
29
|
+
|
|
30
|
+
let currentDir = path.dirname(entryPath);
|
|
31
|
+
while (true) {
|
|
32
|
+
const candidatePath = path.join(currentDir, 'package.json');
|
|
33
|
+
try {
|
|
34
|
+
const content = await fs.readFile(candidatePath, 'utf8');
|
|
35
|
+
packageJson = JSON.parse(content);
|
|
36
|
+
break;
|
|
37
|
+
} catch (err: any) {
|
|
38
|
+
if (err.code !== 'ENOENT') {
|
|
39
|
+
console.error(pc.bold(pc.red(`failed to read package.json for "${packageName}":`)));
|
|
40
|
+
console.error(err);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (currentDir === configDirname) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const parentDir = path.dirname(currentDir);
|
|
50
|
+
if (parentDir === currentDir) {
|
|
51
|
+
break;
|
|
45
52
|
}
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
currentDir = path.dirname(currentDir);
|
|
54
|
+
currentDir = parentDir;
|
|
49
55
|
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.error(pc.bold(pc.red(`failed to resolve package "${packageName}"`)));
|
|
58
|
+
console.error(err);
|
|
59
|
+
process.exit(1);
|
|
50
60
|
}
|
|
51
61
|
|
|
52
|
-
if (!
|
|
53
|
-
console.error(pc.bold(pc.red(`failed to
|
|
54
|
-
console.error(`Could not find package in node_modules starting from ${configDirname}`);
|
|
62
|
+
if (!packageJson) {
|
|
63
|
+
console.error(pc.bold(pc.red(`failed to locate package.json for "${packageName}"`)));
|
|
55
64
|
process.exit(1);
|
|
56
65
|
}
|
|
57
66
|
|
|
58
|
-
// validate package.json
|
|
59
67
|
const result = packageJsonSchema.try(packageJson, { mode: 'passthrough' });
|
|
60
68
|
if (!result.ok) {
|
|
61
69
|
console.error(pc.bold(pc.red(`invalid atcute:lexicons in "${packageName}":`)));
|
|
@@ -117,40 +125,54 @@ const resolveImportsToMappings = async (
|
|
|
117
125
|
return mappings;
|
|
118
126
|
};
|
|
119
127
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
|
|
128
|
+
type ResolvedGenerateConfig = GenerateConfig & { outdir: string; files: string[] };
|
|
129
|
+
|
|
130
|
+
const ensureGenerateConfig = (config: NormalizedConfig): ResolvedGenerateConfig => {
|
|
131
|
+
const generate = config.generate;
|
|
132
|
+
if (!generate) {
|
|
133
|
+
console.error(pc.bold(pc.red(`generate configuration missing`)));
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const { outdir, files } = generate;
|
|
138
|
+
if (!outdir) {
|
|
139
|
+
console.error(pc.bold(pc.red(`generate.outdir is required`)));
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!files || files.length === 0) {
|
|
144
|
+
console.error(pc.bold(pc.red(`generate.files is required`)));
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return { ...generate, outdir, files };
|
|
149
|
+
};
|
|
135
150
|
|
|
136
151
|
/**
|
|
137
152
|
* runs the generate command to create type definitions from lexicon documents
|
|
138
153
|
* @param args parsed command arguments
|
|
139
154
|
*/
|
|
140
|
-
export const
|
|
155
|
+
export const handler = async (args: GenerateCommand): Promise<void> => {
|
|
141
156
|
const config = await loadConfig(args.config);
|
|
157
|
+
const generateConfig = ensureGenerateConfig(config);
|
|
142
158
|
|
|
143
159
|
// resolve imports to mappings
|
|
144
|
-
const importMappings =
|
|
145
|
-
|
|
160
|
+
const importMappings = generateConfig.imports
|
|
161
|
+
? await resolveImportsToMappings(generateConfig.imports, config.root)
|
|
162
|
+
: [];
|
|
163
|
+
const allMappings = [...importMappings, ...(generateConfig.mappings ?? [])];
|
|
146
164
|
|
|
147
165
|
// load lexicons from files
|
|
148
|
-
const loaded = await loadLexicons(
|
|
166
|
+
const loaded = await loadLexicons(generateConfig.files, config.root);
|
|
149
167
|
const documents = loaded.map((l) => l.doc);
|
|
150
168
|
|
|
151
|
-
const outdir = path.join(config.root,
|
|
169
|
+
const outdir = path.join(config.root, generateConfig.outdir);
|
|
152
170
|
const formatter = await createFormatter(config.formatter, config.root);
|
|
153
171
|
|
|
172
|
+
if (generateConfig.clean) {
|
|
173
|
+
await fs.rm(outdir, { recursive: true, force: true });
|
|
174
|
+
}
|
|
175
|
+
|
|
154
176
|
try {
|
|
155
177
|
const pending: Promise<void>[] = [];
|
|
156
178
|
|
|
@@ -158,7 +180,7 @@ export const runGenerate = async (args: GenerateCommand): Promise<void> => {
|
|
|
158
180
|
documents: documents,
|
|
159
181
|
mappings: allMappings,
|
|
160
182
|
modules: {
|
|
161
|
-
importSuffix:
|
|
183
|
+
importSuffix: generateConfig.modules?.importSuffix ?? '.js',
|
|
162
184
|
},
|
|
163
185
|
})) {
|
|
164
186
|
const filename = path.join(outdir, file.filename);
|