parent
15b1b808df
commit
534eb109e9
5 changed files with 35 additions and 4 deletions
|
@ -15,6 +15,7 @@ module.exports = async (info) => {
|
||||||
const {
|
const {
|
||||||
manager,
|
manager,
|
||||||
template,
|
template,
|
||||||
|
templatePath,
|
||||||
name
|
name
|
||||||
} = info
|
} = info
|
||||||
|
|
||||||
|
@ -26,7 +27,9 @@ module.exports = async (info) => {
|
||||||
info.dest = dest
|
info.dest = dest
|
||||||
await mkdirp(dest)
|
await mkdirp(dest)
|
||||||
|
|
||||||
const source = path.join(__dirname, '..', 'template', template)
|
const source = template === 'custom'
|
||||||
|
? path.join(process.cwd(), templatePath)
|
||||||
|
: path.join(__dirname, '..', 'template', template)
|
||||||
const files = await globby(source, {
|
const files = await globby(source, {
|
||||||
dot: true
|
dot: true
|
||||||
})
|
})
|
||||||
|
|
|
@ -52,6 +52,16 @@ const tests = [
|
||||||
license: 'GPL',
|
license: 'GPL',
|
||||||
manager: 'yarn',
|
manager: 'yarn',
|
||||||
template: 'default'
|
template: 'default'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'my-custom-template',
|
||||||
|
author: 'nala',
|
||||||
|
description: 'this is a auto-generated test module. please ignore.',
|
||||||
|
repo: 'nala/my-custom-template',
|
||||||
|
license: 'GPL',
|
||||||
|
manager: 'yarn',
|
||||||
|
template: 'custom',
|
||||||
|
templatePath: './template/default'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ module.exports = async () => {
|
||||||
.option('-l, --license <string>', 'package license', defaults.license)
|
.option('-l, --license <string>', 'package license', defaults.license)
|
||||||
.option('-r, --repo <string>', 'package repo path')
|
.option('-r, --repo <string>', 'package repo path')
|
||||||
.option('-m, --manager <npm|yarn>', 'package manager to use', /^(npm|yarn)$/, defaults.manager)
|
.option('-m, --manager <npm|yarn>', 'package manager to use', /^(npm|yarn)$/, defaults.manager)
|
||||||
.option('-t, --template <default|typescript>', 'package template to use', /^(default|typescript)$/, defaults.template)
|
.option('-t, --template <default|typescript>', 'package template to use', /^(default|typescript|custom)$/, defaults.template)
|
||||||
|
.option('-p, --template-path <string>', 'custom package template path')
|
||||||
.option('-s, --skip-prompts', 'skip all prompts (must provide package-name via cli)')
|
.option('-s, --skip-prompts', 'skip all prompts (must provide package-name via cli)')
|
||||||
.parse(process.argv)
|
.parse(process.argv)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const path = require('path')
|
||||||
|
const fs = require('fs')
|
||||||
const inquirer = require('inquirer')
|
const inquirer = require('inquirer')
|
||||||
const validateNpmName = require('validate-npm-package-name')
|
const validateNpmName = require('validate-npm-package-name')
|
||||||
|
|
||||||
|
@ -69,8 +71,23 @@ module.exports = async (opts) => {
|
||||||
type: 'list',
|
type: 'list',
|
||||||
name: 'template',
|
name: 'template',
|
||||||
message: 'Template',
|
message: 'Template',
|
||||||
choices: [ 'default', 'typescript' ],
|
choices: [ 'default', 'typescript', 'custom' ],
|
||||||
default: opts.template
|
default: opts.template
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'templatePath',
|
||||||
|
message: 'Template Path',
|
||||||
|
when: ({ template }) => template === 'custom',
|
||||||
|
validate: input => new Promise(resolve => {
|
||||||
|
const fullPath = path.resolve(process.cwd(), input)
|
||||||
|
fs.stat(fullPath, (err, stats) => {
|
||||||
|
if (err) {
|
||||||
|
return resolve(`Cannot resolve directory at: ${fullPath}`)
|
||||||
|
}
|
||||||
|
resolve(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
"inquirer": "^6.0.0",
|
"inquirer": "^6.0.0",
|
||||||
"make-dir": "^1.3.0",
|
"make-dir": "^1.3.0",
|
||||||
"node-compat-require": "^1.0.5",
|
"node-compat-require": "^1.0.5",
|
||||||
"ora": "^2.1.0",
|
"ora": "^3.0.0",
|
||||||
"p-each-series": "^1.0.0",
|
"p-each-series": "^1.0.0",
|
||||||
"parse-git-config": "^2.0.2",
|
"parse-git-config": "^2.0.2",
|
||||||
"validate-npm-package-name": "^3.0.0",
|
"validate-npm-package-name": "^3.0.0",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue