@spyglassmc/mcdoc-cli 0.1.2 → 0.1.4
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/lib/index.d.mts +3 -0
- package/lib/{index.js → index.mjs} +37 -28
- package/package.json +13 -11
- package/lib/index.d.ts +0 -3
package/lib/index.d.mts
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env -S
|
|
1
|
+
#!/usr/bin/env -S tsx
|
|
2
2
|
import { dirname, join, parse, resolve } from 'path';
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
4
4
|
import fs from 'fs-extra';
|
|
@@ -13,25 +13,30 @@ import * as mcdoc from '@spyglassmc/mcdoc';
|
|
|
13
13
|
const parentPath = dirname(fileURLToPath(import.meta.url));
|
|
14
14
|
const cacheRoot = join(parentPath, 'cache');
|
|
15
15
|
const CLI = yargs(hideBin(process.argv));
|
|
16
|
+
function removeWindowsCruft(str) {
|
|
17
|
+
if (str.includes('\r'))
|
|
18
|
+
return str.replaceAll('\r', '');
|
|
19
|
+
return str;
|
|
20
|
+
}
|
|
16
21
|
await CLI.scriptName('mcdoc')
|
|
17
22
|
.command('generate [source]', 'Generate JSON files', () => CLI.positional('source', {
|
|
18
|
-
describe: 'path to directory containing mcdoc source',
|
|
23
|
+
describe: 'path to directory containing mcdoc source.',
|
|
19
24
|
type: 'string',
|
|
20
25
|
default: '.',
|
|
21
26
|
}).options({
|
|
22
27
|
'locale': {
|
|
23
28
|
alias: 'l',
|
|
24
|
-
description: 'en-us language key-value store of all doc comments',
|
|
29
|
+
description: 'en-us language key-value store of all doc comments.',
|
|
25
30
|
default: false,
|
|
26
31
|
},
|
|
27
32
|
'module': {
|
|
28
33
|
alias: 'm',
|
|
29
|
-
description: 'file tree mirroring definitions; to optimize for web',
|
|
34
|
+
description: 'file tree mirroring definitions; to optimize for web.',
|
|
30
35
|
default: false,
|
|
31
36
|
},
|
|
32
37
|
'pretty': {
|
|
33
38
|
alias: 'p',
|
|
34
|
-
description: 'pretty printed variants',
|
|
39
|
+
description: 'pretty printed variants.',
|
|
35
40
|
default: false,
|
|
36
41
|
},
|
|
37
42
|
'verbose': {
|
|
@@ -40,7 +45,7 @@ await CLI.scriptName('mcdoc')
|
|
|
40
45
|
},
|
|
41
46
|
'dry': {
|
|
42
47
|
alias: 'd',
|
|
43
|
-
description: 'will not write to disk',
|
|
48
|
+
description: 'will not write to disk.',
|
|
44
49
|
default: false,
|
|
45
50
|
},
|
|
46
51
|
}).boolean('locale').boolean('module').boolean('pretty').boolean('verbose').boolean('dry'), async (args) => {
|
|
@@ -75,11 +80,14 @@ await CLI.scriptName('mcdoc')
|
|
|
75
80
|
});
|
|
76
81
|
await service.project.ready();
|
|
77
82
|
await service.project.cacheService.save();
|
|
78
|
-
const
|
|
83
|
+
const generated = join('out', 'generated');
|
|
79
84
|
if (args.dry !== true) {
|
|
80
|
-
await fs.ensureDir(
|
|
85
|
+
await fs.ensureDir(generated);
|
|
81
86
|
if (args.module) {
|
|
82
|
-
await fs.ensureDir(join(
|
|
87
|
+
await fs.ensureDir(join(generated, 'module'));
|
|
88
|
+
}
|
|
89
|
+
if (args.locale) {
|
|
90
|
+
await fs.ensureDir(join('out', 'locale'));
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
const symbols = [];
|
|
@@ -101,7 +109,7 @@ await CLI.scriptName('mcdoc')
|
|
|
101
109
|
const children = node.children;
|
|
102
110
|
function flattenChild(parent, self, _parent, _child) {
|
|
103
111
|
const child = {};
|
|
104
|
-
|
|
112
|
+
const known_error = false;
|
|
105
113
|
/* @ts-ignore */
|
|
106
114
|
child.self = self;
|
|
107
115
|
/* @ts-ignore */
|
|
@@ -118,6 +126,12 @@ await CLI.scriptName('mcdoc')
|
|
|
118
126
|
}
|
|
119
127
|
}
|
|
120
128
|
child.type = _child.type;
|
|
129
|
+
if (child.type === 'resource_location') {
|
|
130
|
+
/* @ts-ignore */
|
|
131
|
+
child.namespace = _child.namespace;
|
|
132
|
+
/* @ts-ignore */
|
|
133
|
+
child.path = _child.path;
|
|
134
|
+
}
|
|
121
135
|
if (Object.hasOwn(_child, 'isOptional')) {
|
|
122
136
|
/* @ts-ignore */
|
|
123
137
|
child.isOptional = _child.isOptional;
|
|
@@ -131,31 +145,26 @@ await CLI.scriptName('mcdoc')
|
|
|
131
145
|
/* @ts-ignore */
|
|
132
146
|
child.value = _child.value;
|
|
133
147
|
if (internal_locales[parent]) {
|
|
134
|
-
locales[`mcdoc.${resource.replace(
|
|
148
|
+
locales[`mcdoc.${resource.replace(/[\/\\]/g, '.')}.${child.value}`] = removeWindowsCruft(internal_locales[parent].join('').trimEnd());
|
|
135
149
|
delete internal_locales[parent];
|
|
136
150
|
}
|
|
137
151
|
}
|
|
138
152
|
if (child.type === 'mcdoc:struct/map_key' &&
|
|
139
153
|
internal_locales[parent]) {
|
|
140
|
-
locales[`mcdoc.${resource.replace(
|
|
154
|
+
locales[`mcdoc.${resource.replace(/[\/\\]/g, '.')}.map_key`] = removeWindowsCruft(internal_locales[parent].join('').trimEnd());
|
|
141
155
|
delete internal_locales[parent];
|
|
142
156
|
}
|
|
143
157
|
if (Object.hasOwn(_child, 'comment')) {
|
|
144
158
|
/* @ts-ignore */
|
|
145
|
-
const comment = _child.comment
|
|
159
|
+
const comment = _child.comment;
|
|
146
160
|
child.comment = comment;
|
|
147
161
|
if (!args.dry && args.locale &&
|
|
148
162
|
_parent?.type === 'mcdoc:doc_comments') {
|
|
149
163
|
const key = parent.replace(/\[\d+\]$/, '');
|
|
150
|
-
if (!internal_locales
|
|
164
|
+
if (!internal_locales[key]) {
|
|
151
165
|
internal_locales[key] = [];
|
|
152
166
|
}
|
|
153
|
-
internal_locales[key].push(comment);
|
|
154
|
-
}
|
|
155
|
-
else if (comment.startsWith('/ ')) {
|
|
156
|
-
child.type = 'error';
|
|
157
|
-
console.warn(`known error: orphaned dispatch comment`);
|
|
158
|
-
known_error = true;
|
|
167
|
+
internal_locales[key].push(comment.slice(1));
|
|
159
168
|
}
|
|
160
169
|
}
|
|
161
170
|
if (_child.hover)
|
|
@@ -205,12 +214,12 @@ await CLI.scriptName('mcdoc')
|
|
|
205
214
|
};
|
|
206
215
|
symbols.push(symbol);
|
|
207
216
|
if (!args.dry && args.module) {
|
|
208
|
-
const dir = parse(join(
|
|
217
|
+
const dir = parse(join(generated, 'module', resource)).dir;
|
|
209
218
|
if (dir !== '')
|
|
210
219
|
await fs.ensureDir(dir);
|
|
211
|
-
await fs.writeFile(join(
|
|
220
|
+
await fs.writeFile(join(generated, 'module', `${resource}.mcdoc.json`), JSON.stringify(symbol));
|
|
212
221
|
if (args.pretty) {
|
|
213
|
-
await fs.writeFile(join(
|
|
222
|
+
await fs.writeFile(join(generated, 'module', `${resource}.pretty.mcdoc.json`), JSON.stringify(symbol, undefined, 3));
|
|
214
223
|
}
|
|
215
224
|
}
|
|
216
225
|
}
|
|
@@ -218,12 +227,12 @@ await CLI.scriptName('mcdoc')
|
|
|
218
227
|
}
|
|
219
228
|
}
|
|
220
229
|
if (!args.dry) {
|
|
221
|
-
await fs.writeFile(join(
|
|
230
|
+
await fs.writeFile(join(generated, 'generated.mcdoc.json'), JSON.stringify(symbols));
|
|
222
231
|
if (args.pretty) {
|
|
223
|
-
await fs.writeFile(join(
|
|
232
|
+
await fs.writeFile(join(generated, 'generated.pretty.mcdoc.json'), JSON.stringify(symbols, undefined, 3));
|
|
224
233
|
}
|
|
225
234
|
if (args.module) {
|
|
226
|
-
await fs.writeFile(join(
|
|
235
|
+
await fs.writeFile(join(generated, 'module', 'index.json'), JSON.stringify(symbols.map(symbol => symbol.resource)));
|
|
227
236
|
}
|
|
228
237
|
if (args.locale) {
|
|
229
238
|
const orphaned_doc = Object.keys(internal_locales);
|
|
@@ -231,7 +240,7 @@ await CLI.scriptName('mcdoc')
|
|
|
231
240
|
console.warn(`parsing error, ${orphaned_doc.length} orphaned doc comments or incorrectly parsed markup comments`);
|
|
232
241
|
console.warn(internal_locales);
|
|
233
242
|
}
|
|
234
|
-
await fs.writeFile(join(out, 'locale.en-us.json'), JSON.stringify(locales, undefined, 3));
|
|
243
|
+
await fs.writeFile(join('out', 'locale', 'locale.en-us.json'), JSON.stringify(locales, undefined, 3));
|
|
235
244
|
}
|
|
236
245
|
}
|
|
237
246
|
console.log(`Generated JSON files with ${errors} errors.`);
|
|
@@ -240,4 +249,4 @@ await CLI.scriptName('mcdoc')
|
|
|
240
249
|
.strict()
|
|
241
250
|
.demandCommand(1)
|
|
242
251
|
.parse();
|
|
243
|
-
//# sourceMappingURL=index.
|
|
252
|
+
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/mcdoc-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "lib/index.
|
|
6
|
-
"types": "lib/index.d.
|
|
5
|
+
"main": "lib/index.mjs",
|
|
6
|
+
"types": "lib/index.d.mts",
|
|
7
7
|
"contributors": [
|
|
8
8
|
{
|
|
9
|
-
"name": "Misode"
|
|
9
|
+
"name": "Misode",
|
|
10
|
+
"url": "https://github.com/misode"
|
|
10
11
|
},
|
|
11
12
|
{
|
|
12
13
|
"name": "MulverineX",
|
|
13
|
-
"url": "
|
|
14
|
+
"url": "https://mulverine.dev"
|
|
14
15
|
}
|
|
15
16
|
],
|
|
16
17
|
"license": "MIT",
|
|
@@ -18,34 +19,35 @@
|
|
|
18
19
|
"test": "test/"
|
|
19
20
|
},
|
|
20
21
|
"bin": {
|
|
21
|
-
"mcdoc": "
|
|
22
|
+
"mcdoc": "lib/index.mjs"
|
|
22
23
|
},
|
|
23
24
|
"scripts": {
|
|
24
25
|
"release": "npm publish",
|
|
25
26
|
"release:dry": "npm publish --dry-run",
|
|
26
|
-
"test": "rm -rf vanilla-mcdoc && rm -rf src/out && git clone https://github.com/SpyglassMC/vanilla-mcdoc && cd src &&
|
|
27
|
+
"test": "rm -rf vanilla-mcdoc && rm -rf src/out && git clone https://github.com/SpyglassMC/vanilla-mcdoc && cd src && npx tsx src/index.mts generate ../vanilla-mcdoc/ -p -m -l"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
30
|
"fs-extra": "^11.1.1",
|
|
30
31
|
"klaw": "^4.1.0",
|
|
31
32
|
"line-column": "^1.0.2",
|
|
32
33
|
"yargs": "17.6.2",
|
|
33
|
-
"@spyglassmc/core": "0.4.
|
|
34
|
-
"@spyglassmc/mcdoc": "0.3.
|
|
34
|
+
"@spyglassmc/core": "0.4.4",
|
|
35
|
+
"@spyglassmc/mcdoc": "0.3.5"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/fs-extra": "^11.0.2",
|
|
38
39
|
"@types/klaw": "^3.0.4",
|
|
39
40
|
"@types/line-column": "^1.0.0",
|
|
40
41
|
"@types/node": "18.11.17",
|
|
41
|
-
"@types/yargs": "17.0.17"
|
|
42
|
+
"@types/yargs": "17.0.17",
|
|
43
|
+
"typescript": "^5.4.5"
|
|
42
44
|
},
|
|
43
45
|
"publishConfig": {
|
|
44
46
|
"access": "public"
|
|
45
47
|
},
|
|
46
48
|
"repository": {
|
|
47
49
|
"type": "git",
|
|
48
|
-
"url": "https://github.com/SpyglassMC/Spyglass.git"
|
|
50
|
+
"url": "git+https://github.com/SpyglassMC/Spyglass.git"
|
|
49
51
|
},
|
|
50
52
|
"homepage": "https://spyglassmc.com",
|
|
51
53
|
"bugs": {
|
package/lib/index.d.ts
DELETED