mirror of
https://github.com/chenasraf/simple-scaffold.git
synced 2026-05-17 17:28:09 +00:00
feat!: rename verbose to logLevel
This commit is contained in:
@@ -21,8 +21,8 @@ To see this and more information anytime, add the `-h` or `--help` flag to your
|
||||
| `--append-data`\|`-D` | Append additional custom data to the templates, which will overwrite --data, using an alternate syntax, which is easier to use with CLI: -D key1=string -D key2:=raw |
|
||||
| `--create-sub-folder`\|`-s` | Create subfolder with the input name (default: false) |
|
||||
| `--sub-folder-name-helper`\|`-sh` | Default helper to apply to subfolder name when using `--create-sub-folder true`. |
|
||||
| `--quiet`\|`-q` | Suppress output logs (Same as --verbose 0) (default: false) |
|
||||
| `--verbose`\|`-v` | Determine amount of logs to display. The values are: 0 (none) \| 1 (debug) \| 2 (info) \| 3 (warn) \| 4 (error). The provided level will display messages of the same level or higher. (default: 2) |
|
||||
| `--quiet`\|`-q` | Suppress output logs (Same as --log-level 0) (default: false) |
|
||||
| `--log-level`\|`-v` | Determine amount of logs to display. The values are: 0 (none) \| 1 (debug) \| 2 (info) \| 3 (warn) \| 4 (error). The provided level will display messages of the same level or higher. (default: 2) |
|
||||
| `--dry-run`\|`-dr` | 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. (default: false) |
|
||||
|
||||
## Examples:
|
||||
|
||||
@@ -18,8 +18,7 @@ example:
|
||||
}
|
||||
```
|
||||
|
||||
The configuration contents are identical to the
|
||||
[Node.js configuration structure](https://chenasraf.github.io/simple-scaffold/pages/node.md):
|
||||
The configuration contents are identical to the [Node.js configuration structure](./node):
|
||||
|
||||
```ts
|
||||
interface ScaffoldConfig {
|
||||
@@ -29,8 +28,7 @@ interface ScaffoldConfig {
|
||||
createSubFolder?: boolean
|
||||
data?: Record<string, any>
|
||||
overwrite?: FileResponse<boolean>
|
||||
quiet?: boolean
|
||||
verbose?: LogLevel
|
||||
logLevel?: LogLevel
|
||||
dryRun?: boolean
|
||||
helpers?: Record<string, Helper>
|
||||
subFolderNameHelper?: DefaultHelpers | string
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
reading the docs can tell). Alternatively, you can inject the transformed name into your `data`
|
||||
manually using a scaffold config file, by using the Node API or by appending the data to the CLI
|
||||
invocation.
|
||||
- `verbose` can now take the names `debug`, `info`, `warn`, `error` or `none` (case insensitive) or
|
||||
as usual by using the numbering from before.
|
||||
- `verbose` has been renamed to `log-level`, and now takes the names `debug`, `info`, `warn`,
|
||||
`error` or `none` (case insensitive) instead of using the numbering from before.
|
||||
- All boolean flags no longer take a value. `-q` instead of `-q 1` or `-q true`, `-s` instead of
|
||||
`-s 1`, `-w` instead of `-w 1`, etc.
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ interface ScaffoldConfig {
|
||||
createSubFolder?: boolean
|
||||
data?: Record<string, any>
|
||||
overwrite?: FileResponse<boolean>
|
||||
quiet?: boolean
|
||||
verbose?: LogLevel
|
||||
logLevel?: LogLevel
|
||||
dryRun?: boolean
|
||||
helpers?: Record<string, Helper>
|
||||
subFolderNameHelper?: DefaultHelpers | string
|
||||
|
||||
10
src/cmd.ts
10
src/cmd.ts
@@ -105,15 +105,15 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
|
||||
name: "quiet",
|
||||
aliases: ["q"],
|
||||
defaultValue: false,
|
||||
description: "Suppress output logs (Same as --verbose 0)",
|
||||
description: "Suppress output logs (Same as --log-level none)",
|
||||
})
|
||||
.option({
|
||||
name: "verbose",
|
||||
aliases: ["v"],
|
||||
defaultValue: LogLevel.Info,
|
||||
name: "log-level",
|
||||
aliases: ["l"],
|
||||
defaultValue: LogLevel.info,
|
||||
description:
|
||||
"Determine amount of logs to display. The values are: " +
|
||||
`${chalk.bold`0 (none) | 1 (debug) | 2 (info) | 3 (warn) | 4 (error)`}. ` +
|
||||
`${chalk.bold`none | debug | info | warn | error`}. ` +
|
||||
"The provided level will display messages of the same level or higher.",
|
||||
parse: Number,
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
ConfigLoadConfig,
|
||||
FileResponse,
|
||||
FileResponseHandler,
|
||||
LogConfig,
|
||||
LogLevel,
|
||||
ScaffoldCmdConfig,
|
||||
ScaffoldConfig,
|
||||
@@ -46,19 +47,23 @@ function isWrappedWithQuotes(string: string): boolean {
|
||||
/** @internal */
|
||||
export async function parseConfigFile(config: ScaffoldCmdConfig): Promise<ScaffoldConfig> {
|
||||
let c: ScaffoldConfig = config
|
||||
|
||||
if (config.quiet) {
|
||||
config.logLevel = LogLevel.none
|
||||
}
|
||||
|
||||
if (config.github) {
|
||||
log(config, LogLevel.Info, `Loading config from github ${config.github}`)
|
||||
log(config, LogLevel.info, `Loading config from github ${config.github}`)
|
||||
config.config = githubPartToUrl(config.github)
|
||||
}
|
||||
|
||||
if (config.config) {
|
||||
const { configFile, key, isRemote } = parseConfigSelection(config.config, config.key)
|
||||
log(config, LogLevel.Info, `Loading config from ${configFile} with key ${key}`)
|
||||
log(config, LogLevel.info, `Loading config from ${configFile} with key ${key}`)
|
||||
const configPromise = await getConfig({
|
||||
config: configFile,
|
||||
isRemote,
|
||||
quiet: config.quiet,
|
||||
verbose: config.verbose,
|
||||
logLevel: config.logLevel,
|
||||
})
|
||||
let configImport = await resolve(configPromise, config)
|
||||
if (typeof configImport.default === "function" || configImport.default instanceof Promise) {
|
||||
@@ -101,11 +106,11 @@ export function githubPartToUrl(part: string): string {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export async function getConfig(config: ConfigLoadConfig): Promise<ScaffoldConfigFile> {
|
||||
export async function getConfig(config: ConfigLoadConfig & Partial<LogConfig>): Promise<ScaffoldConfigFile> {
|
||||
const { config: configFile, isRemote, ...logConfig } = config as Required<typeof config>
|
||||
|
||||
if (!isRemote) {
|
||||
log(logConfig, LogLevel.Info, `Loading config from file ${configFile}`)
|
||||
log(logConfig, LogLevel.info, `Loading config from file ${configFile}`)
|
||||
const absolutePath = path.resolve(process.cwd(), configFile)
|
||||
return wrapNoopResolver(import(absolutePath))
|
||||
}
|
||||
|
||||
25
src/file.ts
25
src/file.ts
@@ -12,7 +12,7 @@ const { stat, access, mkdir, readFile, writeFile } = fs
|
||||
|
||||
export async function createDirIfNotExists(dir: string, config: ScaffoldConfig): Promise<void> {
|
||||
if (config.dryRun) {
|
||||
log(config, LogLevel.Info, `Dry Run. Not creating dir ${dir}`)
|
||||
log(config, LogLevel.info, `Dry Run. Not creating dir ${dir}`)
|
||||
return
|
||||
}
|
||||
const parentDir = path.dirname(dir)
|
||||
@@ -23,7 +23,7 @@ export async function createDirIfNotExists(dir: string, config: ScaffoldConfig):
|
||||
|
||||
if (!(await pathExists(dir))) {
|
||||
try {
|
||||
log(config, LogLevel.Debug, `Creating dir ${dir}`)
|
||||
log(config, LogLevel.debug, `Creating dir ${dir}`)
|
||||
await mkdir(dir)
|
||||
return
|
||||
} catch (e: any) {
|
||||
@@ -69,12 +69,11 @@ export function getBasePath(relPath: string): string {
|
||||
|
||||
export async function getFileList(_config: ScaffoldConfig, template: string): Promise<string[]> {
|
||||
template = template.replaceAll(/[\\]+/g, "/")
|
||||
log(_config, LogLevel.Debug, `Getting file list for ${template}`)
|
||||
log(_config, LogLevel.debug, `Getting file list for ${template}`)
|
||||
return (
|
||||
await glob(template, {
|
||||
dot: true,
|
||||
nodir: true,
|
||||
// debug: config.verbose === LogLevel.Debug,
|
||||
})
|
||||
).map(path.normalize)
|
||||
}
|
||||
@@ -89,13 +88,13 @@ export interface GlobInfo {
|
||||
|
||||
export async function getTemplateGlobInfo(config: ScaffoldConfig, template: string): Promise<GlobInfo> {
|
||||
const isGlob = hasMagic(template)
|
||||
log(config, LogLevel.Debug, "before isDir", "isGlob:", isGlob, template)
|
||||
log(config, LogLevel.debug, "before isDir", "isGlob:", isGlob, template)
|
||||
let _template = template
|
||||
let nonGlobTemplate = isGlob ? removeGlob(template) : template
|
||||
nonGlobTemplate = path.normalize(nonGlobTemplate)
|
||||
const isDirOrGlob = isGlob ? true : await isDir(template)
|
||||
const _shouldAddGlob = !isGlob && isDirOrGlob
|
||||
log(config, LogLevel.Debug, "after", { isDirOrGlob, _shouldAddGlob })
|
||||
log(config, LogLevel.debug, "after", { isDirOrGlob, _shouldAddGlob })
|
||||
const origTemplate = template
|
||||
if (_shouldAddGlob) {
|
||||
_template = path.join(template, "**", "*")
|
||||
@@ -141,7 +140,7 @@ export async function copyFileTransformed(
|
||||
): Promise<void> {
|
||||
if (!exists || overwrite) {
|
||||
if (exists && overwrite) {
|
||||
log(config, LogLevel.Info, `File ${outputPath} exists, overwriting`)
|
||||
log(config, LogLevel.info, `File ${outputPath} exists, overwriting`)
|
||||
}
|
||||
const templateBuffer = await readFile(inputPath)
|
||||
const unprocessedOutputContents = handlebarsParse(config, templateBuffer)
|
||||
@@ -150,13 +149,13 @@ export async function copyFileTransformed(
|
||||
|
||||
if (!config.dryRun) {
|
||||
await writeFile(outputPath, finalOutputContents)
|
||||
log(config, LogLevel.Info, "Done.")
|
||||
log(config, LogLevel.info, "Done.")
|
||||
} else {
|
||||
log(config, LogLevel.Info, "Dry Run. Output should be:")
|
||||
log(config, LogLevel.Info, finalOutputContents.toString())
|
||||
log(config, LogLevel.info, "Dry Run. Output should be:")
|
||||
log(config, LogLevel.info, finalOutputContents.toString())
|
||||
}
|
||||
} else if (exists) {
|
||||
log(config, LogLevel.Info, `File ${outputPath} already exists, skipping`)
|
||||
log(config, LogLevel.info, `File ${outputPath} already exists, skipping`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +188,7 @@ export async function handleTemplateFile(
|
||||
|
||||
log(
|
||||
config,
|
||||
LogLevel.Debug,
|
||||
LogLevel.debug,
|
||||
`\nParsing ${templatePath}`,
|
||||
`\nBase path: ${basePath}`,
|
||||
`\nFull input path: ${inputPath}`,
|
||||
@@ -201,7 +200,7 @@ export async function handleTemplateFile(
|
||||
|
||||
await createDirIfNotExists(path.dirname(outputPath), config)
|
||||
|
||||
log(config, LogLevel.Info, `Writing to ${outputPath}`)
|
||||
log(config, LogLevel.info, `Writing to ${outputPath}`)
|
||||
await copyFileTransformed(config, { exists, overwrite, outputPath, inputPath })
|
||||
resolve()
|
||||
} catch (e: any) {
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function getGitConfig(
|
||||
): Promise<AsyncResolver<ScaffoldCmdConfig, ScaffoldConfigMap>> {
|
||||
const repoUrl = `${url.protocol}//${url.host}${url.pathname}`
|
||||
|
||||
log(logConfig, LogLevel.Info, `Cloning git repo ${repoUrl}`)
|
||||
log(logConfig, LogLevel.info, `Cloning git repo ${repoUrl}`)
|
||||
|
||||
const tmpPath = path.resolve(os.tmpdir(), `scaffold-config-${Date.now()}`)
|
||||
|
||||
@@ -21,7 +21,7 @@ export async function getGitConfig(
|
||||
clone.on("error", reject)
|
||||
clone.on("close", async (code) => {
|
||||
if (code === 0) {
|
||||
log(logConfig, LogLevel.Info, `Loading config from git repo: ${repoUrl}`)
|
||||
log(logConfig, LogLevel.info, `Loading config from git repo: ${repoUrl}`)
|
||||
const hashPath = url.hash?.replace("#", "") || "scaffold.config.js"
|
||||
const absolutePath = path.resolve(tmpPath, hashPath)
|
||||
const loadedConfig = await resolve(
|
||||
@@ -29,8 +29,8 @@ export async function getGitConfig(
|
||||
logConfig,
|
||||
)
|
||||
|
||||
log(logConfig, LogLevel.Info, `Loaded config from git`)
|
||||
log(logConfig, LogLevel.Debug, `Raw config:`, loadedConfig)
|
||||
log(logConfig, LogLevel.info, `Loaded config from git`)
|
||||
log(logConfig, LogLevel.debug, `Raw config:`, loadedConfig)
|
||||
const fixedConfig: ScaffoldConfigMap = {}
|
||||
for (const [k, v] of Object.entries(loadedConfig)) {
|
||||
fixedConfig[k] = {
|
||||
|
||||
@@ -2,28 +2,28 @@ import { LogConfig, LogLevel, ScaffoldConfig } from "./types"
|
||||
import chalk from "chalk"
|
||||
|
||||
export function log(config: LogConfig, level: LogLevel, ...obj: any[]): void {
|
||||
if (config.quiet || config.verbose === LogLevel.None || level < (config.verbose ?? LogLevel.Info)) {
|
||||
if (config.logLevel === LogLevel.none || level < (config.logLevel ?? LogLevel.info)) {
|
||||
return
|
||||
}
|
||||
|
||||
const levelColor: Record<LogLevel, keyof typeof chalk> = {
|
||||
[LogLevel.None]: "reset",
|
||||
[LogLevel.Debug]: "blue",
|
||||
[LogLevel.Info]: "dim",
|
||||
[LogLevel.Warning]: "yellow",
|
||||
[LogLevel.Error]: "red",
|
||||
const levelColor: Record<keyof typeof LogLevel, keyof typeof chalk> = {
|
||||
[LogLevel.none]: "reset",
|
||||
[LogLevel.debug]: "blue",
|
||||
[LogLevel.info]: "dim",
|
||||
[LogLevel.warning]: "yellow",
|
||||
[LogLevel.error]: "red",
|
||||
}
|
||||
|
||||
const chalkFn: any = chalk[levelColor[level]]
|
||||
const key: "log" | "warn" | "error" = level === LogLevel.Error ? "error" : level === LogLevel.Warning ? "warn" : "log"
|
||||
const key: "log" | "warn" | "error" = level === LogLevel.error ? "error" : level === LogLevel.warning ? "warn" : "log"
|
||||
const logFn: any = console[key]
|
||||
logFn(
|
||||
...obj.map((i) =>
|
||||
i instanceof Error
|
||||
? chalkFn(i, JSON.stringify(i, undefined, 1), i.stack)
|
||||
: typeof i === "object"
|
||||
? chalkFn(JSON.stringify(i, undefined, 1))
|
||||
: chalkFn(i),
|
||||
? chalkFn(JSON.stringify(i, undefined, 1))
|
||||
: chalkFn(i),
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -41,25 +41,22 @@ export function logInputFile(
|
||||
isGlob: boolean
|
||||
},
|
||||
): void {
|
||||
log(config, LogLevel.Debug, data)
|
||||
log(config, LogLevel.debug, data)
|
||||
}
|
||||
|
||||
export function logInitStep(config: ScaffoldConfig): void {
|
||||
log(config, LogLevel.Debug, "Full config:", {
|
||||
log(config, LogLevel.debug, "Full config:", {
|
||||
name: config.name,
|
||||
templates: config.templates,
|
||||
output: config.output,
|
||||
createSubFolder: config.createSubFolder,
|
||||
data: config.data,
|
||||
overwrite: config.overwrite,
|
||||
quiet: config.quiet,
|
||||
subFolderNameHelper: config.subFolderNameHelper,
|
||||
helpers: Object.keys(config.helpers ?? {}),
|
||||
verbose: `${config.verbose} (${Object.keys(LogLevel).find(
|
||||
(k) => (LogLevel[k as any] as unknown as number) === config.verbose!,
|
||||
)})`,
|
||||
logLevel: config.logLevel,
|
||||
dryRun: config.dryRun,
|
||||
beforeWrite: config.beforeWrite,
|
||||
} as Record<keyof ScaffoldConfig, unknown>)
|
||||
log(config, LogLevel.Info, "Data:", config.data)
|
||||
log(config, LogLevel.info, "Data:", config.data)
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ function pascalCase(s: string): string {
|
||||
export function registerHelpers(config: ScaffoldConfig): void {
|
||||
const _helpers = { ...defaultHelpers, ...config.helpers }
|
||||
for (const helperName in _helpers) {
|
||||
log(config, LogLevel.Debug, `Registering helper: ${helperName}`)
|
||||
log(config, LogLevel.debug, `Registering helper: ${helperName}`)
|
||||
Handlebars.registerHelper(helperName, _helpers[helperName as keyof typeof _helpers])
|
||||
}
|
||||
}
|
||||
@@ -120,8 +120,8 @@ export function handlebarsParse(
|
||||
}
|
||||
return Buffer.from(outputContents)
|
||||
} catch (e) {
|
||||
log(config, LogLevel.Debug, e)
|
||||
log(config, LogLevel.Warning, "Couldn't parse file with handlebars, returning original content")
|
||||
log(config, LogLevel.debug, e)
|
||||
log(config, LogLevel.warning, "Couldn't parse file with handlebars, returning original content")
|
||||
return Buffer.from(templateBuffer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ export async function Scaffold(config: ScaffoldConfig): Promise<void> {
|
||||
_template,
|
||||
)
|
||||
const files = await getFileList(config, template)
|
||||
log(config, LogLevel.Debug, "Iterating files", { files, template })
|
||||
log(config, LogLevel.debug, "Iterating files", { files, template })
|
||||
for (const inputFilePath of files) {
|
||||
if (await isDir(inputFilePath)) {
|
||||
continue
|
||||
@@ -93,7 +93,7 @@ export async function Scaffold(config: ScaffoldConfig): Promise<void> {
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
log(config, LogLevel.Error, e)
|
||||
log(config, LogLevel.error, e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ export async function Scaffold(config: ScaffoldConfig): Promise<void> {
|
||||
* @category Main
|
||||
* @return {Promise<void>} A promise that resolves when the scaffold is complete
|
||||
*/
|
||||
Scaffold.fromConfig = async function (
|
||||
Scaffold.fromConfig = async function(
|
||||
/** The path or URL to the config file */
|
||||
pathOrUrl: string,
|
||||
/** Information needed before loading the config */
|
||||
@@ -120,7 +120,7 @@ Scaffold.fromConfig = async function (
|
||||
const _cmdConfig: ScaffoldCmdConfig = {
|
||||
dryRun: false,
|
||||
output: process.cwd(),
|
||||
verbose: LogLevel.Info,
|
||||
logLevel: LogLevel.info,
|
||||
overwrite: false,
|
||||
templates: [],
|
||||
createSubFolder: false,
|
||||
|
||||
52
src/types.ts
52
src/types.ts
@@ -68,12 +68,6 @@ export interface ScaffoldConfig {
|
||||
*/
|
||||
overwrite?: FileResponse<boolean>
|
||||
|
||||
/**
|
||||
* Suppress output logs (Same as `verbose: 0` or `verbose: LogLevel.None`)
|
||||
* @see {@link verbose}
|
||||
*/
|
||||
quiet?: boolean
|
||||
|
||||
/**
|
||||
* Determine amount of logs to display.
|
||||
*
|
||||
@@ -84,7 +78,7 @@ export interface ScaffoldConfig {
|
||||
*
|
||||
* @default `2 (info)`
|
||||
*/
|
||||
verbose?: LogLevel
|
||||
logLevel?: LogLevel
|
||||
|
||||
/**
|
||||
* Don't emit files. This is good for testing your scaffolds and making sure they don't fail, without having to write
|
||||
@@ -263,6 +257,23 @@ export type DefaultHelpers = CaseHelpers | DateHelpers
|
||||
*/
|
||||
export type Helper = HelperDelegate
|
||||
|
||||
export const LogLevel = {
|
||||
/** Silent output */
|
||||
none: "none",
|
||||
/** Debugging information. Very verbose and only recommended for troubleshooting. */
|
||||
debug: "debug",
|
||||
/**
|
||||
* The regular level of logging. Major actions are logged to show the scaffold progress.
|
||||
*
|
||||
* @default
|
||||
*/
|
||||
info: "info",
|
||||
/** Warnings such as when file fails to replace token values properly in template. */
|
||||
warning: "warning",
|
||||
/** Errors, such as missing files, bad replacement token syntax, or un-writable directories. */
|
||||
error: "error",
|
||||
} as const
|
||||
|
||||
/**
|
||||
* The amount of information to log when generating scaffold.
|
||||
* When not `None`, the selected level will be the lowest level included.
|
||||
@@ -270,26 +281,14 @@ export type Helper = HelperDelegate
|
||||
* For example, level `Info` (2) will include `Info`, `Warning` and `Error`, but not `Debug`; and `Warning` will only
|
||||
* show `Warning` and `Error`.
|
||||
*
|
||||
* You may use either the number or the name of the level.
|
||||
* For example, `2` or `info` are both valid.
|
||||
*
|
||||
* @default `2 (info)`
|
||||
*
|
||||
* @category Logging
|
||||
*/
|
||||
export enum LogLevel {
|
||||
/** Silent output */
|
||||
None = 0,
|
||||
/** Debugging information. Very verbose and only recommended for troubleshooting. */
|
||||
Debug = 1,
|
||||
/**
|
||||
* The regular level of logging. Major actions are logged to show the scaffold progress.
|
||||
*
|
||||
* @default
|
||||
*/
|
||||
Info = 2,
|
||||
/** Warnings such as when file fails to replace token values properly in template. */
|
||||
Warning = 3,
|
||||
/** Errors, such as missing files, bad replacement token syntax, or un-writable directories. */
|
||||
Error = 4,
|
||||
}
|
||||
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel]
|
||||
|
||||
/**
|
||||
* A function that takes path information about file, and returns a value of type `T`
|
||||
@@ -315,8 +314,6 @@ export type FileResponseHandler<T> = (fullPath: string, basedir: string, basenam
|
||||
* (fullPath: string, basedir: string, basename: string) => T
|
||||
* ```
|
||||
*
|
||||
* @typedef T The return type
|
||||
*
|
||||
* @see {@link FileResponseHandler}
|
||||
*
|
||||
* @category Config
|
||||
@@ -337,7 +334,7 @@ export interface ScaffoldCmdConfig {
|
||||
appendData?: Record<string, string>
|
||||
overwrite: boolean
|
||||
quiet: boolean
|
||||
verbose: LogLevel
|
||||
logLevel: LogLevel
|
||||
dryRun: boolean
|
||||
config?: string
|
||||
/** The key to use for the file which contains the template configurations. */
|
||||
@@ -373,8 +370,9 @@ export type Resolver<T, R = T> = R | ((value: T) => R)
|
||||
export type AsyncResolver<T, R = T> = Resolver<T, Promise<R> | R>
|
||||
|
||||
/** @internal */
|
||||
export type LogConfig = Pick<ScaffoldConfig, "quiet" | "verbose">
|
||||
export type LogConfig = Pick<ScaffoldConfig, "logLevel">
|
||||
|
||||
// TODO deprecat isRemote
|
||||
/** @internal */
|
||||
export type ConfigLoadConfig = LogConfig & Pick<ScaffoldCmdConfig, "config"> & { isRemote: boolean }
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ScaffoldCmdConfig } from "../src/types"
|
||||
import { LogLevel, ScaffoldCmdConfig } from "../src/types"
|
||||
import * as config from "../src/config"
|
||||
import { resolve } from "../src/utils"
|
||||
// @ts-ignore
|
||||
@@ -17,7 +17,7 @@ jest.mock("../src/git", () => {
|
||||
const { githubPartToUrl, parseAppendData, parseConfigFile, parseConfigSelection } = config
|
||||
|
||||
const blankCliConf: ScaffoldCmdConfig = {
|
||||
verbose: 0,
|
||||
logLevel: LogLevel.none,
|
||||
name: "",
|
||||
output: "",
|
||||
templates: [],
|
||||
@@ -128,8 +128,7 @@ describe("config", () => {
|
||||
const resultFn = await config.getConfig({
|
||||
config: "https://github.com/chenasraf/simple-scaffold.git",
|
||||
isRemote: true,
|
||||
quiet: true,
|
||||
verbose: 0,
|
||||
logLevel: LogLevel.none,
|
||||
})
|
||||
const result = await resolve(resultFn, blankCliConf)
|
||||
expect(result).toEqual(blankCliConf)
|
||||
@@ -139,8 +138,7 @@ describe("config", () => {
|
||||
const resultFn = await config.getConfig({
|
||||
config: "scaffold.config.js",
|
||||
isRemote: false,
|
||||
quiet: true,
|
||||
verbose: 0,
|
||||
logLevel: LogLevel.none,
|
||||
})
|
||||
const result = await resolve(resultFn, {} as any)
|
||||
expect(result).toEqual(configFile)
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as dateFns from "date-fns"
|
||||
import { dateHelper, defaultHelpers, handlebarsParse, nowHelper } from "../src/parser"
|
||||
|
||||
const blankConf: ScaffoldConfig = {
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
name: "",
|
||||
output: "",
|
||||
templates: [],
|
||||
|
||||
@@ -99,7 +99,7 @@ describe("Scaffold", () => {
|
||||
name: "app_name",
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
})
|
||||
const data = readFileSync(join(process.cwd(), "output", "app_name.txt"))
|
||||
expect(data.toString()).toEqual("Hello, my app is app_name")
|
||||
@@ -111,7 +111,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
createSubFolder: true,
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
})
|
||||
|
||||
const data = readFileSync(join(process.cwd(), "output", "app_name", "app_name.txt"))
|
||||
@@ -128,7 +128,7 @@ describe("Scaffold", () => {
|
||||
name: "app_name",
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
})
|
||||
const data = readFileSync(join(process.cwd(), "output", "app_name.txt"))
|
||||
expect(data.toString()).toEqual("Hello, my app is app_name")
|
||||
@@ -147,7 +147,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
data: { value: "1" },
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
})
|
||||
|
||||
await Scaffold({
|
||||
@@ -155,7 +155,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
data: { value: "2" },
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
})
|
||||
|
||||
const data = readFileSync(join(process.cwd(), "output", "app_name.txt"))
|
||||
@@ -168,7 +168,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
data: { value: "1" },
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
})
|
||||
|
||||
await Scaffold({
|
||||
@@ -177,7 +177,7 @@ describe("Scaffold", () => {
|
||||
templates: ["input"],
|
||||
data: { value: "2" },
|
||||
overwrite: true,
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
})
|
||||
|
||||
const data = readFileSync(join(process.cwd(), "output", "app_name.txt"))
|
||||
@@ -205,7 +205,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["non-existing-input"],
|
||||
data: { value: "1" },
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
}),
|
||||
).rejects.toThrow()
|
||||
|
||||
@@ -215,7 +215,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["non-existing-input/non-existing-file.txt"],
|
||||
data: { value: "1" },
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
}),
|
||||
).rejects.toThrow()
|
||||
|
||||
@@ -242,7 +242,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
data: { value: "1" },
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
dryRun: true,
|
||||
})
|
||||
|
||||
@@ -260,7 +260,7 @@ describe("Scaffold", () => {
|
||||
output: (_, __, basename) => join("custom-output", `${basename.split(".")[0]}`),
|
||||
templates: ["input"],
|
||||
data: { value: "1" },
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
})
|
||||
const data = readFileSync(join(process.cwd(), "/custom-output/app_name/app_name.txt"))
|
||||
expect(data.toString()).toEqual("Hello, my app is app_name")
|
||||
@@ -277,7 +277,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
data: { value: "1" },
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
})
|
||||
|
||||
const rootDir = readdirSync(join(process.cwd(), "output"))
|
||||
@@ -309,7 +309,7 @@ describe("Scaffold", () => {
|
||||
name: "app_name",
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
helpers: _helpers,
|
||||
})
|
||||
|
||||
@@ -342,7 +342,7 @@ describe("Scaffold", () => {
|
||||
name: "app_name",
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
data: { customDate },
|
||||
})
|
||||
|
||||
@@ -380,7 +380,7 @@ describe("Scaffold", () => {
|
||||
name: "app_name",
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
helpers: _helpers,
|
||||
})
|
||||
|
||||
@@ -403,7 +403,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
createSubFolder: true,
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
})
|
||||
|
||||
const data = readFileSync(join(process.cwd(), "output", "app_name", "app_name.txt"))
|
||||
@@ -416,7 +416,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
createSubFolder: true,
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
subFolderNameHelper: "upperCase",
|
||||
})
|
||||
|
||||
@@ -430,7 +430,7 @@ describe("Scaffold", () => {
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
createSubFolder: true,
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
subFolderNameHelper: "test",
|
||||
helpers: {
|
||||
test: () => "REPLACED",
|
||||
@@ -450,7 +450,7 @@ describe("Scaffold", () => {
|
||||
name: "app_name",
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
data: {
|
||||
value: "value",
|
||||
},
|
||||
@@ -465,7 +465,7 @@ describe("Scaffold", () => {
|
||||
name: "app_name",
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
data: {
|
||||
value: "value",
|
||||
},
|
||||
@@ -487,7 +487,7 @@ describe("Scaffold", () => {
|
||||
name: "app_name",
|
||||
output: "output",
|
||||
templates: ["input"],
|
||||
verbose: 0,
|
||||
logLevel: "none",
|
||||
data: {
|
||||
value: "value",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user