Skip to content

Commit

Permalink
up to date promises in template tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiip committed May 21, 2015
1 parent afc8944 commit 4091c9b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 48 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"dependencies": {
"chalk": "~1.0.0",
"ejs": "^2.3.1",
"lodash": "~3.7.0",
"slash": "~1.0.0",
"underscore.string": "~3.0.3",
Expand All @@ -39,20 +38,22 @@
"bower": "~1.4.1",
"chai": "~2.3.0",
"chai-as-promised": "~5.0.0",
"commander": "^2.8.1",
"commander": "~2.8.1",
"coveralls": "~2.11.2",
"cross-spawn": "~0.4.0",
"fixture-stdout": "~0.2.1",
"istanbul": "~0.3.14",
"js-beautify": "^1.5.5",
"js-beautify": "~1.5.5",
"mkdirp": "^0.5.1",
"mocha": "~2.2.5",
"mocha-lcov-reporter": "0.0.2",
"q": "^1.4.1",
"recursive-readdir": "^1.2.1",
"sinon": "^1.14.1",
"sinon-chai": "^2.7.0",
"wrench": "^1.5.8"
"recursive-readdir": "~1.2.1",
"sinon": "~1.14.1",
"sinon-chai": "~2.7.0",
"wrench": "1.5.8",
"ejs": "~2.3.1",
"mz": "~1.3.0",
"bluebird": "~2.9.25"
},
"peerDependencies": {
"yo": ">=1.0.0"
Expand Down
40 changes: 20 additions & 20 deletions test/inception.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';

var fs = require('fs');
var fs = require('mz/fs');
var path = require('path');
var spawn = require('cross-spawn');
var q = require('q');
var _ = require('lodash');
var spawn = require('cross-spawn');
var Promise = require('bluebird');
var helpers = require('yeoman-generator').test;

var testDirectory = Promise.promisify(helpers.testDirectory);

var outputInTest = require('./mute');
var mockOptions = require('../app/src/mock-options.js');
var mockPrompts = require('../app/src/mock-prompts.js');
Expand All @@ -24,10 +26,10 @@ function prepare(optionCase, promptCase) {
var options = _.extend({}, _.cloneDeep(mockOptions.defaults), optionCase, skipOptions);
var prompts = _.extend({}, _.cloneDeep(mockPrompts.defaults), promptCase);

return q.nfcall(helpers.testDirectory, tempDir).then(function() {
return q.all([
q.nfcall(fs.symlink, path.join(depsDir, 'node_modules'), path.join(tempDir, 'node_modules')),
q.nfcall(fs.symlink, path.join(depsDir, 'bower_components'), path.join(tempDir, 'bower_components'))
return testDirectory(tempDir).then(function() {
return Promise.all([
fs.symlink(path.join(depsDir, 'node_modules'), path.join(tempDir, 'node_modules')),
fs.symlink(path.join(depsDir, 'bower_components'), path.join(tempDir, 'bower_components'))
]);
}).then(function() {
var gulpAngular = helpers.createGenerator(
Expand All @@ -46,21 +48,19 @@ function prepare(optionCase, promptCase) {
}

function run(generator, task) {
var deferred = q.defer();

generator.conflicter.force = true;
generator.run(function () {
var gulpProcess = spawn('node', ['node_modules/gulp/bin/gulp.js', task], {stdio: 'inherit'});
gulpProcess.on('exit', function(returnCode) {
if(returnCode === 0) {
deferred.resolve();
} else {
deferred.reject('Gulp returned with error code ' + returnCode);
}
return new Promise(function(resolve, reject) {
generator.conflicter.force = true;
generator.run(function () {
var gulpProcess = spawn('node', ['node_modules/gulp/bin/gulp.js', task], {stdio: 'inherit'});
gulpProcess.on('exit', function(returnCode) {
if(returnCode === 0) {
resolve();
} else {
reject('Gulp returned with error code ' + returnCode);
}
});
});
});

return deferred.promise;
}

module.exports = {
Expand Down
34 changes: 17 additions & 17 deletions test/template-tools.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
/* jshint camelcase:false */

var fs = require('fs');
var fs = require('mz/fs');
var Promise = require('bluebird');
var path = require('path');
var mkdirp = require('mkdirp');
var mkdirp = Promise.promisify(require('mkdirp'));
var beautify = require('js-beautify').js_beautify;
var q = require('q');
var readdir = require('recursive-readdir');
var readdir = Promise.promisify(require('recursive-readdir'));
var ejs = require('ejs');

var templatesDir = path.join(__dirname, '../app/templates/');
Expand Down Expand Up @@ -41,14 +41,14 @@ function compile(fileName) {
var destinationFilePath = compiledTemplatesDir + fileName + compiledTemplatesSuffix;
var destinationDir = path.dirname(destinationFilePath);

return q.all([
q.nfcall(mkdirp, destinationDir),
q.nfcall(fs.readFile, sourceFilePath)
return Promise.all([
mkdirp(destinationDir),
fs.readFile(sourceFilePath)
]).then(function(results) {
var content = results[1].toString();
var sourceContent = sourceHeader + beautify(compileEjs(content), { indent_size: 2 }) + sourceFooter;
sourceContent = sourceContent.replace('with(locals || {})', 'with(locals)');
return q.nfcall(fs.writeFile, destinationFilePath, sourceContent);
return fs.writeFile(destinationFilePath, sourceContent);
});
}

Expand All @@ -66,9 +66,9 @@ function load(fileName) {
}

function prepare() {
return q.nfcall(readdir, templatesDir)
return readdir(templatesDir)
.then(function(files) {
return q.all(files.filter(function(file) {
return Promise.all(files.filter(function(file) {
var basename = path.basename(file);
return /^_[^_]/.test(basename);
}).map(function(file) {
Expand Down Expand Up @@ -102,16 +102,16 @@ function deps() {
return ejs.render(string, data);
}

return q.all([
q.nfcall(mkdirp, depsDir),
q.nfcall(fs.readFile, packagePath),
q.nfcall(fs.readFile, bowerPath)
return Promise.all([
mkdirp(depsDir),
fs.readFile(packagePath),
fs.readFile(bowerPath)
]).then(function(results) {
var packageFileContent = processTemplate(results[1]);
var bowerFileContent = processTemplate(results[2]);
return q.all([
q.nfcall(fs.writeFile, packageDestinationPath, packageFileContent),
q.nfcall(fs.writeFile, bowerDestinationPath, bowerFileContent)
return Promise.all([
fs.writeFile(packageDestinationPath, packageFileContent),
fs.writeFile(bowerDestinationPath, bowerFileContent)
]);
})
.catch(function(error) {
Expand Down
4 changes: 2 additions & 2 deletions test/template/test-index-module-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var sinonChai = require('sinon-chai');
chai.should();
chai.use(sinonChai);

var q = require('q');
var Promise = require('bluebird');

var templateTools = require('../template-tools');
var mockModel = require('./mock-model');
Expand All @@ -15,7 +15,7 @@ describe('gulp-angular index js template', function () {
var model, indexJs, indexEs6, indexCoffee, indexTs;

before(function() {
return q.all([
return Promise.all([
templateTools.load('src/app/_index.module.js'),
templateTools.load('src/app/_index.module.es6'),
templateTools.load('src/app/_index.module.coffee'),
Expand Down

0 comments on commit 4091c9b

Please sign in to comment.