mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-19 15:01:06 +08:00
feat: Add support for typePrefix on custom plugins.
This commit is contained in:
parent
4ef870a605
commit
d66d395e01
@ -45,8 +45,8 @@ function getConfigIcons({ components, icons, regex }) {
|
||||
}
|
||||
|
||||
function getBlockDefaultIcons({ components, context, icons, regex }) {
|
||||
Object.entries(components.types.blocks).forEach(([blockName, block]) => {
|
||||
context.typesMap.icons[block.package][blockName].forEach((icon) => {
|
||||
Object.keys(components.types.blocks).forEach((blockName) => {
|
||||
(context.typesMap.icons[blockName] || []).forEach((icon) => {
|
||||
[...JSON.stringify(icon).matchAll(regex)].map((match) => icons.add(match[1]));
|
||||
});
|
||||
});
|
||||
|
@ -20,12 +20,12 @@ function buildStyles({ components, context }) {
|
||||
|
||||
Object.entries(components.types.blocks).forEach(([blockName, block]) => {
|
||||
styles.add(
|
||||
...(context.typesMap.styles[block.package].default || []).map(
|
||||
...(context.typesMap.styles.packages[block.package] || []).map(
|
||||
(style) => `${block.package}/${style}`
|
||||
)
|
||||
);
|
||||
styles.add(
|
||||
...(context.typesMap.styles[block.package][blockName] || []).map(
|
||||
...(context.typesMap.styles.blocks[blockName] || []).map(
|
||||
(style) => `${block.package}/${style}`
|
||||
)
|
||||
);
|
||||
|
@ -28,6 +28,7 @@ function buildTypeClass(
|
||||
throw new Error(`${typeClass} type "${typeName}" was used but is not defined.`);
|
||||
}
|
||||
store[typeName] = {
|
||||
originalTypeName: definitions[typeName].originalTypeName,
|
||||
package: definitions[typeName].package,
|
||||
version: definitions[typeName].version,
|
||||
count: counts[typeName],
|
||||
|
@ -16,19 +16,19 @@
|
||||
import { nunjucksFunction } from '@lowdefy/nunjucks';
|
||||
|
||||
const template = `{%- for import in imports -%}
|
||||
import { {{ import.type }} } from '{{ import.package }}/{{ importPath }}';
|
||||
import { {{ import.originalTypeName }} as {{ import.typeName }} } from '{{ import.package }}/{{ importPath }}';
|
||||
{% endfor -%}
|
||||
export default {
|
||||
{% for import in imports -%}
|
||||
{{ import.type }},
|
||||
{{ import.typeName }},
|
||||
{% endfor -%}
|
||||
}`;
|
||||
};`;
|
||||
|
||||
function generateImportFile({ types, importPath }) {
|
||||
const templateFn = nunjucksFunction(template);
|
||||
const imports = Object.keys(types).map((type) => ({
|
||||
type,
|
||||
...types[type],
|
||||
const imports = Object.keys(types).map((typeName) => ({
|
||||
typeName,
|
||||
...types[typeName],
|
||||
}));
|
||||
return templateFn({ imports, importPath });
|
||||
}
|
||||
|
@ -57,7 +57,10 @@ async function generateDefaultTypesMap() {
|
||||
server: {},
|
||||
},
|
||||
requests: {},
|
||||
styles: {},
|
||||
styles: {
|
||||
packages: {},
|
||||
blocks: {},
|
||||
},
|
||||
};
|
||||
|
||||
await Promise.all(
|
||||
|
@ -21,6 +21,7 @@ function createTypeDefinitions({ packageName, store, typeNames, typePrefix, vers
|
||||
typeNames.forEach((typeName) => {
|
||||
store[`${typePrefix}${typeName}`] = {
|
||||
package: packageName,
|
||||
originalTypeName: typeName,
|
||||
version,
|
||||
};
|
||||
});
|
||||
@ -77,11 +78,19 @@ function createPluginTypesMap({ packageName, packageTypes, typePrefix = '', type
|
||||
});
|
||||
|
||||
if (type.isObject(packageTypes.styles)) {
|
||||
typesMap.styles[packageName] = packageTypes.styles;
|
||||
Object.entries(packageTypes.styles).forEach(([blockType, styles]) => {
|
||||
if (blockType === 'default') {
|
||||
typesMap.styles.packages[packageName] = styles;
|
||||
} else {
|
||||
typesMap.styles.blocks[`${typePrefix}${blockType}`] = styles;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (type.isObject(packageTypes.icons)) {
|
||||
typesMap.icons[packageName] = packageTypes.icons;
|
||||
Object.entries(packageTypes.icons).forEach(([blockType, icons]) => {
|
||||
typesMap.icons[`${typePrefix}${blockType}`] = icons;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ import runStart from './runStart.js';
|
||||
async function build({ context }) {
|
||||
context.print.info('Starting server.');
|
||||
context.sendTelemetry({ sendTypes: true });
|
||||
await runStart({ context, directory: context.directory.server });
|
||||
await runStart({ context, directory: context.directories.server });
|
||||
}
|
||||
|
||||
export default build;
|
||||
|
@ -40,7 +40,6 @@ async function run() {
|
||||
};
|
||||
|
||||
const customTypesMap = await createCustomTypesMap({ directories });
|
||||
console.log(customTypesMap);
|
||||
await build({
|
||||
customTypesMap,
|
||||
directories,
|
||||
|
@ -41,25 +41,24 @@ async function createCustomTypesMap({ directories }) {
|
||||
server: {},
|
||||
},
|
||||
requests: {},
|
||||
styles: {},
|
||||
styles: {
|
||||
packages: {},
|
||||
blocks: {},
|
||||
},
|
||||
};
|
||||
|
||||
const pluginDefinitions = await getPluginDefinitions({ directories });
|
||||
|
||||
// TODO: Prefixes in icons and styles
|
||||
// TODO: Should be resolved in order
|
||||
await Promise.all(
|
||||
pluginDefinitions.map(async (plugin) => {
|
||||
const { default: types } = await import(`${plugin.name}/types`);
|
||||
createPluginTypesMap({
|
||||
packageTypes: types,
|
||||
typesMap: customTypesMap,
|
||||
packageName: plugin.name,
|
||||
version: plugin.version,
|
||||
typePrefix: plugin.typePrefix,
|
||||
});
|
||||
})
|
||||
);
|
||||
for (const plugin of pluginDefinitions) {
|
||||
const { default: types } = await import(`${plugin.name}/types`);
|
||||
createPluginTypesMap({
|
||||
packageTypes: types,
|
||||
typesMap: customTypesMap,
|
||||
packageName: plugin.name,
|
||||
version: plugin.version,
|
||||
typePrefix: plugin.typePrefix,
|
||||
});
|
||||
}
|
||||
|
||||
return customTypesMap;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user