@lowdefy/build 3.23.3 → 4.0.0-alpha.11

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 (105) hide show
  1. package/dist/build/addDefaultPages/404.js +51 -0
  2. package/dist/build/addDefaultPages/addDefaultPages.js +44 -0
  3. package/dist/build/buildAuth/buildAuth.js +31 -0
  4. package/dist/build/buildAuth/buildAuthPlugins.js +78 -0
  5. package/dist/build/buildAuth/buildPageAuth.js +50 -0
  6. package/dist/build/buildAuth/getPageRoles.js +33 -0
  7. package/dist/build/buildAuth/getProtectedPages.js +30 -0
  8. package/dist/build/buildAuth/validateAuthConfig.js +61 -0
  9. package/dist/build/buildConnections.js +46 -0
  10. package/dist/build/buildImports/buildIconImports.js +92 -0
  11. package/dist/build/buildImports/buildImports.js +30 -0
  12. package/dist/build/buildImports/buildImportsDev.js +101 -0
  13. package/dist/build/buildImports/buildImportsProd.js +52 -0
  14. package/dist/build/buildImports/buildStyleImports.js +28 -0
  15. package/dist/build/buildMenu.js +122 -0
  16. package/dist/build/buildPages/buildBlock/buildBlock.js +35 -0
  17. package/dist/build/buildPages/buildBlock/buildEvents.js +75 -0
  18. package/dist/build/buildPages/buildBlock/buildRequests.js +51 -0
  19. package/dist/build/buildPages/buildBlock/buildSubBlocks.js +35 -0
  20. package/dist/build/buildPages/buildBlock/countBlockOperators.js +31 -0
  21. package/dist/build/buildPages/buildBlock/countBlockTypes.js +18 -0
  22. package/dist/build/buildPages/buildBlock/moveSkeletonBlocksToArea.js +35 -0
  23. package/dist/build/buildPages/buildBlock/moveSubBlocksToArea.js +25 -0
  24. package/dist/build/buildPages/buildBlock/setBlockId.js +20 -0
  25. package/dist/build/buildPages/buildBlock/validateBlock.js +38 -0
  26. package/dist/build/buildPages/buildPage.js +50 -0
  27. package/dist/build/buildPages/buildPages.js +33 -0
  28. package/dist/build/buildRefs/buildRefs.js +26 -0
  29. package/dist/build/buildRefs/evaluateBuildOperators.js +35 -0
  30. package/dist/build/buildRefs/getConfigFile.js +28 -0
  31. package/dist/build/buildRefs/getRefContent.js +44 -0
  32. package/dist/build/buildRefs/getRefPath.js +30 -0
  33. package/dist/build/buildRefs/getRefsFromFile.js +37 -0
  34. package/dist/build/buildRefs/getUserJavascriptFunction.js +24 -0
  35. package/dist/build/buildRefs/makeRefDefinition.js +30 -0
  36. package/dist/build/buildRefs/parseNunjucks.js +20 -0
  37. package/dist/build/buildRefs/parseRefContent.js +37 -0
  38. package/dist/build/buildRefs/populateRefs.js +43 -0
  39. package/dist/build/buildRefs/recursiveBuild.js +68 -0
  40. package/dist/build/buildRefs/runRefResolver.js +33 -0
  41. package/dist/build/buildRefs/runTransformer.js +30 -0
  42. package/dist/build/buildTypes.js +119 -0
  43. package/dist/build/cleanBuildDirectory.js +19 -0
  44. package/dist/build/copyPublicFolder.js +23 -0
  45. package/dist/build/testSchema.js +33 -0
  46. package/dist/build/updateServerPackageJson.js +49 -0
  47. package/dist/build/validateApp.js +34 -0
  48. package/dist/build/validateConfig.js +33 -0
  49. package/dist/build/writeApp.js +18 -0
  50. package/dist/build/writeAuth.js +18 -0
  51. package/dist/build/writeConfig.js +18 -0
  52. package/dist/build/writeConnections.js +26 -0
  53. package/dist/build/writeGlobal.js +25 -0
  54. package/dist/build/writeMenus.js +22 -0
  55. package/dist/build/writePages.js +26 -0
  56. package/dist/build/writePluginImports/generateImportFile.js +31 -0
  57. package/dist/build/writePluginImports/writeActionImports.js +22 -0
  58. package/dist/build/writePluginImports/writeAuthImports.js +30 -0
  59. package/dist/build/writePluginImports/writeBlockImports.js +22 -0
  60. package/dist/build/writePluginImports/writeConnectionImports.js +22 -0
  61. package/dist/build/writePluginImports/writeIconImports.js +31 -0
  62. package/dist/build/writePluginImports/writeOperatorImports.js +26 -0
  63. package/dist/build/writePluginImports/writePluginImports.js +52 -0
  64. package/dist/build/writePluginImports/writeStyleImports.js +28 -0
  65. package/dist/build/writeRequests.js +32 -0
  66. package/dist/build/writeTypes.js +18 -0
  67. package/dist/defaultTypesMap.json +1874 -0
  68. package/dist/index.js +179 -1
  69. package/dist/lowdefySchema.js +793 -0
  70. package/dist/scripts/generateDefaultTypes.js +78 -0
  71. package/dist/scripts/run.js +33 -0
  72. package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +22 -0
  73. package/dist/test/buildRefs/testBuildRefsErrorResolver.js +18 -0
  74. package/dist/test/buildRefs/testBuildRefsNullResolver.js +19 -0
  75. package/dist/test/buildRefs/testBuildRefsParsingResolver.js +39 -0
  76. package/dist/test/buildRefs/testBuildRefsResolver.js +23 -0
  77. package/dist/test/buildRefs/testBuildRefsTransform.js +25 -0
  78. package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +21 -0
  79. package/dist/test/testContext.js +48 -0
  80. package/dist/utils/countOperators.js +30 -0
  81. package/dist/utils/createCheckDuplicateId.js +31 -0
  82. package/dist/utils/createCounter.js +33 -0
  83. package/dist/utils/createPluginTypesMap.js +106 -0
  84. package/dist/utils/formatErrorMessage.js +56 -0
  85. package/dist/utils/readConfigFile.js +24 -0
  86. package/dist/utils/writeBuildArtifact.js +23 -0
  87. package/package.json +56 -23
  88. package/dist/138.index.js +0 -2
  89. package/dist/138.index.js.LICENSE.txt +0 -3
  90. package/dist/231.index.js +0 -1
  91. package/dist/319.index.js +0 -1
  92. package/dist/35.index.js +0 -1
  93. package/dist/422.index.js +0 -1
  94. package/dist/443.index.js +0 -1
  95. package/dist/449.index.js +0 -1
  96. package/dist/5.index.js +0 -2
  97. package/dist/5.index.js.LICENSE.txt +0 -1
  98. package/dist/564.index.js +0 -1
  99. package/dist/569.index.js +0 -1
  100. package/dist/625.index.js +0 -1
  101. package/dist/693.index.js +0 -2
  102. package/dist/693.index.js.LICENSE.txt +0 -1
  103. package/dist/734.index.js +0 -1
  104. package/dist/904.index.js +0 -1
  105. package/dist/remoteEntry.js +0 -1
