@lowdefy/build 4.0.0-alpha.8 → 4.0.0-rc.0

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 (91) hide show
  1. package/dist/build/addDefaultPages/404.js +1 -1
  2. package/dist/build/addDefaultPages/addDefaultPages.js +3 -4
  3. package/dist/build/buildAuth/buildAuth.js +12 -28
  4. package/dist/build/buildAuth/buildAuthPlugins.js +71 -0
  5. package/dist/build/buildAuth/buildPageAuth.js +50 -0
  6. package/dist/build/buildAuth/getPageRoles.js +2 -2
  7. package/dist/build/buildAuth/getProtectedPages.js +7 -9
  8. package/dist/build/buildAuth/validateAuthConfig.js +64 -0
  9. package/dist/build/buildConnections.js +2 -2
  10. package/dist/build/{buildIcons.js → buildImports/buildIconImports.js} +16 -24
  11. package/dist/build/buildImports/buildImports.js +30 -0
  12. package/dist/build/buildImports/buildImportsDev.js +106 -0
  13. package/dist/build/buildImports/buildImportsProd.js +54 -0
  14. package/dist/build/{buildStyles.js → buildImports/buildStyleImports.js} +8 -12
  15. package/dist/build/buildImports/defaultIconsDev.js +584 -0
  16. package/dist/build/buildImports/defaultIconsProd.js +21 -0
  17. package/dist/build/buildMenu.js +10 -14
  18. package/dist/build/buildPages/buildBlock/buildBlock.js +8 -4
  19. package/dist/build/buildPages/buildBlock/buildEvents.js +8 -7
  20. package/dist/build/buildPages/buildBlock/buildRequests.js +1 -1
  21. package/dist/build/buildPages/buildBlock/buildSubBlocks.js +3 -8
  22. package/dist/build/buildPages/buildBlock/countBlockOperators.js +2 -2
  23. package/dist/build/buildPages/buildBlock/countBlockTypes.js +18 -0
  24. package/dist/build/buildPages/buildBlock/moveSkeletonBlocksToArea.js +35 -0
  25. package/dist/build/buildPages/buildBlock/moveSubBlocksToArea.js +1 -1
  26. package/dist/build/buildPages/buildBlock/setBlockId.js +1 -1
  27. package/dist/build/buildPages/buildBlock/validateBlock.js +2 -3
  28. package/dist/build/buildPages/buildPage.js +3 -3
  29. package/dist/build/buildPages/buildPages.js +4 -6
  30. package/dist/build/buildPages/buildTestPage.js +46 -0
  31. package/dist/build/buildRefs/buildRefs.js +11 -5
  32. package/dist/build/buildRefs/evaluateBuildOperators.js +3 -4
  33. package/dist/build/buildRefs/getConfigFile.js +2 -2
  34. package/dist/build/buildRefs/getRefContent.js +1 -1
  35. package/dist/build/buildRefs/getRefPath.js +1 -1
  36. package/dist/build/buildRefs/getRefsFromFile.js +1 -1
  37. package/dist/build/buildRefs/getUserJavascriptFunction.js +3 -2
  38. package/dist/build/buildRefs/makeRefDefinition.js +2 -1
  39. package/dist/build/buildRefs/parseNunjucks.js +1 -1
  40. package/dist/build/buildRefs/parseRefContent.js +9 -4
  41. package/dist/build/buildRefs/populateRefs.js +4 -4
  42. package/dist/build/buildRefs/recursiveBuild.js +6 -6
  43. package/dist/build/buildRefs/runRefResolver.js +1 -1
  44. package/dist/build/buildRefs/runTransformer.js +1 -1
  45. package/dist/build/buildTypes.js +39 -2
  46. package/dist/build/cleanBuildDirectory.js +1 -1
  47. package/dist/build/copyPublicFolder.js +1 -1
  48. package/dist/build/testSchema.js +5 -7
  49. package/dist/build/updateServerPackageJson.js +5 -1
  50. package/dist/build/validateApp.js +2 -2
  51. package/dist/build/validateConfig.js +2 -29
  52. package/dist/build/writeApp.js +1 -1
  53. package/dist/build/writeAuth.js +18 -0
  54. package/dist/build/writeConfig.js +1 -1
  55. package/dist/build/writeConnections.js +1 -1
  56. package/dist/build/writeGlobal.js +1 -1
  57. package/dist/build/writeMenus.js +1 -1
  58. package/dist/build/writePages.js +2 -3
  59. package/dist/build/writePluginImports/generateImportFile.js +2 -7
  60. package/dist/build/writePluginImports/writeActionImports.js +2 -2
  61. package/dist/build/writePluginImports/writeAuthImports.js +34 -0
  62. package/dist/build/writePluginImports/writeBlockImports.js +2 -2
  63. package/dist/build/writePluginImports/writeConnectionImports.js +2 -2
  64. package/dist/build/writePluginImports/writeIconImports.js +2 -2
  65. package/dist/build/writePluginImports/writeOperatorImports.js +5 -5
  66. package/dist/build/writePluginImports/writePluginImports.js +52 -0
  67. package/dist/build/writePluginImports/writeStyleImports.js +10 -3
  68. package/dist/build/writeRequests.js +2 -3
  69. package/dist/build/writeTypes.js +1 -1
  70. package/dist/createContext.js +55 -0
  71. package/dist/{defaultTypesMap.json → defaultTypesMap.js} +989 -388
  72. package/dist/index.js +20 -78
  73. package/dist/lowdefySchema.js +177 -68
  74. package/dist/scripts/generateDefaultTypes.js +22 -4
  75. package/dist/scripts/run.js +5 -4
  76. package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +1 -1
  77. package/dist/test/buildRefs/testBuildRefsErrorResolver.js +1 -1
  78. package/dist/test/buildRefs/testBuildRefsNullResolver.js +1 -1
  79. package/dist/test/buildRefs/testBuildRefsParsingResolver.js +1 -1
  80. package/dist/test/buildRefs/testBuildRefsResolver.js +2 -2
  81. package/dist/test/buildRefs/testBuildRefsTransform.js +1 -1
  82. package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +1 -1
  83. package/dist/test/testContext.js +8 -2
  84. package/dist/utils/countOperators.js +1 -1
  85. package/dist/utils/createCheckDuplicateId.js +1 -1
  86. package/dist/utils/createCounter.js +1 -1
  87. package/dist/utils/createPluginTypesMap.js +29 -1
  88. package/dist/utils/formatErrorMessage.js +1 -1
  89. package/dist/utils/readConfigFile.js +5 -2
  90. package/dist/utils/writeBuildArtifact.js +1 -1
  91. package/package.json +55 -44
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import page404 from './404.js';
17
- async function addDefaultPages({ components }) {
17
+ function addDefaultPages({ components }) {
18
18
  // If not copied, the same object is mutated by build every time
19
19
  // build runs for dev server. See #647
20
20
  const defaultPages = [
@@ -33,8 +33,7 @@ async function addDefaultPages({ components }) {
33
33
  return page.id;
34
34
  });
35
35
  // deep copy to avoid mutating defaultConfig
36
- const filteredDefaultPages = defaultPages.filter((defaultPage)=>!pageIds.includes(defaultPage.id)
37
- );
36
+ const filteredDefaultPages = defaultPages.filter((defaultPage)=>!pageIds.includes(defaultPage.id));
38
37
  components.pages = [
39
38
  ...components.pages,
40
39
  ...filteredDefaultPages
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,37 +13,21 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
- import getPageRoles from './getPageRoles.js';
17
- import getProtectedPages from './getProtectedPages.js';
18
- function buildAuth({ components }) {
19
- const protectedPages = getProtectedPages({
16
+ import buildAuthPlugins from './buildAuthPlugins.js';
17
+ import buildPageAuth from './buildPageAuth.js';
18
+ import validateAuthConfig from './validateAuthConfig.js';
19
+ function buildAuth({ components , context }) {
20
+ const configured = !type.isNone(components.auth);
21
+ validateAuthConfig({
20
22
  components
21
23
  });
22
- const pageRoles = getPageRoles({
24
+ components.auth.configured = configured;
25
+ buildPageAuth({
23
26
  components
24
27
  });
25
- let configPublicPages = [];
26
- if (type.isArray(components.config.auth.pages.public)) {
27
- configPublicPages = components.config.auth.pages.public;
28
- }
29
- (components.pages || []).forEach((page)=>{
30
- if (pageRoles[page.id]) {
31
- if (configPublicPages.includes(page.id)) {
32
- throw new Error(`Page "${page.id}" is both protected by roles ${JSON.stringify(pageRoles[page.id])} and public.`);
33
- }
34
- page.auth = {
35
- public: false,
36
- roles: pageRoles[page.id]
37
- };
38
- } else if (protectedPages.includes(page.id)) {
39
- page.auth = {
40
- public: false
41
- };
42
- } else {
43
- page.auth = {
44
- public: true
45
- };
46
- }
28
+ buildAuthPlugins({
29
+ components,
30
+ context
47
31
  });
48
32
  return components;
49
33
  }
@@ -0,0 +1,71 @@
1
+ /*
2
+ Copyright 2020-2022 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 { type } from '@lowdefy/helpers';
16
+ function buildAuthPlugin({ counter , pluginConfig , typeClass }) {
17
+ if (type.isArray(pluginConfig)) {
18
+ pluginConfig.forEach((plugin)=>{
19
+ if (type.isUndefined(plugin.id)) {
20
+ throw new Error(`Auth ${typeClass} id missing.`);
21
+ }
22
+ if (!type.isString(plugin.id)) {
23
+ throw new Error(`Auth ${typeClass} id is not a string. Received ${JSON.stringify(plugin.id)}.`);
24
+ }
25
+ if (!type.isString(plugin.type)) {
26
+ throw new Error(`Auth ${typeClass} type is not a string at ${typeClass} "${plugin.id}". Received ${JSON.stringify(plugin.type)}.`);
27
+ }
28
+ counter.increment(plugin.type);
29
+ });
30
+ }
31
+ }
32
+ function buildAdapter({ components , context }) {
33
+ const { adapter } = components.auth;
34
+ if (type.isNone(adapter)) {
35
+ return;
36
+ }
37
+ if (type.isUndefined(adapter.id)) {
38
+ throw new Error(`Auth adapter id missing.`);
39
+ }
40
+ if (!type.isString(adapter.id)) {
41
+ throw new Error(`Auth adapter id is not a string. Received ${JSON.stringify(adapter.id)}.`);
42
+ }
43
+ if (!type.isString(adapter.type)) {
44
+ throw new Error(`Auth adapter type is not a string at adapter "${adapter.id}". Received ${JSON.stringify(adapter.type)}.`);
45
+ }
46
+ context.typeCounters.auth.adapters.increment(adapter.type);
47
+ }
48
+ function buildAuthPlugins({ components , context }) {
49
+ const counters = context.typeCounters.auth;
50
+ const authConfig = components.auth;
51
+ buildAdapter({
52
+ components,
53
+ context
54
+ });
55
+ buildAuthPlugin({
56
+ counter: counters.callbacks,
57
+ pluginConfig: authConfig.callbacks,
58
+ typeClass: 'callback'
59
+ });
60
+ buildAuthPlugin({
61
+ counter: counters.events,
62
+ pluginConfig: authConfig.events,
63
+ typeClass: 'event'
64
+ });
65
+ buildAuthPlugin({
66
+ counter: counters.providers,
67
+ pluginConfig: authConfig.providers,
68
+ typeClass: 'provider'
69
+ });
70
+ }
71
+ export default buildAuthPlugins;
@@ -0,0 +1,50 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2022 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 { type } from '@lowdefy/helpers';
16
+ import getPageRoles from './getPageRoles.js';
17
+ import getProtectedPages from './getProtectedPages.js';
18
+ function buildPageAuth({ components }) {
19
+ const protectedPages = getProtectedPages({
20
+ components
21
+ });
22
+ const pageRoles = getPageRoles({
23
+ components
24
+ });
25
+ let configPublicPages = [];
26
+ if (type.isArray(components.auth.pages.public)) {
27
+ configPublicPages = components.auth.pages.public;
28
+ }
29
+ (components.pages || []).forEach((page)=>{
30
+ if (pageRoles[page.id]) {
31
+ if (configPublicPages.includes(page.id)) {
32
+ throw new Error(`Page "${page.id}" is both protected by roles ${JSON.stringify(pageRoles[page.id])} and public.`);
33
+ }
34
+ page.auth = {
35
+ public: false,
36
+ roles: pageRoles[page.id]
37
+ };
38
+ } else if (protectedPages.includes(page.id)) {
39
+ page.auth = {
40
+ public: false
41
+ };
42
+ } else {
43
+ page.auth = {
44
+ public: true
45
+ };
46
+ }
47
+ });
48
+ return components;
49
+ }
50
+ export default buildPageAuth;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ function getPageRoles({ components }) {
16
- const roles = components.config.auth.pages.roles;
16
+ const roles = components.auth.pages.roles;
17
17
  const pageRoles = {};
18
18
  Object.keys(roles).forEach((roleName)=>{
19
19
  roles[roleName].forEach((pageId)=>{
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,16 +14,14 @@
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  function getProtectedPages({ components }) {
17
- const pageIds = (components.pages || []).map((page)=>page.id
18
- );
17
+ const pageIds = (components.pages || []).map((page)=>page.id);
19
18
  let protectedPages = [];
20
- if (type.isArray(components.config.auth.pages.public)) {
21
- protectedPages = pageIds.filter((pageId)=>!components.config.auth.pages.public.includes(pageId)
22
- );
23
- } else if (components.config.auth.pages.protected === true) {
19
+ if (type.isArray(components.auth.pages.public)) {
20
+ protectedPages = pageIds.filter((pageId)=>!components.auth.pages.public.includes(pageId));
21
+ } else if (components.auth.pages.protected === true) {
24
22
  protectedPages = pageIds;
25
- } else if (type.isArray(components.config.auth.pages.protected)) {
26
- protectedPages = components.config.auth.pages.protected;
23
+ } else if (type.isArray(components.auth.pages.protected)) {
24
+ protectedPages = components.auth.pages.protected;
27
25
  }
28
26
  return protectedPages;
29
27
  }
@@ -0,0 +1,64 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2022 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 { type } from '@lowdefy/helpers';
16
+ import { validate } from '@lowdefy/ajv';
17
+ import lowdefySchema from '../../lowdefySchema.js';
18
+ async function validateAuthConfig({ components }) {
19
+ if (type.isNone(components.auth)) {
20
+ components.auth = {};
21
+ }
22
+ if (!type.isObject(components.auth)) {
23
+ throw new Error('lowdefy.auth is not an object.');
24
+ }
25
+ if (type.isNone(components.auth.authPages)) {
26
+ components.auth.authPages = {};
27
+ }
28
+ if (type.isNone(components.auth.pages)) {
29
+ components.auth.pages = {};
30
+ }
31
+ if (type.isNone(components.auth.pages.roles)) {
32
+ components.auth.pages.roles = {};
33
+ }
34
+ if (type.isNone(components.auth.callbacks)) {
35
+ components.auth.callbacks = [];
36
+ }
37
+ if (type.isNone(components.auth.events)) {
38
+ components.auth.events = [];
39
+ }
40
+ if (type.isNone(components.auth.providers)) {
41
+ components.auth.providers = [];
42
+ }
43
+ if (type.isNone(components.auth.session)) {
44
+ components.auth.session = {};
45
+ }
46
+ if (type.isNone(components.auth.theme)) {
47
+ components.auth.theme = {};
48
+ }
49
+ validate({
50
+ schema: lowdefySchema.definitions.authConfig,
51
+ data: components.auth
52
+ });
53
+ if (components.auth.pages.protected === true && components.auth.pages.public === true || type.isArray(components.auth.pages.protected) && type.isArray(components.auth.pages.public)) {
54
+ throw new Error('Protected and public pages are mutually exclusive. When protected pages are listed, all unlisted pages are public by default and visa versa.');
55
+ }
56
+ if (components.auth.pages.protected === false) {
57
+ throw new Error('Protected pages can not be set to false.');
58
+ }
59
+ if (components.auth.pages.public === false) {
60
+ throw new Error('Public pages can not be set to false.');
61
+ }
62
+ return components;
63
+ }
64
+ export default validateAuthConfig;
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import countOperators from '../utils/countOperators.js';
17
17
  import createCheckDuplicateId from '../utils/createCheckDuplicateId.js';
18
- async function buildConnections({ components , context }) {
18
+ function buildConnections({ components , context }) {
19
19
  const checkDuplicateConnectionId = createCheckDuplicateId({
20
20
  message: 'Duplicate connectionId "{{ id }}".'
21
21
  });
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -38,54 +38,46 @@
38
38
  function getConfigIcons({ components , icons , regex }) {
39
39
  [
40
40
  ...JSON.stringify(components.global || {}).matchAll(regex)
41
- ].map((match)=>icons.add(match[1])
42
- );
41
+ ].map((match)=>icons.add(match[1]));
43
42
  [
44
43
  ...JSON.stringify(components.menus || []).matchAll(regex)
45
- ].map((match)=>icons.add(match[1])
46
- );
44
+ ].map((match)=>icons.add(match[1]));
47
45
  [
48
46
  ...JSON.stringify(components.pages || []).matchAll(regex)
49
- ].map((match)=>icons.add(match[1])
50
- );
47
+ ].map((match)=>icons.add(match[1]));
51
48
  }
52
- function getBlockDefaultIcons({ components , context , icons , regex }) {
53
- Object.keys(components.types.blocks).forEach((blockName)=>{
54
- (context.typesMap.icons[blockName] || []).forEach((icon)=>{
49
+ function getBlockDefaultIcons({ blocks , context , icons , regex }) {
50
+ blocks.forEach((block)=>{
51
+ (context.typesMap.icons[block.typeName] || []).forEach((icon)=>{
55
52
  [
56
53
  ...JSON.stringify(icon).matchAll(regex)
57
- ].map((match)=>icons.add(match[1])
58
- );
54
+ ].map((match)=>icons.add(match[1]));
59
55
  });
60
56
  });
61
57
  }
62
- function buildIcons({ components , context }) {
63
- components.icons = [];
58
+ function buildIconImports({ blocks , components , context , defaults ={} }) {
59
+ const iconImports = [];
64
60
  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
- }
61
+ defaults;
62
+ const icons = new Set(defaults[iconPackage]);
72
63
  getConfigIcons({
73
64
  components,
74
65
  icons,
75
66
  regex
76
67
  });
77
68
  getBlockDefaultIcons({
78
- components,
69
+ blocks,
79
70
  context,
80
71
  icons,
81
72
  regex
82
73
  });
83
- components.icons.push({
74
+ iconImports.push({
84
75
  icons: [
85
76
  ...icons
86
77
  ],
87
78
  package: iconPackage
88
79
  });
89
80
  });
81
+ return iconImports;
90
82
  }
91
- export default buildIcons;
83
+ export default buildIconImports;
@@ -0,0 +1,30 @@
1
+ /*
2
+ Copyright 2020-2022 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 buildImportsDev from './buildImportsDev.js';
16
+ import buildImportsProd from './buildImportsProd.js';
17
+ function buildImports({ components , context }) {
18
+ if (context.stage === 'dev') {
19
+ components.imports = buildImportsDev({
20
+ components,
21
+ context
22
+ });
23
+ } else {
24
+ components.imports = buildImportsProd({
25
+ components,
26
+ context
27
+ });
28
+ }
29
+ }
30
+ export default buildImports;
@@ -0,0 +1,106 @@
1
+ /*
2
+ Copyright 2020-2022 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 buildIconImports from './buildIconImports.js';
16
+ import buildStyleImports from './buildStyleImports.js';
17
+ import defaultIconsDev from './defaultIconsDev.js';
18
+ function getPluginPackages({ components }) {
19
+ const pluginPackages = new Set();
20
+ function getPackages(types) {
21
+ Object.values(types).forEach((type)=>{
22
+ pluginPackages.add(type.package);
23
+ });
24
+ }
25
+ getPackages(components.types.actions);
26
+ getPackages(components.types.auth.adapters);
27
+ getPackages(components.types.auth.callbacks);
28
+ getPackages(components.types.auth.events);
29
+ getPackages(components.types.auth.providers);
30
+ getPackages(components.types.blocks);
31
+ getPackages(components.types.connections);
32
+ getPackages(components.types.requests);
33
+ getPackages(components.types.operators.client);
34
+ getPackages(components.types.operators.server);
35
+ return pluginPackages;
36
+ }
37
+ function buildImportClassDev({ pluginPackages , map }) {
38
+ return Object.entries(map).map(([typeName, type])=>({
39
+ originalTypeName: type.originalTypeName,
40
+ package: type.package,
41
+ typeName
42
+ })).filter((type)=>pluginPackages.has(type.package));
43
+ }
44
+ function buildImportsDev({ components , context }) {
45
+ const pluginPackages = getPluginPackages({
46
+ components
47
+ });
48
+ const blocks = buildImportClassDev({
49
+ pluginPackages,
50
+ map: context.typesMap.blocks
51
+ });
52
+ return {
53
+ actions: buildImportClassDev({
54
+ pluginPackages,
55
+ map: context.typesMap.actions
56
+ }),
57
+ auth: {
58
+ adapters: buildImportClassDev({
59
+ pluginPackages,
60
+ map: context.typesMap.auth.adapters
61
+ }),
62
+ callbacks: buildImportClassDev({
63
+ pluginPackages,
64
+ map: context.typesMap.auth.callbacks
65
+ }),
66
+ events: buildImportClassDev({
67
+ pluginPackages,
68
+ map: context.typesMap.auth.events
69
+ }),
70
+ providers: buildImportClassDev({
71
+ pluginPackages,
72
+ map: context.typesMap.auth.providers
73
+ })
74
+ },
75
+ blocks,
76
+ connections: buildImportClassDev({
77
+ pluginPackages,
78
+ map: context.typesMap.connections
79
+ }),
80
+ icons: buildIconImports({
81
+ blocks,
82
+ components,
83
+ context,
84
+ defaults: defaultIconsDev
85
+ }),
86
+ requests: buildImportClassDev({
87
+ pluginPackages,
88
+ map: context.typesMap.requests
89
+ }),
90
+ operators: {
91
+ client: buildImportClassDev({
92
+ pluginPackages,
93
+ map: context.typesMap.operators.client
94
+ }),
95
+ server: buildImportClassDev({
96
+ pluginPackages,
97
+ map: context.typesMap.operators.server
98
+ })
99
+ },
100
+ styles: buildStyleImports({
101
+ blocks,
102
+ context
103
+ })
104
+ };
105
+ }
106
+ export default buildImportsDev;
@@ -0,0 +1,54 @@
1
+ /*
2
+ Copyright 2020-2022 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 buildIconImports from './buildIconImports.js';
16
+ import buildStyleImports from './buildStyleImports.js';
17
+ import defaultIconsProd from './defaultIconsProd.js';
18
+ function buildImportClassProd(types) {
19
+ return Object.entries(types).map(([typeName, type])=>({
20
+ originalTypeName: type.originalTypeName,
21
+ package: type.package,
22
+ typeName
23
+ }));
24
+ }
25
+ function buildImportsProd({ components , context }) {
26
+ const blocks = buildImportClassProd(components.types.blocks);
27
+ return {
28
+ actions: buildImportClassProd(components.types.actions),
29
+ auth: {
30
+ adapters: buildImportClassProd(components.types.auth.adapters),
31
+ callbacks: buildImportClassProd(components.types.auth.callbacks),
32
+ events: buildImportClassProd(components.types.auth.events),
33
+ providers: buildImportClassProd(components.types.auth.providers)
34
+ },
35
+ blocks,
36
+ connections: buildImportClassProd(components.types.connections),
37
+ icons: buildIconImports({
38
+ blocks,
39
+ components,
40
+ context,
41
+ defaults: defaultIconsProd
42
+ }),
43
+ requests: buildImportClassProd(components.types.requests),
44
+ operators: {
45
+ client: buildImportClassProd(components.types.operators.client),
46
+ server: buildImportClassProd(components.types.operators.server)
47
+ },
48
+ styles: buildStyleImports({
49
+ blocks,
50
+ context
51
+ })
52
+ };
53
+ }
54
+ export default buildImportsProd;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,18 +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 buildStyles({ components , context }) {
16
- components.styles = [];
15
+ */ function buildStyleImports({ blocks , context }) {
17
16
  const styles = new Set();
18
- Object.entries(components.types.blocks).forEach(([blockName, block])=>{
19
- styles.add(...(context.typesMap.styles.packages[block.package] || []).map((style)=>`${block.package}/${style}`
20
- ));
21
- styles.add(...(context.typesMap.styles.blocks[blockName] || []).map((style)=>`${block.package}/${style}`
22
- ));
17
+ blocks.forEach((block)=>{
18
+ styles.add(...(context.typesMap.styles.packages[block.package] || []).map((style)=>`${block.package}/${style}`));
19
+ styles.add(...(context.typesMap.styles.blocks[block.typeName] || []).map((style)=>`${block.package}/${style}`));
23
20
  });
24
- components.styles = [
21
+ return [
25
22
  ...styles
26
- ].filter((style)=>!!style
27
- );
23
+ ].filter((style)=>!!style);
28
24
  }
29
- export default buildStyles;
25
+ export default buildStyleImports;