Permalink
Browse files

Single to double

  • Loading branch information...
1 parent 7e8bd89 commit 98d31480be999f7b20f0ab496e315d4e1348cf3e @vkadam committed Oct 18, 2014
Showing with 150 additions and 150 deletions.
  1. +36 −36 Gruntfile.js
  2. +9 −9 README.md
  3. +1 −1 bin/grunt-jsbeautifier
  4. +32 −32 tasks/jsbeautifier.js
  5. +25 −25 test/configFile_test.js
  6. +8 −8 test/dest_test.js
  7. +13 −13 test/fileMapping_test.js
  8. +7 −7 test/force_test.js
  9. +19 −19 test/mode_test.js
View
@@ -1,72 +1,72 @@
-'use strict';
+"use strict";
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
- files: ['package.json', 'Gruntfile.js', 'tasks/**/*.js', 'test/**/*.js'],
+ files: ["package.json", "Gruntfile.js", "tasks/**/*.js", "test/**/*.js"],
options: {
jshintrc: true
}
},
jsbeautifier: {
default: {
- src: ['<%= jshint.files %>', '!test/fixtures/**', 'package.json']
+ src: ["<%= jshint.files %>", "!test/fixtures/**", "package.json"]
},
successWithForce: {
- src: ['tmp/verifyMode/not-been-beautified.js', 'tmp/verifyMode/not-been-beautified.css'],
+ src: ["tmp/verifyMode/not-been-beautified.js", "tmp/verifyMode/not-been-beautified.css"],
options: {
- mode: 'VERIFY_ONLY'
+ mode: "VERIFY_ONLY"
}
},
hasNotBeenBeautified: {
- src: ['tmp/verifyMode/not-been-beautified.js', 'tmp/verifyMode/not-been-beautified.css'],
+ src: ["tmp/verifyMode/not-been-beautified.js", "tmp/verifyMode/not-been-beautified.css"],
options: {
- mode: 'VERIFY_ONLY'
+ mode: "VERIFY_ONLY"
}
},
hasBeenBeautified: {
- src: ['tmp/verifyMode/been-beautified.js'],
+ src: ["tmp/verifyMode/been-beautified.js"],
options: {
- mode: 'VERIFY_ONLY'
+ mode: "VERIFY_ONLY"
}
},
fileMapping: {
- src: ['tmp/fileMapping/not-beautified.js.erb',
- 'tmp/fileMapping/not-beautified.css.erb', 'tmp/fileMapping/not-beautified.html.erb'
+ src: ["tmp/fileMapping/not-beautified.js.erb",
+ "tmp/fileMapping/not-beautified.css.erb", "tmp/fileMapping/not-beautified.html.erb"
],
options: {
js: {
- fileTypes: ['.js.erb'],
+ fileTypes: [".js.erb"],
maxPreserveNewlines: 2
},
css: {
- fileTypes: ['.css.erb']
+ fileTypes: [".css.erb"]
},
html: {
- fileTypes: ['.html.erb'],
+ fileTypes: [".html.erb"],
preserveNewLines: true,
maxPreserveNewlines: 1
}
}
},
configFile: {
- src: ['tmp/configFile/test.js',
- 'tmp/configFile/test.css', 'tmp/configFile/test.html'
+ src: ["tmp/configFile/test.js",
+ "tmp/configFile/test.css", "tmp/configFile/test.html"
],
options: {
- config: 'tmp/configFile/jsbeautifyrc.json'
+ config: "tmp/configFile/jsbeautifyrc.json"
}
},
configFileFlat: {
- src: '<%= jsbeautifier.configFile.src %>',
+ src: "<%= jsbeautifier.configFile.src %>",
options: {
- config: 'tmp/configFile/jsbeautifyrc_flat.json'
+ config: "tmp/configFile/jsbeautifyrc_flat.json"
}
},
configFileWithGruntFileOptions: {
- src: '<%= jsbeautifier.configFile.src %>',
+ src: "<%= jsbeautifier.configFile.src %>",
options: {
- config: 'tmp/configFile/jsbeautifyrc_flat.json',
+ config: "tmp/configFile/jsbeautifyrc_flat.json",
js: {
indentSize: 3
},
@@ -79,36 +79,36 @@ module.exports = function(grunt) {
}
},
dest: {
- src: ['tmp/not-been-beautified.js'],
+ src: ["tmp/not-been-beautified.js"],
options: {
- dest: 'dest'
+ dest: "dest"
}
}
},
copy: {
tmp: {
- src: ['**'],
- dest: 'tmp',
- cwd: 'test/fixtures',
+ src: ["**"],
+ dest: "tmp",
+ cwd: "test/fixtures",
expand: true
}
},
- clean: ['tmp', 'dest'],
+ clean: ["tmp", "dest"],
nodeunit: {
- all: ['test/**/*.js']
+ all: ["test/**/*.js"]
}
});
- // Actually load this plugin's task(s).
- grunt.loadTasks('tasks');
+ // Actually load this plugin"s task(s).
+ grunt.loadTasks("tasks");
// These plugins provide necessary tasks.
- grunt.loadNpmTasks('grunt-contrib-jshint');
- grunt.loadNpmTasks('grunt-contrib-nodeunit');
- grunt.loadNpmTasks('grunt-contrib-copy');
- grunt.loadNpmTasks('grunt-contrib-clean');
+ grunt.loadNpmTasks("grunt-contrib-jshint");
+ grunt.loadNpmTasks("grunt-contrib-nodeunit");
+ grunt.loadNpmTasks("grunt-contrib-copy");
+ grunt.loadNpmTasks("grunt-contrib-clean");
// By default, beautifiy, lint and run all tests.
- grunt.registerTask('test', ['jshint', 'copy', 'nodeunit', 'clean']);
- grunt.registerTask('default', ['test', 'jsbeautifier:default']);
+ grunt.registerTask("test", ["jshint", "copy", "nodeunit", "clean"]);
+ grunt.registerTask("default", ["test", "jsbeautifier:default"]);
};
View
@@ -15,7 +15,7 @@ npm install grunt-jsbeautifier --save-dev
One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
```
-grunt.loadNpmTasks('grunt-jsbeautifier');
+grunt.loadNpmTasks("grunt-jsbeautifier");
```
### Grunt `~0.3.0`
@@ -28,7 +28,7 @@ npm install grunt-jsbeautifier@0.1.4
Then add this line to your project's `grunt.js` gruntfile:
```
-grunt.loadNpmTasks('grunt-jsbeautifier');
+grunt.loadNpmTasks("grunt-jsbeautifier");
```
[grunt]: http://gruntjs.com/
@@ -88,7 +88,7 @@ If mode is "VERIFY_ONLY", then task will fail if at least one file can be beauti
#### options.dest (optional)
Type: `String`
-Default value: `''`
+Default value: `""`
All beautified file will be stored under "dest".
@@ -154,7 +154,7 @@ Only specifiy options to overwrite.
All files from foo folder except bar.js
```javascript
jsbeautifier: {
- files: ['foo/*.js', '!foo/bar.js']
+ files: ["foo/*.js", "!foo/bar.js"]
}
```
#### 2. Use specific version of js-beautify
@@ -163,19 +163,19 @@ If you want use specific version of js-beautify instead of latest, please refer
#### 3. Beautify files other than js, json, css & html
If you need to beautify files other than js, json, css & html, it can be done by passing **fileTypes**.
-For example, beautifying **'.js.erb'** files **along with '.js'**, beautifying **'.less'** files **along with '.css'**, beautifying **'.html.erb'** files **along with '.html'**.
+For example, beautifying **".js.erb"** files **along with ".js"**, beautifying **".less"** files **along with ".css"**, beautifying **".html.erb"** files **along with ".html"**.
```
jsbeautifier: {
- files: ['foo/css/*.css', 'bar/css/*.less', 'foo/js/*.js', 'bar/js/*.js.erb', 'foo/html/*.html', 'bar/html/*.html.erb'],
+ files: ["foo/css/*.css", "bar/css/*.less", "foo/js/*.js", "bar/js/*.js.erb", "foo/html/*.html", "bar/html/*.html.erb"],
options: {
js: {
- fileTypes: ['.js.erb']
+ fileTypes: [".js.erb"]
},
css: {
- fileTypes: ['.less']
+ fileTypes: [".less"]
},
html: {
- fileTypes: ['.html.erb']
+ fileTypes: [".html.erb"]
}
}
}
@@ -1,2 +1,2 @@
#!/usr/bin/env node
-require('grunt').npmTasks('grunt-jsbeautifier').cli();
+require("grunt").npmTasks("grunt-jsbeautifier").cli();
View
@@ -1,11 +1,11 @@
-'use strict';
+"use strict";
module.exports = function(grunt) {
- var path = require('path'),
- jsBeautifier = require('js-beautify'),
- lodash = require('lodash'),
- stringUtils = require('underscore.string'),
+ var path = require("path"),
+ jsBeautifier = require("js-beautify"),
+ lodash = require("lodash"),
+ stringUtils = require("underscore.string"),
jsbeautifier = jsBeautifier.js,
cssbeautifier = jsBeautifier.css,
htmlbeautifier = jsBeautifier.html;
@@ -15,11 +15,11 @@ module.exports = function(grunt) {
// ==========================================================================
// TASKS
// ==========================================================================
- grunt.task.registerMultiTask('jsbeautifier', 'jsbeautifier.org for grunt', function() {
+ grunt.task.registerMultiTask("jsbeautifier", "jsbeautifier.org for grunt", function() {
var params = this.options({
- mode: 'VERIFY_AND_WRITE',
- dest: '',
+ mode: "VERIFY_AND_WRITE",
+ dest: "",
js: {},
css: {},
html: {}
@@ -44,7 +44,7 @@ module.exports = function(grunt) {
lodash.forEach([config.js, config.css, config.html], function(conf) {
lodash.forEach(conf, function(value, key) {
underscoreKey = stringUtils.underscored(key);
- if ('fileTypes' !== key && key !== underscoreKey) {
+ if ("fileTypes" !== key && key !== underscoreKey) {
conf[underscoreKey] = value;
delete conf[key];
}
@@ -54,15 +54,15 @@ module.exports = function(grunt) {
if (this.filesSrc && this.filesSrc.length > 0) {
if (!lodash.isEmpty(params.dest)) {
- grunt.verbose.writeln('All beautified files will be stored under "' + params.dest + '" folder');
- if (!stringUtils.endsWith(params.dest, '/')) {
- params.dest += '/';
+ grunt.verbose.writeln("All beautified files will be stored under \"" + params.dest + "\" folder");
+ if (!stringUtils.endsWith(params.dest, "/")) {
+ params.dest += "/";
}
}
- grunt.verbose.writeln('Beautifying using filesSrc with ' + this.filesSrc.length.toString().cyan + ' files...');
+ grunt.verbose.writeln("Beautifying using filesSrc with " + this.filesSrc.length.toString().cyan + " files...");
- grunt.verbose.writeln('Using mode="' + params.mode + '"...');
- var actionHandler = 'VERIFY_ONLY' === params.mode ? verifyActionHandler : verifyAndWriteActionHandler;
+ grunt.verbose.writeln("Using mode=\"" + params.mode + "\"...");
+ var actionHandler = "VERIFY_ONLY" === params.mode ? verifyActionHandler : verifyAndWriteActionHandler;
var config;
if (params.config) {
@@ -84,15 +84,15 @@ module.exports = function(grunt) {
} else {
config = params;
}
- config.js.fileTypes = lodash.union(config.js.fileTypes, ['.js', '.json']);
- config.css.fileTypes = lodash.union(config.css.fileTypes, ['.css']);
- config.html.fileTypes = lodash.union(config.html.fileTypes, ['.html']);
+ config.js.fileTypes = lodash.union(config.js.fileTypes, [".js", ".json"]);
+ config.css.fileTypes = lodash.union(config.css.fileTypes, [".css"]);
+ config.html.fileTypes = lodash.union(config.html.fileTypes, [".html"]);
- grunt.verbose.writeln('Beautify config before converting camelcase to underscore: ' + JSON.stringify(config));
+ grunt.verbose.writeln("Beautify config before converting camelcase to underscore: " + JSON.stringify(config));
convertCamelCaseToUnderScore(config);
- grunt.verbose.writeln('Using beautify config: ' + JSON.stringify(config));
+ grunt.verbose.writeln("Using beautify config: " + JSON.stringify(config));
var done = this.async();
var q = grunt.util.async.queue(function(src, callback) {
@@ -107,10 +107,10 @@ module.exports = function(grunt) {
}, 10);
q.drain = function() {
if (unverifiedFiles.length) {
- grunt.fail.warn('The following files are not beautified:\n' +
- unverifiedFiles.join('\n').cyan + '\n');
+ grunt.fail.warn("The following files are not beautified:\n" +
+ unverifiedFiles.join("\n").cyan + "\n");
}
- grunt.log.write('Beautified ' + fileCount.toString().cyan + ' files, changed ' + changedFileCount.toString().cyan + ' files...');
+ grunt.log.write("Beautified " + fileCount.toString().cyan + " files, changed " + changedFileCount.toString().cyan + " files...");
grunt.log.ok();
done();
};
@@ -129,11 +129,11 @@ module.exports = function(grunt) {
addNewLine = setup[2];
var original = grunt.file.read(file);
- grunt.verbose.write('Beautifying ' + file.cyan + '...');
+ grunt.verbose.write("Beautifying " + file.cyan + "...");
var result = beautifier(original, beautifyConfig);
// jsbeautifier would skip the line terminator for js files
if (addNewLine) {
- result += '\n';
+ result += "\n";
}
grunt.verbose.ok();
/*jshint eqeqeq: false */
@@ -145,9 +145,9 @@ module.exports = function(grunt) {
function getFileType(file, config) {
var fileType = null,
fileMapping = {
- 'js': config.js.fileTypes,
- 'css': config.css.fileTypes,
- 'html': config.html.fileTypes
+ "js": config.js.fileTypes,
+ "css": config.css.fileTypes,
+ "html": config.html.fileTypes
};
lodash.forEach(fileMapping, function(extensions, type) {
fileType = type;
@@ -161,14 +161,14 @@ module.exports = function(grunt) {
function getBeautifierSetup(file, config) {
var fileType = getFileType(file, config);
switch (fileType) {
- case 'js':
+ case "js":
return [jsbeautifier, config.js, true];
- case 'css':
+ case "css":
return [cssbeautifier, config.css];
- case 'html':
+ case "html":
return [htmlbeautifier, config.html];
default:
- grunt.fail.warn('Cannot beautify ' + file.cyan + ' (only js, css and html files can be beautified)');
+ grunt.fail.warn("Cannot beautify " + file.cyan + " (only js, css and html files can be beautified)");
return null;
}
}
Oops, something went wrong.

0 comments on commit 98d3148

Please sign in to comment.