mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-04-06 15:30:30 +08:00
feat(build): Add styles.less in build.
This commit is contained in:
parent
ae93232123
commit
d0147743ec
36
packages/build/src/build/buildStyles.js
Normal file
36
packages/build/src/build/buildStyles.js
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2020-2021 Lowdefy, Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
function buildStyles({ components, context }) {
|
||||
components.styles = [];
|
||||
const styles = new Set();
|
||||
|
||||
Object.entries(components.types.blocks).forEach(([blockName, block]) => {
|
||||
styles.add(
|
||||
...(context.types.styles[block.package].default || []).map(
|
||||
(style) => `${block.package}/${style}`
|
||||
)
|
||||
);
|
||||
styles.add(
|
||||
...(context.types.styles[block.package][blockName] || []).map(
|
||||
(style) => `${block.package}/${style}`
|
||||
)
|
||||
);
|
||||
});
|
||||
components.styles = [...styles].filter((style) => !!style);
|
||||
}
|
||||
|
||||
export default buildStyles;
|
@ -83,13 +83,6 @@ function buildTypes({ components, context }) {
|
||||
// store: components.types.operators.server,
|
||||
// typeClass: 'Operator',
|
||||
// });
|
||||
|
||||
// TODO: Handle styles
|
||||
const blocksPackages = new Set();
|
||||
Object.values(components.types.blocks).forEach((typeDef) => {
|
||||
blocksPackages.add(typeDef.package);
|
||||
});
|
||||
components.styles = context.types.styles.filter((style) => blocksPackages.has(style.package));
|
||||
}
|
||||
|
||||
export default buildTypes;
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright 2020-2021 Lowdefy, Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { nunjucksFunction } from '@lowdefy/nunjucks';
|
||||
|
||||
const template = `@import '@lowdefy/layout/style.less';
|
||||
{% for style in styles -%}
|
||||
@import '{{ style }}';
|
||||
{% endfor -%}
|
||||
`;
|
||||
|
||||
async function writeStyleImports({ components, context }) {
|
||||
const templateFn = nunjucksFunction(template);
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/styles.less',
|
||||
content: templateFn({ styles: components.styles }),
|
||||
});
|
||||
}
|
||||
|
||||
export default writeStyleImports;
|
@ -28,6 +28,7 @@ import buildConnections from './build/buildConnections.js';
|
||||
import buildMenu from './build/buildMenu.js';
|
||||
import buildPages from './build/buildPages/buildPages.js';
|
||||
import buildRefs from './build/buildRefs/buildRefs.js';
|
||||
import buildStyles from './build/buildStyles.js';
|
||||
import buildTypes from './build/buildTypes.js';
|
||||
import cleanBuildDirectory from './build/cleanBuildDirectory.js';
|
||||
import testSchema from './build/testSchema.js';
|
||||
@ -35,13 +36,14 @@ import validateApp from './build/validateApp.js';
|
||||
import validateConfig from './build/validateConfig.js';
|
||||
import writeApp from './build/writeApp.js';
|
||||
import writeBlockImports from './build/writePluginImports/writeBlockImports.js';
|
||||
import writeConnectionImports from './build/writePluginImports/writeConnectionImports.js';
|
||||
import writeConfig from './build/writeConfig.js';
|
||||
import writeConnectionImports from './build/writePluginImports/writeConnectionImports.js';
|
||||
import writeConnections from './build/writeConnections.js';
|
||||
import writeGlobal from './build/writeGlobal.js';
|
||||
import writeMenus from './build/writeMenus.js';
|
||||
import writePages from './build/writePages.js';
|
||||
import writeRequests from './build/writeRequests.js';
|
||||
import writeStyleImports from './build/writePluginImports/writeStyleImports.js';
|
||||
import writeTypes from './build/writeTypes.js';
|
||||
|
||||
async function createContext(options) {
|
||||
@ -91,6 +93,7 @@ async function build(options) {
|
||||
await buildPages({ components, context });
|
||||
await buildMenu({ components, context });
|
||||
await buildTypes({ components, context });
|
||||
await buildStyles({ components, context });
|
||||
await cleanBuildDirectory({ context });
|
||||
await writeApp({ components, context });
|
||||
await writeConnections({ components, context });
|
||||
@ -102,7 +105,7 @@ async function build(options) {
|
||||
await writeTypes({ components, context });
|
||||
await writeBlockImports({ components, context });
|
||||
await writeConnectionImports({ components, context });
|
||||
// TODO: write style file
|
||||
await writeStyleImports({ components, context });
|
||||
// TODO: write icons file
|
||||
// TODO: add plugins to package.json
|
||||
} catch (error) {
|
||||
|
@ -43,7 +43,7 @@ async function generateDefaultTypes() {
|
||||
client: {},
|
||||
server: {},
|
||||
},
|
||||
styles: [],
|
||||
styles: {},
|
||||
};
|
||||
|
||||
await Promise.all(
|
||||
@ -93,14 +93,8 @@ async function generateDefaultTypes() {
|
||||
version,
|
||||
});
|
||||
|
||||
if (type.isArray(types.styles)) {
|
||||
types.styles.forEach((pathName) => {
|
||||
defaultTypes.styles.push({
|
||||
path: pathName,
|
||||
package: packageName,
|
||||
version: packageFile.devDependencies[packageName],
|
||||
});
|
||||
});
|
||||
if (type.isObject(types.styles)) {
|
||||
defaultTypes.styles[packageName] = types.styles;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user