@lowdefy/build 4.0.0-alpha.1 → 4.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/build/addDefaultPages/404.js +36 -41
  2. package/dist/build/addDefaultPages/addDefaultPages.js +6 -2
  3. package/dist/build/buildAuth/getPageRoles.js +1 -2
  4. package/dist/build/buildConnections.js +1 -2
  5. package/dist/build/buildIcons.js +91 -0
  6. package/dist/build/buildPages/buildBlock/buildEvents.js +4 -1
  7. package/dist/build/buildPages/buildBlock/buildRequests.js +1 -2
  8. package/dist/build/buildPages/buildBlock/countBlockOperators.js +2 -4
  9. package/dist/build/buildRefs/buildRefs.js +1 -2
  10. package/dist/build/buildRefs/getUserJavascriptFunction.js +6 -3
  11. package/dist/build/buildRefs/makeRefDefinition.js +1 -2
  12. package/dist/build/buildRefs/parseRefContent.js +2 -2
  13. package/dist/build/buildRefs/recursiveBuild.js +1 -2
  14. package/dist/build/buildRefs/runTransformer.js +5 -1
  15. package/dist/build/buildStyles.js +29 -0
  16. package/dist/build/buildTypes.js +36 -40
  17. package/dist/build/cleanBuildDirectory.js +1 -1
  18. package/dist/build/copyPublicFolder.js +23 -0
  19. package/dist/build/updateServerPackageJson.js +46 -0
  20. package/dist/build/validateApp.js +2 -4
  21. package/dist/build/validateConfig.js +12 -8
  22. package/dist/build/writeApp.js +1 -5
  23. package/dist/build/writeConfig.js +1 -5
  24. package/dist/build/writeConnections.js +1 -4
  25. package/dist/build/writeGlobal.js +2 -6
  26. package/dist/build/writeMenus.js +1 -4
  27. package/dist/build/writePages.js +2 -13
  28. package/dist/build/writePluginImports/generateImportFile.js +36 -0
  29. package/dist/build/writePluginImports/writeActionImports.js +22 -0
  30. package/dist/build/writePluginImports/writeBlockImports.js +5 -22
  31. package/dist/build/writePluginImports/writeConnectionImports.js +5 -22
  32. package/dist/build/writePluginImports/writeIconImports.js +31 -0
  33. package/dist/build/writePluginImports/writeOperatorImports.js +26 -0
  34. package/dist/build/writePluginImports/writeStyleImports.js +27 -0
  35. package/dist/build/writeRequests.js +2 -7
  36. package/dist/build/writeTypes.js +1 -4
  37. package/dist/defaultTypes.json +1418 -19
  38. package/dist/index.js +129 -100
  39. package/dist/lowdefySchema.js +29 -12
  40. package/dist/scripts/generateDefaultTypes.js +35 -26
  41. package/dist/scripts/run.js +12 -11
  42. package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +2 -5
  43. package/dist/test/buildRefs/testBuildRefsErrorResolver.js +1 -1
  44. package/dist/test/buildRefs/testBuildRefsNullResolver.js +1 -1
  45. package/dist/test/buildRefs/testBuildRefsParsingResolver.js +1 -1
  46. package/dist/test/buildRefs/testBuildRefsResolver.js +1 -1
  47. package/dist/test/buildRefs/testBuildRefsTransform.js +1 -1
  48. package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +1 -1
  49. package/dist/test/testContext.js +11 -18
  50. package/dist/utils/formatErrorMessage.js +1 -1
  51. package/dist/utils/{files/readConfigFile.js → readConfigFile.js} +2 -2
  52. package/dist/utils/{files/writeBuildArtifact.js → writeBuildArtifact.js} +3 -6
  53. package/package.json +42 -16
