vovk-cli 0.0.1-draft.14 → 0.0.1-draft.16

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.
@@ -1,4 +1,4 @@
1
- export declare class VovkCLIWatcher {
1
+ export declare class VovkDev {
2
2
  #private;
3
3
  start({ clientOutDir }?: {
4
4
  clientOutDir?: string;
@@ -15,7 +15,7 @@ import generateClient from '../generateClient.mjs';
15
15
  import locateSegments from '../locateSegments.mjs';
16
16
  import debounceWithArgs from '../utils/debounceWithArgs.mjs';
17
17
  import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
18
- export class VovkCLIWatcher {
18
+ export class VovkDev {
19
19
  #projectInfo;
20
20
  #segments = [];
21
21
  #schemas = {};
@@ -289,5 +289,5 @@ export class VovkCLIWatcher {
289
289
  }
290
290
  const env = process.env;
291
291
  if (env.__VOVK_START_WATCHER_IN_STANDALONE_MODE__ === 'true') {
292
- void new VovkCLIWatcher().start();
292
+ void new VovkDev().start();
293
293
  }
@@ -48,11 +48,11 @@ type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
48
48
  ts += `
49
49
  ${validateOnClientImportPath ? `import validateOnClient from '${validateOnClientImportPath}';\n` : '\nconst validateOnClient = undefined;'}
50
50
  type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
51
- const prefix = '${apiEntryPoint}';
51
+ const apiRoot = '${apiEntryPoint}';
52
52
  `;
53
53
  js += `
54
54
  const { default: validateOnClient = null } = ${validateOnClientImportPath ? `require('${validateOnClientImportPath}')` : '{}'};
55
- const prefix = '${apiEntryPoint}';
55
+ const apiRoot = '${apiEntryPoint}';
56
56
  `;
57
57
  for (let i = 0; i < segments.length; i++) {
58
58
  const { segmentName } = segments[i];
@@ -64,8 +64,8 @@ const prefix = '${apiEntryPoint}';
64
64
  continue;
65
65
  for (const key of Object.keys(schema.controllers)) {
66
66
  dts += `export const ${key}: ReturnType<typeof clientizeController<Controllers${i}["${key}"], Options>>;\n`;
67
- js += `exports.${key} = clientizeController(schema['${segmentName}'].controllers.${key}, '${segmentName}', { fetcher, validateOnClient, defaultOptions: { prefix } });\n`;
68
- ts += `export const ${key} = clientizeController<Controllers${i}["${key}"], Options>(schema['${segmentName}'].controllers.${key}, '${segmentName}', { fetcher, validateOnClient, defaultOptions: { prefix } });\n`;
67
+ js += `exports.${key} = clientizeController(schema['${segmentName}'].controllers.${key}, '${segmentName}', { fetcher, validateOnClient, defaultOptions: { apiRoot } });\n`;
68
+ ts += `export const ${key} = clientizeController<Controllers${i}["${key}"], Options>(schema['${segmentName}'].controllers.${key}, '${segmentName}', { fetcher, validateOnClient, defaultOptions: { apiRoot } });\n`;
69
69
  }
70
70
  for (const key of Object.keys(schema.workers)) {
71
71
  dts += `export const ${key}: ReturnType<typeof promisifyWorker<Workers${i}["${key}"]>>;\n`;
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
- import type { VovkConfig, VovkEnv } from './types.mjs';
3
+ import type { VovkConfig, VovkDevEnv } from './types.mjs';
4
4
  import 'dotenv/config';
5
- export type { VovkConfig, VovkEnv };
5
+ export type { VovkConfig, VovkDevEnv };
6
6
  declare const program: Command;
7
7
  export declare function initProgram(p: typeof program, command: string): Command;
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import getAvailablePort from './utils/getAvailablePort.mjs';
7
7
  import getProjectInfo from './getProjectInfo/index.mjs';
8
8
  import generateClient from './generateClient.mjs';
9
9
  import locateSegments from './locateSegments.mjs';
10
- import { VovkCLIWatcher } from './watcher/index.mjs';
10
+ import { VovkDev } from './dev/index.mjs';
11
11
  import { Init } from './init/index.mjs';
12
12
  import newComponents from './new/index.mjs';
13
13
  import 'dotenv/config';
@@ -33,12 +33,11 @@ program
33
33
  if (!PORT) {
34
34
  throw new Error('🐺 ❌ PORT env variable is required');
35
35
  }
36
- console.log(`TODO:`, command.args);
37
36
  if (options.nextDev) {
38
37
  const { result } = concurrently([
39
38
  {
40
- command: `node ${import.meta.dirname}/watcher/index.mjs`,
41
- name: 'Vovk.ts Schema Watcher',
39
+ command: `node ${import.meta.dirname}/dev/index.mjs`,
40
+ name: 'Vovk Dev Command',
42
41
  env: Object.assign({ PORT, __VOVK_START_WATCHER_IN_STANDALONE_MODE__: 'true' }, options.clientOut ? { VOVK_CLIENT_OUT_DIR: options.clientOut } : {}),
43
42
  },
44
43
  {
@@ -58,7 +57,7 @@ program
58
57
  }
59
58
  }
60
59
  else {
61
- void new VovkCLIWatcher().start({ clientOutDir: options.clientOut });
60
+ void new VovkDev().start({ clientOutDir: options.clientOut });
62
61
  }
63
62
  });
64
63
  program
@@ -108,15 +107,6 @@ program
108
107
  .command('help')
109
108
  .description('Show help message')
110
109
  .action(() => program.help());
111
- /*
112
- TODO
113
- vovk new segment [segmentName]
114
- vovk new controller service [segmentName/]moduleName
115
- vovk new c s w [segmentName/]moduleName
116
-
117
- vovk c s w userApi/user
118
- vovk new c s w user
119
- */
120
110
  program.parse(process.argv);
121
111
  if (!process.argv.slice(2).length) {
122
112
  program.outputHelp();
@@ -1,10 +1,9 @@
1
1
  import type getLogger from '../utils/getLogger.mjs';
2
2
  import type { InitOptions } from '../types.mjs';
3
- export default function createConfig({ root, log, dryRun, options: { validationLibrary, validateOnClient }, }: {
3
+ export default function createConfig({ root, log, options: { validationLibrary, validateOnClient, channel, dryRun }, }: {
4
4
  root: string;
5
5
  log: ReturnType<typeof getLogger>;
6
- dryRun?: boolean;
7
- options: Pick<InitOptions, 'validationLibrary' | 'validateOnClient'>;
6
+ options: Pick<InitOptions, 'validationLibrary' | 'validateOnClient' | 'channel' | 'dryRun'>;
8
7
  }): Promise<{
9
8
  configAbsolutePath: string;
10
9
  }>;
@@ -3,7 +3,7 @@ import fs from 'node:fs/promises';
3
3
  import getTemplateFilesFromPackage from './getTemplateFilesFromPackage.mjs';
4
4
  import prettify from '../utils/prettify.mjs';
5
5
  import getFileSystemEntryType, { FileSystemEntryType } from '../utils/getFileSystemEntryType.mjs';
6
- export default async function createConfig({ root, log, dryRun, options: { validationLibrary, validateOnClient }, }) {
6
+ export default async function createConfig({ root, log, options: { validationLibrary, validateOnClient, 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;
@@ -22,7 +22,7 @@ export default async function createConfig({ root, log, dryRun, options: { valid
22
22
  config.validateOnClient = `${validationLibrary}/validateOnClient`;
23
23
  }
24
24
  try {
25
- const validationTemplates = await getTemplateFilesFromPackage(validationLibrary);
25
+ const validationTemplates = await getTemplateFilesFromPackage(validationLibrary, channel);
26
26
  Object.assign(templates, validationTemplates);
27
27
  }
28
28
  catch (error) {
@@ -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 getTemplatesFiles(packageName: string, channel?: string): Promise<Record<string, string>>;
7
+ export default function getTemplateFilesFromPackage(packageName: string, channel?: InitOptions['channel']): Promise<Record<string, string>>;
@@ -7,8 +7,7 @@ import getNPMPackageMetadata from '../utils/getNPMPackageMetadata.mjs';
7
7
  * @param packageName - The name of the NPM package.
8
8
  * @returns A promise that resolves to an array of file paths.
9
9
  */
10
- export default async function getTemplatesFiles(packageName, channel = 'beta' // TODO change to latest
11
- ) {
10
+ export default async function getTemplateFilesFromPackage(packageName, channel = 'latest') {
12
11
  const metadata = await getNPMPackageMetadata(packageName);
13
12
  const latestVersion = metadata['dist-tags'][channel];
14
13
  const tarballUrl = metadata.versions[latestVersion].dist.tarball;
@@ -101,8 +101,7 @@ export class Init {
101
101
  const { configAbsolutePath } = await createConfig({
102
102
  root,
103
103
  log,
104
- options: { validationLibrary, validateOnClient },
105
- dryRun,
104
+ options: { validationLibrary, validateOnClient, channel, dryRun },
106
105
  });
107
106
  log.info('Config created successfully at ' + configAbsolutePath);
108
107
  }
@@ -180,23 +179,23 @@ export class Init {
180
179
  updateScripts =
181
180
  updateScripts ??
182
181
  (await select({
183
- message: 'Do you want to update package.json by adding "generate" and "dev" scripts?',
182
+ message: 'Do you want to update package.json by adding "generate" and "dev" NPM scripts?',
184
183
  default: 'implicit',
185
184
  choices: [
186
185
  {
187
186
  name: 'Yes, use "concurrently" implicitly',
188
- description: `The "dev" script will use "concurrently" API internally in order to run "next dev" and "vovk dev" together and automatically look for an available port ${chalk.whiteBright.bold(`"vovk dev --next-dev"`)}`,
189
187
  value: 'implicit',
188
+ description: `The "dev" script will use "concurrently" API to run "next dev" and "vovk dev" commands together and automatically find an available port ${chalk.whiteBright.bold(`"vovk dev --next-dev"`)}`,
190
189
  },
191
190
  {
192
191
  name: 'Yes, use "concurrently" explicitly',
193
192
  value: 'explicit',
194
- description: `The "dev" script will use pre-defined PORT variable and run "next dev" and "vovk dev" as "concurrently" CLI arguments ${chalk.whiteBright.bold(`"PORT=3000 concurrently 'vovk dev' 'next dev' --kill-others"`)}`,
193
+ description: `The "dev" script will use pre-defined PORT variable and run "next dev" and "vovk dev" as "concurrently" CLI arguments ${chalk.whiteBright.bold(`"PORT=3000 concurrently 'next dev' 'vovk dev' --kill-others"`)}`,
195
194
  },
196
195
  {
197
196
  name: 'No',
198
197
  value: undefined,
199
- description: 'Add the scripts manually',
198
+ description: 'Add the NPM scripts manually',
200
199
  },
201
200
  ],
202
201
  }));
@@ -5,7 +5,7 @@ export default async function updateNPMScripts(root, updateScriptsMode) {
5
5
  scripts: {
6
6
  generate: 'vovk generate',
7
7
  dev: updateScriptsMode === 'explicit'
8
- ? "PORT=3000 concurrently 'vovk dev' 'next dev' --kill-others"
8
+ ? "PORT=3000 concurrently 'next dev' 'vovk dev' --kill-others"
9
9
  : 'vovk dev --next-dev',
10
10
  },
11
11
  });
@@ -60,7 +60,7 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
60
60
  ? path.resolve(cwd, templatePath)
61
61
  : path.resolve(cwd, './node_modules', templatePath);
62
62
  const templateCode = await fs.readFile(templateAbsolutePath, 'utf-8');
63
- const { dirName: renderedDirName, fileName, sourceName, compiledName, code, } = await render(templateCode, {
63
+ const { dir: renderedDirName, fileName, sourceName, compiledName, code, } = await render(templateCode, {
64
64
  cwd,
65
65
  config,
66
66
  withService: what.includes('service'),
@@ -20,14 +20,11 @@ export default async function render(codeTemplate, { config, withService, segmen
20
20
  _, // lodash
21
21
  pluralize,
22
22
  };
23
- // first, render the front matter because it can use ejs variables
24
23
  const parsed = matter((await ejs.render(codeTemplate, templateVars, { async: true })).trim());
25
- const { dirName, fileName, sourceName, compiledName } = parsed.data;
24
+ const { dir, fileName, sourceName, compiledName } = parsed.data;
26
25
  const code = parsed.content;
27
- // const templateContent = parsed.content; TODO
28
- // const code = await ejs.render(templateContent, templateVars, { async: true });
29
26
  return {
30
- dirName,
27
+ dir,
31
28
  fileName,
32
29
  sourceName,
33
30
  compiledName,
package/dist/types.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { LogLevelNames } from 'loglevel';
2
2
  export type KnownAny = any;
3
- export type VovkEnv = {
3
+ export type VovkDevEnv = {
4
4
  PORT?: string;
5
5
  VOVK_CLIENT_OUT_DIR?: string;
6
6
  VOVK_SCHEMA_OUT_DIR?: string;
@@ -39,7 +39,7 @@ export type VovkConfig = {
39
39
  };
40
40
  export type VovkModuleRenderResult = {
41
41
  fileName: string;
42
- dirName: string;
42
+ dir: string;
43
43
  sourceName?: string;
44
44
  compiledName?: string;
45
45
  code: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk-cli",
3
- "version": "0.0.1-draft.14",
3
+ "version": "0.0.1-draft.16",
4
4
  "bin": {
5
5
  "vovk": "./dist/index.mjs"
6
6
  },
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "homepage": "https://vovk.dev",
37
37
  "peerDependencies": {
38
- "vovk": "^3.0.0-draft.14"
38
+ "vovk": "^3.0.0-draft.19"
39
39
  },
40
40
  "dependencies": {
41
41
  "@inquirer/prompts": "^7.0.1",
@@ -4,7 +4,7 @@
4
4
  <% var compiledName = modulePascalName + 'RPC'; %>
5
5
  <% var serviceName = modulePascalName + 'Service'; %>
6
6
  ---
7
- dirName: <%= getModuleDirName(segmentName, moduleName) %>
7
+ dir: <%= getModuleDirName(segmentName, moduleName) %>
8
8
  fileName: <%= controllerName + '.ts' %>
9
9
  sourceName: <%= controllerName %>
10
10
  compiledName: <%= compiledName %>
@@ -3,7 +3,7 @@
3
3
  <% var serviceName = modulePascalName + 'Service'; %>
4
4
  <% var controllerName = modulePascalName + 'Controller'; %>
5
5
  ---
6
- dirName: <%= getModuleDirName(segmentName, moduleName) %>
6
+ dir: <%= getModuleDirName(segmentName, moduleName) %>
7
7
  fileName: <%= serviceName + '.ts' %>
8
8
  ---
9
9
 
@@ -3,7 +3,7 @@
3
3
  <% var workerName = modulePascalName + 'Worker'; %>
4
4
  <% var compiledName = modulePascalName + 'WPC'; %>
5
5
  ---
6
- dirName: <%= getModuleDirName(segmentName, moduleName) %>
6
+ dir: <%= getModuleDirName(segmentName, moduleName) %>
7
7
  fileName: <%= workerName + '.ts' %>
8
8
  sourceName: <%= workerName %>
9
9
  compiledName: <%= compiledName %>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes