Compare commits

...

3 Commits

Author SHA1 Message Date
Chen Asraf
143519974f bump version number [publish] 2022-05-23 21:22:17 +03:00
Chen Asraf
faa5788c38 replace node version 2022-05-23 21:17:24 +03:00
Chen Asraf
7c8f4095ad windows separator fixes on config [publish] 2022-05-23 20:59:49 +03:00
7 changed files with 61 additions and 32 deletions

View File

@@ -2,7 +2,9 @@ name: Alpha Releases
on:
push:
branches: [develop]
branches: [develop, fix/*, feature/*]
# pull_request:
# branches: [master, develop]
jobs:
build:
runs-on: ubuntu-latest
@@ -11,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
node-version: "14.x"
- run: yarn install --frozen-lockfile
- run: yarn test
- run: yarn build

View File

@@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
node-version: "14.x"
- run: cd doc-theme && yarn install && yarn build && rm -rf node_modules && cd ..
- run: yarn install --frozen-lockfile
- run: yarn typedoc

View File

@@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
node-version: "14.x"
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn test

View File

@@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
node-version: "14.x"
- run: yarn install --frozen-lockfile
- run: yarn test
- run: yarn build

View File

@@ -1,6 +1,6 @@
{
"name": "simple-scaffold",
"version": "1.1.2",
"version": "1.1.3-pre.2",
"description": "A simple command to generate any file structure, from single components to entire app boilerplates.",
"homepage": "https://casraf.blog/simple-scaffold",
"repository": "https://github.com/chenasraf/simple-scaffold.git",

View File

@@ -136,6 +136,10 @@ export async function createDirIfNotExists(dir: string, config: ScaffoldConfig):
}
}
export function pathSepFix(pathname: string): string {
return pathname.replace(/[\\\/]+/g, path.sep)
}
export function getOptionValueForFile<T>(
config: ScaffoldConfig,
filePath: string,
@@ -165,8 +169,8 @@ export function handlebarsParse(
}
const parser = Handlebars.compile(str, { noEscape: true })
let outputContents = parser(data)
if (isPath && path.sep !== "/") {
outputContents = outputContents.replace(/\//g, "\\")
if (isPath) {
outputContents = pathSepFix(outputContents)
}
return Buffer.from(outputContents)
} catch (e) {
@@ -206,8 +210,7 @@ export function makeRelativePath(str: string): string {
}
export function getBasePath(relPath: string): string {
return path
.resolve(process.cwd(), relPath)
return pathSepFix(path.resolve(process.cwd(), relPath))
.replace(process.cwd() + path.sep, "")
.replace(process.cwd(), "")
}
@@ -257,12 +260,11 @@ export async function getTemplateFileInfo(
config: ScaffoldConfig,
{ templatePath, basePath }: { templatePath: string; basePath: string },
): Promise<OutputFileInfo> {
const inputPath = path.resolve(process.cwd(), templatePath)
const outputPathOpt = getOptionValueForFile(config, inputPath, config.output)
const outputDir = getOutputDir(config, outputPathOpt, basePath)
const outputPath = handlebarsParse(config, path.join(outputDir, path.basename(inputPath)), {
isPath: true,
}).toString()
const inputPath = pathSepFix(path.resolve(process.cwd(), templatePath))
const outputPathOpt = pathSepFix(getOptionValueForFile(config, inputPath, config.output))
const outputDir = pathSepFix(getOutputDir(config, outputPathOpt, basePath))
const _rawOutputPath = pathSepFix(path.join(outputDir, path.basename(inputPath)))
const outputPath = handlebarsParse(config, _rawOutputPath, { isPath: true }).toString()
const exists = await pathExists(outputPath)
return { inputPath, outputPathOpt, outputDir, outputPath, exists }
}

View File

@@ -1,4 +1,4 @@
import { dateHelper, handlebarsParse, nowHelper } from "../src/utils"
import { dateHelper, getTemplateFileInfo, handlebarsParse, nowHelper, pathSepFix } from "../src/utils"
import { ScaffoldConfig } from "../src/types"
import path from "path"
import * as dateFns from "date-fns"
@@ -12,16 +12,32 @@ const blankConf: ScaffoldConfig = {
}
describe("Utils", () => {
describe("getTemplateFileInfo", () => {
mockPathSep()
test("should fix paths properly for windows", async () => {
const result = await getTemplateFileInfo(
{
output: "/output",
templates: ["/example/template/**/*"],
name: "test",
},
{
basePath: "/example/base",
templatePath: "/example/template/file.ext",
},
)
const wd = pathSepFix(process.cwd())
expect(result).toHaveProperty("inputPath", "\\example\\template\\file.ext")
expect(result).toHaveProperty("outputPathOpt", "\\output")
expect(result).toHaveProperty("outputDir", "\\example\\base")
expect(result).toHaveProperty("outputPath", "\\example\\base\\file.ext")
})
})
describe("handlebarsParse", () => {
let origSep: any
describe("windows paths", () => {
beforeAll(() => {
origSep = path.sep
Object.defineProperty(path, "sep", { value: "\\" })
})
afterAll(() => {
Object.defineProperty(path, "sep", { value: origSep })
})
mockPathSep()
test("should work for windows paths", async () => {
expect(handlebarsParse(blankConf, "C:\\exports\\{{name}}.txt", { isPath: true })).toEqual(
Buffer.from("C:\\exports\\test.txt"),
@@ -29,13 +45,6 @@ describe("Utils", () => {
})
})
describe("non-windows paths", () => {
beforeAll(() => {
origSep = path.sep
Object.defineProperty(path, "sep", { value: "/" })
})
afterAll(() => {
Object.defineProperty(path, "sep", { value: origSep })
})
test("should work for non-windows paths", async () => {
expect(handlebarsParse(blankConf, "/home/test/{{name}}.txt", { isPath: true })).toEqual(
Buffer.from("/home/test/test.txt"),
@@ -89,3 +98,19 @@ describe("Utils", () => {
})
})
})
function mockPathSep() {
let origSep: any
const sep = "\\"
beforeAll(() => {
origSep = path.sep
Object.defineProperty(path, "sep", { value: sep })
Object.defineProperty(path, "join", { value: (...args: string[]) => args.join(sep) })
Object.defineProperty(path, "basename", { value: (arg: string) => arg.split(sep).slice(-1) })
})
afterAll(() => {
Object.defineProperty(path, "sep", { value: origSep })
Object.defineProperty(path, "join", { value: (...args: string[]) => args.join(origSep) })
Object.defineProperty(path, "basename", { value: (arg: string) => arg.split(origSep).slice(-1) })
})
}