0.13.0 • Published 12 months ago

@ninjutsu-build/node v0.13.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Node - Ninjutsu Build

A package to create a ninjutsu-build rule for running JavaScript files within node.

Prerequisites

This project requires NodeJS (version 18.18.0 or later for --import support) and npm.

Installation

Most likely you require both @ninjutsu-build/node and @ninjutsu-build/code as a devDependency, which can be achieved by running the following npm command:

$ npm install @ninjutsu-build/core @ninjutsu-build/node --save-dev

Basic Example

Given the following simple JavaScript file that prints out numbers 1 to N,

// count.js
const process = require('node:process');

const limit = parseInt(process.argv[2]);
for (let i = 1; i < limit; ++i) {
  console.log(i);
}

We can build a build.ninja file that will invoke count.js and save the output,

import { NinjaBuilder, [implicitDeps] } from "@ninjutsu-build/core";
import { makeNodeRule } from "@ninjutsu-build/node";
import { writeFileSync } from "fs";

// Create a `NinjaBuilder`
const ninja = new NinjaBuilder({
  ninja_required_version: "1.1",
  builddir: ".mybuilddir",
});

// Create a `runJS` ninja rule
const node = makeNodeRule(ninja, "runJS");

// Run `src/count.js` and save to `$builddir/output.txt`.
// Pass the `.package-lock.json` file as an implicit dependency
// so that installing or changing dependencies will cause ninja
// to regenerate `output.txt`.
const output = node({
  in: "src/count.js",
  out: "$builddir/output.txt",
  args: 10, // pass `10` to `count.js`
  [implicitDeps]: ["src/node_modules/.package-lock.json"],
});

// Write the ninja file to disk
writeFileSync("build.ninja", ninja.output);
0.12.0

1 year ago

0.13.0

12 months ago

0.12.1

1 year ago

0.10.0

1 year ago

0.11.0

1 year ago

0.9.5

1 year ago

0.9.4

1 year ago

0.9.3

1 year ago

0.9.2

1 year ago

0.9.1

1 year ago

0.9.0

1 year ago

0.8.2

1 year ago

0.8.1

1 year ago

0.8.0

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago