@pantoken/scaffold 0.4.1 → 1.0.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.
package/README.md CHANGED
@@ -13,13 +13,27 @@ npx @pantoken/scaffold components # plain HTML/CSS (Vite + TS) + @pantoken/
13
13
  npx @pantoken/scaffold react # Vite + React + @pantoken/react
14
14
  npx @pantoken/scaffold vue # Vite + Vue 3 + @pantoken/vue
15
15
  npx @pantoken/scaffold web-components # Vite + @pantoken/web-components (no framework)
16
+ npx @pantoken/scaffold canvas-theme-editor # Canvas Theme Editor uploads + RCE template starter
16
17
 
17
18
  # Target a directory other than the current one:
18
19
  npx @pantoken/scaffold react ./my-app
20
+
21
+ # Omit the platform (and/or directory) on a TTY to be prompted interactively:
22
+ npx @pantoken/scaffold
23
+
24
+ # Non-interactive (CI-safe): errors instead of prompting for a missing platform/directory
25
+ npx @pantoken/scaffold react --dir ./my-app --yes
26
+
27
+ # Override the auto-detected display language
28
+ npx @pantoken/scaffold --lang hu
19
29
  ```
20
30
 
21
- `npx` works regardless of which package manager you use. Substitute `pnpm dlx`, `yarn dlx`, or
22
- `bunx` for `npx` if you prefer.
31
+ `npx` works regardless of which package manager you use. Substitute `pnpm dlx`, `yarn dlx`,
32
+ `bunx`, or `deno run npm:` for `npx` if you prefer — the printed "Next steps" install command
33
+ matches whichever one invoked the CLI (detected from `npm_config_user_agent`).
34
+
35
+ Run `npx @pantoken/scaffold --help` for the full flag reference, or `npx @pantoken/scaffold
36
+ completion <shell>` to generate a bash/zsh/fish/PowerShell completion script.
23
37
 
24
38
  Or use it programmatically:
25
39
 
@@ -35,8 +49,27 @@ await scaffoldProject("react", "./my-app");
35
49
  `ScaffoldPlatform` into `dir` (defaults to `"."`). Its basename (or `"pantoken-app"` for `"."`)
36
50
  is passed as the project name to the Bingo preset. Returns the paths written.
37
51
  - **`SCAFFOLD_PLATFORMS: readonly ScaffoldPlatform[]`** — every scaffoldable platform key (discovered
38
- from available presets at build time).
39
- - **`ScaffoldPlatform`** — the platform union, derived from preset registry.
52
+ from available presets at build time, plus legacy template-only platforms like
53
+ `canvas-theme-editor` that aren't backed by a preset yet).
54
+ - **`ScaffoldPlatform`** — the platform union, derived from the preset registry and the legacy
55
+ template map.
56
+
57
+ ## CLI flags
58
+
59
+ | Flag | Description |
60
+ | --------------------- | ------------------------------------------------------------------------- |
61
+ | `[platform]` | Platform to scaffold (prompted interactively if omitted on a TTY) |
62
+ | `-d, --dir <path>` | Target directory (prompted interactively if omitted on a TTY) |
63
+ | `-y, --yes` | Never prompt; error instead of prompting for a missing platform/directory |
64
+ | `-l, --lang <tag>` | Override the auto-detected display language (e.g. `"hu"`) |
65
+ | `--theme <name>` | Token theme: `rebrand` (default), `canvas`, `canvasHighContrast` |
66
+ | `--theme-mode <mode>` | Rebrand token mode: `light` (default) or `adaptive` |
67
+ | `-v, --version` | Print the installed version |
68
+ | `-h, --help` | Print usage |
69
+ | `completion <shell>` | Generate a bash/zsh/fish/PowerShell completion script |
70
+
71
+ The CLI auto-detects its display language from `--lang` > `LC_ALL`/`LANG` > the runtime's `Intl`
72
+ locale > English, falling back to English for any untranslated string.
40
73
 
41
74
  ## Architecture
42
75
 
@@ -1,4 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { runScaffoldCli } from "../dist/cli.mjs";
3
+ import pkg from "../package.json" with { type: "json" };
3
4
 
4
- await runScaffoldCli(process.argv.slice(2), { usageCommand: "pantoken-scaffold" });
5
+ await runScaffoldCli(process.argv.slice(2), {
6
+ usageCommand: "pantoken-scaffold",
7
+ version: pkg.version,
8
+ });
package/dist/cli.d.mts CHANGED
@@ -1,12 +1,179 @@
1
+ import { a as scaffoldProject, i as resolveScaffoldPlatform, o as ThemeMode, r as isScaffoldPlatform, s as ThemeVariant, t as SCAFFOLD_PLATFORMS } from "./index-CyolWk0E.mjs";
2
+ import { Command } from "commander";
3
+ //#region src/locale.d.ts
4
+ /**
5
+ * Locale detection and message lookup for the scaffold CLI.
6
+ *
7
+ * @module
8
+ * @alpha
9
+ */
10
+ /** Resolved locale plus a message lookup function. */
11
+ interface LocaleLookup {
12
+ readonly locale: string;
13
+ /** Looks up `key`, substituting any `{{param}}` placeholders from `params`. */
14
+ t: (key: string, params?: Record<string, string>) => string;
15
+ }
16
+ /**
17
+ * Resolves the active locale: --lang flag \> LC_ALL/LANG env \> Intl \> "en".
18
+ *
19
+ * @param options - Detection options. `langFlag` is an optional --lang flag value; `env` is
20
+ * environment variables (defaults to process.env); `intl` is an optional injected
21
+ * Intl.DateTimeFormat locale function (for testing).
22
+ * @returns The resolved locale tag
23
+ */
24
+ export declare function detectLocale(options: {
25
+ langFlag?: string;
26
+ env?: NodeJS.ProcessEnv;
27
+ intl?: () => string;
28
+ }): string;
29
+ /**
30
+ * Builds a lookup over the given locale bundles, falling back to `bundles[fallback]`
31
+ * for any key missing in the resolved locale.
32
+ *
33
+ * @param bundles - Record mapping locale tags to string bundles
34
+ * @param resolvedLocale - The locale to use (typically from detectLocale)
35
+ * @param fallback - The fallback locale when a key is missing (default "en")
36
+ * @returns A LocaleLookup object with a `t` function
37
+ */
38
+ export declare function createLocaleLookup(bundles: Record<string, Record<string, string>>, resolvedLocale: string, fallback?: string): LocaleLookup;
39
+ //#endregion
40
+ //#region generated/locales/index.d.ts
41
+ export declare const MESSAGES: Record<string, Record<string, string>>;
42
+ //#endregion
1
43
  //#region src/cli.d.ts
2
- /** Options distinguishing the two bins that share this CLI. */
3
- interface ScaffoldCliOptions {
4
- /** How the invoking command reads in its own `--help` usage line, e.g. `"pantoken-scaffold"`. */
5
- usageCommand: string;
44
+ /**
45
+ * Thrown for user-facing CLI errors (e.g., missing platform under --yes);
46
+ * carries an exit code for process.exit or CommanderError handling.
47
+ */
48
+ export declare class ScaffoldCliError extends Error {
49
+ readonly exitCode: number;
50
+ constructor(message: string, exitCode?: number);
6
51
  }
7
- /** Whether the directory prompt should run: no `--dir` flag was given, and stdin is an interactive TTY. */
8
- declare function shouldPromptForDir(dirFlag: string | undefined, isTTY: boolean | undefined): boolean;
9
- /** Run the scaffold CLI end to end: parse argv, prompt if needed, scaffold, and print next steps. */
10
- declare function runScaffoldCli(argv: string[], options: ScaffoldCliOptions): Promise<void>;
52
+ /**
53
+ * Whether a value should be interactively prompted for:
54
+ * no value given, not --yes, and (optionally injected) TTY check passes.
55
+ *
56
+ * @param value - The provided value (or undefined)
57
+ * @param opts - Options: `yes` flag forces non-interactive, `isTTY` injectable for testing
58
+ * @returns True if interactive prompt should proceed
59
+ */
60
+ export declare function shouldPrompt(value: string | undefined, opts: {
61
+ yes?: boolean;
62
+ isTTY?: boolean;
63
+ }): boolean;
64
+ /**
65
+ * Expands a tilde (`~`) in a file path to the user's home directory.
66
+ * On interactive prompts, shells don't expand `~`, so this handles it explicitly.
67
+ * Uses `node:path.join()` for cross-platform robustness (Windows, macOS, Linux).
68
+ *
69
+ * @param dir - The directory path (may start with `~`)
70
+ * @returns The expanded path
71
+ */
72
+ export declare function expandHome(dir: string): string;
73
+ /** Options for {@link resolveScaffoldTarget}. */
74
+ export interface ResolveScaffoldTargetOptions {
75
+ platformArg?: string;
76
+ dirOption?: string;
77
+ yes?: boolean;
78
+ isTTY?: boolean;
79
+ t: LocaleLookup["t"];
80
+ }
81
+ /**
82
+ * Resolves platform + directory: prompts via clack select()/text() when omitted on a TTY
83
+ * (not --yes); throws ScaffoldCliError with a clear, localized message when a required
84
+ * value is missing non-interactively.
85
+ *
86
+ * All prompt copy (message/placeholder/option labels) is looked up via `t`.
87
+ *
88
+ * @param options - Resolution options
89
+ * @returns Promise resolving to \{ platform, dir \}
90
+ * @throws ScaffoldCliError when required values are missing non-interactively
91
+ */
92
+ export declare function resolveScaffoldTarget(options: ResolveScaffoldTargetOptions): Promise<{
93
+ platform: string;
94
+ dir: string;
95
+ }>;
96
+ /**
97
+ * Runs scaffoldProject() wrapped in a clack spinner() whose start/stop text comes from `t`.
98
+ *
99
+ * @param platform - The scaffold platform
100
+ * @param dir - The target directory
101
+ * @param t - Localized string lookup
102
+ * @param options - `theme`/`mode`/`cdn` forwarded to {@link scaffoldProject}
103
+ * @returns The paths written by scaffoldProject
104
+ */
105
+ export declare function scaffoldWithSpinner(platform: string, dir: string, t: LocaleLookup["t"], options?: {
106
+ theme?: ThemeVariant;
107
+ mode?: ThemeMode;
108
+ cdn?: string;
109
+ }): Promise<string[]>;
110
+ /** Package managers `detectPackageManager` can identify. */
111
+ export type PackageManager = "npm" | "pnpm" | "yarn" | "bun" | "deno" | "vp";
112
+ /**
113
+ * Detects the invoking package manager: first from `npm_config_user_agent` (the technique
114
+ * create-vite and create-vue use), then — since `vp`/`vpx` set no such env var — falling back to
115
+ * whether the running Node binary itself is Vite+-managed (`execPath` resolves under a
116
+ * `vite-plus` directory).
117
+ *
118
+ * @param env - Environment variables (defaults to process.env)
119
+ * @param execPath - The running Node binary's path (defaults to process.execPath)
120
+ * @returns Detected package manager, or undefined
121
+ */
122
+ export declare function detectPackageManager(env?: NodeJS.ProcessEnv, execPath?: string): PackageManager | undefined;
123
+ /**
124
+ * Prints the post-scaffold "Next steps" block (plus any template-authored notes/caveats).
125
+ *
126
+ * When `platform` has a `scaffold.json`-derived entry in `SCAFFOLD_METADATA`, next steps/notes/
127
+ * caveats are rendered from its (localized, `{{var}}`-substituted) authored strings. Otherwise a
128
+ * generic cd/install/run-script fallback is used, with the run script itself detected from the
129
+ * scaffolded `package.json` (`dev`, else `preview`).
130
+ *
131
+ * @param dir - The scaffold directory
132
+ * @param written - The paths written by scaffoldProject
133
+ * @param t - Localized string lookup
134
+ * @param platform - The resolved (alias-free) scaffold platform, used to look up `scaffold.json` metadata
135
+ */
136
+ export declare function printNextSteps(dir: string, written: string[], t: LocaleLookup["t"], platform?: string): void;
137
+ /**
138
+ * Shared commander Argument validator for the platform positional.
139
+ * Used by all three CLIs (scaffold, create-pantoken-app, pantoken-ai scaffold)
140
+ * so error wording has one source of truth.
141
+ *
142
+ * @param value - The provided platform argument
143
+ * @returns The validated platform value
144
+ * @throws InvalidArgumentError if the platform is not valid
145
+ */
146
+ export declare function validateScaffoldPlatform(value: string): string;
147
+ /**
148
+ * Commander Argument validator for `--cdn`.
149
+ *
150
+ * @throws InvalidArgumentError if the value isn't a known CDN provider id
151
+ */
152
+ export declare function validateCdnProviderId(value: string): string;
153
+ /** Options for {@link createScaffoldCommand}. */
154
+ export interface ScaffoldCommandOptions {
155
+ name?: string;
156
+ usageCommand?: string;
157
+ version?: string;
158
+ enableCompletions?: boolean;
159
+ }
160
+ /**
161
+ * Builds the full, ready-to-parse commander Command for pantoken-scaffold/create-pantoken-app.
162
+ *
163
+ * @param options - Configuration for the command
164
+ * @returns A configured commander Command
165
+ */
166
+ export declare function createScaffoldCommand(options?: ScaffoldCommandOptions): Command;
167
+ /**
168
+ * Entry point both bin shims call: builds the command and parses argv against it.
169
+ *
170
+ * @param argv - Command-line arguments (typically process.argv.slice(2))
171
+ * @param options - Configuration for the CLI
172
+ * @throws Exits via process.exit on error or successful completion
173
+ */
174
+ export declare function runScaffoldCli(argv: string[], options: {
175
+ usageCommand: string;
176
+ version?: string;
177
+ }): Promise<void>;
11
178
  //#endregion
12
- export { ScaffoldCliOptions, runScaffoldCli, shouldPromptForDir };
179
+ export { type LocaleLookup, SCAFFOLD_PLATFORMS, isScaffoldPlatform, resolveScaffoldPlatform, scaffoldProject };