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

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.
@@ -50,8 +50,8 @@ function getConfigIcons({ components , icons , regex }) {
50
50
  );
51
51
  }
52
52
  function getBlockDefaultIcons({ components , context , icons , regex }) {
53
- Object.entries(components.types.blocks).forEach(([blockName, block])=>{
54
- context.types.icons[block.package][blockName].forEach((icon)=>{
53
+ Object.keys(components.types.blocks).forEach((blockName)=>{
54
+ (context.typesMap.icons[blockName] || []).forEach((icon)=>{
55
55
  [
56
56
  ...JSON.stringify(icon).matchAll(regex)
57
57
  ].map((match)=>icons.add(match[1])
@@ -14,6 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import recursiveBuild from './recursiveBuild.js';
16
16
  import makeRefDefinition from './makeRefDefinition.js';
17
+ // TODO: build operators aren't evaluated in lowdefy.yaml file. Move recursive call up a layer or something.
17
18
  async function buildRefs({ context }) {
18
19
  const components = await recursiveBuild({
19
20
  context,
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { NodeParser } from '@lowdefy/operators';
16
+ import operators from '@lowdefy/operators-js/operators/build';
17
+ async function evaluateBuildOperators({ context , input , refDef }) {
18
+ const operatorsParser = new NodeParser({
19
+ env: process.env,
20
+ operators
21
+ });
22
+ const { output , errors } = operatorsParser.parse({
23
+ input,
24
+ location: refDef.path,
25
+ operatorPrefix: '_build.'
26
+ });
27
+ if (errors.length > 0) {
28
+ await context.logger.warn('Build operator errors.');
29
+ const promises = errors.map((error)=>context.logger.warn(error.message)
30
+ );
31
+ await promises;
32
+ }
33
+ return output;
34
+ }
35
+ export default evaluateBuildOperators;
@@ -17,7 +17,7 @@ import parseRefContent from './parseRefContent.js';
17
17
  import runRefResolver from './runRefResolver.js';
18
18
  async function getRefContent({ context , refDef , referencedFrom }) {
19
19
  let content;
20
- if (refDef.path === 'lowdefy.yaml') {
20
+ if (refDef.path === 'lowdefy.yaml' || refDef.path === 'lowdefy.yml') {
21
21
  content = await getConfigFile({
22
22
  context,
23
23
  refDef,
@@ -12,7 +12,8 @@
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
- */ import getRefContent from './getRefContent.js';
15
+ */ import evaluateBuildOperators from './evaluateBuildOperators.js';
16
+ import getRefContent from './getRefContent.js';
16
17
  import getRefsFromFile from './getRefsFromFile.js';
17
18
  import populateRefs from './populateRefs.js';
18
19
  import runTransformer from './runTransformer.js';
@@ -46,9 +47,14 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
46
47
  count: count + 1,
47
48
  referencedFrom: refDef.path
48
49
  });
50
+ const evaluatedOperators = await evaluateBuildOperators({
51
+ context,
52
+ input: parsedFile,
53
+ refDef: parsedRefDef
54
+ });
49
55
  const transformedFile = await runTransformer({
50
56
  context,
51
- parsedFile,
57
+ input: evaluatedOperators,
52
58
  refDef: parsedRefDef
53
59
  });
54
60
  parsedFiles[newRefDef.id] = transformedFile;
@@ -13,18 +13,18 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import getUserJavascriptFunction from './getUserJavascriptFunction.js';
16
- async function runTransformer({ context , parsedFile , refDef }) {
16
+ async function runTransformer({ context , input , refDef }) {
17
17
  if (refDef.transformer) {
18
18
  const transformerFn = await getUserJavascriptFunction({
19
19
  context,
20
20
  filePath: refDef.transformer
21
21
  });
22
22
  try {
23
- return transformerFn(parsedFile, refDef.vars);
23
+ return transformerFn(input, refDef.vars);
24
24
  } catch (error) {
25
25
  throw Error(`Error calling transformer "${refDef.transformer}" from "${refDef.path}": ${error.message}`);
26
26
  }
27
27
  }
28
- return parsedFile;
28
+ return input;
29
29
  }
30
30
  export default runTransformer;
@@ -16,9 +16,9 @@
16
16
  components.styles = [];
17
17
  const styles = new Set();
18
18
  Object.entries(components.types.blocks).forEach(([blockName, block])=>{
19
- styles.add(...(context.types.styles[block.package].default || []).map((style)=>`${block.package}/${style}`
19
+ styles.add(...(context.typesMap.styles.packages[block.package] || []).map((style)=>`${block.package}/${style}`
20
20
  ));
21
- styles.add(...(context.types.styles[block.package][blockName] || []).map((style)=>`${block.package}/${style}`
21
+ styles.add(...(context.typesMap.styles.blocks[blockName] || []).map((style)=>`${block.package}/${style}`
22
22
  ));
23
23
  });
24
24
  components.styles = [
@@ -23,6 +23,7 @@
23
23
  throw new Error(`${typeClass} type "${typeName}" was used but is not defined.`);
24
24
  }
25
25
  store[typeName] = {
26
+ originalTypeName: definitions[typeName].originalTypeName,
26
27
  package: definitions[typeName].package,
27
28
  version: definitions[typeName].version,
28
29
  count: counts[typeName]
@@ -46,38 +47,38 @@ function buildTypes({ components , context }) {
46
47
  };
47
48
  buildTypeClass(context, {
48
49
  counter: typeCounters.actions,
49
- definitions: context.types.actions,
50
+ definitions: context.typesMap.actions,
50
51
  store: components.types.actions,
51
52
  typeClass: 'Action'
52
53
  });
53
54
  buildTypeClass(context, {
54
55
  counter: typeCounters.blocks,
55
- definitions: context.types.blocks,
56
+ definitions: context.typesMap.blocks,
56
57
  store: components.types.blocks,
57
58
  typeClass: 'Block'
58
59
  });
59
60
  buildTypeClass(context, {
60
61
  counter: typeCounters.connections,
61
- definitions: context.types.connections,
62
+ definitions: context.typesMap.connections,
62
63
  store: components.types.connections,
63
64
  typeClass: 'Connection'
64
65
  });
65
66
  buildTypeClass(context, {
66
67
  counter: typeCounters.requests,
67
- definitions: context.types.requests,
68
+ definitions: context.typesMap.requests,
68
69
  store: components.types.requests,
69
70
  typeClass: 'Request'
70
71
  });
71
72
  buildTypeClass(context, {
72
73
  counter: typeCounters.operators.client,
73
- definitions: context.types.operators.client,
74
+ definitions: context.typesMap.operators.client,
74
75
  store: components.types.operators.client,
75
76
  typeClass: 'Operator',
76
77
  warnIfMissing: true
77
78
  });
78
79
  buildTypeClass(context, {
79
80
  counter: typeCounters.operators.server,
80
- definitions: context.types.operators.server,
81
+ definitions: context.typesMap.operators.server,
81
82
  store: components.types.operators.server,
82
83
  typeClass: 'Operator',
83
84
  warnIfMissing: true
@@ -14,18 +14,18 @@
14
14
  limitations under the License.
15
15
  */ import { nunjucksFunction } from '@lowdefy/nunjucks';
16
16
  const template = `{%- for import in imports -%}
17
- import { {{ import.type }} } from '{{ import.package }}/{{ importPath }}';
17
+ import { {{ import.originalTypeName }} as {{ import.typeName }} } from '{{ import.package }}/{{ importPath }}';
18
18
  {% endfor -%}
19
19
  export default {
20
20
  {% for import in imports -%}
21
- {{ import.type }},
21
+ {{ import.typeName }},
22
22
  {% endfor -%}
23
- }`;
23
+ };`;
24
24
  function generateImportFile({ types , importPath }) {
25
25
  const templateFn = nunjucksFunction(template);
26
- const imports = Object.keys(types).map((type)=>({
27
- type,
28
- ...types[type]
26
+ const imports = Object.keys(types).map((typeName)=>({
27
+ typeName,
28
+ ...types[typeName]
29
29
  })
30
30
  );
31
31
  return templateFn({