create-kimesh 0.2.4 → 0.2.5

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.d.ts CHANGED
@@ -1,5 +1,153 @@
1
- import { main$1 as main } from "./main-WWKDQIfS.js";
1
+ import { main$1 as main } from "./main-DnvYiSHH.js";
2
2
 
3
+ //#region src/utils/monorepo.d.ts
4
+ /**
5
+ * Monorepo detection result
6
+ */
7
+ interface MonorepoInfo {
8
+ /** Root directory of the monorepo */
9
+ root: string;
10
+ /** Package manager used */
11
+ packageManager: "pnpm" | "npm" | "yarn" | "bun";
12
+ /** Workspace patterns */
13
+ workspaces: string[];
14
+ }
15
+ /**
16
+ * Host app candidate
17
+ */
18
+ interface HostAppCandidate {
19
+ /** Name from package.json */
20
+ name: string;
21
+ /** Absolute path to the host app */
22
+ path: string;
23
+ /** Whether it has a kimesh.config.ts */
24
+ hasKimeshConfig: boolean;
25
+ }
26
+ /**
27
+ * Detect if we're in a monorepo and return its root
28
+ *
29
+ * @param cwd - Current working directory to start search from
30
+ * @returns MonorepoInfo if found, null otherwise
31
+ */
32
+ declare function detectMonorepoRoot(cwd: string): Promise<MonorepoInfo | null>;
33
+ /**
34
+ * Find potential host apps in a monorepo
35
+ *
36
+ * @param monorepoRoot - Root directory of the monorepo
37
+ * @returns Array of host app candidates
38
+ */
39
+ declare function findHostApps(monorepoRoot: string): Promise<HostAppCandidate[]>;
40
+ /**
41
+ * Get the recommended layer directory based on monorepo structure
42
+ *
43
+ * @param monorepoRoot - Root of the monorepo
44
+ * @param workspaces - Workspace patterns
45
+ * @returns Recommended directory path for layers
46
+ */
47
+ declare function getRecommendedLayerDir(monorepoRoot: string, workspaces: string[]): string;
48
+ /**
49
+ * Check if a path is within a monorepo workspace
50
+ *
51
+ * @param path - Path to check
52
+ * @param monorepo - Monorepo info
53
+ * @returns true if path is within a workspace pattern
54
+ */
55
+ declare function isInWorkspace(path: string, monorepo: MonorepoInfo): boolean;
56
+ //#endregion
57
+ //#region src/utils/layer.d.ts
58
+ /**
59
+ * Default version for @kimesh/* dependencies.
60
+ * This should match the version of create-kimesh package.
61
+ */
62
+ declare const DEFAULT_KIMESH_VERSION = "0.2.4";
63
+ /**
64
+ * Options for transforming a template to a layer
65
+ */
66
+ interface TransformToLayerOptions {
67
+ /** Absolute path to the layer directory */
68
+ layerPath: string;
69
+ /** Package name for the layer (e.g., "@myorg/my-layer") */
70
+ packageName: string;
71
+ /** Layer name for display/config (e.g., "my-layer") */
72
+ layerName: string;
73
+ }
74
+ /**
75
+ * Result of layer transformation
76
+ */
77
+ interface TransformToLayerResult {
78
+ success: boolean;
79
+ error?: string;
80
+ modifiedFiles: string[];
81
+ }
82
+ /**
83
+ * Transform a downloaded template into a layer
84
+ *
85
+ * This function modifies:
86
+ * - package.json: Updates name, main, exports, files
87
+ * - kimesh.config.ts: Updates to layer configuration with name and prefix
88
+ * - routes: Renames routes to layer-specific paths (e.g., src/routes/index.vue -> src/routes/[layerName]/index.vue)
89
+ *
90
+ * @param options - Transform options
91
+ * @returns Result of the transformation
92
+ */
93
+ declare function transformTemplateToLayer(options: TransformToLayerOptions): Promise<TransformToLayerResult>;
94
+ /**
95
+ * Convert kebab-case or snake_case to PascalCase
96
+ */
97
+ declare function toPascalCase(str: string): string;
98
+ /**
99
+ * Validate layer name
100
+ *
101
+ * @param name - Layer name to validate
102
+ * @returns Error message if invalid, undefined if valid
103
+ */
104
+ declare function validateLayerName(name: string): string | undefined;
105
+ /**
106
+ * Generate a package name from layer name and optional scope
107
+ *
108
+ * @param layerName - The layer name
109
+ * @param scope - Optional npm scope (e.g., "@myorg")
110
+ * @returns Full package name
111
+ */
112
+ declare function generatePackageName(layerName: string, scope?: string): string;
113
+ //#endregion
114
+ //#region src/utils/host-update.d.ts
115
+ /**
116
+ * Result of a host update operation
117
+ */
118
+ interface HostUpdateResult {
119
+ success: boolean;
120
+ error?: string;
121
+ updatedFiles: string[];
122
+ }
123
+ /**
124
+ * Options for updating a host app
125
+ */
126
+ interface HostUpdateOptions {
127
+ /** Absolute path to the host app */
128
+ hostPath: string;
129
+ /** Package name of the layer (e.g., "@myorg/my-layer") */
130
+ layerName: string;
131
+ /** Relative path from host to layer for workspace reference (e.g., "../layers/my-layer") */
132
+ layerRelativePath?: string;
133
+ /** Whether this is a workspace package (use workspace:* version) */
134
+ isWorkspace?: boolean;
135
+ }
136
+ /**
137
+ * Add a layer to a host app's configuration
138
+ *
139
+ * @param options - Update options
140
+ * @returns Result of the update operation
141
+ */
142
+ declare function addLayerToHost(options: HostUpdateOptions): Promise<HostUpdateResult>;
143
+ /**
144
+ * Check if a host app can be updated (has required files)
145
+ */
146
+ declare function canUpdateHost(hostPath: string): {
147
+ canUpdate: boolean;
148
+ missingFiles: string[];
149
+ };
150
+ //#endregion
3
151
  //#region src/types.d.ts
