@voxgig/create-sdkgen 0.0.3 → 0.0.6

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.
Files changed (105) hide show
  1. package/bin/voxgig-create-sdkgen +196 -0
  2. package/dist/create-sdkgen.d.ts +11 -8
  3. package/dist/create-sdkgen.js +61 -63
  4. package/dist/create-sdkgen.js.map +1 -1
  5. package/dist/standard/ModelSdk.js +8 -61
  6. package/dist/standard/ModelSdk.js.map +1 -1
  7. package/dist/standard/Root.js +58 -57
  8. package/dist/standard/Root.js.map +1 -1
  9. package/dist/tsconfig.tsbuildinfo +1 -1
  10. package/package.json +13 -10
  11. package/src/create-sdkgen.ts +56 -74
  12. package/src/standard/ModelSdk.ts +9 -71
  13. package/src/standard/Root.ts +26 -68
  14. package/bin/run-create-sdkgen.js +0 -269
  15. package/bin/run-create-sdkgen.js~ +0 -1
  16. package/src/standard/ModelSdk.ts~ +0 -1
  17. package/src/standard/Root.ts~ +0 -3
  18. package/src/utility.ts +0 -8
  19. package/tm/standard/.env.local +0 -2
  20. package/tm/standard/build/sdk.js +0 -25
  21. package/tm/standard/def/DEFINITION.md +0 -2
  22. package/tm/standard/model/.model-config/model-config.jsonic +0 -13
  23. package/tm/standard/model/go.jsonic +0 -6
  24. package/tm/standard/model/js.jsonic +0 -6
  25. package/tm/standard/model/php.jsonic +0 -6
  26. package/tm/standard/model/py.jsonic +0 -7
  27. package/tm/standard/model/rb.jsonic +0 -6
  28. package/tm/standard/model/sdk.jsonic.off +0 -60
  29. package/tm/standard/package.json +0 -30
  30. package/tm/standard/src/Root.ts +0 -60
  31. package/tm/standard/src/go/Entity_go.ts +0 -226
  32. package/tm/standard/src/go/MainEntity_go.ts +0 -26
  33. package/tm/standard/src/go/Main_go.ts +0 -168
  34. package/tm/standard/src/go/Quick_go.ts +0 -108
  35. package/tm/standard/src/go/ReadmeInstall_go.ts +0 -19
  36. package/tm/standard/src/go/ReadmeQuick_go.ts +0 -45
  37. package/tm/standard/src/go/TestAcceptEntity_go.ts +0 -219
  38. package/tm/standard/src/go/TestAccept_go.ts +0 -38
  39. package/tm/standard/src/go/TestEntity_go.ts +0 -79
  40. package/tm/standard/src/go/TestMain_go.ts +0 -61
  41. package/tm/standard/src/go/Test_go.ts +0 -20
  42. package/tm/standard/src/js/Entity_js.ts +0 -135
  43. package/tm/standard/src/js/MainEntity_js.ts +0 -22
  44. package/tm/standard/src/js/Main_js.ts +0 -128
  45. package/tm/standard/src/js/Quick_js.ts +0 -72
  46. package/tm/standard/src/js/ReadmeInstall_js.ts +0 -19
  47. package/tm/standard/src/js/ReadmeQuick_js.ts +0 -27
  48. package/tm/standard/src/js/TestAcceptEntity_js.ts +0 -101
  49. package/tm/standard/src/js/TestAccept_js.ts +0 -60
  50. package/tm/standard/src/js/TestEntity_js.ts +0 -24
  51. package/tm/standard/src/js/TestMain_js.ts +0 -123
  52. package/tm/standard/src/js/Test_js.ts +0 -24
  53. package/tm/standard/src/php/Entity_php.ts +0 -97
  54. package/tm/standard/src/php/MainEntity_php.ts +0 -43
  55. package/tm/standard/src/php/Main_php.ts +0 -50
  56. package/tm/standard/src/php/Quick_php.ts +0 -59
  57. package/tm/standard/src/php/TestAcceptEntity_php.ts +0 -81
  58. package/tm/standard/src/php/TestAccept_php.ts +0 -33
  59. package/tm/standard/src/php/TestEntity_php.ts +0 -64
  60. package/tm/standard/src/php/TestMain_php.ts +0 -120
  61. package/tm/standard/src/php/Test_php.ts +0 -21
  62. package/tm/standard/src/py/Entity_py.ts +0 -98
  63. package/tm/standard/src/py/MainEntity_py.ts +0 -19
  64. package/tm/standard/src/py/Main_py.ts +0 -211
  65. package/tm/standard/src/py/Quick_py.ts +0 -133
  66. package/tm/standard/src/py/TestAcceptEntity_py.ts +0 -47
  67. package/tm/standard/src/py/TestAccept_py.ts +0 -77
  68. package/tm/standard/src/py/TestEntity_py.ts +0 -50
  69. package/tm/standard/src/py/TestMain_py.ts +0 -103
  70. package/tm/standard/src/py/Test_py.ts +0 -28
  71. package/tm/standard/src/rb/Client_rb.ts +0 -142
  72. package/tm/standard/src/rb/Entity_rb.ts +0 -153
  73. package/tm/standard/src/rb/Error_rb.ts +0 -56
  74. package/tm/standard/src/rb/MainEntity_rb.ts +0 -16
  75. package/tm/standard/src/rb/Main_rb.ts +0 -55
  76. package/tm/standard/src/rb/Quick_rb.ts +0 -65
  77. package/tm/standard/src/rb/ReadmeInstall_rb.ts +0 -19
  78. package/tm/standard/src/rb/ReadmeQuick_rb.ts +0 -30
  79. package/tm/standard/src/rb/TestAcceptEntity_rb.ts +0 -83
  80. package/tm/standard/src/rb/TestAccept_rb.ts +0 -45
  81. package/tm/standard/src/rb/TestEntity_rb.ts +0 -82
  82. package/tm/standard/src/rb/TestMain_rb.ts +0 -67
  83. package/tm/standard/src/rb/Test_rb.ts +0 -27
  84. package/tm/standard/src/tsconfig.json +0 -15
  85. package/tm/standard/tm/go/.env.example +0 -2
  86. package/tm/standard/tm/go/LICENSE +0 -22
  87. package/tm/standard/tm/go/go.mod +0 -5
  88. package/tm/standard/tm/go/go.sum +0 -2
  89. package/tm/standard/tm/js/LICENSE +0 -22
  90. package/tm/standard/tm/js/package.json +0 -17
  91. package/tm/standard/tm/php/LICENSE +0 -22
  92. package/tm/standard/tm/py/LICENSE +0 -22
  93. package/tm/standard/tm/py/MANIFEST.in +0 -4
  94. package/tm/standard/tm/py/Makefile +0 -14
  95. package/tm/standard/tm/py/pyproject.toml +0 -4
  96. package/tm/standard/tm/py/pytest.ini +0 -3
  97. package/tm/standard/tm/py/requirements.txt +0 -4
  98. package/tm/standard/tm/py/setup.cfg +0 -2
  99. package/tm/standard/tm/py/setup.py +0 -82
  100. package/tm/standard/tm/rb/.rspec +0 -1
  101. package/tm/standard/tm/rb/Gemfile +0 -21
  102. package/tm/standard/tm/rb/LICENSE +0 -22
  103. package/tm/standard/tm/rb/Rakefile +0 -6
  104. package/tm/standard/tm/rb/spec/spec_helper.rb +0 -22
  105. package/tm/standard/tm/rb/tm.gemspec +0 -39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxgig/create-sdkgen",