@@ -0,0 +1,51 @@
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
+ */ export default {
16
+ id: '404',
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
+ };
@@ -0,0 +1,44 @@
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
+ import page404 from './404.js';
17
+ async function addDefaultPages({ components }) {
18
+ // If not copied, the same object is mutated by build every time
19
+ // build runs for dev server. See #647
20
+ const defaultPages = [
21
+ JSON.parse(JSON.stringify(page404))
22
+ ];
23
+ if (type.isNone(components.pages)) {
24
+ components.pages = [];
25
+ }
26
+ if (!type.isArray(components.pages)) {
27
+ throw new Error('lowdefy.pages is not an array.');
28
+ }
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
+ });
35
+ // deep copy to avoid mutating defaultConfig
36
+ const filteredDefaultPages = defaultPages.filter((defaultPage)=>!pageIds.includes(defaultPage.id)
37
+ );
38
+ components.pages = [
39
+ ...components.pages,
40
+ ...filteredDefaultPages
41
+ ];
42
+ return components;
43
+ }
44
+ export default addDefaultPages;
@@ -0,0 +1,31 @@
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 buildAuthPlugins from './buildAuthPlugins.js';
16
+ import buildPageAuth from './buildPageAuth.js';
17
+ import validateAuthConfig from './validateAuthConfig.js';
18
+ function buildAuth({ components , context }) {
19
+ validateAuthConfig({
20
+ components
21
+ });
22
+ buildPageAuth({
23
+ components
24
+ });
25
+ buildAuthPlugins({
26
+ components,
27
+ context
28
+ });
29
+ return components;
30
+ }
31
+ export default buildAuth;
@@ -0,0 +1,78 @@
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 buildCallbacks({ components , context }) {
17
+ if (type.isArray(components.auth.callbacks)) {
18
+ components.auth.callbacks.forEach((callback)=>{
19
+ if (type.isUndefined(callback.id)) {
20
+ throw new Error(`Auth callback id missing.`);
21
+ }
22
+ if (!type.isString(callback.id)) {
23
+ throw new Error(`Auth callback id is not a string. Received ${JSON.stringify(callback.id)}.`);
24
+ }
25
+ if (!type.isString(callback.type)) {
26
+ throw new Error(`Auth callback type is not a string at callback "${callback.id}". Received ${JSON.stringify(callback.type)}.`);
27
+ }
28
+ context.typeCounters.auth.callbacks.increment(callback.type);
29
+ });
30
+ }
31
+ }
32
+ function buildEvents({ components , context }) {
33
+ if (type.isArray(components.auth.events)) {
34
+ components.auth.events.forEach((event)=>{
35
+ if (type.isUndefined(event.id)) {
36
+ throw new Error(`Auth event id missing.`);
37
+ }
38
+ if (!type.isString(event.id)) {
39
+ throw new Error(`Auth event id is not a string. Received ${JSON.stringify(event.id)}.`);
40
+ }
41
+ if (!type.isString(event.type)) {
42
+ throw new Error(`Auth event type is not a string at event "${event.id}". Received ${JSON.stringify(event.type)}.`);
43
+ }
44
+ context.typeCounters.auth.events.increment(event.type);
45
+ });
46
+ }
47
+ }
48
+ function buildProviders({ components , context }) {
49
+ if (type.isArray(components.auth.providers)) {
50
+ components.auth.providers.forEach((provider)=>{
51
+ if (type.isUndefined(provider.id)) {
52
+ throw new Error(`Auth provider id missing.`);
53
+ }
54
+ if (!type.isString(provider.id)) {
55
+ throw new Error(`Auth provider id is not a string. Received ${JSON.stringify(provider.id)}.`);
56
+ }
57
+ if (!type.isString(provider.type)) {
58
+ throw new Error(`Auth provider type is not a string at provider "${provider.id}". Received ${JSON.stringify(provider.type)}.`);
59
+ }
60
+ context.typeCounters.auth.providers.increment(provider.type);
61
+ });
62
+ }
63
+ }
64
+ function buildAuthPlugins({ components , context }) {
65
+ buildCallbacks({
66
+ components,
67
+ context
68
+ });
69
+ buildEvents({
70
+ components,
71
+ context
72
+ });
73
+ buildProviders({
74
+ components,
75
+ context
76
+ });
77
+ }
78
+ 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;
@@ -0,0 +1,33 @@
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
+ */ function getPageRoles({ components }) {
16
+ const roles = components.auth.pages.roles;
17
+ const pageRoles = {};
18
+ Object.keys(roles).forEach((roleName)=>{
19
+ roles[roleName].forEach((pageId)=>{
20
+ if (!pageRoles[pageId]) {
21
+ pageRoles[pageId] = new Set();
22
+ }
23
+ pageRoles[pageId].add(roleName);
24
+ });
25
+ });
26
+ Object.keys(pageRoles).forEach((pageId)=>{
27
+ pageRoles[pageId] = [
28
+ ...pageRoles[pageId]
29
+ ];
30
+ });
31
+ return pageRoles;
32
+ }
33
+ export default getPageRoles;
@@ -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 { type } from '@lowdefy/helpers';
16
+ function getProtectedPages({ components }) {
17
+ const pageIds = (components.pages || []).map((page)=>page.id
18
+ );
19
+ let protectedPages = [];
20
+ if (type.isArray(components.auth.pages.public)) {
21
+ protectedPages = pageIds.filter((pageId)=>!components.auth.pages.public.includes(pageId)
22
+ );
23
+ } else if (components.auth.pages.protected === true) {
24
+ protectedPages = pageIds;
25
+ } else if (type.isArray(components.auth.pages.protected)) {
26
+ protectedPages = components.auth.pages.protected;
27
+ }
28
+ return protectedPages;
29
+ }
30
+ export default getProtectedPages;
@@ -0,0 +1,61 @@
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.pages)) {
26
+ components.auth.pages = {};
27
+ }
28
+ if (type.isNone(components.auth.pages.roles)) {
29
+ components.auth.pages.roles = {};
30
+ }
31
+ if (type.isNone(components.auth.callbacks)) {
32
+ components.auth.callbacks = [];
33
+ }
34
+ if (type.isNone(components.auth.events)) {
35
+ components.auth.events = [];
36
+ }
37
+ if (type.isNone(components.auth.providers)) {
38
+ components.auth.providers = [];
39
+ }
40
+ if (type.isNone(components.auth.session)) {
41
+ components.auth.session = {};
42
+ }
43
+ if (type.isNone(components.auth.theme)) {
44
+ components.auth.theme = {};
45
+ }
46
+ validate({
47
+ schema: lowdefySchema.definitions.authConfig,
48
+ data: components.auth
49
+ });
50
+ if (components.auth.pages.protected === true && components.auth.pages.public === true || type.isArray(components.auth.pages.protected) && type.isArray(components.auth.pages.public)) {
51
+ 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.');
52
+ }
53
+ if (components.auth.pages.protected === false) {
54
+ throw new Error('Protected pages can not be set to false.');
55
+ }
56
+ if (components.auth.pages.public === false) {
57
+ throw new Error('Public pages can not be set to false.');
58
+ }
59
+ return components;
60
+ }
61
+ export default validateAuthConfig;
@@ -0,0 +1,46 @@
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 countOperators from '../utils/countOperators.js';
17
+ import createCheckDuplicateId from '../utils/createCheckDuplicateId.js';
18
+ async function buildConnections({ components , context }) {
19
+ const checkDuplicateConnectionId = createCheckDuplicateId({
20
+ message: 'Duplicate connectionId "{{ id }}".'
21
+ });
22
+ if (type.isArray(components.connections)) {
23
+ components.connections.forEach((connection)=>{
24
+ if (type.isUndefined(connection.id)) {
25
+ throw new Error(`Connection id missing.`);
26
+ }
27
+ if (!type.isString(connection.id)) {
28
+ throw new Error(`Connection id is not a string. Received ${JSON.stringify(connection.id)}.`);
29
+ }
30
+ checkDuplicateConnectionId({
31
+ id: connection.id
32
+ });
33
+ if (!type.isString(connection.type)) {
34
+ throw new Error(`Connection type is not a string at connection "${connection.id}". Received ${JSON.stringify(connection.type)}.`);
35
+ }
36
+ context.typeCounters.connections.increment(connection.type);
37
+ connection.connectionId = connection.id;
38
+ connection.id = `connection:${connection.id}`;
39
+ countOperators(connection.properties || {}, {
40
+ counter: context.typeCounters.operators.server
41
+ });
42
+ });
43
+ }
44
+ return components;
45
+ }
46
+ export default buildConnections;
@@ -0,0 +1,92 @@
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
+ */ 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({ blocks , context , icons , regex }) {
53
+ blocks.forEach((block)=>{
54
+ (context.typesMap.icons[block.typeName] || []).forEach((icon)=>{
55
+ [
56
+ ...JSON.stringify(icon).matchAll(regex)
57
+ ].map((match)=>icons.add(match[1])
58
+ );
59
+ });
60
+ });
61
+ }
62
+ function buildIconImports({ blocks , components , context }) {
63
+ const iconImports = [];
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
+ blocks,
79
+ context,
80
+ icons,
81
+ regex
82
+ });
83
+ iconImports.push({
84
+ icons: [
85
+ ...icons
86
+ ],
87
+ package: iconPackage
88
+ });
89
+ });
90
+ return iconImports;
91
+ }
92
+ 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,101 @@
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
+ function getPluginPackages({ components }) {
18
+ const pluginPackages = new Set();
19
+ function getPackages(types) {
20
+ Object.values(types).forEach((type)=>{
21
+ pluginPackages.add(type.package);
22
+ });
23
+ }
24
+ getPackages(components.types.actions);
25
+ getPackages(components.types.auth.callbacks);
26
+ getPackages(components.types.auth.events);
27
+ getPackages(components.types.auth.providers);
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
+ return pluginPackages;
34
+ }
35
+ function buildImportClassDev({ pluginPackages , map }) {
36
+ return Object.entries(map).map(([typeName, type])=>({
37
+ originalTypeName: type.originalTypeName,
38
+ package: type.package,
39
+ typeName
40
+ })
41
+ ).filter((type)=>pluginPackages.has(type.package)
42
+ );
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
+ callbacks: buildImportClassDev({
59
+ pluginPackages,
60
+ map: context.typesMap.auth.callbacks
61
+ }),
62
+ events: buildImportClassDev({
63
+ pluginPackages,
64
+ map: context.typesMap.auth.events
65
+ }),
66
+ providers: buildImportClassDev({
67
+ pluginPackages,
68
+ map: context.typesMap.auth.providers
69
+ })
70
+ },
71
+ blocks,
72
+ connections: buildImportClassDev({
73
+ pluginPackages,
74
+ map: context.typesMap.connections
75
+ }),
76
+ icons: buildIconImports({
77
+ blocks,
78
+ components,
79
+ context
80
+ }),
81
+ requests: buildImportClassDev({
82
+ pluginPackages,
83
+ map: context.typesMap.requests
84
+ }),
85
+ operators: {
86
+ client: buildImportClassDev({
87
+ pluginPackages,
88
+ map: context.typesMap.operators.client
89
+ }),
90
+ server: buildImportClassDev({
91
+ pluginPackages,
92
+ map: context.typesMap.operators.server
93
+ })
94
+ },
95
+ styles: buildStyleImports({
96
+ blocks,
97
+ context
98
+ })
99
+ };
100
+ }
101
+ export default buildImportsDev;