UNPKG

@plugjs/build

Version:

Simple shared build using PlugJS

92 lines (90 loc) 3.84 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // bootstrapper.ts var bootstrapper_exports = {}; __export(bootstrapper_exports, { tasks: () => tasks }); module.exports = __toCommonJS(bootstrapper_exports); var import_plug = require("@plugjs/plug"); var import_logging = require("@plugjs/plug/logging"); function sortByKey(unsorted) { return Object.keys(unsorted).sort().reduce((obj, key) => { obj[key] = unsorted[key]; return obj; }, {}); } var tasks = (0, import_plug.plugjs)({ overwrite: "skip", /** Copy all resources from the `resources/` directory into the target */ async resources() { const pipe = (0, import_plug.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 }); (0, import_plug.log)("Bootstrapped", targets.length, "of", sources.length, "files:"); for (const file of targets.absolutePaths()) (0, import_plug.log)(` ${(0, import_logging.$p)(file)}`); }, /** Setup dependencies and build script into target `package.json` */ async packages() { const buildPackage = (0, import_plug.resolve)("@../package.json"); (0, import_plug.log)(`Reading ${(0, import_logging.$p)(buildPackage)}`); const buildData = await import_plug.fs.readFile(buildPackage, "utf-8"); const buildJson = JSON.parse(buildData); const targetJson = {}; const targetPackage = (0, import_plug.resolve)("./package.json"); if ((0, import_plug.isFile)(targetPackage)) { (0, import_plug.log)(`Reading ${(0, import_logging.$p)(targetPackage)}`); const targetData = await import_plug.fs.readFile(targetPackage, "utf-8"); Object.assign(targetJson, JSON.parse(targetData)); } (0, import_plug.log)(`Updating ${(0, import_logging.$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}` }); (0, import_plug.log)(`Writing ${(0, import_logging.$p)(targetPackage)}`); await import_plug.fs.writeFile(targetPackage, JSON.stringify(targetJson, null, 2) + "\n", "utf-8"); }, /** Bootstrap the project */ async bootstrap() { (0, import_plug.log)(`Boostrapping PlugJS Build from ${(0, import_logging.$p)((0, import_plug.resolve)("@"))}`); await this.resources(); await this.packages(); } }); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { tasks }); //# sourceMappingURL=bootstrapper.cjs.map