Skip to content

Commit

Permalink
refactor!: change config structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Oct 8, 2022
1 parent e4b01f3 commit a966588
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
20 changes: 13 additions & 7 deletions src/config.ts
Expand Up @@ -10,22 +10,26 @@ import enquirer from 'enquirer'
import { findConfigTypePath, which } from './utils'

export interface Config {
/** @default true */
gitInit?: boolean
/** @default false */
gitAdd?: boolean
git?: {
/** @default true */
init?: boolean
/** @default false */
add?: boolean
}
templates: Template[]
}

export interface Template extends Pick<Config, 'gitInit' | 'gitAdd'> {
export interface Template extends Pick<Config, 'git'> {
name: string
color?: string
children?: Template[]
url?: string
}

const demoConfig: Config = {
gitInit: true,
git: {
add: true,
},
templates: [
{
name: 'Library',
Expand All @@ -41,7 +45,9 @@ const demoConfig: Config = {
{
name: 'Web App',
url: 'git@github.com:sxzz/node-lib-starter.git',
gitInit: false,
git: {
init: false,
},
},
],
}
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Expand Up @@ -71,13 +71,14 @@ async function create(config: Config, template: Template) {
const emitter = degit(template.url!)
await emitter.clone(projectName)

if (template.gitInit ?? config.gitInit ?? true) {
const gitInit = template.git?.init ?? config.git?.init ?? true
if (gitInit) {
await execa('git', ['init', projectName], { stdio: 'inherit' })
}

const projectPath = path.resolve(process.cwd(), projectName)

if (template.gitAdd || config.gitAdd) {
if (gitInit && (template.git?.add || config.git?.add)) {
await execa('git', ['add', '.'], { stdio: 'inherit', cwd: projectPath })
}

Expand Down

0 comments on commit a966588

Please sign in to comment.