vovk-cli 0.0.1-draft.5 → 0.0.1-draft.7

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 CHANGED
@@ -1 +1 @@
1
- Description is coming soon.
1
+ Description is coming soon.
@@ -2,10 +2,10 @@ import path from '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.
5
- if (await getFileSystemEntryType(path.join(cwd, 'app')) === FileSystemEntryType.DIRECTORY) {
5
+ if ((await getFileSystemEntryType(path.join(cwd, 'app'))) === FileSystemEntryType.DIRECTORY) {
6
6
  return '.';
7
7
  }
8
- else if (await getFileSystemEntryType(path.join(cwd, 'src/app')) === FileSystemEntryType.DIRECTORY) {
8
+ else if ((await getFileSystemEntryType(path.join(cwd, 'src/app'))) === FileSystemEntryType.DIRECTORY) {
9
9
  return './src';
10
10
  }
11
11
  throw new Error(`${cwd} Could not find app router directory. Check Next.js docs for more info.`);
package/dist/index.d.mts CHANGED
@@ -23,8 +23,8 @@ export interface NewOptions {
23
23
  dryRun?: boolean;
24
24
  template?: string;
25
25
  dirName?: string;
26
- fileName?: string;
27
26
  overwrite?: boolean;
27
+ noSegmentUpdate?: boolean;
28
28
  }
29
29
  declare const program: Command;
30
30
  export declare function initProgram(p: typeof program, command: string): Command;
package/dist/index.mjs CHANGED
@@ -100,6 +100,7 @@ program
100
100
  .option('--dir-name', 'Override dirName in template file')
101
101
  .option('--file-name', 'Override fileName in template file')
102
102
  .option('--dry-run', 'Do not write files to disk')
103
+ .option('--no-segment-update', 'Do not update segment files when creating a new module')
103
104
  .action((components, options) => newComponents(components, options));
104
105
  program
105
106
  .command('help')
@@ -1,2 +1,2 @@
1
1
  import type { NewOptions } from '../index.mjs';
2
- export default function newComponents(components: string[], { dryRun, fileName, dirName, template, overwrite }: NewOptions): Promise<void>;
2
+ export default function newComponents(components: string[], { dryRun, dirName, template, overwrite, noSegmentUpdate }: NewOptions): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import newModule from './newModule.mjs';
2
2
  import newSegment from './newSegment.mjs';
3
- export default async function newComponents(components, { dryRun, fileName, dirName, template, overwrite }) {
3
+ export default async function newComponents(components, { dryRun, dirName, template, overwrite, noSegmentUpdate }) {
4
4
  if (components[0] === 'segment' || components[0] === 'segments') {
5
5
  // vovk new segment [segmentName]
6
6
  let segmentNames = components
@@ -26,10 +26,10 @@ export default async function newComponents(components, { dryRun, fileName, dirN
26
26
  await newModule({
27
27
  what,
28
28
  moduleNameWithOptionalSegment,
29
- fileName,
30
29
  dirName,
31
30
  template,
32
31
  overwrite,
32
+ noSegmentUpdate,
33
33
  dryRun,
34
34
  });
35
35
  }
@@ -1,9 +1,9 @@
1
- export default function newModule({ what, moduleNameWithOptionalSegment, dryRun, fileName: fileNameFlag, dirName: dirNameFlag, template: templateFlag, overwrite, }: {
1
+ export default function newModule({ what, moduleNameWithOptionalSegment, dryRun, dirName: dirNameFlag, template: templateFlag, noSegmentUpdate, overwrite, }: {
2
2
  what: string[];
3
3
  moduleNameWithOptionalSegment: string;
4
4
  dryRun?: boolean;
5
- fileName?: string;
6
5
  dirName?: string;
7
6
  template?: string;
7
+ noSegmentUpdate?: boolean;
8
8
  overwrite?: boolean;
9
9
  }): Promise<void>;
@@ -18,7 +18,7 @@ function splitByLast(str, delimiter = '/') {
18
18
  const after = str.substring(index + delimiter.length);
19
19
  return [before, after];
20
20
  }
21
- export default async function newModule({ what, moduleNameWithOptionalSegment, dryRun, fileName: fileNameFlag, dirName: dirNameFlag, template: templateFlag, overwrite, }) {
21
+ export default async function newModule({ what, moduleNameWithOptionalSegment, dryRun, dirName: dirNameFlag, template: templateFlag, noSegmentUpdate, overwrite, }) {
22
22
  const { config, log, apiDir, cwd } = await getProjectInfo();
23
23
  const templates = config.templates;
24
24
  const [segmentName, moduleName] = splitByLast(moduleNameWithOptionalSegment);
@@ -52,14 +52,13 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
52
52
  ? path.resolve(cwd, templatePath)
53
53
  : path.resolve(cwd, './node_modules', templatePath);
54
54
  const templateCode = await fs.readFile(templateAbsolutePath, 'utf-8');
55
- const { dirName: renderedDirName, fileName: renderedFileName, sourceName, compiledName, code, } = await render(templateCode, {
55
+ const { dirName: renderedDirName, fileName, sourceName, compiledName, code, } = await render(templateCode, {
56
56
  cwd,
57
57
  config,
58
58
  withService: what.includes('service'),
59
59
  segmentName,
60
60
  moduleName,
61
61
  });
62
- const fileName = fileNameFlag || renderedFileName;
63
62
  const dirName = dirNameFlag || renderedDirName;
64
63
  const absoluteModuleDir = path.join(cwd, config.modulesDir, dirName);
65
64
  const absoluteModulePath = path.join(absoluteModuleDir, fileName);
@@ -83,14 +82,16 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
83
82
  const { routeFilePath } = segment;
84
83
  const segmentSourceCode = await fs.readFile(routeFilePath, 'utf-8');
85
84
  const importPath = path.relative(absoluteModuleDir, absoluteModulePath).replace(/\.(ts|tsx)$/, '');
86
- const newSegmentCode = addClassToSegmentCode(segmentSourceCode, {
87
- sourceName,
88
- compiledName,
89
- type,
90
- importPath,
91
- });
92
- if (!dryRun) {
93
- await fs.writeFile(routeFilePath, newSegmentCode);
85
+ if (!noSegmentUpdate) {
86
+ const newSegmentCode = addClassToSegmentCode(segmentSourceCode, {
87
+ sourceName,
88
+ compiledName,
89
+ type,
90
+ importPath,
91
+ });
92
+ if (!dryRun) {
93
+ await fs.writeFile(routeFilePath, newSegmentCode);
94
+ }
94
95
  }
95
96
  log.info(`Added ${chalkHighlightThing(sourceName)} ${type} to ${formatLoggedSegmentName(segmentName)} as ${chalkHighlightThing(compiledName)}`);
96
97
  }
@@ -11,7 +11,9 @@ async function postinstall() {
11
11
  const js = path.join(vovk, 'client.js');
12
12
  const ts = path.join(vovk, 'client.d.ts');
13
13
  const index = path.join(vovk, 'index.ts');
14
- if ((await getFileSystemEntryType(js)) || (await getFileSystemEntryType(ts)) || (await getFileSystemEntryType(index))) {
14
+ if ((await getFileSystemEntryType(js)) ||
15
+ (await getFileSystemEntryType(ts)) ||
16
+ (await getFileSystemEntryType(index))) {
15
17
  return;
16
18
  }
17
19
  await fs.mkdir(vovk, { recursive: true });
@@ -5,7 +5,7 @@ import getFileSystemEntryType from '../utils/getFileSystemEntryType.mjs';
5
5
  export const ROOT_SEGMENT_SCHEMA_NAME = '_root';
6
6
  export default async function writeOneSchemaFile({ schemaOutAbsolutePath, schema, skipIfExists = false, }) {
7
7
  const segmentPath = path.join(schemaOutAbsolutePath, `${schema.segmentName || ROOT_SEGMENT_SCHEMA_NAME}.json`);
8
- if (skipIfExists && await getFileSystemEntryType(segmentPath)) {
8
+ if (skipIfExists && (await getFileSystemEntryType(segmentPath))) {
9
9
  try {
10
10
  await fs.stat(segmentPath);
11
11
  return { isCreated: false, diffResult: null };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk-cli",
3
- "version": "0.0.1-draft.5",
3
+ "version": "0.0.1-draft.7",
4
4
  "bin": {
5
5
  "vovk": "./dist/index.mjs"
6
6
  },
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "homepage": "https://vovk.dev",
35
35
  "peerDependencies": {
36
- "vovk": "^3.0.0-draft.4"
36
+ "vovk": "^3.0.0-draft.10"
37
37
  },
38
38
  "dependencies": {
39
39
  "@inquirer/prompts": "^7.0.1",