vovk 0.2.3-beta.68 → 0.2.3-beta.69
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 +24 -14
- package/cli/getVars.js +10 -1
- package/package.json +1 -1
- package/cli/lib/canRequire.js +0 -11
package/cli/generateClient.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
const fs = require('fs/promises');
|
|
3
3
|
const path = require('path');
|
|
4
|
-
const canRequire = require('./lib/canRequire');
|
|
5
4
|
const getReturnPath = require('./lib/getReturnPath');
|
|
6
5
|
|
|
6
|
+
function canRequire(moduleName) {
|
|
7
|
+
try {
|
|
8
|
+
require.resolve(moduleName);
|
|
9
|
+
return true; // The module exists and can be required
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return false; // The module does not exist
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
/**
|
|
8
16
|
* Generates client code with string concatenation so it should be much faster than using AST
|
|
9
17
|
* TODO: Check fetcher and streamFetcher for existence
|
|
10
18
|
* @type {(rcPath: import('../src').VovkEnv) => Promise<boolean>}
|
|
11
19
|
*/
|
|
12
20
|
async function generateClient({ ...env }) {
|
|
13
|
-
const outDir =
|
|
14
|
-
const returnDir = getReturnPath(outDir,
|
|
21
|
+
const outDir = env.VOVK_CLIENT_OUT;
|
|
22
|
+
const returnDir = getReturnPath(outDir, process.cwd());
|
|
15
23
|
const jsonPath = path.join(returnDir, '.vovk.json');
|
|
16
|
-
const localJsonPath = path.join('
|
|
24
|
+
const localJsonPath = path.join(process.cwd(), '.vovk.json');
|
|
17
25
|
const fetcherPath = env.VOVK_FETCHER.startsWith('.') ? path.join(returnDir, env.VOVK_FETCHER) : env.VOVK_FETCHER;
|
|
18
|
-
|
|
19
26
|
const streamFetcherPath = env.VOVK_STREAM_FETCHER.startsWith('.')
|
|
20
27
|
? path.join(returnDir, env.VOVK_STREAM_FETCHER)
|
|
21
28
|
: env.VOVK_STREAM_FETCHER;
|
|
@@ -37,7 +44,8 @@ async function generateClient({ ...env }) {
|
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
const controllersPath = path.join(returnDir, env.VOVK_ROUTE).replace(/\.ts$/, '');
|
|
40
|
-
let ts =
|
|
47
|
+
let ts = `// auto-generated
|
|
48
|
+
/* eslint-disable */
|
|
41
49
|
import type { Controllers, Workers } from "${controllersPath}";
|
|
42
50
|
import type { clientizeController } from 'vovk/client';
|
|
43
51
|
import type { promisifyWorker } from 'vovk/worker';
|
|
@@ -46,7 +54,8 @@ import type fetcher from '${fetcherPath}';
|
|
|
46
54
|
|
|
47
55
|
type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
|
|
48
56
|
`;
|
|
49
|
-
let js =
|
|
57
|
+
let js = `// auto-generated
|
|
58
|
+
/* eslint-disable */
|
|
50
59
|
const { clientizeController } = require('vovk/client');
|
|
51
60
|
const { promisifyWorker } = require('vovk/worker');
|
|
52
61
|
const metadata = require('${jsonPath}');
|
|
@@ -77,14 +86,15 @@ const { default: validateOnClient = null } = ${
|
|
|
77
86
|
if(typeof window !== 'undefined') fetch(prefix + '/__ping', { method: 'POST' });
|
|
78
87
|
`; */
|
|
79
88
|
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const existingJs = await fs.readFile(
|
|
83
|
-
const existingTs = await fs.readFile(
|
|
89
|
+
const localJsPath = path.join(outDir, 'index.js');
|
|
90
|
+
const localTsPath = path.join(outDir, 'index.d.ts');
|
|
91
|
+
const existingJs = await fs.readFile(localJsPath, 'utf-8').catch(() => '');
|
|
92
|
+
const existingTs = await fs.readFile(localTsPath, 'utf-8').catch(() => '');
|
|
84
93
|
if (existingJs === js && existingTs === ts) return false;
|
|
85
|
-
|
|
86
|
-
await fs.
|
|
87
|
-
await fs.writeFile(
|
|
94
|
+
|
|
95
|
+
await fs.mkdir(outDir, { recursive: true });
|
|
96
|
+
await fs.writeFile(localJsPath, js);
|
|
97
|
+
await fs.writeFile(localTsPath, ts);
|
|
88
98
|
|
|
89
99
|
return true;
|
|
90
100
|
}
|
package/cli/getVars.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
3
5
|
let vars;
|
|
4
6
|
/** @type {(rcPath: string, options?: { warn?: boolean; VOVK_CLIENT_OUT?: string; }) => import('../src').VovkEnv} */
|
|
5
7
|
function getVars(rcPath, options = {}) {
|
|
@@ -21,7 +23,14 @@ function getVars(rcPath, options = {}) {
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
vars = {
|
|
24
|
-
VOVK_CLIENT_OUT:
|
|
26
|
+
VOVK_CLIENT_OUT:
|
|
27
|
+
process.env.VOVK_OUT ||
|
|
28
|
+
(options.VOVK_CLIENT_OUT?.startsWith('/')
|
|
29
|
+
? options.VOVK_CLIENT_OUT
|
|
30
|
+
: options.VOVK_CLIENT_OUT
|
|
31
|
+
? path.join(process.cwd(), options.VOVK_CLIENT_OUT)
|
|
32
|
+
: null) ||
|
|
33
|
+
vovkRc.out,
|
|
25
34
|
VOVK_PORT: process.env.VOVK_PORT || '3420',
|
|
26
35
|
VOVK_ROUTE: process.env.VOVK_ROUTE || vovkRc.route,
|
|
27
36
|
VOVK_FETCHER: process.env.VOVK_FETCHER || vovkRc.fetcher,
|
package/package.json
CHANGED
package/cli/lib/canRequire.js
DELETED