Esempio n. 1
0
function createTestDir () {
  var dirPath = cwp('test')
  var filePath = cwp('test/index.js')

  if (fs.existsSync(filePath)) {
    return this.emit('warn', 'test/index.js already exists')
  }

  if (!fs.existsSync(dirPath)) fs.mkdirSync(dirPath)

  fs.writeFileSync(filePath, '\n')
  this.emit('create', 'test/index.js')
}
Esempio n. 2
0
ModuleInit.prototype.run = function run () {
  var errors = this.validate()
  var err

  if (errors.missing.length) {
    err = new Error('missing required options: ' + errors.missing.join(', '))
    this.emit('err', err)
    return this.cb(err)
  }

  if (errors.invalid.length) {
    err = new Error('invalid options: ' + errors.invalid.join(', '))
    this.emit('err', err)
    return this.cb(err)
  }

  this.data.nodeName = this.data.nodeName || camelCase(this.data.pkgName)
  this.data.year = this.data.year || new Date().getFullYear()

  exec('git init')

  templates.forEach(createFileFromTemplate.bind(this))
  createIndex.apply(this)
  createTestDir.apply(this)
  fixpack(cwp('package.json'), { quiet: true })

  exec('npm install')

  this.emit('done', this.data)
  return this.cb(null, this.data)
}
Esempio n. 3
0
function createIndex () {
  var filePath = cwp('index.js')

  if (fs.existsSync(filePath)) {
    return this.emit('warn', 'index.js already exists')
  }

  fs.writeFileSync(filePath, '\n')
  this.emit('create', 'index.js')
}
Esempio n. 4
0
function createFileFromTemplate (tpl) {
  var filePath = cwp(tpl.filename)

  if (fs.existsSync(filePath)) {
    return this.emit('warn', tpl.filename + ' already exists')
  }

  fs.writeFileSync(filePath, tpl(this.data))

  this.emit('create', tpl.filename)
}