-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
117 lines (105 loc) · 3.2 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var gulp = require("gulp"),
browserSync = require("browser-sync"),
nodemon = require("gulp-nodemon"),
browserify = require("gulp-browserify"),
rename = require("gulp-rename"),
jest = require("gulp-jest"),
sass = require("gulp-sass"),
sourcemaps = require("gulp-sourcemaps"),
autoprefixer = require("gulp-autoprefixer"),
log = require("gulp-util/lib/log"),
plumber = require("gulp-plumber");
gulp.task("start", ["build-js", "scss", "watch-all"]);
gulp.task("watch-all", ["scss-watch", "browserify-watch", "nodemon", "browser-sync"]);
gulp.task("nodemon", function (cb) {
var called = false;
return nodemon({
script: "bin/www",
ext: "js jsx",
watch: ["react/*", "routes/*", "app.js"]
}).on("start", function onStart() {
if (!called) cb();
called = true;
});
});
gulp.task("scss", function () {
// TODO: only include sourcemaps in dev env, not prod.
gulp.src("./scss/*.scss")
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write())
.pipe(autoprefixer({
browsers: ["> 1%", "last 2 versions", "Firefox ESR", "Opera 12.1"]
}))
.pipe(gulp.dest("./public/stylesheets/"));
});
gulp.task("scss-watch", function () {
gulp.watch(["./scss/*.scss"], ["scss"]);
});
gulp.task("build-js", function () {
gulp.src("browser/bootstrap.jsx", {read: false})
.pipe(plumber())
.pipe(browserify({
transform: ["reactify"],
debug: true
}))
.pipe(rename("bundle.js"))
.pipe(gulp.dest("public/javascripts"));
});
gulp.task("browserify-watch", function () {
gulp.watch(["react/**/*.*", "browser/**/*.*"], ["build-js"]);
});
gulp.task("browser-sync", function () {
browserSync.init({
files: ['public/**/*.*'],
proxy: 'http://localhost:3000',
port: 4000,
browser: ['google chrome'],
minify: false,
ghostMode: {
clicks: true,
location: true,
forms: true,
scroll: true
}
});
});
gulp.task("jest-watch", ["jest"], function () {
gulp.watch(["__tests__/*"], ["jest"]);
});
gulp.task("jest", function () {
return gulp.src("__tests__").pipe(jest({
scriptPreprocessor: "../preprocessor.js",
unmockedModulePathPatterns: [
"../node_modules/react"
],
testPathDirs: ["../__tests__"],
testPathIgnorePatterns: [
"../node_modules"
]
//moduleFileExtensions: [
// "js",
// "jsx",
// "json",
// "react"
//]
}));
});
var argv = require('yargs').argv, // for args parsing
spawn = require('child_process').spawn;
gulp.task('default', function () {
var p;
gulp.watch(['gulpfile.js', 'package.json'], spawnChildren);
spawnChildren();
function spawnChildren(e) {
// kill previous spawned process
if (p) {
p.kill();
}
var task = argv.task || 'start';
log('auto-reload task', task);
// `spawn` a child `gulp` process linked to the parent `stdio`
p = spawn('gulp', [task], {stdio: 'inherit'});
}
});