3
- "version": "0.0.3",
3
+ "version": "0.0.6",
4
4
  "main": "dist/create-sdkgen.js",
5
5
  "type": "commonjs",
6
6
  "types": "dist/create-sdkgen.d.ts",
@@ -17,13 +17,15 @@
17
17
  "url": "git://github.com/voxgig/create-sdkgen.git"
18
18
  },
19
19
  "bin": {
20
- "create-sdkgen": "bin/run-create-sdkgen.js"
20
+ "create-sdkgen": "bin/voxgig-create-sdkgen.js"
21
21
  },
22
22
  "scripts": {
23
23
  "test": "node --enable-source-maps --test dist-test",
24
24
  "test-some": "node --enable-source-maps --test-name-pattern=\"$npm_config_pattern\" --test dist-test",
25
25
  "watch": "tsc --build src test -w",
26
26
  "build": "tsc --build src test",
27
+ "test-model": "voxgig-model project/.sdk/test/test.jsonic",
28
+ "test-model-watch": "voxgig-model -w project/.sdk/test/test.jsonic",
27
29
  "clean": "rm -rf node_modules yarn.lock package-lock.json",
28
30
  "reset": "npm run clean && npm i && npm run build && npm test",
29
31
  "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;",
@@ -40,15 +42,16 @@
40
42
  ],
