Comments (4)
I ran into the same issue and — given the age of this issue — modified the task as follows to support all plugins;
I hope this is of use to someone.
/*
* grunt-esformatter
*
* Copyright (c) 2013 Jörn Zaefferer, contributors
* Licensed under the MIT license.
*/
'use strict';
module.exports = function(grunt) {
grunt.registerMultiTask('esformatter', 'Format JS files', gruntEsformatter);
function gruntEsformatter() {
var esformatter = require('esformatter');
var options = this.options();
(options.plugins || []).forEach(registerPlugin);
this.files.forEach(formatFileList);
function formatFileList(file) {
file.src
.filter(assertFile)
.forEach(formatFile);
}
function registerPlugin(name) {
esformatter.register(require(name));
}
function assertFile(filePath) {
if (grunt.file.exists(filePath)) {
return true;
}
grunt.log.warn('Source file "' + filePath + '" not found.');
return false;
}
function formatFile(file) {
var formatted;
var firstLine;
var content = grunt.file.read(file);
if (options.skipHashbang) {
firstLine = content.match(/^#!.+\n/);
content = content.replace(firstLine, "");
}
try {
formatted = esformatter.format(content, options);
} catch (e) {
grunt.log.error('Exception while formatting ' + file);
grunt.log.error(e.stack);
return;
}
if (options.skipHashbang && firstLine) {
formatted = firstLine + formatted;
}
grunt.file.write(file, formatted);
grunt.log.writeln('File ' + file + ' formatted.');
}
}
};
/cc @jzaefferer @sedge
from grunt-esformatter.
A pull request would help.
from grunt-esformatter.
Of course, this is ordinarily what I'd do but I held back after seeing this comment from @sedge, that there is work from him to come in this area.
Thanks all.
from grunt-esformatter.
Good point, I forgot about that PR. Since its been several months, I think you could take this over. Also supporting esformatter plugins in general makes much more sense than supporting one specific plugin.
from grunt-esformatter.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-esformatter.