vovk 0.2.3-beta.33 → 0.2.3-beta.34
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/cli/generateClient.js +26 -7
- package/package.json +1 -1
package/cli/generateClient.js
CHANGED
|
@@ -19,25 +19,44 @@ function canRequire(moduleName) {
|
|
|
19
19
|
async function generateClient(rcPath) {
|
|
20
20
|
const vovkrc = getVovkrc(rcPath);
|
|
21
21
|
const jsonPath = '../../.vovk.json';
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const localJsonPath = path.join('..', jsonPath);
|
|
23
|
+
const fetcherPath = vovkrc.fetcher.startsWith('.') ? path.join(__dirname, '../..', vovkrc.fetcher) : vovkrc.fetcher;
|
|
24
|
+
const localFetcherPath = vovkrc.fetcher.startsWith('.') ? path.join('..', fetcherPath) : fetcherPath;
|
|
25
25
|
const streamFetcherPath = vovkrc.streamFetcher.startsWith('.')
|
|
26
|
-
? path.join(__dirname, '
|
|
26
|
+
? path.join(__dirname, '../..', vovkrc.streamFetcher)
|
|
27
27
|
: vovkrc.streamFetcher;
|
|
28
|
+
const localStreamFetcherPath = vovkrc.streamFetcher.startsWith('.')
|
|
29
|
+
? path.join('..', streamFetcherPath)
|
|
30
|
+
: streamFetcherPath;
|
|
31
|
+
const validatePath = vovkrc.validateOnClient?.startsWith('.')
|
|
32
|
+
? path.join(__dirname, '../..', vovkrc.validateOnClient)
|
|
33
|
+
: vovkrc.validateOnClient;
|
|
34
|
+
const localValidatePath = vovkrc.validateOnClient?.startsWith('.') ? path.join('..', validatePath) : validatePath;
|
|
28
35
|
|
|
29
36
|
if (typeof vovkrc.validateOnClient === 'undefined') {
|
|
30
37
|
vovkrc.validateOnClient = canRequire('vovk-zod/zodValidateOnClient') ? 'vovk-zod/zodValidateOnClient' : null;
|
|
31
|
-
} else if (vovkrc.validateOnClient && !canRequire(
|
|
38
|
+
} else if (vovkrc.validateOnClient && !canRequire(localValidatePath)) {
|
|
32
39
|
throw new Error(
|
|
33
40
|
`Unble to generate Vovk Client: cannot find "validateOnClient" module '${vovkrc.validateOnClient}'. Check your .vovkrc.js file`
|
|
34
41
|
);
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
if (!canRequire(
|
|
44
|
+
if (!canRequire(localJsonPath)) {
|
|
38
45
|
throw new Error(`Unble to generate Vovk Client: cannot find ".vovk.json" file '${jsonPath}'.`);
|
|
39
46
|
}
|
|
40
47
|
|
|
48
|
+
if (!canRequire(localFetcherPath)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Unble to generate Vovk Client: cannot find "fetcher" module '${vovkrc.fetcher}'. Check your .vovkrc.js file`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!canRequire(localStreamFetcherPath)) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Unble to generate Vovk Client: cannot find "streamFetcher" module '${vovkrc.streamFetcher}'. Check your .vovkrc.js file`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
41
60
|
const controllersPath = path.join('../..', vovkrc.route).replace(/\.ts$/, '');
|
|
42
61
|
let ts = `import type { Controllers, Workers } from "${controllersPath}";
|
|
43
62
|
import type { clientizeController } from 'vovk/client';
|
|
@@ -49,7 +68,7 @@ type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
|
|
|
49
68
|
`;
|
|
50
69
|
let js = `const { clientizeController } = require('vovk/client');
|
|
51
70
|
const { promisifyWorker } = require('vovk/worker');
|
|
52
|
-
const metadata = require('${
|
|
71
|
+
const metadata = require('${localJsonPath}');
|
|
53
72
|
const { default: fetcher } = require('${fetcherPath}');
|
|
54
73
|
const { default: streamFetcher } = require('${streamFetcherPath}');
|
|
55
74
|
const prefix = '${vovkrc.prefix ?? '/api'}';
|