mirror of
https://github.com/chenasraf/simple-scaffold.git
synced 2026-05-18 01:29:09 +00:00
Compare commits
8 Commits
v1.7.0-dev
...
v1.7.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de05bca546 | ||
|
|
72d4cf58c5 | ||
|
|
2cf31e827e | ||
|
|
3714e8b3bd | ||
|
|
77be7c09d5 | ||
|
|
1246b51cda | ||
|
|
4868925511 | ||
|
|
79cfdbed38 |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -2,7 +2,7 @@ name: Test & Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master, develop, feat/*, fix/*]
|
||||
branches: [ master, develop, beta, feat/*, fix/* ]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
37
CHANGELOG.md
37
CHANGELOG.md
@@ -1,49 +1,34 @@
|
||||
# Change Log
|
||||
|
||||
## [1.7.0-develop.7](https://github.com/chenasraf/simple-scaffold/compare/v1.7.0-develop.6...v1.7.0-develop.7) (2023-06-07)
|
||||
## [1.7.1](https://github.com/chenasraf/simple-scaffold/compare/v1.7.0...v1.7.1) (2023-06-07)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* local config file load error ([2b74239](https://github.com/chenasraf/simple-scaffold/commit/2b7423993be06b2375631642455c801ae2acf75f))
|
||||
|
||||
## [1.7.0-develop.6](https://github.com/chenasraf/simple-scaffold/compare/v1.7.0-develop.5...v1.7.0-develop.6) (2023-05-27)
|
||||
## [1.7.0](https://github.com/chenasraf/simple-scaffold/compare/v1.7.0-develop.5...v1.7.0) (2023-05-17)
|
||||
|
||||
## [1.7.0-develop.5](https://github.com/chenasraf/simple-scaffold/compare/v1.7.0-develop.4...v1.7.0-develop.5) (2023-05-12)
|
||||
## [1.7.0-develop.7](https://github.com/chenasraf/simple-scaffold/compare/v1.7.0-develop.6...v1.7.0-develop.7) (2023-06-07)
|
||||
|
||||
## [1.7.0-develop.4](https://github.com/chenasraf/simple-scaffold/compare/v1.7.0-develop.3...v1.7.0-develop.4) (2023-05-11)
|
||||
### Bug Fixes
|
||||
|
||||
## [1.7.0-develop.3](https://github.com/chenasraf/simple-scaffold/compare/v1.7.0-develop.2...v1.7.0-develop.3) (2023-05-11)
|
||||
|
||||
## [1.7.0-develop.2](https://github.com/chenasraf/simple-scaffold/compare/v1.7.0-develop.1...v1.7.0-develop.2) (2023-05-10)
|
||||
- local config file load error
|
||||
([2b74239](https://github.com/chenasraf/simple-scaffold/commit/2b7423993be06b2375631642455c801ae2acf75f))
|
||||
|
||||
## [1.7.0-develop.1](https://github.com/chenasraf/simple-scaffold/compare/v1.6.0...v1.7.0-develop.1) (2023-05-09)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* function config file ([02a8ba1](https://github.com/chenasraf/simple-scaffold/commit/02a8ba16cd6ee31806532845cb5ddbe0f5abf7de))
|
||||
|
||||
- function config file
|
||||
([02a8ba1](https://github.com/chenasraf/simple-scaffold/commit/02a8ba16cd6ee31806532845cb5ddbe0f5abf7de))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* use path.normalize ([565090a](https://github.com/chenasraf/simple-scaffold/commit/565090a951e13dd222f2f802df717e7cb6ca0a73))
|
||||
- use path.normalize
|
||||
([565090a](https://github.com/chenasraf/simple-scaffold/commit/565090a951e13dd222f2f802df717e7cb6ca0a73))
|
||||
|
||||
## [1.6.0](https://github.com/chenasraf/simple-scaffold/compare/v1.5.0...v1.6.0) (2023-05-05)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* node.js function for remote configs ([ce5adbe](https://github.com/chenasraf/simple-scaffold/commit/ce5adbe0f898a86db6046d7f66d83dfcaa519ad2))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* move dependency to dev dependency ([d916d88](https://github.com/chenasraf/simple-scaffold/commit/d916d88384054e6c6b40e6299073f1d1acb4d29d))
|
||||
|
||||
## Change Log
|
||||
|
||||
# [1.5.0](https://github.com/chenasraf/simple-scaffold/compare/v1.6.0-develop.1...v1.5.0) (2023-05-04)
|
||||
## [1.6.0](https://github.com/chenasraf/simple-scaffold/compare/v1.6.0-develop.1...v1.6.0) (2023-05-05)
|
||||
|
||||
## [1.6.0-develop.1](https://github.com/chenasraf/simple-scaffold/compare/v1.5.0...v1.6.0-develop.1) (2023-05-04)
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ export default {
|
||||
// unmockedModulePathPatterns: undefined,
|
||||
|
||||
// Indicates whether each individual test should be reported during the run
|
||||
// verbose: undefined,
|
||||
verbose: true,
|
||||
|
||||
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
||||
// watchPathIgnorePatterns: [],
|
||||
|
||||
13
nodemon.json
Normal file
13
nodemon.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ignore": [
|
||||
"**/*.test.ts",
|
||||
"**/*.spec.ts",
|
||||
".git",
|
||||
"node_modules"
|
||||
],
|
||||
"watch": [
|
||||
"src"
|
||||
],
|
||||
"exec": "node -r tsconfig-paths/register -r ts-node/register ./src/index.ts",
|
||||
"ext": "ts, js"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "simple-scaffold",
|
||||
"version": "1.7.0-develop.7",
|
||||
"version": "1.7.1",
|
||||
"description": "Generate any file structure - from single components to entire app boilerplates, with a single command.",
|
||||
"homepage": "https://chenasraf.github.io/simple-scaffold",
|
||||
"repository": "https://github.com/chenasraf/simple-scaffold.git",
|
||||
@@ -49,6 +49,7 @@
|
||||
"@types/jest": "^29.5.1",
|
||||
"@types/mock-fs": "^4.13.1",
|
||||
"@types/node": "^18.16.0",
|
||||
"@types/semantic-release": "^20.0.1",
|
||||
"conventional-changelog": "^3.1.25",
|
||||
"conventional-changelog-cli": "^2.2.2",
|
||||
"conventional-changelog-conventionalcommits": "^5.0.0",
|
||||
|
||||
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
@@ -39,6 +39,9 @@ devDependencies:
|
||||
'@types/node':
|
||||
specifier: ^18.16.0
|
||||
version: 18.16.0
|
||||
'@types/semantic-release':
|
||||
specifier: ^20.0.1
|
||||
version: 20.0.1
|
||||
conventional-changelog:
|
||||
specifier: ^3.1.25
|
||||
version: 3.1.25
|
||||
@@ -1168,6 +1171,12 @@ packages:
|
||||
resolution: {integrity: sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==}
|
||||
dev: true
|
||||
|
||||
/@types/semantic-release@20.0.1:
|
||||
resolution: {integrity: sha512-rANSSye4mYTnP6szFSFUPl9GEowqxKjfKKnE06/axdgOLIL3pQNB4u3gXelZ2wiL6J6Clzb8PSyX8Bbv/JOPHw==}
|
||||
dependencies:
|
||||
'@types/node': 18.16.0
|
||||
dev: true
|
||||
|
||||
/@types/stack-utils@2.0.1:
|
||||
resolution: {integrity: sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==}
|
||||
dev: true
|
||||
|
||||
@@ -12,15 +12,7 @@ const releaseRules = [
|
||||
|
||||
/** @type {import('semantic-release').Options} */
|
||||
module.exports = {
|
||||
branches: [
|
||||
"+([0-9])?(.{+([0-9]),x}).x",
|
||||
"master",
|
||||
"next",
|
||||
"next-major",
|
||||
{ name: "develop", prerelease: true },
|
||||
{ name: "beta", prerelease: true },
|
||||
{ name: "alpha", prerelease: true },
|
||||
],
|
||||
branches: ["+([0-9])?(.{+([0-9]),x}).x", "master", "next", "next-major", { name: "pre", prerelease: true }],
|
||||
analyzeCommits: {
|
||||
path: "semantic-release-conventional-commits",
|
||||
majorTypes: releaseRules.filter((x) => x.release === "major").map((x) => x.type),
|
||||
|
||||
@@ -58,9 +58,14 @@ export async function parseConfig(config: ScaffoldCmdConfig & OptionsBase): Prom
|
||||
}
|
||||
|
||||
if (config.config) {
|
||||
const { configFile, key } = parseConfigSelection(config.config, config.key)
|
||||
const { configFile, key, isRemote } = parseConfigSelection(config.config, config.key)
|
||||
log(config, LogLevel.Info, `Loading config from ${configFile} with key ${key}`)
|
||||
const configPromise = await getConfig({ config: configFile, quiet: config.quiet, verbose: config.verbose })
|
||||
const configPromise = await getConfig({
|
||||
config: configFile,
|
||||
isRemote,
|
||||
quiet: config.quiet,
|
||||
verbose: config.verbose,
|
||||
})
|
||||
const configImport = await resolve(configPromise, config)
|
||||
|
||||
if (!configImport[key]) {
|
||||
@@ -81,7 +86,10 @@ export async function parseConfig(config: ScaffoldCmdConfig & OptionsBase): Prom
|
||||
return c
|
||||
}
|
||||
|
||||
export function parseConfigSelection(config: string, key?: string): { configFile: string; key: string } {
|
||||
export function parseConfigSelection(
|
||||
config: string,
|
||||
key?: string,
|
||||
): { configFile: string; key: string; isRemote: boolean } {
|
||||
const isUrl = config.includes("://")
|
||||
|
||||
const hasColonToken = (!isUrl && config.includes(":")) || (isUrl && count(config, ":") > 1)
|
||||
@@ -90,7 +98,7 @@ export function parseConfigSelection(config: string, key?: string): { configFile
|
||||
? [config.substring(0, colonIndex), config.substring(colonIndex + 1)]
|
||||
: [config, undefined]
|
||||
const _key = (key ?? templateKey) || "default"
|
||||
return { configFile, key: _key }
|
||||
return { configFile, key: _key, isRemote: isUrl }
|
||||
}
|
||||
|
||||
export function githubPartToUrl(part: string): string {
|
||||
@@ -111,19 +119,20 @@ function wrapNoopResolver<T, R = T>(value: Resolver<T, R>): Resolver<T, R> {
|
||||
|
||||
/** @internal */
|
||||
export async function getConfig(config: ConfigLoadConfig): Promise<ScaffoldConfigFile> {
|
||||
const { config: configFile, ...logConfig } = config as Required<typeof config>
|
||||
const url = configFile.includes("://") ? new URL(configFile) : new URL(`file://${configFile}`)
|
||||
const { config: configFile, isRemote, ...logConfig } = config as Required<typeof config>
|
||||
|
||||
if (url.protocol === "file:") {
|
||||
if (!isRemote) {
|
||||
log(logConfig, LogLevel.Info, `Loading config from file ${configFile}`)
|
||||
const absolutePath = path.resolve(process.cwd(), configFile)
|
||||
return wrapNoopResolver(import(absolutePath))
|
||||
}
|
||||
|
||||
const url = new URL(configFile)
|
||||
const isHttp = url.protocol === "http:" || url.protocol === "https:"
|
||||
const isGit = url.protocol === "git:" || (isHttp && url.pathname.endsWith(".git"))
|
||||
|
||||
if (isGit) {
|
||||
console.log("Calling getGitConfig", getGitConfig)
|
||||
return getGitConfig(url, logConfig)
|
||||
}
|
||||
|
||||
@@ -134,10 +143,11 @@ export async function getConfig(config: ConfigLoadConfig): Promise<ScaffoldConfi
|
||||
return wrapNoopResolver(import(path.resolve(process.cwd(), configFile)))
|
||||
}
|
||||
|
||||
async function getGitConfig(
|
||||
export async function getGitConfig(
|
||||
url: URL,
|
||||
logConfig: LogConfig,
|
||||
): Promise<AsyncResolver<ScaffoldCmdConfig, ScaffoldConfigMap>> {
|
||||
console.log("Calling real getGitConfig")
|
||||
const repoUrl = `${url.protocol}//${url.host}${url.pathname}`
|
||||
|
||||
log(logConfig, LogLevel.Info, `Cloning git repo ${repoUrl}`)
|
||||
@@ -165,9 +175,10 @@ async function getGitConfig(
|
||||
)
|
||||
|
||||
resolve(wrapNoopResolver(fixedConfig))
|
||||
} else {
|
||||
reject(new Error(`Git clone failed with code ${code}`))
|
||||
return
|
||||
}
|
||||
|
||||
reject(new Error(`Git clone failed with code ${code}`))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ export type AsyncResolver<T, R = T> = Resolver<T, Promise<R> | R>
|
||||
export type LogConfig = Pick<ScaffoldConfig, "quiet" | "verbose">
|
||||
|
||||
/** @internal */
|
||||
export type ConfigLoadConfig = LogConfig & Pick<ScaffoldCmdConfig, "config">
|
||||
export type ConfigLoadConfig = LogConfig & Pick<ScaffoldCmdConfig, "config"> & { isRemote: boolean }
|
||||
|
||||
/** @internal */
|
||||
export type MinimalConfig = Pick<ScaffoldCmdConfig, "name" | "key">
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { ScaffoldCmdConfig } from "../src/types"
|
||||
import { OptionsBase } from "massarg/types"
|
||||
import { githubPartToUrl, parseAppendData, parseConfigSelection } from "../src/config"
|
||||
import * as config from "../src/config"
|
||||
import { resolve } from "../src/utils"
|
||||
|
||||
const { getConfig, githubPartToUrl, parseAppendData, parseConfig, parseConfigSelection } = config
|
||||
|
||||
const blankCliConf: ScaffoldCmdConfig & OptionsBase = {
|
||||
verbose: 0,
|
||||
@@ -16,6 +19,14 @@ const blankCliConf: ScaffoldCmdConfig & OptionsBase = {
|
||||
help: false,
|
||||
}
|
||||
|
||||
jest.mock("../src/config", () => {
|
||||
console.log("mocking config")
|
||||
return {
|
||||
...jest.requireActual("../src/config"),
|
||||
getGitConfig: () => Promise.resolve({ default: blankCliConf }),
|
||||
}
|
||||
})
|
||||
|
||||
describe("config", () => {
|
||||
describe("parseAppendData", () => {
|
||||
test('works for "key=value"', () => {
|
||||
@@ -34,6 +45,7 @@ describe("config", () => {
|
||||
expect(parseAppendData('key="value test"', blankCliConf)).toEqual({ key: "value test", name: "test" })
|
||||
})
|
||||
})
|
||||
|
||||
describe("githubPartToUrl", () => {
|
||||
test("works", () => {
|
||||
expect(githubPartToUrl("chenasraf/simple-scaffold")).toEqual("https://github.com/chenasraf/simple-scaffold.git")
|
||||
@@ -42,20 +54,99 @@ describe("config", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("parseConfigSelection", () => {
|
||||
test("works", () => {
|
||||
test("separate key", () => {
|
||||
expect(parseConfigSelection("scaffold.config.js", "component")).toEqual({
|
||||
configFile: "scaffold.config.js",
|
||||
key: "component",
|
||||
isRemote: false,
|
||||
})
|
||||
})
|
||||
test("key override", () => {
|
||||
expect(parseConfigSelection("scaffold.config.js:component", "main")).toEqual({
|
||||
configFile: "scaffold.config.js",
|
||||
key: "main",
|
||||
isRemote: false,
|
||||
})
|
||||
})
|
||||
test("isRemote: false", () => {
|
||||
expect(parseConfigSelection("scaffold.config.js", "main")).toEqual({
|
||||
configFile: "scaffold.config.js",
|
||||
key: "main",
|
||||
isRemote: false,
|
||||
})
|
||||
})
|
||||
test("isRemote: true", () => {
|
||||
expect(
|
||||
parseConfigSelection("https://github.com/chenasraf/simple-scaffold.git#scaffold.config.js:component", "main"),
|
||||
).toEqual({
|
||||
configFile: "https://github.com/chenasraf/simple-scaffold.git#scaffold.config.js",
|
||||
key: "main",
|
||||
isRemote: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("parseConfig", () => {
|
||||
test("normal config does not change", async () => {
|
||||
expect(
|
||||
await parseConfig({
|
||||
...blankCliConf,
|
||||
}),
|
||||
).toEqual(blankCliConf)
|
||||
})
|
||||
describe("appendData", () => {
|
||||
test("appends", async () => {
|
||||
const result = await parseConfig({
|
||||
...blankCliConf,
|
||||
appendData: { key: "value" },
|
||||
})
|
||||
expect(result?.data?.key).toEqual("value")
|
||||
})
|
||||
test("overwrites existing value", async () => {
|
||||
const result = await parseConfig({
|
||||
...blankCliConf,
|
||||
data: { num: "123" },
|
||||
appendData: { num: "1234" },
|
||||
})
|
||||
expect(result?.data?.num).toEqual("1234")
|
||||
})
|
||||
})
|
||||
// describe("remote config", () => {
|
||||
// test("works", async () => {
|
||||
// // mock
|
||||
// const result = await parseConfig({
|
||||
// ...blankCliConf,
|
||||
// config: "https://github.com/chenasraf/simple-scaffold",
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
})
|
||||
|
||||
// TODO find how to mock getGitConfig properly
|
||||
//
|
||||
// describe("getConfig", () => {
|
||||
// test("gets git config", async () => {
|
||||
// // const original = config.githubPartToUrl
|
||||
// // config.githubPartToUrl = jest.fn().mockReturnValue(Promise.resolve(blankCliConf))
|
||||
// // const spy = jest.spyOn(config, "parseConfig").mockReturnValue(Promise.resolve(blankCliConf))
|
||||
//
|
||||
// // jest.spyOn(config, "getGitConfig").mockImplementation(() => Promise.resolve({ default: blankCliConf }))
|
||||
// // jest.mock("../src/config", () => ({
|
||||
// // ...jest.requireActual("../src/config"),
|
||||
// // getGitConfig: () => Promise.resolve({ default: blankCliConf }),
|
||||
// // }))
|
||||
// const resultFn = await config.getConfig({
|
||||
// config: "https://github.com/chenasraf/simple-scaffold.git",
|
||||
// isRemote: true,
|
||||
// quiet: true,
|
||||
// verbose: 0,
|
||||
// })
|
||||
// const result = await resolve(resultFn, blankCliConf)
|
||||
// expect(result).toEqual({ default: blankCliConf })
|
||||
// // expect(spy.)
|
||||
// // config.githubPartToUrl = original
|
||||
// })
|
||||
// })
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "commonjs",
|
||||
@@ -9,7 +10,10 @@
|
||||
"outDir": "dist",
|
||||
"strict": true,
|
||||
"sourceMap": true,
|
||||
"removeComments": false
|
||||
"removeComments": false,
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/index.ts", "src/cmd.ts"],
|
||||
"exclude": ["tests/*"]
|
||||
|
||||
Reference in New Issue
Block a user