UNPKG

@plugjs/build

Version:

Simple shared build using PlugJS

67 lines (66 loc) 2.46 kB
// bootstrapper.ts import { find, fs, isFile, log, plugjs, resolve } from "@plugjs/plug"; import { $p } from "@plugjs/plug/logging"; function sortByKey(unsorted) { return Object.keys(unsorted).sort().reduce((obj, key) => { obj[key] = unsorted[key]; return obj; }, {}); } var tasks = plugjs({ overwrite: "skip", /** Copy all resources from the `resources/` directory into the target */ async resources() { const pipe = find("**/*", "**/.*", { directory: "@../resources" }); const sources = await pipe; const targets = await pipe.copy(".", { // it seems NPM has _some_ problems with some dotfiles (e.g. .gitignore) rename: (relative) => relative.replaceAll(/(^|\/)__dot_/g, "$1."), overwrite: this.overwrite }); log("Bootstrapped", targets.length, "of", sources.length, "files:"); for (const file of targets.absolutePaths()) log(` ${$p(file)}`); }, /** Setup dependencies and build script into target `package.json` */ async packages() { const buildPackage = resolve("@../package.json"); log(`Reading ${$p(buildPackage)}`); const buildData = await fs.readFile(buildPackage, "utf-8"); const buildJson = JSON.parse(buildData); const targetJson = {}; const targetPackage = resolve("./package.json"); if (isFile(targetPackage)) { log(`Reading ${$p(targetPackage)}`); const targetData = await fs.readFile(targetPackage, "utf-8"); Object.assign(targetJson, JSON.parse(targetData)); } log(`Updating ${$p(targetPackage)}`); targetJson.scripts = sortByKey({ build: "plug", coverage: "plug coverage", dev: "plug coverage -w src -w test", lint: "plug lint", test: "plug test", transpile: "plug transpile", ...targetJson.scripts }); const targetFiles = /* @__PURE__ */ new Set([...targetJson.files || [], "*.md", "dist/", "src/"]); targetJson.files = [...targetFiles].sort(); targetJson.devDependencies = sortByKey({ ...targetJson.devDependencies, [buildJson.name]: `^${buildJson.version}` }); log(`Writing ${$p(targetPackage)}`); await fs.writeFile(targetPackage, JSON.stringify(targetJson, null, 2) + "\n", "utf-8"); }, /** Bootstrap the project */ async bootstrap() { log(`Boostrapping PlugJS Build from ${$p(resolve("@"))}`); await this.resources(); await this.packages(); } }); export { tasks }; //# sourceMappingURL=bootstrapper.mjs.map