@lowdefy/build 4.0.0-alpha.29 → 4.0.0-alpha.30

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 +51 -0
  2. package/dist/build/addDefaultPages/addDefaultPages.js +43 -0
  3. package/dist/build/buildAuth/buildAuth.js +34 -0
  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 +33 -0
  7. package/dist/build/buildAuth/getProtectedPages.js +28 -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 +83 -0
  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/buildImports/buildStyleImports.js +25 -0
  15. package/dist/build/buildImports/defaultIconsDev.js +584 -0
  16. package/dist/build/buildImports/defaultIconsProd.js +21 -0
  17. package/dist/build/buildMenu.js +118 -0
  18. package/dist/build/buildPages/buildBlock/buildBlock.js +35 -0
  19. package/dist/build/buildPages/buildBlock/buildEvents.js +76 -0
  20. package/dist/build/buildPages/buildBlock/buildRequests.js +51 -0
  21. package/dist/build/buildPages/buildBlock/buildSubBlocks.js +30 -0
  22. package/dist/build/buildPages/buildBlock/countBlockOperators.js +31 -0
  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 +25 -0
  26. package/dist/build/buildPages/buildBlock/setBlockId.js +20 -0
  27. package/dist/build/buildPages/buildBlock/validateBlock.js +38 -0
  28. package/dist/build/buildPages/buildPage.js +50 -0
  29. package/dist/build/buildPages/buildPages.js +31 -0
  30. package/dist/build/buildPages/buildTestPage.js +46 -0
  31. package/dist/build/buildRefs/buildRefs.js +32 -0
  32. package/dist/build/buildRefs/evaluateBuildOperators.js +34 -0
  33. package/dist/build/buildRefs/getConfigFile.js +28 -0
  34. package/dist/build/buildRefs/getRefContent.js +44 -0
  35. package/dist/build/buildRefs/getRefPath.js +30 -0
  36. package/dist/build/buildRefs/getRefsFromFile.js +37 -0
  37. package/dist/build/buildRefs/getUserJavascriptFunction.js +24 -0
  38. package/dist/build/buildRefs/makeRefDefinition.js +30 -0
  39. package/dist/build/buildRefs/parseNunjucks.js +20 -0
  40. package/dist/build/buildRefs/parseRefContent.js +37 -0
  41. package/dist/build/buildRefs/populateRefs.js +43 -0
  42. package/dist/build/buildRefs/recursiveBuild.js +68 -0
  43. package/dist/build/buildRefs/runRefResolver.js +33 -0
  44. package/dist/build/buildRefs/runTransformer.js +30 -0
  45. package/dist/build/buildTypes.js +124 -0
  46. package/dist/build/cleanBuildDirectory.js +19 -0
  47. package/dist/build/copyPublicFolder.js +23 -0
  48. package/dist/build/testSchema.js +32 -0
  49. package/dist/build/updateServerPackageJson.js +50 -0
  50. package/dist/build/validateApp.js +34 -0
  51. package/dist/build/validateConfig.js +33 -0
  52. package/dist/build/writeApp.js +18 -0
  53. package/dist/build/writeAuth.js +18 -0
  54. package/dist/build/writeConfig.js +18 -0
  55. package/dist/build/writeConnections.js +26 -0
  56. package/dist/build/writeGlobal.js +25 -0
  57. package/dist/build/writeMenus.js +22 -0
  58. package/dist/build/writePages.js +25 -0
  59. package/dist/build/writePluginImports/generateImportFile.js +31 -0
  60. package/dist/build/writePluginImports/writeActionImports.js +22 -0
  61. package/dist/build/writePluginImports/writeAuthImports.js +34 -0
  62. package/dist/build/writePluginImports/writeBlockImports.js +22 -0
  63. package/dist/build/writePluginImports/writeConnectionImports.js +22 -0
  64. package/dist/build/writePluginImports/writeIconImports.js +31 -0
  65. package/dist/build/writePluginImports/writeOperatorImports.js +26 -0
  66. package/dist/build/writePluginImports/writePluginImports.js +52 -0
  67. package/dist/build/writePluginImports/writeStyleImports.js +28 -0
  68. package/dist/build/writeRequests.js +31 -0
  69. package/dist/build/writeTypes.js +18 -0
  70. package/dist/createContext.js +55 -0
  71. package/dist/defaultTypesMap.js +2046 -0
  72. package/dist/index.js +139 -0
  73. package/dist/lowdefySchema.js +841 -0
  74. package/dist/scripts/generateDefaultTypes.js +88 -0
  75. package/dist/scripts/run.js +33 -0
  76. package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +22 -0
  77. package/dist/test/buildRefs/testBuildRefsErrorResolver.js +18 -0
  78. package/dist/test/buildRefs/testBuildRefsNullResolver.js +19 -0
  79. package/dist/test/buildRefs/testBuildRefsParsingResolver.js +39 -0
  80. package/dist/test/buildRefs/testBuildRefsResolver.js +23 -0
  81. package/dist/test/buildRefs/testBuildRefsTransform.js +25 -0
  82. package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +21 -0
  83. package/dist/test/testContext.js +54 -0
  84. package/dist/utils/countOperators.js +30 -0
  85. package/dist/utils/createCheckDuplicateId.js +31 -0
  86. package/dist/utils/createCounter.js +33 -0
  87. package/dist/utils/createPluginTypesMap.js +113 -0
  88. package/dist/utils/formatErrorMessage.js +56 -0
  89. package/dist/utils/readConfigFile.js +24 -0
  90. package/dist/utils/writeBuildArtifact.js +23 -0
  91. package/package.json +36 -36
