vovk-cli 0.0.1-draft.6 → 0.0.1-draft.8

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/dist/index.mjs CHANGED
@@ -97,10 +97,9 @@ program
97
97
  .description('Create new components. "vovk new [...components] [segmentName/]moduleName" to create a new module or "vovk new segment [segmentName]" to create a new segment')
98
98
  .option('-O, --overwrite', 'Overwrite existing files')
99
99
  .option('--template', 'Override config template')
100
- .option('--dir-name', 'Override dirName in template file')
101
- .option('--file-name', 'Override fileName in template file')
102
- .option('--dry-run', 'Do not write files to disk')
100
+ .option('--dir-name', 'Override dirName in template file. Relative to the root of the project')
103
101
  .option('--no-segment-update', 'Do not update segment files when creating a new module')
102
+ .option('--dry-run', 'Do not write files to disk')
104
103
  .action((components, options) => newComponents(components, options));
105
104
  program
106
105
  .command('help')
@@ -1,6 +1,10 @@
1
- import { Project, SyntaxKind } from 'ts-morph';
1
+ import { Project, QuoteKind, SyntaxKind } from 'ts-morph';
2
2
  export default function addClassToSegmentCode(segmentSourceCode, { sourceName, compiledName, type, importPath, }) {
3
- const project = new Project();
3
+ const project = new Project({
4
+ manipulationSettings: {
5
+ quoteKind: QuoteKind.Single
6
+ }
7
+ });
4
8
  const sourceFile = project.createSourceFile('route.ts', segmentSourceCode, { overwrite: true });
5
9
  // Add the import if it doesn't exist
6
10
  let importDeclaration = sourceFile.getImportDeclaration((imp) => {
@@ -46,6 +46,9 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
46
46
  if (!segment) {
47
47
  throw new Error(`Segment ${segmentName} not found`);
48
48
  }
49
+ if (noSegmentUpdate && !what.includes('controller')) {
50
+ log.warn('--no-segment-update flag is ignored because it is only relevant when creating a controller');
51
+ }
49
52
  for (const type of what) {
50
53
  const templatePath = templateFlag ?? templates[type];
51
54
  const templateAbsolutePath = templatePath.startsWith('/') || templatePath.startsWith('.')
@@ -59,8 +62,7 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
59
62
  segmentName,
60
63
  moduleName,
61
64
  });
62
- const dirName = dirNameFlag || renderedDirName;
63
- const absoluteModuleDir = path.join(cwd, config.modulesDir, dirName);
65
+ const absoluteModuleDir = path.join(cwd, dirNameFlag || renderedDirName);
64
66
  const absoluteModulePath = path.join(absoluteModuleDir, fileName);
65
67
  const prettiedCode = await prettify(code, absoluteModulePath);
66
68
  if (!dryRun) {
@@ -81,7 +83,7 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
81
83
  }
82
84
  const { routeFilePath } = segment;
83
85
  const segmentSourceCode = await fs.readFile(routeFilePath, 'utf-8');
84
- const importPath = path.relative(absoluteModuleDir, absoluteModulePath).replace(/\.(ts|tsx)$/, '');
86
+ const importPath = path.relative(path.dirname(routeFilePath), absoluteModulePath).replace(/\.(ts|tsx)$/, '');
85
87
  if (!noSegmentUpdate) {
86
88
  const newSegmentCode = addClassToSegmentCode(segmentSourceCode, {
87
89
  sourceName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk-cli",
3
- "version": "0.0.1-draft.6",
3
+ "version": "0.0.1-draft.8",
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.9"
36
+ "vovk": "^3.0.0-draft.10"
37
37
  },
38
38
  "dependencies": {
39
39
  "@inquirer/prompts": "^7.0.1",
@@ -40,12 +40,12 @@ export default class <%= controllerName %> {
40
40
  };
41
41
 
42
42
  @post()
43
- static create<%= modulePascalNamePlural %> = () => {
43
+ static create<%= modulePascalName %> = () => {
44
44
  // ...
45
45
  };
46
46
 
47
47
  @del(':id')
48
- static delete<%= modulePascalNamePlural %> = () => {
48
+ static delete<%= modulePascalName %> = () => {
49
49
  // ...
50
50
  };
51
51
  }