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