@starodubenko/fsd-gen 1.2.0-0 → 1.2.1-0

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 +1 @@
1
- {"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../../src/lib/reverse/analyze.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBAgGlF"}
1
+ {"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../../src/lib/reverse/analyze.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBA+GlF"}
@@ -2,7 +2,7 @@ import { existsSync } from 'fs';
2
2
  import { writeFile } from 'fs/promises';
3
3
  import { basename, join, relative, resolve } from 'path';
4
4
  import { Project } from 'ts-morph';
5
- import { generateVariations, identifyTokens, resolveSourceRoot } from './analyzeHelpers.js';
5
+ import { generateVariations, identifyTokens, resolveSourceRoot, toPascalCase } from './analyzeHelpers.js';
6
6
  import { loadSourceConfig, normalizeLayers } from './buildHelpers.js';
7
7
  /**
8
8
  * Analyzes source code and generates a preset configuration.
@@ -25,7 +25,9 @@ export async function analyzeReversePreset(presetName, templatesDir) {
25
25
  throw new Error(`Source root path does not exist: ${rootPath}`);
26
26
  }
27
27
  console.log(`Analyzing source at: ${rootPath} (Layer: ${layer.targetLayer})`);
28
- const subjectName = basename(rootPath);
28
+ // Normalize folder name to PascalCase for better token recognition
29
+ // e.g., "user-action" -> "UserAction"
30
+ const subjectName = toPascalCase(basename(rootPath));
29
31
  const variations = generateVariations(subjectName);
30
32
  // Discovery
31
33
  project.addSourceFilesAtPaths(join(rootPath, '**', '*.{ts,tsx,css,scss,less,sass}'));
@@ -61,16 +63,28 @@ export async function analyzeReversePreset(presetName, templatesDir) {
61
63
  };
62
64
  return layerMap[layer] || `"${layer}"`;
63
65
  };
66
+ // Helper to convert token value to EntityToken enum reference
67
+ const tokenToEnum = (tokenValue) => {
68
+ const tokenMap = {
69
+ '{{name}}': 'EntityToken.NAME',
70
+ '{{entityName}}': 'EntityToken.ENTITY_NAME',
71
+ '{{entityNameCamel}}': 'EntityToken.ENTITY_NAME_CAMEL',
72
+ '{{entityNameLower}}': 'EntityToken.ENTITY_NAME_LOWER',
73
+ '{{entityNameUpper}}': 'EntityToken.ENTITY_NAME_UPPER',
74
+ '{{entityNameKebab}}': 'EntityToken.ENTITY_NAME_KEBAB'
75
+ };
76
+ return tokenMap[tokenValue] || `"${tokenValue}"`;
77
+ };
64
78
  // Generate TypeScript content with enum values
65
79
  const filesContent = resultFiles.map(file => {
66
80
  const tokensStr = Object.entries(file.tokens)
67
- .map(([key, value]) => ` "${key}": ${value.startsWith('{{') ? `EntityToken.${value.slice(2, -2).toUpperCase().replace(/([A-Z])/g, '_$1').replace(/^_/, '')}` : `"${value}"`}`)
81
+ .map(([key, value]) => ` "${key}": ${tokenToEnum(value)}`)
68
82
  .join(',\n');
69
83
  return ` {
70
84
  "path": "${file.path}",
71
85
  "targetLayer": ${layerToEnum(file.targetLayer)},
72
86
  "tokens": {
73
- ${tokensStr}
87
+ ${tokensStr}
74
88
  }
75
89
  }`;
76
90
  }).join(',\n');
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Converts a string to PascalCase.
3
+ * Handles kebab-case, snake_case, camelCase, and space-separated strings.
4
+ * Examples:
5
+ * "user-action" -> "UserAction"
6
+ * "user_profile" -> "UserProfile"
7
+ * "user action" -> "UserAction"
8
+ * "userAction" -> "UserAction"
9
+ */
10
+ export declare function toPascalCase(str: string): string;
1
11
  /**
2
12
  * Generates naming variations for a given subject string
3
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"analyzeHelpers.d.ts","sourceRoot":"","sources":["../../../src/lib/reverse/analyzeHelpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM;;;;;;EAUjD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBzH;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,SAAS,GAAE,MAAW,GAAG,MAAM,CAMxG"}
1
+ {"version":3,"file":"analyzeHelpers.d.ts","sourceRoot":"","sources":["../../../src/lib/reverse/analyzeHelpers.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAahD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM;;;;;;EAUjD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBzH;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,SAAS,GAAE,MAAW,GAAG,MAAM,CAMxG"}
@@ -1,5 +1,26 @@
1
1
  import { resolve } from 'path';
2
2
  import { EntityToken } from './constants.js';
3
+ /**
4
+ * Converts a string to PascalCase.
5
+ * Handles kebab-case, snake_case, camelCase, and space-separated strings.
6
+ * Examples:
7
+ * "user-action" -> "UserAction"
8
+ * "user_profile" -> "UserProfile"
9
+ * "user action" -> "UserAction"
10
+ * "userAction" -> "UserAction"
11
+ */
12
+ export function toPascalCase(str) {
13
+ // First, split by common delimiters (hyphens, underscores, spaces)
14
+ const words = str.split(/[-_\s]+/);
15
+ // If we got multiple words, capitalize each
16
+ if (words.length > 1) {
17
+ return words
18
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
19
+ .join('');
20
+ }
21
+ // If single word, just ensure first letter is uppercase
22
+ return str.charAt(0).toUpperCase() + str.slice(1);
23
+ }
3
24
  /**
4
25
  * Generates naming variations for a given subject string
5
26
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starodubenko/fsd-gen",
3
- "version": "1.2.0-0",
3
+ "version": "1.2.1-0",
4
4
  "description": "A powerful CLI tool for scaffolding Feature-Sliced Design (FSD) components, slices, and layers.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",