|
| 1 | +{spawnSync} = require "node:child_process" |
| 2 | +{readdirSync, rmSync} = require "node:fs" |
| 3 | +{join} = require "node:path" |
| 4 | +{env} = require "node:process" |
| 5 | +pkg = require "./package.json" |
| 6 | + |
| 7 | +option "-m", "--map", "Whether to generate source maps." |
| 8 | + |
| 9 | +task "build", "Builds the project.", (options) -> |
| 10 | + sourcemaps = if options.map then ["--map"] else [] |
| 11 | + run "coffee", "--compile", sourcemaps..., "--no-header", "--output", "lib", "src" |
| 12 | + |
| 13 | +task "clean", "Deletes all generated files.", -> |
| 14 | + rmSync join("lib", file) for file in readdirSync "lib" when not file.endsWith ".d.ts" |
| 15 | + rmSync join("var", file), recursive: yes for file in readdirSync "var" when file isnt ".gitkeep" |
| 16 | + |
| 17 | +task "dist", "Packages the project.", -> |
| 18 | + invoke "clean" |
| 19 | + invoke "build" |
| 20 | + |
| 21 | +task "lint", "Performs the static analysis of source code.", -> |
| 22 | + npx "coffeelint", "--file=etc/coffeelint.json", "Cakefile", "example", "src", "test" |
| 23 | + |
| 24 | +task "publish", "Publishes the package.", -> |
| 25 | + invoke "dist" |
| 26 | + run "npm", "publish", "--registry=#{registry}" for registry in ["https://registry.npmjs.org", "https://npm.pkg.github.com"] |
| 27 | + run "git", action..., "v#{pkg.version}" for action in [["tag"], ["push", "origin"]] |
| 28 | + |
| 29 | +task "test", "Runs the test suite.", -> |
| 30 | + env.NODE_ENV = "test" |
| 31 | + run "coffee", "--compile", "--map", "--no-header", "--output", "lib", "src", "test" |
| 32 | + run "node", "--enable-source-maps", "--test", "--test-reporter=spec", "lib/**/*_test.js" |
| 33 | + |
| 34 | +task "watch", "Watches for file changes.", (options) -> |
| 35 | + sourcemaps = if options.map then ["--map"] else [] |
| 36 | + run "coffee", "--compile", sourcemaps..., "--no-header", "--output", "lib", "--watch", "src", "test" |
| 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...) -> |
| 43 | + {status} = spawnSync command, args, shell: yes, stdio: "inherit" |
| 44 | + if status isnt 0 |
| 45 | + console.error "Command failed:", command, args... |
| 46 | + process.exit status |
0 commit comments