@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
package/dist/index.js CHANGED
@@ -14,38 +14,43 @@
14
14
  limitations under the License.
15
15
  */ import { readFile } from '@lowdefy/node-utils';
16
16
  import createCounter from './utils/createCounter.js';
17
- import createReadConfigFile from './utils/files/readConfigFile.js';
18
- import createWriteBuildArtifact from './utils/files/writeBuildArtifact.js';
17
+ import createReadConfigFile from './utils/readConfigFile.js';
18
+ import createWriteBuildArtifact from './utils/writeBuildArtifact.js';
19
19
  import addDefaultPages from './build/addDefaultPages/addDefaultPages.js';
20
20
  import buildAuth from './build/buildAuth/buildAuth.js';
21
21
  import buildConnections from './build/buildConnections.js';
22
+ import buildIcons from './build/buildIcons.js';
22
23
  import buildMenu from './build/buildMenu.js';
23
24
  import buildPages from './build/buildPages/buildPages.js';
24
25
  import buildRefs from './build/buildRefs/buildRefs.js';
26
+ import buildStyles from './build/buildStyles.js';
25
27
  import buildTypes from './build/buildTypes.js';
26
28
  import cleanBuildDirectory from './build/cleanBuildDirectory.js';
29
+ import copyPublicFolder from './build/copyPublicFolder.js';
27
30
  import testSchema from './build/testSchema.js';
28
31
  import validateApp from './build/validateApp.js';
29
32
  import validateConfig from './build/validateConfig.js';
33
+ import updateServerPackageJson from './build/updateServerPackageJson.js';
30
34
  import writeApp from './build/writeApp.js';
35
+ import writeActionImports from './build/writePluginImports/writeActionImports.js';
31
36
  import writeBlockImports from './build/writePluginImports/writeBlockImports.js';
32
- import writeConnectionImports from './build/writePluginImports/writeConnectionImports.js';
33
37
  import writeConfig from './build/writeConfig.js';
38
+ import writeConnectionImports from './build/writePluginImports/writeConnectionImports.js';
34
39
  import writeConnections from './build/writeConnections.js';
35
40
  import writeGlobal from './build/writeGlobal.js';
41
+ import writeIconImports from './build/writePluginImports/writeIconImports.js';
36
42
  import writeMenus from './build/writeMenus.js';
43
+ import writeOperatorImports from './build/writePluginImports/writeOperatorImports.js';
37
44
  import writePages from './build/writePages.js';
38
45
  import writeRequests from './build/writeRequests.js';
46
+ import writeStyleImports from './build/writePluginImports/writeStyleImports.js';
39
47
  import writeTypes from './build/writeTypes.js';
