@voxgig/create-sdkgen 0.0.7 → 0.0.9

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.
@@ -4,7 +4,7 @@ const Path = require('node:path')
4
4
  const { statSync } = require('node:fs')
5
5
  const { parseArgs } = require('node:util')
6
6
 
7
- const { Gubu, Fault } = require('gubu')
7
+ const { Gubu, Fault, One } = require('gubu')
8
8
 
9
9
  const Pkg = require('../package.json')
10
10
 
@@ -12,36 +12,40 @@ const { CreateSdkGen } = require('../dist/create-sdkgen.js')
12
12
 
13
13
  const rootpath = require.resolve('../dist/standard/Root')
14
14
 
15
- let CONSOLE = console
15
+ let KONSOLE = global['con'+'sole']
16
16
 
17
17
 
18
- try {
19
- let options = resolveOptions()
18
+ run()
20
19
 
21
- if(options.debug) {
22
- DEBUG = true
23
- }
24
20
 
25
- if(options.version) {
26
- version()
27
- }
21
+ async function run() {
22
+ try {
23
+ let options = resolveOptions()
28
24
 
29
- if(options.help) {
30
- help()
31
- }
25
+ if(options.debug) {
26
+ DEBUG = true
27
+ }
32
28
 
33
- if(options.version || options.help) {
34
- exit()
35
- }
29
+ if(options.version) {
30
+ version()
31
+ }
36
32
 
37
- options = validateOptions(options)
33
+ if(options.help) {
34
+ help()
35
+ }
38
36
 
39
- generate(options)
40
- }
41
- catch(err) {
42
- handleError(err)
43
- }
37
+ if(options.version || options.help) {
38
+ exit()
39
+ }
44
40
 
41
+ options = validateOptions(options)
42
+
43
+ generate(options)
44
+ }
45
+ catch(err) {
46
+ handleError(err)
47
+ }
48
+ }
45
49
 
46
50
 