4
152
  /**
5
153
  * File to generate for a module
@@ -84,6 +232,10 @@ interface CreateOptions {
84
232
  * Directory conflict resolution action
85
233
  */
86
234
  type ConflictAction = "override" | "different" | "abort";
235
+ /**
236
+ * Project type - either an app or a layer
237
+ */
238
+ type ProjectType = "app" | "layer";
87
239
  //#endregion
88
240
  //#region src/modules/registry.d.ts
89
241
  /**
@@ -162,6 +314,58 @@ declare function promptDirectoryConflict(dirname: string): Promise<ConflictActio
162
314
  */
163
315
  declare function promptNewDirectoryName(currentName: string): Promise<string>;
164
316
  //#endregion
317
+ //#region src/prompts/layer.d.ts
318
+ /**
319
+ * Project type options
320
+ */
321
+ type ProjectType$1 = "app" | "layer";
322
+ /**
323
+ * Prompt user to select project type (app or layer)
324
+ *
325
+ * @returns Selected project type
326
+ */
327
+ declare function promptProjectType(): Promise<ProjectType$1>;
328
+ /**
329
+ * Prompt user for layer name
330
+ *
331
+ * @param defaultName - Default layer name
332
+ * @returns Layer name
333
+ */
334
+ declare function promptLayerName(defaultName?: string): Promise<string>;
335
+ /**
336
+ * Prompt user for npm scope
337
+ *
338
+ * @param defaultScope - Default scope (without @)
339
+ * @returns Scope string (without @) or empty string for no scope
340
+ */
341
+ declare function promptNpmScope(defaultScope?: string): Promise<string>;
342
+ /**
343
+ * Prompt user to select a host app to extend
344
+ *
345
+ * @param candidates - List of potential host apps
346
+ * @returns Selected host app path or null if user chooses not to extend
347
+ */
348
+ declare function promptHostAppSelection(candidates: HostAppCandidate[]): Promise<HostAppCandidate | null>;
349
+ /**
350
+ * Prompt user for layer directory in monorepo
351
+ *
352
+ * @param recommendedDir - Recommended directory path
353
+ * @param monorepoRoot - Monorepo root path
354
+ * @returns Selected directory path
355
+ */
356
+ declare function promptLayerDirectory(recommendedDir: string, monorepoRoot: string): Promise<string>;
357
+ /**
358
+ * Prompt user whether to include example files
359
+ */
360
+
361
+ /**
362
+ * Prompt user whether to update host app
363
+ *
364
+ * @param hostName - Name of the host app
365
+ * @returns Whether to update host
366
+ */
367
+ declare function promptUpdateHost(hostName: string): Promise<boolean>;
368
+ //#endregion
165
369
  //#region src/utils/registry.d.ts
