forked from mrmeku/HTfloML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
59 lines (49 loc) · 1.74 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
var gulp = require('gulp');
var fs = require('fs');
var browserify = require('browserify');
var source = require('vinyl-source-stream'); // makes browserify bundle compatible with gulp
var HTFLOML = require('./dist/html-formatter.js');
var browserifyFile = function(event) {
browserify(event.path).bundle()
.pipe(source(event.path.split('/').pop()))
.pipe(gulp.dest('./test'));
}
var formatFile = function(filePath, formatter) {
fs.readFile(filePath, 'utf8', function (err, data) {
if (err) {
console.log(err);
} else {
fs.writeFile(filePath, formatter.format(data), 'utf8');
}
});
}
gulp.task('format', function() {
var args = process.argv.slice(2);
var filePath = args.slice(args.indexOf('-f'))[1];
if (!filePath) {
console.error('Use -f to supply a file path to format');
}
var indentSize = args.slice(args.indexOf('-i'))[1] || 2;
var wrappingColumn = args.slice(args.indexOf('-w'))[1] || 120 ;
var formatter = new HTFLOML.HtmlFormatter(indentSize, wrappingColumn);
formatFile(filePath, formatter);
});
gulp.task('watch', function(done) {
var args = process.argv.slice(2);
var glob = args.slice(args.indexOf('-g'))[1];
if (!glob) {
console.error('Use -g to supply a glob to watch and format');
}
var indentSize = args.slice(args.indexOf('-i'))[1] || 2;
var wrappingColumn = args.slice(args.indexOf('-w'))[1] || 120 ;
var formatter = new HTFLOML.HtmlFormatter(indentSize, wrappingColumn);
gulp.watch(glob, function(event) {
formatFile(event.path, formatter);
});
});
gulp.task('test', function() {
gulp.watch('./dist/*.js', browserifyFile);
browserifyFile({path : './dist/html-formatter.spec.js'})
browserifyFile({path: './dist/html-formatter.js'});
});