Skip to content

Commit

Permalink
Port the build system to Gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Mar 30, 2024
1 parent f4bff18 commit df099a0
Show file tree
Hide file tree
Showing 11 changed files with 1,774 additions and 84 deletions.
80 changes: 40 additions & 40 deletions bin/setup_hashlink.cjs

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions etc/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {env} from "node:process";

/**
* Returns the build options of the client application.
* @returns {import("esbuild").BuildOptions} Thebuild options of the client application.
*/
export default function buildOptions() {
const production = env.NODE_ENV == "production";
return {
banner: {js: "#!/usr/bin/env node"},
bundle: true,
conditions: production ? [] : ["development"],
drop: production ? ["debugger"] : [],
entryPoints: ["src/cli.ts"],
legalComments: "none",
minify: production,
outfile: "bin/setup_hashlink.cjs",
platform: "node",
sourceRoot: new URL("../bin/", import.meta.url).href,
sourcemap: !production,
treeShaking: production
};
}
3 changes: 2 additions & 1 deletion etc/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ export default tsEslint.config(
}
},
{
files: ["test/**/*.js"],
files: ["gulpfile.js", "etc/*.js", "test/**/*.js"],
rules: {
"prefer-arrow-callback": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-floating-promises": "off"
Expand Down
75 changes: 75 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {cp} from "node:fs/promises";
import {env} from "node:process";
import {deleteAsync} from "del";
import esbuild from "esbuild";
import {$} from "execa";
import gulp from "gulp";
import replace from "gulp-replace";
import pkg from "./package.json" with {type: "json"};
import buildOptions from "./etc/esbuild.js";

// Builds the project.
export async function build() {
await $`tsc --project src`;
return esbuild.build(buildOptions());
}

// Deletes all generated files.
export function clean() {
return deleteAsync(["bin/*.map", "lib", "var/**/*"]);
}

// Packages the application.
export async function dist() {
env.NODE_ENV = "production";
await build();
return $`git update-index --chmod=+x bin/setup_hashlink.cjs`;
}

// Builds the documentation.
export async function doc() {
await build();
await $`typedoc --options etc/typedoc.js`;
for (const file of ["CHANGELOG.md", "LICENSE.md"]) await cp(file, `docs/${file.toLowerCase()}`);
return cp("docs/favicon.ico", "docs/api/favicon.ico");
}

// Performs the static analysis of source code.
export async function lint() {
await build();
await $`tsc --project .`;
return $`eslint --config=etc/eslint.config.js gulpfile.js etc src test`;
}

// Publishes the package.
export async function publish() {
for (const action of [["tag"], ["push", "origin"]]) await $`git ${action} v${pkg.version}`;
}

// Runs the test suite.
export async function test() {
await build();
return $`node --test --test-reporter=spec`;
}

// Updates the version number in the sources.
export function version() {
return gulp.src("README.md")
.pipe(replace(/action\/v\d+(\.\d+){2}/, `action/v${pkg.version}`))
.pipe(gulp.dest("."));
}

// Watches for file changes.
export async function watch() {
const context = await esbuild.context(buildOptions());
gulp.watch("src/**/*.ts", {ignoreInitial: false}, function buildCli() {
return context.rebuild();
});
}

// The default task.
export default gulp.series(
clean,
dist,
version
);
Loading

0 comments on commit df099a0

Please sign in to comment.