166
370
  /**
167
371
  * Template definition from registry
@@ -317,6 +521,18 @@ interface DownloadOptions {
317
521
  force?: boolean;
318
522
  /** New project name (for package.json update) */
319
523
  projectName?: string;
524
+ /**
525
+ * Whether we are in a workspace context.
526
+ * When true, keeps "workspace:*" dependencies.
527
+ * When false, replaces "workspace:*" with fixed versions.
528
+ * @default false
529
+ */
530
+ useWorkspaceVersions?: boolean;
531
+ /**
532
+ * Version to use for @kimesh/* dependencies when not using workspace versions.
533
+ * @default DEFAULT_KIMESH_VERSION from layer.ts
534
+ */
535
+ kimeshVersion?: string;
320
536
  }
321
537
  /**
322
538
  * Result of template download operation
@@ -355,4 +571,4 @@ declare function installDependencies(dir: string, packageManager?: "npm" | "yarn
355
571
  */
356
572
  declare function detectPreferredPackageManager(): Promise<"npm" | "yarn" | "pnpm" | "bun">;
357
573
  //#endregion
358
- export { AVAILABLE_MODULES, ConflictAction, CreateOptions, DownloadOptions, DownloadResult, ModuleConfigUpdate, ModuleDefinition, ModuleFile, ModuleInstallOptions, ModuleInstallResult, PackageManager, ResolvedModules, TemplateDefinition, TemplateName, collectPackages, detectPreferredPackageManager, downloadProjectTemplate, fetchAllTemplates, fetchTemplate, generateModuleFiles, getDefaultTemplateName, getInstallSummary, getModule, getModuleDisplayHint, getModuleIds, getTemplateNames, getTemplateSource, hasUnmetDependencies, initGitRepo, installDependencies, installModules, installNpmPackages, isValidModuleId, isValidTemplateName, main, parseModulesArg, promptDirectoryConflict, promptGitInit, promptInstallDeps, promptModuleSelection, promptNewDirectoryName, promptPackageManager, promptProjectName, promptTemplateSelection, resolveModules, updateKimeshConfig, validateProjectName };
574
+ export { AVAILABLE_MODULES, ConflictAction, CreateOptions, DEFAULT_KIMESH_VERSION, DownloadOptions, DownloadResult, type HostAppCandidate, type HostUpdateOptions, type HostUpdateResult, ModuleConfigUpdate, ModuleDefinition, ModuleFile, ModuleInstallOptions, ModuleInstallResult, type MonorepoInfo, PackageManager, ProjectType, ResolvedModules, TemplateDefinition, TemplateName, type TransformToLayerOptions, type TransformToLayerResult, addLayerToHost, canUpdateHost, collectPackages, detectMonorepoRoot, detectPreferredPackageManager, downloadProjectTemplate, fetchAllTemplates, fetchTemplate, findHostApps, generateModuleFiles, generatePackageName, getDefaultTemplateName, getInstallSummary, getModule, getModuleDisplayHint, getModuleIds, getRecommendedLayerDir, getTemplateNames, getTemplateSource, hasUnmetDependencies, initGitRepo, installDependencies, installModules, installNpmPackages, isInWorkspace, isValidModuleId, isValidTemplateName, main, parseModulesArg, promptDirectoryConflict, promptGitInit, promptHostAppSelection, promptInstallDeps, promptLayerDirectory, promptLayerName, promptModuleSelection, promptNewDirectoryName, promptNpmScope, promptPackageManager, promptProjectName, promptProjectType, promptTemplateSelection, promptUpdateHost, resolveModules, toPascalCase, transformTemplateToLayer, updateKimeshConfig, validateLayerName, validateProjectName };
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
- import { AVAILABLE_MODULES, collectPackages, detectPreferredPackageManager, downloadProjectTemplate, fetchAllTemplates, fetchTemplate, generateModuleFiles, getDefaultTemplateName, getInstallSummary, getModule, getModuleDisplayHint, getModuleIds, getTemplateNames, getTemplateSource, hasUnmetDependencies, initGitRepo, installDependencies, installModules, installNpmPackages, isValidModuleId, isValidTemplateName, main, parseModulesArg, promptDirectoryConflict, promptGitInit, promptInstallDeps, promptModuleSelection, promptNewDirectoryName, promptPackageManager, promptProjectName, promptTemplateSelection, resolveModules, updateKimeshConfig, validateProjectName } from "./main-BH0zeBMP.js";
1
+ import { AVAILABLE_MODULES, addLayerToHost, canUpdateHost, collectPackages, detectMonorepoRoot, detectPreferredPackageManager, downloadProjectTemplate, fetchAllTemplates, fetchTemplate, findHostApps, generateModuleFiles, getDefaultTemplateName, getInstallSummary, getModule, getModuleDisplayHint, getModuleIds, getRecommendedLayerDir, getTemplateNames, getTemplateSource, hasUnmetDependencies, initGitRepo, installDependencies, installModules, installNpmPackages, isInWorkspace, isValidModuleId, isValidTemplateName, main, parseModulesArg, promptDirectoryConflict, promptGitInit, promptHostAppSelection, promptInstallDeps, promptLayerDirectory, promptLayerName, promptModuleSelection, promptNewDirectoryName, promptNpmScope, promptPackageManager, promptProjectName, promptProjectType, promptTemplateSelection, promptUpdateHost, resolveModules, updateKimeshConfig, validateProjectName } from "./main-BFNE3EFY.js";
2
+ import { DEFAULT_KIMESH_VERSION, generatePackageName, toPascalCase, transformTemplateToLayer, validateLayerName } from "./layer-C-e43mro.js";
2
3
 
