-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add mojmap option to mod generator * add generator test --------- Co-authored-by: modmuss <[email protected]>
- Loading branch information
Showing
8 changed files
with
140 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"remoteUser": "node", | ||
"build": { "dockerfile": "../Dockerfile" }, | ||
"forwardPorts": [ | ||
4000, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Generator Test | ||
on: | ||
- workflow_dispatch | ||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: devcontainers/[email protected] | ||
with: | ||
runCmd: | | ||
cd cli | ||
make run test | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
path: | ||
cli/tests/1.*/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ | |
!Makefile | ||
!bundle.ts | ||
!fontgen.ts | ||
!test.ts | ||
!utils.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
Input, | ||
Select, | ||
} from "https://deno.land/x/[email protected]/prompt/mod.ts"; | ||
import { parse as parseXml } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { colors } from "https://deno.land/x/[email protected]/ansi/mod.ts"; | ||
import * as utils from "../utils.ts"; | ||
|
@@ -81,27 +82,21 @@ export function initCommand() { | |
}); | ||
} | ||
|
||
async function generate( | ||
cli: CliOptions, | ||
outputDirName: string | undefined, | ||
) { | ||
const outputDir = await getAndPrepareOutputDir(outputDirName); | ||
// Set the XML parser as we do not have DomParser here. | ||
generator.setXmlVersionParser((xml) => { | ||
const document = parseXml(xml) as any; | ||
return document.metadata.versioning.versions.version; | ||
}); | ||
|
||
const isTargetEmpty = await utils.isDirEmpty(outputDir); | ||
if (!isTargetEmpty) { | ||
fatalError("The target directory must be empty"); | ||
} | ||
const fontLoader = pureimage.registerFont("", generator.ICON_FONT); | ||
fontLoader.font = opentype.parse(decodeBase64(fontData).buffer); | ||
fontLoader.loaded = true; | ||
|
||
const config = | ||
await (cli.defaultOptions | ||
? defaultOptions(path.basename(outputDir)) | ||
: promptUser(path.basename(outputDir), cli)); | ||
|
||
const fontLoader = pureimage.registerFont("", generator.ICON_FONT); | ||
fontLoader.font = opentype.parse(decodeBase64(fontData).buffer); | ||
fontLoader.loaded = true; | ||
|
||
const options: generator.Options = { | ||
export function getGeneratorOptions( | ||
outputDir: string, | ||
config: generator.Configuration, | ||
): generator.Options { | ||
return { | ||
config, | ||
writer: { | ||
write: async (contentPath, content, options) => { | ||
|
@@ -142,10 +137,27 @@ async function generate( | |
}, | ||
}, | ||
}; | ||
} | ||
|
||
async function generate( | ||
cli: CliOptions, | ||
outputDirName: string | undefined, | ||
) { | ||
const outputDir = await getAndPrepareOutputDir(outputDirName); | ||
|
||
const isTargetEmpty = await utils.isDirEmpty(outputDir); | ||
if (!isTargetEmpty) { | ||
fatalError("The target directory must be empty"); | ||
} | ||
|
||
const config = | ||
await (cli.defaultOptions | ||
? defaultOptions(path.basename(outputDir)) | ||
: promptUser(path.basename(outputDir), cli)); | ||
|
||
console.log(progress("Generating mod template...")); | ||
|
||
await generator.generateTemplate(options); | ||
await generator.generateTemplate(getGeneratorOptions(outputDir, config)); | ||
console.log(success("Done!")); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
// @deno-types="../scripts/dist/fabric-template-generator.d.ts" | ||
import * as generator from "../scripts/dist/fabric-template-generator.js"; | ||
import { parse as parseXml } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { | ||
Command, | ||
CompletionsCommand, | ||
|
@@ -14,12 +13,6 @@ import { upgradeCommand } from "./commands/upgrade.ts"; | |
declare let __VERSION__: string; | ||
const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "dev"; | ||
|
||
// Set the XML parser as we do not have DomParser here. | ||
generator.setXmlVersionParser((xml) => { | ||
const document = parseXml(xml) as any; | ||
return document.metadata.versioning.versions.version; | ||
}); | ||
|
||
if (import.meta.main) { | ||
const cmd = new Command() | ||
.name("Fabric CLI tools") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// @deno-types="../scripts/dist/fabric-template-generator.d.ts" | ||
import { | ||
generateTemplate, | ||
getTemplateGameVersions, | ||
} from "../scripts/dist/fabric-template-generator.js"; | ||
import { getGeneratorOptions } from "./commands/init.ts"; | ||
import { assert } from "https://deno.land/[email protected]/assert/mod.ts"; | ||
import * as fs from "https://deno.land/[email protected]/fs/mod.ts"; | ||
|
||
const rootDir = "./tests"; | ||
if (await fs.exists(rootDir)) { | ||
await Deno.remove(rootDir, { recursive: true }); | ||
} | ||
await Deno.mkdir(rootDir); | ||
|
||
const cwd = await Deno.realPath(Deno.cwd()); | ||
const inDir = `${rootDir}/_in`; | ||
const runDir = `${rootDir}/_run`; | ||
await Deno.mkdir(runDir); | ||
|
||
const minecraftVersions = await getTemplateGameVersions(); | ||
|
||
for (const { version } of minecraftVersions) { | ||
for (const mapping of ["yarn", "mojmap"]) { | ||
for (const language of ["java", "kotlin"]) { | ||
const testId = `${version}_${mapping}_${language}`; | ||
const outDir = `${rootDir}/${testId}`; | ||
|
||
Deno.test(testId, async () => { | ||
let success = false; | ||
|
||
// try rebuilding if it fail, usual gradle stuff | ||
for (let i = 0; i < 3; i++) { | ||
const options = getGeneratorOptions(inDir, { | ||
modid: "test", | ||
projectName: "test", | ||
packageName: "net.fabricmc.generator.test", | ||
dataGeneration: false, | ||
splitSources: true, | ||
uniqueModIcon: true, | ||
|
||
minecraftVersion: version, | ||
mojmap: mapping === "mojmap", | ||
useKotlin: language === "kotlin", | ||
}); | ||
|
||
await generateTemplate(options); | ||
|
||
// build in the same directory for all test | ||
// to make it use only one daemon and build cache | ||
for await (const { name } of Deno.readDir(inDir)) { | ||
await fs.copy(`${inDir}/${name}`, `${runDir}/${name}`); | ||
} | ||
|
||
Deno.chdir(runDir); | ||
const gradle = new Deno.Command("./gradlew", { | ||
args: ["build"], | ||
}).spawn(); | ||
Deno.chdir(cwd); | ||
|
||
const output = await gradle.output(); | ||
|
||
for await (const { name } of Deno.readDir(inDir)) { | ||
await Deno.remove(`${runDir}/${name}`, { recursive: true }); | ||
} | ||
|
||
await Deno.remove(inDir, { recursive: true }); | ||
|
||
if (output.success) { | ||
await fs.move(`${runDir}/build/libs`, `${outDir}`); | ||
success = true; | ||
break; | ||
} | ||
} | ||
|
||
assert(success); | ||
}); | ||
} | ||
} | ||
} |