@fnet/cli 0.111.0 → 0.111.1

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 (155) hide show
  1. package/README.md +145 -0
  2. package/dist/fnet/index.DBSKvJyG.js +1 -0
  3. package/dist/fnet/index.DrwlOzAe.js +1 -0
  4. package/dist/fnet/index.js +1 -1
  5. package/dist/fnode/index.53yND1Av.js +1 -0
  6. package/dist/fnode/index.B1zLg4Y2.js +1 -0
  7. package/dist/fnode/index.B2LXSSn7.js +1 -0
  8. package/dist/fnode/index.BBrItYB9.js +1 -0
  9. package/dist/fnode/index.BSQp_bJN.js +1 -0
  10. package/dist/fnode/index.Bqzc7Bx8.js +1 -0
  11. package/dist/fnode/index.BwhWziH6.js +1 -0
  12. package/dist/fnode/index.CLlKzCGk.js +1 -0
  13. package/dist/fnode/index.Chvv_TJm.js +1 -0
  14. package/dist/fnode/index.D4KQB1ot.js +1 -0
  15. package/dist/fnode/index.DItyYiZ_.js +1 -0
  16. package/dist/fnode/index.DrwlOzAe.js +1 -0
  17. package/dist/fnode/index.js +1 -1
  18. package/dist/frun/index.js +126 -0
  19. package/package.json +8 -9
  20. package/template/fnet/bun/fnet/flows.yaml.njk +1 -0
  21. package/template/fnet/bun/fnet.yaml.njk +1 -0
  22. package/template/fnet/bun/src/app/index.html.njk +67 -0
  23. package/template/fnet/bun/src/app/index.js.njk +36 -0
  24. package/template/fnet/bun/src/cli/index.js.njk +44 -0
  25. package/template/fnet/bun/src/default/blocks/assign.js.njk +40 -0
  26. package/template/fnet/bun/src/default/blocks/call.js.njk +92 -0
  27. package/template/fnet/bun/src/default/blocks/for.js.njk +81 -0
  28. package/template/fnet/bun/src/default/blocks/form.js.njk +65 -0
  29. package/template/fnet/bun/src/default/blocks/jump.js.njk +31 -0
  30. package/template/fnet/bun/src/default/blocks/modules.js.njk +50 -0
  31. package/template/fnet/bun/src/default/blocks/operation.js.njk +24 -0
  32. package/template/fnet/bun/src/default/blocks/raise.js.njk +25 -0
  33. package/template/fnet/bun/src/default/blocks/return.js.njk +27 -0
  34. package/template/fnet/bun/src/default/blocks/steps.js.njk +56 -0
  35. package/template/fnet/bun/src/default/blocks/switch.js.njk +73 -0
  36. package/template/fnet/bun/src/default/blocks/tryexcept.js.njk +65 -0
  37. package/template/fnet/bun/src/default/engine.js.njk +79 -0
  38. package/template/fnet/bun/src/default/macros/block-body-header.js.njk +7 -0
  39. package/template/fnet/bun/src/default/macros/block-footer.js.njk +3 -0
  40. package/template/fnet/bun/src/default/macros/block-header.js.njk +14 -0
  41. package/template/fnet/bun/src/default/macros/block-library-header.js.njk +19 -0
  42. package/template/fnet/bun/src/default/macros/block-modules-header.js.njk +8 -0
  43. package/template/fnet/bun/src/default/macros/block-modules.js.njk +29 -0
  44. package/template/fnet/bun/src/default/macros/block-next-header.js.njk +6 -0
  45. package/template/fnet/bun/src/default/macros/block-next.js.njk +20 -0
  46. package/template/fnet/bun/src/default/macros/block-run-form.js.njk +32 -0
  47. package/template/fnet/bun/src/default/macros/block-run-header.js.njk +39 -0
  48. package/template/fnet/bun/src/default/macros/page.js.njk +8 -0
  49. package/template/fnet/bun/src/default/macros/workflow-header.js.njk +7 -0
  50. package/template/fnet/bun/src/default/to.args.js.njk +120 -0
  51. package/template/fnet/bun/src/default/workflow.js.njk +117 -0
  52. package/template/fnet/core/assert.js +6 -0
  53. package/template/fnet/core/message.js +3 -0
  54. package/template/fnet/core/object.js +43 -0
  55. package/template/fnet/core/print.js +1 -0
  56. package/template/fnet/core/sleep.js +5 -0
  57. package/template/fnet/node/.gitignore.njk +8 -0
  58. package/template/fnet/node/fnet/flows.yaml.njk +1 -0
  59. package/template/fnet/node/fnet.yaml.njk +1 -0
  60. package/template/fnet/node/package.json.njk +90 -0
  61. package/template/fnet/node/readme.md.njk +21 -0
  62. package/template/fnet/node/rollup.config.mjs.njk +363 -0
  63. package/template/fnet/node/rollup_config_external.njk +8 -0
  64. package/template/fnet/node/rollup_config_onwarn.njk +9 -0
  65. package/template/fnet/node/rollup_config_output_banner.njk +3 -0
  66. package/template/fnet/node/rollup_config_output_footer.njk +5 -0
  67. package/template/fnet/node/rollup_config_output_globals.njk +9 -0
  68. package/template/fnet/node/rollup_config_output_name.njk +3 -0
  69. package/template/fnet/node/rollup_config_plugins.njk +90 -0
  70. package/template/fnet/node/src/app/index.html.njk +67 -0
  71. package/template/fnet/node/src/app/index.js.njk +36 -0
  72. package/template/fnet/node/src/cli/index.js.njk +44 -0
  73. package/template/fnet/node/src/default/blocks/assign.js.njk +40 -0
  74. package/template/fnet/node/src/default/blocks/call.js.njk +92 -0
  75. package/template/fnet/node/src/default/blocks/for.js.njk +81 -0
  76. package/template/fnet/node/src/default/blocks/form.js.njk +65 -0
  77. package/template/fnet/node/src/default/blocks/jump.js.njk +31 -0
  78. package/template/fnet/node/src/default/blocks/modules.js.njk +50 -0
  79. package/template/fnet/node/src/default/blocks/operation.js.njk +24 -0
  80. package/template/fnet/node/src/default/blocks/raise.js.njk +25 -0
  81. package/template/fnet/node/src/default/blocks/return.js.njk +27 -0
  82. package/template/fnet/node/src/default/blocks/steps.js.njk +56 -0
  83. package/template/fnet/node/src/default/blocks/switch.js.njk +73 -0
  84. package/template/fnet/node/src/default/blocks/tryexcept.js.njk +65 -0
  85. package/template/fnet/node/src/default/engine.js.njk +79 -0
  86. package/template/fnet/node/src/default/macros/block-body-header.js.njk +7 -0
  87. package/template/fnet/node/src/default/macros/block-footer.js.njk +3 -0
  88. package/template/fnet/node/src/default/macros/block-header.js.njk +14 -0
  89. package/template/fnet/node/src/default/macros/block-library-header.js.njk +19 -0
  90. package/template/fnet/node/src/default/macros/block-modules-header.js.njk +8 -0
  91. package/template/fnet/node/src/default/macros/block-modules.js.njk +29 -0
  92. package/template/fnet/node/src/default/macros/block-next-header.js.njk +6 -0
  93. package/template/fnet/node/src/default/macros/block-next.js.njk +20 -0
  94. package/template/fnet/node/src/default/macros/block-run-form.js.njk +32 -0
  95. package/template/fnet/node/src/default/macros/block-run-header.js.njk +39 -0
  96. package/template/fnet/node/src/default/macros/page.js.njk +8 -0
  97. package/template/fnet/node/src/default/macros/workflow-header.js.njk +7 -0
  98. package/template/fnet/node/src/default/to.args.js.njk +120 -0
  99. package/template/fnet/node/src/default/workflow.js.njk +117 -0
  100. package/template/fnet/node/tsconfig.json.njk +16 -0
  101. package/template/fnet/project/.gitignore.njk +7 -0
  102. package/template/fnet/project/.vscode/launch.json +41 -0
  103. package/template/fnet/project/.vscode/tasks.json +46 -0
  104. package/template/fnet/project/fnet/flows.yaml.njk +4 -0
  105. package/template/fnet/project/fnet/targets.yaml.njk +7 -0
  106. package/template/fnet/project/fnet.yaml.njk +3 -0
  107. package/template/fnode/bun/.gitignore.njk +8 -0
  108. package/template/fnode/bun/build.js.njk +156 -0
  109. package/template/fnode/bun/fnode.yaml.njk +1 -0
  110. package/template/fnode/bun/package.json.njk +89 -0
  111. package/template/fnode/bun/readme.md.njk +21 -0
  112. package/template/fnode/bun/src/app/index-js-with-react-host.njk +50 -0
  113. package/template/fnode/bun/src/app/index-js-without-react-host.njk +23 -0
  114. package/template/fnode/bun/src/app/index.html.njk +67 -0
  115. package/template/fnode/bun/src/app/index.js.njk +9 -0
  116. package/template/fnode/bun/src/cli/index.js.njk +81 -0
  117. package/template/fnode/bun/src/default/engine.js.njk +17 -0
  118. package/template/fnode/bun/src/default/to.args.js.njk +120 -0
  119. package/template/fnode/bun/tsconfig.json.njk +16 -0
  120. package/template/fnode/node/.gitignore.njk +8 -0
  121. package/template/fnode/node/fnode.yaml.njk +1 -0
  122. package/template/fnode/node/package.json.njk +90 -0
  123. package/template/fnode/node/readme.md.njk +21 -0
  124. package/template/fnode/node/rollup.config.mjs.njk +363 -0
  125. package/template/fnode/node/rollup_config_external.njk +8 -0
  126. package/template/fnode/node/rollup_config_onwarn.njk +9 -0
  127. package/template/fnode/node/rollup_config_output_banner.njk +3 -0
  128. package/template/fnode/node/rollup_config_output_footer.njk +5 -0
  129. package/template/fnode/node/rollup_config_output_globals.njk +9 -0
  130. package/template/fnode/node/rollup_config_output_name.njk +3 -0
  131. package/template/fnode/node/rollup_config_plugins.njk +90 -0
  132. package/template/fnode/node/src/app/index-js-with-react-host.njk +50 -0
  133. package/template/fnode/node/src/app/index-js-without-react-host.njk +23 -0
  134. package/template/fnode/node/src/app/index.html.njk +67 -0
  135. package/template/fnode/node/src/app/index.js.njk +9 -0
  136. package/template/fnode/node/src/cli/index.js.njk +81 -0
  137. package/template/fnode/node/src/default/engine.js.njk +17 -0
  138. package/template/fnode/node/src/default/to.args.js.njk +120 -0
  139. package/template/fnode/node/tsconfig.json.njk +16 -0
  140. package/template/fnode/project/.gitignore.njk +11 -0
  141. package/template/fnode/project/.vscode/launch.json.njk +78 -0
  142. package/template/fnode/project/.vscode/tasks.json.njk +46 -0
  143. package/template/fnode/project/fnet/targets.yaml.njk +25 -0
  144. package/template/fnode/project/fnode.yaml.njk +12 -0
  145. package/template/fnode/python/.gitignore.njk +7 -0
  146. package/template/fnode/python/fnode.yaml.njk +1 -0
  147. package/template/fnode/python/package.json.njk +4 -0
  148. package/template/fnode/python/pyproject.toml.njk +3 -0
  149. package/template/fnode/python/readme.md.njk +12 -0
  150. package/template/fnode/python/setup.py.njk +19 -0
  151. package/template/fnode/python/src/cli/index.py.njk +25 -0
  152. package/template/schemas/to-npm.yaml +14 -0
  153. package/dist/fnet/index.DZbefC4O.js +0 -1
  154. package/dist/fnode/index.DrdnDArw.js +0 -1
  155. package/readme.md +0 -50
@@ -0,0 +1,65 @@
1
+
2
+ {% include "src/default/macros/block-header.js.njk" %}
3
+
4
+ {# {% include "src/default/macros/block-next-header.js.njk" %} #}
5
+
6
+ {% include "src/default/macros/block-modules-header.js.njk" %}
7
+
8
+ {% for child in childs %}
9
+ {% if not child.definition.dynamic %}
10
+ // CHILD: {{child.indexKey}}
11
+ import {{child.codeKey}} from "./{{child.codeKey}}";
12
+ {% endif %}
13
+ {% endfor%}
14
+
15
+ export default function Block(context) {
16
+
17
+ {% include "src/default/macros/block-body-header.js.njk" %}
18
+
19
+ this.run= function (){
20
+
21
+ const args=Array.from(arguments);
22
+
23
+ return new Promise(async (resolve,reject)=>{
24
+
25
+ {% include "src/default/macros/block-run-header.js.njk" %}
26
+
27
+ {% include "src/default/macros/page.js.njk" %}
28
+
29
+ {% include "src/default/macros/block-modules.js.njk" %}
30
+
31
+ try{
32
+
33
+ {% if context.try.definition.dynamic %}
34
+ const { default: {{context.try.codeKey}} } = await import("./{{context.try.codeKey}}");
35
+ {% endif %}
36
+
37
+ const current=new {{context.try.codeKey}}({ parent:_this, engine, flow, caller:c });
38
+
39
+ {% if workflow.parent.context.atom.doc.features.print_runners %}
40
+ console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
41
+ {% endif %}
42
+
43
+ return resolve(await current.run.apply(current,args));
44
+ }
45
+ catch({{context.except.context.transform.as | safe}}){
46
+
47
+ {% if context.except.definition.dynamic %}
48
+ const { default: {{context.except.codeKey}} } = await import("./{{context.except.codeKey}}");
49
+ {% endif %}
50
+
51
+ const current=new {{context.except.codeKey}}({ parent:_this, engine, flow, caller:c });
52
+
53
+ {% if workflow.parent.context.atom.doc.features.print_runners %}
54
+ console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
55
+ {% endif %}
56
+
57
+ return resolve(await current.run.apply(current,args));
58
+ }
59
+ });
60
+ }
61
+
62
+ Object.freeze(this);
63
+ }
64
+
65
+ {% include "src/default/macros/block-footer.js.njk" %}
@@ -0,0 +1,79 @@
1
+ import Object from "../core/object";
2
+
3
+ import { default as Workflow } from "./{{flow.codeKey}}";
4
+
5
+ {% set form_enabled = false if flow.name === 'cli' else flow.parent.context.atom.doc.features.form_enabled %}
6
+
7
+ {% set form_enabled = false if flow.definition.features.server === true else form_enabled %}
8
+
9
+ {% if form_enabled %}
10
+ import { App } from "{{ui.package}}";
11
+ {% endif %}
12
+
13
+ export default class Engine extends Object {
14
+
15
+ #main;
16
+ {% if form_enabled %}
17
+ #app;
18
+ #appOwner;
19
+ {% endif %}
20
+
21
+ constructor(context) {
22
+ super(context);
23
+
24
+ this.#main = new Workflow({ engine: this });
25
+
26
+ {% if form_enabled %}
27
+ this.#app =context?.app || new App();
28
+ this.#appOwner = !!context?.app;
29
+ {% endif %}
30
+ }
31
+
32
+ async #init(context) {
33
+ {% if form_enabled %}
34
+ await this.#initApp(context);
35
+ {% endif %}
36
+ }
37
+
38
+ {% if form_enabled %}
39
+
40
+ async #initApp(context) {
41
+ const container = context.params?.container;
42
+ await this.#app.init({ container });
43
+ }
44
+
45
+ async setActiveForm(context) {
46
+ const form = context.form;
47
+ const props = context.props;
48
+
49
+ await this.#app.setActiveForm({form,props});
50
+ }
51
+
52
+ get app(){
53
+ return this.#app;
54
+ }
55
+
56
+ {% endif %}
57
+
58
+ // Main entry function to run workflow
59
+ async run(params) {
60
+
61
+ {% if flow.parent.context.atom.doc.features.print_steps %}
62
+ console.log(new Date().toLocaleString(),'{{ flow.parent.context.atom.doc.title or flow.parent.context.atom.doc.name }}');
63
+ {% endif %}
64
+
65
+ await this.#init({ params });
66
+
67
+ const response = await this.#main.run({ params });
68
+
69
+ return response?.value;
70
+ }
71
+
72
+ async destroy() {
73
+ {% if form_enabled %}
74
+ if (this.#appOwner) {
75
+ await this.#app.destroy();
76
+ }
77
+ {% endif %}
78
+ }
79
+ }
@@ -0,0 +1,7 @@
1
+ if (this.constructor !== Block) throw Error(Message.USE_CONSTRUCTOR);
2
+
3
+ this.context=context;
4
+
5
+ const { engine, flow, caller }=context || {};
6
+
7
+ const _this=this;
@@ -0,0 +1,3 @@
1
+ Block.TypeId="{{ typeId }}";
2
+ Block.ParentTypeId="{{ parent.typeId }}";
3
+ Block.IndexKey="{{ indexKey }}";
@@ -0,0 +1,14 @@
1
+ // BLOCK: {{indexKey}}
2
+
3
+ import Message from "../../core/message";
4
+ {% if context.transform.print %}
5
+ import print from "../../core/print";
6
+ {% endif %}
7
+
8
+ {% if context.transform.sleep %}
9
+ import sleep from "../../core/sleep";
10
+ {% endif %}
11
+
12
+ {% if context.transform.assert %}
13
+ import assert from "../../core/assert";
14
+ {% endif %}
@@ -0,0 +1,19 @@
1
+ {% if context.lib.type==='atom'%}
2
+ // LIBRARY: {{context.lib.atom.name}}
3
+ {% if context.lib.atom.relativePath %}
4
+ {% if context.transform.import %}
5
+ import { {{ context.transform.call | safe }} as LIBRARY } from "{{context.lib.atom.relativePath}}";
6
+ {% else %}
7
+ import { default as LIBRARY } from "{{context.lib.atom.relativePath}}";
8
+ {% endif %}
9
+ {% else %}
10
+ {% if context.transform.import %}
11
+ import { {{ context.transform.call | safe }} as LIBRARY } from "../../libs/{{context.lib.atom.id or context.lib.atom.name}}";
12
+ {% else %}
13
+ import { default as LIBRARY } from "../../libs/{{context.lib.atom.id or context.lib.atom.name}}";
14
+ {% endif %}
15
+ {% endif %}
16
+ {% elseif context.lib.type==='subworkflow' %}
17
+ // LIBRARY: {{context.lib.indexKey}}
18
+ import { default as {{context.lib.codeKey}} } from "../{{context.lib.codeKey}}";
19
+ {% endif %}
@@ -0,0 +1,8 @@
1
+ {% for child in childs %}
2
+ {% if child.module===true%}
3
+ {% if not child.definition.dynamic %}
4
+ // MODULE : {{child.indexKey}}
5
+ import { default as {{child.codeKey}} } from "./{{child.codeKey}}";
6
+ {% endif %}
7
+ {% endif %}
8
+ {% endfor%}
@@ -0,0 +1,29 @@
1
+ {% for child in childs %}
2
+
3
+ {% if child.module===true%}
4
+
5
+ // MODULE : {{child.indexKey}}
6
+ {% if child.definition.dynamic %}
7
+ const { default: {{child.codeKey}} } = await import("./{{child.codeKey}}");
8
+ {% endif %}
9
+
10
+ m['{{child.name}}']=async function(){
11
+ const entry=new {{child.codeKey}}({engine,flow,parent:_this,caller:c,module:true});
12
+ const nextBlock=await entry.run.apply(entry,arguments);
13
+
14
+ if(nextBlock?.type==='return') return nextBlock.value;
15
+ else if(nextBlock?.type==='block') {
16
+ {% if workflow.parent.context.atom.doc.features.print_module_final_next %}
17
+ console.log('MODULE FINAL NEXT:',nextBlock);
18
+ {% endif %}
19
+ resolve(nextBlock);
20
+ }
21
+ }
22
+
23
+ {% if child.context.transform.export %}
24
+ flow.setModule({{child.context.transform.export | safe}}, m['{{child.name}}']);
25
+ {% endif %}
26
+
27
+ {% endif %}
28
+
29
+ {% endfor%}
@@ -0,0 +1,6 @@
1
+ {% if context.next %}
2
+ {% if not context.next.definition.dynamic %}
3
+ // NEXT : {{context.next.indexKey}}
4
+ import { default as {{context.next.codeKey}} } from "./{{context.next.codeKey}}";
5
+ {% endif %}
6
+ {% endif %}
@@ -0,0 +1,20 @@
1
+ {% if context.next %}
2
+
3
+ // NEXT : {{context.next.indexKey}}
4
+ {% if context.next.definition.dynamic %}
5
+ const { default: {{context.next.codeKey}} } = await import("./{{context.next.codeKey}}");
6
+ {% endif %}
7
+
8
+
9
+ return resolve ({
10
+ type: 'block',
11
+ from: _this,
12
+ fromType: _this.constructor,
13
+ fromClosure: c,
14
+ toType:{{context.next.codeKey}},
15
+ {% if context.transform.nextArgs %}
16
+ withArgs: {{context.transform.nextArgs | safe}},
17
+ {% endif %}
18
+ });
19
+
20
+ {% endif %}
@@ -0,0 +1,32 @@
1
+ {% if context.transform.props %}
2
+ const formProps ={{context.transform.props | safe}} ;
3
+ {% else %}
4
+ const formProps={};
5
+ {% endif %}
6
+
7
+ function actionClick(){
8
+ flow.continueForNext({key:'{{indexKey}}'});
9
+ }
10
+
11
+ formProps.form=form;
12
+
13
+ formProps.actionClick=actionClick;
14
+
15
+ function Form(){
16
+ React.useEffect(()=>{
17
+
18
+ {% if workflow.parent.context.atom.doc.features.print_form_mounts %}
19
+ console.log('MOUNT:','{{indexKey}}');
20
+ {% endif %}
21
+
22
+ return ()=>{
23
+ {% if workflow.parent.context.atom.doc.features.print_form_mounts %}
24
+ console.log('UNMOUNT:','{{indexKey}}');
25
+ {% endif %}
26
+ }
27
+ },[]);
28
+
29
+ return React.createElement(formLib,formProps);
30
+ }
31
+
32
+ engine.setActiveForm({ form: Form, props:formProps });
@@ -0,0 +1,39 @@
1
+ {# variables #}
2
+ const v=flow.get();
3
+
4
+ {# module #}
5
+ {% if hasModules %}
6
+ const m={};
7
+ {% else %}
8
+ const m = null;
9
+ {% endif %}
10
+
11
+ {# form #}
12
+ {% if type === 'form' %}
13
+ const form={};
14
+ {% else %}
15
+ const form=null;
16
+ {% endif %}
17
+
18
+ {# closure #}
19
+ const c={ caller, resolve, reject, args, get form(){return form||caller?.form}, get module(){return m||caller?.module} };
20
+
21
+ {% if workflow.parent.context.atom.doc.features.print_steps %}
22
+ console.log(new Date().toLocaleString(),'{{indexKey}}');
23
+ {% endif %}
24
+
25
+ {% if definition.debugger %}
26
+ debugger;
27
+ {% endif %}
28
+
29
+ {% if context.transform.print %}
30
+ print({{context.transform.print | safe}});
31
+ {% endif%}
32
+
33
+ {% if context.transform.assert %}
34
+ assert({{context.transform.assert | safe}});
35
+ {% endif%}
36
+
37
+ {% if context.transform.sleep %}
38
+ await sleep({{context.transform.sleep}});
39
+ {% endif %}
@@ -0,0 +1,8 @@
1
+ {% if context.transform.page %}
2
+ const page= {{context.transform.page | safe}};
3
+
4
+ {% if definition.page.title %}
5
+ document? document.title=page.title:undefined;
6
+ {% endif %}
7
+
8
+ {% endif %}
@@ -0,0 +1,7 @@
1
+ // WORKFLOW: {{ indexKey }}
2
+
3
+ import Object from "../core/object";
4
+
5
+ {% if context.transform.print %}
6
+ import print from "../core/print";
7
+ {% endif %}
@@ -0,0 +1,120 @@
1
+ {% if atom.doc.features.project.format === 'esm' %}
2
+ import fnetArgs from '@fnet/args';
3
+ import validate from "./validate_input";
4
+ {% elif atom.doc.features.project.format === 'cjs' %}
5
+ const fnetArgs = require('@fnet/args');
6
+ const validate = require("./validate_input");
7
+ {% endif %}
8
+
9
+ {% if atom.doc.features.cli.fargs and atom.doc.features.cli.fargs?.enabled !== false %}
10
+
11
+ const get_fargs = (argv) => {
12
+ const fargsIndex = argv.indexOf('--fargs');
13
+ if (fargsIndex !== -1 && argv[fargsIndex + 1]) return argv[fargsIndex + 1];
14
+ {% if atom.doc.features.cli.fargs.default %}
15
+ else return "{{atom.doc.features.cli.fargs.default}}";
16
+ {% endif %}
17
+ };
18
+
19
+ const get_ftags = (argv) => {
20
+ const ftags = [];
21
+ for (let i = 0; i < argv.length; i++) {
22
+ if (argv[i] === '--ftag' && argv[i + 1]) {
23
+ ftags.push(argv[i + 1]);
24
+ i++;
25
+ }
26
+ }
27
+
28
+ {% if atom.doc.features.cli.fargs.tags %}
29
+ return ftags.length > 0 ? ftags : {{atom.doc.features.cli.fargs.tags | dump | safe}};
30
+ {% else %}
31
+ return ftags.length > 0 ? ftags : undefined;
32
+ {% endif %}
33
+ };
34
+
35
+ {% endif %}
36
+
37
+ {% if atom.doc.features.project.format === 'esm' %}
38
+
39
+ export default async () => {
40
+
41
+ let schema = {{options | dump | safe}};
42
+ let initial;
43
+
44
+ {% if atom.doc.features.cli.fargs and atom.doc.features.cli.fargs?.enabled !== false %}
45
+ const fargs = get_fargs(process.argv.slice(2));
46
+ const ftags = get_ftags(process.argv.slice(2));
47
+
48
+ if (fargs) {
49
+ const { default: fnetConfig } = await import("@fnet/config");
50
+ const config = await fnetConfig({ name: fargs, tags: ftags });
51
+ if (config?.data) {
52
+ initial=config.data;
53
+ }
54
+ }
55
+ {% endif %}
56
+
57
+ const packageCallback = async () => {
58
+ const { default: url } = await import("node:url");
59
+ const { default: path } = await import("node:path");
60
+ const { default: fs } = await import("node:fs");
61
+ let currentDir = path.dirname(url.fileURLToPath(import.meta.url));
62
+ let firstPackageJson = path.join(currentDir, "package.json");
63
+ while (currentDir !== path.parse(currentDir).root && !fs.existsSync(firstPackageJson)) {
64
+ currentDir = path.dirname(currentDir);
65
+ firstPackageJson = path.join(currentDir, "package.json");
66
+ }
67
+ if (!fs.existsSync(firstPackageJson)) return {
68
+ name: "Unknown",
69
+ version: "Unknown"
70
+ }
71
+ else return await JSON.parse(fs.readFileSync(firstPackageJson, "utf8"));
72
+ };
73
+
74
+ return await fnetArgs({schema,initial,validate,packageCallback});
75
+ };
76
+
77
+ {% elif atom.doc.features.project.format === 'cjs' %}
78
+
79
+ module.exports = async () => {
80
+ let schema = {{options | dump | safe}};
81
+ let initial;
82
+
83
+ {% if atom.doc.features.cli.fargs and atom.doc.features.cli.fargs?.enabled !== false %}
84
+ const fargs = get_fargs(process.argv.slice(2));
85
+ const ftags = get_ftags(process.argv.slice(2));
86
+
87
+ if (fargs) {
88
+ const { default: fnetConfig } = await import("@fnet/config");
89
+ const config = await fnetConfig({ name: fargs, tags: ftags });
90
+ if (config?.data) {
91
+ initial=config.data;
92
+ }
93
+ }
94
+ {% endif %}
95
+
96
+ const packageCallback = async () => {
97
+ const path = require("node:path");
98
+ const fs = require("node:fs");
99
+
100
+ let currentDir = __dirname;
101
+ let firstPackageJson = path.join(currentDir, "package.json");
102
+
103
+ while (currentDir !== path.parse(currentDir).root && !fs.existsSync(firstPackageJson)) {
104
+ currentDir = path.dirname(currentDir);
105
+ firstPackageJson = path.join(currentDir, "package.json");
106
+ }
107
+
108
+ if (!fs.existsSync(firstPackageJson)) {
109
+ return {
110
+ name: "Unknown",
111
+ version: "Unknown"
112
+ };
113
+ } else {
114
+ return JSON.parse(fs.readFileSync(firstPackageJson, "utf8"));
115
+ }
116
+ };
117
+
118
+ return await fnetArgs({schema,initial,validate,packageCallback});
119
+ };
120
+ {% endif %}
@@ -0,0 +1,117 @@
1
+ {% include "src/default/macros/workflow-header.js.njk" %}
2
+
3
+ {% if context.next %}
4
+ {% if not context.next.definition.dynamic %}
5
+ // NEXT: {{context.next.indexKey}}
6
+ import {{context.next.codeKey}} from "./blocks/{{context.next.codeKey}}";
7
+ {% endif %}
8
+ {% endif %}
9
+
10
+ export default class Workflow extends Object {
11
+
12
+ #waitContext;
13
+
14
+ constructor(context) {
15
+ super(context);
16
+
17
+ this.engine=context.engine;
18
+ }
19
+
20
+ async init(context) {
21
+
22
+ {% if context.transform.params %}
23
+ const params = context?.params;
24
+
25
+ {% for param in context.transform.params %}
26
+ {% if param.hasDefault%}
27
+ {% if param.type ==='string'%}
28
+ this.set('{{param.key}}', params?.hasOwnProperty('{{param.key}}')? params['{{param.key}}']:'{{param.default}}');
29
+ {% else %}
30
+ this.set('{{param.key}}', params?.hasOwnProperty('{{param.key}}')? params['{{param.key}}']:{{param.default | dump}});
31
+ {% endif %}
32
+ {% else %}
33
+ this.set('{{param.key}}',this.getValue(params,'{{param.key}}'));
34
+ {% endif %}
35
+ {% endfor%}
36
+
37
+ this.set('$params',params);
38
+
39
+ {% endif %}
40
+ }
41
+
42
+ waitForNext(context){
43
+ this.#waitContext=context;
44
+ }
45
+
46
+ async continueForNext(context){
47
+ const next=this.#waitContext?.next;
48
+ this.#waitContext=undefined;
49
+ next && await next();
50
+ }
51
+
52
+ async run(context) {
53
+
54
+ {% if workflow.parent.context.atom.doc.features.print_steps %}
55
+ console.log(new Date().toLocaleString(),'{{indexKey}}');
56
+ {% endif %}
57
+
58
+ {% if definition.debugger %}
59
+ debugger;
60
+ {% endif %}
61
+
62
+ {% if context.transform.print %}
63
+ print({{context.transform.print | safe}});
64
+ {% endif%}
65
+
66
+ {% if context.transform.assert %}
67
+ assert({{context.transform.assert | safe}});
68
+ {% endif%}
69
+
70
+ {% if context.transform.sleep %}
71
+ await sleep({{context.transform.sleep}});
72
+ {% endif %}
73
+
74
+ await this.init(context);
75
+
76
+ {% if context.next %}
77
+
78
+ {% if context.next.definition.dynamic %}
79
+ // NEXT : {{context.next.indexKey}}
80
+ const { default: {{context.next.codeKey}} } = await import("./blocks/{{context.next.codeKey}}");
81
+ {% endif %}
82
+
83
+ {# closure #}
84
+ const c={};
85
+
86
+ let current=new {{context.next.codeKey}}({ parent:this, engine:this.engine, flow:this, caller:c });
87
+ let currentArgs;
88
+
89
+ do {
90
+
91
+ {% if workflow.parent.context.atom.doc.features.print_runners %}
92
+ console.log(new Date().toLocaleString(),' * ', this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
93
+ {% endif %}
94
+
95
+ const nextBlock= typeof currentArgs==='undefined'? await current.run()
96
+ : Array.isArray(currentArgs)? await current.run.apply(current,currentArgs) : await current.run.call(current, currentArgs) ;
97
+
98
+
99
+ if(nextBlock?.type==='return') return nextBlock;
100
+ else if(nextBlock?.type!=='block') break;
101
+
102
+ if(nextBlock.toType.ParentTypeId!==this.constructor.TypeId)
103
+ throw new Error('Unknown situation');
104
+
105
+ current=new nextBlock.toType({ parent:this, engine:this.engine, flow:this, caller:c });
106
+ currentArgs=nextBlock.withArgs;
107
+
108
+ } while(true);
109
+
110
+ {% endif %}
111
+
112
+ return this.result;
113
+ }
114
+ }
115
+
116
+ Workflow.TypeId="{{typeId}}";
117
+ Workflow.IndexKey="{{indexKey}}";
@@ -0,0 +1,16 @@
1
+ {
2
+ "include": [
3
+ "src/**/*.js"
4
+ ],
5
+ "compilerOptions": {
6
+ "outDir": "./types",
7
+ "declaration": true,
8
+ "allowJs": true,
9
+ "emitDeclarationOnly": true,
10
+ "target": "es5",
11
+ "strict": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "skipLibCheck": true,
14
+ "jsx": "react-jsx"
15
+ }
16
+ }
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ .workspace
3
+ .fnet
4
+ .out
5
+ .package
6
+ .npmrc
7
+ .vscode
@@ -0,0 +1,41 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "debug-fnet-cli",
9
+ "type": "node",
10
+ "request": "launch",
11
+ "skipFiles": [
12
+ "<node_internals>/**"
13
+ ],
14
+ "program": "${workspaceFolder}/.workspace/dist/cli/esm/index.js",
15
+ "cwd": "${workspaceFolder}/.workspace",
16
+ "preLaunchTask": "fnet-watch",
17
+ "console": "integratedTerminal"
18
+ },
19
+ {
20
+ "name": "debug-fnet-app",
21
+ "type": "chrome",
22
+ "request": "launch",
23
+ "url": "http://localhost:3000/dist/app/esm/",
24
+ "webRoot": "${workspaceFolder}/.workspace",
25
+ "preLaunchTask": "fnet-watch",
26
+ // "userDataDir": false,
27
+ // "runtimeArgs": [
28
+ // "--profile-directory=<profile-name>",
29
+ // ]
30
+ },
31
+ ],
32
+ // "compounds": [
33
+ // {
34
+ // "name": "debug-fnet-all",
35
+ // "configurations": [
36
+ // "debug-fnet-cli",
37
+ // "debug-fnet-app"
38
+ // ]
39
+ // }
40
+ // ]
41
+ }