fix: windows path resolution

This commit is contained in:
2023-08-14 00:19:50 +03:00
parent 8c3369a00d
commit 98ee00031f
6 changed files with 2031 additions and 1399 deletions

5
examples/.dotdir/README.md Executable file
View File

@@ -0,0 +1,5 @@
# {{ name }} Readme
TO DO:
- [ ] ...

View File

@@ -37,7 +37,7 @@
"dependencies": {
"chalk": "^4.1.2",
"date-fns": "^2.30.0",
"glob": "^10.2.3",
"glob": "^10.3.3",
"handlebars": "^4.7.7",
"massarg": "^1.0.7-pre.1"
},

3412
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -53,7 +53,7 @@ export async function isDir(path: string): Promise<boolean> {
}
export function removeGlob(template: string): string {
return template.replace(/\*/g, "").replace(/(\/\/|\\\\)/g, path.sep)
return path.normalize(template.replace(/\*/g, ""))
}
export function makeRelativePath(str: string): string {
@@ -68,6 +68,8 @@ 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}`)
return (
await glob(template, {
dot: true,
@@ -92,8 +94,8 @@ export async function getTemplateGlobInfo(config: ScaffoldConfig, template: stri
let nonGlobTemplate = isGlob ? removeGlob(template) : template
nonGlobTemplate = path.normalize(nonGlobTemplate)
const isDirOrGlob = isGlob ? true : await isDir(template)
log(config, LogLevel.Debug, "after isDir", isDirOrGlob)
const _shouldAddGlob = !isGlob && isDirOrGlob
log(config, LogLevel.Debug, "after", { isDirOrGlob, _shouldAddGlob })
const origTemplate = template
if (_shouldAddGlob) {
_template = path.join(template, "**", "*")

View File

@@ -67,6 +67,7 @@ export async function Scaffold(config: ScaffoldConfig): Promise<void> {
_template,
)
const files = await getFileList(config, template)
log(config, LogLevel.Debug, "Iterating files", { files, template })
for (const inputFilePath of files) {
if (await isDir(inputFilePath)) {
continue

View File

@@ -38,8 +38,8 @@ describe("parser", () => {
Object.defineProperty(path, "sep", { value: origSep })
})
test("should work for windows paths", async () => {
expect(handlebarsParse(blankConf, "C:\\exports\\{{name}}.txt", { isPath: true })).toEqual(
Buffer.from("C:\\exports\\test.txt"),
expect(handlebarsParse(blankConf, "C:\\exports\\{{name}}.txt", { isPath: true }).toString()).toEqual(
"C:\\exports\\test.txt",
)
})
})