feat: add to build/flecks.yml
This commit is contained in:
parent
b74e23ccc0
commit
77a5c60a44
|
@ -27,7 +27,8 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"@flecks/core": "^2.0.3",
|
||||
"@flecks/create-app": "^2.0.3"
|
||||
"@flecks/create-app": "^2.0.3",
|
||||
"@inquirer/prompts": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@flecks/fleck": "^2.0.3"
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import {stat} from 'fs/promises';
|
||||
import {readFile, stat, writeFile} from 'fs/promises';
|
||||
import {join, normalize} from 'path';
|
||||
|
||||
import {build, move, validate} from '@flecks/create-app/server';
|
||||
import {Flecks} from '@flecks/core/server';
|
||||
import {dumpYml, Flecks, loadYml} from '@flecks/core/server';
|
||||
import {confirm} from '@inquirer/prompts';
|
||||
|
||||
const {
|
||||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
|
@ -10,7 +11,7 @@ const {
|
|||
|
||||
const cwd = normalize(FLECKS_CORE_ROOT);
|
||||
|
||||
const hasPackages = async (cwd) => {
|
||||
const checkIsMonorepo = async (cwd) => {
|
||||
try {
|
||||
await stat(join(cwd, 'packages'));
|
||||
return true;
|
||||
|
@ -47,7 +48,7 @@ const target = async (name) => {
|
|||
let scope;
|
||||
if (1 === parts.length) {
|
||||
pkg = name;
|
||||
if (await hasPackages(cwd)) {
|
||||
if (await checkIsMonorepo(cwd)) {
|
||||
scope = await monorepoScope(cwd);
|
||||
}
|
||||
return [scope, pkg];
|
||||
|
@ -56,12 +57,20 @@ const target = async (name) => {
|
|||
};
|
||||
|
||||
const create = async (flecks) => {
|
||||
const isMonorepo = await checkIsMonorepo(cwd);
|
||||
const [scope, pkg] = await target(process.argv[2]);
|
||||
const path = scope && (await hasPackages(cwd)) ? join(cwd, 'packages') : cwd;
|
||||
const path = scope && isMonorepo ? join(cwd, 'packages') : cwd;
|
||||
const name = [scope, pkg].filter((e) => !!e).join('/');
|
||||
const destination = join(path, pkg);
|
||||
await move(name, join(__dirname, 'template'), destination, 'fleck', flecks);
|
||||
await build(destination);
|
||||
if (isMonorepo && await confirm({message: 'Add fleck to `build/flecks.yml`?'})) {
|
||||
const key = `${name}:${join('.', 'packages', pkg)}`;
|
||||
const ymlPath = join(FLECKS_CORE_ROOT, 'build', 'flecks.yml');
|
||||
let yml = loadYml(await readFile(ymlPath));
|
||||
yml = Object.fromEntries(Object.entries(yml).concat([[key, {}]]));
|
||||
await writeFile(ymlPath, dumpYml(yml, {forceQuotes: true, sortKeys: true}));
|
||||
}
|
||||
};
|
||||
|
||||
(async () => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user