41
43
  "devDependencies": {
42
44
  "@hapi/code": "^9.0.3",
43
- "@types/node": "22.5.5",
44
- "esbuild": "^0.23.1",
45
- "memfs": "^4.12.0",
46
- "typescript": "^5.6.2"
45
+ "@types/node": "22.15.12",
46
+ "esbuild": "^0.25.4",
47
+ "memfs": "^4.17.1",
48
+ "typescript": "^5.8.3"
47
49
  },
48
50
  "dependencies": {
49
- "aontu": "^0.22.0",
50
- "chokidar": "^4.0.0",
51
- "gubu": "^8.3.0",
52
- "jostraca": "^0.6.0"
51
+ "@voxgig/util": "^0.0.10",
52
+ "aontu": "^0.28.0",
53
+ "chokidar": "^4.0.3",
54
+ "gubu": "^9.0.0",
55
+ "jostraca": "^0.16.2"
53
56
  }
54
57
  }
@@ -1,120 +1,102 @@
1
1
  /* Copyright (c) 2024 Richard Rodger, MIT License */
2
2
 
3
3
  import * as Fs from 'node:fs'
4
+ import Path from 'node:path'
4
5
 
5
- import { FSWatcher } from 'chokidar'
6
+ import { prettyPino, Pino } from '@voxgig/util'
6
7
 
7
8
  import * as JostracaModule from 'jostraca'
8
9
 
9
10
 
10
11
 
11
12
  type FullCreateSdkGenOptions = {
12
- folder: string
13
- fs: any
14
- model: any
15
- meta: any
16
- rootpath: string
13
+ fs?: any
14
+ debug?: boolean | string
15
+ pino?: ReturnType<typeof Pino>
16
+
17
17
  }
18
18
 
19
19
  type CreateSdkGenOptions = Partial<FullCreateSdkGenOptions>
20
20
 
21
21
 
22
- const { Jostraca } = JostracaModule
22
+ type GenerateSpec = {
23
+ name: string // Name of SDK project.
24
+ def: string // Path to OpenAPI definition file, copied into SDK project.
25
+ root: string // Path to Root template component.
26
+ }
23
27
 
24
28
 
