jostraca 0.1.1 → 0.1.3
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/jostraca.d.ts +8 -7
- package/dist/jostraca.js +91 -63
- package/dist/jostraca.js.map +1 -1
- package/package.json +2 -2
- package/src/jostraca.ts +109 -76
package/dist/jostraca.d.ts
CHANGED
|
@@ -4,13 +4,14 @@ type JostracaOptions = {
|
|
|
4
4
|
};
|
|
5
5
|
type Component = (props: any, children?: any) => void;
|
|
6
6
|
declare function Jostraca(): {
|
|
7
|
-
cmp: (component: Function) => Component;
|
|
8
|
-
each: (fnarr: Function[]) => void;
|
|
9
7
|
generate: (opts: JostracaOptions, root: Function) => void;
|
|
10
|
-
Project: Component;
|
|
11
|
-
Code: Component;
|
|
12
|
-
File: Component;
|
|
13
|
-
Folder: Component;
|
|
14
8
|
};
|
|
9
|
+
declare const Code: Component;
|
|
10
|
+
declare const File: Component;
|
|
11
|
+
declare const Project: Component;
|
|
12
|
+
declare const Folder: Component;
|
|
13
|
+
declare function cmp(component: Function): Component;
|
|
14
|
+
declare function each(subject: any, apply?: any): any;
|
|
15
|
+
declare function select(key: any, map: Record<string, Function>): any;
|
|
15
16
|
export type { JostracaOptions, Component, };
|
|
16
|
-
export { Jostraca, };
|
|
17
|
+
export { Jostraca, cmp, each, select, Project, Code, File, Folder, };
|
package/dist/jostraca.js
CHANGED
|
@@ -24,11 +24,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.Folder = exports.File = exports.Code = exports.Project = void 0;
|
|
27
28
|
exports.Jostraca = Jostraca;
|
|
29
|
+
exports.cmp = cmp;
|
|
30
|
+
exports.each = each;
|
|
31
|
+
exports.select = select;
|
|
28
32
|
const Fs = __importStar(require("node:fs"));
|
|
29
33
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
34
|
+
const GLOBAL = global;
|
|
30
35
|
function Jostraca() {
|
|
31
|
-
const GLOBAL = global;
|
|
32
36
|
GLOBAL.jostraca = new node_async_hooks_1.AsyncLocalStorage();
|
|
33
37
|
function generate(opts, root) {
|
|
34
38
|
const fs = opts.fs || Fs;
|
|
@@ -38,6 +42,8 @@ function Jostraca() {
|
|
|
38
42
|
root();
|
|
39
43
|
const ctx$ = GLOBAL.jostraca.getStore();
|
|
40
44
|
const node = ctx$.node;
|
|
45
|
+
// console.log('JOSTRACA TOP')
|
|
46
|
+
// console.dir(node, { depth: null })
|
|
41
47
|
build(node, {
|
|
42
48
|
fs,
|
|
43
49
|
current: {
|
|
@@ -48,40 +54,7 @@ function Jostraca() {
|
|
|
48
54
|
});
|
|
49
55
|
});
|
|
50
56
|
}
|
|
51
|
-
function cmp(component) {
|
|
52
|
-
const cf = (props, children) => {
|
|
53
|
-
props = props || {};
|
|
54
|
-
if (null == props || 'object' !== typeof props) {
|
|
55
|
-
props = { arg: props };
|
|
56
|
-
}
|
|
57
|
-
props.ctx$ = GLOBAL.jostraca.getStore();
|
|
58
|
-
children = 'function' === typeof children ? [children] : children;
|
|
59
|
-
let node = {
|
|
60
|
-
kind: 'content',
|
|
61
|
-
children: []
|
|
62
|
-
};
|
|
63
|
-
const parent = props.ctx$.node = (props.ctx$.node || node);
|
|
64
|
-
const siblings = props.ctx$.children = (props.ctx$.children || []);
|
|
65
|
-
siblings.push(node);
|
|
66
|
-
props.ctx$.children = node.children;
|
|
67
|
-
props.ctx$.node = node;
|
|
68
|
-
let out = component(props, children);
|
|
69
|
-
props.ctx$.children = siblings;
|
|
70
|
-
props.ctx$.node = parent;
|
|
71
|
-
return out;
|
|
72
|
-
};
|
|
73
|
-
Object.defineProperty(cf, 'name', { value: component.name });
|
|
74
|
-
return cf;
|
|
75
|
-
}
|
|
76
|
-
function each(fnarr) {
|
|
77
|
-
if (fnarr) {
|
|
78
|
-
for (let fn of fnarr) {
|
|
79
|
-
fn();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
57
|
function build(topnode, ctx) {
|
|
84
|
-
// console.dir(topnode, { depth: null })
|
|
85
58
|
step(topnode, ctx);
|
|
86
59
|
}
|
|
87
60
|
function step(node, ctx) {
|
|
@@ -134,42 +107,97 @@ function Jostraca() {
|
|
|
134
107
|
},
|
|
135
108
|
content: {
|
|
136
109
|
before(node, ctx) {
|
|
137
|
-
const
|
|
138
|
-
ctx.current.file.content.push(
|
|
110
|
+
const content = ctx.current.content = node;
|
|
111
|
+
ctx.current.file.content.push(content.content);
|
|
112
|
+
},
|
|
113
|
+
after(_node, _ctx) {
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
none: {
|
|
117
|
+
before(_node, ctx) {
|
|
139
118
|
},
|
|
140
119
|
after(_node, _ctx) {
|
|
141
120
|
},
|
|
142
121
|
},
|
|
143
122
|
};
|
|
144
|
-
const Code = cmp(function Code(props) {
|
|
145
|
-
let src = props.arg;
|
|
146
|
-
props.ctx$.node.content = src;
|
|
147
|
-
});
|
|
148
|
-
const File = cmp(function File(props, children) {
|
|
149
|
-
props.ctx$.node.kind = 'file';
|
|
150
|
-
props.ctx$.node.name = props.name;
|
|
151
|
-
Code('// FILE START: ' + props.name + '\n');
|
|
152
|
-
each(children);
|
|
153
|
-
Code('// FILE END: ' + props.name + '\n');
|
|
154
|
-
});
|
|
155
|
-
const Project = cmp(function Project(props, children) {
|
|
156
|
-
props.ctx$.node.kind = 'project';
|
|
157
|
-
props.ctx$.node.name = props.name;
|
|
158
|
-
each(children);
|
|
159
|
-
});
|
|
160
|
-
const Folder = cmp(function Folder(props, children) {
|
|
161
|
-
props.ctx$.node.kind = 'folder';
|
|
162
|
-
props.ctx$.node.name = props.name;
|
|
163
|
-
each(children);
|
|
164
|
-
});
|
|
165
123
|
return {
|
|
166
|
-
cmp,
|
|
167
|
-
each,
|
|
168
124
|
generate,
|
|
169
|
-
Project,
|
|
170
|
-
Code,
|
|
171
|
-
File,
|
|
172
|
-
Folder,
|
|
173
125
|
};
|
|
174
126
|
}
|
|
127
|
+
const Code = cmp(function Code(props) {
|
|
128
|
+
props.ctx$.node.kind = 'content';
|
|
129
|
+
let src = props.arg;
|
|
130
|
+
props.ctx$.node.content = src;
|
|
131
|
+
});
|
|
132
|
+
exports.Code = Code;
|
|
133
|
+
const File = cmp(function File(props, children) {
|
|
134
|
+
props.ctx$.node.kind = 'file';
|
|
135
|
+
props.ctx$.node.name = props.name;
|
|
136
|
+
// Code('// FILE START: ' + props.name + '\n')
|
|
137
|
+
each(children);
|
|
138
|
+
// Code('// FILE END: ' + props.name + '\n')
|
|
139
|
+
});
|
|
140
|
+
exports.File = File;
|
|
141
|
+
const Project = cmp(function Project(props, children) {
|
|
142
|
+
props.ctx$.node.kind = 'project';
|
|
143
|
+
props.ctx$.node.name = props.name;
|
|
144
|
+
each(children);
|
|
145
|
+
});
|
|
146
|
+
exports.Project = Project;
|
|
147
|
+
const Folder = cmp(function Folder(props, children) {
|
|
148
|
+
props.ctx$.node.kind = 'folder';
|
|
149
|
+
props.ctx$.node.name = props.name;
|
|
150
|
+
each(children);
|
|
151
|
+
});
|
|
152
|
+
exports.Folder = Folder;
|
|
153
|
+
function cmp(component) {
|
|
154
|
+
const cf = (props, children) => {
|
|
155
|
+
props = props || {};
|
|
156
|
+
if (null == props || 'object' !== typeof props) {
|
|
157
|
+
props = { arg: props };
|
|
158
|
+
}
|
|
159
|
+
props.ctx$ = GLOBAL.jostraca.getStore();
|
|
160
|
+
children = 'function' === typeof children ? [children] : children;
|
|
161
|
+
let node = {
|
|
162
|
+
kind: 'none',
|
|
163
|
+
children: []
|
|
164
|
+
};
|
|
165
|
+
const parent = props.ctx$.node = (props.ctx$.node || node);
|
|
166
|
+
const siblings = props.ctx$.children = (props.ctx$.children || []);
|
|
167
|
+
siblings.push(node);
|
|
168
|
+
props.ctx$.children = node.children;
|
|
169
|
+
props.ctx$.node = node;
|
|
170
|
+
let out = component(props, children);
|
|
171
|
+
props.ctx$.children = siblings;
|
|
172
|
+
props.ctx$.node = parent;
|
|
173
|
+
return out;
|
|
174
|
+
};
|
|
175
|
+
Object.defineProperty(cf, 'name', { value: component.name });
|
|
176
|
+
return cf;
|
|
177
|
+
}
|
|
178
|
+
function each(subject, apply) {
|
|
179
|
+
if (null == apply) {
|
|
180
|
+
if (Array.isArray(subject)) {
|
|
181
|
+
for (let fn of subject) {
|
|
182
|
+
fn();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
if (Array.isArray(subject)) {
|
|
188
|
+
return subject.map(apply);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
const entries = Object.entries(subject);
|
|
192
|
+
if (entries[0] && entries[0][1] && 'string' === typeof entries[0][1].name) {
|
|
193
|
+
entries.sort((a, b) => a.name < b.name ? 1 : b.name < a.name ? -1 : 0);
|
|
194
|
+
}
|
|
195
|
+
return entries.map((n, ...args) => apply(n[1], [0], ...args));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function select(key, map) {
|
|
200
|
+
const fn = map && map[key];
|
|
201
|
+
return fn ? fn() : undefined;
|
|
202
|
+
}
|
|
175
203
|
//# sourceMappingURL=jostraca.js.map
|
package/dist/jostraca.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jostraca.js","sourceRoot":"","sources":["../src/jostraca.ts"],"names":[],"mappings":";AAAA,oDAAoD
|
|
1
|
+
{"version":3,"file":"jostraca.js","sourceRoot":"","sources":["../src/jostraca.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;;AA4QlD,4BAAQ;AACR,kBAAG;AAEH,oBAAI;AACJ,wBAAM;AA9QR,4CAA6B;AAE7B,uDAAoD;AAqBpD,MAAM,MAAM,GAAI,MAAc,CAAA;AAI9B,SAAS,QAAQ;IACf,MAAM,CAAC,QAAQ,GAAG,IAAI,o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
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"main": "dist/jostraca.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "dist/jostraca.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@hapi/code": "^9.0.3",
|
|
37
|
-
"@types/node": "22.
|
|
37
|
+
"@types/node": "22.1.0",
|
|
38
38
|
"esbuild": "^0.23.0",
|
|
39
39
|
"memfs": "^4.11.1",
|
|
40
40
|
"typescript": "^5.5.4"
|
package/src/jostraca.ts
CHANGED
|
@@ -23,9 +23,11 @@ type Node = {
|
|
|
23
23
|
type Component = (props: any, children?: any) => void
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const GLOBAL = (global as any)
|
|
27
|
+
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
|
|
30
|
+
function Jostraca() {
|
|
29
31
|
GLOBAL.jostraca = new AsyncLocalStorage()
|
|
30
32
|
|
|
31
33
|
|
|
@@ -39,6 +41,9 @@ function Jostraca() {
|
|
|
39
41
|
const ctx$ = GLOBAL.jostraca.getStore()
|
|
40
42
|
const node = ctx$.node
|
|
41
43
|
|
|
44
|
+
// console.log('JOSTRACA TOP')
|
|
45
|
+
// console.dir(node, { depth: null })
|
|
46
|
+
|
|
42
47
|
build(
|
|
43
48
|
node,
|
|
44
49
|
{
|
|
@@ -53,50 +58,7 @@ function Jostraca() {
|
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
|
|
56
|
-
function cmp(component: Function): Component {
|
|
57
|
-
const cf = (props: any, children?: any) => {
|
|
58
|
-
props = props || {}
|
|
59
|
-
if (null == props || 'object' !== typeof props) {
|
|
60
|
-
props = { arg: props }
|
|
61
|
-
}
|
|
62
|
-
props.ctx$ = GLOBAL.jostraca.getStore()
|
|
63
|
-
children = 'function' === typeof children ? [children] : children
|
|
64
|
-
|
|
65
|
-
let node = {
|
|
66
|
-
kind: 'content',
|
|
67
|
-
children: []
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const parent = props.ctx$.node = (props.ctx$.node || node)
|
|
71
|
-
const siblings = props.ctx$.children = (props.ctx$.children || [])
|
|
72
|
-
siblings.push(node)
|
|
73
|
-
|
|
74
|
-
props.ctx$.children = node.children
|
|
75
|
-
props.ctx$.node = node
|
|
76
|
-
|
|
77
|
-
let out = component(props, children)
|
|
78
|
-
|
|
79
|
-
props.ctx$.children = siblings
|
|
80
|
-
props.ctx$.node = parent
|
|
81
|
-
|
|
82
|
-
return out
|
|
83
|
-
}
|
|
84
|
-
Object.defineProperty(cf, 'name', { value: component.name })
|
|
85
|
-
return cf
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
function each(fnarr: Function[]) {
|
|
90
|
-
if (fnarr) {
|
|
91
|
-
for (let fn of fnarr) {
|
|
92
|
-
fn()
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
61
|
function build(topnode: Node, ctx: any) {
|
|
99
|
-
// console.dir(topnode, { depth: null })
|
|
100
62
|
step(topnode, ctx)
|
|
101
63
|
}
|
|
102
64
|
|
|
@@ -171,70 +133,132 @@ function Jostraca() {
|
|
|
171
133
|
|
|
172
134
|
content: {
|
|
173
135
|
before(node: Node, ctx: any) {
|
|
174
|
-
const
|
|
175
|
-
ctx.current.file.content.push(
|
|
136
|
+
const content = ctx.current.content = node
|
|
137
|
+
ctx.current.file.content.push(content.content)
|
|
176
138
|
},
|
|
177
139
|
|
|
178
140
|
after(_node: Node, _ctx: any) {
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
|
|
179
144
|
|
|
145
|
+
none: {
|
|
146
|
+
before(_node: Node, ctx: any) {
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
after(_node: Node, _ctx: any) {
|
|
180
150
|
},
|
|
181
151
|
},
|
|
182
152
|
|
|
153
|
+
}
|
|
154
|
+
|
|
183
155
|
|
|
156
|
+
return {
|
|
157
|
+
generate,
|
|
184
158
|
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
const Code = cmp(function Code(props: any) {
|
|
163
|
+
props.ctx$.node.kind = 'content'
|
|
164
|
+
let src = props.arg
|
|
165
|
+
props.ctx$.node.content = src
|
|
166
|
+
})
|
|
185
167
|
|
|
186
168
|
|
|
169
|
+
const File = cmp(function File(props: any, children: any) {
|
|
170
|
+
props.ctx$.node.kind = 'file'
|
|
171
|
+
props.ctx$.node.name = props.name
|
|
187
172
|
|
|
188
|
-
|
|
189
|
-
let src = props.arg
|
|
190
|
-
props.ctx$.node.content = src
|
|
191
|
-
})
|
|
173
|
+
// Code('// FILE START: ' + props.name + '\n')
|
|
192
174
|
|
|
175
|
+
each(children)
|
|
193
176
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
props.ctx$.node.name = props.name
|
|
177
|
+
// Code('// FILE END: ' + props.name + '\n')
|
|
178
|
+
})
|
|
197
179
|
|
|
198
|
-
Code('// FILE START: ' + props.name + '\n')
|
|
199
180
|
|
|
200
|
-
|
|
181
|
+
const Project: Component = cmp(function Project(props: any, children: any) {
|
|
182
|
+
props.ctx$.node.kind = 'project'
|
|
183
|
+
props.ctx$.node.name = props.name
|
|
201
184
|
|
|
202
|
-
|
|
203
|
-
|
|
185
|
+
each(children)
|
|
186
|
+
})
|
|
204
187
|
|
|
205
188
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
189
|
+
const Folder = cmp(function Folder(props: any, children: any) {
|
|
190
|
+
props.ctx$.node.kind = 'folder'
|
|
191
|
+
props.ctx$.node.name = props.name
|
|
209
192
|
|
|
210
|
-
|
|
211
|
-
|
|
193
|
+
each(children)
|
|
194
|
+
})
|
|
212
195
|
|
|
213
196
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
props
|
|
197
|
+
function cmp(component: Function): Component {
|
|
198
|
+
const cf = (props: any, children?: any) => {
|
|
199
|
+
props = props || {}
|
|
200
|
+
if (null == props || 'object' !== typeof props) {
|
|
201
|
+
props = { arg: props }
|
|
202
|
+
}
|
|
203
|
+
props.ctx$ = GLOBAL.jostraca.getStore()
|
|
204
|
+
children = 'function' === typeof children ? [children] : children
|
|
217
205
|
|
|
218
|
-
|
|
219
|
-
|
|
206
|
+
let node = {
|
|
207
|
+
kind: 'none',
|
|
208
|
+
children: []
|
|
209
|
+
}
|
|
220
210
|
|
|
211
|
+
const parent = props.ctx$.node = (props.ctx$.node || node)
|
|
212
|
+
const siblings = props.ctx$.children = (props.ctx$.children || [])
|
|
213
|
+
siblings.push(node)
|
|
221
214
|
|
|
215
|
+
props.ctx$.children = node.children
|
|
216
|
+
props.ctx$.node = node
|
|
217
|
+
|
|
218
|
+
let out = component(props, children)
|
|
219
|
+
|
|
220
|
+
props.ctx$.children = siblings
|
|
221
|
+
props.ctx$.node = parent
|
|
222
|
+
|
|
223
|
+
return out
|
|
224
|
+
}
|
|
225
|
+
Object.defineProperty(cf, 'name', { value: component.name })
|
|
226
|
+
return cf
|
|
227
|
+
}
|
|
222
228
|
|
|
223
|
-
return {
|
|
224
|
-
cmp,
|
|
225
|
-
each,
|
|
226
|
-
generate,
|
|
227
229
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
function each(subject: any, apply?: any) {
|
|
231
|
+
if (null == apply) {
|
|
232
|
+
if (Array.isArray(subject)) {
|
|
233
|
+
for (let fn of subject) {
|
|
234
|
+
fn()
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
if (Array.isArray(subject)) {
|
|
240
|
+
return subject.map(apply)
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
const entries: any = Object.entries(subject)
|
|
244
|
+
if (entries[0] && entries[0][1] && 'string' === typeof entries[0][1].name) {
|
|
245
|
+
entries.sort((a: any, b: any) => a.name < b.name ? 1 : b.name < a.name ? -1 : 0)
|
|
246
|
+
}
|
|
247
|
+
return entries.map((n: any, ...args: any[]) =>
|
|
248
|
+
apply(n[1], [0], ...args))
|
|
249
|
+
}
|
|
232
250
|
}
|
|
251
|
+
}
|
|
233
252
|
|
|
234
253
|
|
|
254
|
+
function select(key: any, map: Record<string, Function>) {
|
|
255
|
+
const fn = map && map[key]
|
|
256
|
+
return fn ? fn() : undefined
|
|
235
257
|
}
|
|
236
258
|
|
|
237
259
|
|
|
260
|
+
|
|
261
|
+
|
|
238
262
|
export type {
|
|
239
263
|
JostracaOptions,
|
|
240
264
|
Component,
|
|
@@ -243,4 +267,13 @@ export type {
|
|
|
243
267
|
|
|
244
268
|
export {
|
|
245
269
|
Jostraca,
|
|
270
|
+
cmp,
|
|
271
|
+
|
|
272
|
+
each,
|
|
273
|
+
select,
|
|
274
|
+
|
|
275
|
+
Project,
|
|
276
|
+
Code,
|
|
277
|
+
File,
|
|
278
|
+
Folder,
|
|
246
279
|
}
|