47
51
  function exit(err) {
@@ -60,9 +64,15 @@ function generate(options) {
60
64
 
61
65
 
62
66
  const spec = {
67
+ root: 'Root',
68
+
63
69
  name: options.name,
64
- root: './standard/Root',
65
70
  def: options.def,
71
+ dryrun: options.dryrun,
72
+ project: options.project,
73
+ install: options.install,
74
+ target: options.target,
75
+ feature: options.feature,
66
76
  }
67
77
 
68
78
  createSdkGen.generate(spec)
@@ -77,6 +87,7 @@ function resolveOptions() {
77
87
  try {
78
88
  args = parseArgs({
79
89
  allowPositionals: true,
90
+ allowNegative: true,
80
91
  options: {
81
92
  def: {
82
93
  type: 'string',
@@ -84,6 +95,35 @@ function resolveOptions() {
84
95
  default: ''
85
96
  },
86
97
 
98
+ project: {
99
+ type: 'string',
100
+ short: 'p',
101
+ default: 'standard'
102
+ },
103
+
104
+ dryrun: {
105
+ type: 'boolean',
106
+ short: 'y',
107
+ },
108
+
109
+ install: {
110
+ type: 'boolean',
111
+ short: 'y',
112
+ default: true,
113
+ },
114
+
115
+ target: {
116
+ type: 'string',
117
+ short: 't',
118
+ multiple: true
119
+ },
120
+
121
+ feature: {
122
+ type: 'string',
123
+ short: 'f',
124
+ multiple: true
125
+ },
126
+
87
127
  debug: {
88
128
  type: 'string',
89
129
  short: 'g',
@@ -114,15 +154,29 @@ function resolveOptions() {
114
154
  let name = args.positionals[0]
115
155
  name = null == name ? '' : name
116
156
  name = '' === name && (args.values.help || args.values.version) ? '__none__' : name
157
+
158
+ targets = args.values.target || []
159
+ if( 1 < args.positionals.length ) {
160
+ targets.push(args.positionals.slice(1))
161
+ }
162
+
163
+ features = args.values.feature || []
117
164
 
118
165
  const options = {
119
166
  name,
120
167
  def: args.values.def,
121
- debug: !!args.values.debug,
168
+ project: args.values.project,
169
+ dryrun: !!args.values.dryrun,
170
+ install: !!args.values.install,
171
+ target: targets,
172
+ feature: features,
173
+ debug: args.values.debug,
122
174
  help: !!args.values.help,
123
175
  version: !!args.values.version,
124
176
  }
125
177
 
178
+ // console.log('ARGS', args, options)
179
+
126
180
  return options
127
181
  }
128
182
 
@@ -131,7 +185,12 @@ function validateOptions(rawOptions) {
131
185
  const optShape = Gubu({
132
186
  name: Fault('The first argument must be the project name.', String),
133
187
  def: '',
134
- debug: Boolean,
188
+ project: String,
189
+ dryrun: Boolean,
190
+ install: Boolean,
191
+ target: [String],
192
+ feature: [String],
193
+ debug: String,
135
194
  help: Boolean,
136
195
  version: Boolean,
137
196
  })
@@ -148,13 +207,13 @@ function validateOptions(rawOptions) {
148
207
 
149
208
 
150
209
  function handleError(err) {
151
- CONSOLE.log('Voxgig Create SDK Error: '+err)
210
+ KONSOLE.log('Voxgig Create SDK Error: '+err)
152
211
  exit(err)
153
212
  }
154
213
 
155
214
 
156
215
  function version() {
157
- CONSOLE.log(Pkg.version)
216
+ KONSOLE.log(Pkg.version)
158
217
  }
159
218
 
160
219
 
@@ -173,6 +232,12 @@ Usage: npm create @voxgig/sdkgen@latest <name> <args>
173
232
  --def Path to the OpenAPI definition file (optional).
174
233
  -d
175
234
 
235
+ --project Project template (folder or package reference). Default: standard.
236
+ -p
237
+
238
+ --dryrun Perform a dry run, where no files are modified.
239
+ -y
240
+
176
241
  --debug Set log level (default: info): trace, error, debug, info, warn, fatal.
177
242
  -g
178
243
 
@@ -192,5 +257,5 @@ Examples:
192
257
  See also: https://voxgig.com/sdkgen
193
258
  `
194
259
 
195
- CONSOLE.log(s)
260
+ KONSOLE.log(s)
196
261
  }
@@ -9,6 +9,12 @@ type GenerateSpec = {
9
9
  name: string;
10
10
  def: string;
11
11
  root: string;
12
+ project: string;
13
+ debug?: string;
14
+ dryrun?: boolean;
15
+ target?: string[];
16
+ feature?: string[];
17
+ install?: boolean;
12
18
  };
13
19
  declare function CreateSdkGen(opts: FullCreateSdkGenOptions): {
14
20
  generate: (spec: GenerateSpec) => Promise<void>;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- /* Copyright (c) 2024 Richard Rodger, MIT License */
2
+ /* Copyright (c) 2024-2025 Richard Rodger, MIT License */
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -40,9 +40,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.CreateSdkGen = CreateSdkGen;
41
41
  const Fs = __importStar(require("node:fs"));
42
42
  const node_path_1 = __importDefault(require("node:path"));
43
- const util_1 = require("@voxgig/util");
43
+ const child_process_1 = require("child_process");
44
44
  const JostracaModule = __importStar(require("jostraca"));
45
- const { each, names, Jostraca } = JostracaModule;
45
+ const util_1 = require("@voxgig/util");
46
+ const package_json_1 = __importDefault(require("../package.json"));
47
+ const { names, Jostraca } = JostracaModule;
46
48
  function CreateSdkGen(opts) {
47
49
  const fs = opts.fs || Fs;
48
50
  const pino = (0, util_1.prettyPino)('create', opts);
@@ -50,48 +52,141 @@ function CreateSdkGen(opts) {
50
52
  const jostraca = Jostraca();
51
53
  async function generate(spec) {
52
54
  const start = Date.now();
53
- log.info({ point: 'generate-start', start });
55
+ log.info({ point: 'generate-start', start, note: spec.project });
54
56
  log.debug({ point: 'generate-spec', spec, note: JSON.stringify(spec, null, 2) });
55
- const rootModule = require(spec.root);
57
+ const projectFolder = resolveProjectFolder(spec);
58
+ const rootPath = node_path_1.default.join(projectFolder, spec.root);
59
+ const rootModule = require(rootPath);
56
60
  const Root = rootModule.Root;
57
61
  const name = spec.name;
58
62
  spec.def = (null == spec.def || '' === spec.def) ? name + '-openapi3.yml' : spec.def;
59
63
  const folder = node_path_1.default.join(process.cwd(), name + (name.endsWith('-sdk') ? '' : '-sdk'));
60
- const opts = {
64
+ const jopts = {
61
65
  fs: () => fs,
62
66
  folder,
63
67
  log: log.child({ cmp: 'jostraca' }),
64
68
  meta: { spec },
65
69
  existing: {
66
- // write: false,
67
- // present: true,
68
- merge: true
70
+ txt: {
71
+ merge: true
72
+ }
73
+ },
74
+ control: {
75
+ dryrun: spec.dryrun
69
76
  }
70
77
  };
71
78
  const model = {
72
79
  name,
80
+ project_name: name,
81
+ project_kind: spec.project,
73
82
  year: new Date().getFullYear(),
83
+ create_version: package_json_1.default.version
74
84
  };
75
85
  names(model, model.name);
86
+ names(model, model.name, 'project_name');
76
87
  log.debug({ point: 'generate-model', model, note: JSON.stringify(model, null, 2) });
77
- const info = await jostraca.generate(opts, () => Root({ model, spec }));
78
- logfiles(info, log);
88
+ const jres = await jostraca.generate(jopts, () => Root({ model, spec }));
89
+ // logfiles(jres, log)
90
+ (0, util_1.showChanges)(jopts.log, 'generate-result', jres, node_path_1.default.dirname(process.cwd()));
91
+ if (!spec.dryrun && spec.install) {
92
+ await installNpm(spec, jopts, model);
93
+ }
79
94
  log.info({ point: 'generate-end' });
80
95
  }
96
+ function resolveProjectFolder(spec) {
97
+ let projectFolder = spec.project;
98
+ if (node_path_1.default.isAbsolute(projectFolder)) {
99
+ return projectFolder;
100
+ }
101
+ projectFolder = node_path_1.default.resolve(node_path_1.default.join(__dirname, 'project', spec.project));
102
+ // TODO: support auto install project npm package (specific version) in a special cache folder
103
+ if (!fs.existsSync(projectFolder)) {
104
+ projectFolder = spec.project;
105
+ }
106
+ return projectFolder;
107
+ }
81
108
  return {
82
109
  generate,
83
110
  };
84
111
  }
85
- function logfiles(info, log) {
86
- const cwd = process.cwd();
87
- ['preserve', 'present', 'merge'].map(action => {
88
- let entries = info.file[action];
89
- if (0 < entries.length) {
90
- log.info({
91
- point: 'file-' + action, entries,
92
- note: '\n' + entries.map((n) => n.path.replace(cwd, '.')).join('\n')
93
- });
94
- }
112
+ async function installNpm(spec, opts, model) {
113
+ const folder = opts.folder;
114
+ const log = opts.log;
115
+ return new Promise((resolve, reject) => {
116
+ const cwd = node_path_1.default.resolve(folder, '.sdk');
117
+ log.info({ point: 'generate-install', install: 'npm', note: 'npm install # ' + cwd });
118
+ const env = {
119
+ ...process.env,
120
+ PATH: `${node_path_1.default.dirname(process.execPath)}${node_path_1.default.delimiter}${process.env.PATH}`,
121
+ };
122
+ const args = ['install'];
123
+ const spawn_opts = {
124
+ cwd,
125
+ env,
126
+ stdio: 'inherit', // Direct passthrough for real-time output
127
+ };
128
+ const child = (0, child_process_1.spawn)('npm', args, spawn_opts);
129
+ child.on('error', (err) => reject(new Error(`Failed to start npm: ${err.message}`)));
130
+ child.on('close', async (code) => {
131
+ if (code !== 0) {
132
+ reject(new Error(`npm install exited with code ${code}`));
133
+ }
134
+ else {
135
+ await installTargets(spec, opts, model, spawn_opts);
136
+ await installFeatures(spec, opts, model, spawn_opts);
137
+ resolve(null);
138
+ }
139
+ });
140
+ });
141
+ }
142
+ async function installTargets(spec, opts, model, spawn_opts) {
143
+ const target = spec.target;
144
+ if (null == target || 0 === target.length) {
145
+ return;
146
+ }
147
+ const log = opts.log;
148
+ return new Promise((resolve, reject) => {
149
+ const targetlist = target.join(',');
150
+ log.info({
151
+ point: 'generate-target', target: targetlist,
152
+ note: 'npm run target-add ' + targetlist
153
+ });
154
+ const args = ['run', 'add-target', targetlist];
155
+ const child = (0, child_process_1.spawn)('npm', args, spawn_opts);
156
+ child.on('error', (err) => reject(new Error(`Failed to start npm: ${err.message}`)));
157
+ child.on('close', async (code) => {
158
+ if (code !== 0) {
159
+ reject(new Error(`npm exited with code ${code}`));
160
+ }
161
+ else {
162
+ resolve(null);
163
+ }
164
+ });
165
+ });
166
+ }
167
+ async function installFeatures(spec, opts, model, spawn_opts) {
168
+ const feature = spec.feature;
169
+ if (null == feature || 0 === feature.length) {
170
+ return;
171
+ }
172
+ const log = opts.log;
173
+ return new Promise((resolve, reject) => {
174
+ const featurelist = feature.join(',');
175
+ log.info({
176
+ point: 'generate-feature', feature: featurelist,
177
+ note: 'npm run feature-add ' + featurelist
178
+ });
179
+ const args = ['run', 'add-feature', featurelist];
180
+ const child = (0, child_process_1.spawn)('npm', args, spawn_opts);
181
+ child.on('error', (err) => reject(new Error(`Failed to start npm: ${err.message}`)));
182
+ child.on('close', async (code) => {
183
+ if (code !== 0) {
184
+ reject(new Error(`npm exited with code ${code}`));
185
+ }
186
+ else {
187
+ resolve(null);
188
+ }
189
+ });
95
190
  });
96
191
  }
97
192
  //# sourceMappingURL=create-sdkgen.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-sdkgen.js","sourceRoot":"","sources":["../src/create-sdkgen.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;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AC,CAAA;QAEhD,MAAM,KAAK,GAAG,IAAA,qBAAK,EAAC,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;QAE5C,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,wBAAwB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;QAEpF,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAC/B,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;gBACf,MAAM,CAAC,IAAI,KAAK,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAC,CAAA;YACnD,CAAC;iBACI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,CAAA;YACf,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AAEJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const ModelSdk: import("jostraca").Component;
2
+ export { ModelSdk };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModelSdk = void 0;
4
+ const jostraca_1 = require("jostraca");
5
+ const ModelSdk = (0, jostraca_1.cmp)(function ModelSdk(props) {
6
+ const { spec } = props;
7
+ (0, jostraca_1.File)({ name: 'sdk.jsonic' }, () => {
8
+ (0, jostraca_1.Fragment)({
9
+ from: __dirname + '/../../../project/standard/.sdk/model/sdk.fragment.jsonic',
10
+ replace: {
11
+ ProjectName: spec.name,
12
+ NAME: spec.name,
13
+ DEF: spec.def,
14
+ }
15
+ });
16
+ });
17
+ });
18
+ exports.ModelSdk = ModelSdk;
19
+ //# sourceMappingURL=ModelSdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelSdk.js","sourceRoot":"","sources":["../../../src/project/standard/ModelSdk.ts"],"names":[],"mappings":";;;AACA,uCAKiB;AAIjB,MAAM,QAAQ,GAAG,IAAA,cAAG,EAAC,SAAS,QAAQ,CAAC,KAAU;IAC/C,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;IAGtB,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE;QAChC,IAAA,mBAAQ,EAAC;YACP,IAAI,EAAE,SAAS,GAAG,2DAA2D;YAC7E,OAAO,EAAE;gBACP,WAAW,EAAE,IAAI,CAAC,IAAI;gBACtB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,GAAG,EAAE,IAAI,CAAC,GAAG;aACd;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AAEJ,CAAC,CAAC,CAAA;AAIA,4BAAQ"}
@@ -0,0 +1,2 @@
1
+ declare const Root: import("jostraca").Component;
2
+ export { Root };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Root = void 0;
40
+ const node_path_1 = __importDefault(require("node:path"));
41
+ const Fs = __importStar(require("node:fs"));
42
+ const jostraca_1 = require("jostraca");
43
+ const ModelSdk_1 = require("./ModelSdk");
44
+ // TODO: rename to RootSdk
45
+ const Root = (0, jostraca_1.cmp)(function Root(props) {
46
+ const { ctx$, ctx$: { folder }, spec, model } = props;
47
+ // TODO: move to @voxgig/util as duplicated
48
+ model.const = { name: model.name };
49
+ (0, jostraca_1.names)(model.const, model.name);
50
+ model.const.year = new Date().getFullYear();
51
+ ctx$.model = model;
52
+ (0, jostraca_1.Project)({ folder }, () => {
53
+ const from = node_path_1.default.resolve(node_path_1.default.join(__dirname + '..', '..', '..', '..', 'project', 'standard'));
54
+ // console.log('FROM', from)
55
+ (0, jostraca_1.Copy)({
56
+ from
57
+ });
58
+ const origdef = spec.def;
59
+ const projdef = node_path_1.default.basename(origdef);
60
+ spec.def = projdef;
61
+ (0, jostraca_1.Folder)({ name: '.sdk' }, () => {
62
+ (0, jostraca_1.Folder)({ name: 'def' }, () => {
63
+ if (Fs.existsSync(origdef)) {
64
+ (0, jostraca_1.Copy)({ from: origdef, to: projdef });
65
+ }
66
+ else {
67
+ (0, jostraca_1.File)({ name: projdef }, () => {
68
+ (0, jostraca_1.Content)('# OpenAPI Definition');
69
+ });
70
+ }
71
+ });
72
+ (0, jostraca_1.Folder)({ name: 'model' }, () => {
73
+ (0, ModelSdk_1.ModelSdk)({ spec });
74
+ });
75
+ });
76
+ });
77
+ });
78
+ exports.Root = Root;
79
+ //# sourceMappingURL=Root.js.map
@@ -0,0 +1 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C,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE;gBAC3B,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC3B,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;gBACtC,CAAC;qBACI,CAAC;oBACJ,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE;wBAC3B,IAAA,kBAAO,EAAC,sBAAsB,CAAC,CAAA;oBACjC,CAAC,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC,CAAC,CAAA;YAEF,IAAA,iBAAM,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE;gBAC7B,IAAA,mBAAQ,EAAC,EAAE,IAAI,EAAE,CAAC,CAAA;YACpB,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IAEJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAIA,oBAAI"}
@@ -8,6 +8,7 @@ const ModelSdk = (0, jostraca_1.cmp)(function ModelSdk(props) {
8
8
  (0, jostraca_1.Fragment)({
9
9
  from: __dirname + '/../../project/.sdk/model/sdk.fragment.jsonic',
10
10
  replace: {
11
+ // TODO: should use ProjectName for consistency
11
12
  NAME: spec.name,
12
13
  DEF: spec.def,
13
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ModelSdk.js","sourceRoot":"","sources":["../../src/standard/ModelSdk.ts"],"names":[],"mappings":";;;AACA,uCAKiB;AAIjB,MAAM,QAAQ,GAAG,IAAA,cAAG,EAAC,SAAS,QAAQ,CAAC,KAAU;IAC/C,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;IAGtB,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE;QAChC,IAAA,mBAAQ,EAAC;YACP,IAAI,EAAE,SAAS,GAAG,+CAA+C;YACjE,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,GAAG,EAAE,IAAI,CAAC,GAAG;aACd;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AAEJ,CAAC,CAAC,CAAA;AAIA,4BAAQ"}
1
+ {"version":3,"file":"ModelSdk.js","sourceRoot":"","sources":["../../src/standard/ModelSdk.ts"],"names":[],"mappings":";;;AACA,uCAKiB;AAIjB,MAAM,QAAQ,GAAG,IAAA,cAAG,EAAC,SAAS,QAAQ,CAAC,KAAU;IAC/C,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;IAGtB,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE;QAChC,IAAA,mBAAQ,EAAC;YACP,IAAI,EAAE,SAAS,GAAG,+CAA+C;YACjE,OAAO,EAAE;gBACP,+CAA+C;gBAC/C,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,GAAG,EAAE,IAAI,CAAC,GAAG;aACd;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AAEJ,CAAC,CAAC,CAAA;AAIA,4BAAQ"}
@@ -1 +1 @@
1
- {"root":["../src/create-sdkgen.ts","../src/standard/modelsdk.ts","../src/standard/root.ts"],"version":"5.8.3"}
1
+ {"root":["../src/create-sdkgen.ts","../src/project/standard/modelsdk.ts","../src/project/standard/root.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxgig/create-sdkgen",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "main": "dist/create-sdkgen.js",
5
5
  "type": "commonjs",
6
6
  "types": "dist/create-sdkgen.d.ts",
@@ -42,16 +42,16 @@
42
42
  ],
43
43
  "devDependencies": {
44
44
  "@hapi/code": "^9.0.3",
45
- "@types/node": "22.15.15",
46
- "esbuild": "^0.25.4",
47
- "memfs": "^4.17.1",
45
+ "@types/node": "24.1.0",
46
+ "esbuild": "^0.25.8",
47
+ "memfs": "^4.24.0",
48
48
  "typescript": "^5.8.3"
49
49
  },
50
50
  "dependencies": {
51
- "@voxgig/util": "^0.0.10",
51
+ "@voxgig/util": "^0.2.0",
52
52
  "aontu": "^0.28.0",
53
53
  "chokidar": "^4.0.3",
54
54
  "gubu": "^9.0.0",
55
- "jostraca": "^0.17.0"
55
+ "jostraca": "^0.23.0"
56
56
  }
57
57
  }
@@ -1,12 +1,14 @@
1
- /* Copyright (c) 2024 Richard Rodger, MIT License */
1
+ /* Copyright (c) 2024-2025 Richard Rodger, MIT License */
2
2
 
3
3
  import * as Fs from 'node:fs'
4
4
  import Path from 'node:path'
5
-
6
- import { prettyPino, Pino } from '@voxgig/util'
5
+ import { spawn } from 'child_process'
7
6
 
8
7
  import * as JostracaModule from 'jostraca'
9
8
 
9
+ import { showChanges, prettyPino, Pino } from '@voxgig/util'
10
+
11
+ import Pkg from '../package.json'
10
12
 
11
13
 
12
14
  type FullCreateSdkGenOptions = {
@@ -23,10 +25,16 @@ type GenerateSpec = {
23
25
  name: string // Name of SDK project.
24
26
  def: string // Path to OpenAPI definition file, copied into SDK project.
25
27
  root: string // Path to Root template component.
28
+ project: string
29
+ debug?: string
30
+ dryrun?: boolean
31
+ target?: string[]
32
+ feature?: string[]
33
+ install?: boolean
26
34
  }
27
35
 
28
36
 
29
- const { each, names, Jostraca } = JostracaModule
37
+ const { names, Jostraca } = JostracaModule
30
38
 
31
39
 
32
40
  function CreateSdkGen(opts: FullCreateSdkGenOptions) {
@@ -39,10 +47,13 @@ function CreateSdkGen(opts: FullCreateSdkGenOptions) {
39
47
  async function generate(spec: GenerateSpec) {
40
48
  const start = Date.now()
41
49
 
42
- log.info({ point: 'generate-start', start })
50
+ log.info({ point: 'generate-start', start, note: spec.project })
43
51
  log.debug({ point: 'generate-spec', spec, note: JSON.stringify(spec, null, 2) })
44
52
 
45
- const rootModule: any = require(spec.root)
53
+ const projectFolder = resolveProjectFolder(spec)
54
+ const rootPath = Path.join(projectFolder, spec.root)
55
+
56
+ const rootModule: any = require(rootPath)
46
57
  const Root = rootModule.Root
47
58
 
48
59
  const name = spec.name
@@ -50,34 +61,67 @@ function CreateSdkGen(opts: FullCreateSdkGenOptions) {
50
61
 
51
62
  const folder = Path.join(process.cwd(), name + (name.endsWith('-sdk') ? '' : '-sdk'))
52
63
 
53
- const opts = {
64
+ const jopts = {
54
65
  fs: () => fs,
55
66
  folder,
56
67
  log: log.child({ cmp: 'jostraca' }),
57
68
  meta: { spec },
58
69
  existing: {
59
- // write: false,
60
- // present: true,
61
- merge: true
70
+ txt: {
71
+ merge: true
72
+ }
73
+ },
74
+ control: {
75
+ dryrun: spec.dryrun
62
76
  }
63
77
  }
64
78
 
65
79
  const model = {
66
80
  name,
81
+ project_name: name,
82
+ project_kind: spec.project,
67
83
  year: new Date().getFullYear(),
84
+ create_version: Pkg.version
68
85
  }
69
86
 
70
87
  names(model, model.name)
88
+ names(model, model.name, 'project_name')
71
89
 
72
90
  log.debug({ point: 'generate-model', model, note: JSON.stringify(model, null, 2) })
73
91
 
74
- const info = await jostraca.generate(opts, () => Root({ model, spec }))
92
+ const jres = await jostraca.generate(jopts, () => Root({ model, spec }))
75
93
 
76
- logfiles(info, log)
94
+ // logfiles(jres, log)
95
+
96
+ showChanges(jopts.log, 'generate-result', jres, Path.dirname(process.cwd()))
97
+
98
+ if (!spec.dryrun && spec.install) {
99
+ await installNpm(spec, jopts, model)
100
+ }
77
101
 
78
102
  log.info({ point: 'generate-end' })
79
103
  }
80
104
 
105
+
106
+ function resolveProjectFolder(spec: GenerateSpec) {
107
+ let projectFolder = spec.project
108
+
109
+ if (Path.isAbsolute(projectFolder)) {
110
+ return projectFolder
111
+ }
112
+
113
+ projectFolder = Path.resolve(Path.join(__dirname, 'project', spec.project))
114
+
115
+ // TODO: support auto install project npm package (specific version) in a special cache folder
116
+
117
+ if (!fs.existsSync(projectFolder)) {
118
+ projectFolder = spec.project
119
+ }
120
+
121
+ return projectFolder
122
+ }
123
+
124
+
81
125
  return {
82
126
  generate,
83
127
  }
@@ -85,20 +129,131 @@ function CreateSdkGen(opts: FullCreateSdkGenOptions) {
85
129
  }
86
130
 
87
131
 
132
+
133
+
134
+ async function installNpm(spec: GenerateSpec, opts: any, model: any) {
135
+ const folder = opts.folder
136
+ const log = opts.log
137
+
138
+ return new Promise((resolve, reject) => {
139
+ const cwd = Path.resolve(folder, '.sdk')
140
+ log.info({ point: 'generate-install', install: 'npm', note: 'npm install # ' + cwd })
141
+
142
+ const env = {
143
+ ...process.env,
144
+ PATH: `${Path.dirname(process.execPath)}${Path.delimiter}${process.env.PATH}`,
145
+ }
146
+
147
+ const args = ['install']
148
+
149
+ const spawn_opts: any = {
150
+ cwd,
151
+ env,
152
+ stdio: 'inherit', // Direct passthrough for real-time output
153
+ }
154
+
155
+ const child = spawn('npm', args, spawn_opts)
156
+
157
+ child.on('error', (err) => reject(new Error(`Failed to start npm: ${err.message}`)))
158
+
159
+ child.on('close', async (code) => {
160
+ if (code !== 0) {
161
+ reject(new Error(`npm install exited with code ${code}`))
162
+ }
163
+ else {
164
+ await installTargets(spec, opts, model, spawn_opts)
165
+ await installFeatures(spec, opts, model, spawn_opts)
166
+ resolve(null)
167
+ }
168
+ })
169
+ })
170
+ }
171
+
172
+
173
+ async function installTargets(spec: GenerateSpec, opts: any, model: any, spawn_opts: any) {
174
+ const target = (spec.target as string[])
175
+
176
+ if (null == target || 0 === target.length) {
177
+ return
178
+ }
179
+
180
+ const log = opts.log
181
+ return new Promise((resolve, reject) => {
182
+ const targetlist = target.join(',')
183
+
184
+ log.info({
185
+ point: 'generate-target', target: targetlist,
186
+ note: 'npm run target-add ' + targetlist
187
+ })
188
+
189
+ const args = ['run', 'add-target', targetlist]
190
+
191
+ const child = spawn('npm', args, spawn_opts)
192
+
193
+ child.on('error', (err) => reject(new Error(`Failed to start npm: ${err.message}`)))
194
+
195
+ child.on('close', async (code) => {
196
+ if (code !== 0) {
197
+ reject(new Error(`npm exited with code ${code}`))
198
+ }
199
+ else {
200
+ resolve(null)
201
+ }
202
+ })
203
+ })
204
+ }
205
+
206
+
207
+ async function installFeatures(spec: GenerateSpec, opts: any, model: any, spawn_opts: any) {
208
+ const feature = (spec.feature as string[])
209
+
210
+ if (null == feature || 0 === feature.length) {
211
+ return
212
+ }
213
+
214
+ const log = opts.log
215
+ return new Promise((resolve, reject) => {
216
+ const featurelist = feature.join(',')
217
+
218
+ log.info({
219
+ point: 'generate-feature', feature: featurelist,
220
+ note: 'npm run feature-add ' + featurelist
221
+ })
222
+
223
+ const args = ['run', 'add-feature', featurelist]
224
+
225
+ const child = spawn('npm', args, spawn_opts)
226
+
227
+ child.on('error', (err) => reject(new Error(`Failed to start npm: ${err.message}`)))
228
+
229
+ child.on('close', async (code) => {
230
+ if (code !== 0) {
231
+ reject(new Error(`npm exited with code ${code}`))
232
+ }
233
+ else {
234
+ resolve(null)
235
+ }
236
+ })
237
+ })
238
+
239
+ }
240
+
241
+
242
+ /*
88
243
  function logfiles(info: any, log: ReturnType<typeof Pino>) {
89
244
  const cwd = process.cwd()
90
245
 
91
- ;['preserve', 'present', 'merge'].map(action => {
92
- let entries = info.file[action]
246
+ ; Object.keys(info.files).map(action => {
247
+ let entries = info.files[action]
93
248
  if (0 < entries.length) {
94
- log.info({
249
+ log.debug({
95
250
  point: 'file-' + action, entries,
96
- note: '\n' + entries.map((n: any) => n.path.replace(cwd, '.')).join('\n')
251
+ note: '\n' + entries.map((n: any) => n.replace(cwd, '.')).join('\n')
97
252
  })
98
253
  }
99
254
  })
100
255
  }
101
-
256
+ */
102
257
 
103
258
  export type {
104
259
  CreateSdkGenOptions,
@@ -14,8 +14,9 @@ const ModelSdk = cmp(function ModelSdk(props: any) {
14
14
 
15
15
  File({ name: 'sdk.jsonic' }, () => {
16
16
  Fragment({
17
- from: __dirname + '/../../project/.sdk/model/sdk.fragment.jsonic',
17
+ from: __dirname + '/../../../project/standard/.sdk/model/sdk.fragment.jsonic',
18
18
  replace: {
19
+ ProjectName: spec.name,
19
20
  NAME: spec.name,
20
21
  DEF: spec.def,
21
22
  }
@@ -31,8 +31,13 @@ const Root = cmp(function Root(props: any) {
31
31
  ctx$.model = model
32
32
 
33
33
  Project({ folder }, () => {
34
+ const from =
35
+ Path.resolve(Path.join(__dirname + '..', '..', '..', '..', 'project', 'standard'))
36
+
37
+ // console.log('FROM', from)
38
+
34
39
  Copy({
35
- from: __dirname + '/../../project',
40
+ from
36
41
  })
37
42
 
38
43
  const origdef = spec.def