2024-01-16 00:28:20 -06:00
|
|
|
const {join} = require('path');
|
2024-01-13 04:46:07 -06:00
|
|
|
|
2024-01-16 00:28:20 -06:00
|
|
|
const {glob} = require('@flecks/core/server');
|
2024-01-13 04:46:07 -06:00
|
|
|
|
2024-01-16 00:28:20 -06:00
|
|
|
const commands = require('./commands');
|
2022-02-25 04:58:08 -06:00
|
|
|
|
2024-01-13 04:46:07 -06:00
|
|
|
const {
|
|
|
|
FLECKS_CORE_ROOT = process.cwd(),
|
|
|
|
} = process.env;
|
|
|
|
|
2024-01-16 00:28:20 -06:00
|
|
|
exports.hooks = {
|
2022-08-10 10:09:02 -05:00
|
|
|
'@flecks/core.commands': commands,
|
|
|
|
'@flecks/core.config': () => ({
|
|
|
|
/**
|
2023-11-30 21:41:42 -06:00
|
|
|
* Webpack stats configuration.
|
2022-08-10 10:09:02 -05:00
|
|
|
*/
|
|
|
|
stats: {
|
|
|
|
colors: true,
|
2023-11-30 21:41:42 -06:00
|
|
|
errorDetails: true,
|
2022-08-10 10:09:02 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
'@flecks/core.targets': () => ['fleck'],
|
2024-01-16 00:28:20 -06:00
|
|
|
'@flecks/fleck.processAssets': async (assets, compilation, flecks) => {
|
2024-01-13 04:46:07 -06:00
|
|
|
const {RawSource} = compilation.compiler.webpack.sources;
|
|
|
|
const packageJson = assets['package.json'];
|
|
|
|
const json = JSON.parse(packageJson.source().toString());
|
|
|
|
const {files} = json;
|
|
|
|
// Add defaults.
|
2024-01-16 00:28:20 -06:00
|
|
|
files.push('build');
|
|
|
|
// Add source if it exists.
|
|
|
|
if ((await glob(join(FLECKS_CORE_ROOT, 'src/**/*.js'))).length > 0) {
|
|
|
|
files.push('src');
|
|
|
|
}
|
2024-01-13 04:46:07 -06:00
|
|
|
// Add tests if they exist.
|
2024-01-16 00:28:20 -06:00
|
|
|
const testFiles = await glob(join(FLECKS_CORE_ROOT, 'test/**/*.js'));
|
2024-01-13 04:46:07 -06:00
|
|
|
if (testFiles.length > 0) {
|
2024-01-19 05:17:37 -06:00
|
|
|
files.push('test');
|
2024-01-13 04:46:07 -06:00
|
|
|
}
|
|
|
|
// Let others have a say.
|
2024-01-16 00:28:20 -06:00
|
|
|
await flecks.invokeSequentialAsync('@flecks/fleck.packageJson', json, compilation);
|
2024-01-13 04:46:07 -06:00
|
|
|
// Add any sourcemaps.
|
|
|
|
json.files = json.files
|
|
|
|
.map((filename) => {
|
|
|
|
const maybeWithMap = [filename];
|
|
|
|
if (compilation.assets[`${filename}.map`]) {
|
|
|
|
maybeWithMap.push(`${filename}.map`);
|
|
|
|
}
|
|
|
|
return maybeWithMap;
|
|
|
|
})
|
|
|
|
.flat();
|
|
|
|
// Sort and uniquify.
|
|
|
|
json.files = [...new Set(json.files.sort((l, r) => (l < r ? -1 : 1)))];
|
|
|
|
compilation.updateAsset('package.json', new RawSource(JSON.stringify(json, null, 2)));
|
|
|
|
},
|
2022-02-25 04:58:08 -06:00
|
|
|
};
|