refactor: async
This commit is contained in:
parent
765a2eed9e
commit
97536387e6
|
@ -130,22 +130,22 @@ module.exports = class Build extends Flecks {
|
|||
roots,
|
||||
runtime,
|
||||
} = await this.buildRuntime(originalConfig, platforms, configFlecks);
|
||||
const flecks = super.from(runtime);
|
||||
const flecks = await super.from(runtime);
|
||||
flecks.platforms = platforms;
|
||||
flecks.roots = roots;
|
||||
flecks.resolver = resolver;
|
||||
flecks.loadBuildConfigs();
|
||||
flecks.loadBuildFiles();
|
||||
return flecks;
|
||||
}
|
||||
|
||||
loadBuildConfigs() {
|
||||
loadBuildFiles() {
|
||||
Object.entries(this.invoke('@flecks/build.files'))
|
||||
.forEach(([fleck, configs]) => {
|
||||
configs.forEach((config) => {
|
||||
this.buildFiles[config] = fleck;
|
||||
.forEach(([fleck, filenames]) => {
|
||||
filenames.forEach((filename) => {
|
||||
this.buildFiles[filename] = fleck;
|
||||
});
|
||||
});
|
||||
debugSilly('build configs loaded: %O', this.buildFiles);
|
||||
debugSilly('build files loaded: %O', this.buildFiles);
|
||||
}
|
||||
|
||||
get realiasedConfig() {
|
||||
|
|
|
@ -360,7 +360,7 @@ exports.Flecks = class Flecks {
|
|||
* @param {Object} config Configuration.
|
||||
* @returns {Flecks} A flecks instance.
|
||||
*/
|
||||
static from(runtime) {
|
||||
static async from(runtime) {
|
||||
const {flecks} = runtime;
|
||||
const mixinDescription = Object.entries(flecks)
|
||||
.map(([path, {mixin}]) => [path, mixin]).filter(([, mixin]) => mixin);
|
||||
|
|
|
@ -5,8 +5,8 @@ import {Flecks, ById, ByType} from '@flecks/core';
|
|||
const testOne = require('./packages/one');
|
||||
const testTwo = require('./packages/two');
|
||||
|
||||
it('can gather', () => {
|
||||
const flecks = Flecks.from({
|
||||
it('can gather', async () => {
|
||||
const flecks = await Flecks.from({
|
||||
flecks: {
|
||||
'@flecks/core/one': testOne,
|
||||
'@flecks/core/two': testTwo,
|
||||
|
|
|
@ -14,14 +14,14 @@ it('can create an empty instance', () => {
|
|||
.to.equal(0);
|
||||
});
|
||||
|
||||
it('can gather config', () => {
|
||||
it('can gather config', async () => {
|
||||
let flecks;
|
||||
flecks = Flecks.from({
|
||||
flecks = await Flecks.from({
|
||||
flecks: {'@flecks/core/one': testOne},
|
||||
});
|
||||
expect(flecks.get(['@flecks/core/one']))
|
||||
.to.contain({foo: 'bar'});
|
||||
flecks = Flecks.from({
|
||||
flecks = await Flecks.from({
|
||||
config: {'@flecks/core/one': {foo: 'baz'}},
|
||||
flecks: {'@flecks/core/one': testOne},
|
||||
});
|
||||
|
|
|
@ -12,8 +12,8 @@ const testTwo = require('./packages/two');
|
|||
|
||||
let flecks;
|
||||
|
||||
beforeEach(() => {
|
||||
flecks = Flecks.from({
|
||||
beforeEach(async () => {
|
||||
flecks = await Flecks.from({
|
||||
flecks: {
|
||||
'@flecks/core/one': testOne,
|
||||
'@flecks/core/two': testTwo,
|
||||
|
|
|
@ -6,8 +6,8 @@ const testOne = require('./packages/one');
|
|||
const testTwo = require('./packages/two');
|
||||
const testThree = require('./packages/three');
|
||||
|
||||
it('can make middleware', (done) => {
|
||||
const flecks = Flecks.from({
|
||||
it('can make middleware', async () => {
|
||||
const flecks = await Flecks.from({
|
||||
config: {
|
||||
'@flecks/core/test': {
|
||||
middleware: [
|
||||
|
@ -23,14 +23,16 @@ it('can make middleware', (done) => {
|
|||
});
|
||||
const foo = {bar: 1};
|
||||
const mw = flecks.makeMiddleware('@flecks/core/test.middleware');
|
||||
mw(foo, () => {
|
||||
expect(foo.bar).to.equal(4);
|
||||
done();
|
||||
await new Promise((resolve) => {
|
||||
mw(foo, () => {
|
||||
expect(foo.bar).to.equal(4);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('respects explicit middleware configuration', (done) => {
|
||||
const flecks = Flecks.from({
|
||||
it('respects explicit middleware configuration', async () => {
|
||||
const flecks = await Flecks.from({
|
||||
config: {
|
||||
'@flecks/core/test': {
|
||||
middleware: [
|
||||
|
@ -46,14 +48,16 @@ it('respects explicit middleware configuration', (done) => {
|
|||
});
|
||||
const foo = {bar: 1};
|
||||
const mw = flecks.makeMiddleware('@flecks/core/test.middleware');
|
||||
mw(foo, () => {
|
||||
expect(foo.bar).to.equal(3);
|
||||
done();
|
||||
await new Promise((resolve) => {
|
||||
mw(foo, () => {
|
||||
expect(foo.bar).to.equal(3);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('respects middleware elision', (done) => {
|
||||
const flecks = Flecks.from({
|
||||
it('respects middleware elision', async () => {
|
||||
const flecks = await Flecks.from({
|
||||
config: {
|
||||
'@flecks/core/test': {
|
||||
middleware: [
|
||||
|
@ -68,14 +72,16 @@ it('respects middleware elision', (done) => {
|
|||
});
|
||||
const foo = {bar: 1};
|
||||
const mw = flecks.makeMiddleware('@flecks/core/test.middleware');
|
||||
mw(foo, () => {
|
||||
expect(foo.bar).to.equal(3);
|
||||
done();
|
||||
await new Promise((resolve) => {
|
||||
mw(foo, () => {
|
||||
expect(foo.bar).to.equal(3);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('throws on elision graph cycle', () => {
|
||||
const flecks = Flecks.from({
|
||||
it('throws on elision graph cycle', async () => {
|
||||
const flecks = await Flecks.from({
|
||||
config: {
|
||||
'@flecks/core/test': {
|
||||
middleware: [
|
||||
|
|
|
@ -21,8 +21,8 @@ const {version} = require('../package.json');
|
|||
}
|
||||
const debug = D('@flecks/server/entry');
|
||||
debug('starting server...');
|
||||
global.flecks = await Flecks.from({...runtime, flecks: await loadFlecks()});
|
||||
try {
|
||||
global.flecks = await Flecks.from({...runtime, flecks: await loadFlecks()});
|
||||
await Promise.all(global.flecks.invokeFlat('@flecks/core.starting'));
|
||||
await global.flecks.invokeSequentialAsync('@flecks/server.up');
|
||||
debug('up!');
|
||||
|
|
|
@ -53,10 +53,9 @@ const {version} = require('@flecks/web/package.json');
|
|||
const runtime = await loader(progress.update.bind(progress));
|
||||
progress.finish();
|
||||
debug('starting client...');
|
||||
// Flecks mixins.
|
||||
const flecks = Flecks.from(runtime);
|
||||
window.flecks = flecks;
|
||||
try {
|
||||
const flecks = await Flecks.from(runtime);
|
||||
window.flecks = flecks;
|
||||
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
||||
await flecks.invokeSequentialAsync('@flecks/web/client.up');
|
||||
const appMountContainerId = `#${config['@flecks/web'].appMountId}-container`;
|
||||
|
|
Loading…
Reference in New Issue
Block a user