jostraca 0.5.0 → 0.6.0

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 (55) hide show
  1. package/dist/cmp/Content.d.ts +2 -0
  2. package/dist/cmp/Content.js +12 -0
  3. package/dist/cmp/Content.js.map +1 -0
  4. package/dist/cmp/Copy.d.ts +1 -1
  5. package/dist/cmp/Copy.js +6 -19
  6. package/dist/cmp/Copy.js.map +1 -1
  7. package/dist/cmp/File.d.ts +2 -0
  8. package/dist/cmp/File.js +13 -0
  9. package/dist/cmp/File.js.map +1 -0
  10. package/dist/cmp/Folder.d.ts +2 -0
  11. package/dist/cmp/Folder.js +12 -0
  12. package/dist/cmp/Folder.js.map +1 -0
  13. package/dist/cmp/Project.d.ts +2 -0
  14. package/dist/cmp/Project.js +13 -0
  15. package/dist/cmp/Project.js.map +1 -0
  16. package/dist/jostraca.d.ts +8 -40
  17. package/dist/jostraca.js +98 -290
  18. package/dist/jostraca.js.map +1 -1
  19. package/dist/op/ContentOp.d.ts +6 -0
  20. package/dist/op/ContentOp.js +12 -0
  21. package/dist/op/ContentOp.js.map +1 -0
  22. package/dist/op/CopyOp.d.ts +1 -1
  23. package/dist/op/CopyOp.js +111 -14
  24. package/dist/op/CopyOp.js.map +1 -1
  25. package/dist/op/FileOp.d.ts +6 -0
  26. package/dist/op/FileOp.js +43 -0
  27. package/dist/op/FileOp.js.map +1 -0
  28. package/dist/op/FolderOp.d.ts +6 -0
  29. package/dist/op/FolderOp.js +23 -0
  30. package/dist/op/FolderOp.js.map +1 -0
  31. package/dist/op/NoneOp.d.ts +6 -0
  32. package/dist/op/NoneOp.js +9 -0
  33. package/dist/op/NoneOp.js.map +1 -0
  34. package/dist/op/ProjectOp.d.ts +6 -0
  35. package/dist/op/ProjectOp.js +24 -0
  36. package/dist/op/ProjectOp.js.map +1 -0
  37. package/dist/tsconfig.tsbuildinfo +1 -1
  38. package/dist/utility.d.ts +44 -0
  39. package/dist/utility.js +213 -0
  40. package/dist/utility.js.map +1 -0
  41. package/package.json +3 -3
  42. package/src/cmp/Content.ts +19 -0
  43. package/src/cmp/Copy.ts +9 -22
  44. package/src/cmp/File.ts +21 -0
  45. package/src/cmp/Folder.ts +21 -0
  46. package/src/cmp/Project.ts +22 -0
  47. package/src/jostraca.ts +114 -385
  48. package/src/op/ContentOp.ts +18 -0
  49. package/src/op/CopyOp.ts +137 -16
  50. package/src/op/FileOp.ts +58 -0
  51. package/src/op/FolderOp.ts +31 -0
  52. package/src/op/NoneOp.ts +14 -0
  53. package/src/op/ProjectOp.ts +33 -0
  54. package/src/utility.ts +306 -0
  55. package/src/op/CopyOp.ts~ +0 -12
@@ -0,0 +1,2 @@
1
+ declare const Content: import("../utility").Component;
2
+ export { Content };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Content = void 0;
4
+ const jostraca_1 = require("../jostraca");
5
+ const Content = (0, jostraca_1.cmp)(function Content(props, _children) {
6
+ const node = props.ctx$.node;
7
+ node.kind = 'content';
8
+ let src = props.arg;
9
+ node.content = src;
10
+ });
11
+ exports.Content = Content;
12
+ //# sourceMappingURL=Content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Content.js","sourceRoot":"","sources":["../../src/cmp/Content.ts"],"names":[],"mappings":";;;AAIA,0CAAiC;AAGjC,MAAM,OAAO,GAAG,IAAA,cAAG,EAAC,SAAS,OAAO,CAAC,KAAU,EAAE,SAAc;IAC7D,MAAM,IAAI,GAAS,KAAK,CAAC,IAAI,CAAC,IAAI,CAAA;IAClC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAA;IACrB,IAAI,GAAG,GAAG,KAAK,CAAC,GAAG,CAAA;IACnB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAA;AACpB,CAAC,CAAC,CAAA;AAKA,0BAAO"}
@@ -1,2 +1,2 @@
1
- declare const Copy: import("../jostraca").Component;
1
+ declare const Copy: import("../utility").Component;
2
2
  export { Copy };
