Skip to content

Commit

Permalink
add local template
Browse files Browse the repository at this point in the history
  • Loading branch information
mirreal committed Feb 8, 2018
1 parent 055df86 commit e4441b1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
20 changes: 20 additions & 0 deletions lib/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const path = require('path')
const chalk = require('chalk')
const ncp = require('ncp').ncp

ncp.limit = 36

const source = path.resolve(__dirname, '../templates/base/')

module.exports = function(projectName) {
console.log('Start copy local template...')

ncp(source, projectName, err => {
if (err) {
console.log('\n')
return console.log(chalk.red(err))
}

console.log(chalk.green(`Success! Created ${projectName} at ${path.resolve(projectName)}`))
})
}
17 changes: 8 additions & 9 deletions lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ const download = require('download-git-repo')
const ora = require('ora')
const chalk = require('chalk')

const template = {
name: 'trucyx/base-template',
branch: 'master'
}
const template = require('./template')
const copy = require('./copy')

module.exports = function(projectName) {
const downloadUrl = `${template.name}#${template.branch}`
const projectPath = `./${projectName}`

const spinner = ora('Downloading template...')
spinner.start()

download(downloadUrl, projectPath, err => {
download(downloadUrl, projectName, err => {
spinner.stop()

if (err) {
console.log('\n')
console.log(chalk.red(err))
process.exit()

return copy(projectName)
}

spinner.stop()
console.log(chalk.green(`Success! Created ${projectName} at ${path.resolve(projectPath)}`))
console.log(chalk.green(`Success! Created ${projectName} at ${path.resolve(projectName)}`))
})
}
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const downloadTemplate = require('./download')
const copy = require('./copy')

module.exports = {
downloadTemplate
downloadTemplate,
copy
}
4 changes: 4 additions & 0 deletions lib/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
name: 'trucyx/base-template',
branch: 'master'
}

0 comments on commit e4441b1

Please sign in to comment.