forked from GSA/resources.data.gov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
126 lines (107 loc) · 3.21 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
118
119
120
121
122
123
124
125
126
var autoprefixer = require("autoprefixer");
var autoprefixerOptions = require("./node_modules/uswds-gulp/config/browsers");
var cssnano = require("cssnano");
var gulp = require("gulp");
var mqpacker = require("css-mqpacker");
var path = require("path");
var pkg = require("./node_modules/uswds/package.json");
var postcss = require("gulp-postcss");
var rename = require("gulp-rename");
var replace = require("gulp-replace");
var sass = require("gulp-sass");
var sourcemaps = require("gulp-sourcemaps");
var uswds = require("./node_modules/uswds-gulp/config/uswds");
var watchify = require("watchify");
var browserify = require("browserify");
var source = require("vinyl-source-stream");
var buffer = require("vinyl-buffer");
var log = require("gulplog");
var assign = require("lodash.assign");
// Project Javascript source directory
const PROJECT_JS_SRC = "./pages/_js";
// Javascript destination
const PROJECT_JS_DEST = "./_site/assets/js";
// Project Sass source directory
const PROJECT_SASS_SRC = "./pages/_scss";
// Images destination
const IMG_DEST = "./_site/assets/uswds/img";
// Fonts destination
const FONTS_DEST = "./_site/assets/uswds/fonts";
// Javascript destination
const JS_DEST = "./_site/assets/uswds/js";
// Compiled CSS destination
const CSS_DEST = "./_site/assets/uswds/css";
/*
----------------------------------------
TASKS
----------------------------------------
*/
gulp.task("copy-uswds-fonts", () => {
return gulp.src(`${uswds}/fonts/**/**`).pipe(gulp.dest(`${FONTS_DEST}`));
});
gulp.task("copy-uswds-images", () => {
return gulp.src(`${uswds}/img/**/**`).pipe(gulp.dest(`${IMG_DEST}`));
});
gulp.task("copy-uswds-js", () => {
return gulp.src(`${uswds}/js/**/**`).pipe(gulp.dest(`${JS_DEST}`));
});
gulp.task("build-sass", function(done) {
var plugins = [
autoprefixer(autoprefixerOptions),
mqpacker({ sort: true }),
cssnano({ autoprefixer: { browsers: autoprefixerOptions } })
];
return gulp
.src(`${PROJECT_SASS_SRC}/styles.scss`)
.pipe(sourcemaps.init({ largeFile: true }))
.pipe(
sass({
includePaths: [
PROJECT_SASS_SRC,
`${uswds}/scss`,
`${uswds}/scss/packages`
]
})
)
.pipe(replace(/\buswds @version\b/g, "based on uswds v" + pkg.version))
.pipe(postcss(plugins))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(CSS_DEST));
});
var customOpts = {
entries: [`${PROJECT_JS_SRC}/index.js`]
};
var opts = assign({}, watchify.args, customOpts);
var b = function() {
return browserify(opts);
};
var w = watchify(b());
var bundle = function(pkg) {
return pkg
.bundle()
.on("error", log.error.bind(log, "Browserify Error"))
.pipe(source("bundle.js"))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(PROJECT_JS_DEST));
};
gulp.task("build-js", bundle.bind(null, b()));
gulp.task(
"init",
gulp.series(
"copy-uswds-fonts",
"copy-uswds-images",
"copy-uswds-js",
"build-js",
"build-sass"
)
);
gulp.task("watch-js", function() {
bundle(w);
w.on("update", bundle.bind(null, w));
w.on("log", log.info);
});
gulp.task("watch-sass", function() {
gulp.watch(`${PROJECT_SASS_SRC}/**/*.scss`, gulp.series("build-sass"));
});