test: build
This commit is contained in:
parent
b0dbc59f6d
commit
742b8d0f24
|
@ -44,7 +44,12 @@ module.exports = class Build extends Flecks {
|
|||
.filter((e) => e);
|
||||
}
|
||||
|
||||
static async buildRuntime(originalConfig, platforms, flecks = {}) {
|
||||
static async buildRuntime({
|
||||
flecks = {},
|
||||
originalConfig,
|
||||
platforms,
|
||||
root,
|
||||
}) {
|
||||
const cleanConfig = JSON.parse(JSON.stringify(originalConfig));
|
||||
// Dealias the config keys.
|
||||
const dealiasedConfig = Object.fromEntries(
|
||||
|
@ -57,7 +62,7 @@ module.exports = class Build extends Flecks {
|
|||
];
|
||||
}),
|
||||
);
|
||||
const resolver = new Resolver({root: FLECKS_CORE_ROOT});
|
||||
const resolver = new Resolver({root});
|
||||
const {paths, roots} = await explicate({
|
||||
paths: Object.keys(originalConfig),
|
||||
platforms,
|
||||
|
@ -129,6 +134,7 @@ module.exports = class Build extends Flecks {
|
|||
config: configParameter,
|
||||
flecks: configFlecks,
|
||||
platforms = ['server'],
|
||||
root = FLECKS_CORE_ROOT,
|
||||
} = {},
|
||||
) {
|
||||
// Load or use parameterized configuration.
|
||||
|
@ -136,7 +142,7 @@ module.exports = class Build extends Flecks {
|
|||
let configType = 'parameter';
|
||||
if (!configParameter) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
[configType, originalConfig] = await loadConfig();
|
||||
[configType, originalConfig] = await loadConfig(root);
|
||||
}
|
||||
else {
|
||||
originalConfig = JSON.parse(JSON.stringify(configParameter));
|
||||
|
@ -147,9 +153,15 @@ module.exports = class Build extends Flecks {
|
|||
resolver,
|
||||
roots,
|
||||
runtime,
|
||||
} = await this.buildRuntime(originalConfig, platforms, configFlecks);
|
||||
} = await this.buildRuntime({
|
||||
flecks: configFlecks,
|
||||
originalConfig,
|
||||
platforms,
|
||||
root,
|
||||
});
|
||||
const flecks = await super.from(runtime);
|
||||
flecks.platforms = platforms;
|
||||
flecks.root = root;
|
||||
flecks.roots = roots;
|
||||
flecks.resolver = resolver;
|
||||
flecks.loadBuildFiles();
|
||||
|
@ -181,7 +193,7 @@ module.exports = class Build extends Flecks {
|
|||
if (!fleck) {
|
||||
throw new Error(`Unknown build config: '${config}'`);
|
||||
}
|
||||
const rootConfig = await this.resolver.resolve(join(FLECKS_CORE_ROOT, 'build', config));
|
||||
const rootConfig = await this.resolver.resolve(join(this.root, 'build', config));
|
||||
if (rootConfig) {
|
||||
return rootConfig;
|
||||
}
|
||||
|
|
|
@ -5,14 +5,10 @@ const D = require('@flecks/core/build/debug');
|
|||
|
||||
const debug = D('@flecks/build/build/load-config');
|
||||
|
||||
const {
|
||||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
} = process.env;
|
||||
|
||||
module.exports = async function loadConfig() {
|
||||
module.exports = async function loadConfig(root) {
|
||||
try {
|
||||
const {load} = require('js-yaml');
|
||||
const filename = join(FLECKS_CORE_ROOT, 'build', 'flecks.yml');
|
||||
const filename = join(root, 'build', 'flecks.yml');
|
||||
const buffer = await readFile(filename, 'utf8');
|
||||
debug('parsing configuration from YML...');
|
||||
return ['YML', load(buffer, {filename})];
|
||||
|
@ -21,7 +17,7 @@ module.exports = async function loadConfig() {
|
|||
if ('ENOENT' !== error.code) {
|
||||
throw error;
|
||||
}
|
||||
const {name} = require(join(FLECKS_CORE_ROOT, 'package.json'));
|
||||
const {name} = require(join(root, 'package.json'));
|
||||
const barebones = {
|
||||
'@flecks/build': {},
|
||||
'@flecks/core': {},
|
||||
|
@ -30,7 +26,7 @@ module.exports = async function loadConfig() {
|
|||
if (barebones[name]) {
|
||||
delete barebones[name];
|
||||
}
|
||||
barebones[`${name}:${FLECKS_CORE_ROOT}`] = {};
|
||||
barebones[`${name}:${root}`] = {};
|
||||
return ['barebones', barebones];
|
||||
}
|
||||
};
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
"clean": "rm -rf dist node_modules yarn.lock",
|
||||
"lint": "eslint --config ./build/eslint.config.js .",
|
||||
"postversion": "npm run build",
|
||||
"test": "webpack --config ../core/build/build.test.webpack.config.js --mode production && mocha --colors ./dist/test.js --timeout 10000",
|
||||
"test": "webpack --config ./build/build.test.webpack.config.js --mode production && mocha --colors ./dist/test.js --timeout 10000",
|
||||
"test:watch": "webpack watch --config ./build/build.test.webpack.config.js --mode development & mocha --parallel --watch --watch-files ./dist/test.js --colors ./dist/test.js --timeout 10000"
|
||||
},
|
||||
"bin": {
|
||||
|
|
56
packages/build/test/server/build.js
Normal file
56
packages/build/test/server/build.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
import {join} from 'path';
|
||||
|
||||
import {expect} from 'chai';
|
||||
|
||||
const {
|
||||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
} = process.env;
|
||||
|
||||
const Build = __non_webpack_require__(join(FLECKS_CORE_ROOT, 'build', 'build'));
|
||||
const loadConfig = __non_webpack_require__(join(FLECKS_CORE_ROOT, 'build', 'load-config'));
|
||||
|
||||
const buildRoot = join(FLECKS_CORE_ROOT, 'test', 'server', 'build', 'root');
|
||||
|
||||
it('defaults config', async () => {
|
||||
expect(await loadConfig(FLECKS_CORE_ROOT))
|
||||
.to.deep.equal([
|
||||
'barebones',
|
||||
{
|
||||
[`@flecks/build:${FLECKS_CORE_ROOT}`]: {},
|
||||
'@flecks/core': {},
|
||||
'@flecks/fleck': {},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('loads config', async () => {
|
||||
expect(await loadConfig(buildRoot))
|
||||
.to.deep.equal(['YML', {one: {}, 'two:./two': {}}]);
|
||||
});
|
||||
|
||||
it('configures from environment', async () => {
|
||||
const {env} = process;
|
||||
env.FLECKS_ENV__one__foo = '{"boo": 2}';
|
||||
env.FLECKS_ENV__two__bar = 'yo';
|
||||
expect(
|
||||
Build.environmentConfiguration({
|
||||
one: {foo: {boo: 1}},
|
||||
two: {bar: 'hi'},
|
||||
}),
|
||||
)
|
||||
.to.deep.equal({
|
||||
one: {foo: {boo: 2}},
|
||||
two: {bar: 'yo'},
|
||||
});
|
||||
});
|
||||
|
||||
it('dealiases config', async () => {
|
||||
expect(await Build.buildRuntime({
|
||||
originalConfig: {'two:./two': {foo: 2}},
|
||||
platforms: [],
|
||||
root: buildRoot,
|
||||
}))
|
||||
.to.nested.include({
|
||||
'runtime.config.two.foo': 2,
|
||||
});
|
||||
});
|
2
packages/build/test/server/build/root/build/flecks.yml
Normal file
2
packages/build/test/server/build/root/build/flecks.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
one: {}
|
||||
'two:./two': {}
|
0
packages/build/test/server/build/root/two/index.js
Normal file
0
packages/build/test/server/build/root/two/index.js
Normal file
1
packages/build/test/server/build/root/two/package.json
Normal file
1
packages/build/test/server/build/root/two/package.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
4
packages/build/test/server/yml/build/flecks.yml
Normal file
4
packages/build/test/server/yml/build/flecks.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
a: {}
|
||||
bar: {}
|
||||
foo: {}
|
||||
two: {}
|
Loading…
Reference in New Issue
Block a user