40
48
  async function createContext(options) {
41
- const { blocksServerUrl , buildDirectory , cacheDirectory , configDirectory , logger , refResolver } = options;
49
+ const { directories , logger , refResolver } = options;
42
50
  const defaultTypes = JSON.parse(await readFile(new URL('./defaultTypes.json', import.meta.url).pathname));
43
51
  // TODO: resolve custom plugin types
44
52
  const context = {
45
- blocksServerUrl,
46
- buildDirectory,
47
- cacheDirectory,
48
- configDirectory,
53
+ directories,
49
54
  typeCounters: {
50
55
  actions: createCounter(),
51
56
  blocks: createCounter(),
@@ -58,108 +63,132 @@ async function createContext(options) {
58
63
  },
59
64
  logger,
60
65
  readConfigFile: createReadConfigFile({
61
- configDirectory
66
+ directories
62
67
  }),
63
68
  refResolver,
64
69
  types: defaultTypes,
65
70
  writeBuildArtifact: createWriteBuildArtifact({
66
- buildDirectory
71
+ directories
67
72
  })
68
73
  };
69
74
  return context;
70
75
  }
71
76
  async function build(options) {
72
77
  const context = await createContext(options);
73
- try {
74
- const components = await buildRefs({
75
- context
76
- });
77
- await testSchema({
78
- components,
79
- context
80
- });
81
- await validateApp({
82
- components,
83
- context
84
- });
85
- await validateConfig({
86
- components,
87
- context
88
- });
89
- await addDefaultPages({
90
- components,
91
- context
92
- });
93
- await buildAuth({
94
- components,
95
- context
96
- });
97
- await buildConnections({
98
- components,
99
- context
100
- });
101
- await buildPages({
102
- components,
103
- context
104
- });
105
- await buildMenu({
106
- components,
107
- context
108
- });
109
- await buildTypes({
110
- components,
111
- context
112
- });
113
- await cleanBuildDirectory({
114
- context
115
- });
116
- await writeApp({
117
- components,
118
- context
119
- });
120
- await writeConnections({
121
- components,
122
- context
123
- });
124
- await writeRequests({
125
- components,
126
- context
127
- });
128
- await writePages({
129
- components,
130
- context
131
- });
132
- await writeConfig({
133
- components,
134
- context
135
- });
136
- await writeGlobal({
137
- components,
138
- context
139
- });
140
- await writeMenus({
141
- components,
142
- context
143
- });
144
- await writeTypes({
145
- components,
146
- context
147
- });
148
- await writeBlockImports({
149
- components,
150
- context
151
- });
152
- await writeConnectionImports({
153
- components,
154
- context
155
- });
156
- // TODO: write style file
157
- // TODO: write icons file
158
- // TODO: add plugins to package.json
159
- } catch (error) {
160
- context.logger.error(error);
161
- throw error;
162
- }
78
+ const components = await buildRefs({
79
+ context
80
+ });
81
+ await testSchema({
82
+ components,
83
+ context
84
+ });
85
+ await validateApp({
86
+ components,
87
+ context
88
+ });
89
+ await validateConfig({
90
+ components,
91
+ context
92
+ });
93
+ await addDefaultPages({
94
+ components,
95
+ context
96
+ });
97
+ await buildAuth({
98
+ components,
99
+ context
100
+ });
101
+ await buildConnections({
102
+ components,
103
+ context
104
+ });
105
+ await buildPages({
106
+ components,
107
+ context
108
+ });
109
+ await buildMenu({
110
+ components,
111
+ context
112
+ });
113
+ await buildTypes({
114
+ components,
115
+ context
116
+ });
117
+ await buildIcons({
118
+ components,
119
+ context
120
+ });
121
+ await buildStyles({
122
+ components,
123
+ context
124
+ });
125
+ await cleanBuildDirectory({
126
+ context
127
+ });
128
+ await writeActionImports({
129
+ components,
130
+ context
131
+ });
132
+ await writeApp({
133
+ components,
134
+ context
135
+ });
136
+ await writeConnections({
137
+ components,
138
+ context
139
+ });
140
+ await writeRequests({
141
+ components,
142
+ context
143
+ });
144
+ await writePages({
145
+ components,
146
+ context
147
+ });
148
+ await writeConfig({
149
+ components,
150
+ context
151
+ });
152
+ await writeGlobal({
153
+ components,
154
+ context
155
+ });
156
+ await writeMenus({
157
+ components,
158
+ context
159
+ });
160
+ await writeTypes({
161
+ components,
162
+ context
163
+ });
164
+ await writeBlockImports({
165
+ components,
166
+ context
167
+ });
168
+ await writeConnectionImports({
169
+ components,
170
+ context
171
+ });
172
+ await writeOperatorImports({
173
+ components,
174
+ context
175
+ });
176
+ await writeStyleImports({
177
+ components,
178
+ context
179
+ });
180
+ await writeIconImports({
181
+ components,
182
+ context
183
+ });
184
+ await updateServerPackageJson({
185
+ components,
186
+ context
187
+ });
188
+ await copyPublicFolder({
189
+ components,
190
+ context
191
+ });
163
192
  }
164
193
  export { createContext };
165
194
  export default build;
@@ -24,12 +24,9 @@ export default {
24
24
  type: 'Action "id" should be a string.'
25
25
  }
26
26
  },
