refactor: async
This commit is contained in:
parent
18bb7b961b
commit
73f36ab3c0
|
@ -2,13 +2,18 @@ const neutrino = require('neutrino');
|
|||
|
||||
const R = require('../bootstrap/require');
|
||||
const {targetNeutrino} = require('../server/commands');
|
||||
const D = require('../debug');
|
||||
const {default: Flecks} = require('../server/flecks');
|
||||
|
||||
const debug = D('@flecks/core/.eslintrc.js');
|
||||
|
||||
const {
|
||||
FLECKS_CORE_BUILD_TARGET = 'fleck',
|
||||
} = process.env;
|
||||
|
||||
debug('bootstrapping flecks...');
|
||||
const flecks = Flecks.bootstrap();
|
||||
debug('bootstrapped');
|
||||
|
||||
const config = R(process.env[targetNeutrino(FLECKS_CORE_BUILD_TARGET)]);
|
||||
flecks.invokeFlat('@flecks/core/build', FLECKS_CORE_BUILD_TARGET, config);
|
||||
|
|
|
@ -29,9 +29,11 @@ const buildList = FLECKS_CORE_BUILD_LIST
|
|||
.map((name) => name.trim())
|
||||
.filter((e) => e);
|
||||
|
||||
export default (async () => {
|
||||
debug('bootstrapping flecks...');
|
||||
const flecks = Flecks.bootstrap();
|
||||
debug('bootstrapped');
|
||||
|
||||
const buildConfigs = async () => {
|
||||
debug('gathering configs');
|
||||
let targets = flatten(flecks.invokeFlat('@flecks/core/targets'));
|
||||
if (buildList.length > 0) {
|
||||
|
@ -68,6 +70,4 @@ const buildConfigs = async () => {
|
|||
await new Promise(() => {});
|
||||
}
|
||||
return webpackConfigs;
|
||||
};
|
||||
|
||||
export default buildConfigs();
|
||||
})();
|
||||
|
|
|
@ -79,6 +79,7 @@ else {
|
|||
const program = new Command();
|
||||
program.enablePositionalOptions();
|
||||
// Bootstrap.
|
||||
(async () => {
|
||||
debug('bootstrapping flecks...');
|
||||
const flecks = Flecks.bootstrap();
|
||||
debug('bootstrapped');
|
||||
|
@ -106,4 +107,5 @@ else {
|
|||
}
|
||||
// Parse commandline.
|
||||
program.parse(process.argv);
|
||||
})();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import D from 'debug';
|
||||
const D = require('debug');
|
||||
|
||||
const {
|
||||
VSCODE_INSPECTOR_OPTIONS,
|
||||
} = process.env;
|
||||
|
||||
let hasInitialized;
|
||||
export default (name) => {
|
||||
module.exports = (name) => {
|
||||
if (!hasInitialized) {
|
||||
// VSCode has a problem showing colors when formatting objects.
|
||||
if (VSCODE_INSPECTOR_OPTIONS) {
|
||||
|
|
|
@ -5,16 +5,18 @@ const {join} = require('path');
|
|||
const banner = require('@neutrinojs/banner');
|
||||
const copy = require('@neutrinojs/copy');
|
||||
|
||||
module.exports = require('@flecks/fleck/server/build/fleck.neutrinorc');
|
||||
module.exports = (async () => {
|
||||
// eslint-disable-next-line global-require
|
||||
const config = await require('@flecks/fleck/server/build/fleck.neutrinorc');
|
||||
|
||||
module.exports.use.push(banner({
|
||||
config.use.push(banner({
|
||||
banner: '#!/usr/bin/env node',
|
||||
include: /^cli\.js$/,
|
||||
pluginId: 'shebang',
|
||||
raw: true,
|
||||
}));
|
||||
|
||||
module.exports.use.push(({config}) => {
|
||||
config.use.push(({config}) => {
|
||||
config
|
||||
.plugin('executable')
|
||||
.use(class Executable {
|
||||
|
@ -32,7 +34,7 @@ module.exports.use.push(({config}) => {
|
|||
});
|
||||
});
|
||||
|
||||
module.exports.use.push(
|
||||
config.use.push(
|
||||
copy({
|
||||
copyUnmodified: true,
|
||||
patterns: [
|
||||
|
@ -43,3 +45,7 @@ module.exports.use.push(
|
|||
],
|
||||
}),
|
||||
);
|
||||
|
||||
return config;
|
||||
|
||||
})();
|
||||
|
|
|
@ -5,16 +5,18 @@ const {join} = require('path');
|
|||
const banner = require('@neutrinojs/banner');
|
||||
const copy = require('@neutrinojs/copy');
|
||||
|
||||
module.exports = require('@flecks/fleck/server/build/fleck.neutrinorc');
|
||||
module.exports = (async () => {
|
||||
// eslint-disable-next-line global-require
|
||||
const config = await require('@flecks/fleck/server/build/fleck.neutrinorc');
|
||||
|
||||
module.exports.use.push(banner({
|
||||
config.use.push(banner({
|
||||
banner: '#!/usr/bin/env node',
|
||||
include: /^cli\.js$/,
|
||||
pluginId: 'shebang',
|
||||
raw: true,
|
||||
}));
|
||||
|
||||
module.exports.use.push(({config}) => {
|
||||
config.use.push(({config}) => {
|
||||
config
|
||||
.plugin('executable')
|
||||
.use(class Executable {
|
||||
|
@ -32,7 +34,7 @@ module.exports.use.push(({config}) => {
|
|||
});
|
||||
});
|
||||
|
||||
module.exports.use.push(
|
||||
config.use.push(
|
||||
copy({
|
||||
copyUnmodified: true,
|
||||
patterns: [
|
||||
|
@ -43,3 +45,7 @@ module.exports.use.push(
|
|||
],
|
||||
}),
|
||||
);
|
||||
|
||||
return config;
|
||||
|
||||
})();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {execSync, spawn} from 'child_process';
|
||||
import {exec, spawn} from 'child_process';
|
||||
import {mkdir} from 'fs/promises';
|
||||
import {tmpdir} from 'os';
|
||||
import {join} from 'path';
|
||||
|
@ -7,23 +7,25 @@ import {D} from '@flecks/core';
|
|||
|
||||
const debug = D('@flecks/docker/container');
|
||||
|
||||
const containerIsRunning = (name) => {
|
||||
try {
|
||||
const output = execSync(
|
||||
const containerIsRunning = async (name) => (
|
||||
new Promise((r, e) => {
|
||||
exec(
|
||||
`docker container inspect -f '{{.State.Running}}' ${name}`,
|
||||
{stdio: 'pipe'},
|
||||
).toString();
|
||||
if ('true\n' === output) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
(error, stdout) => {
|
||||
if (error) {
|
||||
if (1 !== e.status) {
|
||||
throw e;
|
||||
e(error);
|
||||
}
|
||||
else {
|
||||
r(false);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
r('true\n' === stdout);
|
||||
},
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
export default async (flecks, key, config) => {
|
||||
const {id} = flecks.get('@flecks/core');
|
||||
|
|
|
@ -12,12 +12,13 @@ const {
|
|||
|
||||
const debug = D('@flecks/fleck/fleck.neutrino.js');
|
||||
|
||||
const config = require('../../../../core/src/bootstrap/fleck.neutrinorc');
|
||||
|
||||
module.exports = (async () => {
|
||||
debug('bootstrapping flecks...');
|
||||
const flecks = Flecks.bootstrap();
|
||||
debug('bootstrapped');
|
||||
|
||||
const config = require('../../../../core/src/bootstrap/fleck.neutrinorc');
|
||||
|
||||
const compiler = flecks.invokeFleck(
|
||||
'@flecks/fleck/compiler',
|
||||
flecks.get('@flecks/fleck.compiler'),
|
||||
|
@ -60,4 +61,5 @@ config.use.push((neutrino) => {
|
|||
}
|
||||
});
|
||||
|
||||
module.exports = config;
|
||||
return config;
|
||||
})();
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
const config = require('@flecks/fleck/server/build/fleck.neutrinorc');
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const copy = require('@neutrinojs/copy');
|
||||
/* eslint-enable import/no-extraneous-dependencies */
|
||||
|
||||
module.exports = (async () => {
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies, global-require
|
||||
const config = await require('@flecks/fleck/server/build/fleck.neutrinorc');
|
||||
config.use.push(({config}) => {
|
||||
config.entryPoints.delete('build/template');
|
||||
});
|
||||
|
||||
config.use.push(
|
||||
copy({
|
||||
copyUnmodified: true,
|
||||
|
@ -18,5 +18,5 @@ config.use.push(
|
|||
],
|
||||
}),
|
||||
);
|
||||
|
||||
module.exports = config;
|
||||
return config;
|
||||
})();
|
||||
|
|
|
@ -14,10 +14,10 @@ const {
|
|||
|
||||
const debug = D('@flecks/http/http.neutrino.js');
|
||||
|
||||
module.exports = (async () => {
|
||||
debug('bootstrapping flecks...');
|
||||
const flecks = Flecks.bootstrap();
|
||||
debug('bootstrapped');
|
||||
|
||||
// Neutrino configuration.
|
||||
const config = {
|
||||
options: {
|
||||
|
@ -32,7 +32,7 @@ const config = {
|
|||
FLECKS_CORE_BUILD_TARGET: 'client',
|
||||
}]);
|
||||
},
|
||||
targets(flecks),
|
||||
await targets(flecks),
|
||||
],
|
||||
};
|
||||
// Compile code.
|
||||
|
@ -65,8 +65,8 @@ else {
|
|||
// Configure dev server.
|
||||
config.use.push(devServer(flecks));
|
||||
// Build the client runtime.
|
||||
config.use.push(runtime(flecks));
|
||||
config.use.push(await runtime(flecks));
|
||||
// Output configuration.
|
||||
config.use.push(outputs());
|
||||
|
||||
module.exports = config;
|
||||
return config;
|
||||
})();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {realpathSync} = require('fs');
|
||||
const {realpath} = require('fs/promises');
|
||||
const {
|
||||
dirname,
|
||||
join,
|
||||
|
@ -10,10 +10,16 @@ const glob = require('glob');
|
|||
|
||||
const debug = D('@flecks/http/runtime');
|
||||
|
||||
module.exports = (flecks) => (neutrino) => {
|
||||
module.exports = async (flecks) => {
|
||||
debug('bootstrapping flecks...');
|
||||
const httpFlecks = Flecks.bootstrap({platforms: ['client'], without: ['server']});
|
||||
debug('bootstrapped');
|
||||
const runtime = await realpath(R.resolve(join(flecks.resolve('@flecks/http'), 'runtime')));
|
||||
const fullresolve = (fleck, path) => realpath(R.resolve(join(flecks.resolve(fleck), path)));
|
||||
const entry = await fullresolve('@flecks/http', 'entry');
|
||||
const importLoader = await fullresolve('@flecks/http', 'import-loader');
|
||||
const tests = await realpath(R.resolve(join(flecks.resolve('@flecks/http'), 'tests')));
|
||||
return (neutrino) => {
|
||||
const {resolver} = httpFlecks;
|
||||
const paths = Object.entries(resolver);
|
||||
const source = [
|
||||
|
@ -36,7 +42,7 @@ module.exports = (flecks) => (neutrino) => {
|
|||
// HMR.
|
||||
source.push('if (module.hot) {');
|
||||
paths.forEach(([path]) => {
|
||||
source.push(` module.hot.accept('${path}', () => {`);
|
||||
source.push(` module.hot.accept('${path}', async () => {`);
|
||||
source.push(` window.flecks.refresh('${path}', require('${path}'));`);
|
||||
source.push(` window.flecks.invoke('@flecks/core/hmr', '${path}');`);
|
||||
source.push(' });');
|
||||
|
@ -44,7 +50,6 @@ module.exports = (flecks) => (neutrino) => {
|
|||
source.push('}');
|
||||
source.push('');
|
||||
// Create runtime.
|
||||
const runtime = realpathSync(R.resolve(join(flecks.resolve('@flecks/http'), 'runtime')));
|
||||
neutrino.config.module
|
||||
.rule(runtime)
|
||||
.test(runtime)
|
||||
|
@ -57,13 +62,11 @@ module.exports = (flecks) => (neutrino) => {
|
|||
.set('@flecks/http/runtime$', runtime);
|
||||
flecks.runtimeCompiler('http', neutrino);
|
||||
// Handle runtime import.
|
||||
const fullresolve = (fleck, path) => realpathSync(R.resolve(join(flecks.resolve(fleck), path)));
|
||||
const entry = fullresolve('@flecks/http', 'entry');
|
||||
neutrino.config.module
|
||||
.rule(entry)
|
||||
.test(entry)
|
||||
.use('entry/http')
|
||||
.loader(fullresolve('@flecks/http', 'import-loader'));
|
||||
.loader(importLoader);
|
||||
// Aliases.
|
||||
const aliases = flecks.aliases();
|
||||
if (Object.keys(aliases).length > 0) {
|
||||
|
@ -101,7 +104,6 @@ module.exports = (flecks) => (neutrino) => {
|
|||
const testEntry = neutrino.config.entry('test').clear();
|
||||
testPaths.forEach(([, path]) => testEntry.add(path));
|
||||
}
|
||||
const tests = realpathSync(R.resolve(join(flecks.resolve('@flecks/http'), 'tests')));
|
||||
neutrino.config.module
|
||||
.rule(tests)
|
||||
.test(tests)
|
||||
|
@ -123,3 +125,4 @@ module.exports = (flecks) => (neutrino) => {
|
|||
).join(''),
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* eslint-disable no-param-reassign */
|
||||
const {dirname, join} = require('path');
|
||||
const {realpathSync} = require('fs');
|
||||
const {realpath} = require('fs/promises');
|
||||
|
||||
const {require: R} = require('@flecks/core/server');
|
||||
|
||||
|
@ -8,14 +8,16 @@ const {
|
|||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
} = process.env;
|
||||
|
||||
module.exports = (flecks) => (neutrino) => {
|
||||
module.exports = async (flecks) => {
|
||||
const root = await realpath(dirname(R.resolve(join(flecks.resolve('@flecks/http'), 'entry.js'))));
|
||||
return (neutrino) => {
|
||||
const {options} = neutrino;
|
||||
const {output: originalOutput} = options;
|
||||
neutrino.config.resolve.modules.merge([
|
||||
join(FLECKS_CORE_ROOT, 'node_modules'),
|
||||
'node_modules',
|
||||
]);
|
||||
options.root = realpathSync(dirname(R.resolve(join(flecks.resolve('@flecks/http'), 'entry.js'))));
|
||||
options.root = root;
|
||||
options.source = '.';
|
||||
options.mains.index = 'entry';
|
||||
options.mains.tests = {
|
||||
|
@ -24,3 +26,4 @@ module.exports = (flecks) => (neutrino) => {
|
|||
};
|
||||
options.output = join(originalOutput, flecks.get('@flecks/http/server.output'));
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
const {realpathSync} = require('fs');
|
||||
const {realpath} = require('fs/promises');
|
||||
const {join} = require('path');
|
||||
|
||||
const {require: R} = require('@flecks/core/server');
|
||||
|
||||
module.exports = (flecks) => (neutrino) => {
|
||||
module.exports = async (flecks) => {
|
||||
const runtime = await realpath(R.resolve(join(flecks.resolve('@flecks/server'), 'runtime')));
|
||||
return (neutrino) => {
|
||||
const {config, resolver} = flecks;
|
||||
// Inject flecks configuration.
|
||||
const paths = Object.keys(resolver);
|
||||
|
@ -40,7 +42,7 @@ module.exports = (flecks) => (neutrino) => {
|
|||
source.push(' });');
|
||||
// Hooks for each fleck.
|
||||
paths.forEach((path) => {
|
||||
source.push(` module.hot.accept('${path}', () => {`);
|
||||
source.push(` module.hot.accept('${path}', async () => {`);
|
||||
source.push(` global.flecks.refresh('${path}', require('${path}'));`);
|
||||
source.push(` global.flecks.invoke('@flecks/core/hmr', '${path}');`);
|
||||
source.push(' });');
|
||||
|
@ -48,7 +50,6 @@ module.exports = (flecks) => (neutrino) => {
|
|||
source.push('}');
|
||||
// Create runtime.
|
||||
const entries = neutrino.config.entry('index');
|
||||
const runtime = realpathSync(R.resolve(join(flecks.resolve('@flecks/server'), 'runtime')));
|
||||
neutrino.config.module
|
||||
.rule(runtime)
|
||||
.test(runtime)
|
||||
|
@ -77,3 +78,4 @@ module.exports = (flecks) => (neutrino) => {
|
|||
const nodeExternals = R('webpack-node-externals');
|
||||
neutrino.config.externals(nodeExternals({allowlist}));
|
||||
};
|
||||
};
|
||||
|
|
|
@ -14,6 +14,8 @@ const {
|
|||
|
||||
const debug = D('@flecks/server/server.neutrino.js');
|
||||
|
||||
module.exports = (async () => {
|
||||
|
||||
debug('bootstrapping flecks...');
|
||||
const flecks = Flecks.bootstrap();
|
||||
debug('bootstrapped');
|
||||
|
@ -121,7 +123,7 @@ if (Object.keys(aliases).length > 0) {
|
|||
}
|
||||
|
||||
// Build the server runtime.
|
||||
config.use.push(runtime(flecks));
|
||||
config.use.push(await runtime(flecks));
|
||||
|
||||
// Give the resolver a helping hand.
|
||||
config.use.push((neutrino) => {
|
||||
|
@ -131,4 +133,5 @@ config.use.push((neutrino) => {
|
|||
]);
|
||||
});
|
||||
|
||||
module.exports = config;
|
||||
return config;
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue
Block a user