UNPKG

stackpress

Version:

Incept is a content management framework.

47 lines (46 loc) 2.5 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildPackageJSON = buildPackageJSON; const node_path_1 = __importDefault(require("node:path")); const Server_1 = require("@stackpress/ingest/Server"); const build_js_1 = __importDefault(require("../../scripts/build.js")); exports.default = (0, Server_1.action)(function BuildScript(_req, res, ctx) { return __awaiter(this, void 0, void 0, function* () { const cli = ctx.plugin('cli'); const cwd = ctx.config.path('server.cwd', process.cwd()); const build = ctx.config.path('server.build', node_path_1.default.join(cwd, '.build')); yield (0, build_js_1.default)(ctx, cli); (cli === null || cli === void 0 ? void 0 : cli.verbose) && cli.control.system('Making package.json...'); buildPackageJSON(cwd, build, ctx.loader.fs); (cli === null || cli === void 0 ? void 0 : cli.verbose) && cli.control.success('Build Complete.'); res.setStatus(200); }); }); function buildPackageJSON(cwd, build, fs) { return __awaiter(this, void 0, void 0, function* () { const source = node_path_1.default.join(cwd, 'package.json'); const destination = node_path_1.default.join(build, 'package.json'); const contents = yield fs.readFile(source, 'utf8'); const settings = JSON.parse(contents); delete settings.devDependencies; settings.scripts = { generate: 'node scripts/generate.js', start: 'node scripts/serve.js', postinstall: 'node scripts/generate.js' }; yield fs.writeFile(destination, JSON.stringify(settings, null, 2)); }); } ;