From f975b7b61abc2ee62045e47d5c94f1fecb209d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Belin?= Date: Wed, 13 Nov 2024 11:39:04 +0100 Subject: [PATCH] Restore the Gulp build system --- Cakefile | 1 - gulpfile.coffee | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/cakefile.coffee | 47 --------------------------------------------- 3 files changed, 46 insertions(+), 48 deletions(-) delete mode 120000 Cakefile create mode 100644 gulpfile.coffee delete mode 100644 src/cakefile.coffee diff --git a/Cakefile b/Cakefile deleted file mode 120000 index d26489a..0000000 --- a/Cakefile +++ /dev/null @@ -1 +0,0 @@ -./src/cakefile.coffee \ No newline at end of file diff --git a/gulpfile.coffee b/gulpfile.coffee new file mode 100644 index 0000000..d390957 --- /dev/null +++ b/gulpfile.coffee @@ -0,0 +1,46 @@ +import gulp from "gulp" +import {spawn} from "node:child_process" +import {readdir, rm} from "node:fs/promises" +import {join} from "node:path" +import {env} from "node:process" + +# Builds the project. +export build = -> + await npx "coffee", "--compile", "--no-header", "--output", "lib", "src" + +# Deletes all generated files. +export clean = -> + await rm join("lib", file) for file from await readdir "lib" when not file.endsWith ".d.ts" + await rm join("var", file), recursive: yes for file from await readdir "var" when file isnt ".gitkeep" + +# Performs the static analysis of source code. +export lint = -> + await npx "coffeelint", "--file=etc/coffeelint.json", "example", "src", "test" + +# Publishes the package. +export publish = -> + {default: {version}} = await import("./package.json", with: {type: "json"}) + await run "gulp" + await run "npm", "publish", "--registry=#{registry}" for registry from ["https://registry.npmjs.org", "https://npm.pkg.github.com"] + await run "git", action..., "v#{version}" for action from [["tag"], ["push", "origin"]] + +# Runs the test suite. +export test = -> + env.NODE_ENV = "test" + await npx "coffee", "--compile", "--map", "--no-header", "--output", "lib", "src", "test" + await run "node", "--enable-source-maps", "--test", "--test-reporter=spec", "lib/**/*_test.js" + +# Watches for file changes. +export watch = -> + await npx "coffee", "--compile", "--no-header", "--output", "lib", "--watch", "src", "test" + +# The default task. +export default gulp.series clean, build + +# Executes a command from a local package. +npx = (command, args...) -> run "npm", "exec", "--", command, ...args + +# Spawns a new process using the specified command. +run = (command, args...) -> new Promise (resolve, reject) -> + spawn command, args, shell: on, stdio: "inherit" + .on "close", (code) -> if code then reject(Error [command, args...].join(" ")) else resolve() diff --git a/src/cakefile.coffee b/src/cakefile.coffee deleted file mode 100644 index 9e5c18a..0000000 --- a/src/cakefile.coffee +++ /dev/null @@ -1,47 +0,0 @@ -{spawnSync} = require "node:child_process" -console = require "node:console" -{readdirSync, rmSync} = require "node:fs" -{join} = require "node:path" -{env, exit} = require "node:process" -pkg = require "../package.json" - -option "-m", "--map", "Whether to generate source maps." - -task "build", "Builds the project.", (options) -> - sourcemaps = if options.map then ["--map"] else [] - run "coffee", "--compile", sourcemaps..., "--no-header", "--output", "lib", "src" - -task "clean", "Deletes all generated files.", -> - rmSync join("lib", file) for file from readdirSync "lib" when not file.endsWith ".d.ts" - rmSync join("var", file), recursive: yes for file from readdirSync "var" when file isnt ".gitkeep" - -task "dist", "Packages the project.", -> - invoke script for script from ["clean", "build"] - rmSync "lib/cakefile.js" - -task "lint", "Performs the static analysis of source code.", -> - npx "coffeelint", "--file=etc/coffeelint.json", "example", "src", "test" - -task "publish", "Publishes the package.", -> - invoke "dist" - run "npm", "publish", "--registry=#{registry}" for registry from ["https://registry.npmjs.org", "https://npm.pkg.github.com"] - run "git", action..., "v#{pkg.version}" for action from [["tag"], ["push", "origin"]] - -task "test", "Runs the test suite.", -> - env.NODE_ENV = "test" - run "coffee", "--compile", "--map", "--no-header", "--output", "lib", "src", "test" - run "node", "--enable-source-maps", "--test", "--test-reporter=spec", "lib/**/*_test.js" - -task "watch", "Watches for file changes.", (options) -> - sourcemaps = if options.map then ["--map"] else [] - run "coffee", "--compile", sourcemaps..., "--no-header", "--output", "lib", "--watch", "src", "test" - -# Executes a command from a local package. -npx = (command, args...) -> run "npm", "exec", "--", command, args... - -# Spawns a new process using the specified command. -run = (command, args...) -> - {status} = spawnSync command, args, shell: on, stdio: "inherit" - unless status is 0 - console.error "Command failed:", command, args... - exit status