Skip to content

Commit

Permalink
remove coffeescript dep in all forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Escalante committed Mar 24, 2016
1 parent 02a12f7 commit f888089
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 143 deletions.
50 changes: 11 additions & 39 deletions lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ const fs = node.liftAll(_fs, (pfs, lifted, name) => {
})
const dns = node.liftAll(_dns)

/*
* Register CoffeeScript `init` file in template can be either CoffeeScript or
* JavaScript.
*/

require('coffee-script/register')

/*
* Given a Sprout instance and a name, returns a Template instance.
* @param {Function} sprout - Sprout instance.
Expand Down Expand Up @@ -75,7 +68,6 @@ class Template {
.then(ensureInternetConnection)
.then(removeTemplate)
.then(moveSourceToSproutPath)
.then(validateTemplate)
.yield(this)
}

Expand All @@ -99,6 +91,7 @@ class Template {
return node.call(Joi.validate, opts, schema).with(this)
.then((res) => { opts = res })
.then(this.update.bind(this))
.then(validateTemplate)
.then(validateTarget.bind(this, target))
.then(handleBranchOrTagOption.bind(this, opts))
.then(createTargetDirectory.bind(this, target))
Expand Down Expand Up @@ -233,18 +226,13 @@ function moveSourceToSproutPath () {
}

function validateTemplate () {
return W.resolve().then(() => {
if (!fs.existsSync(path.join(this.path, 'init.js')) && !fs.existsSync(path.join(this.path, 'init.coffee'))) {
throw new Error('neither init.coffee nor init.js exist in this template')
}
if (!fs.existsSync(path.join(this.path, 'init.js'))) {
throw new Error('init.js does not exist in this template')
}

// Check for root path.
if (!fs.existsSync(this.rootPath)) {
throw new Error('root path doesn\'t exist in template')
}
}).catch((error) => {
return rimraf(this.path).then(() => { throw error })
})
if (!fs.existsSync(this.rootPath)) {
throw new Error('root path does not exist in template')
}
}

function validateTarget (target) {
Expand Down Expand Up @@ -286,17 +274,7 @@ function installDependenciesIfPresent () {
}

function loadConfigFile () {
const initCoffee = path.join(this.path, 'init.coffee')
const initJS = path.join(this.path, 'init.js')
let initPath

if (fs.existsSync(initJS)) {
initPath = initJS
} else if (fs.existsSync(initCoffee)) {
initPath = initCoffee
} else {
throw new Error('neither init.coffee nor init.js exist')
}
const initPath = path.join(this.path, 'init.js')

this.sprout.emit('msg', `requiring and validating ${initPath}`)

Expand Down Expand Up @@ -409,15 +387,9 @@ function runAfterHook (utils) {
}

function validateGenerator (generator) {
const generatorCoffee = path.join(this.generatorsPath, `${generator}.coffee`)
const generatorJs = path.join(this.generatorsPath, `${generator}.js`)
let generatorPath

if (fs.existsSync(generatorJs)) {
generatorPath = generatorJs
} else if (fs.existsSync(generatorCoffee)) {
generatorPath = generatorCoffee
} else {
const generatorPath = path.join(this.generatorsPath, `${generator}.js`)

if (!fs.existsSync(generatorPath)) {
throw new Error(`'${generator}' is not a generator in this template`)
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
],
"dependencies": {
"argparse": "^1.0.2",
"coffee-script": "^1.9.3",
"ejs": "^2.3.1",
"isbinaryfile": "^3.0.0",
"joi": "^8.0.5",
Expand Down
107 changes: 4 additions & 103 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,44 +576,6 @@ describe('template',
)
}
)

it("should throw and remove template when init.coffee and init.js don't exist in template",
function (done) {
var name = 'noInit'
var src = path.join(saveTemplateFixturesPath, name)
var template = new Template({ sprout: sprout, name: name, src: src })
return gitInit(src).then(
function () {
return template.save()
}
).catch(
function (error) {
fs.existsSync(template.path).should.be.false
error.toString().should.eq('Error: neither init.coffee nor init.js exist in this template')
done()
}
)
}
)

it("should throw and remove template when root path doesn't exist in template",
function (done) {
var name = 'noRoot'
var src = path.join(saveTemplateFixturesPath, name)
var template = new Template({ sprout: sprout, name: name, src: src })
return gitInit(src).then(
function () {
return template.save()
}
).catch(
function (error) {
fs.existsSync(template.path).should.be.false
error.toString().should.eq("Error: root path doesn't exist in template")
done()
}
)
}
)
}
)

Expand Down Expand Up @@ -680,7 +642,7 @@ describe('template',
}
).catch(
function (error) {
error.toString().should.match(/ENOENT: no such file or directory/)
error.toString().should.eq('Error: root path does not exist in template')
fs.mkdirSync(template.rootPath)
fs.writeFileSync(path.join(template.rootPath, '.keep'), '')
return template.remove().then(
Expand Down Expand Up @@ -770,7 +732,7 @@ describe('template',
}
)

it('should throw when no init.js or init.coffee provided',
it('should throw when no init.js provided',
function (done) {
var name = 'init'
var fixture = path.join(initTemplateFixturesPath, name)
Expand All @@ -780,12 +742,12 @@ describe('template',
return template.save().then(
function (template) {
fs.existsSync(template.path).should.be.true
fs.unlinkSync(path.join(template.path, 'init.coffee'))
fs.unlinkSync(path.join(template.path, 'init.js'))
return template.init(target)
}
).catch(
function (error) {
error.toString().should.eq('Error: neither init.coffee nor init.js exist')
error.toString().should.eq('Error: init.js does not exist in this template')
return template.remove().then(
function () {
rimraf(target, done)
Expand Down Expand Up @@ -854,35 +816,6 @@ describe('template',
}
)

it('should use init.coffee',
function (done) {
var name = 'initCoffee'
var fixture = path.join(initTemplateFixturesPath, name)
var src = path.join(fixture, 'src')
var target = path.join(fixture, 'target')
var template = new Template({ sprout: sprout, name: name, src: src })
return gitInit(src).then(
function () {
return template.save()
}
).then(
function (template) {
fs.existsSync(template.path).should.be.true
return template.init(target)
}
).then(
function (template) {
fs.readFileSync(path.join(target, 'foo'), 'utf8').should.eq('bar\n')
return template.remove()
}
).then(
function () {
return rimraf(target, done)
}
)
}
)

it('should use a different git branch if specified',
function (done) {
var name = 'branch'
Expand Down Expand Up @@ -1800,38 +1733,6 @@ describe('template',
}
)

it("should run generator if it's a .coffee file",
function (done) {
var name = 'generatorCoffee'
var fixture = path.join(runTemplateFixturesPath, name)
var src = path.join(fixture, 'src')
var target = path.join(fixture, 'target')
var template = new Template({ sprout: sprout, name: name, src: src })
return gitInit(src).then(
function () {
return template.save()
}
).then(
function () {
return template.init(target)
}
).then(
function (template) {
return template.run(target, 'foo')
}
).then(
function (template) {
fs.readFileSync(path.join(target, 'foo'), 'utf8').should.eq('bar')
return template.remove(name)
}
).then(
function () {
return rimraf(target, done)
}
)
}
)

it('should throw error if require returns error',
function (done) {
var name = 'requireError'
Expand Down

1 comment on commit f888089

@kylemac
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔪 ☕

Please sign in to comment.