@voxgig/sdkgen 0.0.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.
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/sdkgen.d.ts +15 -0
- package/dist/sdkgen.js +45 -0
- package/dist/sdkgen.js.map +1 -0
- package/package.json +46 -0
- package/src/sdkgen.ts +50 -0
- package/src/sdkgen.ts~ +246 -0
- package/src/tsconfig.json +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Voxgig Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/sdkgen.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type SdkGenOptions = {
|
|
2
|
+
folder: string;
|
|
3
|
+
fs: any;
|
|
4
|
+
};
|
|
5
|
+
declare function SdkGen(opts: SdkGenOptions): {
|
|
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
|
+
};
|
|
14
|
+
export type { SdkGenOptions, };
|
|
15
|
+
export { SdkGen, };
|
package/dist/sdkgen.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2024 Richard Rodger, MIT License */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.SdkGen = SdkGen;
|
|
28
|
+
const Fs = __importStar(require("node:fs"));
|
|
29
|
+
const jostraca_1 = require("jostraca");
|
|
30
|
+
function SdkGen(opts) {
|
|
31
|
+
const fs = opts.fs || Fs;
|
|
32
|
+
const folder = opts.folder || '.';
|
|
33
|
+
const jostraca = (0, jostraca_1.Jostraca)();
|
|
34
|
+
const { cmp, each, Project, Folder, File, Code } = jostraca;
|
|
35
|
+
function generate(spec) {
|
|
36
|
+
const { model, root } = spec;
|
|
37
|
+
jostraca.generate({ fs, folder }, () => root(model));
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
generate,
|
|
41
|
+
cmp, each,
|
|
42
|
+
Project, Folder, File, Code
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=sdkgen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkgen.js","sourceRoot":"","sources":["../src/sdkgen.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;AAgDlD,wBAAM;AA9CR,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,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAA;IAE3D,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,KAAK,CAAC,CAClB,CAAA;IACH,CAAC;IAED,OAAO;QACL,QAAQ;QAER,GAAG,EAAE,IAAI;QAET,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;KAC5B,CAAA;AAEH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@voxgig/sdkgen",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "dist/sdkgen.js",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"types": "dist/sdkgen.d.ts",
|
|
7
|
+
"description": "Voxgig SDK Generator.",
|
|
8
|
+
"homepage": "https://github.com/voxgig/voxgig-sdkgen",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"voxgig-sdkgen",
|
|
11
|
+
"voxgig-sdkgen"
|
|
12
|
+
],
|
|
13
|
+
"author": "Richard Rodger (http://richardrodger.com)",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git://github.com/voxgig/sdkgen.git"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "node --enable-source-maps --test dist-test",
|
|
20
|
+
"test-some": "node --enable-source-maps --test-name-pattern=\"$npm_config_pattern\" --test dist-test",
|
|
21
|
+
"watch": "tsc --build src test -w",
|
|
22
|
+
"build": "tsc --build src test",
|
|
23
|
+
"clean": "rm -rf node_modules yarn.lock package-lock.json",
|
|
24
|
+
"reset": "npm run clean && npm i && npm run build && npm test",
|
|
25
|
+
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;",
|
|
26
|
+
"repo-publish": "npm run clean && npm i && npm run repo-publish-quick",
|
|
27
|
+
"repo-publish-quick": "npm run build && npm run test && npm run repo-tag && npm publish --registry https://registry.npmjs.org --access=public"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"files": [
|
|
31
|
+
"src",
|
|
32
|
+
"dist",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@hapi/code": "^9.0.3",
|
|
37
|
+
"@types/node": "22.0.0",
|
|
38
|
+
"aontu": "^0.21.1",
|
|
39
|
+
"esbuild": "^0.23.0",
|
|
40
|
+
"memfs": "^4.11.1",
|
|
41
|
+
"typescript": "^5.5.4"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"jostraca": "^0.1.1"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/sdkgen.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* Copyright (c) 2024 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
import * as Fs from 'node:fs'
|
|
4
|
+
|
|
5
|
+
import { Jostraca } from 'jostraca'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
type SdkGenOptions = {
|
|
9
|
+
folder: string
|
|
10
|
+
fs: any
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function SdkGen(opts: SdkGenOptions) {
|
|
17
|
+
const fs = opts.fs || Fs
|
|
18
|
+
const folder = opts.folder || '.'
|
|
19
|
+
const jostraca = Jostraca()
|
|
20
|
+
|
|
21
|
+
const { cmp, each, Project, Folder, File, Code } = jostraca
|
|
22
|
+
|
|
23
|
+
function generate(spec: any) {
|
|
24
|
+
const { model, root } = spec
|
|
25
|
+
|
|
26
|
+
jostraca.generate(
|
|
27
|
+
{ fs, folder },
|
|
28
|
+
() => root(model)
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
generate,
|
|
34
|
+
|
|
35
|
+
cmp, each,
|
|
36
|
+
|
|
37
|
+
Project, Folder, File, Code
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export type {
|
|
44
|
+
SdkGenOptions,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
SdkGen,
|
|
50
|
+
}
|
package/src/sdkgen.ts~
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"esModuleInterop": true,
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"noEmitOnError": true,
|
|
6
|
+
"outDir":"../dist",
|
|
7
|
+
"rootDir":".",
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"target": "es2021",
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationDir": "../dist"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|