feat: flecks add
This commit is contained in:
parent
77a5c60a44
commit
f44027854d
2
TODO.md
2
TODO.md
|
@ -32,7 +32,7 @@
|
||||||
- [ ] `$flecks/db/sequelize` should be `$flecks/db.sequelize`
|
- [ ] `$flecks/db/sequelize` should be `$flecks/db.sequelize`
|
||||||
- [x] `url()` in styles breaks HMR
|
- [x] `url()` in styles breaks HMR
|
||||||
- [ ] 2 underscores for `FLECKS_ENV` variables
|
- [ ] 2 underscores for `FLECKS_ENV` variables
|
||||||
- [ ] flecks add
|
- [x] flecks add
|
||||||
|
|
||||||
# Next
|
# Next
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import flatten from 'lodash.flatten';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
|
|
||||||
import D from '../debug';
|
import D from '../debug';
|
||||||
|
import Flecks from './flecks';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_CORE_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
|
@ -45,6 +46,26 @@ export const spawnWith = (cmd, opts = {}) => {
|
||||||
|
|
||||||
export default (program, flecks) => {
|
export default (program, flecks) => {
|
||||||
const commands = {
|
const commands = {
|
||||||
|
add: {
|
||||||
|
args: [
|
||||||
|
new Argument('<fleck>>', 'fleck'),
|
||||||
|
],
|
||||||
|
description: 'add a fleck to your application',
|
||||||
|
action: async (fleck, opts) => {
|
||||||
|
const {
|
||||||
|
noYarn,
|
||||||
|
} = opts;
|
||||||
|
await processCode(
|
||||||
|
noYarn
|
||||||
|
? spawn('npm', ['install', fleck], {stdio: 'inherit'})
|
||||||
|
: spawn('yarn', ['add', fleck], {stdio: 'inherit'}),
|
||||||
|
);
|
||||||
|
await Flecks.addFleckToYml(fleck);
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
['--no-yarn', 'use npm instead of yarn'],
|
||||||
|
],
|
||||||
|
},
|
||||||
clean: {
|
clean: {
|
||||||
description: 'remove node_modules, lock file, build artifacts, then reinstall',
|
description: 'remove node_modules, lock file, build artifacts, then reinstall',
|
||||||
action: (opts) => {
|
action: (opts) => {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
realpathSync,
|
realpathSync,
|
||||||
statSync,
|
statSync,
|
||||||
} from 'fs';
|
} from 'fs';
|
||||||
|
import {readFile, writeFile} from 'fs/promises';
|
||||||
import {
|
import {
|
||||||
basename,
|
basename,
|
||||||
dirname,
|
dirname,
|
||||||
|
@ -10,10 +11,12 @@ import {
|
||||||
isAbsolute,
|
isAbsolute,
|
||||||
join,
|
join,
|
||||||
resolve,
|
resolve,
|
||||||
|
sep,
|
||||||
} from 'path';
|
} from 'path';
|
||||||
|
|
||||||
import babelmerge from 'babel-merge';
|
import babelmerge from 'babel-merge';
|
||||||
import enhancedResolve from 'enhanced-resolve';
|
import enhancedResolve from 'enhanced-resolve';
|
||||||
|
import {dump as dumpYml, load as loadYml} from 'js-yaml';
|
||||||
import {addHook} from 'pirates';
|
import {addHook} from 'pirates';
|
||||||
|
|
||||||
import D from '../debug';
|
import D from '../debug';
|
||||||
|
@ -40,6 +43,14 @@ export default class ServerFlecks extends Flecks {
|
||||||
this.rcs = options.rcs || {};
|
this.rcs = options.rcs || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async addFleckToYml(fleck, path) {
|
||||||
|
const key = [fleck].concat(path ? `.${sep}${join('packages', path, 'src')}` : []).join(':');
|
||||||
|
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, {sortKeys: true}));
|
||||||
|
}
|
||||||
|
|
||||||
get aliasedConfig() {
|
get aliasedConfig() {
|
||||||
const aliases = this.aliases();
|
const aliases = this.aliases();
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import {readFile, stat, writeFile} from 'fs/promises';
|
import {stat} from 'fs/promises';
|
||||||
import {join, normalize} from 'path';
|
import {join, normalize} from 'path';
|
||||||
|
|
||||||
import {build, move, validate} from '@flecks/create-app/server';
|
import {build, move, validate} from '@flecks/create-app/server';
|
||||||
import {dumpYml, Flecks, loadYml} from '@flecks/core/server';
|
import {Flecks} from '@flecks/core/server';
|
||||||
import {confirm} from '@inquirer/prompts';
|
import {confirm} from '@inquirer/prompts';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -65,11 +65,7 @@ const create = async (flecks) => {
|
||||||
await move(name, join(__dirname, 'template'), destination, 'fleck', flecks);
|
await move(name, join(__dirname, 'template'), destination, 'fleck', flecks);
|
||||||
await build(destination);
|
await build(destination);
|
||||||
if (isMonorepo && await confirm({message: 'Add fleck to `build/flecks.yml`?'})) {
|
if (isMonorepo && await confirm({message: 'Add fleck to `build/flecks.yml`?'})) {
|
||||||
const key = `${name}:${join('.', 'packages', pkg)}`;
|
await Flecks.addFleckToYml(name, 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}));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user