@voxgig/sdkgen 0.14.0 → 0.16.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/bin/voxgig-sdkgen +135 -0
- package/dist/action/feature.d.ts +2 -0
- package/dist/action/feature.js +76 -0
- package/dist/action/feature.js.map +1 -0
- package/dist/action/lang.d.ts +2 -0
- package/dist/action/lang.js +68 -0
- package/dist/action/lang.js.map +1 -0
- package/dist/action/target.d.ts +2 -0
- package/dist/action/target.js +82 -0
- package/dist/action/target.js.map +1 -0
- package/dist/cmp/Entity.js +3 -3
- package/dist/cmp/Entity.js.map +1 -1
- package/dist/cmp/Feature.js +10 -3
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/FeatureHook.d.ts +2 -0
- package/dist/cmp/FeatureHook.js +17 -0
- package/dist/cmp/FeatureHook.js.map +1 -0
- package/dist/cmp/Hook.d.ts +2 -0
- package/dist/cmp/Hook.js +10 -0
- package/dist/cmp/Hook.js.map +1 -0
- package/dist/cmp/Main.js +12 -5
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/Readme.js +8 -8
- package/dist/cmp/Readme.js.map +1 -1
- package/dist/cmp/ReadmeInstall.js +3 -3
- package/dist/cmp/ReadmeInstall.js.map +1 -1
- package/dist/cmp/ReadmeOptions.js +2 -2
- package/dist/cmp/ReadmeOptions.js.map +1 -1
- package/dist/cmp/ReadmeQuick.js +3 -3
- package/dist/cmp/ReadmeQuick.js.map +1 -1
- package/dist/sdkgen.d.ts +15 -4
- package/dist/sdkgen.js +106 -35
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.d.ts +4 -1
- package/dist/utility.js +11 -2
- package/dist/utility.js.map +1 -1
- package/model/sdkgen.jsonic +58 -6
- package/package.json +13 -13
- package/src/action/feature.ts +120 -0
- package/src/action/target.ts +127 -0
- package/src/cmp/Entity.ts +6 -4
- package/src/cmp/Feature.ts +11 -4
- package/src/cmp/FeatureHook.ts +23 -0
- package/src/cmp/Main.ts +14 -6
- package/src/cmp/Readme.ts +8 -8
- package/src/cmp/ReadmeInstall.ts +3 -3
- package/src/cmp/ReadmeOptions.ts +2 -2
- package/src/cmp/ReadmeQuick.ts +3 -3
- package/src/sdkgen.ts +116 -34
- package/src/utility.ts +11 -1
- package/src/prepare-openapi.ts +0 -59
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
Jostraca,
|
|
4
|
+
Project,
|
|
5
|
+
File,
|
|
6
|
+
Folder,
|
|
7
|
+
Content,
|
|
8
|
+
Copy,
|
|
9
|
+
cmp,
|
|
10
|
+
each,
|
|
11
|
+
} from 'jostraca'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
import { SdkGenError } from '../utility'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const CMD_MAP: any = {
|
|
18
|
+
add: cmd_target_add
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function action_target(args: any[], ctx: any) {
|
|
22
|
+
|
|
23
|
+
const cmdname = args[1]
|
|
24
|
+
|
|
25
|
+
const cmd = CMD_MAP[cmdname]
|
|
26
|
+
|
|
27
|
+
if (null == cmd) {
|
|
28
|
+
throw new SdkGenError('Unknown target cmd: ' + cmdname)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await cmd(args, ctx)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
async function cmd_target_add(args: any[], ctx: any) {
|
|
36
|
+
|
|
37
|
+
let targets = args[2]
|
|
38
|
+
targets = 'string' === typeof targets ? targets.split(',') : targets
|
|
39
|
+
|
|
40
|
+
const jostraca = Jostraca()
|
|
41
|
+
|
|
42
|
+
const opts = {
|
|
43
|
+
fs: ctx.fs,
|
|
44
|
+
folder: ctx.folder,
|
|
45
|
+
log: ctx.log.child({ cmp: 'jostraca' }),
|
|
46
|
+
meta: { model: ctx.model, tree: ctx.tree }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await jostraca.generate(opts, () => TargetRoot({ targets }))
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
const TargetRoot = cmp(function TargetRoot(props: any) {
|
|
55
|
+
const { ctx$, targets } = props
|
|
56
|
+
|
|
57
|
+
// TODO: model should be a top level ctx property
|
|
58
|
+
ctx$.model = ctx$.meta.model
|
|
59
|
+
|
|
60
|
+
// console.log('MODEL')
|
|
61
|
+
// console.dir(ctx$.model, { depth: null })
|
|
62
|
+
|
|
63
|
+
Project({}, () => {
|
|
64
|
+
each(targets, (n) => {
|
|
65
|
+
// TODO: validate target is a-z0-9-_. only
|
|
66
|
+
const name = n.val$
|
|
67
|
+
|
|
68
|
+
Folder({ name: 'model/target' }, () => {
|
|
69
|
+
Copy({
|
|
70
|
+
from: 'node_modules/@voxgig/sdkgen/project/generate/model/target/' + name + '.jsonic',
|
|
71
|
+
// exclude: true
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
Folder({ name: 'src/cmp/' + name }, () => {
|
|
76
|
+
Copy({
|
|
77
|
+
from: 'node_modules/@voxgig/sdkgen/project/generate/src/cmp/' + name,
|
|
78
|
+
// exclude: true
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
Folder({ name: 'tm/' + name }, () => {
|
|
83
|
+
Copy({
|
|
84
|
+
from: 'node_modules/@voxgig/sdkgen/project/generate/tm/' + name,
|
|
85
|
+
exclude: [/src\/feature/]
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
modifyModel({
|
|
94
|
+
targets,
|
|
95
|
+
model: ctx$.meta.model,
|
|
96
|
+
tree: ctx$.meta.tree,
|
|
97
|
+
fs: ctx$.fs
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async function modifyModel({ targets, model, tree, fs }: any) {
|
|
104
|
+
// TODO: This is a kludge.
|
|
105
|
+
// Aontu should provide option for as-is AST so that can be used
|
|
106
|
+
// to find injection point more reliably
|
|
107
|
+
|
|
108
|
+
const path = tree.url
|
|
109
|
+
let src = fs().readFileSync(path, 'utf8')
|
|
110
|
+
|
|
111
|
+
// Inject target file references into model
|
|
112
|
+
targets.sort().map((target: string) => {
|
|
113
|
+
const lineRE =
|
|
114
|
+
new RegExp(`@"target/${target}.jsonic"`)
|
|
115
|
+
if (!src.match(lineRE)) {
|
|
116
|
+
src = src.replace(/(main:\s+sdk:\s+target:\s+\{\s*\}\n)/, '$1' +
|
|
117
|
+
`@"target/${target}.jsonic"\n`)
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
fs().writeFileSync(path, src)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
export {
|
|
126
|
+
action_target
|
|
127
|
+
}
|
package/src/cmp/Entity.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
cmp,
|
|
4
|
+
} from 'jostraca'
|
|
3
5
|
|
|
4
6
|
import { requirePath } from '../utility'
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
const Entity = cmp(function Entity(props: any) {
|
|
8
|
-
const {
|
|
10
|
+
const { target, entity, ctx$ } = props
|
|
9
11
|
|
|
10
|
-
const Entity_sdk = requirePath(ctx$,
|
|
11
|
-
Entity_sdk['Entity']({
|
|
12
|
+
const Entity_sdk = requirePath(ctx$, `./cmp/${target.name}/Entity_${target.name}`)
|
|
13
|
+
Entity_sdk['Entity']({ target, entity })
|
|
12
14
|
})
|
|
13
15
|
|
|
14
16
|
|
package/src/cmp/Feature.ts
CHANGED
|
@@ -5,10 +5,17 @@ import { resolvePath } from '../utility'
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
const Feature = cmp(function Feature(props: any) {
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
Folder({ name: 'src/' + feature.name }, () => {
|
|
11
|
-
|
|
8
|
+
const { target, feature, ctx$ } = props
|
|
9
|
+
|
|
10
|
+
Folder({ name: 'src/feature/' + feature.name }, () => {
|
|
11
|
+
// TODO: Copy should just warn if from not found
|
|
12
|
+
Copy({
|
|
13
|
+
from: 'tm/' + target.name + '/src/feature/' + feature.name,
|
|
14
|
+
replace: {
|
|
15
|
+
FEATURE_VERSION: feature.version,
|
|
16
|
+
FEATURE_Name: feature.Name,
|
|
17
|
+
}
|
|
18
|
+
})
|
|
12
19
|
})
|
|
13
20
|
|
|
14
21
|
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
import { each, cmp, names, Content } from 'jostraca'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const FeatureHook = cmp(function FeatureHook(props: any, children: any) {
|
|
6
|
+
const { ctx$: { model } } = props
|
|
7
|
+
|
|
8
|
+
const { feature } = model.main.sdk
|
|
9
|
+
|
|
10
|
+
const hook: any = {}
|
|
11
|
+
names(hook, props.name)
|
|
12
|
+
|
|
13
|
+
// TODO: much better error reporting for invalid feature hook names
|
|
14
|
+
each(feature)
|
|
15
|
+
// .map(feature => (console.log(props.name, feature), feature))
|
|
16
|
+
.filter(feature => feature.active && feature.hook[props.name].active)
|
|
17
|
+
.map(feature => each(children, { call: true, args: feature }))
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
FeatureHook
|
|
23
|
+
}
|
package/src/cmp/Main.ts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
|
|
2
|
-
import { cmp, Copy } from 'jostraca'
|
|
2
|
+
import { cmp, Copy, Folder } from 'jostraca'
|
|
3
3
|
|
|
4
4
|
import { resolvePath } from '../utility'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
const Main = cmp(function Main(props: any) {
|
|
8
|
-
const {
|
|
8
|
+
const { target, ctx$ } = props
|
|
9
9
|
const { model } = ctx$
|
|
10
10
|
|
|
11
|
-
const Main_sdk = require(resolvePath(ctx$,
|
|
11
|
+
const Main_sdk = require(resolvePath(ctx$, `cmp/${target.name}/Main_${target.name}`))
|
|
12
12
|
|
|
13
|
-
Main_sdk['Main']({ model,
|
|
13
|
+
Main_sdk['Main']({ model, target })
|
|
14
14
|
|
|
15
|
-
// TODO: make optional via
|
|
16
|
-
Copy({ from: 'tm/' +
|
|
15
|
+
// TODO: make optional via target model
|
|
16
|
+
Copy({ from: 'tm/' + target.name + '/LICENSE', to: 'LICENSE' })
|
|
17
|
+
|
|
18
|
+
Folder({ name: 'src/utility' }, () => {
|
|
19
|
+
Copy({
|
|
20
|
+
from: 'tm/' + target.name + '/src/utility',
|
|
21
|
+
// TODO: make this work for folders
|
|
22
|
+
// to: target + '/src'
|
|
23
|
+
})
|
|
24
|
+
})
|
|
17
25
|
})
|
|
18
26
|
|
|
19
27
|
|
package/src/cmp/Readme.ts
CHANGED
|
@@ -11,21 +11,21 @@ import { ReadmeEntity } from './ReadmeEntity'
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
const Readme = cmp(function Readme(props: any) {
|
|
14
|
-
const {
|
|
14
|
+
const { target } = props
|
|
15
15
|
const { model } = props.ctx$
|
|
16
16
|
|
|
17
17
|
File({ name: 'README.md' }, () => {
|
|
18
18
|
|
|
19
19
|
Content(`
|
|
20
|
-
# ${model.Name} ${
|
|
20
|
+
# ${model.Name} ${target.title} SDK
|
|
21
21
|
`)
|
|
22
22
|
// Sections
|
|
23
|
-
ReadmeIntro({
|
|
24
|
-
ReadmeInstall({
|
|
25
|
-
ReadmeQuick({
|
|
26
|
-
ReadmeModel({
|
|
27
|
-
ReadmeOptions({
|
|
28
|
-
ReadmeEntity({
|
|
23
|
+
ReadmeIntro({ target })
|
|
24
|
+
ReadmeInstall({ target })
|
|
25
|
+
ReadmeQuick({ target })
|
|
26
|
+
ReadmeModel({ target })
|
|
27
|
+
ReadmeOptions({ target })
|
|
28
|
+
ReadmeEntity({ target })
|
|
29
29
|
})
|
|
30
30
|
})
|
|
31
31
|
|
package/src/cmp/ReadmeInstall.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { requirePath } from '../utility'
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
const ReadmeInstall = cmp(function ReadmeInstall(props: any) {
|
|
9
|
-
const {
|
|
9
|
+
const { target, ctx$ } = props
|
|
10
10
|
|
|
11
11
|
Content(`
|
|
12
12
|
## Install
|
|
@@ -14,10 +14,10 @@ const ReadmeInstall = cmp(function ReadmeInstall(props: any) {
|
|
|
14
14
|
|
|
15
15
|
// Optional
|
|
16
16
|
const ReadmeInstall_sdk =
|
|
17
|
-
requirePath(ctx$,
|
|
17
|
+
requirePath(ctx$, `./target/${target.name}/ReadmeInstall_${target.name}`, { ignore: true })
|
|
18
18
|
|
|
19
19
|
if (ReadmeInstall_sdk) {
|
|
20
|
-
ReadmeInstall_sdk['ReadmeInstall']({
|
|
20
|
+
ReadmeInstall_sdk['ReadmeInstall']({ target })
|
|
21
21
|
}
|
|
22
22
|
})
|
|
23
23
|
|
package/src/cmp/ReadmeOptions.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { cmp, each, Content } from 'jostraca'
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
const ReadmeOptions = cmp(function ReadmeOptions(props: any) {
|
|
6
|
-
const {
|
|
6
|
+
const { target } = props
|
|
7
7
|
|
|
8
8
|
Content(`
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ const ReadmeOptions = cmp(function ReadmeOptions(props: any) {
|
|
|
11
11
|
|
|
12
12
|
`)
|
|
13
13
|
|
|
14
|
-
each(
|
|
14
|
+
each(target.options)
|
|
15
15
|
.filter((option: any) => option.publish)
|
|
16
16
|
.map((option: any) => {
|
|
17
17
|
Content(`
|
package/src/cmp/ReadmeQuick.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { requirePath } from '../utility'
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
const ReadmeQuick = cmp(function ReadmeQuick(props: any) {
|
|
8
|
-
const {
|
|
8
|
+
const { target, ctx$ } = props
|
|
9
9
|
|
|
10
10
|
Content(`
|
|
11
11
|
## Quick Start
|
|
@@ -13,10 +13,10 @@ const ReadmeQuick = cmp(function ReadmeQuick(props: any) {
|
|
|
13
13
|
`)
|
|
14
14
|
|
|
15
15
|
const ReadmeQuick_sdk =
|
|
16
|
-
requirePath(ctx$,
|
|
16
|
+
requirePath(ctx$, `./target/${target.name}/ReadmeQuick_${target.name}`, { ignore: true })
|
|
17
17
|
|
|
18
18
|
if (ReadmeQuick_sdk) {
|
|
19
|
-
ReadmeQuick_sdk['ReadmeQuick']({
|
|
19
|
+
ReadmeQuick_sdk['ReadmeQuick']({ target })
|
|
20
20
|
}
|
|
21
21
|
})
|
|
22
22
|
|
package/src/sdkgen.ts
CHANGED
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Fs from 'node:fs'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
import * as JostracaModule from 'jostraca'
|
|
7
|
-
|
|
8
|
-
// import Pino from 'pino'
|
|
9
|
-
// import PinoPretty from 'pino-pretty'
|
|
10
|
-
|
|
11
5
|
import { prettyPino, Pino } from '@voxgig/util'
|
|
12
6
|
|
|
13
|
-
import {
|
|
7
|
+
import { Jsonic } from 'jsonic'
|
|
8
|
+
import * as JostracaModule from 'jostraca'
|
|
9
|
+
import { Aontu, Context } from 'aontu'
|
|
14
10
|
|
|
11
|
+
import { SdkGenError } from './utility'
|
|
15
12
|
|
|
16
13
|
import { Main } from './cmp/Main'
|
|
17
14
|
import { Entity } from './cmp/Entity'
|
|
@@ -20,8 +17,11 @@ import { Readme } from './cmp/Readme'
|
|
|
20
17
|
import { ReadmeInstall } from './cmp/ReadmeInstall'
|
|
21
18
|
import { ReadmeOptions } from './cmp/ReadmeOptions'
|
|
22
19
|
import { ReadmeEntity } from './cmp/ReadmeEntity'
|
|
20
|
+
import { FeatureHook } from './cmp/FeatureHook'
|
|
21
|
+
|
|
22
|
+
import { action_target } from './action/target'
|
|
23
|
+
import { action_feature } from './action/feature'
|
|
23
24
|
|
|
24
|
-
import { PrepareOpenAPI } from './prepare-openapi'
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
type SdkGenOptions = {
|
|
@@ -44,18 +44,20 @@ type SdkGenOptions = {
|
|
|
44
44
|
const { Jostraca } = JostracaModule
|
|
45
45
|
|
|
46
46
|
|
|
47
|
+
const ACTION_MAP: any = {
|
|
48
|
+
target: action_target,
|
|
49
|
+
feature: action_feature,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
47
53
|
function SdkGen(opts: SdkGenOptions) {
|
|
48
54
|
const fs = opts.fs || Fs
|
|
49
|
-
const folder = opts.folder || '
|
|
50
|
-
// const def = opts.def || 'def.yml'
|
|
55
|
+
const folder = opts.folder || '../'
|
|
51
56
|
const jostraca = Jostraca()
|
|
52
57
|
|
|
53
58
|
const pino = prettyPino('sdkgen', opts)
|
|
54
|
-
|
|
55
59
|
const log = pino.child({ cmp: 'sdkgen' })
|
|
56
60
|
|
|
57
|
-
// console.log('SDKGEN OPTS', opts)
|
|
58
|
-
|
|
59
61
|
|
|
60
62
|
async function generate(spec: any) {
|
|
61
63
|
const start = Date.now()
|
|
@@ -72,28 +74,107 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
72
74
|
Root = rootModule.Root
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
const jopts = {
|
|
78
|
+
fs: () => fs,
|
|
79
|
+
folder,
|
|
80
|
+
log: log.child({ cmp: 'jostraca' }),
|
|
81
|
+
meta: { spec },
|
|
82
|
+
debug: opts.debug,
|
|
78
83
|
}
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
const opts = { fs, folder, log: log.child({ cmp: 'jostraca' }), meta: { spec } }
|
|
82
84
|
|
|
83
|
-
await jostraca.generate(
|
|
85
|
+
await jostraca.generate(jopts, () => Root({ model }))
|
|
84
86
|
|
|
85
87
|
log.info({ point: 'generate-end' })
|
|
88
|
+
|
|
89
|
+
return { ok: true, name: 'sdkgen' }
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
|
|
89
|
-
async function
|
|
90
|
-
|
|
93
|
+
async function action(args: string[]) {
|
|
94
|
+
const pargs = args.map(arg => Jsonic(arg))
|
|
95
|
+
|
|
96
|
+
const actname = args[0]
|
|
97
|
+
const action = ACTION_MAP[actname]
|
|
98
|
+
|
|
99
|
+
if (null == action) {
|
|
100
|
+
throw new SdkGenError('Unknown action: ' + actname)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
const { model, tree } = resolveModel()
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
const ctx = {
|
|
108
|
+
fs: () => fs,
|
|
109
|
+
log,
|
|
110
|
+
folder: '.', // The `generate` folder,
|
|
111
|
+
model,
|
|
112
|
+
tree,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
await action(pargs, ctx)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
function resolveModel() {
|
|
120
|
+
const path = './model/sdk.jsonic'
|
|
121
|
+
const aopts = { path }
|
|
122
|
+
const src = fs.readFileSync(path, 'utf8')
|
|
123
|
+
|
|
124
|
+
const tree = Aontu(src, aopts)
|
|
125
|
+
const hasErr = tree.err && 0 < tree.err.length
|
|
126
|
+
|
|
127
|
+
if (hasErr) {
|
|
128
|
+
for (let serr of tree.err) {
|
|
129
|
+
let err: any = new SdkGenError('Model Error: ' + serr.msg)
|
|
130
|
+
err.cause$ = [serr]
|
|
131
|
+
|
|
132
|
+
if ('syntax' === serr.why) {
|
|
133
|
+
err.uxmsg$ = true
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// log.error({ fail: 'parse', point: 'guide-parse', file: path, err })
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
err.rooterrs$ = tree.err
|
|
140
|
+
throw err
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let genctx = new Context({ root: tree })
|
|
145
|
+
const model = tree.gen(genctx)
|
|
146
|
+
|
|
147
|
+
// TODO: collect all errors
|
|
148
|
+
if (genctx.err && 0 < genctx.err.length) {
|
|
149
|
+
const err: any = new SdkGenError('Model Error:\n' +
|
|
150
|
+
(genctx.err.map((pe: any) => pe.msg)).join('\n'))
|
|
151
|
+
// log.error({ fail: 'build', what: 'guide', file: path, err })
|
|
152
|
+
err.errs = () => genctx.err
|
|
153
|
+
throw err
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// TODO: FIX: This is a hack to set the correct src file
|
|
157
|
+
// aontu bug: url is empty
|
|
158
|
+
tree.url = path
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
model.const = { name: model.name }
|
|
162
|
+
|
|
163
|
+
names(model.const, model.name)
|
|
164
|
+
|
|
165
|
+
model.const.year = new Date().getFullYear()
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
model,
|
|
169
|
+
tree,
|
|
170
|
+
}
|
|
91
171
|
}
|
|
92
172
|
|
|
93
173
|
|
|
94
174
|
return {
|
|
95
175
|
pino,
|
|
96
176
|
generate,
|
|
177
|
+
action,
|
|
97
178
|
}
|
|
98
179
|
|
|
99
180
|
}
|
|
@@ -101,6 +182,7 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
101
182
|
|
|
102
183
|
SdkGen.makeBuild = async function(opts: SdkGenOptions) {
|
|
103
184
|
let sdkgen: any = undefined
|
|
185
|
+
// let apidef: any = undefined
|
|
104
186
|
|
|
105
187
|
const config = {
|
|
106
188
|
root: opts.root,
|
|
@@ -115,21 +197,12 @@ SdkGen.makeBuild = async function(opts: SdkGenOptions) {
|
|
|
115
197
|
sdkgen = SdkGen({
|
|
116
198
|
...opts,
|
|
117
199
|
pino: build.log,
|
|
200
|
+
debug: build.spec.debug,
|
|
118
201
|
})
|
|
119
|
-
|
|
120
|
-
const apidef = ApiDef({
|
|
121
|
-
pino: build.log,
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
if (true === ctx.watch) {
|
|
125
|
-
await apidef.watch(config)
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
await apidef.generate(config)
|
|
129
|
-
}
|
|
130
202
|
}
|
|
131
203
|
|
|
132
|
-
await
|
|
204
|
+
// await apidef.generate({ model, build, config })
|
|
205
|
+
return await sdkgen.generate({ model, build, config })
|
|
133
206
|
}
|
|
134
207
|
}
|
|
135
208
|
|
|
@@ -191,6 +264,11 @@ export const cmap: (o: any, p: any) => any = JostracaModule.cmap
|
|
|
191
264
|
export const vmap: (o: any, p: any) => any = JostracaModule.vmap
|
|
192
265
|
export const get: (root: any, path: string | string[]) => any = JostracaModule.get
|
|
193
266
|
export const getx: (root: any, path: string | string[]) => any = JostracaModule.getx
|
|
267
|
+
export const template: (root: any, path: string | string[]) => any = JostracaModule.template
|
|
268
|
+
|
|
269
|
+
export const deep: (...args: any[]) => any = JostracaModule.deep
|
|
270
|
+
export const omap: (...args: any[]) => any = JostracaModule.omap
|
|
271
|
+
|
|
194
272
|
|
|
195
273
|
export const Project: Component = JostracaModule.Project
|
|
196
274
|
export const Folder: Component = JostracaModule.Folder
|
|
@@ -199,6 +277,9 @@ export const Content: Component = JostracaModule.Content
|
|
|
199
277
|
export const Copy: Component = JostracaModule.Copy
|
|
200
278
|
export const Fragment: Component = JostracaModule.Fragment
|
|
201
279
|
export const Inject: Component = JostracaModule.Inject
|
|
280
|
+
export const Line: Component = JostracaModule.Line
|
|
281
|
+
export const Slot: Component = JostracaModule.Slot
|
|
282
|
+
export const List: Component = JostracaModule.List
|
|
202
283
|
|
|
203
284
|
|
|
204
285
|
export {
|
|
@@ -209,6 +290,7 @@ export {
|
|
|
209
290
|
ReadmeInstall,
|
|
210
291
|
ReadmeOptions,
|
|
211
292
|
ReadmeEntity,
|
|
293
|
+
FeatureHook,
|
|
212
294
|
|
|
213
295
|
Jostraca,
|
|
214
296
|
SdkGen,
|
package/src/utility.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
import Path from 'node:path'
|
|
3
3
|
|
|
4
|
+
// TODO: move to @voxgig/util as duplicated with @voxgig/sdkgen
|
|
4
5
|
|
|
5
6
|
const resolvePath = (ctx$: any, path: string): any => {
|
|
6
|
-
|
|
7
|
+
// console.log('RP', ctx$.folder)
|
|
8
|
+
const fullpath = Path.join(ctx$.folder, 'generate', 'dist', path)
|
|
7
9
|
return fullpath
|
|
8
10
|
}
|
|
9
11
|
|
|
@@ -26,8 +28,16 @@ const requirePath = (ctx$: any, path: string, flags?: { ignore?: boolean }): any
|
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
|
|
31
|
+
class SdkGenError extends Error {
|
|
32
|
+
constructor(...args: any[]) {
|
|
33
|
+
super(...args)
|
|
34
|
+
this.name = 'SdkGenError'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
29
38
|
|
|
30
39
|
export {
|
|
31
40
|
resolvePath,
|
|
32
41
|
requirePath,
|
|
42
|
+
SdkGenError,
|
|
33
43
|
}
|
package/src/prepare-openapi.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import * as Fs from 'node:fs'
|
|
3
|
-
|
|
4
|
-
import { each } from 'jostraca'
|
|
5
|
-
|
|
6
|
-
import { bundleFromString, createConfig } from '@redocly/openapi-core'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
async function PrepareOpenAPI(inspec: any, ctx: any) {
|
|
10
|
-
|
|
11
|
-
// TODO: avoid rebuilding if unchanged
|
|
12
|
-
|
|
13
|
-
// const source = Fs.readFileSync(ctx.def, 'utf8')
|
|
14
|
-
|
|
15
|
-
// const config = await createConfig({})
|
|
16
|
-
// const bundle = await bundleFromString({
|
|
17
|
-
// source,
|
|
18
|
-
// config,
|
|
19
|
-
// dereference: true,
|
|
20
|
-
// })
|
|
21
|
-
|
|
22
|
-
// // console.log('BUNDLE', bundle)
|
|
23
|
-
|
|
24
|
-
// Fs.writeFileSync(
|
|
25
|
-
// ctx.folder + '/../model/def.jsonic',
|
|
26
|
-
// JSON.stringify(bundle.bundle.parsed, null, 2)
|
|
27
|
-
// )
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// const spec: any = {}
|
|
31
|
-
|
|
32
|
-
// spec.main = {
|
|
33
|
-
// sdk: {
|
|
34
|
-
// api: {
|
|
35
|
-
// // cmap
|
|
36
|
-
// /*
|
|
37
|
-
// path: each(bundle.bundle.parsed.paths, (path: any) => ({
|
|
38
|
-
// param: {}
|
|
39
|
-
// }))
|
|
40
|
-
// */
|
|
41
|
-
// }
|
|
42
|
-
// }
|
|
43
|
-
// }
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Fs.writeFileSync(
|
|
47
|
-
// ctx.folder + '/../model/spec.jsonic',
|
|
48
|
-
// JSON.stringify(spec, null, 2)
|
|
49
|
-
// )
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return false
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
export {
|
|
58
|
-
PrepareOpenAPI
|
|
59
|
-
}
|