forked from jenkinsci/blueocean-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
201 lines (167 loc) · 5.36 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
"use strict";
process.env.SKIP_BLUE_IMPORTS = 'YES';
process.env.NODE_ENV = 'production';
/*
Build file for Jenkins Design Language theme.
*/
const gulp = require('gulp');
const gutil = require('gulp-util');
const fs = require('fs');
const sourcemaps = require('gulp-sourcemaps');
const babel = require('gulp-babel');
const less = require('gulp-less');
const rename = require('gulp-rename');
const copy = require('gulp-copy');
const svgmin = require('gulp-svgmin');
const lint = require('gulp-eslint');
const ts = require('gulp-typescript');
const tsProject = ts.createProject('./tsconfig.json');
// Options, src/dest folders, etc
const config = {
react: {
sources: "src/**/*.{js,jsx}",
dest: "dist"
},
ts: {
sources: "src/**/*.{ts,tsx}",
dest: "dist"
},
less: {
sources: "less/theme.less",
watch: "less/**/*.less", // Watch includes as well as main
dest: "dist/assets/css"
},
svgmin: {
sources: "icons/**/*",
dest: "icons/"
},
copy: {
icons: {
sources: "icons/**/*",
dest: "dist/assets/"
},
octicons: {
sources: "node_modules/octicons/build/font/octicons.{eot,woff,woff2,ttf,svg}",
dest: "target/classes/io/jenkins/blueocean/"
},
fonts: {
sources: "fonts/*.woff",
dest: "dist/assets/fonts/"
},
componentDocFiles: {
sources: "src/js/stories/doc-*.{md,ejs,jade}",
dest: "website/component-docs/"
},
licenses_octicons: {
sources: "node_modules/octicons/LICENSE",
dest: "licenses/"
},
licenses_ofl: {
sources: "fonts/OFL.txt",
dest: "licenses/"
}
},
test: {
sources: 'test/js',
},
};
// Watch all
gulp.task("watch", ["build"], () => {
gulp.watch(config.react.sources, ["compile-react"]);
gulp.watch(config.less.watch, ["less"]);
});
// Watch only styles, for when you're using Storybook
gulp.task("watch-styles", ["build"], () => {
gulp.watch(config.less.watch, ["less"]);
});
// Default to all
gulp.task("default", ["lint", "test", "build", "validate"]);
// Build all
gulp.task("build", ["compile-typescript", "compile-react", "less", "copy"]);
// Compile react sources
gulp.task("compile-react", () =>
gulp.src(config.react.sources)
.pipe(sourcemaps.init())
.pipe(babel(config.react.babel))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(config.react.dest)));
gulp.task("compile-typescript", () =>
gulp.src(config.ts.sources)
.pipe(tsProject())
.pipe(gulp.dest(config.ts.dest)));
// Build the CSS
gulp.task("less", () =>
gulp.src(config.less.sources)
.pipe(sourcemaps.init())
.pipe(less())
.pipe(rename("jenkins-design-language.css"))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(config.less.dest)));
// Optimize SVG
gulp.task("svgmin", () =>
gulp.src(config.svgmin.sources)
.pipe(svgmin())
.pipe(gulp.dest(config.svgmin.dest)));
// Copy things
gulp.task("copy", ["copy-icons", "copy-octicons", "copy-fonts",
"copy-componentDocFiles", "copy-licenses-octicons", "copy-licenses-ofl"]);
gulp.task("copy-icons", () =>
gulp.src(config.copy.icons.sources)
.pipe(copy(config.copy.icons.dest)));
gulp.task("copy-octicons", () =>
gulp.src(config.copy.octicons.sources)
.pipe(copy(config.copy.octicons.dest, {prefix: 4})));
gulp.task("copy-fonts", () =>
gulp.src(config.copy.fonts.sources)
.pipe(copy(config.copy.fonts.dest, {prefix: 1})));
gulp.task("copy-componentDocFiles", () =>
gulp.src(config.copy.componentDocFiles.sources)
.pipe(copy(config.copy.componentDocFiles.dest, {prefix: 3})));
gulp.task("copy-licenses-octicons", () =>
gulp.src(config.copy.licenses_octicons.sources)
.pipe(copy(config.copy.licenses_octicons.dest, {prefix: 1})));
gulp.task("copy-licenses-ofl", () =>
gulp.src(config.copy.licenses_ofl.sources)
.pipe(copy(config.copy.licenses_ofl.dest, {prefix: 1})));
// Validate contents
gulp.task("validate", () => {
const paths = [
config.less.dest,
config.copy.fonts.dest,
config.copy.octicons.dest,
];
for (const path of paths) {
try {
fs.statSync(path);
} catch (err) {
gutil.log('Error occurred during validation; see stack trace for details');
throw err;
}
}
});
var builder = require('@jenkins-cd/js-builder');
builder.src([
'src/js',
'less',
'dist' // for icons & fonts; NOTE: would be nice to find another way to do this as files in dist creates issues for jest & eslint
]);
builder.tests(config.test.sources);
// redefine 'lint' to check only react and test sources (avoid dist)
builder.defineTask("lint", () => (
gulp.src([config.react.sources, config.test.sources])
.pipe(lint())
.pipe(lint.format())
.pipe(lint.failAfterError())
));
//
// Create the main bundle.
//
builder.bundle('src/js/components/index.js', 'jenkins-design-language.js')
.inDir('target/classes/io/jenkins/blueocean')
.less('less/jenkins-design-language.less')
.export('moment')
.export('moment-duration-format')
.export('react')
.export('react-dom')
.export('react-router')
.export('react-addons-css-transition-group');