create-kitcms 0.1.0 → 0.1.1

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.js CHANGED
@@ -3,7 +3,7 @@ import { createRequire } from 'node:module';
3
3
  import path from 'node:path';
4
4
  import readline from 'node:readline/promises';
5
5
  import { TEMPLATES, USAGE, parseArgs } from './args.js';
6
- import { copyTemplate, isNonEmptyDir, linkDependencies, setDatabaseId, templatesDir, toAppName, writeDevVars, } from './scaffold.js';
6
+ import { copyTemplate, isNonEmptyDir, linkDependencies, setDatabaseId, templatesDir, toAppName, validateAppName, writeDevVars, } from './scaffold.js';
7
7
  import { parseDatabaseId } from './wrangler.js';
8
8
  // `src/` and `dist/` both sit one level below package.json.
9
9
  export const VERSION = createRequire(import.meta.url)('../package.json').version;
@@ -67,7 +67,18 @@ export async function run(argv, deps) {
67
67
  log(`create-kitcms: unknown template "${args.template}" (available: ${TEMPLATES.join(', ')})`);
68
68
  return 1;
69
69
  }
70
- const dirInput = args.dir ?? (await ask('Project name / directory?', 'kitcms-app'));
70
+ // Prompted names are asked again until valid; a name given as an argument fails fast.
71
+ let dirInput = args.dir ?? (await ask('Project name / directory?', 'kitcms-app'));
72
+ let nameError = validateAppName(toAppName(path.basename(path.resolve(deps.cwd, dirInput))));
73
+ while (nameError && args.dir === undefined && !args.yes && deps.interactive) {
74
+ log(nameError);
75
+ dirInput = await deps.ask('Project name / directory?', 'kitcms-app');
76
+ nameError = validateAppName(toAppName(path.basename(path.resolve(deps.cwd, dirInput))));
77
+ }
78
+ if (nameError) {
79
+ log(`create-kitcms: ${nameError}`);
80
+ return 1;
81
+ }
71
82
  const target = path.resolve(deps.cwd, dirInput);
72
83
  if (isNonEmptyDir(target)) {
73
84
  log(`create-kitcms: target directory "${target}" is not empty. Pick another name or empty it first.`);
@@ -11,6 +11,12 @@ export declare function packageRoot(): string;
11
11
  /** Published: `<pkg>/templates` (copied by `prepack`). Monorepo checkout: `<repo>/templates`. */
12
12
  export declare function templatesDir(root?: string): string;
13
13
  export declare function toAppName(input: string): string;
14
+ /**
15
+ * The app name is reused as the Worker, D1 database and R2 bucket name. R2 bucket names need
16
+ * 3-63 characters; 58 is create-cloudflare's own cap, which keeps every derived name valid.
17
+ * Returns an error message, or undefined when the (already normalized) name is fine.
18
+ */
19
+ export declare function validateAppName(name: string): string | undefined;
14
20
  export declare function replacePlaceholders(text: string, values: Placeholders): string;
15
21
  export declare function copyTemplate(src: string, dest: string, values: Placeholders): string[];
16
22
  /** True when the directory exists and contains anything. */
package/dist/scaffold.js CHANGED
@@ -25,6 +25,17 @@ export function toAppName(input) {
25
25
  .replace(/[^a-z0-9]+/g, '-')
26
26
  .replace(/^-+|-+$/g, '') || 'kitcms-app');
27
27
  }
28
+ /**
29
+ * The app name is reused as the Worker, D1 database and R2 bucket name. R2 bucket names need
30
+ * 3-63 characters; 58 is create-cloudflare's own cap, which keeps every derived name valid.
31
+ * Returns an error message, or undefined when the (already normalized) name is fine.
32
+ */
33
+ export function validateAppName(name) {
34
+ if (name.length < 3 || name.length > 58) {
35
+ return `Project names must be 3-58 characters (got "${name}", ${name.length}): it is also used as the Worker, D1 database and R2 bucket name.`;
36
+ }
37
+ return undefined;
38
+ }
28
39
  export function replacePlaceholders(text, values) {
29
40
  let out = text;
30
41
  for (const [k, v] of Object.entries(values))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-kitcms",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Scaffold a kitcms app: pnpm create kitcms",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -15,8 +15,8 @@
15
15
  "types": "kitcms generate:types"
16
16
  },
17
17
  "dependencies": {
18
- "@kitcms/core": "^0.1.0",
19
- "@kitcms/ui": "^0.1.0"
18
+ "@kitcms/core": "^0.1.1",
19
+ "@kitcms/ui": "^0.1.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@cloudflare/workers-types": "^5.20261116.1",
@@ -19,8 +19,8 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@fontsource-variable/hanken-grotesk": "^5.2.0",
22
- "@kitcms/core": "^0.1.0",
23
- "@kitcms/ui": "^0.1.0"
22
+ "@kitcms/core": "^0.1.1",
23
+ "@kitcms/ui": "^0.1.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@cloudflare/workers-types": "^5.20261116.1",