Skip to content

Commit

Permalink
Speed up build by running steps in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
cowwoc committed Nov 30, 2023
1 parent c9d722c commit 37b2154
Showing 1 changed file with 97 additions and 85 deletions.
182 changes: 97 additions & 85 deletions build.mts
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,42 @@ class Build
public async lint()
{
log.info("lint()");
try
{
const eslint = new ESLint({
baseConfig: eslintConfig,
cache: true,
"overrideConfig": {
parserOptions: {
debugLevel: false
}
const eslint = new ESLint({
baseConfig: eslintConfig,
cache: true,
"overrideConfig": {
parserOptions: {
debugLevel: false
}
});
const results = await eslint.lintFiles(["src/**/*.mts"]);
const formatter = await eslint.loadFormatter("stylish");
const resultText = formatter.format(results);
console.log(resultText);

let buildFailed = false;
for (const result of results)
}
});
return async () =>
{
try
{
if (result.errorCount > 0)
const results = await eslint.lintFiles(["src/**/*.mts"]);
const formatter = await eslint.loadFormatter("stylish");
const resultText = formatter.format(results);
console.log(resultText);

let buildFailed = false;
for (const result of results)
{
buildFailed = true;
break;
if (result.errorCount > 0)
{
buildFailed = true;
break;
}
}
if (buildFailed)
process.exit(1);
}
if (buildFailed)
catch (error)
{
log.error(error);
process.exit(1);
}
catch (error)
{
log.error(error);
process.exit(1);
}
}
};
}

public async compileForNode()
Expand Down Expand Up @@ -142,29 +145,32 @@ class Build
(rollupCommonjs as unknown as Function)({include: "node_modules/**"})
];

const bundle = await rollup(
{
input: "src/index.mts",
plugins,
onwarn(warning, warn)
return async () =>
{
const bundle = await rollup(
{
// Ignore false alarm about circular dependencies involving internal.mts
const ignoredCircular = ["src/internal/internal.mts"];
const isCircularDependency = warning.code === "CIRCULAR_DEPENDENCY" &&
ignoredCircular.some(predicate =>
warning.message.replace(/\\/g, "/").includes(predicate));
if (isCircularDependency)
return;
warn(warning);
}
});
await bundle.write(
{
sourcemap: true,
dir: "target/publish/browser"
});
if (this.mode === "RELEASE")
await this.minifyBrowserSources();
input: "src/index.mts",
plugins,
onwarn(warning, warn)
{
// Ignore false alarm about circular dependencies involving internal.mts
const ignoredCircular = ["src/internal/internal.mts"];
const isCircularDependency = warning.code === "CIRCULAR_DEPENDENCY" &&
ignoredCircular.some(predicate =>
warning.message.replace(/\\/g, "/").includes(predicate));
if (isCircularDependency)
return;
warn(warning);
}
});
await bundle.write(
{
sourcemap: true,
dir: "target/publish/browser"
});
if (this.mode === "RELEASE")
await this.minifyBrowserSources();
};
}

/**
Expand All @@ -182,52 +188,58 @@ class Build
const pathToCode: { [name: string]: string } = {};
for (const file of sourceFiles)
pathToCode[file] = fs.readFileSync(file, "utf8");
const {
code,
map
} = await minify(pathToCode, {
ecma: 2020,
compress:
{
/* eslint-disable camelcase */
drop_console: true,
global_defs:
{
"@alert": "console.log"
}
/* eslint-enable camelcase */
},
sourceMap: {
filename: "index.min.mjs.map"
return async () =>
{
const {
code,
map
} = await minify(pathToCode, {
ecma: 2020,
compress:
{
/* eslint-disable camelcase */
drop_console: true,
global_defs:
{
"@alert": "console.log"
}
/* eslint-enable camelcase */
},
sourceMap: {
filename: "index.min.mjs.map"
}
}
}
);
assert(typeof (code) === "string");
assert(typeof (map) === "string");
);
assert(typeof (code) === "string");
assert(typeof (map) === "string");

fs.writeFileSync(targetDirectory + "index.min.mjs", code);
fs.writeFileSync(targetDirectory + "index.min.mjs.map", map);
fs.writeFileSync(targetDirectory + "index.min.mjs", code);
fs.writeFileSync(targetDirectory + "index.min.mjs.map", map);
};
}

public async generateDocumentation()
{
log.info("generateDocumentation()");
const targetDirectory = "target/apidocs/";

const app = await TypeDoc.Application.bootstrapWithPlugins({}, [
new TypeDoc.TypeDocReader(),
new TypeDoc.TSConfigReader()
]);
return async () =>
{
const app = await TypeDoc.Application.bootstrapWithPlugins({}, [
new TypeDoc.TypeDocReader(),
new TypeDoc.TSConfigReader()
]);

const project = await app.convert();
if (!project)
process.exit(1);
app.validate(project);
if (app.logger.hasErrors())
process.exit(1);
await app.generateDocs(project, targetDirectory);
if (app.logger.hasErrors())
process.exit(1);
const project = await app.convert();
if (!project)
process.exit(1);
app.validate(project);
if (app.logger.hasErrors())
process.exit(1);
await app.generateDocs(project, targetDirectory);
if (app.logger.hasErrors())
process.exit(1);
};
}

public async copyResources()
Expand Down

0 comments on commit 37b2154

Please sign in to comment.