Skip to content

Commit

Permalink
updates cbt
Browse files Browse the repository at this point in the history
  • Loading branch information
harryob committed Apr 8, 2024
1 parent fb6bf1f commit 2dbc787
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 38 deletions.
33 changes: 20 additions & 13 deletions tools/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,30 @@ export const YarnTarget = new Juke.Target({
export const TgFontTarget = new Juke.Target({
dependsOn: [YarnTarget],
inputs: [
'tgui/.yarn/install-target',
'tgui/packages/tgfont/**/*.+(js|cjs|svg)',
'tgui/packages/tgfont/package.json',
"tgui/.yarn/install-target",
"tgui/packages/tgfont/**/*.+(js|cjs|svg)",
"tgui/packages/tgfont/package.json",
],
outputs: [
'tgui/packages/tgfont/dist/tgfont.css',
'tgui/packages/tgfont/dist/tgfont.eot',
'tgui/packages/tgfont/dist/tgfont.woff2',
"tgui/packages/tgfont/dist/tgfont.css",
"tgui/packages/tgfont/dist/tgfont.eot",
"tgui/packages/tgfont/dist/tgfont.woff2",
],
executes: async () => {
await yarn('tgfont:build');
fs.copyFileSync('tgui/packages/tgfont/dist/tgfont.css', 'tgui/packages/tgfont/static/tgfont.css');
fs.copyFileSync('tgui/packages/tgfont/dist/tgfont.eot', 'tgui/packages/tgfont/static/tgfont.eot');
fs.copyFileSync('tgui/packages/tgfont/dist/tgfont.woff2', 'tgui/packages/tgfont/static/tgfont.woff2');
}
await yarn("tgfont:build");
fs.copyFileSync(
"tgui/packages/tgfont/dist/tgfont.css",
"tgui/packages/tgfont/static/tgfont.css"
);
fs.copyFileSync(
"tgui/packages/tgfont/dist/tgfont.eot",
"tgui/packages/tgfont/static/tgfont.eot"
);
fs.copyFileSync(
"tgui/packages/tgfont/dist/tgfont.woff2",
"tgui/packages/tgfont/static/tgfont.woff2"
);
},
});

export const TguiTarget = new Juke.Target({
Expand Down Expand Up @@ -303,8 +312,6 @@ export const CleanTarget = new Juke.Target({
dependsOn: [TguiCleanTarget],
executes: async () => {
Juke.rm("*.{dmb,rsc}");
Juke.rm("*.mdme*");
Juke.rm("*.m.*");
Juke.rm("maps/templates.dm");
},
});
Expand Down
68 changes: 43 additions & 25 deletions tools/build/lib/byond.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,47 @@ export const DreamMaker = async (dmeFile, options = {}) => {
throw err;
}
};
testOutputFile(`${dmeBaseName}.dmb`);
testOutputFile(`${dmeBaseName}.rsc`);
const runWithWarningChecks = async (dmeFile, args) => {
const execReturn = await Juke.exec(dmeFile, args);

const testDmVersion = async (dmPath) => {
const execReturn = await Juke.exec(dmPath, [], {
silent: true,
throw: false,
});
const version = execReturn.combined.match(
`DM compiler version (\\d+)\\.(\\d+)`
);
if (version == null) {
Juke.logger.error(
`Unexpected DreamMaker return, ensure "${dmPath}" is correct DM path.`
);
throw new Juke.ExitCode(1);
}
const requiredMajorVersion = 515;
const requiredMinorVersion = 1597; // First with -D switch functionality
const major = Number(version[1]);
const minor = Number(version[2]);
if (
options.warningsAsErrors &&
execReturn.combined.match(/\d+:warning: /)
major < requiredMajorVersion ||
(major == requiredMajorVersion && minor < requiredMinorVersion)
) {
Juke.logger.error(
`${requiredMajorVersion}.${requiredMinorVersion} DM version required`
);
throw new Juke.ExitCode(1);
}
};

await testDmVersion(dmPath);
testOutputFile(`${dmeBaseName}.dmb`);
testOutputFile(`${dmeBaseName}.rsc`);
const runWithWarningChecks = async (dmPath, args) => {
const execReturn = await Juke.exec(dmPath, args);
const ignoredWarningCodes = options.ignoreWarningCodes ?? [];
const reg =
ignoredWarningCodes.length > 0
? new RegExp(`\d+:warning: (?!(${ignoredWarningCodes.join("|")}))`)
: /\d+:warning: /;
if (options.warningsAsErrors && execReturn.combined.match(reg)) {
Juke.logger.error(`Compile warnings treated as errors`);
throw new Juke.ExitCode(2);
}
Expand All @@ -156,26 +189,11 @@ export const DreamMaker = async (dmeFile, options = {}) => {
const { defines } = options;
if (defines && defines.length > 0) {
Juke.logger.info("Using defines:", defines.join(", "));
try {
const injectedContent = defines.map((x) => `#define ${x}\n`).join("");
fs.writeFileSync(`${dmeBaseName}.m.dme`, injectedContent);
const dmeContent = fs.readFileSync(`${dmeBaseName}.dme`);
fs.appendFileSync(`${dmeBaseName}.m.dme`, dmeContent);
await runWithWarningChecks(dmPath, [`${dmeBaseName}.m.dme`]);
fs.writeFileSync(
`${dmeBaseName}.dmb`,
fs.readFileSync(`${dmeBaseName}.m.dmb`)
);
fs.writeFileSync(
`${dmeBaseName}.rsc`,
fs.readFileSync(`${dmeBaseName}.m.rsc`)
);
} finally {
Juke.rm(`${dmeBaseName}.m.*`);
}
} else {
await runWithWarningChecks(dmPath, [dmeFile]);
}
await runWithWarningChecks(dmPath, [
...defines.map((def) => `-D${def}`),
dmeFile,
]);
};

/**
Expand Down

0 comments on commit 2dbc787

Please sign in to comment.