-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
97 lines (87 loc) · 2.7 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var del = require("del");
var fs = require("fs");
var info = require("./package.json");
var gulp = require("gulp");
var jshint = require("gulp-jshint");
var stylish = require('jshint-stylish');
var prettify = require("gulp-jsbeautifier");
var rename = require("gulp-rename");
var template = require("gulp-template");
var uglify = require("gulp-uglify");
var wrapper = require("gulp-wrapper");
var yuidoc = require("gulp-yuidoc");
var paths = {};
paths.src = "./lib/*.js";
paths.docDir = "./doc/";
paths.dist = "./dist";
paths.distRatio = paths.dist + "/Ratio-VERSION.js".replace("VERSION", info.version);
paths.libRatio = "./lib/Ratio-beta.js";
paths.packageInfo = "./package.json";
paths.readme = "./readme.md";
paths.index = "./examples/index.html";
paths.tests = "./test/js/**/*.js";
paths.gulpfile = "./gulpfile.js";
var readAndUpdateVersion = function(filePath, updateFunc) {
console.log("Updating version number in %s", filePath);
var file = fs.readFileSync(filePath).toString(),
updatedFile = updateFunc(file, info.version);
fs.writeFileSync(filePath, updatedFile);
};
var updateRatioFilePathFunc = function(str, version) {
return ("" + str).replace(/(\/Ratio-)([\d.]+[^\.]+)(.js)/, "$1" + version + "$3");
};
gulp.task("makeMin", ["makeDist"], function() {
gulp.src(paths.distRatio)
.pipe(uglify())
.pipe(wrapper({
header: "/*Ratio.js version:" + info.version + " by Larry Battle*/\n"
}))
.pipe(rename({
suffix: ".min"
}))
.pipe(gulp.dest(paths.dist));
});
gulp.task("makeDist", ["lint"], function() {
del([paths.dist], function() {
gulp.src(paths.libRatio)
.pipe(rename({
basename: "Ratio-",
suffix: info.version
}))
.pipe(template(info))
.pipe(gulp.dest(paths.dist));
});
});
gulp.task("buildDoc", function() {
del([paths.docDir], function() {
gulp.src(paths.distRatio)
.pipe(yuidoc())
.pipe(gulp.dest(paths.docDir));
});
});
gulp.task("format", function() {
gulp.src([paths.src, paths.tests, paths.gulpfile], {
base: "./"
})
.pipe(prettify({
js: {
indentSize: 2
}
}))
.pipe(gulp.dest("./"));
});
gulp.task("lint", function(cb) {
return gulp.src([paths.src])
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter("fail"));
});
gulp.task("updateLinks", function() {
readAndUpdateVersion(paths.readme, function(str, version) {
return ("" + str).replace(/("ratioVersion"\s*>)([^<]+)(<\/)/, "$1" + version + "$3");
});
"packageInfo,readme,index".split(",").forEach(function(pathName) {
readAndUpdateVersion(paths[pathName], updateRatioFilePathFunc);
});
});
gulp.task("build", ["lint", "format", "makeDist", "makeMin", "buildDoc", "updateLinks"]);