vovk-cli 0.0.1-draft.8 → 0.0.1-draft.81
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/README.md +29 -1
- package/client-templates/main/main.cjs.ejs +15 -0
- package/client-templates/main/main.d.cts.ejs +14 -0
- package/client-templates/module/module.d.mts.ejs +14 -0
- package/client-templates/module/module.mjs.ejs +24 -0
- package/client-templates/python/__init__.py +276 -0
- package/client-templates/ts/index.ts.ejs +25 -0
- package/dist/dev/diffSchema.d.mts +36 -0
- package/dist/{watcher → dev}/diffSchema.mjs +3 -11
- package/dist/{watcher → dev}/ensureSchemaFiles.d.mts +3 -0
- package/dist/{watcher → dev}/ensureSchemaFiles.mjs +28 -14
- package/dist/dev/index.d.mts +6 -0
- package/dist/{watcher → dev}/index.mjs +129 -62
- package/dist/{watcher → dev}/isMetadataEmpty.mjs +1 -1
- package/dist/{watcher → dev}/logDiffResult.d.mts +2 -2
- package/dist/dev/logDiffResult.mjs +57 -0
- package/dist/{watcher → dev}/writeOneSchemaFile.d.mts +1 -1
- package/dist/{watcher → dev}/writeOneSchemaFile.mjs +2 -2
- package/dist/generate/ensureClient.d.mts +5 -0
- package/dist/generate/ensureClient.mjs +27 -0
- package/dist/generate/getClientTemplates.d.mts +15 -0
- package/dist/generate/getClientTemplates.mjs +30 -0
- package/dist/generate/index.d.mts +13 -0
- package/dist/generate/index.mjs +84 -0
- package/dist/getProjectInfo/getConfig.d.mts +3 -3
- package/dist/getProjectInfo/getConfig.mjs +8 -5
- package/dist/getProjectInfo/getConfigAbsolutePaths.mjs +2 -2
- package/dist/getProjectInfo/getRelativeSrcRoot.mjs +1 -1
- package/dist/getProjectInfo/getUserConfig.mjs +3 -1
- package/dist/getProjectInfo/importUncachedModule.mjs +0 -1
- package/dist/getProjectInfo/importUncachedModuleWorker.mjs +0 -1
- package/dist/getProjectInfo/index.d.mts +14 -5
- package/dist/getProjectInfo/index.mjs +21 -13
- package/dist/index.d.mts +1 -27
- package/dist/index.mjs +59 -64
- package/dist/init/checkTSConfigForExperimentalDecorators.mjs +2 -2
- package/dist/init/createConfig.d.mts +3 -4
- package/dist/init/createConfig.mjs +9 -8
- package/dist/init/getTemplateFilesFromPackage.d.mts +2 -1
- package/dist/init/getTemplateFilesFromPackage.mjs +4 -5
- package/dist/init/index.d.mts +2 -3
- package/dist/init/index.mjs +61 -97
- package/dist/init/installDependencies.d.mts +4 -1
- package/dist/init/installDependencies.mjs +2 -2
- package/dist/init/logUpdateDependenciesError.d.mts +11 -0
- package/dist/init/logUpdateDependenciesError.mjs +45 -0
- package/dist/init/updateDependenciesWithoutInstalling.d.mts +3 -2
- package/dist/init/updateDependenciesWithoutInstalling.mjs +13 -8
- package/dist/init/updateNPMScripts.d.mts +3 -1
- package/dist/init/updateNPMScripts.mjs +10 -6
- package/dist/init/updateTypeScriptConfig.mjs +2 -2
- package/dist/initProgram.d.mts +2 -0
- package/dist/initProgram.mjs +22 -0
- package/dist/locateSegments.d.mts +7 -1
- package/dist/locateSegments.mjs +9 -6
- package/dist/new/addClassToSegmentCode.d.mts +1 -2
- package/dist/new/addClassToSegmentCode.mjs +5 -5
- package/dist/new/addCommonTerms.mjs +1 -0
- package/dist/new/index.d.mts +2 -2
- package/dist/new/index.mjs +3 -3
- package/dist/new/newModule.d.mts +3 -3
- package/dist/new/newModule.mjs +37 -28
- package/dist/new/newSegment.mjs +8 -6
- package/dist/new/render.mjs +2 -5
- package/dist/postinstall.mjs +16 -19
- package/dist/types.d.mts +48 -9
- package/dist/utils/debounceWithArgs.d.mts +1 -1
- package/dist/utils/debounceWithArgs.mjs +24 -9
- package/dist/utils/formatLoggedSegmentName.mjs +1 -1
- package/dist/utils/getAvailablePort.mjs +3 -2
- package/dist/utils/getFileSystemEntryType.mjs +1 -1
- package/package.json +21 -18
- package/templates/controller.ejs +10 -9
- package/templates/service.ejs +6 -6
- package/dist/generateClient.d.mts +0 -7
- package/dist/generateClient.mjs +0 -97
- package/dist/watcher/diffSchema.d.mts +0 -43
- package/dist/watcher/index.d.mts +0 -6
- package/dist/watcher/logDiffResult.mjs +0 -90
- package/templates/worker.ejs +0 -1
- /package/dist/{watcher → dev}/isMetadataEmpty.d.mts +0 -0
|
@@ -5,23 +5,26 @@ export default async function getConfig({ clientOutDir, cwd }) {
|
|
|
5
5
|
const { configAbsolutePaths, error, userConfig } = await getUserConfig({ cwd });
|
|
6
6
|
const conf = userConfig ?? {};
|
|
7
7
|
const srcRoot = await getRelativeSrcRoot({ cwd });
|
|
8
|
+
const validateOnClientImport = env.VOVK_VALIDATE_ON_CLIENT_PATH ?? conf.validateOnClientImport ?? null;
|
|
9
|
+
const fetcherImport = env.VOVK_FETCHER_PATH ?? conf.fetcherImport ?? 'vovk/dist/client/defaultFetcher.js';
|
|
10
|
+
const createRPCImport = env.VOVK_CREATE_RPC_PATH ?? conf.createRPCImport ?? 'vovk/dist/client/createRPC.js';
|
|
8
11
|
const config = {
|
|
9
12
|
modulesDir: env.VOVK_MODULES_DIR ?? conf.modulesDir ?? './' + [srcRoot, 'modules'].filter(Boolean).join('/'),
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
validateOnClientImport: typeof validateOnClientImport === 'string' ? [validateOnClientImport] : validateOnClientImport,
|
|
14
|
+
fetcherImport: typeof fetcherImport === 'string' ? [fetcherImport] : fetcherImport,
|
|
15
|
+
createRPCImport: typeof createRPCImport === 'string' ? [createRPCImport] : createRPCImport,
|
|
13
16
|
schemaOutDir: env.VOVK_SCHEMA_OUT_DIR ?? conf.schemaOutDir ?? './.vovk-schema',
|
|
14
17
|
clientOutDir: clientOutDir ?? env.VOVK_CLIENT_OUT_DIR ?? conf.clientOutDir ?? './node_modules/.vovk-client',
|
|
15
18
|
origin: (env.VOVK_ORIGIN ?? conf.origin ?? '').replace(/\/$/, ''), // Remove trailing slash
|
|
16
19
|
rootEntry: env.VOVK_ROOT_ENTRY ?? conf.rootEntry ?? 'api',
|
|
17
20
|
rootSegmentModulesDirName: env.VOVK_ROOT_SEGMENT_MODULES_DIR_NAME ?? conf.rootSegmentModulesDirName ?? '',
|
|
18
|
-
logLevel: env.VOVK_LOG_LEVEL ?? conf.logLevel ?? '
|
|
21
|
+
logLevel: env.VOVK_LOG_LEVEL ?? conf.logLevel ?? 'info',
|
|
19
22
|
prettifyClient: (env.VOVK_PRETTIFY_CLIENT ? !!env.VOVK_PRETTIFY_CLIENT : null) ?? conf.prettifyClient ?? false,
|
|
20
23
|
devHttps: (env.VOVK_DEV_HTTPS ? !!env.VOVK_DEV_HTTPS : null) ?? conf.devHttps ?? false,
|
|
24
|
+
experimental_clientGenerateTemplateNames: conf.experimental_clientGenerateTemplateNames ?? ['ts', 'module', 'main'],
|
|
21
25
|
templates: {
|
|
22
26
|
service: 'vovk-cli/templates/service.ejs',
|
|
23
27
|
controller: 'vovk-cli/templates/controller.ejs',
|
|
24
|
-
worker: 'vovk-cli/templates/worker.ejs',
|
|
25
28
|
...conf.templates,
|
|
26
29
|
},
|
|
27
30
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
3
|
export default async function getConfigAbsolutePaths({ cwd, relativePath, }) {
|
|
4
4
|
const rootDir = path.resolve(cwd, relativePath || '');
|
|
5
5
|
const baseName = 'vovk.config';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import path from 'path';
|
|
1
|
+
import path from 'node:path';
|
|
2
2
|
import getFileSystemEntryType, { FileSystemEntryType } from '../utils/getFileSystemEntryType.mjs';
|
|
3
3
|
export default async function getRelativeSrcRoot({ cwd }) {
|
|
4
4
|
// Next.js Docs: src/app or src/pages will be ignored if app or pages are present in the root directory.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
1
2
|
import getConfigAbsolutePaths from './getConfigAbsolutePaths.mjs';
|
|
2
3
|
import importUncachedModule from './importUncachedModule.mjs';
|
|
3
4
|
async function getUserConfig({ cwd, }) {
|
|
@@ -14,7 +15,8 @@ async function getUserConfig({ cwd, }) {
|
|
|
14
15
|
catch {
|
|
15
16
|
try {
|
|
16
17
|
const cacheBuster = Date.now();
|
|
17
|
-
|
|
18
|
+
const configPathUrl = pathToFileURL(configPath).href;
|
|
19
|
+
({ default: userConfig } = (await import(`${configPathUrl}?cache=${cacheBuster}`)));
|
|
18
20
|
}
|
|
19
21
|
catch (e) {
|
|
20
22
|
return { userConfig: null, configAbsolutePaths, error: e };
|
|
@@ -3,7 +3,6 @@ import { Worker } from 'node:worker_threads';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import './importUncachedModuleWorker.mjs'; // required for TS compilation
|
|
6
|
-
// TODO comments
|
|
7
6
|
function importUncachedModule(modulePath) {
|
|
8
7
|
return new Promise((resolve, reject) => {
|
|
9
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -6,13 +6,22 @@ export default function getProjectInfo({ port: givenPort, clientOutDir, cwd, }?:
|
|
|
6
6
|
}): Promise<{
|
|
7
7
|
cwd: string;
|
|
8
8
|
port: string;
|
|
9
|
-
|
|
9
|
+
apiRoot: string;
|
|
10
10
|
apiDir: string;
|
|
11
11
|
srcRoot: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
config: import("../types.mjs").VovkStrictConfig;
|
|
13
|
+
clientImports: {
|
|
14
|
+
schema: string;
|
|
15
|
+
fetcher: string;
|
|
16
|
+
createRPC: string;
|
|
17
|
+
validateOnClient: string | null;
|
|
18
|
+
module: {
|
|
19
|
+
schema: string;
|
|
20
|
+
fetcher: string;
|
|
21
|
+
createRPC: string;
|
|
22
|
+
validateOnClient: string | null;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
16
25
|
log: {
|
|
17
26
|
info: (msg: string) => void;
|
|
18
27
|
warn: (msg: string) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import path from 'path';
|
|
1
|
+
import path from 'node:path';
|
|
2
2
|
import getConfig from './getConfig.mjs';
|
|
3
3
|
import getLogger from '../utils/getLogger.mjs';
|
|
4
4
|
export default async function getProjectInfo({ port: givenPort, clientOutDir, cwd = process.cwd(), } = {}) {
|
|
@@ -6,15 +6,10 @@ export default async function getProjectInfo({ port: givenPort, clientOutDir, cw
|
|
|
6
6
|
// Make PORT available to the config file at getConfig
|
|
7
7
|
process.env.PORT = port;
|
|
8
8
|
const { config, srcRoot, configAbsolutePaths, userConfig, error } = await getConfig({ clientOutDir, cwd });
|
|
9
|
-
const
|
|
9
|
+
const apiRoot = `${config.origin ?? ''}/${config.rootEntry}`;
|
|
10
10
|
const apiDir = path.join(srcRoot, 'app', config.rootEntry);
|
|
11
|
-
const schemaOutImportPath = path.relative(config.clientOutDir, config.schemaOutDir)
|
|
12
|
-
|
|
13
|
-
? path.relative(config.clientOutDir, config.fetcher)
|
|
14
|
-
: config.fetcher;
|
|
15
|
-
const validateOnClientImportPath = config.validateOnClient?.startsWith('.')
|
|
16
|
-
? path.relative(config.clientOutDir, config.validateOnClient)
|
|
17
|
-
: config.validateOnClient;
|
|
11
|
+
const schemaOutImportPath = path.relative(config.clientOutDir, config.schemaOutDir).replace(/\\/g, '/') + // windows fix
|
|
12
|
+
'/main.cjs';
|
|
18
13
|
const log = getLogger(config.logLevel);
|
|
19
14
|
if (configAbsolutePaths.length > 1) {
|
|
20
15
|
log.warn(`Multiple config files found. Using the first one: ${configAbsolutePaths[0]}`);
|
|
@@ -22,16 +17,29 @@ export default async function getProjectInfo({ port: givenPort, clientOutDir, cw
|
|
|
22
17
|
if (!userConfig && configAbsolutePaths.length > 0) {
|
|
23
18
|
log.error(`Error reading config file at ${configAbsolutePaths[0]}: ${error?.message ?? 'Unknown Error'}`);
|
|
24
19
|
}
|
|
20
|
+
const getImportPath = (p) => (p.startsWith('.') ? path.relative(config.clientOutDir, p) : p);
|
|
21
|
+
const clientImports = {
|
|
22
|
+
schema: schemaOutImportPath,
|
|
23
|
+
fetcher: getImportPath(config.fetcherImport[0]),
|
|
24
|
+
createRPC: getImportPath(config.createRPCImport[0]),
|
|
25
|
+
validateOnClient: config.validateOnClientImport ? getImportPath(config.validateOnClientImport[0]) : null,
|
|
26
|
+
module: {
|
|
27
|
+
schema: schemaOutImportPath,
|
|
28
|
+
fetcher: getImportPath(config.fetcherImport[1] ?? config.fetcherImport[0]),
|
|
29
|
+
createRPC: getImportPath(config.createRPCImport[1] ?? config.createRPCImport[0]),
|
|
30
|
+
validateOnClient: config.validateOnClientImport
|
|
31
|
+
? getImportPath(config.validateOnClientImport[1] ?? config.validateOnClientImport[0])
|
|
32
|
+
: null,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
25
35
|
return {
|
|
26
36
|
cwd,
|
|
27
37
|
port,
|
|
28
|
-
|
|
38
|
+
apiRoot,
|
|
29
39
|
apiDir,
|
|
30
40
|
srcRoot,
|
|
31
|
-
schemaOutImportPath,
|
|
32
|
-
fetcherClientImportPath,
|
|
33
|
-
validateOnClientImportPath,
|
|
34
41
|
config,
|
|
42
|
+
clientImports,
|
|
35
43
|
log,
|
|
36
44
|
};
|
|
37
45
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,30 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
import type { LogLevelNames } from 'loglevel';
|
|
4
|
-
import type { VovkConfig, VovkEnv } from './types.mjs';
|
|
5
2
|
import 'dotenv/config';
|
|
3
|
+
import type { VovkConfig, VovkEnv } from './types.mjs';
|
|
6
4
|
export type { VovkConfig, VovkEnv };
|
|
7
|
-
export interface InitOptions {
|
|
8
|
-
yes?: boolean;
|
|
9
|
-
logLevel: LogLevelNames;
|
|
10
|
-
useNpm?: boolean;
|
|
11
|
-
useYarn?: boolean;
|
|
12
|
-
usePnpm?: boolean;
|
|
13
|
-
useBun?: boolean;
|
|
14
|
-
skipInstall?: boolean;
|
|
15
|
-
updateTsConfig?: boolean;
|
|
16
|
-
updateScripts?: 'implicit' | 'explicit';
|
|
17
|
-
validationLibrary?: string | null;
|
|
18
|
-
validateOnClient?: boolean;
|
|
19
|
-
dryRun?: boolean;
|
|
20
|
-
channel?: 'latest' | 'beta' | 'dev';
|
|
21
|
-
}
|
|
22
|
-
export interface NewOptions {
|
|
23
|
-
dryRun?: boolean;
|
|
24
|
-
template?: string;
|
|
25
|
-
dirName?: string;
|
|
26
|
-
overwrite?: boolean;
|
|
27
|
-
noSegmentUpdate?: boolean;
|
|
28
|
-
}
|
|
29
|
-
declare const program: Command;
|
|
30
|
-
export declare function initProgram(p: typeof program, command: string): Command;
|
package/dist/index.mjs
CHANGED
|
@@ -1,51 +1,62 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import path from 'path';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import 'dotenv/config';
|
|
3
6
|
import { Command } from 'commander';
|
|
4
|
-
import { readFileSync } from 'fs';
|
|
5
7
|
import concurrently from 'concurrently';
|
|
6
8
|
import getAvailablePort from './utils/getAvailablePort.mjs';
|
|
7
9
|
import getProjectInfo from './getProjectInfo/index.mjs';
|
|
8
|
-
import
|
|
10
|
+
import generate from './generate/index.mjs';
|
|
9
11
|
import locateSegments from './locateSegments.mjs';
|
|
10
|
-
import {
|
|
11
|
-
import { Init } from './init/index.mjs';
|
|
12
|
+
import { VovkDev } from './dev/index.mjs';
|
|
12
13
|
import newComponents from './new/index.mjs';
|
|
13
|
-
import '
|
|
14
|
+
import initProgram from './initProgram.mjs';
|
|
14
15
|
const program = new Command();
|
|
15
16
|
const packageJSON = JSON.parse(readFileSync(path.join(import.meta.dirname, '../package.json'), 'utf-8'));
|
|
16
17
|
program.name('vovk').description('Vovk CLI').version(packageJSON.version);
|
|
18
|
+
initProgram(program.command('init'));
|
|
17
19
|
program
|
|
18
20
|
.command('dev')
|
|
19
|
-
.
|
|
20
|
-
.
|
|
21
|
-
.
|
|
22
|
-
.
|
|
23
|
-
.
|
|
21
|
+
.alias('d')
|
|
22
|
+
.description('start schema watcher (optional flag --next-dev to start it with Next.js)')
|
|
23
|
+
.argument('[nextArgs...]', 'extra arguments for the dev command')
|
|
24
|
+
.option('--next-dev', 'start schema watcher and Next.js with automatic port allocation')
|
|
25
|
+
.option('--exit', 'kill the processe when schema and client is generated')
|
|
26
|
+
.action(async (nextArgs, options) => {
|
|
27
|
+
const { nextDev, exit = false } = options;
|
|
24
28
|
const portAttempts = 30;
|
|
25
|
-
const PORT = !
|
|
29
|
+
const PORT = !nextDev
|
|
26
30
|
? process.env.PORT
|
|
27
31
|
: process.env.PORT ||
|
|
28
|
-
(await getAvailablePort(3000, portAttempts, 0, (failedPort, tryingPort) =>
|
|
29
|
-
|
|
32
|
+
(await getAvailablePort(3000, portAttempts, 0, (failedPort, tryingPort) =>
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.warn(`🐺 Port ${failedPort} is in use, trying ${tryingPort} instead.`)).catch(() => {
|
|
35
|
+
throw new Error(`🐺 ❌ Failed to find an available port after ${portAttempts} attempts`);
|
|
30
36
|
}));
|
|
31
37
|
if (!PORT) {
|
|
32
38
|
throw new Error('🐺 ❌ PORT env variable is required');
|
|
33
39
|
}
|
|
34
|
-
if (
|
|
40
|
+
if (nextDev) {
|
|
35
41
|
const { result } = concurrently([
|
|
36
42
|
{
|
|
37
|
-
command: `
|
|
38
|
-
name: 'Vovk.ts Schema Watcher',
|
|
39
|
-
env: Object.assign({ PORT, __VOVK_START_WATCHER_IN_STANDALONE_MODE__: 'true' }, options.clientOut ? { VOVK_CLIENT_OUT_DIR: options.clientOut } : {}),
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
command: `npx next dev ${command.args.join(' ')}`,
|
|
43
|
+
command: `npx next dev ${nextArgs.join(' ')}`,
|
|
43
44
|
name: 'Next.js Development Server',
|
|
44
45
|
env: { PORT },
|
|
45
46
|
},
|
|
47
|
+
{
|
|
48
|
+
command: `node ${import.meta.dirname}/dev/index.mjs`,
|
|
49
|
+
name: 'Vovk Dev Watcher',
|
|
50
|
+
env: {
|
|
51
|
+
PORT,
|
|
52
|
+
__VOVK_START_WATCHER_IN_STANDALONE_MODE__: 'true',
|
|
53
|
+
__VOVK_EXIT__: exit ? 'true' : 'false',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
46
56
|
], {
|
|
47
57
|
killOthers: ['failure', 'success'],
|
|
48
58
|
prefix: 'none',
|
|
59
|
+
successCondition: 'first',
|
|
49
60
|
});
|
|
50
61
|
try {
|
|
51
62
|
await result;
|
|
@@ -55,65 +66,49 @@ program
|
|
|
55
66
|
}
|
|
56
67
|
}
|
|
57
68
|
else {
|
|
58
|
-
void new
|
|
69
|
+
void new VovkDev().start({ exit });
|
|
59
70
|
}
|
|
60
71
|
});
|
|
61
72
|
program
|
|
62
73
|
.command('generate')
|
|
63
|
-
.
|
|
64
|
-
.
|
|
74
|
+
.alias('g')
|
|
75
|
+
.description('Generate RPC client from schema')
|
|
76
|
+
.option('--out, --client-out-dir <path>', 'path to output directory')
|
|
77
|
+
.option('--template, --templates <templates...>', 'client code templates ("ts", "compiled", "python", "none", a custom path)')
|
|
78
|
+
.option('--full-schema [fileName]', 'generate client with full schema')
|
|
79
|
+
.option('--prettify', 'prettify output files')
|
|
65
80
|
.action(async (options) => {
|
|
66
|
-
const
|
|
81
|
+
const { clientOutDir, templates, prettify, fullSchema } = options;
|
|
82
|
+
const projectInfo = await getProjectInfo({ clientOutDir });
|
|
67
83
|
const { cwd, config, apiDir } = projectInfo;
|
|
68
|
-
const segments = await locateSegments(apiDir);
|
|
84
|
+
const segments = await locateSegments({ dir: apiDir, config });
|
|
69
85
|
const schemaOutAbsolutePath = path.join(cwd, config.schemaOutDir);
|
|
70
|
-
const
|
|
71
|
-
await
|
|
86
|
+
const schemaImportUrl = pathToFileURL(path.join(schemaOutAbsolutePath, 'main.cjs')).href;
|
|
87
|
+
const { default: segmentsSchema } = (await import(schemaImportUrl));
|
|
88
|
+
await generate({
|
|
89
|
+
projectInfo,
|
|
90
|
+
segments,
|
|
91
|
+
segmentsSchema,
|
|
92
|
+
templates,
|
|
93
|
+
prettify,
|
|
94
|
+
fullSchema,
|
|
95
|
+
forceNothingWrittenLog: true,
|
|
96
|
+
});
|
|
72
97
|
});
|
|
73
|
-
// reused at vovk-init
|
|
74
|
-
export function initProgram(p, command) {
|
|
75
|
-
return p
|
|
76
|
-
.command(command + '[prefix]')
|
|
77
|
-
.description('Initialize Vovk project')
|
|
78
|
-
.option('-Y, --yes', 'Skip all prompts and use default values')
|
|
79
|
-
.option('--log-level <level>', 'Set log level', 'info')
|
|
80
|
-
.option('--use-npm', 'Use npm as package manager')
|
|
81
|
-
.option('--use-yarn', 'Use yarn as package manager')
|
|
82
|
-
.option('--use-pnpm', 'Use pnpm as package manager')
|
|
83
|
-
.option('--use-bun', 'Use bun as package manager')
|
|
84
|
-
.option('--skip-install', 'Skip installing dependencies')
|
|
85
|
-
.option('--update-ts-config', 'Update tsconfig.json')
|
|
86
|
-
.option('--update-scripts <mode>', 'Update package.json scripts (implicit or explicit)')
|
|
87
|
-
.option('--validation-library <library>', 'Validation library to use ("vovk-zod", "vovk-yup", "vovk-dto" or another). Set to "none" to skip validation')
|
|
88
|
-
.option('--validate-on-client', 'Validate on client')
|
|
89
|
-
.option('--channel <channel>', 'Channel to use for fetching packages', 'latest')
|
|
90
|
-
.option('--dry-run', 'Do not write files to disk')
|
|
91
|
-
.action((prefix = '.', options) => new Init().main(prefix, options));
|
|
92
|
-
}
|
|
93
|
-
initProgram(program, 'init ');
|
|
94
98
|
program
|
|
95
99
|
.command('new [components...]')
|
|
96
100
|
.alias('n')
|
|
97
|
-
.description('
|
|
98
|
-
.option('-
|
|
99
|
-
.option('--template', '
|
|
100
|
-
.option('--dir
|
|
101
|
-
.option('--no-segment-update', '
|
|
102
|
-
.option('--dry-run', '
|
|
101
|
+
.description('create new components. "vovk new [...components] [segmentName/]moduleName" to create a new module or "vovk new segment [segmentName]" to create a new segment')
|
|
102
|
+
.option('-o, --overwrite', 'overwrite existing files')
|
|
103
|
+
.option('--template, --templates <templates...>', 'override config template; accepts an array of strings that correspond the order of the components')
|
|
104
|
+
.option('--dir <dirname>', 'override dirName in template file; relative to the root of the project')
|
|
105
|
+
.option('--no-segment-update', 'do not update segment files when creating a new module')
|
|
106
|
+
.option('--dry-run', 'do not write files to disk')
|
|
103
107
|
.action((components, options) => newComponents(components, options));
|
|
104
108
|
program
|
|
105
109
|
.command('help')
|
|
106
110
|
.description('Show help message')
|
|
107
111
|
.action(() => program.help());
|
|
108
|
-
/*
|
|
109
|
-
TODO
|
|
110
|
-
vovk new segment [segmentName]
|
|
111
|
-
vovk new controller service [segmentName/]moduleName
|
|
112
|
-
vovk new c s w [segmentName/]moduleName
|
|
113
|
-
|
|
114
|
-
vovk c s w userApi/user
|
|
115
|
-
vovk new c s w user
|
|
116
|
-
*/
|
|
117
112
|
program.parse(process.argv);
|
|
118
113
|
if (!process.argv.slice(2).length) {
|
|
119
114
|
program.outputHelp();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs/promises';
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
3
|
import * as jsonc from 'jsonc-parser';
|
|
4
4
|
export default async function checkTSConfigForExperimentalDecorators(root) {
|
|
5
5
|
const tsconfigPath = path.resolve(root, 'tsconfig.json');
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type getLogger from '../utils/getLogger.mjs';
|
|
2
|
-
import type { InitOptions } from '../
|
|
3
|
-
export default function createConfig({ root, log,
|
|
2
|
+
import type { InitOptions } from '../types.mjs';
|
|
3
|
+
export default function createConfig({ root, log, options: { validationLibrary, validateOnClient, reactQuery, channel, dryRun }, }: {
|
|
4
4
|
root: string;
|
|
5
5
|
log: ReturnType<typeof getLogger>;
|
|
6
|
-
dryRun
|
|
7
|
-
options: Pick<InitOptions, 'validationLibrary' | 'validateOnClient'>;
|
|
6
|
+
options: Pick<InitOptions, 'validationLibrary' | 'validateOnClient' | 'reactQuery' | 'channel' | 'dryRun'>;
|
|
8
7
|
}): Promise<{
|
|
9
8
|
configAbsolutePath: string;
|
|
10
9
|
}>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs/promises';
|
|
3
|
-
import getFileSystemEntryType, { FileSystemEntryType } from '../utils/getFileSystemEntryType.mjs';
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
4
3
|
import getTemplateFilesFromPackage from './getTemplateFilesFromPackage.mjs';
|
|
5
4
|
import prettify from '../utils/prettify.mjs';
|
|
6
|
-
|
|
5
|
+
import getFileSystemEntryType, { FileSystemEntryType } from '../utils/getFileSystemEntryType.mjs';
|
|
6
|
+
export default async function createConfig({ root, log, options: { validationLibrary, validateOnClient, reactQuery, channel, dryRun }, }) {
|
|
7
7
|
const config = {};
|
|
8
8
|
const dotConfigPath = path.join(root, '.config');
|
|
9
9
|
const dir = (await getFileSystemEntryType(dotConfigPath)) === FileSystemEntryType.DIRECTORY ? dotConfigPath : root;
|
|
@@ -14,21 +14,22 @@ export default async function createConfig({ root, log, dryRun, options: { valid
|
|
|
14
14
|
const templates = {
|
|
15
15
|
controller: 'vovk-cli/templates/controller.ejs',
|
|
16
16
|
service: 'vovk-cli/templates/service.ejs',
|
|
17
|
-
worker: 'vovk-cli/templates/worker.ejs',
|
|
18
17
|
};
|
|
19
18
|
if (validationLibrary) {
|
|
20
|
-
config.validationLibrary = validationLibrary;
|
|
21
19
|
if (validateOnClient) {
|
|
22
|
-
config.
|
|
20
|
+
config.validateOnClientImport = `${validationLibrary}/validateOnClient.js`;
|
|
23
21
|
}
|
|
24
22
|
try {
|
|
25
|
-
const validationTemplates = await getTemplateFilesFromPackage(validationLibrary);
|
|
23
|
+
const validationTemplates = await getTemplateFilesFromPackage(validationLibrary, channel);
|
|
26
24
|
Object.assign(templates, validationTemplates);
|
|
27
25
|
}
|
|
28
26
|
catch (error) {
|
|
29
27
|
log.warn(`Failed to fetch validation library templates: ${error.message}`);
|
|
30
28
|
}
|
|
31
29
|
}
|
|
30
|
+
if (reactQuery) {
|
|
31
|
+
config.createRPCImport = 'vovk-react-query';
|
|
32
|
+
}
|
|
32
33
|
config.templates = templates;
|
|
33
34
|
const configStr = await prettify(`/** @type {import('vovk-cli').VovkConfig} */
|
|
34
35
|
const config = ${JSON.stringify(config, null, 2)};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { InitOptions } from '../types.mjs';
|
|
1
2
|
/**
|
|
2
3
|
* Retrieves a list of files in the 'templates' folder of an NPM package.
|
|
3
4
|
* @param packageName - The name of the NPM package.
|
|
4
5
|
* @returns A promise that resolves to an array of file paths.
|
|
5
6
|
*/
|
|
6
|
-
export default function
|
|
7
|
+
export default function getTemplateFilesFromPackage(packageName: string, channel?: InitOptions['channel']): Promise<Record<string, string>>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { createGunzip } from 'node:zlib';
|
|
2
3
|
import tar from 'tar-stream';
|
|
3
|
-
import { Readable } from 'stream';
|
|
4
4
|
import getNPMPackageMetadata from '../utils/getNPMPackageMetadata.mjs';
|
|
5
|
+
// Crereated with AI
|
|
5
6
|
/**
|
|
6
7
|
* Retrieves a list of files in the 'templates' folder of an NPM package.
|
|
7
8
|
* @param packageName - The name of the NPM package.
|
|
8
9
|
* @returns A promise that resolves to an array of file paths.
|
|
9
10
|
*/
|
|
10
|
-
export default async function
|
|
11
|
-
) {
|
|
11
|
+
export default async function getTemplateFilesFromPackage(packageName, channel = 'latest') {
|
|
12
12
|
const metadata = await getNPMPackageMetadata(packageName);
|
|
13
13
|
const latestVersion = metadata['dist-tags'][channel];
|
|
14
14
|
const tarballUrl = metadata.versions[latestVersion].dist.tarball;
|
|
@@ -37,7 +37,6 @@ function extractTemplatesFromTarball(tarballBuffer) {
|
|
|
37
37
|
const files = [];
|
|
38
38
|
extract.on('entry', (header, stream, next) => {
|
|
39
39
|
const filePath = header.name;
|
|
40
|
-
// TODO revisit comments
|
|
41
40
|
// Check if the file is in the 'templates' folder
|
|
42
41
|
if (filePath.startsWith('package/templates/')) {
|
|
43
42
|
files.push(filePath.replace('package/', ''));
|
package/dist/init/index.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import type { InitOptions } from '../index.mjs';
|
|
1
|
+
import type { InitOptions } from '../types.mjs';
|
|
3
2
|
import getLogger from '../utils/getLogger.mjs';
|
|
4
3
|
export declare class Init {
|
|
5
4
|
#private;
|
|
6
5
|
root: string;
|
|
7
6
|
log: ReturnType<typeof getLogger>;
|
|
8
|
-
main(prefix: string, { yes, logLevel, useNpm, useYarn, usePnpm, useBun, skipInstall, updateTsConfig, updateScripts, validationLibrary, validateOnClient, dryRun, channel, }: InitOptions): Promise<void>;
|
|
7
|
+
main(prefix: string, { yes, logLevel, useNpm, useYarn, usePnpm, useBun, skipInstall, updateTsConfig, updateScripts, validationLibrary, validateOnClient, reactQuery, dryRun, channel, }: InitOptions): Promise<void>;
|
|
9
8
|
}
|