@voxgig/sdkgen 0.0.2 → 0.0.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/sdkgen.d.ts +3 -6
- package/dist/sdkgen.js +10 -4
- package/dist/sdkgen.js.map +1 -1
- package/package.json +2 -2
- package/src/sdkgen.ts +14 -4
- package/src/sdkgen.ts~ +0 -246
package/dist/sdkgen.d.ts
CHANGED
|
@@ -4,12 +4,9 @@ type SdkGenOptions = {
|
|
|
4
4
|
};
|
|
5
5
|
declare function SdkGen(opts: SdkGenOptions): {
|
|
6
6
|
generate: (spec: any) => void;
|
|
7
|
-
cmp: (component: Function) => import("jostraca").Component;
|
|
8
|
-
each: (subject: any, apply?: any) => any;
|
|
9
|
-
Project: import("jostraca").Component;
|
|
10
|
-
Folder: import("jostraca").Component;
|
|
11
|
-
File: import("jostraca").Component;
|
|
12
|
-
Code: import("jostraca").Component;
|
|
13
7
|
};
|
|
8
|
+
declare namespace SdkGen {
|
|
9
|
+
var makeBuild: (root: any, opts: SdkGenOptions) => (model: any, build: any) => void;
|
|
10
|
+
}
|
|
14
11
|
export type { SdkGenOptions, };
|
|
15
12
|
export { SdkGen, };
|
package/dist/sdkgen.js
CHANGED
|
@@ -31,15 +31,21 @@ function SdkGen(opts) {
|
|
|
31
31
|
const fs = opts.fs || Fs;
|
|
32
32
|
const folder = opts.folder || '.';
|
|
33
33
|
const jostraca = (0, jostraca_1.Jostraca)();
|
|
34
|
-
const { cmp, each, Project, Folder, File, Code } = jostraca
|
|
34
|
+
// const { cmp, each, Project, Folder, File, Code } = jostraca
|
|
35
35
|
function generate(spec) {
|
|
36
36
|
const { model, root } = spec;
|
|
37
|
-
jostraca.generate({ fs, folder }, () => root(model));
|
|
37
|
+
jostraca.generate({ fs, folder }, () => root({ model }));
|
|
38
38
|
}
|
|
39
39
|
return {
|
|
40
40
|
generate,
|
|
41
|
-
cmp, each,
|
|
42
|
-
Project, Folder, File, Code
|
|
41
|
+
// cmp, each,
|
|
42
|
+
// Project, Folder, File, Code
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
+
SdkGen.makeBuild = function (root, opts) {
|
|
46
|
+
const sdkgen = SdkGen(opts);
|
|
47
|
+
return function build(model, build) {
|
|
48
|
+
return sdkgen.generate({ model, build, root });
|
|
49
|
+
};
|
|
50
|
+
};
|
|
45
51
|
//# sourceMappingURL=sdkgen.js.map
|
package/dist/sdkgen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkgen.js","sourceRoot":"","sources":["../src/sdkgen.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"sdkgen.js","sourceRoot":"","sources":["../src/sdkgen.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;AA0DlD,wBAAM;AAxDR,4CAA6B;AAE7B,uCAAmC;AAWnC,SAAS,MAAM,CAAC,IAAmB;IACjC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,CAAA;IACxB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,CAAA;IACjC,MAAM,QAAQ,GAAG,IAAA,mBAAQ,GAAE,CAAA;IAE3B,8DAA8D;IAE9D,SAAS,QAAQ,CAAC,IAAS;QACzB,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;QAE5B,QAAQ,CAAC,QAAQ,CACf,EAAE,EAAE,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CACtB,CAAA;IACH,CAAC;IAED,OAAO;QACL,QAAQ;QAER,aAAa;QAEb,8BAA8B;KAC/B,CAAA;AAEH,CAAC;AAGD,MAAM,CAAC,SAAS,GAAG,UAAS,IAAS,EAAE,IAAmB;IACxD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAE3B,OAAO,SAAS,KAAK,CAAC,KAAU,EAAE,KAAU;QAC1C,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAChD,CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voxgig/sdkgen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "dist/sdkgen.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "dist/sdkgen.d.ts",
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"typescript": "^5.5.4"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"jostraca": "^0.1.
|
|
44
|
+
"jostraca": "^0.1.3"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/sdkgen.ts
CHANGED
|
@@ -18,28 +18,38 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
18
18
|
const folder = opts.folder || '.'
|
|
19
19
|
const jostraca = Jostraca()
|
|
20
20
|
|
|
21
|
-
const { cmp, each, Project, Folder, File, Code } = jostraca
|
|
21
|
+
// const { cmp, each, Project, Folder, File, Code } = jostraca
|
|
22
22
|
|
|
23
23
|
function generate(spec: any) {
|
|
24
24
|
const { model, root } = spec
|
|
25
25
|
|
|
26
26
|
jostraca.generate(
|
|
27
27
|
{ fs, folder },
|
|
28
|
-
() => root(model)
|
|
28
|
+
() => root({ model })
|
|
29
29
|
)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
return {
|
|
33
33
|
generate,
|
|
34
34
|
|
|
35
|
-
cmp, each,
|
|
35
|
+
// cmp, each,
|
|
36
36
|
|
|
37
|
-
Project, Folder, File, Code
|
|
37
|
+
// Project, Folder, File, Code
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
SdkGen.makeBuild = function(root: any, opts: SdkGenOptions) {
|
|
44
|
+
const sdkgen = SdkGen(opts)
|
|
45
|
+
|
|
46
|
+
return function build(model: any, build: any) {
|
|
47
|
+
return sdkgen.generate({ model, build, root })
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
43
53
|
export type {
|
|
44
54
|
SdkGenOptions,
|
|
45
55
|
}
|
package/src/sdkgen.ts~
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2024 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
import * as Fs from 'node:fs'
|
|
4
|
-
|
|
5
|
-
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type JostracaOptions = {
|
|
9
|
-
folder: string
|
|
10
|
-
fs: any
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type Node = {
|
|
15
|
-
kind: string
|
|
16
|
-
children?: Node[]
|
|
17
|
-
name?: string
|
|
18
|
-
path?: string
|
|
19
|
-
content?: any[]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type Component = (props: any, children?: any) => void
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function Jostraca() {
|
|
27
|
-
|
|
28
|
-
const GLOBAL = (global as any)
|
|
29
|
-
GLOBAL.jostraca = new AsyncLocalStorage()
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function generate(opts: JostracaOptions, root: Function) {
|
|
33
|
-
const fs = opts.fs || Fs
|
|
34
|
-
GLOBAL.jostraca.run({
|
|
35
|
-
content: null,
|
|
36
|
-
}, () => {
|
|
37
|
-
root()
|
|
38
|
-
|
|
39
|
-
const ctx$ = GLOBAL.jostraca.getStore()
|
|
40
|
-
const node = ctx$.node
|
|
41
|
-
|
|
42
|
-
build(
|
|
43
|
-
node,
|
|
44
|
-
{
|
|
45
|
-
fs,
|
|
46
|
-
current: {
|
|
47
|
-
folder: {
|
|
48
|
-
parent: opts.folder
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
function build(topnode: Node, ctx: any) {
|
|
99
|
-
// console.dir(topnode, { depth: null })
|
|
100
|
-
step(topnode, ctx)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
function step(node: Node, ctx: any) {
|
|
105
|
-
const op = opmap[node.kind]
|
|
106
|
-
if (null == op) {
|
|
107
|
-
throw new Error('missing op: ' + node.kind)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
op.before(node, ctx)
|
|
111
|
-
|
|
112
|
-
if (node.children) {
|
|
113
|
-
for (let childnode of node.children) {
|
|
114
|
-
step(childnode, ctx)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
op.after(node, ctx)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const opmap: any = {
|
|
124
|
-
|
|
125
|
-
project: {
|
|
126
|
-
before(node: Node, ctx: any) {
|
|
127
|
-
const cproject: any = ctx.current.project = (ctx.current.project || {})
|
|
128
|
-
cproject.node = node
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
after(_node: Node, _ctx: any) {
|
|
132
|
-
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
folder: {
|
|
138
|
-
before(node: Node, ctx: any) {
|
|
139
|
-
const cfolder = ctx.current.folder = (ctx.current.folder || {})
|
|
140
|
-
|
|
141
|
-
cfolder.node = node
|
|
142
|
-
cfolder.path = (cfolder.path || [ctx.current.folder.parent])
|
|
143
|
-
cfolder.path.push(node.name)
|
|
144
|
-
|
|
145
|
-
let fullpath = cfolder.path.join('/')
|
|
146
|
-
ctx.fs.mkdirSync(fullpath, { recursive: true })
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
after(_node: Node, ctx: any) {
|
|
151
|
-
const cfolder = ctx.current.folder
|
|
152
|
-
cfolder.path.length = cfolder.path.length - 1
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
file: {
|
|
158
|
-
before(node: Node, ctx: any) {
|
|
159
|
-
const cfile = ctx.current.file = node
|
|
160
|
-
cfile.path = ctx.current.folder.path.join('/') + '/' + node.name
|
|
161
|
-
cfile.content = []
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
after(_node: Node, ctx: any) {
|
|
165
|
-
const cfile = ctx.current.file
|
|
166
|
-
const content = cfile.content.join('')
|
|
167
|
-
ctx.fs.writeFileSync(cfile.path, content)
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
content: {
|
|
173
|
-
before(node: Node, ctx: any) {
|
|
174
|
-
const ccontent = ctx.current.content = node
|
|
175
|
-
ctx.current.file.content.push(ccontent.content)
|
|
176
|
-
},
|
|
177
|
-
|
|
178
|
-
after(_node: Node, _ctx: any) {
|
|
179
|
-
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const Code = cmp(function Code(props: any) {
|
|
189
|
-
let src = props.arg
|
|
190
|
-
props.ctx$.node.content = src
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const File = cmp(function File(props: any, children: any) {
|
|
195
|
-
props.ctx$.node.kind = 'file'
|
|
196
|
-
props.ctx$.node.name = props.name
|
|
197
|
-
|
|
198
|
-
Code('// FILE START: ' + props.name + '\n')
|
|
199
|
-
|
|
200
|
-
each(children)
|
|
201
|
-
|
|
202
|
-
Code('// FILE END: ' + props.name + '\n')
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const Project: Component = cmp(function Project(props: any, children: any) {
|
|
207
|
-
props.ctx$.node.kind = 'project'
|
|
208
|
-
props.ctx$.node.name = props.name
|
|
209
|
-
|
|
210
|
-
each(children)
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const Folder = cmp(function Folder(props: any, children: any) {
|
|
215
|
-
props.ctx$.node.kind = 'folder'
|
|
216
|
-
props.ctx$.node.name = props.name
|
|
217
|
-
|
|
218
|
-
each(children)
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return {
|
|
224
|
-
cmp,
|
|
225
|
-
each,
|
|
226
|
-
generate,
|
|
227
|
-
|
|
228
|
-
Project,
|
|
229
|
-
Code,
|
|
230
|
-
File,
|
|
231
|
-
Folder,
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
export type {
|
|
239
|
-
JostracaOptions,
|
|
240
|
-
Component,
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
export {
|
|
245
|
-
Jostraca,
|
|
246
|
-
}
|