reverse accepts new file paths via globs
All checks were successful
Publish npm package / publish (push) Successful in 22s
All checks were successful
Publish npm package / publish (push) Successful in 22s
This commit is contained in:
21
cli.ts
21
cli.ts
@@ -5,7 +5,7 @@ function printHelp() {
|
||||
console.log(`tdir
|
||||
|
||||
Usage:
|
||||
tdir reverse <rendered-dir> <template-dir> [--map <path>]
|
||||
tdir reverse <rendered-dir> <template-dir> [--map <path>] [--include <glob>...]
|
||||
|
||||
Commands:
|
||||
reverse Rebuild template files from a rendered directory and reverse map
|
||||
@@ -13,18 +13,20 @@ Commands:
|
||||
Options:
|
||||
--map Reverse map path. Defaults to <rendered-dir>/.tdir-map.json.
|
||||
Relative paths are resolved from <rendered-dir>.
|
||||
--include Include new rendered files matching a glob. Can be repeated.
|
||||
--help Show this help message.
|
||||
`)
|
||||
}
|
||||
|
||||
function parseReverseArgs(args: string[]) {
|
||||
const positional: string[] = []
|
||||
const include: string[] = []
|
||||
let mapPath: string | undefined
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i]!
|
||||
if (arg === "--help" || arg === "-h") {
|
||||
return { help: true, positional, mapPath }
|
||||
return { help: true, positional, mapPath, include }
|
||||
}
|
||||
if (arg === "--map") {
|
||||
const value = args[++i]
|
||||
@@ -32,10 +34,16 @@ function parseReverseArgs(args: string[]) {
|
||||
mapPath = value
|
||||
continue
|
||||
}
|
||||
if (arg === "--include") {
|
||||
const value = args[++i]
|
||||
if (!value) throw new Error("Missing value for --include")
|
||||
include.push(value)
|
||||
continue
|
||||
}
|
||||
positional.push(arg)
|
||||
}
|
||||
|
||||
return { help: false, positional, mapPath }
|
||||
return { help: false, positional, mapPath, include }
|
||||
}
|
||||
|
||||
function main(argv: string[]) {
|
||||
@@ -58,10 +66,13 @@ function main(argv: string[]) {
|
||||
|
||||
const [renderedDir, templateDir] = parsed.positional
|
||||
if (!renderedDir || !templateDir || parsed.positional.length > 2) {
|
||||
throw new Error("Usage: tdir reverse <rendered-dir> <template-dir> [--map <path>]")
|
||||
throw new Error("Usage: tdir reverse <rendered-dir> <template-dir> [--map <path>] [--include <glob>...]")
|
||||
}
|
||||
|
||||
const result = reverseDir(renderedDir, templateDir, { mapPath: parsed.mapPath })
|
||||
const result = reverseDir(renderedDir, templateDir, {
|
||||
mapPath: parsed.mapPath,
|
||||
include: parsed.include,
|
||||
})
|
||||
console.log(`Wrote ${result.filesWritten} file${result.filesWritten === 1 ? "" : "s"}`)
|
||||
for (const warning of result.warnings) {
|
||||
console.warn(`Warning: ${warning.outputPath}: ${warning.message}`)
|
||||
|
||||
Reference in New Issue
Block a user