From 1a147c6a59c2db087f2fb6124d67bbb4f2ad37de Mon Sep 17 00:00:00 2001 From: Paden Date: Mon, 29 Jun 2015 11:34:49 -0500 Subject: [PATCH 1/2] typescript-formatter#verify updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update to async lib (grunt async is deprecated) - Removed directory check (wasn’t needed) - Add grunt tests for verify method - Updated package version (sorry if this was presumptuous) - fixes #2 --- .gitignore | 2 ++ Gruntfile.js | 22 +++++++++++++--- package.json | 5 ++-- tasks/typescript-formatter.js | 47 ++++++++++++++++++++++------------- 4 files changed, 53 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 6cb772b..7b59b3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules tmp + +tsconfig.json diff --git a/Gruntfile.js b/Gruntfile.js index 994e2f2..f7fc639 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -16,24 +16,38 @@ module.exports = function(grunt) { // Configuration to be run (and then tested). 'typescript-formatter': { - test: { + replaceInTemp: { options: { - replace: false + replace: false, + verbose: true, }, files: { "tmp/": "test/**/*.ts" } + }, + verifyTemp: { + options: { + verbose: true, + replace: false, + verify: true + }, + files: + { + src: ["tmp/**/*.ts"] + } } + } }); // Actually load this plugin's task(s). - grunt.loadTasks("tasks"); + grunt.loadTasks("./tasks"); // These plugins provide necessary tasks. grunt.loadNpmTasks("grunt-contrib-jshint"); grunt.loadNpmTasks("grunt-contrib-clean"); - grunt.registerTask("test", ["typescript-formatter"]); + grunt.registerTask("test", ["typescript-formatter:replaceInTemp"]); + grunt.registerTask("test2", ["typescript-formatter:verifyTemp"]); // By default, lint and run all tests. grunt.registerTask("default", ["jshint", "test"]); diff --git a/package.json b/package.json index f8dcc36..15f0f25 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt-typescript-formatter", "description": "Grunt formatter for TypeScript.", - "version": "0.2.2", + "version": "0.2.3", "homepage": "https://github.com/daptiv/grunt-typescript-formatter", "author": { "name": "Jonathan Park, Daptiv" @@ -27,6 +27,7 @@ "test": "grunt test" }, "dependencies": { + "async": "^1.2.1", "native-promise-only": "^0.7.6-a", "underscore": "^1.6.0" }, @@ -40,7 +41,7 @@ }, "peerDependencies": { "grunt": "~0.4.1", - "typescript-formatter": "^0.2.2" + "typescript-formatter": "~0.4.0" }, "keywords": [ "gruntplugin" diff --git a/tasks/typescript-formatter.js b/tasks/typescript-formatter.js index 0d713e3..5ca1b81 100644 --- a/tasks/typescript-formatter.js +++ b/tasks/typescript-formatter.js @@ -5,6 +5,7 @@ module.exports = function(grunt) { require('native-promise-only'); var path = require('path'); var formatter = require("typescript-formatter"); + var async = require('async'); grunt.registerMultiTask("typescript-formatter", "A formatter for TypeScript.", function() { var options = this.options({ replace: true, dryRun: true }); @@ -13,32 +14,44 @@ module.exports = function(grunt) { // Iterate over all specified file groups, async for 'streaming' output on large projects - grunt.util.async.reduce(this.files, true, function(success, filePair, callback) { + async.reduce(this.files, true, function(success, filePair, callback) { var files = filePair.src; - if (!grunt.file.isDir(filePair.dest)) { - grunt.log.error("Destination must be a folder", filePair.dest); - failed++; - } - var result = formatter.processFiles(files, options); - _.each(result, function(file) { - if(!options.replace) { - grunt.file.write(path.resolve(filePair.dest, file.fileName), file.dest); + + formatter.processFiles(files, options).then(function(result) { + _.each(result, function(file) { + if(file.error) { + failed++; + grunt.log.error(file.message); + } + }); + + if (failed > 0) { + callback(true); + return; } - }); - // Using setTimout as process.nextTick() doesn't flush - setImmediate(function() { - callback(null, success); + + _.each(result, function(file) { + if(!options.replace || !options.verify) { + grunt.file.write(path.resolve(filePair.dest, file.fileName), file.dest); + } + }); + // Using setTimout as process.nextTick() doesn't flush + setImmediate(function() { + callback(null, success); + }); }); }, function(err, success) { - if (err) { - done(err); - } else if (!success) { + if (err || !success) { grunt.log.error(failed + " " + grunt.util.pluralize(failed,"error/errors")); done(false); } else { + if (options.verify) { + grunt.log.ok("files in correct format."); + } else { grunt.log.ok("files reformatted."); - done(); + } + done(); } }.bind(this)); }); From 3e20ab1f41edd6785aa412828045cff7fc610617 Mon Sep 17 00:00:00 2001 From: Paden Date: Tue, 30 Jun 2015 15:12:04 -0500 Subject: [PATCH 2/2] Updates to replace method that tsft now accomodates --- tasks/typescript-formatter.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tasks/typescript-formatter.js b/tasks/typescript-formatter.js index 5ca1b81..6d2ba70 100644 --- a/tasks/typescript-formatter.js +++ b/tasks/typescript-formatter.js @@ -30,11 +30,20 @@ module.exports = function(grunt) { return; } - _.each(result, function(file) { - if(!options.replace || !options.verify) { - grunt.file.write(path.resolve(filePair.dest, file.fileName), file.dest); - } - }); + if(!options.replace) + { + if (!grunt.file.isDir(filePair.dest)) { + grunt.log.error("Destination must be a folder", filePair.dest); + failed++; + callback(true); + return; + } else { + _.each(result, function(file) { + grunt.file.write(path.resolve(filePair.dest, file.fileName), file.dest); + }); + } + } + // Using setTimout as process.nextTick() doesn't flush setImmediate(function() { callback(null, success);