This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
gulpfile.js
144 lines (122 loc) · 4.05 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
var gulp = require("gulp"),
gulpif = require("gulp-if"),
sass = require("gulp-sass"),
minifyCss = require("gulp-minify-css"),
replace = require("gulp-replace"),
babel = require("gulp-babel"),
concat = require("gulp-concat"),
uglify = require("gulp-uglify"),
yaml = require("js-yaml"),
connect = require("gulp-connect"),
fs = require("fs"),
path = require("path");
CONFIG = yaml.safeLoad(fs.readFileSync("nanoc.yaml", "utf8"));
IS_PRODUCTION = process.env.NODE_ENV == "production";
gulp.task("css", function() {
return gulp.src("assets/stylesheets/*.css")
.pipe(gulp.dest("output/assets/stylesheets/"));
});
gulp.task("sass", function() {
return gulp.src("assets/stylesheets/*.scss")
.pipe(sass())
.pipe(gulpif(IS_PRODUCTION, minifyCss()))
.pipe(gulp.dest("output/assets/stylesheets/"));
});
gulp.task("javascript_vendor", function () {
return gulp.src([
"assets/vendor/jquery/dist/jquery.js",
"assets/vendor/mustache/mustache.js",
"assets/vendor/lunr.js/lunr.js"
])
.pipe(concat("vendor.js"))
.pipe(gulp.dest("tmp/"));
})
gulp.task("javascript_babel", function () {
return gulp.src([
"assets/javascripts/*.js",
])
.pipe(babel({
presets: ["es2015"]
}))
.pipe(concat("babel.js"))
.pipe(gulp.dest("tmp/"));
});
gulp.task("javascript_workers", function () {
return gulp.src([
"assets/javascripts/workers/*.js",
"assets/vendor/lunr.js/lunr.min.js"
])
.pipe(gulp.dest("output/assets/javascripts/"));
});
gulp.task("javascript_concat", function () {
return gulp.src(["./tmp/vendor.js", "./tmp/babel.js"])
.pipe(concat("application.js"))
.pipe(gulpif(IS_PRODUCTION, uglify()))
.pipe(gulp.dest("output/assets/javascripts/"))
});
gulp.task("javascript", gulp.series("javascript_vendor", "javascript_babel", "javascript_workers", "javascript_concat"));
gulp.task("octicons", function() {
return gulp.src("assets/vendor/octicons/octicons/**/*")
.pipe(gulp.dest("output/assets/vendor/octicons/octicons"));
});
gulp.task("images", function() {
return gulp.src("assets/images/**/*")
.pipe(gulp.dest("output/assets/images"));
});
gulp.task("favicon", function() {
return gulp.src("assets/images/favicon.ico")
.pipe(gulp.dest("output/"));
});
gulp.task("extract_api_docs_data", function (cb) {
const destDir = 'content/api';
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir);
const srcDir = 'data/apis-by-version';
fs.readdirSync(srcDir).forEach((file) => {
if (path.extname(file) != '.json') return;
const version = path.basename(file, '.json');
const versionDestDir = `${destDir}/${version}`;
if (!fs.existsSync(versionDestDir)) fs.mkdirSync(versionDestDir);
const srcPath = `${srcDir}/${file}`;
const docs = JSON.parse(fs.readFileSync(srcPath));
for (klass in docs['classes']) {
const destPath = `${versionDestDir}/${klass}.json`;
const docsForClass = JSON.stringify(docs['classes'][klass]);
fs.writeFileSync(destPath, docsForClass);
}
})
cb();
});
gulp.task("nanoc:compile", function (cb) {
const { spawn } = require('child_process');
const compile = spawn('bundle', ['exec', 'nanoc', 'compile'], { stdio: 'inherit' });
compile.on('close', (code) => {
console.log(`'bundle exec nanoc compile' exited with code ${code}`);
cb();
})
});
gulp.task("server", function() {
connect.server({
port: 4000,
root: ["output"],
fallback: "output/404.html"
});
});
gulp.task("watch:nanoc", function() {
gulp.watch([
"nanoc.yaml",
"Rules",
"data/**/*",
"content/**/*",
"layouts/**/*",
"lib/**/*"
], gulp.series("nanoc:compile"));
});
gulp.task("watch:assets", function() {
gulp.watch([
"assets/**/*"
], gulp.series("assets"));
});
gulp.task("serve", gulp.parallel("server", "watch:nanoc", "watch:assets"));
gulp.task("assets", gulp.parallel("css", "sass", "javascript", "octicons", "images", "favicon"));
gulp.task("build", gulp.parallel("extract_api_docs_data", "nanoc:compile", "assets"));
gulp.task("default", gulp.series("build", "serve"));