@soleil-se/build-app
Version:
Script for building WebApps, RESTApps and Widgets with Svelte in Sitevision.
125 lines (114 loc) • 4.15 kB
JavaScript
import fse from 'fs-extra';
import args from '@soleil-se/build-utils/args';
import runTasks from '@soleil-se/build-utils/runTasks';
import task from '@soleil-se/build-utils/task';
import watch from '@soleil-se/build-utils/watch';
import { logError, logStartup, logEnviroment, logTimestamp } from '@soleil-se/build-utils/log';
import createChecksumChecker from '@soleil-se/build-utils/createChecksumChecker';
import { env, rollup } from '@soleil-se/build-config';
import { readManifest } from './manifest.js';
import { clean, copy, files, zip, eslint } from './utils/index.js';
import { client, server } from './rollup/index.js';
import { activate, upload, sign } from './requests/index.js';
import config from './config/index.js';
function getWatchOptions() {
const appendPath = args['append-watch-path'];
const defaultIgnored = ['dist', 'node_modules', '*.md', '.*', 'package-lock.json', 'yarn.lock', '*config*.*'];
const ignored = appendPath
? defaultIgnored.map((ignore) => `${appendPath}/${ignore}`).concat(defaultIgnored)
: defaultIgnored;
const paths = appendPath ? ['.', appendPath] : ['.'];
return { paths, ignored };
}
async function main() {
const manifest = await readManifest();
const zipPath = `./dist/${manifest.id}-${manifest.version}.zip`;
logTimestamp(`${manifest.name} (${manifest.id})`);
logStartup(import.meta.url);
if (!manifest.bundled) {
logError('WebApps 1 is no longer supported. To use WebApps 2 set bundled to true in manifest.json.');
process.exit(1);
}
if (!args.project && args.sync && env) {
logEnviroment(env);
}
const tasks = [
task('clean', clean({ dir: './dist' })),
args.eslint && task('eslint', eslint({ src: ['./**/*.{js,svelte}'] })),
task('copy', [
copy({ src: './manifest.json', dest: './dist/src' }),
copy({ src: ['./src/manifest.json', './src/appDataDefaults.json', './src/i18n/*.json', './src/config', './src/resource'], dest: './dist' }),
]),
task('server', server({
input: './src/index.js',
output: './dist/src/index.js',
debug: args.debug,
cache: args.cache,
extractCss: true,
}), () => fse.existsSync('./src/index.js')),
task('client', client({
input: './src/main.js',
output: './dist/src/main.js',
globals: rollup?.client?.globals,
debug: args.debug,
cache: args.cache,
extractCss: true,
}), () => fse.existsSync('./src/main.js')),
task('headless', server({
input: './src/headless.js',
output: './dist/src/headless.js',
debug: args.debug,
cache: args.cache,
extractCss: true,
}), () => fse.existsSync('./src/headless.js')),
task('hooks', server({
input: './src/hooks.js',
output: './dist/src/hooks.js',
debug: args.debug,
cache: args.cache,
extractCss: true,
}), () => fse.existsSync('./src/hooks.js')),
task('config', config({
src: './config',
dest: './dist/src/config',
cache: args.cache,
debug: args.debug,
}), () => fse.existsSync('./config')),
task('globalConfig', config({
src: './config_global',
dest: './dist/src/config/global',
cache: args.cache,
}), () => fse.existsSync('./config_global')),
task('files', files({ manifest, dest: './dist' })),
task('zip', zip({ src: './dist/src', dest: zipPath })),
];
if (args.sign ?? env?.sign ?? env?.production) {
tasks.push(task('sign', sign({ src: zipPath })));
}
if (args.sync) {
tasks.push(task('upload', upload({
src: zipPath,
force: args.force || !env?.production,
})));
if (args.activate) {
tasks.push(task('activate', activate()));
}
}
if (args.watch) {
const { paths, ignored } = getWatchOptions(args);
watch(paths, () => runTasks(tasks), {
message: 'Watching for changes...',
ignored,
});
if (!args.project) createChecksumChecker();
} else {
await runTasks(tasks);
}
if (args.build) await runTasks(tasks);
}
main().catch((e) => {
logError(e.message);
logError(e.stack);
process.exit(1);
});
process.on('unhandledRejection', () => {});