27
- messages: {
28
- },
29
- params: {
30
- },
31
- skip: {
32
- },
27
+ messages: {},
28
+ params: {},
29
+ skip: {},
33
30
  type: {
34
31
  type: 'string',
35
32
  errorMessage: {
@@ -247,8 +244,7 @@ export default {
247
244
  type: 'Block "style" should be an object.'
248
245
  }
249
246
  },
250
- visible: {
251
- },
247
+ visible: {},
252
248
  blocks: {
253
249
  type: 'array',
254
250
  items: {
@@ -267,8 +263,7 @@ export default {
267
263
  type: 'Block "requests" should be an array.'
268
264
  }
269
265
  },
270
- required: {
271
- },
266
+ required: {},
272
267
  validate: {
273
268
  type: 'array',
274
269
  items: {
@@ -630,6 +625,16 @@ export default {
630
625
  },
631
626
  additionalProperties: false,
632
627
  properties: {
628
+ auth: {
629
+ $ref: '#/definitions/authConfig'
630
+ },
631
+ basePath: {
632
+ type: 'string',
633
+ description: 'App base path to apply to all routes. Base path must start with "/".',
634
+ errorMessage: {
635
+ type: 'App "config.basePath" should be a string.'
636
+ }
637
+ },
633
638
  homePageId: {
634
639
  type: 'string',
635
640
  description: 'Page id to use as homepage. When visiting home route "/", the router will redirect to this page. If not provided, the first page in default or first menu will be used as the homePageId.',
@@ -637,8 +642,20 @@ export default {
637
642
  type: 'App "config.homePageId" should be a string.'
638
643
  }
639
644
  },
640
- auth: {
641
- $ref: '#/definitions/authConfig'
645
+ theme: {
646
+ type: 'object',
647
+ errorMessage: {
648
+ type: 'App "config.theme" should be an object.'
649
+ },
650
+ properties: {
651
+ lessVariables: {
652
+ type: 'object',
653
+ description: 'App theme less variables.',
654
+ errorMessage: {
655
+ type: 'App "config.theme.lessVariables" should be an object.'
656
+ }
657
+ }
658
+ }
642
659
  }
643
660
  }
644
661
  },
@@ -17,8 +17,28 @@
17
17
  import { type } from '@lowdefy/helpers';
18
18
  import { readFile, writeFile } from '@lowdefy/node-utils';
19
19
  const defaultPackages = [
20
+ '@lowdefy/actions-core',
21
+ '@lowdefy/blocks-antd',
20
22
  '@lowdefy/blocks-basic',
21
- '@lowdefy/connection-axios-http'
23
+ '@lowdefy/blocks-color-selectors',
24
+ '@lowdefy/blocks-echarts',
25
+ '@lowdefy/blocks-loaders',
26
+ '@lowdefy/blocks-markdown',
27
+ '@lowdefy/connection-axios-http',
28
+ '@lowdefy/connection-elasticsearch',
29
+ '@lowdefy/connection-google-sheets',
30
+ '@lowdefy/connection-knex',
31
+ '@lowdefy/connection-mongodb',
32
+ '@lowdefy/connection-redis',
33
+ '@lowdefy/connection-sendgrid',
34
+ '@lowdefy/connection-stripe',
35
+ '@lowdefy/operators-change-case',
36
+ '@lowdefy/operators-diff',
37
+ '@lowdefy/operators-js',
38
+ '@lowdefy/operators-mql',
39
+ '@lowdefy/operators-nunjucks',
40
+ '@lowdefy/operators-uuid',
41
+ '@lowdefy/operators-yaml',
22
42
  ];
23
43
  function createTypeDefinitions({ typeNames , store , packageName , version }) {
24
44
  if (type.isArray(typeNames)) {
@@ -33,21 +53,16 @@ function createTypeDefinitions({ typeNames , store , packageName , version }) {
33
53
  async function generateDefaultTypes() {
34
54
  const packageFile = JSON.parse(await readFile(path.resolve(process.cwd(), './package.json')));
35
55
  const defaultTypes = {
36
- actions: {
37
- },
38
- blocks: {
39
- },
40
- connections: {
41
- },
42
- requests: {
43
- },
56
+ actions: {},
57
+ blocks: {},
58
+ connections: {},
59
+ requests: {},
44
60
  operators: {
45
- client: {
46
- },
47
- server: {
48
- }
61
+ client: {},
62
+ server: {}
49
63
  },
50
- styles: []
64
+ icons: {},
65
+ styles: {}
51
66
  };
52
67
  await Promise.all(defaultPackages.map(async (packageName)=>{
53
68
  const { default: types } = await import(`${packageName}/types`);
@@ -88,19 +103,13 @@ async function generateDefaultTypes() {
88
103
  packageName,
89
104
  version
90
105
  });
91
- if (type.isArray(types.styles)) {
92
- types.styles.forEach((pathName)=>{
93
- defaultTypes.styles.push({
94
- path: pathName,
95
- package: packageName,
96
- version: packageFile.devDependencies[packageName]
97
- });
98
- });
106
+ if (type.isObject(types.styles)) {
107
+ defaultTypes.styles[packageName] = types.styles;
108
+ }
109
+ if (type.isObject(types.icons)) {
110
+ defaultTypes.icons[packageName] = types.icons;
99
111
  }
100
112
  }));
101
- await writeFile({
102
- filePath: path.resolve(process.cwd(), './dist/defaultTypes.json'),
103
- content: JSON.stringify(defaultTypes, null, 2)
104
- });
113
+ await writeFile(path.resolve(process.cwd(), './dist/defaultTypes.json'), JSON.stringify(defaultTypes, null, 2));
105
114
  }
106
115
  generateDefaultTypes();
@@ -14,18 +14,19 @@
14
14
  See the License for the specific language governing permissions and
15
15
  limitations under the License.
16
16
  */ import path from 'path';
17
+ import yargs from 'yargs';
18
+ import { hideBin } from 'yargs/helpers';
17
19
  import build from '../index.js';
20
+ const argv = yargs(hideBin(process.argv)).argv;
18
21
  async function run() {
19
- // TODO: resolve build with no config
20
- try {
21
- await build({
22
- logger: console,
23
- buildDirectory: path.resolve(process.cwd(), './.lowdefy/build'),
24
- cacheDirectory: path.resolve(process.cwd(), './.lowdefy/.cache'),
25
- configDirectory: process.cwd()
26
- });
27
- } catch (e) {
28
- console.error(e);
29
- }
22
+ await build({
23
+ logger: console,
24
+ refResolver: argv.refResolver || process.env.LOWDEFY_BUILD_REF_RESOLVER,
25
+ directories: {
26
+ build: path.resolve(argv.buildDirectory || process.env.LOWDEFY_DIRECTORY_BUILD || path.join(process.cwd(), 'build')),
27
+ config: path.resolve(argv.configDirectory || process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()),
28
+ server: path.resolve(argv.serverDirectory || process.env.LOWDEFY_DIRECTORY_SERVER || process.cwd())
29
+ }
30
+ });
30
31
  }
31
32
  run();
@@ -12,14 +12,11 @@
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
- */ const wait = (ms)=>{
16
- return new Promise((resolve)=>setTimeout(resolve, ms)
17
- );
18
- };
15
+ */ import { wait } from '@lowdefy/helpers';
19
16
  async function asyncFn() {
20
17
  await wait(20);
21
18
  return {
22
19
  async: true
23
20
  };
24
21
  }
25
- module.exports = asyncFn;
22
+ export default asyncFn;
@@ -15,4 +15,4 @@
15
15
  */ function resolver() {
16
16
  throw new Error('Test error');
17
17
  }
18
- module.exports = resolver;
18
+ export default resolver;
@@ -16,4 +16,4 @@
16
16
  if (path === 'null') return null;
17
17
  return undefined;
18
18
  }
19
- module.exports = resolver;
19
+ export default resolver;
@@ -36,4 +36,4 @@ array:
36
36
  return null;
37
37
  }
38
38
  }
39
- module.exports = resolver;
39
+ export default resolver;
@@ -20,4 +20,4 @@
20
20
  contextId: context.id
21
21
  };
22
22
  }
23
- module.exports = resolver;
23
+ export default resolver;
@@ -22,4 +22,4 @@ function transformer(obj, vars) {
22
22
  var: vars.var1
23
23
  };
24
24
  }
25
- module.exports = transformer;
25
+ export default transformer;
@@ -18,4 +18,4 @@
18
18
  vars
19
19
  };
