mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-23 14:39:32 +08:00
fix(build): write config object to output in build
This commit is contained in:
parent
7d269e0563
commit
46ec66d9e0
@ -26,6 +26,7 @@ import buildPages from './build/buildPages';
|
||||
import buildRefs from './build/buildRefs';
|
||||
import cleanOutputDirectory from './build/cleanOutputDirectory';
|
||||
import testSchema from './build/testSchema';
|
||||
import writeConfig from './build/writeConfig';
|
||||
import writeConnections from './build/writeConnections';
|
||||
import writeGlobal from './build/writeGlobal';
|
||||
import writeMenus from './build/writeMenus';
|
||||
@ -57,6 +58,7 @@ async function build(options) {
|
||||
await writeConnections({ components, context });
|
||||
await writeRequests({ components, context });
|
||||
await writePages({ components, context });
|
||||
await writeConfig({ components, context });
|
||||
await writeGlobal({ components, context });
|
||||
await writeMenus({ components, context });
|
||||
} catch (error) {
|
||||
|
@ -93,7 +93,6 @@ data:
|
||||
|
||||
test('multiple schema errors', async () => {
|
||||
const components = {
|
||||
config: 'config',
|
||||
pages: [
|
||||
{
|
||||
blocks: [
|
||||
|
32
packages/build/src/build/writeConfig.js
Normal file
32
packages/build/src/build/writeConfig.js
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright 2020 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 { type } from '@lowdefy/helpers';
|
||||
|
||||
async function writeConfig({ components, context }) {
|
||||
if (type.isNone(components.config)) {
|
||||
components.config = {};
|
||||
}
|
||||
if (!type.isObject(components.config)) {
|
||||
throw new Error('Config is not an object.');
|
||||
}
|
||||
await context.artifactSetter.set({
|
||||
filePath: 'config.json',
|
||||
content: JSON.stringify(components.config, null, 2),
|
||||
});
|
||||
}
|
||||
|
||||
export default writeConfig;
|
84
packages/build/src/build/writeConfig.test.js
Normal file
84
packages/build/src/build/writeConfig.test.js
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright 2020 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 writeConfig from './writeConfig';
|
||||
import testContext from '../test/testContext';
|
||||
|
||||
const mockSet = jest.fn();
|
||||
|
||||
const artifactSetter = {
|
||||
set: mockSet,
|
||||
};
|
||||
|
||||
const context = testContext({ artifactSetter });
|
||||
|
||||
beforeEach(() => {
|
||||
mockSet.mockReset();
|
||||
});
|
||||
|
||||
test('writeConfig', async () => {
|
||||
const components = {
|
||||
config: {
|
||||
key: 'value',
|
||||
},
|
||||
};
|
||||
await writeConfig({ components, context });
|
||||
expect(mockSet.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'config.json',
|
||||
content: `{
|
||||
"key": "value"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test('writeConfig empty config', async () => {
|
||||
const components = {
|
||||
config: {},
|
||||
};
|
||||
await writeConfig({ components, context });
|
||||
expect(mockSet.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'config.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test('writeConfig config undefined', async () => {
|
||||
const components = {};
|
||||
await writeConfig({ components, context });
|
||||
expect(mockSet.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'config.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test('writeConfig config not an object', async () => {
|
||||
const components = {
|
||||
config: 'config',
|
||||
};
|
||||
await expect(writeConfig({ components, context })).rejects.toThrow('Config is not an object.');
|
||||
});
|
@ -225,9 +225,15 @@
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"version": {
|
||||
"type": "string"
|
||||
},
|
||||
"config": {
|
||||
"type": "object"
|
||||
},
|
||||
"global": {
|
||||
"type": "object"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user