Skip to content

Commit

Permalink
🚧 Prepare mcdoc-cli for release 0.1.3 (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
MulverineX authored May 18, 2024
1 parent f9b5ab2 commit 25de684
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 51 deletions.
20 changes: 11 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/src/parser/resourceLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function resourceLocation(

if (ans.isTag && !options.allowTag) {
ctx.err.report(
localize('parser.resource-location.tag-diallowed'),
localize('parser.resource-location.tag-disallowed'),
ans,
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/java-edition/src/mcfunction/tree/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export function getPatch(release: ReleaseVersion): PartialRootTreeNode {
* 2. `teleport <location: vec3>`
* 3. `teleport <targets: entity(multiple)> <...arguments>`
*
* It is impossible for Spyglass to differentiate between (1) and (3) when it encouters a single entity
* It is impossible for Spyglass to differentiate between (1) and (3) when it encounters a single entity
* at the position of the first argument, due to its lack of ability to backtrack.
*
* Therefore, we have compromised to patch the trees to something like this:
Expand Down
2 changes: 1 addition & 1 deletion packages/locales/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"parser.record.value": "a value",
"parser.resource-location.illegal": "Illegal character(s): %0%",
"parser.resource-location.namespace-expected": "Namespaces cannot be omitted here",
"parser.resource-location.tag-diallowed": "Tags are not allowed here",
"parser.resource-location.tag-disallowed": "Tags are not allowed here",
"parser.string.illegal-brigadier": "Encountered non-[0-9A-Za-z_.+-] characters in %0%",
"parser.string.illegal-escape": "Unexpected escape character %0%",
"parser.string.illegal-quote": "Only %0% can be used to quote strings here",
Expand Down
2 changes: 1 addition & 1 deletion packages/locales/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"parser.record.value": "une valeur",
"parser.resource-location.illegal": "Caractère(s) inattendu(s) : %0%",
"parser.resource-location.namespace-expected": "Les espaces de noms ne peuvent pas être omis ici",
"parser.resource-location.tag-diallowed": "Les tags ne sont pas autorisés ici",
"parser.resource-location.tag-disallowed": "Les tags ne sont pas autorisés ici",
"parser.string.illegal-brigadier": "Des caractères autres que [0-9A-Za-z_.+-] ont été rencontrés dans %0%",
"parser.string.illegal-escape": "Caractère d'échappement inattendu %0%",
"parser.string.illegal-quote": "Seuls %0% peuvent être utilisés pour citer des chaînes de caractères",
Expand Down
2 changes: 1 addition & 1 deletion packages/locales/src/locales/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"parser.record.value": "um valor",
"parser.resource-location.illegal": "Caráter(s) ilegal(is): %0%",
"parser.resource-location.namespace-expected": "EspaçoDeNome não podem ser omitidos aqui",
"parser.resource-location.tag-diallowed": "Tags não são permitidas aqui",
"parser.resource-location.tag-disallowed": "Tags não são permitidas aqui",
"parser.string.illegal-brigadier": "Encontrou não-[0-9A-Za-z_.+-] caracteres em %0%",
"parser.string.illegal-escape": "Caráter de escape inesperado %0%",
"parser.string.illegal-quote": "Apenas %0% pode ser usado para citar strings aqui",
Expand Down
2 changes: 1 addition & 1 deletion packages/locales/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"parser.record.value": "一个值",
"parser.resource-location.illegal": "无效字符:%0%",
"parser.resource-location.namespace-expected": "不可在此省略命名空间",
"parser.resource-location.tag-diallowed": "此处不允许使用标签",
"parser.resource-location.tag-disallowed": "此处不允许使用标签",
"parser.string.illegal-brigadier": "在 %0% 中遇到了非 [0-9A-Za-z_.+-] 字符",
"parser.string.illegal-escape": "预期外的转义字符 %0%",
"parser.string.illegal-quote": "此处只允许使用 %0% 包裹字符串",
Expand Down
2 changes: 1 addition & 1 deletion packages/locales/src/locales/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"parser.record.value": "一個值",
"parser.resource-location.illegal": "無效字元:%0%",
"parser.resource-location.namespace-expected": "不可在此省略命名空間",
"parser.resource-location.tag-diallowed": "此處不允許使用標籤",
"parser.resource-location.tag-disallowed": "此處不允許使用標籤",
"parser.string.illegal-brigadier": "在 %0% 中遇到了非 [0-9A-Za-z_.+-] 字元",
"parser.string.illegal-escape": "預期外的跳脫字元 %0%",
"parser.string.illegal-quote": "此處只允許使用 %0% 包裹字串",
Expand Down
16 changes: 9 additions & 7 deletions packages/mcdoc-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
{
"name": "@spyglassmc/mcdoc-cli",
"version": "0.1.1",
"version": "0.1.3",
"type": "module",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"contributors": [
{
"name": "Misode"
"name": "Misode",
"url": "https://github.com/misode"
},
{
"name": "MulverineX",
"url": "http://mulverine.dev"
"url": "https://mulverine.dev"
}
],
"license": "MIT",
"directories": {
"test": "test/"
},
"bin": {
"mcdoc": "./lib/index.js"
"mcdoc": "lib/index.js"
},
"scripts": {
"release": "npm publish",
"release:dry": "npm publish --dry-run",
"test": "rm -rf vanilla-mcdoc && rm -rf src/out && git clone https://github.com/SpyglassMC/vanilla-mcdoc && cd src && ./index.ts generate ../vanilla-mcdoc/ -p -m -l"
"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"
},
"dependencies": {
"fs-extra": "^11.1.1",
Expand All @@ -36,14 +37,15 @@
"@types/klaw": "^3.0.4",
"@types/line-column": "^1.0.0",
"@types/node": "18.11.17",
"@types/yargs": "17.0.17"
"@types/yargs": "17.0.17",
"typescript": "^5.4.5"
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/SpyglassMC/Spyglass.git"
"url": "git+https://github.com/SpyglassMC/Spyglass.git"
},
"homepage": "https://spyglassmc.com",
"bugs": {
Expand Down
66 changes: 41 additions & 25 deletions packages/mcdoc-cli/src/index.ts → packages/mcdoc-cli/src/index.mts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S ts-node --esm
#!/usr/bin/env -S tsx
import { dirname, join, parse, resolve } from 'path'
import { fileURLToPath, pathToFileURL } from 'url'

Expand All @@ -24,6 +24,11 @@ const cacheRoot = join(parentPath, 'cache')

const CLI = yargs(hideBin(process.argv))

function removeWindowsCruft(str: string) {
if (str.includes('\r')) return str.replaceAll('\r', '')
return str
}

await CLI.scriptName('mcdoc')
.command(
'generate [source]',
Expand Down Expand Up @@ -118,13 +123,16 @@ await CLI.scriptName('mcdoc')
await service.project.ready()
await service.project.cacheService.save()

const out = 'out'
const generated = join('out', 'generated')

if (args.dry !== true) {
await fs.ensureDir(out)
await fs.ensureDir(generated)

if (args.module) {
await fs.ensureDir(join(out, 'module'))
await fs.ensureDir(join(generated, 'module'))
}
if (args.locale) {
await fs.ensureDir(join('out', 'locale'))
}
}

Expand Down Expand Up @@ -176,7 +184,7 @@ await CLI.scriptName('mcdoc')
) {
const child: any = {}

let known_error = false
const known_error = false

/* @ts-ignore */
child.self = self
Expand Down Expand Up @@ -206,6 +214,13 @@ await CLI.scriptName('mcdoc')

child.type = _child.type

if (child.type === 'resource_location') {
/* @ts-ignore */
child.namespace = _child.namespace
/* @ts-ignore */
child.path = _child.path
}

if (Object.hasOwn(_child, 'isOptional')) {
/* @ts-ignore */
child.isOptional = _child.isOptional
Expand All @@ -224,9 +239,11 @@ await CLI.scriptName('mcdoc')
if (internal_locales[parent]) {
locales[
`mcdoc.${
resource.replace(/\//g, '.')
resource.replace(/[\/\\]/g, '.')
}.${child.value}`
] = internal_locales[parent].join('\n')
] = removeWindowsCruft(
internal_locales[parent].join('').trimEnd(),
)

delete internal_locales[parent]
}
Expand All @@ -237,15 +254,19 @@ await CLI.scriptName('mcdoc')
internal_locales[parent]
) {
locales[
`mcdoc.${resource.replace(/\//g, '.')}.map_key`
] = internal_locales[parent].join('\n')
`mcdoc.${
resource.replace(/[\/\\]/g, '.')
}.map_key`
] = removeWindowsCruft(
internal_locales[parent].join('').trimEnd(),
)

delete internal_locales[parent]
}

if (Object.hasOwn(_child, 'comment')) {
/* @ts-ignore */
const comment: string = _child.comment.trim()
const comment: string = _child.comment
child.comment = comment

if (
Expand All @@ -254,17 +275,11 @@ await CLI.scriptName('mcdoc')
) {
const key = parent.replace(/\[\d+\]$/, '')

if (!internal_locales.key) {
if (!internal_locales[key]) {
internal_locales[key] = []
}

internal_locales[key].push(comment)
} else if (comment.startsWith('/ ')) {
child.type = 'error'
console.warn(
`known error: orphaned dispatch comment`,
)
known_error = true
internal_locales[key].push(comment.slice(1))
}
}

Expand Down Expand Up @@ -343,19 +358,20 @@ await CLI.scriptName('mcdoc')
symbols.push(symbol)

if (!args.dry && args.module) {
const dir = parse(join(out, 'module', resource)).dir
const dir =
parse(join(generated, 'module', resource)).dir

if (dir !== '') await fs.ensureDir(dir)

await fs.writeFile(
join(out, 'module', `${resource}.mcdoc.json`),
join(generated, 'module', `${resource}.mcdoc.json`),
JSON.stringify(symbol),
)

if (args.pretty) {
await fs.writeFile(
join(
out,
generated,
'module',
`${resource}.pretty.mcdoc.json`,
),
Expand All @@ -370,20 +386,20 @@ await CLI.scriptName('mcdoc')

if (!args.dry) {
await fs.writeFile(
join(out, 'generated.mcdoc.json'),
join(generated, 'generated.mcdoc.json'),
JSON.stringify(symbols),
)

if (args.pretty) {
await fs.writeFile(
join(out, 'generated.pretty.mcdoc.json'),
join(generated, 'generated.pretty.mcdoc.json'),
JSON.stringify(symbols, undefined, 3),
)
}

if (args.module) {
await fs.writeFile(
join(out, 'module', 'index.json'),
join(generated, 'module', 'index.json'),
JSON.stringify(symbols.map(symbol => symbol.resource)),
)
}
Expand All @@ -397,7 +413,7 @@ await CLI.scriptName('mcdoc')
console.warn(internal_locales)
}
await fs.writeFile(
join(out, 'locale.en-us.json'),
join('out', 'locale', 'locale.en-us.json'),
JSON.stringify(locales, undefined, 3),
)
}
Expand Down
3 changes: 0 additions & 3 deletions packages/mcdoc-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
{
"path": "src"
},
{
"path": "test"
}
]
}
1 change: 1 addition & 0 deletions packages/mcdoc/src/type/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const StaticIndexKeywords = Object.freeze(
'fallback',
'none',
'unknown',
'spawnitem',
] as const,
)
export type StaticIndexKeyword = (typeof StaticIndexKeywords)[number]
Expand Down

0 comments on commit 25de684

Please sign in to comment.