facilmap/frontend/gulpfile.js

128 wiersze
3.5 KiB
JavaScript
Czysty Zwykły widok Historia

2016-02-26 15:36:00 +00:00
var async = require("async");
var es = require("event-stream");
var fs = require("fs");
var gulp = require("gulp");
var templateCache = require("gulp-angular-templatecache");
var clean = require("gulp-clean");
var concat = require("gulp-concat");
var cssBase64 = require("gulp-css-base64");
var gulpIf = require("gulp-if");
2016-10-02 17:23:29 +00:00
var cleanCss = require("gulp-clean-css");
2016-02-26 15:36:00 +00:00
var newer = require("gulp-newer");
var ngAnnotate = require("gulp-ng-annotate");
var replace = require("gulp-replace");
var uglify = require("gulp-uglify");
var mainBowerFiles = require("main-bower-files");
var combine = require("stream-combiner");
2016-10-02 17:23:29 +00:00
var sourcemaps = require("gulp-sourcemaps");
2016-10-07 11:57:20 +00:00
var inject = require("gulp-inject");
2016-10-07 11:30:15 +00:00
var img64 = require("./gulpfile-img64");
var path = require("path");
2016-02-26 15:36:00 +00:00
var files = [
"app/**/*.js",
"app/**/*.css",
"app/**/*.html",
"assets/**/*.css"
2016-02-26 15:36:00 +00:00
];
2016-10-07 11:57:20 +00:00
gulp.task("default", [ "index" ]);
2016-02-26 15:36:00 +00:00
gulp.task("clean", function() {
return combine(
gulp.src("build"),
clean()
);
});
gulp.task("deps", function() {
return combine(
gulp.src(mainBowerFiles({ paths: { bowerDirectory: __dirname + '/../bower_components', bowerJson: __dirname + '/../bower.json' } }), { base: path.resolve(__dirname + "/..") + "/" }),
2016-02-26 15:36:00 +00:00
gulpIf([ "**/*.js", "**/*.css" ], combine(
gulpIf("**/*.js", combine(
newer("build/dependencies.js"),
2016-10-03 14:38:21 +00:00
sourcemaps.init({ loadMaps: true }),
2016-02-26 15:36:00 +00:00
concat("dependencies.js"),
2016-10-02 17:23:29 +00:00
uglify(),
sourcemaps.write("./sourcemaps")
2016-02-26 15:36:00 +00:00
)),
gulpIf("**/*.css", combine(
newer("build/dependencies.css"),
2016-10-03 14:38:21 +00:00
gulpIf("**/bower_components/bootstrap/**", combine(
replace("src: url('../fonts/glyphicons-halflings-regular.eot');", ""),
replace(/src: url\('\.\.\/fonts\/glyphicons-halflings-regular\..*/g, "src: url('../fonts/glyphicons-halflings-regular.ttf') format('truetype');")
)),
cssBase64({ maxWeightResource: 1000000 }),
sourcemaps.init({ loadMaps: true }),
2016-02-26 15:36:00 +00:00
concat("dependencies.css"),
2016-10-02 17:23:29 +00:00
cleanCss(),
sourcemaps.write("./sourcemaps")
2016-02-26 15:36:00 +00:00
)),
gulp.dest("build")
))
);
});
gulp.task("app", function() {
return combine(
gulp.src(files, { base: process.cwd() + "/" }),
2016-10-07 11:30:15 +00:00
gulpIf("**/*.html", combine(
img64(),
templateCache({ module: "facilpad", base: process.cwd() + "/app/" })
)),
2016-02-26 15:36:00 +00:00
gulpIf("**/*.js", combine(
newer("build/app.js"),
2016-10-02 17:23:29 +00:00
sourcemaps.init(),
2016-02-26 15:36:00 +00:00
concat("app.js"),
ngAnnotate(),
2016-10-02 17:23:29 +00:00
uglify(),
sourcemaps.write("./sourcemaps")
2016-02-26 15:36:00 +00:00
)),
gulpIf("**/*.css", combine(
newer("build/app.css"),
cssBase64({ maxWeightResource: 1000000 }),
2016-10-02 17:23:29 +00:00
sourcemaps.init(),
2016-02-26 15:36:00 +00:00
concat("app.css"),
2016-10-02 17:23:29 +00:00
cleanCss(),
sourcemaps.write("./sourcemaps")
2016-02-26 15:36:00 +00:00
)),
gulp.dest("build")
);
});
2016-10-07 11:57:20 +00:00
gulp.task("all", [ "deps", "app" ], function() {
return combine(
es.merge(
2016-02-26 15:36:00 +00:00
combine(
2016-10-07 11:57:20 +00:00
gulp.src([ "build/dependencies.js", "build/app.js" ]),
newer("build/all.js"),
sourcemaps.init({ loadMaps: true }),
concat("all.js"),
sourcemaps.write("./sourcemaps")
),
2016-02-26 15:36:00 +00:00
combine(
2016-10-07 11:57:20 +00:00
gulp.src([ "build/dependencies.css", "build/app.css" ]),
newer("build/all.css"),
sourcemaps.init({ loadMaps: true }),
concat("all.css"),
sourcemaps.write("./sourcemaps")
),
gulp.src("deref.html")
2016-10-07 11:57:20 +00:00
),
gulp.dest("build")
);
});
gulp.task("index", [ "all" ], function() {
return combine(
gulp.src("index.html"),
img64(),
concat("build/index.html"),
2016-10-07 11:57:20 +00:00
inject(gulp.src([ "build/all.js", "build/all.css" ], { read: false }), { relative: true, removeTags: true }),
gulp.dest(".")
2016-10-07 11:57:20 +00:00
);
2016-02-26 15:36:00 +00:00
});
2016-10-07 11:57:20 +00:00
gulp.task("watch", [ "index" ], function() {
gulp.watch([ "index.html", "bower.json" ].concat(files), [ "index" ]);
2016-02-26 15:36:00 +00:00
});