Skip to content

Commit

Permalink
fix: creators
Browse files Browse the repository at this point in the history
  • Loading branch information
cha0s committed Jan 23, 2024
1 parent 675aaad commit c1eee58
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/build/build/cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node

const D = require('@flecks/core/build/debug');
const {processCode} = require('@flecks/core/server');
const {Command} = require('commander');

const Build = require('./build');
const {processCode} = require('./commands');

const debug = D('@flecks/build/build/cli');
const debugSilly = debug.extend('silly');
Expand Down
29 changes: 4 additions & 25 deletions packages/build/build/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {spawn} = require('child_process');
const {join, normalize} = require('path');

const D = require('@flecks/core/build/debug');
const {processCode, spawnWith} = require('@flecks/core/server');
const {Argument, Option, program} = require('commander');
const {glob} = require('glob');
const rimraf = require('rimraf');
Expand Down Expand Up @@ -33,7 +34,7 @@ exports.commands = (program, flecks) => {
args.push(packageManager, ['install', fleck]);
}
args.push({stdio: 'inherit'});
await exports.processCode(spawn(...args));
await processCode(spawn(...args));
await addFleckToYml(fleck);
},
},
Expand Down Expand Up @@ -85,7 +86,7 @@ exports.commands = (program, flecks) => {
'--mode', (production && !hot) ? 'production' : 'development',
...((watch || hot) ? ['--watch'] : []),
];
return exports.spawnWith(
return spawnWith(
cmd,
{
env: {
Expand Down Expand Up @@ -117,7 +118,7 @@ exports.commands = (program, flecks) => {
'.',
];
promises.push(new Promise((resolve, reject) => {
const child = exports.spawnWith(
const child = spawnWith(
cmd,
{
cwd,
Expand Down Expand Up @@ -156,28 +157,6 @@ exports.commands = (program, flecks) => {
return commands;
};

exports.processCode = (child) => new Promise((resolve, reject) => {
child.on('error', reject);
child.on('exit', (code) => {
child.off('error', reject);
resolve(code);
});
});

exports.spawnWith = (cmd, opts = {}) => {
debug("spawning: '%s'", cmd.join(' '));
debugSilly('with options: %O', opts);
const child = spawn(cmd[0], cmd.slice(1), {
stdio: 'inherit',
...opts,
env: {
...process.env,
...opts.env,
},
});
return child;
};

exports.Argument = Argument;
exports.Option = Option;
exports.program = program;
2 changes: 1 addition & 1 deletion packages/build/build/flecks.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {

exports.hooks = {
'@flecks/build.extensions': () => ['.mjs', '.js', '.json', '.wasm'],
'@flecks/build.commands': commands,
'@flecks/build.config': async (target, config, env, argv, flecks) => {
if (flecks.get('@flecks/build.profile').includes(target)) {
config.plugins.push(
Expand Down Expand Up @@ -45,7 +46,6 @@ exports.hooks = {
*/
'fleck.webpack.config.js',
],
'@flecks/build.commands': commands,
'@flecks/core.config': () => ({
/**
* The package manager used for tasks.
Expand Down
29 changes: 29 additions & 0 deletions packages/core/src/server/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
const {spawn} = require('child_process');

export {glob} from 'glob';

const D = require('../../build/debug');

const debug = D('@flecks/core/server');
const debugSilly = debug.extend('silly');

export {JsonStream, transform} from '../../build/stream';

export const processCode = (child) => new Promise((resolve, reject) => {
child.on('error', reject);
child.on('exit', (code) => {
child.off('error', reject);
resolve(code);
});
});

export const spawnWith = (cmd, opts = {}) => {
debug("spawning: '%s'", cmd.join(' '));
debugSilly('with options: %O', opts);
const child = spawn(cmd[0], cmd.slice(1), {
stdio: 'inherit',
...opts,
env: {
...process.env,
...opts.env,
},
});
return child;
};
2 changes: 1 addition & 1 deletion packages/create-app/build/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {processCode, spawnWith} = require('@flecks/build/build/commands');
const {processCode, spawnWith} = require('@flecks/core/server');

module.exports = async (packageManager, cwd) => {
const code = await processCode(spawnWith([packageManager, 'install'], {cwd}));
Expand Down
7 changes: 2 additions & 5 deletions packages/create-app/build/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
const {join} = require('path');

const {program} = require('@flecks/build/build/commands');
const {
dumpYml,
loadYml,
transform,
} = require('@flecks/core/server');
const {dumpYml, loadYml} = require('@flecks/build/server');
const {transform} = require('@flecks/core/server');
const validate = require('validate-npm-package-name');

const build = require('./build');
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"template"
],
"dependencies": {
"@flecks/build": "^3.0.0",
"@flecks/core": "^3.0.0",
"minimatch": "^5.0.1",
"validate-npm-package-name": "^3.0.0"
},
"devDependencies": {
"@flecks/build": "^3.0.0",
"@flecks/fleck": "^3.0.0"
}
}
1 change: 1 addition & 0 deletions packages/create-app/template/build/flecks.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
'@flecks/build': {}
'@flecks/core': {}
'@flecks/server': {}
2 changes: 1 addition & 1 deletion packages/create-fleck/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"template"
],
"dependencies": {
"@flecks/build": "^3.0.0",
"@flecks/core": "^3.0.0",
"@flecks/create-app": "^3.0.0"
},
"devDependencies": {
"@flecks/build": "^3.0.0",
"@flecks/fleck": "^3.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/web/build/flecks.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const {stat, unlink} = require('fs/promises');
const {join} = require('path');

const Build = require('@flecks/build/build/build');
const {spawnWith} = require('@flecks/build/build/commands');
const {regexFromExtensions} = require('@flecks/build/server');
const {spawnWith} = require('@flecks/core/server');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const {
Expand Down

0 comments on commit c1eee58

Please sign in to comment.