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