62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
const { execSync } = require('child_process');
|
|
|
|
const parseModules = (modules) => {
|
|
let result = [];
|
|
|
|
Object.keys(modules).forEach((key, index) => {
|
|
result[key] = typeof modules[key] === 'boolean' ? JSON.stringify(modules[key]) : modules[key];
|
|
});
|
|
|
|
return result;
|
|
};
|
|
|
|
export interface IComponents {
|
|
[key: string]: {
|
|
version: number
|
|
selector: string
|
|
entrypoints: string[]
|
|
version_js: number
|
|
version_css: number
|
|
template: string
|
|
};
|
|
}
|
|
|
|
type IComponentEntrypoints = Map<string,Set<string>>;
|
|
|
|
const generateComponentEntrypoints = (components: IComponents): IComponentEntrypoints => {
|
|
const entrypoints:IComponentEntrypoints = new Map();
|
|
|
|
for (const [name, component] of Object.entries(components)) {
|
|
for (const entrypoint of component.entrypoints) {
|
|
if (!entrypoints.has(entrypoint)) {
|
|
entrypoints.set(entrypoint, new Set());
|
|
}
|
|
|
|
entrypoints.get(entrypoint).add(name);
|
|
}
|
|
}
|
|
|
|
return entrypoints;
|
|
};
|
|
|
|
console.log('Discovering shop configuration ...');
|
|
|
|
const fullConfig = JSON.parse(execSync('./engine/bin/console kupshop:config:get').toString());
|
|
|
|
console.log('Parsing shop configuration ...');
|
|
|
|
let modules = parseModules(fullConfig.modules);
|
|
let modulesWithValues = parseModules(fullConfig.modulesWithValues);
|
|
let components: IComponents = fullConfig.components;
|
|
let entrypoints = generateComponentEntrypoints(fullConfig.components);
|
|
const hasComponents = Object.keys(components).length > 0;
|
|
|
|
module.exports = {
|
|
fullConfig,
|
|
modules,
|
|
modulesWithValues,
|
|
components,
|
|
hasComponents,
|
|
entrypoints,
|
|
}
|