UNPKG

stackpress

Version:

Incept is a content management framework.

28 lines (27 loc) 1.15 kB
import path from 'node:path'; import { action } from '@stackpress/ingest/Server'; import buildScript from '../../scripts/build.js'; export default action(async function BuildScript(_req, res, ctx) { const cli = ctx.plugin('cli'); const cwd = ctx.config.path('server.cwd', process.cwd()); const build = ctx.config.path('server.build', path.join(cwd, '.build')); await buildScript(ctx, cli); cli?.verbose && cli.control.system('Making package.json...'); buildPackageJSON(cwd, build, ctx.loader.fs); cli?.verbose && cli.control.success('Build Complete.'); res.setStatus(200); }); export async function buildPackageJSON(cwd, build, fs) { const source = path.join(cwd, 'package.json'); const destination = path.join(build, 'package.json'); const contents = await 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' }; await fs.writeFile(destination, JSON.stringify(settings, null, 2)); } ;