@@ -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,43 @@
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
+ 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
+ components.pages = [
38
+ ...components.pages,
39
+ ...filteredDefaultPages
40
+ ];
41
+ return components;
42
+ }
43
+ export default addDefaultPages;
@@ -0,0 +1,34 @@
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 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({
22
+ components
23
+ });
24
+ components.auth.configured = configured;
25
+ buildPageAuth({
26
+ components
27
+ });
28
+ buildAuthPlugins({
29
+ components,
30
+ context
31
+ });
32
+ return components;
33
+ }
34
+ export default buildAuth;
@@ -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;
@@ -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,28 @@
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
+ let protectedPages = [];
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) {
22
+ protectedPages = pageIds;
23
+ } else if (type.isArray(components.auth.pages.protected)) {
24
+ protectedPages = components.auth.pages.protected;
25
+ }
26
+ return protectedPages;
27
+ }
28
+ 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
+ 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,83 @@
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
+ ...JSON.stringify(components.menus || []).matchAll(regex)
44
+ ].map((match)=>icons.add(match[1]));
45
+ [
46
+ ...JSON.stringify(components.pages || []).matchAll(regex)
47
+ ].map((match)=>icons.add(match[1]));
48
+ }
49
+ function getBlockDefaultIcons({ blocks , context , icons , regex }) {
50
+ blocks.forEach((block)=>{
51
+ (context.typesMap.icons[block.typeName] || []).forEach((icon)=>{
52
+ [
53
+ ...JSON.stringify(icon).matchAll(regex)
54
+ ].map((match)=>icons.add(match[1]));
55
+ });
56
+ });
57
+ }
58
+ function buildIconImports({ blocks , components , context , defaults ={} }) {
59
+ const iconImports = [];
60
+ Object.entries(iconPackages).forEach(([iconPackage, regex])=>{
61
+ defaults;
62
+ const icons = new Set(defaults[iconPackage]);
63
+ getConfigIcons({
64
+ components,
65
+ icons,
66
+ regex
67
+ });
68
+ getBlockDefaultIcons({
69
+ blocks,
70
+ context,
71
+ icons,
72
+ regex
73
+ });
74
+ iconImports.push({
75
+ icons: [
76
+ ...icons
77
+ ],
78
+ package: iconPackage
79
+ });
80
+ });
81
+ return iconImports;
82
+ }
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;