mirror of
https://github.com/chenasraf/simple-scaffold.git
synced 2026-05-17 17:28:09 +00:00
fix: support quote wrapping in append-data
This commit is contained in:
@@ -5,7 +5,6 @@ import { LogLevel, ScaffoldCmdConfig } from "./types"
|
||||
import { Scaffold } from "./scaffold"
|
||||
import path from "path"
|
||||
import fs from "fs/promises"
|
||||
import { OptionsBase } from "massarg/types"
|
||||
import { parseAppendData } from "./utils"
|
||||
|
||||
export async function parseCliArgs(args = process.argv.slice(2)) {
|
||||
@@ -13,7 +12,11 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
|
||||
|
||||
return (
|
||||
massarg<ScaffoldCmdConfig>()
|
||||
.main(Scaffold)
|
||||
.main((config) => {
|
||||
config.data = { ...config.data, ...config.appendData }
|
||||
delete config.appendData
|
||||
return Scaffold(config)
|
||||
})
|
||||
.option({
|
||||
name: "name",
|
||||
aliases: ["n"],
|
||||
|
||||
@@ -331,6 +331,7 @@ export interface ScaffoldCmdConfig {
|
||||
output: string
|
||||
createSubFolder: boolean
|
||||
data?: Record<string, string>
|
||||
appendData?: Record<string, string>
|
||||
overwrite: boolean
|
||||
quiet: boolean
|
||||
verbose: LogLevel
|
||||
|
||||
@@ -389,5 +389,9 @@ export function parseAppendData(value: string, options: ScaffoldCmdConfig & Opti
|
||||
if (value.includes(":=") && !val.includes(":=")) {
|
||||
return { ...data, [key]: JSON.parse(val) }
|
||||
}
|
||||
return { ...data, [key]: val }
|
||||
return { ...data, [key]: isWrappedWithQuotes(val) ? val.substring(1, val.length - 1) : val }
|
||||
}
|
||||
|
||||
function isWrappedWithQuotes(string: string): boolean {
|
||||
return (string.startsWith('"') && string.endsWith('"')) || (string.startsWith("'") && string.endsWith("'"))
|
||||
}
|
||||
|
||||
@@ -116,5 +116,9 @@ describe("Utils", () => {
|
||||
test("overwrites existing value", () => {
|
||||
expect(parseAppendData("name:=123", blankCliConf)).toEqual({ name: 123 })
|
||||
})
|
||||
|
||||
test("works with quotes", () => {
|
||||
expect(parseAppendData('key="value test"', blankCliConf)).toEqual({ key: "value test", name: "test" })
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user