@@ -12,45 +12,40 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ // TODO: temp fix while waiting for blocks-antd
16
- export default {
15
+ */ export default {
17
16
  id: '404',
18
- type: 'Box'
19
- }; // export default {
20
- // id: '404',
21
- // type: 'Result',
22
- // style: {
23
- // minHeight: '100vh',
24
- // },
25
- // properties: {
26
- // status: 404,
27
- // title: '404',
28
- // subTitle: 'Sorry, the page you are visiting does not exist.',
29
- // },
30
- // areas: {
31
- // extra: {
32
- // blocks: [
33
- // {
34
- // id: 'home',
35
- // type: 'Button',
36
- // properties: {
37
- // title: 'Go to home page',
38
- // type: 'Link',
39
- // icon: 'HomeOutlined',
40
- // },
41
- // events: {
42
- // onClick: [
43
- // {
44
- // id: 'home',
45
- // type: 'Link',
46
- // params: {
47
- // home: true,
48
- // },
49
- // },
50
- // ],
51
- // },
52
- // },
53
- // ],
54
- // },
55
- // },
56
- // };
17
+ type: 'Result',
18
+ style: {
19
+ minHeight: '100vh'
20
+ },
21
+ properties: {
22
+ status: 404,
23
+ title: '404',
24
+ subTitle: 'Sorry, the page you are visiting does not exist.'
25
+ },
26
+ areas: {
27
+ extra: {
28
+ blocks: [
29
+ {
30
+ id: 'home',
31
+ type: 'Button',
32
+ properties: {
33
+ title: 'Go to home page',
34
+ type: 'Link'
35
+ },
36
+ events: {
37
+ onClick: [
38
+ {
39
+ id: 'home',
40
+ type: 'Link',
41
+ params: {
42
+ home: true
43
+ }
44
+ },
45
+ ]
46
+ }
47
+ },
48
+ ]
49
+ }
50
+ }
51
+ };
@@ -26,8 +26,12 @@ async function addDefaultPages({ components }) {
26
26
  if (!type.isArray(components.pages)) {
27
27
  throw new Error('lowdefy.pages is not an array.');
28
28
  }
29
- const pageIds = components.pages.map((page)=>page.id
30
- );
29
+ const pageIds = components.pages.map((page, index)=>{
30
+ if (!type.isObject(page)) {
31
+ throw new Error(`pages[${index}] is not an object. Received ${JSON.stringify(page)}`);
32
+ }
33
+ return page.id;
34
+ });
31
35
  // deep copy to avoid mutating defaultConfig
32
36
  const filteredDefaultPages = defaultPages.filter((defaultPage)=>!pageIds.includes(defaultPage.id)
33
37
  );
@@ -14,8 +14,7 @@
14
14
  limitations under the License.
15
15
  */ function getPageRoles({ components }) {
16
16
  const roles = components.config.auth.pages.roles;
17
- const pageRoles = {
18
- };
17
+ const pageRoles = {};
19
18
  Object.keys(roles).forEach((roleName)=>{
20
19
  roles[roleName].forEach((pageId)=>{
21
20
  if (!pageRoles[pageId]) {
@@ -36,8 +36,7 @@ async function buildConnections({ components , context }) {
36
36
  context.typeCounters.connections.increment(connection.type);
37
37
  connection.connectionId = connection.id;
38
38
  connection.id = `connection:${connection.id}`;
39
- countOperators(connection.properties || {
40
- }, {
39
+ countOperators(connection.properties || {}, {
41
40
  counter: context.typeCounters.operators.server
42
41
  });
43
42
  });
@@ -0,0 +1,91 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ const iconPackages = {
16
+ 'react-icons/ai': /"(Ai[A-Z0-9]\w*)"/gm,
17
+ 'react-icons/bs': /"(Bs[A-Z0-9]\w*)"/gm,
18
+ 'react-icons/bi': /"(Bi[A-Z0-9]\w*)"/gm,
19
+ 'react-icons/di': /"(Di[A-Z0-9]\w*)"/gm,
20
+ 'react-icons/fi': /"(Fi[A-Z0-9]\w*)"/gm,
21
+ 'react-icons/fc': /"(Fc[A-Z0-9]\w*)"/gm,
22
+ 'react-icons/fa': /"(Fa[A-Z0-9]\w*)"/gm,
23
+ 'react-icons/gi': /"(Gi[A-Z0-9]\w*)"/gm,
24
+ 'react-icons/go': /"(Go[A-Z0-9]\w*)"/gm,
25
+ 'react-icons/gr': /"(Gr[A-Z0-9]\w*)"/gm,
26
+ 'react-icons/hi': /"(Hi[A-Z0-9]\w*)"/gm,
27
+ 'react-icons/im': /"(Im[A-Z0-9]\w*)"/gm,
28
+ 'react-icons/io': /"(IoIos[A-Z0-9]\w*)"/gm,
29
+ 'react-icons/io5': /"(Io[A-Z0-9]\w*)"/gm,
30
+ 'react-icons/md': /"(Md[A-Z0-9]\w*)"/gm,
31
+ 'react-icons/ri': /"(Ri[A-Z0-9]\w*)"/gm,
32
+ 'react-icons/si': /"(Si[A-Z0-9]\w*)"/gm,
33
+ 'react-icons/ti': /"(Ti[A-Z0-9]\w*)"/gm,
34
+ 'react-icons/vsc': /"(Vsc[A-Z0-9]\w*)"/gm,
35
+ 'react-icons/wi': /"(Wi[A-Z0-9]\w*)"/gm,
36
+ 'react-icons/cg': /"(Cg[A-Z0-9]\w*)"/gm
37
+ };
38
+ function getConfigIcons({ components , icons , regex }) {
39
+ [
40
+ ...JSON.stringify(components.global || {}).matchAll(regex)
41
+ ].map((match)=>icons.add(match[1])
42
+ );
43
+ [
44
+ ...JSON.stringify(components.menus || []).matchAll(regex)
45
+ ].map((match)=>icons.add(match[1])
46
+ );
47
+ [
48
+ ...JSON.stringify(components.pages || []).matchAll(regex)
49
+ ].map((match)=>icons.add(match[1])
50
+ );
51
+ }
52
+ function getBlockDefaultIcons({ components , context , icons , regex }) {
53
+ Object.entries(components.types.blocks).forEach(([blockName, block])=>{
54
+ context.types.icons[block.package][blockName].forEach((icon)=>{
55
+ [
56
+ ...JSON.stringify(icon).matchAll(regex)
57
+ ].map((match)=>icons.add(match[1])
58
+ );
59
+ });
60
+ });
61
+ }
62
+ function buildIcons({ components , context }) {
63
+ components.icons = [];
64
+ Object.entries(iconPackages).forEach(([iconPackage, regex])=>{
65
+ const icons = new Set();
66
+ // TODO: Can we do better than this?
67
+ // Add default icons
68
+ if (iconPackage === 'react-icons/ai') {
69
+ icons.add('AiOutlineLoading3Quarters');
70
+ icons.add('AiOutlineExclamationCircle');
71
+ }
72
+ getConfigIcons({
73
+ components,
74
+ icons,
75
+ regex
76
+ });
77
+ getBlockDefaultIcons({
78
+ components,
79
+ context,
80
+ icons,
81
+ regex
82
+ });
83
+ components.icons.push({
84
+ icons: [
85
+ ...icons
86
+ ],
87
+ package: iconPackage
88
+ });
89
+ });
90
+ }
91
+ export default buildIcons;
@@ -44,7 +44,10 @@ function buildEvents(block, pageContext) {
44
44
  if (!type.isArray(block.events[key].try)) {
45
45
  throw new Error(`Events must be an array of actions at "${block.blockId}" in event "${key}" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].try)}`);
46
46
  }
47
- if (!type.isArray(block.events[key].catch) && !type.isNone(block.events[key].catch)) {
47
+ if (type.isNone(block.events[key].catch)) {
48
+ block.events[key].catch = [];
49
+ }
50
+ if (!type.isArray(block.events[key].catch)) {
48
51
  throw new Error(`Catch events must be an array of actions at "${block.blockId}" in event "${key}" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].catch)}`);
49
52
  }
50
53
  const checkDuplicateActionId = createCheckDuplicateId({
@@ -32,8 +32,7 @@ function buildRequest(request, pageContext) {
32
32
  throw new Error(`Request type is not a string at at request at "${request.id}" at page "${pageId}". Received ${JSON.stringify(request.type)}.`);
33
33
  }
34
34
  typeCounters.requests.increment(request.type);
35
- if (type.isUndefined(request.payload)) request.payload = {
36
- };
35
+ if (type.isUndefined(request.payload)) request.payload = {};
37
36
  if (!type.isObject(request.payload)) {
38
37
  throw new Error(`Request "${request.id}" at page "${pageId}" payload should be an object.`);
39
38
  }
@@ -20,12 +20,10 @@ function countBlockOperators(block, { typeCounters }) {
20
20
  counter: typeCounters.operators.client
21
21
  });
22
22
  (requests || []).forEach((request)=>{
23
- countOperators(request.payload || {
24
- }, {
23
+ countOperators(request.payload || {}, {
25
24
  counter: typeCounters.operators.client
26
25
  });
27
- countOperators(request.properties || {
28
- }, {
26
+ countOperators(request.properties || {}, {
29
27
  counter: typeCounters.operators.server
30
28
  });
31
29
  });
@@ -20,7 +20,6 @@ async function buildRefs({ context }) {
20
20
  refDef: makeRefDefinition('lowdefy.yaml'),
21
21
  count: 0
22
22
  });
23
- return components || {
24
- };
23
+ return components || {};
25
24
  }
26
25
  export default buildRefs;
@@ -13,9 +13,12 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import path from 'path';
16
- import { readFile } from '@lowdefy/node-utils';
17
16
  async function getUserJavascriptFunction({ context , filePath }) {
18
- const jsFile = await readFile(path.resolve(context.configDirectory, filePath));
19
- return eval(jsFile);
17
+ try {
18
+ return (await import(path.resolve(context.directories.config, filePath))).default;
19
+ } catch (error) {
20
+ context.logger.error(`Error importing ${filePath}.`);
21
+ throw Error(error);
22
+ }
20
23
  }
21
24
  export default getUserJavascriptFunction;
@@ -23,8 +23,7 @@ function makeRefDefinition(refDefinition) {
23
23
  resolver: get(refDefinition, 'resolver'),
24
24
  transformer: get(refDefinition, 'transformer'),
25
25
  vars: get(refDefinition, 'vars', {
26
- default: {
27
- }
26
+ default: {}
28
27
  })
29
28
  };
30
29
  }
@@ -15,7 +15,7 @@
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import { getFileExtension, getFileSubExtension } from '@lowdefy/node-utils';
17
17
  import JSON5 from 'json5';
18
- import YAML from 'js-yaml';
18
+ import YAML from 'yaml';
19
19
  import parseNunjucks from './parseNunjucks.js';
20
20
  function parseRefContent({ content , refDef }) {
21
21
  const { path , vars } = refDef;
@@ -26,7 +26,7 @@ function parseRefContent({ content , refDef }) {
26
26
  ext = getFileSubExtension(path);
27
27
  }
28
28
  if (ext === 'yaml' || ext === 'yml') {
29
- return YAML.load(content);
29
+ return YAML.parse(content);
30
30
  }
31
31
  if (ext === 'json') {
32
32
  return JSON5.parse(content);
@@ -27,8 +27,7 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
27
27
  referencedFrom
28
28
  });
29
29
  const { foundRefs , fileContentBuiltRefs } = getRefsFromFile(fileContent);
30
- const parsedFiles = {
31
- };
30
+ const parsedFiles = {};
32
31
  // Since we can have references in the variables of a reference, we need to first parse
33
32
  // the deeper nodes, so we can use those parsed files in references higher in the tree.
34
33
  // To do this, since foundRefs is an array of ref definitions that are in order of the
@@ -19,7 +19,11 @@ async function runTransformer({ context , parsedFile , refDef }) {
19
19
  context,
20
20
  filePath: refDef.transformer
21
21
  });
22
- return transformerFn(parsedFile, refDef.vars);
22
+ try {
23
+ return transformerFn(parsedFile, refDef.vars);
24
+ } catch (error) {
25
+ throw Error(`Error calling transformer "${refDef.transformer}" from "${refDef.path}": ${error.message}`);
26
+ }
23
27
  }
24
28
  return parsedFile;
25
29
  }
@@ -0,0 +1,29 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function buildStyles({ components , context }) {
16
+ components.styles = [];
17
+ const styles = new Set();
18
+ Object.entries(components.types.blocks).forEach(([blockName, block])=>{
19
+ styles.add(...(context.types.styles[block.package].default || []).map((style)=>`${block.package}/${style}`
20
+ ));
21
+ styles.add(...(context.types.styles[block.package][blockName] || []).map((style)=>`${block.package}/${style}`
22
+ ));
23
+ });
24
+ components.styles = [
25
+ ...styles
26
+ ].filter((style)=>!!style
27
+ );
28
+ }
29
+ export default buildStyles;
@@ -12,10 +12,14 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function buildTypeClass({ counter , definitions , store , typeClass }) {
15
+ */ function buildTypeClass(context, { counter , definitions , store , typeClass , warnIfMissing =false }) {
16
16
  const counts = counter.getCounts();
17
17
  Object.keys(counts).forEach((typeName)=>{
18
18
  if (!definitions[typeName]) {
19
+ if (warnIfMissing) {
20
+ context.logger.warn(`${typeClass} type "${typeName}" was used but is not defined.`);
21
+ return;
22
+ }
19
23
  throw new Error(`${typeClass} type "${typeName}" was used but is not defined.`);
20
24
  }
21
25
  store[typeName] = {
@@ -27,64 +31,56 @@
27
31
  }
28
32
  function buildTypes({ components , context }) {
29
33
  const { typeCounters } = context;
34
+ // Add operators used by form validation
35
+ typeCounters.operators.client.increment('_not');
36
+ typeCounters.operators.client.increment('_type');
30
37
  components.types = {
31
- actions: {
32
- },
33
- blocks: {
34
- },
35
- connections: {
36
- },
37
- requests: {
38
- },
38
+ actions: {},
39
+ blocks: {},
40
+ connections: {},
41
+ requests: {},
39
42
  operators: {
40
- client: {
41
- },
42
- server: {
43
- }
43
+ client: {},
44
+ server: {}
44
45
  }
45
46
  };
46
- // buildTypeClass({
47
- // counter: typeCounters.actions,
48
- // definitions: context.types.actions,
49
- // store: components.types.actions,
50
- // typeClass: 'Action',
51
- // });
52
- buildTypeClass({
47
+ buildTypeClass(context, {
48
+ counter: typeCounters.actions,
49
+ definitions: context.types.actions,
50
+ store: components.types.actions,
51
+ typeClass: 'Action'
52
+ });
53
+ buildTypeClass(context, {
53
54
  counter: typeCounters.blocks,
54
55
  definitions: context.types.blocks,
55
56
  store: components.types.blocks,
56
57
  typeClass: 'Block'
57
58
  });
58
- buildTypeClass({
59
+ buildTypeClass(context, {
59
60
  counter: typeCounters.connections,
60
61
  definitions: context.types.connections,
61
62
  store: components.types.connections,
62
63
  typeClass: 'Connection'
63
64
  });
64
- buildTypeClass({
65
+ buildTypeClass(context, {
65
66
  counter: typeCounters.requests,
66
67
  definitions: context.types.requests,
67
68
  store: components.types.requests,
68
69
  typeClass: 'Request'
69
70
  });
70
- // buildTypeClass({
71
- // counter: typeCounters.operators.client,
72
- // definitions: context.types.operators.client,
73
- // store: components.types.operators.client,
74
- // typeClass: 'Operator',
75
- // });
76
- // buildTypeClass({
77
- // counter: typeCounters.operators.server,
78
- // definitions: context.types.operators.server,
79
- // store: components.types.operators.server,
80
- // typeClass: 'Operator',
81
- // });
82
- // TODO: Handle styles
83
- const blocksPackages = new Set();
84
- Object.values(components.types.blocks).forEach((typeDef)=>{
85
- blocksPackages.add(typeDef.package);
71
+ buildTypeClass(context, {
72
+ counter: typeCounters.operators.client,
73
+ definitions: context.types.operators.client,
74
+ store: components.types.operators.client,
75
+ typeClass: 'Operator',
76
+ warnIfMissing: true
77
+ });
78
+ buildTypeClass(context, {
79
+ counter: typeCounters.operators.server,
80
+ definitions: context.types.operators.server,
81
+ store: components.types.operators.server,
82
+ typeClass: 'Operator',
83
+ warnIfMissing: true
86
84
  });
87
- components.styles = context.types.styles.filter((style)=>blocksPackages.has(style.package)
88
- );
89
85
  }
90
86
  export default buildTypes;
@@ -14,6 +14,6 @@
14
14
  limitations under the License.
15
15
  */ import { cleanDirectory } from '@lowdefy/node-utils';
16
16
  async function cleanBuildDirectory({ context }) {
17
- return cleanDirectory(context.buildDirectory);
17
+ await cleanDirectory(context.directories.build);
18
18
  }
19
19
  export default cleanBuildDirectory;
@@ -0,0 +1,23 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import path from 'path';
16
+ import fs from 'fs';
17
+ import { copyDirectory } from '@lowdefy/node-utils';
18
+ async function copyPublicFolder({ context }) {
19
+ if (context.directories.config === context.directories.server) return;
20
+ if (!fs.existsSync(path.resolve(context.directories.config, 'public'))) return;
21
+ await copyDirectory(path.resolve(context.directories.config, 'public'), path.resolve(context.directories.server, 'public'));
22
+ }
23
+ export default copyPublicFolder;
@@ -0,0 +1,46 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import path from 'path';
16
+ import { readFile, writeFile } from '@lowdefy/node-utils';
17
+ async function updateServerPackageJson({ components , context }) {
18
+ const filePath = path.join(context.directories.server, 'package.json');
19
+ const packageJsonContent = await readFile(filePath);
20
+ const packageJson = JSON.parse(packageJsonContent);
21
+ const dependencies = packageJson.dependencies;
22
+ function getPackages(types) {
23
+ Object.values(types).forEach((type)=>{
24
+ dependencies[type.package] = type.version;
25
+ });
26
+ }
27
+ getPackages(components.types.actions);
28
+ getPackages(components.types.blocks);
29
+ getPackages(components.types.connections);
30
+ getPackages(components.types.requests);
31
+ getPackages(components.types.operators.client);
32
+ getPackages(components.types.operators.server);
33
+ // Sort dependencies
34
+ packageJson.dependencies = {};
35
+ Object.keys(dependencies).sort().forEach((name)=>{
36
+ packageJson.dependencies[name] = dependencies[name];
37
+ });
38
+ const newPackageJsonContent = JSON.stringify(packageJson, null, 2).concat('\n');
39
+ // Only write package.json if it has changed since dev server will
40
+ // be watching the file to trigger reinstalls
41
+ if (newPackageJsonContent !== packageJsonContent) {
42
+ context.logger.warn('Plugin dependencies have changed. Updating "package.json".');
43
+ await writeFile(filePath, newPackageJsonContent);
44
+ }
45
+ }
46
+ export default updateServerPackageJson;
@@ -15,15 +15,13 @@
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  async function validateApp({ components }) {
17
17
  if (type.isNone(components.app)) {
18
- components.app = {
19
- };
18
+ components.app = {};
20
19
  }
21
20
  if (!type.isObject(components.app)) {
22
21
  throw new Error('lowdefy.app is not an object.');
23
22
  }
24
23
  if (type.isNone(components.app.html)) {
25
- components.app.html = {
26
- };
24
+ components.app.html = {};
27
25
  }
28
26
  if (type.isNone(components.app.html.appendBody)) {
29
27
  components.app.html.appendBody = '';
@@ -17,23 +17,27 @@ import { validate } from '@lowdefy/ajv';
17
17
  import lowdefySchema from '../lowdefySchema.js';
18
18
  async function validateConfig({ components }) {
19
19
  if (type.isNone(components.config)) {
20
- components.config = {
21
- };
20
+ components.config = {};
22
21
  }
23
22
  if (!type.isObject(components.config)) {
24
23
  throw new Error('lowdefy.config is not an object.');
25
24
  }
26
25
  if (type.isNone(components.config.auth)) {
27
- components.config.auth = {
28
- };
26
+ components.config.auth = {};
29
27
  }
30
28
  if (type.isNone(components.config.auth.pages)) {
31
- components.config.auth.pages = {
32
- };
29
+ components.config.auth.pages = {};
33
30
  }
34
31
  if (type.isNone(components.config.auth.pages.roles)) {
35
- components.config.auth.pages.roles = {
36
- };
32
+ components.config.auth.pages.roles = {};
33
+ }
34
+ if (type.isNone(components.config.theme)) {
35
+ components.config.theme = {};
36
+ }
37
+ if (type.isString(components.config.basePath)) {
38
+ if (components.config.basePath[0] !== '/') {
39
+ throw Error('Base path must start with "/".');
40
+ }
37
41
  }
38
42
  validate({
39
43
  schema: lowdefySchema.definitions.authConfig,
@@ -13,10 +13,6 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ async function writeApp({ components , context }) {
16
- await context.writeBuildArtifact({
17
- filePath: 'app.json',
18
- content: JSON.stringify(components.app || {
19
- }, null, 2)
20
- });
16
+ await context.writeBuildArtifact('app.json', JSON.stringify(components.app || {}, null, 2));
21
17
  }
22
18
  export default writeApp;
@@ -13,10 +13,6 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ async function writeConfig({ components , context }) {
16
- await context.writeBuildArtifact({
17
- filePath: 'config.json',
18
- content: JSON.stringify(components.config || {
19
- }, null, 2)
20
- });
16
+ await context.writeBuildArtifact('config.json', JSON.stringify(components.config || {}, null, 2));
21
17
  }
22
18
  export default writeConfig;
@@ -19,10 +19,7 @@ async function writeConnections({ components , context }) {
19
19
  throw new Error(`Connections is not an array.`);
20
20
  }
21
21
  const writePromises = components.connections.map(async (connection)=>{
22
- await context.writeBuildArtifact({
23
- filePath: `connections/${connection.connectionId}.json`,
24
- content: JSON.stringify(connection, null, 2)
25
- });
22
+ await context.writeBuildArtifact(`connections/${connection.connectionId}.json`, JSON.stringify(connection, null, 2));
26
23
  });
27
24
  return Promise.all(writePromises);
28
25
  }