Skip to content

Commit

Permalink
fix: remove implicit use of Q
Browse files Browse the repository at this point in the history
... when Q is not even in the dependency list
  • Loading branch information
nknapp committed Feb 19, 2019
1 parent f08cadf commit a84fdd9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
30 changes: 15 additions & 15 deletions handlebars/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const { resolvePackageRoot } = require('../../lib/utils/resolve-package-root')
const Handlebars = require('handlebars')
const fs = require('fs-extra')
const util = require('util')
const Q = require('q')

/**
* Default Handlebars-helpers for Thought
Expand Down Expand Up @@ -285,7 +284,7 @@ function htmlId (value) {
* and return true if any of them exists and contains the string.
* We expect coveralls to be configured then.
*
* @return {boolean} true, if coveralls is configured
* @return {Promise<boolean>} true, if coveralls is configured
*
* @access public
* @memberOf helpers
Expand All @@ -301,32 +300,33 @@ function hasCoveralls () {
* and return true if any of them exists and contains the string.
* We expect coveralls to be configured then.
*
* @return {boolean} true, if coveralls is configured
* @return {Promise<boolean> boolean} true, if coveralls is configured
*
* @access public
* @memberOf helpers
*/
function hasCodecov () {
async function hasCodecov () {
return _searchCiConfig('codecov')
}

/**
* Internal function to look for a given string in popular CI config files (like .travis.yml and appveyor.yml)
* @param searchString
* @param {string} searchString the string to search for within the ci files
* @return {Promise<boolean>} true, if the given string is either part of .travis.yml or appveyor.yml
* @private
*/
function _searchCiConfig (searchString) {
const travis = fs.readFile('.travis.yml', 'utf-8')
const appveyor = fs.readFile('appveyor.yml', 'utf-8')
return Q.allSettled([travis, appveyor]).then(function (files) {
let i
for (i = 0; i < files.length; i++) {
if (files[i].state === 'fulfilled' && files[i].value.indexOf(searchString) >= 0) {
return true
async function _searchCiConfig (searchString) {
const ciConfigs = await Promise.all(['.travis.yml', 'appveyor.yml'].map(async (filename) => {
try {
return await fs.readFile(filename, 'utf-8')
} catch (e) {
if (e.code === 'ENOENT') {
return ''
}
throw e
}
return false
})
}))
return ciConfigs.findIndex((contents) => contents.includes(searchString)) >= 0
}

/**
Expand Down
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
'use strict'

var customize = require('customize')
var Q = require('q')
var debug = require('debug')('thought:run')
var write = require('customize-write-files')

Expand All @@ -32,13 +31,11 @@ function thought (options) {
.then(function (filenames) {
if (options.addToGit) {
// Add computed files to the git index.
var git = require('simple-git')()
var deferred = Q.defer()
debug('Adding ' + filenames.join(', ') + ' to git index')
git.add(filenames, deferred.makeNodeResolver())
// Wait for git-add to finish, but return the filenames.
return deferred.promise.then(function () {
return filenames
return new Promise((resolve, reject) => {
var git = require('simple-git')()
debug('Adding ' + filenames.join(', ') + ' to git index')
// Wait for git-add to finish, but return the filenames.
git.add(filenames, (err) => err ? reject(err) : resolve(filenames))
})
}
return filenames
Expand Down
4 changes: 2 additions & 2 deletions test/cli-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ describe('The cli script', function () {
it('should report missing hooks in package.json', function () {
return scenario.prepareAndRun(() => runMockThought('run'))
.then(result => {
expect(result.code).to.equal(0)
expect(result.stdout).to.match(/Not registered in package.json yet/)
expect(result.stderr).to.equal('')
expect(result.stdout).to.match(/Not registered in package.json yet/)
expect(result.code).to.equal(0)
expect(scenario.readActual('README.md')).to.equal(scenario.readExpected('README.md'))
})
})
Expand Down

0 comments on commit a84fdd9

Please sign in to comment.