|
| 1 | +import gulp from "gulp" |
| 2 | +import {spawn} from "node:child_process" |
| 3 | +import {readdir, rm} from "node:fs/promises" |
| 4 | +import {join} from "node:path" |
| 5 | + |
| 6 | +# Builds the project. |
| 7 | +export build = -> |
| 8 | + await npx "coffee", "--compile", "--no-header", "--output", "lib", "src" |
| 9 | + |
| 10 | +# Deletes all generated files. |
| 11 | +export clean = -> |
| 12 | + await rm "lib", force: yes, recursive: yes |
| 13 | + await rm join("var", file), recursive: yes for file from await readdir "var" when file isnt ".gitkeep" |
| 14 | + |
| 15 | +# Performs the static analysis of source code. |
| 16 | +export lint = -> |
| 17 | + await npx "coffeelint", "--file=etc/coffeelint.json", "gulpfile.coffee", "example", "src", "test" |
| 18 | + |
| 19 | +# Publishes the package. |
| 20 | +export publish = -> |
| 21 | + {default: {version}} = await import("./package.json", with: type: "json") |
| 22 | + await npx "gulp" |
| 23 | + await run "npm", "publish", "--registry=#{registry}" for registry from ["https://registry.npmjs.org", "https://npm.pkg.github.com"] |
| 24 | + await run "git", action..., "v#{version}" for action from [["tag"], ["push", "origin"]] |
| 25 | + |
| 26 | +# Runs the test suite. |
| 27 | +export test = -> |
| 28 | + await npx "coffee", "--compile", "--map", "--no-header", "--output", "lib", "src", "test" |
| 29 | + await run "node", "--enable-source-maps", "--test" |
| 30 | + |
| 31 | +# Watches for file changes. |
| 32 | +export watch = -> |
| 33 | + npx "coffee", "--compile", "--no-header", "--output", "lib", "--watch", "src", "test" |
| 34 | + |
| 35 | +# The default task. |
| 36 | +export default gulp.series clean, build |
| 37 | + |
| 38 | +# Executes a command from a local package. |
| 39 | +npx = (command, args...) -> run "npm", "exec", "--", command, args... |
| 40 | + |
| 41 | +# Spawns a new process using the specified command. |
| 42 | +run = (command, args...) -> new Promise (resolve, reject) -> |
| 43 | + process = spawn command, args, shell: on, stdio: "inherit" |
| 44 | + process.on "close", (code) -> if code then reject(Error [command, args...].join(" ")) else resolve() |
0 commit comments