simple-scaffold 2.3.3 → 3.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.
- package/README.md +55 -13
- package/before-write.d.ts +7 -0
- package/cmd.js +331 -259
- package/cmd.js.map +1 -1
- package/colors.d.ts +32 -0
- package/config.d.ts +12 -10
- package/file.d.ts +32 -12
- package/fs-utils.d.ts +9 -0
- package/ignore.d.ts +21 -0
- package/index.d.ts +1 -0
- package/index.js +15 -23
- package/index.js.map +1 -1
- package/init.d.ts +20 -0
- package/logger.d.ts +14 -0
- package/package.json +42 -20
- package/parser.d.ts +1 -1
- package/path-utils.d.ts +6 -0
- package/prompts.d.ts +36 -0
- package/scaffold-DOzCgpZT.js +1263 -0
- package/scaffold-DOzCgpZT.js.map +1 -0
- package/types.d.ts +110 -0
- package/utils.d.ts +4 -24
- package/validate.d.ts +96 -0
- package/config.js +0 -254
- package/config.js.map +0 -1
- package/file.js +0 -166
- package/file.js.map +0 -1
- package/git.js +0 -81
- package/git.js.map +0 -1
- package/logger.js +0 -58
- package/logger.js.map +0 -1
- package/parser.js +0 -100
- package/parser.js.map +0 -1
- package/scaffold.js +0 -139
- package/scaffold.js.map +0 -1
- package/types.js +0 -31
- package/types.js.map +0 -1
- package/utils.js +0 -61
- package/utils.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold-DOzCgpZT.js","names":[],"sources":["../src/colors.ts","../src/utils.ts","../src/types.ts","../src/logger.ts","../src/parser.ts","../src/fs-utils.ts","../src/path-utils.ts","../src/file.ts","../src/git.ts","../src/before-write.ts","../src/config.ts","../src/prompts.ts","../src/ignore.ts","../src/validate.ts","../src/scaffold.ts"],"sourcesContent":["/** ANSI color code mapping for terminal output. */\nconst colorMap = {\n reset: 0,\n dim: 2,\n bold: 1,\n italic: 3,\n underline: 4,\n red: 31,\n green: 32,\n yellow: 33,\n blue: 34,\n magenta: 35,\n cyan: 36,\n white: 37,\n gray: 90,\n} as const\n\n/** Available terminal color names. */\nexport type TermColor = keyof typeof colorMap\n\nfunction _colorize(text: string, color: TermColor): string {\n const c = colorMap[color]!\n let r: number\n\n if (c > 1 && c < 30) {\n r = c + 20\n } else if (c === 1) {\n r = 23\n } else {\n r = 0\n }\n\n return `\\x1b[${c}m${text}\\x1b[${r}m`\n}\n\nfunction isTemplateStringArray(\n template: TemplateStringsArray | unknown,\n): template is TemplateStringsArray {\n return Array.isArray(template) && typeof template[0] === \"string\"\n}\n\nconst createColorize =\n (color: TermColor) =>\n (template: TemplateStringsArray | unknown, ...params: unknown[]): string => {\n return isTemplateStringArray(template)\n ? _colorize(\n (template as TemplateStringsArray).reduce(\n (acc, str, i) => acc + str + (params[i] ?? \"\"),\n \"\",\n ),\n color,\n )\n : _colorize(String(template), color)\n }\n\ntype TemplateStringsFn = ReturnType<typeof createColorize> & ((text: string) => string)\ntype TemplateStringsFns = { [key in TermColor]: TemplateStringsFn }\n\n/**\n * Colorize text for terminal output.\n *\n * Can be used as a function: `colorize(\"text\", \"red\")`\n * Or via named helpers: `colorize.red(\"text\")` / `colorize.red\\`template\\``\n */\nexport const colorize: typeof _colorize & TemplateStringsFns = Object.assign(\n _colorize,\n Object.entries(colorMap).reduce(\n (acc, [key]) => {\n acc[key as TermColor] = createColorize(key as TermColor)\n return acc\n },\n {} as Record<TermColor, TemplateStringsFn>,\n ),\n)\n","import { Resolver } from \"./types\"\n\n// Re-export colors for backward compatibility\nexport { colorize, type TermColor } from \"./colors\"\n\n/** Throws the error if non-null, no-ops otherwise. */\nexport function handleErr(err: NodeJS.ErrnoException | null): void {\n if (err) throw err\n}\n\n/** Resolves a value that may be either a static value or a function that produces one. */\nexport function resolve<T, R = T>(resolver: Resolver<T, R>, arg: T): R {\n return typeof resolver === \"function\" ? (resolver as (value: T) => R)(arg) : (resolver as R)\n}\n\n/** Wraps a static value in a resolver function. If already a function, returns as-is. */\nexport function wrapNoopResolver<T, R = T>(value: Resolver<T, R>): Resolver<T, R> {\n if (typeof value === \"function\") {\n return value\n }\n\n return (_) => value\n}\n","import { HelperDelegate } from \"handlebars/runtime\"\n\n/**\n * The config object for defining a scaffolding group.\n *\n * @see {@link https://chenasraf.github.io/simple-scaffold/docs/usage/node| Node.js usage}\n * @see {@link https://chenasraf.github.io/simple-scaffold/docs/usage/cli| CLI usage}\n * @see {@link DefaultHelpers}\n * @see {@link CaseHelpers}\n * @see {@link DateHelpers}\n *\n * @category Config\n */\nexport interface ScaffoldConfig {\n /**\n * Name to be passed to the generated files. `{{name}}` and `{{Name}}` inside contents and file names will be replaced\n * accordingly.\n */\n name: string\n\n /**\n * Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path,\n * or a glob pattern for multiple file matching easily.\n *\n * You may omit files from output by prepending a `!` to their glob pattern.\n *\n * For example, `[\"components/**\", \"!components/README.md\"]` will include everything in the directory `components`\n * except the `README.md` file inside.\n *\n * @default Current working directory\n */\n templates: string[]\n\n /**\n * Path to output to. If `subdir` is `true`, the subdir will be created inside this path.\n *\n * May also be a {@link FileResponseHandler} which returns a new output path to override the default one.\n *\n * @see {@link FileResponse}\n * @see {@link FileResponseHandler}\n */\n output: FileResponse<string>\n\n /**\n * Whether to create subdir with the input name.\n *\n * When `true`, you may also use {@link subdirHelper} to determine a pre-process helper on\n * the directory name.\n *\n * @default `false`\n */\n subdir?: boolean\n\n /**\n * Add custom data to the templates. By default, only your app name is included as `{{name}}` and `{{Name}}`.\n *\n * This can be any object that will be usable by Handlebars.\n */\n data?: Record<string, unknown>\n\n /**\n * Enable to override output files, even if they already exist.\n *\n * You may supply a function to this option, which can take the arguments `(fullPath, baseDir, baseName)` and returns\n * a boolean for each file.\n *\n * May also be a {@link FileResponseHandler} which returns a boolean value per file.\n *\n * @see {@link FileResponse}\n * @see {@link FileResponseHandler}\n *\n * @default `false`\n */\n overwrite?: FileResponse<boolean>\n\n /**\n * Determine amount of logs to display.\n *\n * The values are: `0 (none) | 1 (debug) | 2 (info) | 3 (warn) | 4 (error)`. The provided level will display messages\n * of the same level or higher.\n *\n * @see {@link LogLevel}\n *\n * @default `2 (info)`\n */\n logLevel?: LogLevel\n\n /**\n * Don't emit files. This is good for testing your scaffolds and making sure they don't fail, without having to write\n * actual file contents or create directories.\n *\n * @default `false`\n */\n dryRun?: boolean\n\n /**\n * Additional helpers to add to the template parser. Provide an object whose keys are the name of the function to add,\n * and the value is the helper function itself. The signature of helpers is as follows:\n * ```typescript\n * (text: string, ...args: any[]) => string\n * ```\n *\n * A full example might be:\n *\n * ```typescript\n * Scaffold({\n * //...\n * helpers: {\n * upperKebabCase: (text) => kebabCase(text).toUpperCase()\n * }\n * })\n * ```\n *\n * Which will allow:\n *\n * ```\n * {{ upperKebabCase \"my value\" }}\n * ```\n *\n * To transform to:\n *\n * ```\n * MY-VALUE\n * ```\n *\n * See {@link DefaultHelpers} for a list of all the built-in available helpers.\n *\n * Simple Scaffold uses Handlebars.js, so all the syntax from there is supported. See\n * [their docs](https://handlebarsjs.com/guide/#custom-helpers) for more information.\n *\n * @see {@link DefaultHelpers}\n * @see {@link CaseHelpers}\n * @see {@link DateHelpers}\n * @see {@link https://chenasraf.github.io/simple-scaffold/docs/usage/templates| Templates}\n * */\n helpers?: Record<string, Helper>\n\n /**\n * Default transformer to apply to subdir name when using `subdir: true`. Can be one of the default\n * capitalization helpers, or a custom one you provide to `helpers`. Defaults to `undefined`, which means no\n * transformation is done.\n *\n * @see {@link subdir}\n * @see {@link CaseHelpers}\n * @see {@link DefaultHelpers}\n */\n subdirHelper?: DefaultHelpers | string\n\n /**\n * This callback runs right before content is being written to the disk. If you supply this function, you may return\n * a string that represents the final content of your file, you may process the content as you see fit. For example,\n * you may run formatters on a file, fix output in edge-cases not supported by helpers or data, etc.\n *\n * If the return value of this function is `undefined`, the original content will be used.\n *\n * @param content The original template after token replacement\n * @param rawContent The original template before token replacement\n * @param outputPath The final output path of the processed file\n *\n * @returns {Promise<String | Buffer | undefined> | String | Buffer | undefined} The final output of the file\n * contents-only, after further modifications - or `undefined` to use the original content (i.e. `content.toString()`)\n */\n beforeWrite?(\n content: Buffer,\n rawContent: Buffer,\n outputPath: string,\n ): string | Buffer | undefined | Promise<string | Buffer | undefined>\n\n /**\n * Defines interactive inputs for the template. Each input becomes a template data variable.\n *\n * When running interactively, required inputs that are not already provided via `data` or CLI args\n * will be prompted for. Optional inputs without a value will use their `default` if defined.\n *\n * @example\n * ```typescript\n * Scaffold({\n * // ...\n * inputs: {\n * author: { message: \"Author name\", required: true },\n * license: { message: \"License\", default: \"MIT\" },\n * },\n * })\n * ```\n *\n * In templates: `{{ author }}`, `{{ license }}`\n *\n * @see {@link ScaffoldInput}\n */\n inputs?: Record<string, ScaffoldInput>\n\n /**\n * A callback or shell command that runs after all files have been written.\n *\n * When provided as a **function** (Node.js API), it receives a context object with the scaffold\n * config and the list of files that were written:\n *\n * ```typescript\n * Scaffold({\n * // ...\n * afterScaffold: async ({ config, files }) => {\n * console.log(`Created ${files.length} files`)\n * execSync(\"npm install\", { cwd: config.output })\n * },\n * })\n * ```\n *\n * When provided as a **string** (CLI `--after` flag), it is executed as a shell command\n * in the output directory after scaffolding completes.\n *\n * @see {@link AfterScaffoldContext}\n */\n afterScaffold?: AfterScaffoldHook\n\n /** @internal */\n tmpDir?: string\n}\n\n/**\n * Context passed to the {@link ScaffoldConfig.afterScaffold} hook.\n *\n * @category Config\n */\nexport interface AfterScaffoldContext {\n /** The resolved scaffold config that was used. */\n config: ScaffoldConfig\n /** List of absolute paths to files that were written. */\n files: string[]\n}\n\n/**\n * A hook that runs after scaffolding completes.\n * Can be a function receiving context, or a shell command string.\n *\n * @category Config\n */\nexport type AfterScaffoldHook = ((context: AfterScaffoldContext) => void | Promise<void>) | string\n\n/**\n * The type of an interactive input prompt.\n *\n * - `\"text\"` — free-form text input (default)\n * - `\"select\"` — choose from a list of options\n * - `\"confirm\"` — yes/no boolean prompt\n * - `\"number\"` — numeric input\n *\n * @category Config\n */\nexport type ScaffoldInputType = \"text\" | \"select\" | \"confirm\" | \"number\"\n\n/**\n * Defines a single interactive input for a scaffold template.\n *\n * @example\n * ```typescript\n * inputs: {\n * author: { message: \"Author name\", required: true },\n * license: { type: \"select\", message: \"License\", options: [\"MIT\", \"Apache-2.0\", \"GPL-3.0\"] },\n * private: { type: \"confirm\", message: \"Private package?\", default: false },\n * port: { type: \"number\", message: \"Dev server port\", default: 3000 },\n * }\n * ```\n *\n * @category Config\n */\nexport interface ScaffoldInput {\n /** The type of prompt. Defaults to `\"text\"`. */\n type?: ScaffoldInputType\n /** The prompt message shown to the user. Defaults to the input key name if omitted. */\n message?: string\n /** Whether this input must be provided. If true and missing, the user will be prompted interactively. */\n required?: boolean\n /** Default value. Type depends on the input type: string for text/select, boolean for confirm, number for number. */\n default?: string | boolean | number\n /** List of options for `type: \"select\"`. Each can be a string or `{ name, value }`. */\n options?: (string | { name: string; value: string })[]\n}\n\n/**\n * The names of the available helper functions that relate to text capitalization.\n *\n * These are available for `subdirHelper`.\n *\n * | Helper name | Example code | Example output |\n * | ------------ | ----------------------- | -------------- |\n * | [None] | `{{ name }}` | my name |\n * | `camelCase` | `{{ camelCase name }}` | myName |\n * | `snakeCase` | `{{ snakeCase name }}` | my_name |\n * | `startCase` | `{{ startCase name }}` | My Name |\n * | `kebabCase` | `{{ kebabCase name }}` | my-name |\n * | `hyphenCase` | `{{ hyphenCase name }}` | my-name |\n * | `pascalCase` | `{{ pascalCase name }}` | MyName |\n * | `upperCase` | `{{ upperCase name }}` | MY NAME |\n * | `lowerCase` | `{{ lowerCase name }}` | my name |\n *\n * @see {@link DefaultHelpers}\n * @see {@link DateHelpers}\n * @see {@link ScaffoldConfig}\n * @see {@link ScaffoldConfig.subdirHelper}\n *\n * @category Helpers\n */\nexport type CaseHelpers =\n | \"camelCase\"\n | \"hyphenCase\"\n | \"kebabCase\"\n | \"lowerCase\"\n | \"pascalCase\"\n | \"snakeCase\"\n | \"startCase\"\n | \"upperCase\"\n\n/**\n * The names of the available helper functions that relate to dates.\n *\n * | Helper name | Description | Example code | Example output |\n * | -------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------ |\n * | `now` | Current date with format | `{{ now \"yyyy-MM-dd HH:mm\" }}` | `2042-01-01 15:00` |\n * | `now` (with offset) | Current date with format, and with offset | `{{ now \"yyyy-MM-dd HH:mm\" -1 \"hours\" }}` | `2042-01-01 14:00` |\n * | `date` | Custom date with format | `{{ date \"2042-01-01T15:00:00Z\" \"yyyy-MM-dd HH:mm\" }}` | `2042-01-01 15:00` |\n * | `date` (with offset) | Custom date with format, and with offset | `{{ date \"2042-01-01T15:00:00Z\" \"yyyy-MM-dd HH:mm\" -1 \"days\" }}` | `2041-31-12 15:00` |\n * | `date` (with date from `--data`) | Custom date with format, with data from the `data` config option | `{{ date myCustomDate \"yyyy-MM-dd HH:mm\" }}` | `2042-01-01 12:00` |\n *\n * Further details:\n *\n * - We use [`date-fns`](https://date-fns.org/docs/) for parsing/manipulating the dates. If you want\n * more information on the date tokens to use, refer to\n * [their format documentation](https://date-fns.org/docs/format).\n *\n * - The date helper format takes the following arguments:\n *\n * ```typescript\n * (\n * date: string,\n * format: string,\n * offsetAmount?: number,\n * offsetType?: \"years\" | \"months\" | \"weeks\" | \"days\" | \"hours\" | \"minutes\" | \"seconds\"\n * )\n * ```\n *\n * - **The now helper** (for current time) takes the same arguments, minus the first one (`date`) as it is implicitly\n * the current date.\n *\n * @see {@link DefaultHelpers}\n * @see {@link CaseHelpers}\n * @see {@link ScaffoldConfig}\n *\n * @category Helpers\n */\nexport type DateHelpers = \"date\" | \"now\"\n\n/**\n * The names of all the available helper functions in templates.\n * Simple-Scaffold provides some built-in text transformation filters usable by Handlebars.js.\n *\n * For example, you may use `{{ snakeCase name }}` inside a template file or filename, and it will\n * replace `My Name` with `my_name` when producing the final value.\n *\n * @see {@link CaseHelpers}\n * @see {@link DateHelpers}\n * @see {@link ScaffoldConfig}\n *\n * @category Helpers\n */\nexport type DefaultHelpers = CaseHelpers | DateHelpers\n\n/**\n * Helper function, see https://handlebarsjs.com/guide/#custom-helpers\n *\n * @category Helpers\n */\nexport type Helper = HelperDelegate\n\n/**\n * The amount of information to log when generating scaffold.\n * When not `none`, the selected level will be the lowest level included.\n *\n * For example, level `info` will include `info`, `warning` and `error`, but not `debug`; and `warning` will only\n * show `warning` and `error`, but not `info` or `debug`.\n *\n * @default `info`\n *\n * @category Logging (const)\n */\n\nexport const LogLevel = {\n /** Silent output */\n none: \"none\",\n /** Debugging information. Very verbose and only recommended for troubleshooting. */\n debug: \"debug\",\n /**\n * The regular level of logging. Major actions are logged to show the scaffold progress.\n *\n * @default\n */\n info: \"info\",\n /** Warnings such as when file fails to replace token values properly in template. */\n warning: \"warning\",\n /** Errors, such as missing files, bad replacement token syntax, or un-writable directories. */\n error: \"error\",\n} as const\n\n/**\n * The amount of information to log when generating scaffold.\n * When not `none`, the selected level will be the lowest level included.\n *\n * For example, level `info` will include `info`, `warning` and `error`, but not `debug`; and `warning` will only\n * show `warning` and `error`, but not `info` or `debug`.\n *\n * @default `info`\n *\n * @category Logging (type)\n */\nexport type LogLevel = (typeof LogLevel)[keyof typeof LogLevel]\n\n/**\n * A function that takes path information about file, and returns a value of type `T`\n *\n * @template T The return type for the function\n * @param {string} fullPath The full path of the current file\n * @param {string} basedir The directory containing the current file\n * @param {string} basename The name of the file\n *\n * @returns {T} A return value\n *\n * @category Config\n */\nexport type FileResponseHandler<T> = (fullPath: string, basedir: string, basename: string) => T\n\n/**\n * Represents a response for file path information.\n * Can either be:\n *\n * 1. `T` - static value\n * 2. A function with the following signature which returns `T`:\n * ```typescript\n * (fullPath: string, basedir: string, basename: string) => T\n * ```\n *\n * @see {@link FileResponseHandler}\n *\n * @category Config\n * */\nexport type FileResponse<T> = T | FileResponseHandler<T>\n\n/**\n * The Scaffold config for CLI\n * Contains less and more specific options than {@link ScaffoldConfig}.\n *\n * For more information about each option, see {@link ScaffoldConfig}.\n *\n * @internal\n */\nexport type ScaffoldCmdConfig = {\n /** The name of the scaffold template to use. */\n name: string\n /** The templates to use for generation */\n templates: string[]\n /** The output path to write to */\n output: string\n /** Whether to create subdir with the input name */\n subdir: boolean\n /** Default transformer to apply to subdir name when using `subdir: true` */\n subdirHelper?: string\n /** Add custom data to the templates */\n data?: Record<string, string>\n /** Add custom data to the template in a CLI-friendly syntax (and not JSON) */\n appendData?: Record<string, string>\n /** Enable to override output files, even if they already exist */\n overwrite: boolean\n /** Silence logs, same as `logLevel: \"none\"` */\n quiet: boolean\n /**\n * Determine amount of logs to display.\n *\n * @see {@link LogLevel}\n */\n logLevel: LogLevel\n /** Don't emit files. This is good for testing your scaffolds and making sure they don't fail, without having to write actual file contents or create directories. */\n dryRun: boolean\n /** Config file path to use */\n config?: string\n /** The key of the template to use */\n key?: string\n /** The git repository to use to fetch the config file */\n git?: string\n /** Display version */\n version: boolean\n /** Run a script before writing the files. This can be a command or a path to a file. The file contents will be passed to the given command. */\n beforeWrite?: string\n /** Run a shell command after all files have been written. Executed in the output directory. */\n afterScaffold?: string\n /** @internal */\n tmpDir?: string\n}\n\n/**\n * A mapping of scaffold template keys to their configurations.\n *\n * Each configuration is a {@link ScaffoldConfig} object.\n *\n * The key is the name of the template, and the value is the configuration for that template.\n *\n * When no template key is provided to the scaffold command, the \"default\" template is used.\n *\n * @see {@link ScaffoldConfig}\n *\n * @internal\n * @category Config\n */\nexport type ScaffoldConfigMap = Record<string, ScaffoldConfig>\n\n/**\n * The scaffold config file is either:\n * - A {@link ScaffoldConfigMap} object\n * - A function that returns a {@link ScaffoldConfigMap} object\n * - A promise that resolves to a {@link ScaffoldConfigMap} object\n * - A function that returns a promise that resolves to a {@link ScaffoldConfigMap} object\n *\n * @internal\n * @category Config\n */\nexport type ScaffoldConfigFile = AsyncResolver<ScaffoldCmdConfig, ScaffoldConfigMap>\n\n/** @internal */\nexport type Resolver<T, R = T> = R | ((_value: T) => R)\n\n/** @internal */\nexport type AsyncResolver<T, R = T> = Resolver<T, Promise<R> | R>\n\n/** @internal */\nexport type LogConfig = Pick<ScaffoldConfig, \"logLevel\">\n\n/** @internal */\nexport type ConfigLoadConfig = LogConfig & Pick<ScaffoldCmdConfig, \"config\">\n\n/** @internal */\nexport type RemoteConfigLoadConfig = LogConfig &\n Pick<ScaffoldCmdConfig, \"config\" | \"git\" | \"tmpDir\">\n\n/** @internal */\nexport type MinimalConfig = Pick<ScaffoldCmdConfig, \"name\" | \"key\">\n\n/** @internal */\nexport type ListCommandCliOptions = Pick<ScaffoldCmdConfig, \"config\" | \"git\" | \"logLevel\" | \"quiet\">\n","import util from \"util\"\nimport path from \"node:path\"\nimport { LogConfig, LogLevel, ScaffoldConfig } from \"./types\"\nimport { colorize, TermColor } from \"./colors\"\n\n/** Priority ordering for log levels (higher = more severe). */\nconst LOG_PRIORITY: Record<LogLevel, number> = {\n [LogLevel.none]: 0,\n [LogLevel.debug]: 1,\n [LogLevel.info]: 2,\n [LogLevel.warning]: 3,\n [LogLevel.error]: 4,\n}\n\n/** Maps each log level to a terminal color. */\nconst LOG_LEVEL_COLOR: Record<LogLevel, TermColor> = {\n [LogLevel.none]: \"reset\",\n [LogLevel.debug]: \"dim\",\n [LogLevel.info]: \"reset\",\n [LogLevel.warning]: \"yellow\",\n [LogLevel.error]: \"red\",\n}\n\n/** Logs a message at the given level, respecting the configured log level filter. */\nexport function log(config: LogConfig, level: LogLevel, ...obj: unknown[]): void {\n if (\n config.logLevel === LogLevel.none ||\n LOG_PRIORITY[level] < LOG_PRIORITY[config.logLevel ?? LogLevel.info]\n ) {\n return\n }\n\n const colorFn = colorize[LOG_LEVEL_COLOR[level]]\n const key: \"log\" | \"warn\" | \"error\" =\n level === LogLevel.error ? \"error\" : level === LogLevel.warning ? \"warn\" : \"log\"\n const logFn: (..._args: unknown[]) => void = console[key]\n logFn(\n ...obj.map((i) =>\n i instanceof Error\n ? colorFn(i, JSON.stringify(i, undefined, 1), i.stack)\n : typeof i === \"object\"\n ? util.inspect(i, { depth: null, colors: true })\n : colorFn(i),\n ),\n )\n}\n\n/**\n * Logs detailed file processing information at debug level.\n * @deprecated Use `log(config, LogLevel.debug, data)` directly instead.\n */\nexport function logInputFile(\n config: ScaffoldConfig,\n data: {\n originalTemplate: string\n relativePath: string\n parsedTemplate: string\n inputFilePath: string\n nonGlobTemplate: string\n basePath: string\n isDirOrGlob: boolean\n isGlob: boolean\n },\n): void {\n log(config, LogLevel.debug, data)\n}\n\n/** Logs the full scaffold configuration at debug level. */\nexport function logInitStep(config: ScaffoldConfig): void {\n log(config, LogLevel.debug, \"Full config:\", {\n name: config.name,\n templates: config.templates,\n output: config.output,\n subdir: config.subdir,\n data: config.data,\n overwrite: config.overwrite,\n subdirHelper: config.subdirHelper,\n helpers: Object.keys(config.helpers ?? {}),\n logLevel: config.logLevel,\n dryRun: config.dryRun,\n beforeWrite: config.beforeWrite,\n } as Record<keyof ScaffoldConfig, unknown>)\n}\n\n/**\n * Logs a tree of created files, grouped by directory.\n */\nexport function logFileTree(config: LogConfig, files: string[]): void {\n if (files.length === 0) return\n\n // Find common prefix to make paths relative\n const commonDir = files.reduce((prefix, file) => {\n while (!file.startsWith(prefix)) {\n prefix = path.dirname(prefix)\n }\n return prefix\n }, path.dirname(files[0]))\n\n log(config, LogLevel.info, \"\")\n log(config, LogLevel.info, colorize.bold(`📁 ${commonDir}`))\n\n const relPaths = files.map((f) => path.relative(commonDir, f)).sort()\n\n for (let i = 0; i < relPaths.length; i++) {\n const isLast = i === relPaths.length - 1\n const prefix = isLast ? \"└── \" : \"├── \"\n log(config, LogLevel.info, colorize.dim(prefix) + relPaths[i])\n }\n}\n\n/**\n * Logs a final summary line with file count and elapsed time.\n */\nexport function logSummary(\n config: LogConfig,\n fileCount: number,\n elapsedMs: number,\n dryRun?: boolean,\n): void {\n const timeStr =\n elapsedMs < 1000 ? `${Math.round(elapsedMs)}ms` : `${(elapsedMs / 1000).toFixed(2)}s`\n\n log(config, LogLevel.info, \"\")\n if (dryRun) {\n log(\n config,\n LogLevel.info,\n colorize.yellow(`🏜️ Dry run complete — ${fileCount} file(s) would be created (${timeStr})`),\n )\n } else if (fileCount === 0) {\n log(config, LogLevel.info, colorize.yellow(`⚠️ No files created (${timeStr})`))\n } else {\n log(config, LogLevel.info, colorize.green(`✅ Created ${fileCount} file(s) in ${timeStr}`))\n }\n}\n","import path from \"node:path\"\nimport { DefaultHelpers, Helper, LogLevel, ScaffoldConfig } from \"./types\"\nimport Handlebars from \"handlebars\"\nimport { add, format, parseISO, type Duration } from \"date-fns\"\nimport { log } from \"./logger\"\n\nconst dateFns = { add, format, parseISO }\n\nexport const defaultHelpers: Record<DefaultHelpers, Helper> = {\n camelCase,\n snakeCase,\n startCase,\n kebabCase,\n hyphenCase: kebabCase,\n pascalCase,\n lowerCase: (text) => text.toLowerCase(),\n upperCase: (text) => text.toUpperCase(),\n now: nowHelper,\n date: dateHelper,\n}\n\nfunction _dateHelper(date: Date, formatString: string): string\nfunction _dateHelper(\n date: Date,\n formatString: string,\n durationDifference: number,\n durationType: keyof Duration,\n): string\nfunction _dateHelper(\n date: Date,\n formatString: string,\n durationDifference?: number,\n durationType?: keyof Duration,\n): string {\n if (durationType && durationDifference !== undefined) {\n return dateFns.format(dateFns.add(date, { [durationType]: durationDifference }), formatString)\n }\n return dateFns.format(date, formatString)\n}\n\nexport function nowHelper(formatString: string): string\nexport function nowHelper(\n formatString: string,\n durationDifference: number,\n durationType: keyof Duration,\n): string\nexport function nowHelper(\n formatString: string,\n durationDifference?: number,\n durationType?: keyof Duration,\n): string {\n return _dateHelper(new Date(), formatString, durationDifference!, durationType!)\n}\n\nexport function dateHelper(date: string, formatString: string): string\nexport function dateHelper(\n date: string,\n formatString: string,\n durationDifference: number,\n durationType: keyof Duration,\n): string\nexport function dateHelper(\n date: string,\n formatString: string,\n durationDifference?: number,\n durationType?: keyof Duration,\n): string {\n return _dateHelper(dateFns.parseISO(date), formatString, durationDifference!, durationType!)\n}\n\n// splits by either non-alphanumeric character or capital letter boundaries\nfunction toWordParts(string: string): string[] {\n // First split on non-alphanumeric characters\n return string\n .split(/[^a-zA-Z0-9]/)\n .flatMap((segment) =>\n // Then split camelCase/PascalCase boundaries, handling consecutive uppercase (e.g. \"HTMLParser\" -> \"HTML\", \"Parser\")\n segment.split(/(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/),\n )\n .filter((s) => s.length > 0)\n}\n\nfunction camelCase(s: string): string {\n return toWordParts(s).reduce((acc, part, i) => {\n if (i === 0) {\n return part.toLowerCase()\n }\n return acc + part[0].toUpperCase() + part.slice(1).toLowerCase()\n }, \"\")\n}\n\nfunction snakeCase(s: string): string {\n return toWordParts(s).join(\"_\").toLowerCase()\n}\n\nfunction kebabCase(s: string): string {\n return toWordParts(s).join(\"-\").toLowerCase()\n}\n\nfunction startCase(s: string): string {\n return toWordParts(s)\n .map((part) => part[0].toUpperCase() + part.slice(1).toLowerCase())\n .join(\" \")\n}\n\nfunction pascalCase(s: string): string {\n return startCase(s).replace(/\\s+/g, \"\")\n}\n\nexport function registerHelpers(config: ScaffoldConfig): void {\n const _helpers = { ...defaultHelpers, ...config.helpers }\n for (const helperName in _helpers) {\n log(config, LogLevel.debug, `Registering helper: ${helperName}`)\n Handlebars.registerHelper(helperName, _helpers[helperName as keyof typeof _helpers])\n }\n}\n\nexport function handlebarsParse(\n config: ScaffoldConfig,\n templateBuffer: Buffer | string,\n { asPath = false }: { asPath?: boolean } = {},\n): Buffer {\n const { data } = config\n try {\n let str = templateBuffer.toString()\n if (asPath) {\n str = str.replace(/\\\\/g, \"/\")\n }\n const parser = Handlebars.compile(str, { noEscape: true })\n let outputContents = parser(data)\n if (asPath && path.sep !== \"/\") {\n outputContents = outputContents.replace(/\\//g, \"\\\\\")\n }\n return Buffer.from(outputContents)\n } catch (e) {\n log(config, LogLevel.debug, e)\n log(config, LogLevel.debug, \"Couldn't parse file with handlebars, returning original content\")\n return Buffer.from(templateBuffer)\n }\n}\n","import os from \"node:os\"\nimport path from \"node:path\"\nimport fs from \"node:fs/promises\"\nimport { F_OK } from \"node:constants\"\nimport { LogConfig, LogLevel, ScaffoldConfig } from \"./types\"\nimport { log } from \"./logger\"\n\nconst { stat, access, mkdir } = fs\n\n/** Recursively creates a directory and its parents if they don't exist. */\nexport async function createDirIfNotExists(\n dir: string,\n config: LogConfig & Pick<ScaffoldConfig, \"dryRun\">,\n): Promise<void> {\n if (config.dryRun) {\n log(config, LogLevel.info, `Dry Run. Not creating dir ${dir}`)\n return\n }\n const parentDir = path.dirname(dir)\n\n if (!(await pathExists(parentDir))) {\n await createDirIfNotExists(parentDir, config)\n }\n\n if (!(await pathExists(dir))) {\n try {\n log(config, LogLevel.debug, `Creating dir ${dir}`)\n await mkdir(dir)\n return\n } catch (e: unknown) {\n if (e && (e as NodeJS.ErrnoException).code !== \"EEXIST\") {\n throw e\n }\n return\n }\n }\n}\n\n/** Checks whether a file or directory exists at the given path. */\nexport async function pathExists(filePath: string): Promise<boolean> {\n try {\n await access(filePath, F_OK)\n return true\n } catch (e: unknown) {\n if (e && (e as NodeJS.ErrnoException).code === \"ENOENT\") {\n return false\n }\n throw e\n }\n}\n\n/** Returns true if the given path is a directory. */\nexport async function isDir(dirPath: string): Promise<boolean> {\n const tplStat = await stat(dirPath)\n return tplStat.isDirectory()\n}\n\n/** Generates a unique temporary directory path for scaffold operations. @internal */\nexport function getUniqueTmpPath(): string {\n return path.resolve(\n os.tmpdir(),\n `scaffold-config-${Date.now()}-${Math.random().toString(36).slice(2)}`,\n )\n}\n","import path from \"node:path\"\n\n/** Strips glob wildcard characters from a template path. */\nexport function removeGlob(template: string): string {\n return path.normalize(template.replace(/\\*/g, \"\"))\n}\n\n/** Removes a leading path separator, making the path relative. */\nexport function makeRelativePath(str: string): string {\n return str.startsWith(path.sep) ? str.slice(1) : str\n}\n\n/** Computes a base path relative to the current working directory. */\nexport function getBasePath(relPath: string): string {\n return path\n .resolve(process.cwd(), relPath)\n .replace(process.cwd() + path.sep, \"\")\n .replace(process.cwd(), \"\")\n}\n","import path from \"node:path\"\nimport fs from \"node:fs/promises\"\nimport { FileResponse, FileResponseHandler, LogLevel, ScaffoldConfig } from \"./types\"\nimport { glob, hasMagic } from \"glob\"\nimport { log } from \"./logger\"\nimport { handlebarsParse } from \"./parser\"\nimport { handleErr } from \"./utils\"\nimport { createDirIfNotExists, pathExists, isDir } from \"./fs-utils\"\nimport { removeGlob } from \"./path-utils\"\n\nconst { readFile, writeFile } = fs\n\n// Re-export extracted utilities for backward compatibility (tests import from here)\nexport { createDirIfNotExists, pathExists, isDir, getUniqueTmpPath } from \"./fs-utils\"\nexport { removeGlob, makeRelativePath, getBasePath } from \"./path-utils\"\n\n/**\n * Resolves a config option that may be either a static value or a per-file function.\n * For function values, the file path is parsed through Handlebars before being passed.\n * @internal\n */\nexport function getOptionValueForFile<T>(\n config: ScaffoldConfig,\n filePath: string,\n fn: FileResponse<T>,\n defaultValue?: T,\n): T {\n if (typeof fn !== \"function\") {\n return defaultValue ?? (fn as T)\n }\n return (fn as FileResponseHandler<T>)(\n filePath,\n path.dirname(handlebarsParse(config, filePath, { asPath: true }).toString()),\n path.basename(handlebarsParse(config, filePath, { asPath: true }).toString()),\n )\n}\n\n/** Information about a template glob pattern and how it was resolved. */\nexport interface GlobInfo {\n /** The template path with glob wildcards stripped. */\n baseTemplatePath: string\n /** The original template string as provided by the user. */\n origTemplate: string\n /** Whether the template is a directory or contains glob patterns. */\n isDirOrGlob: boolean\n /** Whether the template contains glob wildcard characters. */\n isGlob: boolean\n /** The final resolved template path (with `**\\/*` appended for directories). */\n template: string\n}\n\n/** Expands a list of glob patterns into a flat list of matching file paths. */\nexport async function getFileList(config: ScaffoldConfig, templates: string[]): Promise<string[]> {\n log(config, LogLevel.debug, `Getting file list for glob list: ${templates}`)\n return (\n await glob(templates, {\n dot: true,\n nodir: true,\n })\n ).map(path.normalize)\n}\n\n/** Analyzes a template path to determine if it's a glob, directory, or single file. */\nexport async function getTemplateGlobInfo(\n config: ScaffoldConfig,\n template: string,\n): Promise<GlobInfo> {\n const _isGlob = hasMagic(template)\n log(config, LogLevel.debug, \"before isDir\", \"isGlob:\", _isGlob, template)\n\n let resolvedTemplate = template\n let baseTemplatePath = _isGlob ? removeGlob(template) : template\n baseTemplatePath = path.normalize(baseTemplatePath)\n const isDirOrGlob = _isGlob ? true : await isDir(template)\n const shouldAddGlob = !_isGlob && isDirOrGlob\n log(config, LogLevel.debug, \"after\", { isDirOrGlob, shouldAddGlob })\n\n if (shouldAddGlob) {\n resolvedTemplate = path.join(template, \"**\", \"*\")\n }\n return {\n baseTemplatePath,\n origTemplate: template,\n isDirOrGlob,\n isGlob: _isGlob,\n template: resolvedTemplate,\n }\n}\n\n/** Complete information about a template file's output destination. */\nexport interface OutputFileInfo {\n inputPath: string\n outputPathOpt: string\n outputDir: string\n outputPath: string\n exists: boolean\n}\n\n/** Computes the full output path and metadata for a single template file. */\nexport async function getTemplateFileInfo(\n config: ScaffoldConfig,\n { templatePath, basePath }: { templatePath: string; basePath: string },\n): Promise<OutputFileInfo> {\n const inputPath = path.resolve(process.cwd(), templatePath)\n const outputPathOpt = getOptionValueForFile(config, inputPath, config.output)\n const outputDir = getOutputDir(config, outputPathOpt, basePath.replace(config.tmpDir!, \"./\"))\n const rawOutputPath = path.join(outputDir, path.basename(inputPath))\n const outputPath = handlebarsParse(config, rawOutputPath, { asPath: true }).toString()\n const exists = await pathExists(outputPath)\n return { inputPath, outputPathOpt, outputDir, outputPath, exists }\n}\n\n/**\n * Reads a template file, applies Handlebars parsing, runs the beforeWrite hook,\n * and writes the result to the output path.\n */\nexport async function copyFileTransformed(\n config: ScaffoldConfig,\n {\n exists,\n overwrite,\n outputPath,\n inputPath,\n }: {\n exists: boolean\n overwrite: boolean\n outputPath: string\n inputPath: string\n },\n): Promise<void> {\n if (!exists || overwrite) {\n if (exists && overwrite) {\n log(config, LogLevel.debug, `Overwriting ${outputPath}`)\n }\n log(config, LogLevel.debug, `Processing file ${inputPath}`)\n const templateBuffer = await readFile(inputPath)\n const unprocessedOutputContents = handlebarsParse(config, templateBuffer)\n const finalOutputContents =\n (await config.beforeWrite?.(unprocessedOutputContents, templateBuffer, outputPath)) ??\n unprocessedOutputContents\n\n if (!config.dryRun) {\n await writeFile(outputPath, finalOutputContents)\n } else {\n log(config, LogLevel.debug, \"Dry run — output would be:\")\n log(config, LogLevel.debug, finalOutputContents.toString())\n }\n } else if (exists) {\n log(config, LogLevel.debug, `Skipped ${outputPath} (already exists)`)\n }\n}\n\n/** Computes the output directory for a file, combining the output path, base path, and optional subdir. */\nexport function getOutputDir(\n config: ScaffoldConfig,\n outputPathOpt: string,\n basePath: string,\n): string {\n return path.resolve(\n process.cwd(),\n ...([\n outputPathOpt,\n basePath,\n config.subdir\n ? config.subdirHelper\n ? handlebarsParse(config, `{{ ${config.subdirHelper} name }}`).toString()\n : config.name\n : undefined,\n ].filter(Boolean) as string[]),\n )\n}\n\n/**\n * Processes a single template file: resolves output paths, creates directories,\n * and writes the transformed output.\n * Returns the output path if the file was written, or null if skipped.\n */\nexport async function handleTemplateFile(\n config: ScaffoldConfig,\n { templatePath, basePath }: { templatePath: string; basePath: string },\n): Promise<string | null> {\n try {\n const { inputPath, outputPathOpt, outputDir, outputPath, exists } = await getTemplateFileInfo(\n config,\n {\n templatePath,\n basePath,\n },\n )\n const overwrite = getOptionValueForFile(config, inputPath, config.overwrite ?? false)\n\n log(\n config,\n LogLevel.debug,\n `\\nParsing ${templatePath}`,\n `\\nBase path: ${basePath}`,\n `\\nFull input path: ${inputPath}`,\n `\\nOutput Path Opt: ${outputPathOpt}`,\n `\\nFull output dir: ${outputDir}`,\n `\\nFull output path: ${outputPath}`,\n `\\n`,\n )\n\n await createDirIfNotExists(path.dirname(outputPath), config)\n\n const shouldWrite = (!exists || overwrite) && !config.dryRun\n log(config, LogLevel.debug, `Writing to ${outputPath}`)\n await copyFileTransformed(config, { exists, overwrite, outputPath, inputPath })\n return shouldWrite ? outputPath : null\n } catch (e: unknown) {\n handleErr(e as NodeJS.ErrnoException)\n throw e\n }\n}\n","import path from \"node:path\"\nimport { log } from \"./logger\"\nimport { AsyncResolver, LogConfig, LogLevel, ScaffoldCmdConfig, ScaffoldConfigMap } from \"./types\"\nimport { spawn } from \"node:child_process\"\nimport { resolve, wrapNoopResolver } from \"./utils\"\nimport { findConfigFile } from \"./config\"\n\nexport async function getGitConfig(\n url: URL,\n file: string,\n tmpPath: string,\n logConfig: LogConfig,\n): Promise<AsyncResolver<ScaffoldCmdConfig, ScaffoldConfigMap>> {\n const repoUrl = `${url.protocol}//${url.host}${url.pathname}`\n\n log(logConfig, LogLevel.debug, `Cloning git repo ${repoUrl}`)\n\n return new Promise((res, reject) => {\n log(logConfig, LogLevel.debug, `Cloning git repo to ${tmpPath}`)\n const clone = spawn(\"git\", [\"clone\", \"--recurse-submodules\", \"--depth\", \"1\", repoUrl, tmpPath])\n\n clone.on(\"error\", reject)\n clone.on(\"close\", async (code) => {\n if (code === 0) {\n res(await loadGitConfig({ logConfig, url: repoUrl, file, tmpPath }))\n return\n }\n\n reject(new Error(`Git clone failed with code ${code}`))\n })\n })\n}\n\n/** @internal */\nexport async function loadGitConfig({\n logConfig,\n url: repoUrl,\n file,\n tmpPath,\n}: {\n logConfig: LogConfig\n url: string\n file: string\n tmpPath: string\n}): Promise<AsyncResolver<ScaffoldCmdConfig, ScaffoldConfigMap>> {\n log(logConfig, LogLevel.debug, `Loading config from git repo: ${repoUrl}`)\n const filename = file || (await findConfigFile(tmpPath))\n const absolutePath = path.resolve(tmpPath, filename)\n log(logConfig, LogLevel.debug, `Resolving config file: ${absolutePath}`)\n const loadedConfig = await resolve(\n async () => (await import(absolutePath)).default as ScaffoldConfigMap,\n logConfig,\n )\n\n log(logConfig, LogLevel.debug, `Loaded config from git`)\n log(logConfig, LogLevel.debug, `Raw config:`, loadedConfig)\n const fixedConfig: ScaffoldConfigMap = {}\n for (const [k, v] of Object.entries(loadedConfig)) {\n fixedConfig[k] = {\n ...v,\n templates: v.templates.map((t) => path.resolve(tmpPath, t)),\n }\n }\n return wrapNoopResolver(fixedConfig)\n}\n","import path from \"node:path\"\nimport fs from \"node:fs/promises\"\nimport { exec } from \"node:child_process\"\nimport { LogConfig, LogLevel, ScaffoldConfig } from \"./types\"\nimport { log } from \"./logger\"\nimport { createDirIfNotExists, getUniqueTmpPath } from \"./fs-utils\"\n\n/**\n * Wraps a CLI beforeWrite command string into a beforeWrite callback function.\n * The command receives the processed content via a temp file and can return modified content via stdout.\n * @internal\n */\nexport function wrapBeforeWrite(\n config: LogConfig & Pick<ScaffoldConfig, \"dryRun\">,\n beforeWrite: string,\n): ScaffoldConfig[\"beforeWrite\"] {\n return async (content, rawContent, outputFile) => {\n const tmpDir = path.join(getUniqueTmpPath(), path.basename(outputFile))\n await createDirIfNotExists(path.dirname(tmpDir), config)\n const ext = path.extname(outputFile)\n const rawTmpPath = tmpDir.replace(ext, \".raw\" + ext)\n try {\n log(config, LogLevel.debug, \"Parsing beforeWrite command\", beforeWrite)\n const cmd = await prepareBeforeWriteCmd({\n beforeWrite,\n tmpDir,\n content,\n rawTmpPath,\n rawContent,\n })\n const result = await new Promise<string | undefined>((resolve, reject) => {\n log(config, LogLevel.debug, \"Running parsed beforeWrite command:\", cmd)\n const proc = exec(cmd)\n proc.stdout!.on(\"data\", (data) => {\n if (data.trim()) {\n resolve(data.toString())\n } else {\n resolve(undefined)\n }\n })\n proc.stderr!.on(\"data\", (data) => {\n reject(data.toString())\n })\n })\n return result\n } catch (e) {\n log(config, LogLevel.debug, e)\n log(config, LogLevel.warning, \"Error running beforeWrite command, returning original content\")\n return undefined\n } finally {\n await fs.rm(tmpDir, { force: true })\n await fs.rm(rawTmpPath, { force: true })\n }\n }\n}\n\nasync function prepareBeforeWriteCmd({\n beforeWrite,\n tmpDir,\n content,\n rawTmpPath,\n rawContent,\n}: {\n beforeWrite: string\n tmpDir: string\n content: Buffer\n rawTmpPath: string\n rawContent: Buffer\n}): Promise<string> {\n let cmd: string = \"\"\n const pathReg = /\\{\\{\\s*path\\s*\\}\\}/gi\n const rawPathReg = /\\{\\{\\s*rawpath\\s*\\}\\}/gi\n if (pathReg.test(beforeWrite)) {\n await fs.writeFile(tmpDir, content)\n cmd = beforeWrite.replaceAll(pathReg, tmpDir)\n }\n if (rawPathReg.test(beforeWrite)) {\n await fs.writeFile(rawTmpPath, rawContent)\n cmd = beforeWrite.replaceAll(rawPathReg, rawTmpPath)\n }\n if (!cmd) {\n await fs.writeFile(tmpDir, content)\n cmd = [beforeWrite, tmpDir].join(\" \")\n }\n return cmd\n}\n","import path from \"node:path\"\nimport {\n ConfigLoadConfig,\n LogConfig,\n LogLevel,\n RemoteConfigLoadConfig,\n ScaffoldCmdConfig,\n ScaffoldConfig,\n ScaffoldConfigFile,\n ScaffoldConfigMap,\n} from \"./types\"\nimport { log } from \"./logger\"\nimport { resolve, wrapNoopResolver } from \"./utils\"\nimport { getGitConfig } from \"./git\"\nimport { isDir, pathExists } from \"./fs-utils\"\nimport { wrapBeforeWrite } from \"./before-write\"\n\n// Re-export for backward compatibility (tests import from here)\nexport { getOptionValueForFile } from \"./file\"\n\n/** Parses CLI append-data syntax (`key=value` or `key:=jsonValue`) into a data object. @internal */\nexport function parseAppendData(value: string, options: ScaffoldCmdConfig): unknown {\n const data = options.data ?? {}\n const [key, val] = value.split(/:?=/)\n if (value.includes(\":=\") && !val.includes(\":=\")) {\n return { ...data, [key]: JSON.parse(val) }\n }\n return { ...data, [key]: isWrappedWithQuotes(val) ? val.substring(1, val.length - 1) : val }\n}\n\nfunction isWrappedWithQuotes(string: string): boolean {\n return (\n (string.startsWith('\"') && string.endsWith('\"')) ||\n (string.startsWith(\"'\") && string.endsWith(\"'\"))\n )\n}\n\n/** Loads and resolves a config file (local or remote). @internal */\nexport async function getConfigFile(config: ScaffoldCmdConfig): Promise<ScaffoldConfigMap> {\n if (config.git && !config.git.includes(\"://\")) {\n log(config, LogLevel.debug, `Loading config from GitHub ${config.git}`)\n config.git = githubPartToUrl(config.git)\n }\n\n const isGit = Boolean(config.git)\n const configFilename = config.config\n const configPath = isGit ? config.git : configFilename\n\n log(config, LogLevel.debug, `Loading config from file ${configFilename}`)\n\n const configPromise = await (isGit\n ? getRemoteConfig({\n git: configPath,\n config: configFilename,\n logLevel: config.logLevel,\n tmpDir: config.tmpDir!,\n })\n : getLocalConfig({ config: configFilename, logLevel: config.logLevel }))\n\n let configImport = await resolve(configPromise, config)\n\n if (typeof configImport.default === \"function\" || configImport.default instanceof Promise) {\n log(config, LogLevel.debug, \"Config is a function or promise, resolving...\")\n configImport = await resolve(configImport.default, config)\n }\n return configImport\n}\n\n/**\n * Parses a CLI config into a full ScaffoldConfig by merging CLI args, config file values,\n * and append-data overrides. @internal\n */\nexport async function parseConfigFile(config: ScaffoldCmdConfig): Promise<ScaffoldConfig> {\n let output: ScaffoldConfig = {\n name: config.name,\n templates: config.templates ?? [],\n output: config.output,\n logLevel: config.logLevel,\n dryRun: config.dryRun,\n data: config.data,\n subdir: config.subdir,\n overwrite: config.overwrite,\n subdirHelper: config.subdirHelper,\n beforeWrite: undefined,\n tmpDir: config.tmpDir!,\n }\n\n if (config.quiet) {\n config.logLevel = LogLevel.none\n }\n\n const shouldLoadConfig = Boolean(config.config || config.git)\n\n if (shouldLoadConfig) {\n const key = config.key ?? \"default\"\n const configImport = await getConfigFile(config)\n\n if (!configImport[key]) {\n throw new Error(`Template \"${key}\" not found in ${config.config}`)\n }\n\n const imported = configImport[key]\n log(config, LogLevel.debug, \"Imported result\", imported)\n output = {\n ...output,\n ...imported,\n beforeWrite: undefined,\n templates: config.templates || imported.templates,\n output: config.output || imported.output,\n data: {\n ...imported.data,\n ...config.data,\n },\n }\n }\n\n output.data = { ...output.data, ...config.appendData }\n const cmdBeforeWrite = config.beforeWrite\n ? wrapBeforeWrite(config, config.beforeWrite)\n : undefined\n output.beforeWrite = cmdBeforeWrite ?? output.beforeWrite\n if (config.afterScaffold) {\n output.afterScaffold = config.afterScaffold\n }\n\n if (!output.name) {\n throw new Error(\"simple-scaffold: Missing required option: name\")\n }\n\n log(output, LogLevel.debug, \"Parsed config\", output)\n return output\n}\n\n/** Converts a GitHub shorthand (user/repo) to a full HTTPS git URL. @internal */\nexport function githubPartToUrl(part: string): string {\n const gitUrl = new URL(`https://github.com/${part}`)\n if (!gitUrl.pathname.endsWith(\".git\")) {\n gitUrl.pathname += \".git\"\n }\n return gitUrl.toString()\n}\n\n/** Loads a scaffold config from a local file or directory. @internal */\nexport async function getLocalConfig(\n config: ConfigLoadConfig & Partial<LogConfig>,\n): Promise<ScaffoldConfigFile> {\n const { config: configFile, ...logConfig } = config as Required<typeof config>\n\n const absolutePath = path.resolve(process.cwd(), configFile)\n\n const _isDir = await isDir(absolutePath)\n\n if (_isDir) {\n log(logConfig, LogLevel.debug, `Resolving config file from directory ${absolutePath}`)\n const file = await findConfigFile(absolutePath)\n const exists = await pathExists(file)\n if (!exists) {\n throw new Error(`Could not find config file in directory ${absolutePath}`)\n }\n log(logConfig, LogLevel.debug, `Loading config from: ${path.resolve(absolutePath, file)}`)\n return wrapNoopResolver(import(path.resolve(absolutePath, file)))\n }\n\n log(logConfig, LogLevel.debug, `Loading config from: ${absolutePath}`)\n return wrapNoopResolver(import(absolutePath))\n}\n\n/** Loads a scaffold config from a remote git repository. @internal */\nexport async function getRemoteConfig(\n config: RemoteConfigLoadConfig & Partial<LogConfig>,\n): Promise<ScaffoldConfigFile> {\n const { config: configFile, git, tmpDir, ...logConfig } = config as Required<typeof config>\n\n log(\n logConfig,\n LogLevel.debug,\n `Loading config from remote ${git}, config file ${configFile || \"<auto-detect>\"}`,\n )\n\n const url = new URL(git!)\n const isHttp = url.protocol === \"http:\" || url.protocol === \"https:\"\n const isGit = url.protocol === \"git:\" || (isHttp && url.pathname.endsWith(\".git\"))\n\n if (!isGit) {\n throw new Error(`Unsupported protocol ${url.protocol}`)\n }\n\n return getGitConfig(url, configFile, tmpDir, logConfig)\n}\n\n/** Searches for a scaffold config file in the given directory, trying known filenames in order. @internal */\nexport async function findConfigFile(root: string): Promise<string> {\n const allowed = [\"mjs\", \"cjs\", \"js\", \"json\"].reduce((acc, ext) => {\n acc.push(`scaffold.config.${ext}`)\n acc.push(`scaffold.${ext}`)\n acc.push(`.scaffold.${ext}`)\n return acc\n }, [] as string[])\n for (const file of allowed) {\n const exists = await pathExists(path.resolve(root, file))\n if (exists) {\n return file\n }\n }\n throw new Error(`Could not find config file in git repo`)\n}\n","import input from \"@inquirer/input\"\nimport select from \"@inquirer/select\"\nimport confirm from \"@inquirer/confirm\"\nimport number from \"@inquirer/number\"\nimport { colorize } from \"./colors\"\nimport {\n ScaffoldCmdConfig,\n ScaffoldConfig,\n ScaffoldConfigMap,\n ScaffoldInput,\n ScaffoldInputType,\n} from \"./types\"\n\n/** Prompts the user for a scaffold name. */\nexport async function promptForName(): Promise<string> {\n return input({\n message: colorize.cyan(\"Scaffold name:\"),\n required: true,\n validate: (value) => {\n if (!value.trim()) return \"Name cannot be empty\"\n return true\n },\n })\n}\n\n/** Prompts the user to select a template key from the available config keys. */\nexport async function promptForTemplateKey(configMap: ScaffoldConfigMap): Promise<string> {\n const keys = Object.keys(configMap)\n if (keys.length === 0) {\n throw new Error(\"No templates found in config file\")\n }\n if (keys.length === 1) {\n return keys[0]\n }\n return select({\n message: colorize.cyan(\"Select a template:\"),\n choices: keys.map((key) => ({\n name: key,\n value: key,\n })),\n })\n}\n\n/** Prompts the user for an output directory path. */\nexport async function promptForOutput(): Promise<string> {\n return input({\n message: colorize.cyan(\"Output directory:\"),\n required: true,\n default: \".\",\n validate: (value) => {\n if (!value.trim()) return \"Output directory cannot be empty\"\n return true\n },\n })\n}\n\n/** Prompts the user for template paths (comma-separated). */\nexport async function promptForTemplates(): Promise<string[]> {\n const value = await input({\n message: colorize.cyan(\"Template paths (comma-separated):\"),\n required: true,\n validate: (value) => {\n if (!value.trim()) return \"At least one template path is required\"\n return true\n },\n })\n return value\n .split(\",\")\n .map((t) => t.trim())\n .filter(Boolean)\n}\n\n/** Prompts for a single input based on its type. */\nasync function promptSingleInput(\n key: string,\n def: ScaffoldInput,\n): Promise<string | boolean | number | undefined> {\n const type: ScaffoldInputType = def.type ?? \"text\"\n const message = colorize.cyan(def.message ?? `${key}:`)\n\n switch (type) {\n case \"text\":\n return input({\n message,\n required: def.required,\n default: def.default as string | undefined,\n validate: def.required\n ? (value) => {\n if (!value.trim()) return `${key} is required`\n return true\n }\n : undefined,\n })\n\n case \"select\": {\n const choices = (def.options ?? []).map((opt) =>\n typeof opt === \"string\" ? { name: opt, value: opt } : opt,\n )\n if (choices.length === 0) {\n throw new Error(`Input \"${key}\" has type \"select\" but no options defined`)\n }\n return select({\n message,\n choices,\n default: def.default as string | undefined,\n })\n }\n\n case \"confirm\":\n return confirm({\n message,\n default: (def.default as boolean | undefined) ?? false,\n })\n\n case \"number\":\n return (\n (await number({\n message,\n required: def.required,\n default: def.default as number | undefined,\n })) ?? def.default\n )\n }\n}\n\n/**\n * Prompts the user for any required scaffold inputs that are not already provided in data.\n * Also applies default values for optional inputs that have one.\n * Returns the merged data object.\n */\nexport async function promptForInputs(\n inputs: Record<string, ScaffoldInput>,\n existingData: Record<string, unknown> = {},\n): Promise<Record<string, unknown>> {\n const data = { ...existingData }\n\n for (const [key, def] of Object.entries(inputs)) {\n // Skip if already provided via data/CLI\n if (key in data && data[key] !== undefined && data[key] !== \"\") {\n continue\n }\n\n if (def.required || def.type === \"select\" || def.type === \"confirm\") {\n data[key] = await promptSingleInput(key, def)\n } else if (def.default !== undefined && !(key in data)) {\n data[key] = def.default\n }\n }\n\n return data\n}\n\n/** Returns true if the process is running in an interactive terminal. */\nexport function isInteractive(): boolean {\n return Boolean(process.stdin.isTTY)\n}\n\n/**\n * Prompts for name and template key before the config file is parsed.\n * These are needed by parseConfigFile to know which template to load.\n */\nexport async function promptBeforeConfig(\n config: ScaffoldCmdConfig,\n configMap?: ScaffoldConfigMap,\n): Promise<ScaffoldCmdConfig> {\n if (!isInteractive()) {\n return config\n }\n\n if (!config.name) {\n config.name = await promptForName()\n }\n\n if (configMap && !config.key) {\n const keys = Object.keys(configMap)\n if (keys.length > 1) {\n config.key = await promptForTemplateKey(configMap)\n }\n }\n\n return config\n}\n\n/**\n * Prompts for any values still missing after the config file has been parsed.\n * Only prompts in interactive mode.\n */\nexport async function promptAfterConfig(config: ScaffoldConfig): Promise<ScaffoldConfig> {\n if (!isInteractive()) {\n return config\n }\n\n if (!config.output || (typeof config.output === \"string\" && !config.output)) {\n config.output = await promptForOutput()\n }\n\n if (!config.templates || config.templates.length === 0) {\n config.templates = await promptForTemplates()\n }\n\n return config\n}\n\n/**\n * @deprecated Use {@link promptBeforeConfig} and {@link promptAfterConfig} instead.\n */\nexport async function promptForMissingConfig(\n config: ScaffoldCmdConfig,\n configMap?: ScaffoldConfigMap,\n): Promise<ScaffoldCmdConfig> {\n const afterPre = await promptBeforeConfig(config, configMap)\n\n if (!isInteractive()) {\n return afterPre\n }\n\n if (!afterPre.output) {\n afterPre.output = await promptForOutput()\n }\n\n if (!afterPre.templates || afterPre.templates.length === 0) {\n afterPre.templates = await promptForTemplates()\n }\n\n return afterPre\n}\n\n/**\n * Prompts for any required inputs defined in the scaffold config and merges them into data.\n * Only prompts in interactive mode; in non-interactive mode, only applies defaults.\n */\nexport async function resolveInputs(config: ScaffoldConfig): Promise<ScaffoldConfig> {\n if (!config.inputs) {\n return config\n }\n\n const interactive = isInteractive()\n\n if (interactive) {\n config.data = await promptForInputs(config.inputs, config.data)\n } else {\n // Non-interactive: only apply defaults\n const data = { ...config.data }\n for (const [key, def] of Object.entries(config.inputs)) {\n if (def.default !== undefined && !(key in data)) {\n data[key] = def.default\n }\n }\n config.data = data\n }\n\n return config\n}\n","import path from \"node:path\"\nimport fs from \"node:fs/promises\"\nimport { minimatch } from \"minimatch\"\nimport { pathExists } from \"./fs-utils\"\n\nconst IGNORE_FILENAME = \".scaffoldignore\"\n\n/**\n * Reads a `.scaffoldignore` file from the given directory and returns\n * the parsed patterns for filtering.\n *\n * Lines starting with `#` are comments. Empty lines are skipped.\n *\n * @param dir The directory to search for `.scaffoldignore`\n * @returns Array of glob patterns to ignore\n */\nexport async function loadIgnorePatterns(dir: string): Promise<string[]> {\n const ignorePath = path.resolve(dir, IGNORE_FILENAME)\n\n if (!(await pathExists(ignorePath))) {\n return []\n }\n\n const content = await fs.readFile(ignorePath, \"utf-8\")\n return parseIgnoreFile(content)\n}\n\n/**\n * Parses the contents of a `.scaffoldignore` file into glob patterns.\n * @internal\n */\nexport function parseIgnoreFile(content: string): string[] {\n return content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line.length > 0 && !line.startsWith(\"#\"))\n}\n\n/**\n * Filters a list of file paths, removing any that match the ignore patterns.\n * Patterns are matched against the relative path from baseDir.\n * Also always excludes `.scaffoldignore` itself.\n */\nexport function filterIgnoredFiles(\n files: string[],\n ignorePatterns: string[],\n baseDir: string,\n): string[] {\n return files.filter((file) => {\n const basename = path.basename(file)\n if (basename === IGNORE_FILENAME) {\n return false\n }\n\n const relPath = path.relative(baseDir, file)\n\n for (const pattern of ignorePatterns) {\n if (\n minimatch(relPath, pattern, { dot: true }) ||\n minimatch(basename, pattern, { dot: true })\n ) {\n return false\n }\n }\n return true\n })\n}\n","import { z } from \"zod/v4\"\nimport { pathExists } from \"./fs-utils\"\n\n// --- Reusable schemas ---\n\n/** Schema for a JavaScript function value. */\nconst functionSchema = z\n .any()\n .refine((v) => typeof v === \"function\", { message: \"Expected a function\" })\n\n/** Schema for a value that can be either a string or a function. */\nconst stringOrFunctionSchema = z.union([z.string(), functionSchema])\n\n/** Schema for a value that can be either a boolean or a function. */\nconst booleanOrFunctionSchema = z.union([z.boolean(), functionSchema])\n\n/** Schema for a select input option — either a plain string or a `{ name, value }` object. */\nconst selectOptionSchema = z.union([z.string(), z.object({ name: z.string(), value: z.string() })])\n\n/** Schema for the input type enum. */\nconst inputTypeSchema = z.enum([\"text\", \"select\", \"confirm\", \"number\"])\n\n/** Schema for the log level enum. */\nconst logLevelSchema = z.enum([\"none\", \"debug\", \"info\", \"warning\", \"error\"])\n\n// --- Input schema ---\n\n/** Zod schema for a single scaffold input definition. */\nconst scaffoldInputSchema = z.object({\n type: inputTypeSchema.optional(),\n message: z.string().optional(),\n required: z.boolean().optional(),\n default: z.union([z.string(), z.boolean(), z.number()]).optional(),\n options: z.array(selectOptionSchema).optional(),\n})\n\ntype InputDef = z.infer<typeof scaffoldInputSchema>\n\nfunction validateInputSemantics(\n key: string,\n input: InputDef,\n): { path: (string | number)[]; message: string }[] {\n const issues: { path: (string | number)[]; message: string }[] = []\n if (input.type === \"select\" && (!input.options || input.options.length === 0)) {\n issues.push({\n path: [\"inputs\", key, \"options\"],\n message: \"select input must have a non-empty options array\",\n })\n }\n if (\n input.type === \"confirm\" &&\n input.default !== undefined &&\n typeof input.default !== \"boolean\"\n ) {\n issues.push({\n path: [\"inputs\", key, \"default\"],\n message: \"confirm input default must be a boolean\",\n })\n }\n if (input.type === \"number\" && input.default !== undefined && typeof input.default !== \"number\") {\n issues.push({\n path: [\"inputs\", key, \"default\"],\n message: \"number input default must be a number\",\n })\n }\n return issues\n}\n\n// --- Config schema ---\n\n/** Zod schema for ScaffoldConfig. */\nconst scaffoldConfigSchema = z\n .object({\n name: z.string().min(1, \"name is required\"),\n templates: z.array(z.string()).min(1, \"templates must contain at least one entry\"),\n output: stringOrFunctionSchema,\n subdir: z.boolean().optional(),\n data: z.record(z.string(), z.unknown()).optional(),\n overwrite: booleanOrFunctionSchema.optional(),\n logLevel: logLevelSchema.optional(),\n dryRun: z.boolean().optional(),\n helpers: z.record(z.string(), functionSchema).optional(),\n subdirHelper: z.string().optional(),\n inputs: z.record(z.string(), scaffoldInputSchema).optional(),\n beforeWrite: functionSchema.optional(),\n afterScaffold: stringOrFunctionSchema.optional(),\n tmpDir: z.string().optional(),\n })\n .check((ctx) => {\n const config = ctx.value\n\n if (config.subdirHelper && !config.subdir) {\n ctx.issues.push({\n code: \"custom\",\n message: \"subdirHelper is set but subdir is not enabled\",\n path: [\"subdirHelper\"],\n input: config,\n })\n }\n\n if (config.inputs) {\n for (const [key, val] of Object.entries(config.inputs)) {\n for (const issue of validateInputSemantics(key, val)) {\n ctx.issues.push({ code: \"custom\", ...issue, input: config })\n }\n }\n }\n })\n\nexport {\n scaffoldConfigSchema,\n scaffoldInputSchema,\n functionSchema,\n stringOrFunctionSchema,\n booleanOrFunctionSchema,\n selectOptionSchema,\n inputTypeSchema,\n logLevelSchema,\n}\n\n/**\n * Validates a scaffold config and returns a list of human-readable errors.\n * Returns an empty array if the config is valid.\n */\nexport function validateConfig(config: unknown): string[] {\n const result = scaffoldConfigSchema.safeParse(config)\n if (result.success) {\n return []\n }\n return result.error.issues.map((issue) => {\n const path = issue.path.length > 0 ? issue.path.join(\".\") : \"(root)\"\n return `${path}: ${issue.message}`\n })\n}\n\n/**\n * Validates template paths exist on disk.\n * Only checks non-glob, non-negation paths.\n */\nexport async function validateTemplatePaths(templates: string[]): Promise<string[]> {\n const errors: string[] = []\n for (const tpl of templates) {\n if (tpl.startsWith(\"!\") || tpl.includes(\"*\")) continue\n if (!(await pathExists(tpl))) {\n errors.push(`templates: path does not exist: ${tpl}`)\n }\n }\n return errors\n}\n\n/**\n * Validates the config and throws a formatted error if any issues are found.\n * Checks both schema validity and template path existence.\n */\nexport async function assertConfigValid(config: unknown): Promise<void> {\n const schemaErrors = validateConfig(config)\n\n const pathErrors =\n config &&\n typeof config === \"object\" &&\n \"templates\" in config &&\n Array.isArray((config as { templates: unknown }).templates)\n ? await validateTemplatePaths((config as { templates: string[] }).templates)\n : []\n\n const allErrors = [...schemaErrors, ...pathErrors]\n if (allErrors.length > 0) {\n const lines = allErrors.map((e) => ` - ${e}`)\n throw new Error(`Invalid scaffold config:\\n${lines.join(\"\\n\")}`)\n }\n}\n","/**\n * @module\n * Simple Scaffold\n *\n * See [readme](README.md)\n */\nimport path from \"node:path\"\nimport os from \"node:os\"\nimport { exec } from \"node:child_process\"\n\nimport { handleErr, resolve } from \"./utils\"\nimport { isDir, getTemplateGlobInfo, getFileList, handleTemplateFile, GlobInfo } from \"./file\"\nimport { removeGlob, makeRelativePath, getBasePath } from \"./path-utils\"\nimport { LogLevel, MinimalConfig, Resolver, ScaffoldCmdConfig, ScaffoldConfig } from \"./types\"\nimport { registerHelpers } from \"./parser\"\nimport { log, logInitStep, logFileTree, logSummary } from \"./logger\"\nimport { parseConfigFile } from \"./config\"\nimport { resolveInputs } from \"./prompts\"\nimport { loadIgnorePatterns, filterIgnoredFiles } from \"./ignore\"\nimport { assertConfigValid } from \"./validate\"\n\n/**\n * Create a scaffold using given `options`.\n *\n * #### Create files\n * To create a file structure to output, use any directory and file structure you would like.\n * Inside folder names, file names or file contents, you may place `{{ var }}` where `var` is either\n * `name` which is the scaffold name you provided or one of the keys you provided in the `data` option.\n *\n * The contents and names will be replaced with the transformed values so you can use your original structure as a\n * boilerplate for other projects, components, modules, or even single files.\n *\n * The files will maintain their structure, starting from the directory containing the template (or the template itself\n * if it is already a directory), and will output from that directory into the directory defined by `config.output`.\n *\n * #### Helpers\n * Helpers are functions you can use to transform your `{{ var }}` contents into other values without having to\n * pre-define the data and use a duplicated key.\n *\n * Any functions you provide in `helpers` option will also be available to you to make custom formatting as you see fit\n * (for example, formatting a date)\n *\n * For available default values, see {@link DefaultHelpers}.\n *\n * @param {ScaffoldConfig} config The main configuration object\n * @return {Promise<void>} A promise that resolves when the scaffold is complete\n *\n * @see {@link DefaultHelpers}\n * @see {@link CaseHelpers}\n * @see {@link DateHelpers}\n *\n * @category Main\n */\nexport async function Scaffold(config: ScaffoldConfig): Promise<void> {\n config.output ??= process.cwd()\n\n await assertConfigValid(config)\n config = await resolveInputs(config)\n registerHelpers(config)\n\n const startTime = performance.now()\n const writtenFiles: string[] = []\n try {\n config.data = { name: config.name, ...config.data }\n logInitStep(config)\n\n log(config, LogLevel.info, `Scaffolding \"${config.name}\"...`)\n\n const excludes = config.templates.filter((t) => t.startsWith(\"!\"))\n const includes = config.templates.filter((t) => !t.startsWith(\"!\"))\n\n const templates = await resolveTemplateGlobs(config, includes)\n\n for (const tpl of templates) {\n const files = await processTemplateGlob(config, tpl, excludes)\n writtenFiles.push(...files)\n }\n } catch (e: unknown) {\n log(config, LogLevel.error, e)\n throw e\n }\n\n const elapsed = performance.now() - startTime\n\n logFileTree(config, writtenFiles)\n logSummary(config, writtenFiles.length, elapsed, config.dryRun)\n\n if (config.afterScaffold) {\n await runAfterScaffoldHook(config, writtenFiles)\n }\n}\n\n/** Resolves included template paths into GlobInfo objects. */\nasync function resolveTemplateGlobs(\n config: ScaffoldConfig,\n includes: string[],\n): Promise<GlobInfo[]> {\n const templates: GlobInfo[] = []\n for (const includedTemplate of includes) {\n try {\n templates.push(await getTemplateGlobInfo(config, includedTemplate))\n } catch (e: unknown) {\n handleErr(e as NodeJS.ErrnoException)\n }\n }\n return templates\n}\n\n/** Processes all files matching a single template glob pattern. Returns paths of written files. */\nasync function processTemplateGlob(\n config: ScaffoldConfig,\n tpl: GlobInfo,\n excludes: string[],\n): Promise<string[]> {\n const written: string[] = []\n\n // Load .scaffoldignore from the template base directory\n const ignorePatterns = await loadIgnorePatterns(tpl.baseTemplatePath)\n if (ignorePatterns.length > 0) {\n log(config, LogLevel.debug, `Loaded .scaffoldignore patterns:`, ignorePatterns)\n }\n\n const allFiles = await getFileList(config, [tpl.template, ...excludes])\n const files = filterIgnoredFiles(allFiles, ignorePatterns, tpl.baseTemplatePath)\n for (const file of files) {\n if (await isDir(file)) {\n continue\n }\n log(config, LogLevel.debug, \"Iterating files\", { files, file })\n const relPath = makeRelativePath(\n path.dirname(removeGlob(file).replace(tpl.baseTemplatePath, \"\")),\n )\n const basePath = getBasePath(relPath)\n\n log(config, LogLevel.debug, {\n originalTemplate: tpl.origTemplate,\n relativePath: relPath,\n parsedTemplate: tpl.template,\n inputFilePath: file,\n baseTemplatePath: tpl.baseTemplatePath,\n basePath,\n isDirOrGlob: tpl.isDirOrGlob,\n isGlob: tpl.isGlob,\n })\n\n const outputPath = await handleTemplateFile(config, { templatePath: file, basePath })\n if (outputPath) {\n written.push(outputPath)\n }\n }\n return written\n}\n\n/** Executes the afterScaffold hook — either a function or a shell command string. */\nasync function runAfterScaffoldHook(config: ScaffoldConfig, files: string[]): Promise<void> {\n const hook = config.afterScaffold!\n\n if (typeof hook === \"function\") {\n log(config, LogLevel.debug, \"Running afterScaffold function hook\")\n await hook({ config, files })\n return\n }\n\n // Shell command string\n const outputDir = typeof config.output === \"string\" ? config.output : process.cwd()\n const cwd = path.resolve(process.cwd(), outputDir)\n\n log(config, LogLevel.info, `Running afterScaffold command: ${hook}`)\n await new Promise<void>((resolve, reject) => {\n const proc = exec(hook, { cwd })\n proc.stdout?.on(\"data\", (data: string) => {\n log(config, LogLevel.info, data.toString().trimEnd())\n })\n proc.stderr?.on(\"data\", (data: string) => {\n log(config, LogLevel.warning, data.toString().trimEnd())\n })\n proc.on(\"close\", (code) => {\n if (code === 0) {\n resolve()\n } else {\n reject(new Error(`afterScaffold command exited with code ${code}`))\n }\n })\n proc.on(\"error\", reject)\n })\n}\n\n/**\n * Create a scaffold based on a config file or URL.\n *\n * @param {string} pathOrUrl The path or URL to the config file\n * @param {Record<string, string>} config Information needed before loading the config\n * @param {Partial<Omit<ScaffoldConfig, 'name'>>} overrides Any overrides to the loaded config\n *\n * @see {@link Scaffold}\n * @category Main\n * @return {Promise<void>} A promise that resolves when the scaffold is complete\n */\nScaffold.fromConfig = async function (\n pathOrUrl: string,\n config: MinimalConfig,\n overrides?: Resolver<ScaffoldCmdConfig, Partial<Omit<ScaffoldConfig, \"name\">>>,\n): Promise<void> {\n const tmpPath = path.resolve(os.tmpdir(), `scaffold-config-${Date.now()}`)\n const _cmdConfig: ScaffoldCmdConfig = {\n dryRun: false,\n output: process.cwd(),\n logLevel: LogLevel.info,\n overwrite: false,\n templates: [],\n subdir: false,\n quiet: false,\n config: pathOrUrl,\n version: false,\n tmpDir: tmpPath,\n ...config,\n }\n const _overrides = resolve(overrides, _cmdConfig)\n const _config = await parseConfigFile(_cm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EACX,UAAS;OAET,wBAAO,IAAI,MAAM,0CAA0C,OAAO,CAAC;IAErE;AACF,OAAK,GAAG,SAAS,OAAO;GACxB;;;;;;;;;;;;;AAcJ,SAAS,aAAa,eACpB,WACA,QACA,WACe;CACf,MAAM,UAAU,UAAA,QAAK,QAAQ,QAAA,QAAG,QAAQ,EAAE,mBAAmB,KAAK,KAAK,GAAG;CAC1E,MAAM,aAAgC;EACpC,QAAQ;EACR,QAAQ,QAAQ,KAAK;EACrB,UAAU,SAAS;EACnB,WAAW;EACX,WAAW,EAAE;EACb,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,GAAG;EACJ;CACD,MAAM,aAAa,QAAQ,WAAW,WAAW;AAEjD,QAAO,SAAS;EAAE,GADF,MAAM,gBAAgB,WAAW;EACnB,GAAG;EAAY,CAAC"}
|
package/types.d.ts
CHANGED
|
@@ -150,9 +150,112 @@ export interface ScaffoldConfig {
|
|
|
150
150
|
* contents-only, after further modifications - or `undefined` to use the original content (i.e. `content.toString()`)
|
|
151
151
|
*/
|
|
152
152
|
beforeWrite?(content: Buffer, rawContent: Buffer, outputPath: string): string | Buffer | undefined | Promise<string | Buffer | undefined>;
|
|
153
|
+
/**
|
|
154
|
+
* Defines interactive inputs for the template. Each input becomes a template data variable.
|
|
155
|
+
*
|
|
156
|
+
* When running interactively, required inputs that are not already provided via `data` or CLI args
|
|
157
|
+
* will be prompted for. Optional inputs without a value will use their `default` if defined.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* Scaffold({
|
|
162
|
+
* // ...
|
|
163
|
+
* inputs: {
|
|
164
|
+
* author: { message: "Author name", required: true },
|
|
165
|
+
* license: { message: "License", default: "MIT" },
|
|
166
|
+
* },
|
|
167
|
+
* })
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* In templates: `{{ author }}`, `{{ license }}`
|
|
171
|
+
*
|
|
172
|
+
* @see {@link ScaffoldInput}
|
|
173
|
+
*/
|
|
174
|
+
inputs?: Record<string, ScaffoldInput>;
|
|
175
|
+
/**
|
|
176
|
+
* A callback or shell command that runs after all files have been written.
|
|
177
|
+
*
|
|
178
|
+
* When provided as a **function** (Node.js API), it receives a context object with the scaffold
|
|
179
|
+
* config and the list of files that were written:
|
|
180
|
+
*
|
|
181
|
+
* ```typescript
|
|
182
|
+
* Scaffold({
|
|
183
|
+
* // ...
|
|
184
|
+
* afterScaffold: async ({ config, files }) => {
|
|
185
|
+
* console.log(`Created ${files.length} files`)
|
|
186
|
+
* execSync("npm install", { cwd: config.output })
|
|
187
|
+
* },
|
|
188
|
+
* })
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* When provided as a **string** (CLI `--after` flag), it is executed as a shell command
|
|
192
|
+
* in the output directory after scaffolding completes.
|
|
193
|
+
*
|
|
194
|
+
* @see {@link AfterScaffoldContext}
|
|
195
|
+
*/
|
|
196
|
+
afterScaffold?: AfterScaffoldHook;
|
|
153
197
|
/** @internal */
|
|
154
198
|
tmpDir?: string;
|
|
155
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Context passed to the {@link ScaffoldConfig.afterScaffold} hook.
|
|
202
|
+
*
|
|
203
|
+
* @category Config
|
|
204
|
+
*/
|
|
205
|
+
export interface AfterScaffoldContext {
|
|
206
|
+
/** The resolved scaffold config that was used. */
|
|
207
|
+
config: ScaffoldConfig;
|
|
208
|
+
/** List of absolute paths to files that were written. */
|
|
209
|
+
files: string[];
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* A hook that runs after scaffolding completes.
|
|
213
|
+
* Can be a function receiving context, or a shell command string.
|
|
214
|
+
*
|
|
215
|
+
* @category Config
|
|
216
|
+
*/
|
|
217
|
+
export type AfterScaffoldHook = ((context: AfterScaffoldContext) => void | Promise<void>) | string;
|
|
218
|
+
/**
|
|
219
|
+
* The type of an interactive input prompt.
|
|
220
|
+
*
|
|
221
|
+
* - `"text"` — free-form text input (default)
|
|
222
|
+
* - `"select"` — choose from a list of options
|
|
223
|
+
* - `"confirm"` — yes/no boolean prompt
|
|
224
|
+
* - `"number"` — numeric input
|
|
225
|
+
*
|
|
226
|
+
* @category Config
|
|
227
|
+
*/
|
|
228
|
+
export type ScaffoldInputType = "text" | "select" | "confirm" | "number";
|
|
229
|
+
/**
|
|
230
|
+
* Defines a single interactive input for a scaffold template.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* inputs: {
|
|
235
|
+
* author: { message: "Author name", required: true },
|
|
236
|
+
* license: { type: "select", message: "License", options: ["MIT", "Apache-2.0", "GPL-3.0"] },
|
|
237
|
+
* private: { type: "confirm", message: "Private package?", default: false },
|
|
238
|
+
* port: { type: "number", message: "Dev server port", default: 3000 },
|
|
239
|
+
* }
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* @category Config
|
|
243
|
+
*/
|
|
244
|
+
export interface ScaffoldInput {
|
|
245
|
+
/** The type of prompt. Defaults to `"text"`. */
|
|
246
|
+
type?: ScaffoldInputType;
|
|
247
|
+
/** The prompt message shown to the user. Defaults to the input key name if omitted. */
|
|
248
|
+
message?: string;
|
|
249
|
+
/** Whether this input must be provided. If true and missing, the user will be prompted interactively. */
|
|
250
|
+
required?: boolean;
|
|
251
|
+
/** Default value. Type depends on the input type: string for text/select, boolean for confirm, number for number. */
|
|
252
|
+
default?: string | boolean | number;
|
|
253
|
+
/** List of options for `type: "select"`. Each can be a string or `{ name, value }`. */
|
|
254
|
+
options?: (string | {
|
|
255
|
+
name: string;
|
|
256
|
+
value: string;
|
|
257
|
+
})[];
|
|
258
|
+
}
|
|
156
259
|
/**
|
|
157
260
|
* The names of the available helper functions that relate to text capitalization.
|
|
158
261
|
*
|
|
@@ -308,6 +411,8 @@ export type FileResponse<T> = T | FileResponseHandler<T>;
|
|
|
308
411
|
* Contains less and more specific options than {@link ScaffoldConfig}.
|
|
309
412
|
*
|
|
310
413
|
* For more information about each option, see {@link ScaffoldConfig}.
|
|
414
|
+
*
|
|
415
|
+
* @internal
|
|
311
416
|
*/
|
|
312
417
|
export type ScaffoldCmdConfig = {
|
|
313
418
|
/** The name of the scaffold template to use. */
|
|
@@ -346,6 +451,8 @@ export type ScaffoldCmdConfig = {
|
|
|
346
451
|
version: boolean;
|
|
347
452
|
/** Run a script before writing the files. This can be a command or a path to a file. The file contents will be passed to the given command. */
|
|
348
453
|
beforeWrite?: string;
|
|
454
|
+
/** Run a shell command after all files have been written. Executed in the output directory. */
|
|
455
|
+
afterScaffold?: string;
|
|
349
456
|
/** @internal */
|
|
350
457
|
tmpDir?: string;
|
|
351
458
|
};
|
|
@@ -360,6 +467,7 @@ export type ScaffoldCmdConfig = {
|
|
|
360
467
|
*
|
|
361
468
|
* @see {@link ScaffoldConfig}
|
|
362
469
|
*
|
|
470
|
+
* @internal
|
|
363
471
|
* @category Config
|
|
364
472
|
*/
|
|
365
473
|
export type ScaffoldConfigMap = Record<string, ScaffoldConfig>;
|
|
@@ -370,6 +478,7 @@ export type ScaffoldConfigMap = Record<string, ScaffoldConfig>;
|
|
|
370
478
|
* - A promise that resolves to a {@link ScaffoldConfigMap} object
|
|
371
479
|
* - A function that returns a promise that resolves to a {@link ScaffoldConfigMap} object
|
|
372
480
|
*
|
|
481
|
+
* @internal
|
|
373
482
|
* @category Config
|
|
374
483
|
*/
|
|
375
484
|
export type ScaffoldConfigFile = AsyncResolver<ScaffoldCmdConfig, ScaffoldConfigMap>;
|
|
@@ -385,4 +494,5 @@ export type ConfigLoadConfig = LogConfig & Pick<ScaffoldCmdConfig, "config">;
|
|
|
385
494
|
export type RemoteConfigLoadConfig = LogConfig & Pick<ScaffoldCmdConfig, "config" | "git" | "tmpDir">;
|
|
386
495
|
/** @internal */
|
|
387
496
|
export type MinimalConfig = Pick<ScaffoldCmdConfig, "name" | "key">;
|
|
497
|
+
/** @internal */
|
|
388
498
|
export type ListCommandCliOptions = Pick<ScaffoldCmdConfig, "config" | "git" | "logLevel" | "quiet">;
|
package/utils.d.ts
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
import { Resolver } from "./types";
|
|
2
|
+
export { colorize, type TermColor } from "./colors";
|
|
3
|
+
/** Throws the error if non-null, no-ops otherwise. */
|
|
2
4
|
export declare function handleErr(err: NodeJS.ErrnoException | null): void;
|
|
5
|
+
/** Resolves a value that may be either a static value or a function that produces one. */
|
|
3
6
|
export declare function resolve<T, R = T>(resolver: Resolver<T, R>, arg: T): R;
|
|
7
|
+
/** Wraps a static value in a resolver function. If already a function, returns as-is. */
|
|
4
8
|
export declare function wrapNoopResolver<T, R = T>(value: Resolver<T, R>): Resolver<T, R>;
|
|
5
|
-
declare const colorMap: {
|
|
6
|
-
readonly reset: 0;
|
|
7
|
-
readonly dim: 2;
|
|
8
|
-
readonly bold: 1;
|
|
9
|
-
readonly italic: 3;
|
|
10
|
-
readonly underline: 4;
|
|
11
|
-
readonly red: 31;
|
|
12
|
-
readonly green: 32;
|
|
13
|
-
readonly yellow: 33;
|
|
14
|
-
readonly blue: 34;
|
|
15
|
-
readonly magenta: 35;
|
|
16
|
-
readonly cyan: 36;
|
|
17
|
-
readonly white: 37;
|
|
18
|
-
readonly gray: 90;
|
|
19
|
-
};
|
|
20
|
-
export type TermColor = keyof typeof colorMap;
|
|
21
|
-
declare function _colorize(text: string, color: TermColor): string;
|
|
22
|
-
declare const createColorize: (color: TermColor) => (template: TemplateStringsArray | unknown, ...params: unknown[]) => string;
|
|
23
|
-
type TemplateStringsFn = ReturnType<typeof createColorize> & ((text: string) => string);
|
|
24
|
-
type TemplateStringsFns = {
|
|
25
|
-
[key in TermColor]: TemplateStringsFn;
|
|
26
|
-
};
|
|
27
|
-
export declare const colorize: typeof _colorize & TemplateStringsFns;
|
|
28
|
-
export {};
|
package/validate.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
/** Schema for a JavaScript function value. */
|
|
3
|
+
declare const functionSchema: z.ZodAny;
|
|
4
|
+
/** Schema for a value that can be either a string or a function. */
|
|
5
|
+
declare const stringOrFunctionSchema: z.ZodUnion<readonly [z.ZodString, z.ZodAny]>;
|
|
6
|
+
/** Schema for a value that can be either a boolean or a function. */
|
|
7
|
+
declare const booleanOrFunctionSchema: z.ZodUnion<readonly [z.ZodBoolean, z.ZodAny]>;
|
|
8
|
+
/** Schema for a select input option — either a plain string or a `{ name, value }` object. */
|
|
9
|
+
declare const selectOptionSchema: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
10
|
+
name: z.ZodString;
|
|
11
|
+
value: z.ZodString;
|
|
12
|
+
}, z.core.$strip>]>;
|
|
13
|
+
/** Schema for the input type enum. */
|
|
14
|
+
declare const inputTypeSchema: z.ZodEnum<{
|
|
15
|
+
number: "number";
|
|
16
|
+
text: "text";
|
|
17
|
+
select: "select";
|
|
18
|
+
confirm: "confirm";
|
|
19
|
+
}>;
|
|
20
|
+
/** Schema for the log level enum. */
|
|
21
|
+
declare const logLevelSchema: z.ZodEnum<{
|
|
22
|
+
none: "none";
|
|
23
|
+
debug: "debug";
|
|
24
|
+
info: "info";
|
|
25
|
+
warning: "warning";
|
|
26
|
+
error: "error";
|
|
27
|
+
}>;
|
|
28
|
+
/** Zod schema for a single scaffold input definition. */
|
|
29
|
+
declare const scaffoldInputSchema: z.ZodObject<{
|
|
30
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
31
|
+
number: "number";
|
|
32
|
+
text: "text";
|
|
33
|
+
select: "select";
|
|
34
|
+
confirm: "confirm";
|
|
35
|
+
}>>;
|
|
36
|
+
message: z.ZodOptional<z.ZodString>;
|
|
37
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodNumber]>>;
|
|
39
|
+
options: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
40
|
+
name: z.ZodString;
|
|
41
|
+
value: z.ZodString;
|
|
42
|
+
}, z.core.$strip>]>>>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
/** Zod schema for ScaffoldConfig. */
|
|
45
|
+
declare const scaffoldConfigSchema: z.ZodObject<{
|
|
46
|
+
name: z.ZodString;
|
|
47
|
+
templates: z.ZodArray<z.ZodString>;
|
|
48
|
+
output: z.ZodUnion<readonly [z.ZodString, z.ZodAny]>;
|
|
49
|
+
subdir: z.ZodOptional<z.ZodBoolean>;
|
|
50
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
51
|
+
overwrite: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodAny]>>;
|
|
52
|
+
logLevel: z.ZodOptional<z.ZodEnum<{
|
|
53
|
+
none: "none";
|
|
54
|
+
debug: "debug";
|
|
55
|
+
info: "info";
|
|
56
|
+
warning: "warning";
|
|
57
|
+
error: "error";
|
|
58
|
+
}>>;
|
|
59
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
60
|
+
helpers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
61
|
+
subdirHelper: z.ZodOptional<z.ZodString>;
|
|
62
|
+
inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
63
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
64
|
+
number: "number";
|
|
65
|
+
text: "text";
|
|
66
|
+
select: "select";
|
|
67
|
+
confirm: "confirm";
|
|
68
|
+
}>>;
|
|
69
|
+
message: z.ZodOptional<z.ZodString>;
|
|
70
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
71
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodNumber]>>;
|
|
72
|
+
options: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
73
|
+
name: z.ZodString;
|
|
74
|
+
value: z.ZodString;
|
|
75
|
+
}, z.core.$strip>]>>>;
|
|
76
|
+
}, z.core.$strip>>>;
|
|
77
|
+
beforeWrite: z.ZodOptional<z.ZodAny>;
|
|
78
|
+
afterScaffold: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodAny]>>;
|
|
79
|
+
tmpDir: z.ZodOptional<z.ZodString>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
export { scaffoldConfigSchema, scaffoldInputSchema, functionSchema, stringOrFunctionSchema, booleanOrFunctionSchema, selectOptionSchema, inputTypeSchema, logLevelSchema, };
|
|
82
|
+
/**
|
|
83
|
+
* Validates a scaffold config and returns a list of human-readable errors.
|
|
84
|
+
* Returns an empty array if the config is valid.
|
|
85
|
+
*/
|
|
86
|
+
export declare function validateConfig(config: unknown): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Validates template paths exist on disk.
|
|
89
|
+
* Only checks non-glob, non-negation paths.
|
|
90
|
+
*/
|
|
91
|
+
export declare function validateTemplatePaths(templates: string[]): Promise<string[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Validates the config and throws a formatted error if any issues are found.
|
|
94
|
+
* Checks both schema validity and template path existence.
|
|
95
|
+
*/
|
|
96
|
+
export declare function assertConfigValid(config: unknown): Promise<void>;
|