flecks/packages/create-app/src/cli.js

37 lines
875 B
JavaScript
Raw Normal View History

2022-02-25 04:58:08 -06:00
import {join, normalize} from 'path';
2022-03-01 01:52:56 -06:00
import {Flecks} from '@flecks/core/server';
import validate from 'validate-npm-package-name';
2022-02-25 04:58:08 -06:00
2022-03-01 01:52:56 -06:00
import build from './build';
import move from './move';
2022-02-25 04:58:08 -06:00
2022-03-01 01:52:56 -06:00
const {
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
2022-02-25 04:58:08 -06:00
2022-03-01 01:52:56 -06:00
const cwd = normalize(FLECKS_CORE_ROOT);
2022-02-25 04:58:08 -06:00
2022-03-01 01:52:56 -06:00
const create = async (flecks) => {
2022-02-25 04:58:08 -06:00
const name = process.argv[2];
2022-03-01 01:52:56 -06:00
const {errors} = validate(name);
if (errors) {
throw new Error(`@flecks/create-app: invalid app name: ${errors.join(', ')}`);
2022-02-25 04:58:08 -06:00
}
2022-03-01 01:52:56 -06:00
const destination = join(cwd, name);
2022-03-01 10:30:33 -06:00
await move(name, join(__dirname, 'template'), destination, 'app', flecks);
2022-03-01 01:52:56 -06:00
await build(destination);
2022-02-25 04:58:08 -06:00
};
2022-03-01 01:52:56 -06:00
(async () => {
const flecks = await Flecks.bootstrap();
try {
await create(flecks);
}
catch (error) {
// eslint-disable-next-line no-console
console.error(error.message);
process.exitCode = 1;
}
})();