3
- export { AVAILABLE_MODULES, collectPackages, detectPreferredPackageManager, downloadProjectTemplate, fetchAllTemplates, fetchTemplate, generateModuleFiles, getDefaultTemplateName, getInstallSummary, getModule, getModuleDisplayHint, getModuleIds, getTemplateNames, getTemplateSource, hasUnmetDependencies, initGitRepo, installDependencies, installModules, installNpmPackages, isValidModuleId, isValidTemplateName, main, parseModulesArg, promptDirectoryConflict, promptGitInit, promptInstallDeps, promptModuleSelection, promptNewDirectoryName, promptPackageManager, promptProjectName, promptTemplateSelection, resolveModules, updateKimeshConfig, validateProjectName };
4
+ export { AVAILABLE_MODULES, DEFAULT_KIMESH_VERSION, addLayerToHost, canUpdateHost, collectPackages, detectMonorepoRoot, detectPreferredPackageManager, downloadProjectTemplate, fetchAllTemplates, fetchTemplate, findHostApps, generateModuleFiles, generatePackageName, getDefaultTemplateName, getInstallSummary, getModule, getModuleDisplayHint, getModuleIds, getRecommendedLayerDir, getTemplateNames, getTemplateSource, hasUnmetDependencies, initGitRepo, installDependencies, installModules, installNpmPackages, isInWorkspace, isValidModuleId, isValidTemplateName, main, parseModulesArg, promptDirectoryConflict, promptGitInit, promptHostAppSelection, promptInstallDeps, promptLayerDirectory, promptLayerName, promptModuleSelection, promptNewDirectoryName, promptNpmScope, promptPackageManager, promptProjectName, promptProjectType, promptTemplateSelection, promptUpdateHost, resolveModules, toPascalCase, transformTemplateToLayer, updateKimeshConfig, validateLayerName, validateProjectName };
@@ -0,0 +1,214 @@
1
+ import { existsSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
4
+
5
+ //#region src/utils/layer.ts
6
+ /**
7
+ * Default version for @kimesh/* dependencies.
8
+ * This should match the version of create-kimesh package.
9
+ */
10
+ const DEFAULT_KIMESH_VERSION = "0.2.4";
11
+ /**
12
+ * Transform a downloaded template into a layer
13
+ *
14
+ * This function modifies:
15
+ * - package.json: Updates name, main, exports, files
16
+ * - kimesh.config.ts: Updates to layer configuration with name and prefix
17
+ * - routes: Renames routes to layer-specific paths (e.g., src/routes/index.vue -> src/routes/[layerName]/index.vue)
18
+ *
19
+ * @param options - Transform options
20
+ * @returns Result of the transformation
21
+ */
22
+ async function transformTemplateToLayer(options) {
23
+ const { layerPath, packageName, layerName } = options;
24
+ const modifiedFiles = [];
25
+ try {
26
+ await updatePackageJsonForLayer(layerPath, packageName);
27
+ modifiedFiles.push("package.json");
28
+ await updateKimeshConfigForLayer(layerPath, layerName);
29
+ modifiedFiles.push("kimesh.config.ts");
30
+ await restructureRoutesForLayer(layerPath, layerName);
31
+ modifiedFiles.push(`src/routes/${layerName}.vue`);
32
+ modifiedFiles.push(`src/routes/${layerName}/index.vue`);
33
+ await cleanupForLayer(layerPath);
34
+ modifiedFiles.push("removed: src/app.vue", "removed: src/routes/__root.vue");
35
+ return {
36
+ success: true,
37
+ modifiedFiles
38
+ };
39
+ } catch (error) {
40
+ return {
41
+ success: false,
42
+ error: error instanceof Error ? error.message : String(error),
43
+ modifiedFiles
44
+ };
45
+ }
46
+ }
47
+ /**
48
+ * Update package.json for layer usage
49
+ */
50
+ async function updatePackageJsonForLayer(layerPath, packageName) {
51
+ const pkgPath = join(layerPath, "package.json");
52
+ if (!existsSync(pkgPath)) throw new Error("package.json not found");
53
+ const content = await readFile(pkgPath, "utf-8");
54
+ const pkg = JSON.parse(content);
55
+ pkg.name = packageName;
56
+ pkg.main = "./kimesh.config.ts";
57
+ pkg.exports = { ".": "./kimesh.config.ts" };
58
+ pkg.files = ["src", "kimesh.config.ts"];
59
+ if (pkg.scripts) {
60
+ delete pkg.scripts.dev;
61
+ delete pkg.scripts.build;
62
+ delete pkg.scripts.preview;
63
+ if (Object.keys(pkg.scripts).length === 0) delete pkg.scripts;
64
+ }
65
+ await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
66
+ }
67
+ /**
68
+ * Update kimesh.config.ts for layer usage
69
+ */
70
+ async function updateKimeshConfigForLayer(layerPath, layerName) {
71
+ const configPath = join(layerPath, "kimesh.config.ts");
72
+ const pascalName = toPascalCase(layerName);
73
+ const newConfig = `import { defineKmConfig } from "@kimesh/kit";
74
+
75
+ export default defineKmConfig({
76
+ name: "${layerName}",
77
+ components: {
78
+ prefix: "${pascalName}",
79
+ },
80
+ });
81
+ `;
82
+ await writeFile(configPath, newConfig);
83
+ }
84
+ /**
85
+ * Restructure routes from app pattern to layer pattern
86
+ *
87
+ * App pattern:
88
+ * src/routes/__root.vue
89
+ * src/routes/index.vue
90
+ * src/routes/about.vue
91
+ * src/routes/blog.vue
92
+ *
93
+ * Layer pattern:
94
+ * src/routes/[layerName].vue <- layout wrapper
95
+ * src/routes/[layerName]/index.vue <- index page
96
+ */
97
+ async function restructureRoutesForLayer(layerPath, layerName) {
98
+ const routesDir = join(layerPath, "src", "routes");
99
+ const layerRoutesDir = join(routesDir, layerName);
100
+ if (!existsSync(layerRoutesDir)) await mkdir(layerRoutesDir, { recursive: true });
101
+ const newIndexPath = join(layerRoutesDir, "index.vue");
102
+ const indexContent = generateLayerIndexRoute(layerName);
103
+ await writeFile(newIndexPath, indexContent);
104
+ const layoutPath = join(routesDir, `${layerName}.vue`);
105
+ const layoutContent = generateLayerLayoutRoute(layerName);
106
+ await writeFile(layoutPath, layoutContent);
107
+ }
108
+ /**
109
+ * Clean up files that aren't needed for layers
110
+ */
111
+ async function cleanupForLayer(layerPath) {
112
+ const routesDir = join(layerPath, "src", "routes");
113
+ const filesToRemove = [
114
+ join(routesDir, "__root.vue"),
115
+ join(routesDir, "index.vue"),
116
+ join(routesDir, "about.vue"),
117
+ join(routesDir, "blog.vue"),
118
+ join(layerPath, "src", "app.vue")
119
+ ];
120
+ for (const file of filesToRemove) if (existsSync(file)) await rm(file);
121
+ }
122
+ /**
123
+ * Generate a layout route for the layer
124
+ */
125
+ function generateLayerLayoutRoute(layerName) {
126
+ const pascalName = toPascalCase(layerName);
127
+ return `<script setup lang="ts">
128
+ /**
129
+ * ${pascalName} Layer Layout
130
+ *
131
+ * This layout wraps all routes under /${layerName}/*
132
+ */
133
+ </script>
134
+
135
+ <template>
136
+ <div class="${layerName}-layout">
137
+ <slot />
138
+ </div>
139
+ </template>
140
+
141
+ <style scoped>
142
+ .${layerName}-layout {
143
+ min-height: 100vh;
144
+ }
145
+ </style>
146
+ `;
147
+ }
148
+ /**
149
+ * Generate an index route for the layer
150
+ */
151
+ function generateLayerIndexRoute(layerName) {
152
+ const pascalName = toPascalCase(layerName);
153
+ return `<script setup lang="ts">
154
+ /**
155
+ * ${pascalName} Layer Index Page
156
+ *
157
+ * Route: /${layerName}
158
+ */
159
+ </script>
160
+
161
+ <template>
162
+ <div class="${layerName}-page">
163
+ <h1>Welcome to ${pascalName}</h1>
164
+ <p>This is the ${layerName} layer index page.</p>
165
+ </div>
166
+ </template>
167
+
168
+ <style scoped>
169
+ .${layerName}-page {
170
+ padding: 2rem;
171
+ }
172
+
173
+ h1 {
174
+ margin-bottom: 1rem;
175
+ }
176
+ </style>
177
+ `;
178
+ }
179
+ /**
180
+ * Convert kebab-case or snake_case to PascalCase
181
+ */
182
+ function toPascalCase(str) {
183
+ return str.split(/[-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
184
+ }
185
+ /**
186
+ * Validate layer name
187
+ *
188
+ * @param name - Layer name to validate
189
+ * @returns Error message if invalid, undefined if valid
190
+ */
191
+ function validateLayerName(name) {
192
+ if (!name) return "Layer name is required";
193
+ if (!/^[a-z][a-z0-9-]*$/.test(name)) return "Layer name must start with a letter and contain only lowercase letters, numbers, and hyphens";
194
+ if (name.length < 2) return "Layer name must be at least 2 characters";
195
+ if (name.length > 50) return "Layer name must be at most 50 characters";
196
+ return void 0;
197
+ }
198
+ /**
199
+ * Generate a package name from layer name and optional scope
200
+ *
201
+ * @param layerName - The layer name
202
+ * @param scope - Optional npm scope (e.g., "@myorg")
203
+ * @returns Full package name
204
+ */
205
+ function generatePackageName(layerName, scope) {
206
+ if (scope) {
207
+ const normalizedScope = scope.startsWith("@") ? scope : `@${scope}`;
208
+ return `${normalizedScope}/${layerName}`;
209
+ }
210
+ return layerName;
211
+ }
212
+
213
+ //#endregion
214
+ export { DEFAULT_KIMESH_VERSION, generatePackageName, toPascalCase, transformTemplateToLayer, validateLayerName };
@@ -0,0 +1,3 @@
1
+ import { DEFAULT_KIMESH_VERSION, generatePackageName, toPascalCase, transformTemplateToLayer, validateLayerName } from "./layer-C-e43mro.js";
2
+
3
+ export { validateLayerName };