test: build
This commit is contained in:
parent
b0dbc59f6d
commit
742b8d0f24
|
@ -44,7 +44,12 @@ module.exports = class Build extends Flecks {
|
||||||
.filter((e) => e);
|
.filter((e) => e);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async buildRuntime(originalConfig, platforms, flecks = {}) {
|
static async buildRuntime({
|
||||||
|
flecks = {},
|
||||||
|
originalConfig,
|
||||||
|
platforms,
|
||||||
|
root,
|
||||||
|
}) {
|
||||||
const cleanConfig = JSON.parse(JSON.stringify(originalConfig));
|
const cleanConfig = JSON.parse(JSON.stringify(originalConfig));
|
||||||
// Dealias the config keys.
|
// Dealias the config keys.
|
||||||
const dealiasedConfig = Object.fromEntries(
|
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({
|
const {paths, roots} = await explicate({
|
||||||
paths: Object.keys(originalConfig),
|
paths: Object.keys(originalConfig),
|
||||||
platforms,
|
platforms,
|
||||||
|
@ -129,6 +134,7 @@ module.exports = class Build extends Flecks {
|
||||||
config: configParameter,
|
config: configParameter,
|
||||||
flecks: configFlecks,
|
flecks: configFlecks,
|
||||||
platforms = ['server'],
|
platforms = ['server'],
|
||||||
|
root = FLECKS_CORE_ROOT,
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
// Load or use parameterized configuration.
|
// Load or use parameterized configuration.
|
||||||
|
@ -136,7 +142,7 @@ module.exports = class Build extends Flecks {
|
||||||
let configType = 'parameter';
|
let configType = 'parameter';
|
||||||
if (!configParameter) {
|
if (!configParameter) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
[configType, originalConfig] = await loadConfig();
|
[configType, originalConfig] = await loadConfig(root);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
originalConfig = JSON.parse(JSON.stringify(configParameter));
|
originalConfig = JSON.parse(JSON.stringify(configParameter));
|
||||||
|
@ -147,9 +153,15 @@ module.exports = class Build extends Flecks {
|
||||||
resolver,
|
resolver,
|
||||||
roots,
|
roots,
|
||||||
runtime,
|
runtime,
|
||||||
} = await this.buildRuntime(originalConfig, platforms, configFlecks);
|
} = await this.buildRuntime({
|
||||||
|
flecks: configFlecks,
|
||||||
|
originalConfig,
|
||||||
|
platforms,
|
||||||
|
root,
|
||||||
|
});
|
||||||
const flecks = await super.from(runtime);
|
const flecks = await super.from(runtime);
|
||||||
flecks.platforms = platforms;
|
flecks.platforms = platforms;
|
||||||
|
flecks.root = root;
|
||||||
flecks.roots = roots;
|
flecks.roots = roots;
|
||||||
flecks.resolver = resolver;
|
flecks.resolver = resolver;
|
||||||
flecks.loadBuildFiles();
|
flecks.loadBuildFiles();
|
||||||
|
@ -181,7 +193,7 @@ module.exports = class Build extends Flecks {
|
||||||
if (!fleck) {
|
if (!fleck) {
|
||||||
throw new Error(`Unknown build config: '${config}'`);
|
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) {
|
if (rootConfig) {
|
||||||
return rootConfig;
|
return rootConfig;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,10 @@ const D = require('@flecks/core/build/debug');
|
||||||
|
|
||||||
const debug = D('@flecks/build/build/load-config');
|
const debug = D('@flecks/build/build/load-config');
|
||||||
|
|
||||||
const {
|
module.exports = async function loadConfig(root) {
|
||||||
FLECKS_CORE_ROOT = process.cwd(),
|
|
||||||
} = process.env;
|
|
||||||
|
|
||||||
module.exports = async function loadConfig() {
|
|
||||||
try {
|
try {
|
||||||
const {load} = require('js-yaml');
|
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');
|
const buffer = await readFile(filename, 'utf8');
|
||||||
debug('parsing configuration from YML...');
|
debug('parsing configuration from YML...');
|
||||||
return ['YML', load(buffer, {filename})];
|
return ['YML', load(buffer, {filename})];
|
||||||
|
@ -21,7 +17,7 @@ module.exports = async function loadConfig() {
|
||||||
if ('ENOENT' !== error.code) {
|
if ('ENOENT' !== error.code) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
const {name} = require(join(FLECKS_CORE_ROOT, 'package.json'));
|
const {name} = require(join(root, 'package.json'));
|
||||||
const barebones = {
|
const barebones = {
|
||||||
'@flecks/build': {},
|
'@flecks/build': {},
|
||||||
'@flecks/core': {},
|
'@flecks/core': {},
|
||||||
|
@ -30,7 +26,7 @@ module.exports = async function loadConfig() {
|
||||||
if (barebones[name]) {
|
if (barebones[name]) {
|
||||||
delete barebones[name];
|
delete barebones[name];
|
||||||
}
|
}
|
||||||
barebones[`${name}:${FLECKS_CORE_ROOT}`] = {};
|
barebones[`${name}:${root}`] = {};
|
||||||
return ['barebones', barebones];
|
return ['barebones', barebones];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
"clean": "rm -rf dist node_modules yarn.lock",
|
"clean": "rm -rf dist node_modules yarn.lock",
|
||||||
"lint": "eslint --config ./build/eslint.config.js .",
|
"lint": "eslint --config ./build/eslint.config.js .",
|
||||||
"postversion": "npm run build",
|
"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"
|
"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": {
|
"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