vovk-cli 0.0.1-draft.302 → 0.0.1-draft.306
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/dev/index.d.mts +2 -3
- package/dist/dev/index.mjs +10 -4
- package/dist/dev/writeMetaJson.mjs +1 -1
- package/dist/generate/getClientTemplateFiles.mjs +9 -21
- package/dist/getProjectInfo/getConfig/getTemplateDefs.d.mts +2 -0
- package/dist/getProjectInfo/getConfig/getTemplateDefs.mjs +26 -6
- package/dist/getProjectInfo/getConfig/index.mjs +1 -1
- package/dist/index.mjs +4 -2
- package/dist/types.d.mts +2 -0
- package/package.json +3 -3
package/dist/dev/index.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import type { DevOptions } from '../types.mjs';
|
|
1
2
|
export declare class VovkDev {
|
|
2
3
|
#private;
|
|
3
|
-
constructor({ schemaOut }:
|
|
4
|
-
schemaOut: string | undefined;
|
|
5
|
-
});
|
|
4
|
+
constructor({ schemaOut, devHttps }: Pick<DevOptions, 'schemaOut' | 'devHttps'>);
|
|
6
5
|
start({ exit }: {
|
|
7
6
|
exit: boolean;
|
|
8
7
|
}): Promise<void>;
|
package/dist/dev/index.mjs
CHANGED
|
@@ -36,8 +36,10 @@ export class VovkDev {
|
|
|
36
36
|
#segmentWatcher = null;
|
|
37
37
|
#onFirstTimeGenerate = null;
|
|
38
38
|
#schemaOut = null;
|
|
39
|
-
|
|
39
|
+
#devHttps;
|
|
40
|
+
constructor({ schemaOut, devHttps }) {
|
|
40
41
|
this.#schemaOut = schemaOut ?? null;
|
|
42
|
+
this.#devHttps = devHttps ?? false;
|
|
41
43
|
}
|
|
42
44
|
#watchSegments = (callback) => {
|
|
43
45
|
const segmentReg = /\/?\[\[\.\.\.[a-zA-Z-_]+\]\]\/route.ts$/;
|
|
@@ -252,7 +254,7 @@ export class VovkDev {
|
|
|
252
254
|
};
|
|
253
255
|
#requestSchema = debounceWithArgs(async (segmentName) => {
|
|
254
256
|
const { apiRoot, log, port, config } = this.#projectInfo;
|
|
255
|
-
const
|
|
257
|
+
const devHttps = this.#devHttps ?? config.devHttps;
|
|
256
258
|
const endpoint = `${apiRoot.startsWith(`http${devHttps ? 's' : ''}://`) ? apiRoot : `http${devHttps ? 's' : ''}://localhost:${port}${apiRoot}`}/${segmentName ? `${segmentName}/` : ''}_schema_`;
|
|
257
259
|
log.debug(`Requesting schema for ${formatLoggedSegmentName(segmentName)} at ${endpoint}`);
|
|
258
260
|
try {
|
|
@@ -326,7 +328,8 @@ export class VovkDev {
|
|
|
326
328
|
log.info('The schemas and the RPC client have been generated. Exiting...');
|
|
327
329
|
});
|
|
328
330
|
}
|
|
329
|
-
|
|
331
|
+
const devHttps = this.#devHttps ?? config.devHttps;
|
|
332
|
+
if (devHttps) {
|
|
330
333
|
const agent = new Agent({
|
|
331
334
|
connect: {
|
|
332
335
|
rejectUnauthorized: false,
|
|
@@ -382,7 +385,10 @@ export class VovkDev {
|
|
|
382
385
|
}
|
|
383
386
|
const env = process.env;
|
|
384
387
|
if (env.__VOVK_START_WATCHER_IN_STANDALONE_MODE__ === 'true') {
|
|
385
|
-
void new VovkDev({
|
|
388
|
+
void new VovkDev({
|
|
389
|
+
schemaOut: env.__VOVK_SCHEMA_OUT_FLAG__ || undefined,
|
|
390
|
+
devHttps: env.__VOVK_DEV_HTTPS_FLAG__ === 'true',
|
|
391
|
+
}).start({
|
|
386
392
|
exit: env.__VOVK_EXIT__ === 'true',
|
|
387
393
|
});
|
|
388
394
|
}
|
|
@@ -5,7 +5,7 @@ import { META_FILE_NAME } from './writeOneSegmentSchemaFile.mjs';
|
|
|
5
5
|
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
6
6
|
export default async function writeMetaJson(schemaOutAbsolutePath, projectInfo) {
|
|
7
7
|
const metaJsonPath = path.join(schemaOutAbsolutePath, META_FILE_NAME + '.json');
|
|
8
|
-
const metaStr = JSON.stringify({ config: projectInfo ? pick(projectInfo.config, projectInfo.config.emitConfig) : {} }, null, 2);
|
|
8
|
+
const metaStr = JSON.stringify({ config: projectInfo ? pick(projectInfo.config, [...projectInfo.config.emitConfig, '$schema']) : {} }, null, 2);
|
|
9
9
|
const existingStr = await fs.readFile(metaJsonPath, 'utf-8').catch(() => null);
|
|
10
10
|
if (existingStr !== metaStr) {
|
|
11
11
|
await fs.writeFile(metaJsonPath, metaStr);
|
|
@@ -3,7 +3,6 @@ import { glob } from 'glob';
|
|
|
3
3
|
import resolveAbsoluteModulePath from '../utils/resolveAbsoluteModulePath.mjs';
|
|
4
4
|
import getFileSystemEntryType, { FileSystemEntryType } from '../utils/getFileSystemEntryType.mjs';
|
|
5
5
|
import getPublicModuleNameFromPath from '../utils/getPublicModuleNameFromPath.mjs';
|
|
6
|
-
import { BuiltInTemplateName } from '../getProjectInfo/getConfig/getTemplateDefs.mjs';
|
|
7
6
|
export default async function getClientTemplateFiles({ config, cwd, log, configKey, cliGenerateOptions, }) {
|
|
8
7
|
const usedTemplateDefs = {};
|
|
9
8
|
const fromTemplates = configKey === 'composedClient'
|
|
@@ -19,19 +18,8 @@ export default async function getClientTemplateFiles({ config, cwd, log, configK
|
|
|
19
18
|
if (!(templateName in config.clientTemplateDefs)) {
|
|
20
19
|
throw new Error(`Unknown template name: ${templateName}`);
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
if (usedDef.isTsClient) {
|
|
24
|
-
usedDef = {
|
|
25
|
-
...usedDef,
|
|
26
|
-
requires: {
|
|
27
|
-
...usedDef.requires,
|
|
28
|
-
[BuiltInTemplateName.mixins]: '.',
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
usedTemplateDefs[templateName] = usedDef;
|
|
21
|
+
usedTemplateDefs[templateName] = config.clientTemplateDefs[templateName];
|
|
33
22
|
}
|
|
34
|
-
// $openapi['github']['components']['schemas']['User'];
|
|
35
23
|
const templateFiles = [];
|
|
36
24
|
const entries = Object.entries(usedTemplateDefs);
|
|
37
25
|
for (let i = 0; i < entries.length; i++) {
|
|
@@ -49,6 +37,7 @@ export default async function getClientTemplateFiles({ config, cwd, log, configK
|
|
|
49
37
|
}
|
|
50
38
|
const defOutDir = configKey === 'composedClient' ? templateDef.composedClient?.outDir : templateDef.segmentedClient?.outDir;
|
|
51
39
|
let files = [];
|
|
40
|
+
const outCwdRelativeDir = forceOutCwdRelativeDir ?? cliOutDir ?? defOutDir ?? configOutDir;
|
|
52
41
|
if (templateAbsolutePath) {
|
|
53
42
|
if (entryType === FileSystemEntryType.FILE) {
|
|
54
43
|
files = [{ filePath: templateAbsolutePath, isSingleFileTemplate: true }];
|
|
@@ -64,7 +53,6 @@ export default async function getClientTemplateFiles({ config, cwd, log, configK
|
|
|
64
53
|
log.error(`Template "${templateAbsolutePath}" not found`);
|
|
65
54
|
continue;
|
|
66
55
|
}
|
|
67
|
-
const outCwdRelativeDir = forceOutCwdRelativeDir ?? cliOutDir ?? defOutDir ?? configOutDir;
|
|
68
56
|
for (const { filePath, isSingleFileTemplate } of files) {
|
|
69
57
|
templateFiles.push({
|
|
70
58
|
templateName,
|
|
@@ -74,14 +62,14 @@ export default async function getClientTemplateFiles({ config, cwd, log, configK
|
|
|
74
62
|
templateDef,
|
|
75
63
|
});
|
|
76
64
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
entries.push([tName, def, path.join(outCwdRelativeDir, reqRelativeDir)]);
|
|
65
|
+
}
|
|
66
|
+
if (templateDef.requires) {
|
|
67
|
+
for (const [tName, reqRelativeDir] of Object.entries(templateDef.requires)) {
|
|
68
|
+
const def = config.clientTemplateDefs[tName];
|
|
69
|
+
if (!def) {
|
|
70
|
+
throw new Error(`Template "${tName}" required by "${templateName}" not found`);
|
|
84
71
|
}
|
|
72
|
+
entries.push([tName, def, path.join(outCwdRelativeDir, reqRelativeDir)]);
|
|
85
73
|
}
|
|
86
74
|
}
|
|
87
75
|
}
|
|
@@ -12,9 +12,11 @@ export declare enum BuiltInTemplateName {
|
|
|
12
12
|
mixins = "mixins",
|
|
13
13
|
rsSrc = "rsSrc",
|
|
14
14
|
rsPkg = "rsPkg",
|
|
15
|
+
rsReadme = "rsReadme",
|
|
15
16
|
rs = "rs",
|
|
16
17
|
pySrc = "pySrc",
|
|
17
18
|
pyPkg = "pyPkg",
|
|
19
|
+
pyReadme = "pyReadme",
|
|
18
20
|
py = "py"
|
|
19
21
|
}
|
|
20
22
|
export default function getTemplateDefs(userTemplateDefs?: VovkStrictConfig['clientTemplateDefs']): VovkStrictConfig['clientTemplateDefs'];
|
|
@@ -17,9 +17,11 @@ export var BuiltInTemplateName;
|
|
|
17
17
|
// other languages (packages installed separately)
|
|
18
18
|
BuiltInTemplateName["rsSrc"] = "rsSrc";
|
|
19
19
|
BuiltInTemplateName["rsPkg"] = "rsPkg";
|
|
20
|
+
BuiltInTemplateName["rsReadme"] = "rsReadme";
|
|
20
21
|
BuiltInTemplateName["rs"] = "rs";
|
|
21
22
|
BuiltInTemplateName["pySrc"] = "pySrc";
|
|
22
23
|
BuiltInTemplateName["pyPkg"] = "pyPkg";
|
|
24
|
+
BuiltInTemplateName["pyReadme"] = "pyReadme";
|
|
23
25
|
BuiltInTemplateName["py"] = "py";
|
|
24
26
|
})(BuiltInTemplateName || (BuiltInTemplateName = {}));
|
|
25
27
|
export default function getTemplateDefs(userTemplateDefs = {}) {
|
|
@@ -27,18 +29,24 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
|
|
|
27
29
|
const builtInDefs = {
|
|
28
30
|
[BuiltInTemplateName.ts]: {
|
|
29
31
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.ts}/`,
|
|
30
|
-
requires: {
|
|
31
|
-
|
|
32
|
+
requires: {
|
|
33
|
+
[BuiltInTemplateName.schemaTs]: '.',
|
|
34
|
+
[BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
|
|
35
|
+
},
|
|
32
36
|
},
|
|
33
37
|
[BuiltInTemplateName.cjs]: {
|
|
34
38
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.cjs}/`,
|
|
35
|
-
requires: {
|
|
36
|
-
|
|
39
|
+
requires: {
|
|
40
|
+
[BuiltInTemplateName.schemaCjs]: '.',
|
|
41
|
+
[BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
|
|
42
|
+
},
|
|
37
43
|
},
|
|
38
44
|
[BuiltInTemplateName.mjs]: {
|
|
39
45
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.mjs}/`,
|
|
40
|
-
requires: {
|
|
41
|
-
|
|
46
|
+
requires: {
|
|
47
|
+
[BuiltInTemplateName.schemaCjs]: '.',
|
|
48
|
+
[BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
|
|
49
|
+
},
|
|
42
50
|
},
|
|
43
51
|
[BuiltInTemplateName.schemaTs]: {
|
|
44
52
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.schemaTs}/`,
|
|
@@ -66,6 +74,12 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
|
|
|
66
74
|
},
|
|
67
75
|
[BuiltInTemplateName.rsPkg]: {
|
|
68
76
|
templatePath: `vovk-rust/client-templates/${BuiltInTemplateName.rsPkg}/`,
|
|
77
|
+
requires: {
|
|
78
|
+
[BuiltInTemplateName.rsReadme]: './',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
[BuiltInTemplateName.rsReadme]: {
|
|
82
|
+
templatePath: `vovk-rust/client-templates/${BuiltInTemplateName.rsReadme}/`,
|
|
69
83
|
},
|
|
70
84
|
[BuiltInTemplateName.rs]: {
|
|
71
85
|
composedClient: {
|
|
@@ -84,6 +98,12 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
|
|
|
84
98
|
},
|
|
85
99
|
[BuiltInTemplateName.pyPkg]: {
|
|
86
100
|
templatePath: `vovk-python/client-templates/${BuiltInTemplateName.pyPkg}/`,
|
|
101
|
+
requires: {
|
|
102
|
+
[BuiltInTemplateName.pyReadme]: './',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
[BuiltInTemplateName.pyReadme]: {
|
|
106
|
+
templatePath: `vovk-python/client-templates/${BuiltInTemplateName.pyReadme}/`,
|
|
87
107
|
},
|
|
88
108
|
[BuiltInTemplateName.py]: {
|
|
89
109
|
composedClient: {
|
|
@@ -75,7 +75,7 @@ export default async function getConfig({ configPath, cwd }) {
|
|
|
75
75
|
openApiMixins: {},
|
|
76
76
|
};
|
|
77
77
|
if (typeof conf.emitConfig === 'undefined') {
|
|
78
|
-
config.emitConfig = ['
|
|
78
|
+
config.emitConfig = ['libs'];
|
|
79
79
|
}
|
|
80
80
|
else if (conf.emitConfig === true) {
|
|
81
81
|
config.emitConfig = Object.keys(config);
|
package/dist/index.mjs
CHANGED
|
@@ -24,8 +24,9 @@ program
|
|
|
24
24
|
.option('--next-dev', 'start schema watcher and Next.js with automatic port allocation')
|
|
25
25
|
.option('--exit', 'kill the processe when schema and client is generated')
|
|
26
26
|
.option('--schema-out <path>', 'path to schema output directory (default: .vovk-schema)')
|
|
27
|
+
.option('--https, --dev-https', 'use HTTPS for the dev server (default: false)')
|
|
27
28
|
.action(async (nextArgs, options) => {
|
|
28
|
-
const { nextDev, exit = false, schemaOut } = options;
|
|
29
|
+
const { nextDev, exit = false, schemaOut, devHttps } = options;
|
|
29
30
|
const portAttempts = 30;
|
|
30
31
|
const PORT = !nextDev
|
|
31
32
|
? process.env.PORT
|
|
@@ -52,6 +53,7 @@ program
|
|
|
52
53
|
PORT,
|
|
53
54
|
__VOVK_START_WATCHER_IN_STANDALONE_MODE__: 'true',
|
|
54
55
|
__VOVK_SCHEMA_OUT_FLAG__: schemaOut ?? '',
|
|
56
|
+
__VOVK_DEV_HTTPS_FLAG__: devHttps ? 'true' : 'false',
|
|
55
57
|
__VOVK_EXIT__: exit ? 'true' : 'false',
|
|
56
58
|
},
|
|
57
59
|
},
|
|
@@ -68,7 +70,7 @@ program
|
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
else {
|
|
71
|
-
void new VovkDev({ schemaOut }).start({ exit });
|
|
73
|
+
void new VovkDev({ schemaOut, devHttps }).start({ exit });
|
|
72
74
|
}
|
|
73
75
|
});
|
|
74
76
|
program
|
package/dist/types.d.mts
CHANGED
|
@@ -11,6 +11,7 @@ export interface DevOptions {
|
|
|
11
11
|
schemaOut?: string;
|
|
12
12
|
nextDev?: boolean;
|
|
13
13
|
exit?: boolean;
|
|
14
|
+
devHttps?: boolean;
|
|
14
15
|
}
|
|
15
16
|
export interface GenerateOptions {
|
|
16
17
|
prettify?: boolean;
|
|
@@ -80,5 +81,6 @@ export type VovkEnv = {
|
|
|
80
81
|
VOVK_DEV_HTTPS?: string;
|
|
81
82
|
__VOVK_START_WATCHER_IN_STANDALONE_MODE__?: 'true';
|
|
82
83
|
__VOVK_SCHEMA_OUT_FLAG__?: string;
|
|
84
|
+
__VOVK_DEV_HTTPS_FLAG__?: 'true' | 'false';
|
|
83
85
|
__VOVK_EXIT__?: 'true' | 'false';
|
|
84
86
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vovk-cli",
|
|
3
|
-
"version": "0.0.1-draft.
|
|
3
|
+
"version": "0.0.1-draft.306",
|
|
4
4
|
"bin": {
|
|
5
5
|
"vovk": "./dist/index.mjs"
|
|
6
6
|
},
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://vovk.dev",
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"vovk": "^3.0.0-draft.
|
|
38
|
+
"vovk": "^3.0.0-draft.351"
|
|
39
39
|
},
|
|
40
40
|
"optionalDependencies": {
|
|
41
|
-
"vovk-python": "^0.0.1-draft.
|
|
41
|
+
"vovk-python": "^0.0.1-draft.56"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@iarna/toml": "^2.2.5",
|