20
20
  }
21
- module.exports = transformer;
21
+ export default transformer;
@@ -13,24 +13,19 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import createCounter from '../utils/createCounter.js';
16
- function testContext({ writeBuildArtifact , configDirectory , readConfigFile , logger ={
17
- } } = {
18
- }) {
16
+ function testContext({ writeBuildArtifact , configDirectory , readConfigFile , logger ={} } = {}) {
19
17
  const defaultLogger = {
20
- info: ()=>{
21
- },
22
- log: ()=>{
23
- },
24
- warn: ()=>{
25
- },
26
- error: ()=>{
27
- },
28
- succeed: ()=>{
29
- }
18
+ info: ()=>{},
19
+ log: ()=>{},
20
+ warn: ()=>{},
21
+ error: ()=>{},
22
+ succeed: ()=>{}
30
23
  };
31
24
  const context = {
32
25
  id: 'test',
33
- configDirectory: configDirectory || '',
26
+ directories: {
27
+ config: configDirectory || ''
28
+ },
34
29
  typeCounters: {
35
30
  actions: createCounter(),
36
31
  blocks: createCounter(),
@@ -41,10 +36,8 @@ function testContext({ writeBuildArtifact , configDirectory , readConfigFile , l
41
36
  server: createCounter()
42
37
  }
43
38
  },
44
- writeBuildArtifact: writeBuildArtifact || (()=>{
45
- }),
46
- readConfigFile: readConfigFile || (()=>{
47
- })
39
+ writeBuildArtifact: writeBuildArtifact || (()=>{}),
40
+ readConfigFile: readConfigFile || (()=>{})
48
41
  };
49
42
  context.logger = {
50
43
  ...defaultLogger,
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import { get, type } from '@lowdefy/helpers';
16
16
  function formatArrayKey({ index , object }) {
17
- if (!type.isNone(object.id) || !type.isNone(object.type)) {
17
+ if (type.isObject(object) && (!type.isNone(object.id) || !type.isNone(object.type))) {
18
18
  const objectId = type.isNone(object.id) ? '_ERROR_MISSING_ID_' : object.id;
19
19
  const objectType = type.isNone(object.type) ? '_ERROR_MISSING_TYPE_' : object.type;
20
20
  return `[${index}:${objectId}:${objectType}]`;
@@ -15,9 +15,9 @@
15
15
  */ import path from 'path';
16
16
  import { cachedPromises } from '@lowdefy/helpers';
17
17
  import { readFile } from '@lowdefy/node-utils';
18
- function createReadConfigFile({ configDirectory }) {
18
+ function createReadConfigFile({ directories }) {
19
19
  async function readConfigFile(filePath) {
20
- return readFile(path.resolve(configDirectory, filePath));
20
+ return readFile(path.resolve(directories.config, filePath));
21
21
  }
22
22
  return cachedPromises(readConfigFile);
23
23
  }
@@ -14,12 +14,9 @@
14
14
  limitations under the License.
15
15
  */ import path from 'path';
16
16
  import { writeFile } from '@lowdefy/node-utils';
17
- function createWriteBuildArtifact({ buildDirectory }) {
18
- async function writeBuildArtifact({ filePath , content }) {
19
- return writeFile({
20
- filePath: path.resolve(buildDirectory, filePath),
21
- content
22
- });
17
+ function createWriteBuildArtifact({ directories }) {
18
+ async function writeBuildArtifact(filePath, content) {
19
+ await writeFile(path.join(directories.build, filePath), content);
23
20
  }
24
21
  return writeBuildArtifact;
25
22
  }