vovk-cli 0.0.1-draft.116 → 0.0.1-draft.118

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,5 +1,5 @@
1
1
  import fs from 'node:fs/promises';
2
- import getClientTemplates from './getClientTemplates.mjs';
2
+ import getClientTemplates, { BuiltInTemplateName } from './getClientTemplates.mjs';
3
3
  import uniq from 'lodash/uniq.js';
4
4
  import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
5
5
  import path from 'node:path';
@@ -11,14 +11,24 @@ export default async function ensureClient({ config, cwd, log }) {
11
11
  generateFrom: config.generateFrom,
12
12
  });
13
13
  let usedTemplateNames = [];
14
- const text = `// auto-generated ${new Date().toISOString()}
14
+ const defaultText = `// auto-generated ${new Date().toISOString()}
15
15
  // This is a temporary placeholder to avoid compilation errors if client is imported before it's generated.
16
16
  // If you still see this text, the client is not generated yet because of an unknown problem.
17
17
  // Feel free to report an issue at https://github.com/finom/vovk/issues`;
18
18
  for (const { outPath, templateName } of templateFiles) {
19
19
  const existing = await fs.readFile(outPath, 'utf-8').catch(() => null);
20
+ let text = defaultText;
20
21
  if (!existing) {
21
22
  await fs.mkdir(path.dirname(outPath), { recursive: true });
23
+ // a workaround that prevents compilation error when client is not yet generated but back-end imports fullSchema
24
+ if (Object.keys(BuiltInTemplateName).includes(templateName)) {
25
+ if (outPath.endsWith('.cjs')) {
26
+ text += '\nmodule.exports.fullSchema = {};';
27
+ }
28
+ else {
29
+ text += '\nexport const fullSchema = {};';
30
+ }
31
+ }
22
32
  await fs.writeFile(outPath, outPath.endsWith('.py') ? text.replace(/\/\//g, '#') : text);
23
33
  usedTemplateNames.push(templateName);
24
34
  }
@@ -7,6 +7,12 @@ interface ClientTemplate {
7
7
  fullSchemaOutAbsolutePath: string | null;
8
8
  origin?: string | null;
9
9
  }
10
+ export declare enum BuiltInTemplateName {
11
+ ts = "ts",
12
+ main = "main",
13
+ module = "module",
14
+ fullSchema = "fullSchema"
15
+ }
10
16
  export default function getClientTemplates({ config, cwd, generateFrom, }: {
11
17
  config: VovkStrictConfig;
12
18
  cwd: string;
@@ -2,33 +2,40 @@ import path from 'node:path';
2
2
  import { glob } from 'node:fs/promises';
3
3
  import resolveAbsoluteModulePath from '../utils/resolveAbsoluteModulePath.mjs';
4
4
  export const DEFAULT_FULL_SCHEMA_FILE_NAME = 'full-schema.json';
5
+ export var BuiltInTemplateName;
6
+ (function (BuiltInTemplateName) {
7
+ BuiltInTemplateName["ts"] = "ts";
8
+ BuiltInTemplateName["main"] = "main";
9
+ BuiltInTemplateName["module"] = "module";
10
+ BuiltInTemplateName["fullSchema"] = "fullSchema";
11
+ })(BuiltInTemplateName || (BuiltInTemplateName = {}));
5
12
  export default async function getClientTemplates({ config, cwd, generateFrom = [], }) {
6
13
  const templatesDir = path.join(import.meta.dirname, '../..', 'client-templates');
7
14
  const clientOutDirAbsolutePath = path.resolve(cwd, config.clientOutDir);
8
15
  const builtIn = {
9
16
  ts: {
10
- templateName: 'ts',
17
+ templateName: BuiltInTemplateName.ts,
11
18
  templatePath: path.resolve(templatesDir, 'ts/*'),
12
19
  outDir: clientOutDirAbsolutePath,
13
20
  fullSchema: false,
14
21
  origin: null,
15
22
  },
16
23
  main: {
17
- templateName: 'main',
24
+ templateName: BuiltInTemplateName.main,
18
25
  templatePath: path.resolve(templatesDir, 'main/*'),
19
26
  outDir: clientOutDirAbsolutePath,
20
27
  fullSchema: false,
21
28
  origin: null,
22
29
  },
23
30
  module: {
24
- templateName: 'module',
31
+ templateName: BuiltInTemplateName.module,
25
32
  templatePath: path.resolve(templatesDir, 'module/*'),
26
33
  outDir: clientOutDirAbsolutePath,
27
34
  fullSchema: false,
28
35
  origin: null,
29
36
  },
30
37
  fullSchema: {
31
- templateName: 'fullSchema',
38
+ templateName: BuiltInTemplateName.fullSchema,
32
39
  templatePath: path.resolve(templatesDir, 'fullSchema/*'),
33
40
  outDir: clientOutDirAbsolutePath,
34
41
  fullSchema: false,
@@ -9,9 +9,6 @@ export default async function updateNPMScripts(pkgJson, root, updateScriptsMode)
9
9
  pkgJson.update({
10
10
  scripts: {
11
11
  ...pkgJson.content.scripts,
12
- generate: pkgJson.content.scripts?.generate
13
- ? `${pkgJson.content.scripts.generate} && vovk generate`
14
- : 'vovk generate',
15
12
  dev: getDevScript(pkgJson, updateScriptsMode),
16
13
  },
17
14
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk-cli",
3
- "version": "0.0.1-draft.116",
3
+ "version": "0.0.1-draft.118",
4
4
  "bin": {
5
5
  "vovk": "./dist/index.mjs"
6
6
  },