package/dist/cmp/Copy.js CHANGED
@@ -2,25 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Copy = void 0;
4
4
  const jostraca_1 = require("../jostraca");
5
- const Copy = (0, jostraca_1.cmp)(function Copy(props, children) {
6
- const fs = props.ctx$.fs;
7
- const name = props.name;
8
- const from = props.from;
9
- const fromStat = fs.statSync(from);
10
- if (fromStat.isFile()) {
11
- props.ctx$.node.kind = 'file';
12
- props.ctx$.node.name = props.name;
13
- const content = fs.readFileSync(from).toString();
14
- (0, jostraca_1.Code)(content);
15
- }
16
- else if (fromStat.isDirectory()) {
17
- props.ctx$.node.kind = 'copy';
18
- props.ctx$.node.name = props.name;
19
- props.ctx$.node.from = from;
20
- }
21
- else {
22
- throw new Error('Copy: invalid from: ' + from);
23
- }
5
+ const Copy = (0, jostraca_1.cmp)(function Copy(props, _children) {
6
+ const node = props.ctx$.node;
7
+ node.kind = 'copy';
8
+ node.name = props.name;
9
+ node.from = props.from;
10
+ node.exclude = null == props.exclude ? node.exclude : !!props.exclude;
24
11
  });
25
12
  exports.Copy = Copy;
26
13
  //# sourceMappingURL=Copy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Copy.js","sourceRoot":"","sources":["../../src/cmp/Copy.ts"],"names":[],"mappings":";;;AAEA,0CAAuC;AAGvC,MAAM,IAAI,GAAG,IAAA,cAAG,EAAC,SAAS,IAAI,CAAC,KAAU,EAAE,QAAa;IACtD,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAA;IACxB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACvB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IAEvB,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAElC,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAA;QAC7B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;QACjC,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;QAChD,IAAA,eAAI,EAAC,OAAO,CAAC,CAAA;IACf,CAAC;SACI,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAA;QAC7B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;QACjC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAC7B,CAAC;SACI,CAAC;QACJ,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAA;IAChD,CAAC;AAEH,CAAC,CAAC,CAAA;AAKA,oBAAI"}
1
+ {"version":3,"file":"Copy.js","sourceRoot":"","sources":["../../src/cmp/Copy.ts"],"names":[],"mappings":";;;AAGA,0CAAiC;AAGjC,MAAM,IAAI,GAAG,IAAA,cAAG,EAAC,SAAS,IAAI,CAAC,KAAU,EAAE,SAAc;IACvD,MAAM,IAAI,GAAS,KAAK,CAAC,IAAI,CAAC,IAAI,CAAA;IAElC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAA;IAClB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACtB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACtB,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAA;AACvE,CAAC,CAAC,CAAA;AAKA,oBAAI"}
@@ -0,0 +1,2 @@
1
+ declare const File: import("../utility").Component;
2
+ export { File };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.File = void 0;
4
+ const jostraca_1 = require("../jostraca");
5
+ const File = (0, jostraca_1.cmp)(function File(props, children) {
6
+ const node = props.ctx$.node;
7
+ node.kind = 'file';
8
+ node.name = props.name;
9
+ node.exclude = null == props.exclude ? node.exclude : !!props.exclude;
10
+ (0, jostraca_1.each)(children);
11
+ });
12
+ exports.File = File;
13
+ //# sourceMappingURL=File.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"File.js","sourceRoot":"","sources":["../../src/cmp/File.ts"],"names":[],"mappings":";;;AAGA,0CAAuC;AAGvC,MAAM,IAAI,GAAG,IAAA,cAAG,EAAC,SAAS,IAAI,CAAC,KAAU,EAAE,QAAa;IACtD,MAAM,IAAI,GAAS,KAAK,CAAC,IAAI,CAAC,IAAI,CAAA;IAElC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAA;IAClB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACtB,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAA;IAErE,IAAA,eAAI,EAAC,QAAQ,CAAC,CAAA;AAChB,CAAC,CAAC,CAAA;AAKA,oBAAI"}
@@ -0,0 +1,2 @@
1
+ declare const Folder: import("../utility").Component;
2
+ export { Folder };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Folder = void 0;
4
+ const jostraca_1 = require("../jostraca");
5
+ const Folder = (0, jostraca_1.cmp)(function Folder(props, children) {
6
+ const node = props.ctx$.node;
7
+ node.kind = 'folder';
8
+ node.name = props.name;
9
+ (0, jostraca_1.each)(children);
10
+ });
11
+ exports.Folder = Folder;
12
+ //# sourceMappingURL=Folder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Folder.js","sourceRoot":"","sources":["../../src/cmp/Folder.ts"],"names":[],"mappings":";;;AAIA,0CAAuC;AAGvC,MAAM,MAAM,GAAG,IAAA,cAAG,EAAC,SAAS,MAAM,CAAC,KAAU,EAAE,QAAa;IAC1D,MAAM,IAAI,GAAS,KAAK,CAAC,IAAI,CAAC,IAAI,CAAA;IAElC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAA;IACpB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IAEtB,IAAA,eAAI,EAAC,QAAQ,CAAC,CAAA;AAChB,CAAC,CAAC,CAAA;AAKA,wBAAM"}
@@ -0,0 +1,2 @@
1
+ declare const Project: import("../utility").Component;
2
+ export { Project };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Project = void 0;
4
+ const jostraca_1 = require("../jostraca");
5
+ const Project = (0, jostraca_1.cmp)(function Project(props, children) {
6
+ const node = props.ctx$.node;
7
+ node.kind = 'project';
8
+ node.name = props.name;
9
+ node.folder = props.folder;
10
+ (0, jostraca_1.each)(children);
11
+ });
12
+ exports.Project = Project;
13
+ //# sourceMappingURL=Project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Project.js","sourceRoot":"","sources":["../../src/cmp/Project.ts"],"names":[],"mappings":";;;AAIA,0CAAuC;AAGvC,MAAM,OAAO,GAAG,IAAA,cAAG,EAAC,SAAS,OAAO,CAAC,KAAU,EAAE,QAAa;IAC5D,MAAM,IAAI,GAAS,KAAK,CAAC,IAAI,CAAC,IAAI,CAAA;IAElC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAA;IACrB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;IAE1B,IAAA,eAAI,EAAC,QAAQ,CAAC,CAAA;AAChB,CAAC,CAAC,CAAA;AAKA,0BAAO"}
@@ -1,45 +1,13 @@
1
+ import type { JostracaOptions, Node, Component } from './utility';
2
+ import { each, select, get, getx, camelify, snakify, kebabify, cmap, vmap, names } from './utility';
3
+ import { Content } from './cmp/Content';
1
4
  import { Copy } from './cmp/Copy';
2
- type JostracaOptions = {
3
- folder?: string;
4
- fs?: any;
5
- meta?: any;
6
- };
7
- type Node = {
8
- kind: string;
9
- children?: Node[];
10
- name?: string;
11
- path?: string;
12
- from?: string;
13
- content?: any[];
14
- };
15
- type Component = (props: any, children?: any) => void;
5
+ import { File } from './cmp/File';
6
+ import { Folder } from './cmp/Folder';
7
+ import { Project } from './cmp/Project';
16
8
  declare function Jostraca(): {
17
- generate: (opts: JostracaOptions, root: Function) => void;
9
+ generate: (opts: JostracaOptions, root: Function) => Promise<any>;
18
10
  };
19
- declare const Code: Component;
20
- declare const File: Component;
21
- declare const Project: Component;
22
- declare const Folder: Component;
23
11
  declare function cmp(component: Function): Component;
24
- declare function each(subject?: any, apply?: any): any;
25
- declare function select(key: any, map: Record<string, Function>): any;
26
- declare function getx(root: any, path: string | string[]): any;
27
- declare function get(root: any, path: string | string[]): any;
28
- declare function camelify(input: any[] | string): string;
29
- declare function kebabify(input: any[] | string): string;
30
- declare function snakify(input: any[] | string): string;
31
- declare function names(base: any, name: string, prop?: string): void;
32
- declare function cmap(o: any, p: any): any;
33
- declare namespace cmap {
34
- var COPY: (x: any) => any;
35
- var FILTER: (x: any) => any;
36
- var KEY: (_: any, p: any) => any;
37
- }
38
- declare function vmap(o: any, p: any): any;
39
- declare namespace vmap {
40
- var COPY: (x: any) => any;
41
- var FILTER: (x: any) => any;
42
- var KEY: (_: any, p: any) => any;
43
- }
44
12
  export type { JostracaOptions, Component, Node, };
45
- export { Jostraca, cmp, each, select, get, getx, camelify, snakify, kebabify, cmap, vmap, names, Project, Code, File, Folder, Copy, };
13
+ export { Jostraca, cmp, each, select, get, getx, camelify, snakify, kebabify, cmap, vmap, names, Project, Content, File, Folder, Copy, };
package/dist/jostraca.js CHANGED
@@ -23,56 +23,74 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  __setModuleDefault(result, mod);
24
24
  return result;
25
25
  };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
26
29
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.Copy = exports.Folder = exports.File = exports.Code = exports.Project = void 0;
30
+ exports.Copy = exports.Folder = exports.File = exports.Content = exports.Project = exports.names = exports.vmap = exports.cmap = exports.kebabify = exports.snakify = exports.camelify = exports.getx = exports.get = exports.select = exports.each = void 0;
28
31
  exports.Jostraca = Jostraca;
29
32
  exports.cmp = cmp;
30
- exports.each = each;
31
- exports.select = select;
32
- exports.get = get;
33
- exports.getx = getx;
34
- exports.camelify = camelify;
35
- exports.snakify = snakify;
36
- exports.kebabify = kebabify;
37
- exports.cmap = cmap;
38
- exports.vmap = vmap;
39
- exports.names = names;
40
33
  const Fs = __importStar(require("node:fs"));
34
+ const node_path_1 = __importDefault(require("node:path"));
41
35
  const node_async_hooks_1 = require("node:async_hooks");
36
+ const utility_1 = require("./utility");
37
+ Object.defineProperty(exports, "each", { enumerable: true, get: function () { return utility_1.each; } });
38
+ Object.defineProperty(exports, "select", { enumerable: true, get: function () { return utility_1.select; } });
39
+ Object.defineProperty(exports, "get", { enumerable: true, get: function () { return utility_1.get; } });
40
+ Object.defineProperty(exports, "getx", { enumerable: true, get: function () { return utility_1.getx; } });
41
+ Object.defineProperty(exports, "camelify", { enumerable: true, get: function () { return utility_1.camelify; } });
42
+ Object.defineProperty(exports, "snakify", { enumerable: true, get: function () { return utility_1.snakify; } });
43
+ Object.defineProperty(exports, "kebabify", { enumerable: true, get: function () { return utility_1.kebabify; } });
44
+ Object.defineProperty(exports, "cmap", { enumerable: true, get: function () { return utility_1.cmap; } });
45
+ Object.defineProperty(exports, "vmap", { enumerable: true, get: function () { return utility_1.vmap; } });
46
+ Object.defineProperty(exports, "names", { enumerable: true, get: function () { return utility_1.names; } });
47
+ const Content_1 = require("./cmp/Content");
48
+ Object.defineProperty(exports, "Content", { enumerable: true, get: function () { return Content_1.Content; } });
42
49
  const Copy_1 = require("./cmp/Copy");
43
50
  Object.defineProperty(exports, "Copy", { enumerable: true, get: function () { return Copy_1.Copy; } });
51
+ const File_1 = require("./cmp/File");
52
+ Object.defineProperty(exports, "File", { enumerable: true, get: function () { return File_1.File; } });
53
+ const Folder_1 = require("./cmp/Folder");
54
+ Object.defineProperty(exports, "Folder", { enumerable: true, get: function () { return Folder_1.Folder; } });
55
+ const Project_1 = require("./cmp/Project");
56
+ Object.defineProperty(exports, "Project", { enumerable: true, get: function () { return Project_1.Project; } });
44
57
  const CopyOp_1 = require("./op/CopyOp");
45
- const jsonic_next_1 = require("@jsonic/jsonic-next");
46
- const { deep } = jsonic_next_1.util;
58
+ const ProjectOp_1 = require("./op/ProjectOp");
59
+ const FolderOp_1 = require("./op/FolderOp");
60
+ const FileOp_1 = require("./op/FileOp");
61
+ const ContentOp_1 = require("./op/ContentOp");
62
+ const NoneOp_1 = require("./op/NoneOp");
47
63
  const GLOBAL = global;
48
64
  function Jostraca() {
49
65
  GLOBAL.jostraca = new node_async_hooks_1.AsyncLocalStorage();
50
- function generate(opts, root) {
66
+ async function generate(opts, root) {
51
67
  const fs = opts.fs || Fs;
52
68
  const meta = opts.meta || {};
53
69
  const folder = opts.folder || '.';
54
70
  const ctx$ = {
55
- fs,
56
71
  folder,
57
72
  content: null,
58
73
  meta,
74
+ fs,
59
75
  };
60
- GLOBAL.jostraca.run(ctx$, () => {
76
+ return GLOBAL.jostraca.run(ctx$, async () => {
61
77
  try {
62
- // console.log('START ROOT')
78
+ // Define phase
63
79
  root();
64
- // console.log('END ROOT')
65
80
  const ctx$ = GLOBAL.jostraca.getStore();
66
- // console.log('START BUILD')
67
- build(ctx$, {
81
+ // console.dir(ctx$.node, { depth: null })
82
+ // Build phase
83
+ const buildctx = {
68
84
  fs,
85
+ folder,
69
86
  current: {
70
87
  folder: {
71
88
  parent: folder
72
89
  }
73
90
  }
74
- });
75
- // console.log('END BUILD')
91
+ };
92
+ await build(ctx$, buildctx);
93
+ return buildctx;
76
94
  }
77
95
  catch (err) {
78
96
  console.log('JOSTRACA ERROR:', err);
@@ -80,104 +98,69 @@ function Jostraca() {
80
98
  }
81
99
  });
82
100
  }
83
- function build(ctx$, buildctx) {
101
+ async function build(ctx$, buildctx) {
84
102
  const topnode = ctx$.node;
85
- step(topnode, ctx$, buildctx);
103
+ let info = { exclude: [], last: -1 };
104
+ const infopath = node_path_1.default.join(buildctx.folder, '.jostraca', 'info.json');
105
+ try {
106
+ info = JSON.parse(ctx$.fs.readFileSync(infopath, 'utf8'));
107
+ }
108
+ catch (err) {
109
+ // console.log(err)
110
+ // TODO: file not foound ignored, handle others!
111
+ }
112
+ buildctx.info = info;
113
+ // console.log('B-INFO', buildctx.info)
114
+ await step(topnode, ctx$, buildctx);
115
+ try {
116
+ const info = {
117
+ last: Date.now(),
118
+ exclude: buildctx.info.exclude,
119
+ };
120
+ ctx$.fs.mkdirSync(node_path_1.default.dirname(infopath), { recursive: true });
121
+ ctx$.fs.writeFileSync(infopath, JSON.stringify(info, null, 2));
122
+ }
123
+ catch (err) {
124
+ console.log(err);
125
+ // TODO: file not foound ignored, handle others!
126
+ }
127
+ return { node: topnode, ctx$, buildctx };
86
128
  }
87
- function step(node, ctx$, buildctx) {
88
- const op = opmap[node.kind];
89
- if (null == op) {
90
- throw new Error('missing op: ' + node.kind);
129
+ async function step(node, ctx$, buildctx) {
130
+ try {
131
+ const op = opmap[node.kind];
132
+ if (null == op) {
133
+ throw new Error('missing op: ' + node.kind);
134
+ }
135
+ await op.before(node, ctx$, buildctx);
136
+ if (node.children) {
137
+ for (let childnode of node.children) {
138
+ await step(childnode, ctx$, buildctx);
139
+ }
140
+ }
141
+ await op.after(node, ctx$, buildctx);
91
142
  }
92
- op.before(node, ctx$, buildctx);
93
- if (node.children) {
94
- for (let childnode of node.children) {
95
- step(childnode, ctx$, buildctx);
143
+ catch (err) {
144
+ if (err.jostraca) {
145
+ throw err;
96
146
  }
147
+ err.jostraca = true;
148
+ err.step = node.kind;
149
+ throw err;
97
150
  }
98
- op.after(node, ctx$, buildctx);
99
151
  }
100
152
  const opmap = {
101
- project: {
102
- before(node, _ctx$, buildctx) {
103
- const cproject = buildctx.current.project = (buildctx.current.project || {});
104
- cproject.node = node;
105
- },
106
- after(_node, _ctx$, _buildctx) {
107
- },
108
- },
109
- folder: {
110
- before(node, _ctx$, buildctx) {
111
- const cfolder = buildctx.current.folder = (buildctx.current.folder || {});
112
- cfolder.node = node;
113
- cfolder.path = (cfolder.path || [buildctx.current.folder.parent]);
114
- cfolder.path.push(node.name);
115
- let fullpath = cfolder.path.join('/');
116
- buildctx.fs.mkdirSync(fullpath, { recursive: true });
117
- },
118
- after(_node, _ctx$, buildctx) {
119
- const cfolder = buildctx.current.folder;
120
- cfolder.path.length = cfolder.path.length - 1;
121
- },
122
- },
123
- file: {
124
- before(node, _ctx$, buildctx) {
125
- const cfile = buildctx.current.file = node;
126
- cfile.path = buildctx.current.folder.path.join('/') + '/' + node.name;
127
- cfile.content = [];
128
- },
129
- after(_node, _ctx$, buildctx) {
130
- const cfile = buildctx.current.file;
131
- const content = cfile.content.join('');
132
- buildctx.fs.writeFileSync(cfile.path, content);
133
- },
134
- },
135
- content: {
136
- before(node, _ctx$, buildctx) {
137
- const content = buildctx.current.content = node;
138
- buildctx.current.file.content.push(content.content);
139
- },
140
- after(_node, _ctx$, buildctx) {
141
- },
142
- },
153
+ project: ProjectOp_1.ProjectOp,
154
+ folder: FolderOp_1.FolderOp,
155
+ file: FileOp_1.FileOp,
156
+ content: ContentOp_1.ContentOp,
143
157
  copy: CopyOp_1.CopyOp,
144
- none: {
145
- before(_node, _ctx$, buildctx) {
146
- },
147
- after(_node, _ctx$, buildctx) {
148
- },
149
- },
158
+ none: NoneOp_1.NoneOp,
150
159
  };
151
160
  return {
152
161
  generate,
153
162
  };
154
163
  }
155
- const Code = cmp(function Code(props) {
156
- props.ctx$.node.kind = 'content';
157
- let src = props.arg;
158
- props.ctx$.node.content = src;
159
- });
160
- exports.Code = Code;
161
- const File = cmp(function File(props, children) {
162
- props.ctx$.node.kind = 'file';
163
- props.ctx$.node.name = props.name;
164
- // Code('// FILE START: ' + props.name + '\n')
165
- each(children);
166
- // Code('// FILE END: ' + props.name + '\n')
167
- });
168
- exports.File = File;
169
- const Project = cmp(function Project(props, children) {
170
- props.ctx$.node.kind = 'project';
171
- props.ctx$.node.name = props.name;
172
- each(children);
173
- });
174
- exports.Project = Project;
175
- const Folder = cmp(function Folder(props, children) {
176
- props.ctx$.node.kind = 'folder';
177
- props.ctx$.node.name = props.name;
178
- each(children);
179
- });
180
- exports.Folder = Folder;
181
164
  function cmp(component) {
182
165
  const cf = (props, children) => {
183
166
  props = props || {};
@@ -188,13 +171,20 @@ function cmp(component) {
188
171
  children = 'function' === typeof children ? [children] : children;
189
172
  let node = {
190
173
  kind: 'none',
191
- children: []
174
+ children: [],
175
+ path: [],
192
176
  };
193
177
  const parent = props.ctx$.node = (props.ctx$.node || node);
194
178
  const siblings = props.ctx$.children = (props.ctx$.children || []);
195
179
  siblings.push(node);
196
180
  props.ctx$.children = node.children;
197
181
  props.ctx$.node = node;
182
+ node.path = parent.path.slice(0);
183
+ if ('string' === typeof props.name) {
184
+ node.path.push(props.name);
185
+ // console.log('CMP-PATH', component.name, node.path)
186
+ // console.trace()
187
+ }
198
188
  let out = component(props, children);
199
189
  props.ctx$.children = siblings;
200
190
  props.ctx$.node = parent;
@@ -203,186 +193,4 @@ function cmp(component) {
203
193
  Object.defineProperty(cf, 'name', { value: component.name });
204
194
  return cf;
205
195
  }
206
- function each(subject, apply) {
207
- if (null == apply) {
208
- let out = [];
209
- if (Array.isArray(subject)) {
210
- for (let fn of subject) {
211
- out.push('function' === typeof fn ? fn() : fn);
212
- }
213
- return out.sort();
214
- }
215
- else if (null == subject || 'object' !== typeof subject) {
216
- return [];
217
- }
218
- }
219
- else if (Array.isArray(subject)) {
220
- return subject.map(apply);
221
- }
222
- if (null == subject || 'object' !== typeof subject) {
223
- return [];
224
- }
225
- const entries = Object.entries(subject).map((n, _) => (_ = typeof n[1],
226
- (null != n[1] && 'object' === _) ? (n[1].key$ = n[0]) :
227
- (n[1] = { name: n[0], key$: n[0], val$: n[1] }), n));
228
- if (1 < entries.length) {
229
- if (entries[0] && entries[0][1] && 'string' === typeof entries[0][1].name) {
230
- entries.sort((a, b) => a[1].name < b[1].name ? -1 : b[1].name < a[1].name ? 1 : 0);
231
- }
232
- else if (entries[0] && entries[0][1] && 'string' === typeof entries[0][1].key$) {
233
- entries.sort((a, b) => a[1].key$ < b[1].key$ ? -1 : b[1].key$ < a[1].key$ ? 1 : 0);
234
- }
235
- }
236
- apply = 'function' === typeof apply ? apply : (x) => x;
237
- return entries.map((n, ...args) => apply(n[1], n[0], ...args));
238
- }
239
- function select(key, map) {
240
- const fn = map && map[key];
241
- return fn ? fn() : undefined;
242
- }
243
- function getx(root, path) {
244
- path = ('string' === typeof path ? path.split(/[.\s\r\n\t]/) : path).filter(part => '' != part);
245
- let node = root;
246
- let parents = [];
247
- partloop: for (let i = 0; i < path.length && null != node; i++) {
248
- let part = String(path[i]).trim();
249
- let m = part.match(/^([^<=>~^?!]*)([<=>~^?!]+)(.*)$/);
250
- if (m) {
251
- part = m[1];
252
- let op = m[2];
253
- let arg = m[3];
254
- let val = '' === part ? node : node[part];
255
- if ('=' === op && 'null' === arg) {
256
- parents.push(node);
257
- node = {}; // virtual node so that ^ works consistently
258
- continue partloop;
259
- }
260
- else if ('^' === op && '' === part && '' !== arg) {
261
- node = parents[parents.length - Number(arg)];
262
- continue partloop;
263
- }
264
- else if ('?' === op[0]) {
265
- arg = (1 < op.length ? op.substring(1) : '') + arg;
266
- node = Array.isArray(val) ?
267
- each(val).filter((n) => (null != getx(n, arg))) :
268
- each(val).filter((n) => (null != getx(n, arg)))
269
- .reduce((a, n) => (a[n.key$] = n, delete n.key$, a), {});
270
- continue partloop;
271
- }
272
- if (null == val)
273
- return undefined;
274
- val = Array.isArray(val) ? val.length :
275
- 'object' === typeof val ? Object.keys(val).filter(k => !k.includes('$')).length :
276
- val;
277
- switch (op) {
278
- case '<':
279
- if (!(val < arg))
280
- return undefined;
281
- break;
282
- case '<=':
283
- if (!(val <= arg))
284
- return undefined;
285
- break;
286
- case '>':
287
- if (!(val > arg))
288
- return undefined;
289
- break;
290
- case '>=':
291
- if (!(val >= arg))
292
- return undefined;
293
- break;
294
- case '=':
295
- if (!(val == arg))
296
- return undefined;
297
- break;
298
- case '!=':
299
- if (!(val != arg))
300
- return undefined;
301
- break;
302
- case '~':
303
- if (!(String(val).match(RegExp(arg))))
304
- return undefined;
305
- break;
306
- case '^':
307
- node = parents[parents.length - Number(arg)];
308
- continue partloop;
309
- default:
310
- return undefined;
311
- }
312
- }
313
- parents.push(node);
314
- node = '' === part ? node : node[part];
315
- }
316
- return node;
317
- }
318
- function get(root, path) {
319
- path = 'string' === typeof path ? path.split('.') : path;
320
- let node = root;
321
- for (let i = 0; i < path.length && null != node; i++) {
322
- node = node[path[i]];
323
- }
324
- return node;
325
- }
326
- function camelify(input) {
327
- let parts = 'string' == typeof input ? input.split('-') : input.map(n => '' + n);
328
- return parts
329
- .map((p) => ('' === p ? '' : (p[0].toUpperCase() + p.substring(1))))
330
- .join('');
331
- }
332
- function kebabify(input) {
333
- let parts = 'string' == typeof input ? input.split(/([A-Z])/) : input.map(n => '' + n);
334
- return parts
335
- .filter((p) => '' !== p)
336
- .reduce((a, n, i) => ((0 === i % 2 ? a.push(n.toLowerCase()) : a[(i / 2) | 0] += n), a), [])
337
- .join('-');
338
- }
339
- function snakify(input) {
340
- let parts = 'string' == typeof input ? input.split(/([A-Z])/) : input.map(n => '' + n);
341
- return parts
342
- .filter((p) => '' !== p)
343
- .reduce((a, n, i) => ((0 === i % 2 ? a.push(n.toLowerCase()) : a[(i / 2) | 0] += n), a), [])
344
- .join('_');
345
- }
346
- function names(base, name, prop = 'name') {
347
- base.name$ = name;
348
- base[prop.toLowerCase()] = name.toLowerCase();
349
- base[camelify(prop)] = camelify(name);
350
- base[snakify(prop)] = snakify(name);
351
- base[kebabify(prop)] = kebabify(name);
352
- base[prop.toUpperCase()] = name.toUpperCase();
353
- }
354
- // Map child objects to new child objects
355
- function cmap(o, p) {
356
- return Object
357
- .entries(o)
358
- .reduce((r, n, _) => (_ = Object
359
- .entries(p)
360
- .reduce((s, m) => (cmap.FILTER === s ? s : (s[m[0]] = (
361
- // transfom(val,key,current,parentkey,parent)
362
- 'function' === typeof m[1] ? m[1](n[1][m[0]], {
363
- skey: m[0], self: n[1], key: n[0], parent: o
364
- }) : m[1]), (cmap.FILTER === s[m[0]] ? cmap.FILTER : s))), {})
365
- , (cmap.FILTER === _ ? 0 : r[n[0]] = _), r), {});
366
- }
367
- cmap.COPY = (x) => x;
368
- // keep self if x is truthy, or function returning truthy-new-value or [truthy,new-value]
369
- cmap.FILTER = (x) => 'function' === typeof x ? ((y, p, _) => (_ = x(y, p), Array.isArray(_) ? !_[0] ? _[1] : cmap.FILTER : _)) : (x ? x : cmap.FILTER);
370
- cmap.KEY = (_, p) => p.key;
371
- // Map child objects to a list of child objects
372
- function vmap(o, p) {
373
- return Object
374
- .entries(o)
375
- .reduce((r, n, _) => (_ = Object
376
- .entries(p)
377
- .reduce((s, m) => (vmap.FILTER === s ? s : (s[m[0]] = (
378
- // transfom(val,key,current,parentkey,parent)
379
- // 'function' === typeof m[1] ? m[1](n[1][m[0]], m[0], n[1], n[0], o) : m[1]
380
- 'function' === typeof m[1] ? m[1](n[1][m[0]], {
381
- skey: m[0], self: n[1], key: n[0], parent: o
382
- }) : m[1]), (vmap.FILTER === s[m[0]] ? vmap.FILTER : s))), {})
383
- , (vmap.FILTER === _ ? 0 : r.push(_)), r), []);
384
- }
385
- vmap.COPY = (x) => x;
386
- vmap.FILTER = (x) => 'function' === typeof x ? ((y, p, _) => (_ = x(y, p), Array.isArray(_) ? !_[0] ? _[1] : vmap.FILTER : _)) : (x ? x : vmap.FILTER);
387
- vmap.KEY = (_, p) => p.key;
388
196
  //# sourceMappingURL=jostraca.js.map