25
- function CreateSdkGen(opts: CreateSdkGenOptions) {
26
- const fs = opts.fs || Fs
27
- const folder = opts.folder || '.'
28
- const jostraca = Jostraca()
29
- const rootpath = opts.rootpath as string
29
+ const { each, names, Jostraca } = JostracaModule
30
30
 
31
- async function generate(spec: any) {
32
- // console.log('CreateSdkGen.generate', spec)
33
31
 
34
- const { model } = spec
32
+ function CreateSdkGen(opts: FullCreateSdkGenOptions) {
33
+ const fs = opts.fs || Fs
34
+ const pino = prettyPino('create', opts)
35
+ const log = pino.child({ cmp: 'create' })
35
36
 
36
- const ctx$ = { fs, folder, meta: { spec } }
37
+ const jostraca = Jostraca()
37
38
 
38
- clear()
39
- const { Root } = require(rootpath)
39
+ async function generate(spec: GenerateSpec) {
40
+ const start = Date.now()
40
41
 
41
- try {
42
- await jostraca.generate(ctx$, () => Root({ model }))
43
- }
44
- catch (err: any) {
45
- console.log('CREATE SDKGEN ERROR: ', err)
46
- throw err
47
- }
48
- }
42
+ log.info({ point: 'generate-start', start })
43
+ log.debug({ point: 'generate-spec', spec, note: JSON.stringify(spec, null, 2) })
49
44
 
45
+ const rootModule: any = require(spec.root)
46
+ const Root = rootModule.Root
50
47
 
51
- async function watch(spec: any) {
52
- const fsw = new FSWatcher()
53
- let last_change_time = 0
48
+ const name = spec.name
49
+ spec.def = (null == spec.def || '' === spec.def) ? name + '-openapi3.yml' : spec.def
54
50
 
55
- await generate(spec)
51
+ const folder = Path.join(process.cwd(), name + (name.endsWith('-sdk') ? '' : '-sdk'))
56
52
 
57
- fsw.on('change', (args: any[]) => {
58
- // console.log('CHANGE', args)
53
+ const opts = {
54
+ fs: () => fs,
55
+ folder,
56
+ log: log.child({ cmp: 'jostraca' }),
57
+ meta: { spec },
58
+ existing: {
59
+ // write: false,
60
+ // present: true,
61
+ merge: true
62
+ }
63
+ }
59
64
 
60
- const dorun = 1111 < Date.now() - last_change_time
65
+ const model = {
66
+ name,
67
+ year: new Date().getFullYear(),
68
+ }
61
69
 
62
- if (dorun) {
63
- last_change_time = Date.now()
64
- generate(spec)
65
- }
66
- })
70
+ names(model, model.name)
67
71
 
68
- spec.watch
69
- .map((wf: string) => (__dirname + '/' + wf))
70
- // .map((wf: string) => (console.log(wf), wf))
71
- .map((wf: string) => fsw.add(wf))
72
+ log.debug({ point: 'generate-model', model, note: JSON.stringify(model, null, 2) })
72
73
 
73
- // generate()
74
- }
74
+ const info = await jostraca.generate(opts, () => Root({ model, spec }))
75
75
 
76
+ logfiles(info, log)
76
77
 
77
- function clear() {
78
- if (rootpath) {
79
- clearRequire(rootpath)
80
- }
78
+ log.info({ point: 'generate-end' })
81
79
  }
82
80
 
83
-
84
81
  return {
85
82
  generate,
86
- watch,
87
83
  }
88
84
 
89
85
  }
90
86
 
91
87
 
92
- // Adapted from https://github.com/sindresorhus/import-fresh - Thanks!
93
- function clearRequire(path: string) {
94
- let filePath = require.resolve(path)
95
-
96
- if (require.cache[filePath]) {
97
- const children = require.cache[filePath].children.map(child => child.id)
98
-
99
- // Delete module from cache
100
- delete require.cache[filePath]
101
-
102
- for (const id of children) {
103
- clearRequire(id)
104
- }
105
- }
106
-
88
+ function logfiles(info: any, log: ReturnType<typeof Pino>) {
89
+ const cwd = process.cwd()
107
90
 
108
- if (require.cache[filePath] && require.cache[filePath].parent) {
109
- let i = require.cache[filePath].parent.children.length
110
-
111
- while (i--) {
112
- if (require.cache[filePath].parent.children[i].id === filePath) {
113
- require.cache[filePath].parent.children.splice(i, 1)
91
+ ;['preserve', 'present', 'merge'].map(action => {
92
+ let entries = info.file[action]
93
+ if (0 < entries.length) {
94
+ log.info({
95
+ point: 'file-' + action, entries,
96
+ note: '\n' + entries.map((n: any) => n.path.replace(cwd, '.')).join('\n')
97
+ })
114
98
  }
115
- }
116
- }
117
-
99
+ })
118
100
  }
119
101
 
120
102
 
@@ -1,87 +1,25 @@
1
1
 
2
2
  import {
3
- names,
4
3
  cmp,
5
- each,
6
-
7
- Project,
8
- Folder,
9
- Copy,
10
4
  File,
11
- Content,
5
+ Fragment,
12
6
 
13
7
  } from 'jostraca'
14
8
 
15
9
 
16
10
 
17
11
  const ModelSdk = cmp(function ModelSdk(props: any) {
18
- const { ctx$, ctx$: { model } } = props
19
-
20
-
21
- // console.log('ModelSdk 2', model)
22
-
23
- // TODO: use apidef
24
- // const def = ctx$.fs.readFileSync(model.def.filepath)
12
+ const { spec } = props
25
13
 
26
14
 
27
15
  File({ name: 'sdk.jsonic' }, () => {
28
- Content(`
29
- name: '${model.name}'
30
-
31
- @"api.jsonic"
32
- @"def.jsonic"
33
-
34
- main: sdk: build: &: { name: .$KEY }
35
-
36
- main: sdk: build: js: @"js.jsonic"
37
-
38
- main: sdk: build: rb: @"rb.jsonic"
39
-
40
- main: sdk: build: py: @"py.jsonic"
41
-
42
- main: sdk: build: php: @"php.jsonic"
43
-
44
- main: sdk: build: go: @"go.jsonic"
45
-
46
-
47
-
48
- main: sdk: test: quick: entity: name: q
49
-
50
-
51
- main: sdk: entity: $.main.api.entity
52
-
53
-
54
- main: sdk: entity: &: {
55
- name: .$KEY
56
- publish: *true | boolean
57
- }
58
-
59
-
60
-
61
- main: sdk: options: &: {
62
- name: .$KEY
63
- publish: *true | boolean
64
- }
65
-
66
-
67
- main: sdk: options: {
68
-
69
- endpoint: {
70
- kind: *String | string
71
- short: "${model.Name} API URL"
72
- }
73
-
74
- apikey: {
75
- kind: *String | string
76
- short: "${model.Name} API Key"
77
- }
78
-
79
- fetch: {
80
- kind: *Any | string
81
- publish: false
82
- }
83
- }
84
- `)
16
+ Fragment({
17
+ from: __dirname + '/../../project/.sdk/model/sdk.fragment.jsonic',
18
+ replace: {
19
+ NAME: spec.name,
20
+ DEF: spec.def,
21
+ }
22
+ })
85
23
  })
86
24
 
87
25
  })
@@ -1,12 +1,11 @@
1
1
 
2
2
 
3
3
  import Path from 'node:path'
4
-
4
+ import * as Fs from 'node:fs'
5
5
 
6
6
  import {
7
7
  names,
8
8
  cmp,
9
- each,
10
9
 
11
10
  Project,
12
11
  Folder,
@@ -20,85 +19,44 @@ import {
20
19
  import { ModelSdk } from './ModelSdk'
21
20
 
22
21
 
22
+ // TODO: rename to RootSdk
23
23
  const Root = cmp(function Root(props: any) {
24
- const { model, ctx$ } = props
25
-
26
- const { folder, meta } = ctx$
27
- const { spec } = meta
28
-
29
- console.log('Root 5')
30
-
31
- // console.log('SPEC', spec)
32
-
33
- names(model, model.name)
24
+ const { ctx$, ctx$: { folder }, spec, model } = props
34
25
 
35
- // console.log('MODEL')
36
- // console.dir(model, { depth: null })
26
+ // TODO: move to @voxgig/util as duplicated
27
+ model.const = { name: model.name }
28
+ names(model.const, model.name)
29
+ model.const.year = new Date().getFullYear()
37
30
 
38
31
  ctx$.model = model
39
32
 
40
- /*
41
- let createInfo = { exclude: [], last: Number.MAX_SAFE_INTEGER }
42
-
43
-
44
- try {
45
- createInfo = JSON.parse(ctx$.fs.readFileSync(
46
- Path.join(folder, '.voxgig', 'create-sdkgen.json'), 'utf8'))
47
- }
48
- catch (err: any) {
49
- console.log(err)
50
- // TODO: file not foound ignored, handle others!
51
- }
52
-
53
- ctx$.info = createInfo
54
-
55
- console.log('INFO', ctx$.info)
56
- */
57
-
58
33
  Project({ folder }, () => {
34
+ Copy({
35
+ from: __dirname + '/../../project',
36
+ })
59
37
 
60
- // TODO: perhaps remove the need for this, create top level folder in Project
61
- // would keep paths indo of project folder name
62
- // Folder({ name: Path.basename(folder) }, () => {
63
-
64
- // File({ name: 'foo.txt' }, () => {
65
- // Content('FOO')
66
- // })
67
-
68
- // console.log('FOLDER', folder)
69
- Copy({ from: __dirname + '/../../tm/standard' })
38
+ const origdef = spec.def
39
+ const projdef = Path.basename(origdef)
40
+ spec.def = projdef
70
41
 
71
- const def = model.def.filepath
72
- if (null != def && '' !== def) {
42
+ Folder({ name: '.sdk' }, () => {
73
43
  Folder({ name: 'def' }, () => {
74
- Copy({ from: def, name: Path.basename(def) })
44
+ if (Fs.existsSync(origdef)) {
45
+ Copy({ from: origdef, to: projdef })
46
+ }
47
+ else {
48
+ File({ name: projdef }, () => {
49
+ Content('# OpenAPI Definition')
50
+ })
51
+ }
75
52
  })
76
- }
77
53
 
78
- Folder({ name: '.voxgig' }, () => { })
79
-
80
- Folder({ name: 'model' }, () => {
81
- ModelSdk({})
54
+ Folder({ name: 'model' }, () => {
55
+ ModelSdk({ spec })
56
+ })
82
57
  })
83
- })
84
58
 
85
- /*
86
- // TODO: need mechanism to ensure this is last
87
- setTimeout(() => {
88
- try {
89
- const info = {
90
- last: Date.now(),
91
- exclude: ctx$.info.exclude,
92
- }
93
- ctx$.fs.writeFileSync(Path.join(folder, '.voxgig', 'create-sdkgen.json'),
94
- JSON.stringify(info, null, 2))
95
- }
96
- catch (err: any) {
97
- console.log(err)
98
- // TODO: file not foound ignored, handle others!
99
- }
100
- }, 777)
101
- */
59
+ })
102
60
  })
103
61
 
104
62