forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
243 lines (221 loc) · 9.37 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
'use strict';
// modules
const csso = require('gulp-csso');
const del = require('del');
const fs = require('fs');
const glob = require('glob');
const gap = require('gulp-append-prepend');
const replace = require('replace-in-file');
const gulp = require('gulp');
const argv = require('minimist')(process.argv.slice(2));
const gulpif = require('gulp-if');
const prefix = require('gulp-autoprefixer');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const gulp_watch = require('gulp-watch');
// package.json
const packages = require('./package.json');
// configuration
let config = {
all: [], // must always be empty
// Command Line Arguments
dev: argv['dev'],
build: argv['b'],
install: argv['i'],
// Source file locations
src: {
styles: {
style_portal: 'interface/themes/patientportal-style.scss',
style_uni: 'interface/themes/oe-styles/style_*.scss',
style_color: 'interface/themes/colors/*.scss',
directional: 'interface/themes/directional.scss'
}
},
dist: {
assets: 'public/assets/'
},
dest: {
themes: 'public/themes'
}
};
// Clean up lingering static themes
function clean(done) {
del.sync([config.dest.themes + "/*"]);
done();
}
// Parses command line arguments
function ingest(done) {
if (config.dev && typeof config.dev !== "boolean") {
config.dev = true;
}
done();
}
// definition of header for all compiled css
const autoGeneratedHeader = `
/*! This style sheet was autogenerated using gulp + scss
* For usage instructions, see: https://github.com/openemr/openemr/blob/master/interface/README.md
*/
`;
// standard themes css compilation
function styles_style_portal() {
return gulp.src(config.src.styles.style_portal)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(prefix('last 1 version'))
.pipe(gap.prependText(autoGeneratedHeader))
.pipe(gulpif(!config.dev, csso()))
.pipe(gulpif(!config.dev, sourcemaps.write()))
.pipe(gulp.dest(config.dest.themes));
}
// standard themes css compilation
function styles_style_uni() {
return gulp.src(config.src.styles.style_uni)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(prefix('last 1 version'))
.pipe(gap.prependText(autoGeneratedHeader))
.pipe(gulpif(!config.dev, csso()))
.pipe(gulpif(!config.dev, sourcemaps.write()))
.pipe(gulp.dest(config.dest.themes));
}
// color themes css compilation
function styles_style_color() {
return gulp.src(config.src.styles.style_color)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(prefix('last 1 version'))
.pipe(gap.prependText(autoGeneratedHeader))
.pipe(gulpif(!config.dev, csso()))
.pipe(gulpif(!config.dev, sourcemaps.write()))
.pipe(gulp.dest(config.dest.themes));
}
// rtl standard themes css compilation
function rtl_style_portal() {
return gulp.src(config.src.styles.style_portal)
.pipe(gap.prependText('$dir: rtl;\n@import "rtl";\n@import "directional";\n')) // watch out for this relative path!
.pipe(gap.appendText('@include if-rtl { @include rtl_style; }\n'))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(prefix('last 1 version'))
.pipe(gap.prependText(autoGeneratedHeader))
.pipe(gulpif(!config.dev, csso()))
.pipe(gulpif(!config.dev, sourcemaps.write()))
.pipe(rename({ prefix: "rtl_" }))
.pipe(gulp.dest(config.dest.themes));
}
// rtl standard themes css compilation
function rtl_style_uni() {
return gulp.src(config.src.styles.style_uni)
.pipe(gap.prependText('$dir: rtl;\n@import "../rtl";\n')) // watch out for this relative path!
.pipe(gap.appendText('@include if-rtl { @include rtl_style; #bigCal { border-right: 1px solid $black !important; } }\n'))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(prefix('last 1 version'))
.pipe(gap.prependText(autoGeneratedHeader))
.pipe(gulpif(!config.dev, csso()))
.pipe(gulpif(!config.dev, sourcemaps.write()))
.pipe(rename({ prefix: "rtl_" }))
.pipe(gulp.dest(config.dest.themes));
}
// rtl color themes css compilation
function rtl_style_color() {
return gulp.src(config.src.styles.style_color)
.pipe(gap.prependText('$dir: rtl;\n@import "../rtl";\n')) // watch out for this relative path!
.pipe(gap.appendText('@include if-rtl { @include rtl_style; #bigCal { border-right: 1px solid $black !important; } }\n'))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(prefix('last 1 version'))
.pipe(gap.prependText(autoGeneratedHeader))
.pipe(gulpif(!config.dev, csso()))
.pipe(gulpif(!config.dev, sourcemaps.write()))
.pipe(rename({ prefix: "rtl_" }))
.pipe(gulp.dest(config.dest.themes));
}
// compile themes
const styles = gulp.parallel(styles_style_color, styles_style_uni, styles_style_portal, rtl_style_color, rtl_style_uni, rtl_style_portal);
// Copies (and distills, if possible) assets from node_modules to public/assets
function install(done) {
// combine dependencies and napa sources into one object
const dependencies = packages.dependencies;
for (let key in packages.napa) {
if (packages.napa.hasOwnProperty(key)) {
dependencies[key] = packages.napa[key];
}
}
for (let key in dependencies) {
// check if the property/key is defined in the object itself, not in parent
if (dependencies.hasOwnProperty(key)) {
if (key == 'dwv') {
// dwv is special and need to copy dist, decoders and locales
gulp.src('node_modules/' + key + '/dist/**/*')
.pipe(gulp.dest(config.dist.assets + key + '/dist'));
gulp.src('node_modules/' + key + '/decoders/**/*')
.pipe(gulp.dest(config.dist.assets + key + '/decoders'));
gulp.src('node_modules/' + key + '/locales/**/*')
.pipe(gulp.dest(config.dist.assets + key + '/locales'));
} else if (key == 'bootstrap' || key == 'bootstrap-v4-rtl' || key == 'bootswatch') {
// bootstrap, bootstrap-v4-rtl, and bootswatch are special and need to copy dist and scss
gulp.src('node_modules/' + key + '/dist/**/*')
.pipe(gulp.dest(config.dist.assets + key + '/dist'));
gulp.src('node_modules/' + key + '/scss/**/*')
.pipe(gulp.dest(config.dist.assets + key + '/scss'));
} else if (key == '@ttskch/select2-bootstrap4-theme') {
// @ttskch/select2-bootstrap4-theme is special and need to copy dist and src
// modify src/layout.scss in order for sass build to work by removing:
// @import "~bootstrap/scss/functions";
// @import "~bootstrap/scss/variables";
// @import "~bootstrap/scss/mixins";
gulp.src('node_modules/' + key + '/dist/**/*')
.pipe(gulp.dest(config.dist.assets + key + '/dist'));
gulp.src('node_modules/' + key + '/src/**/*')
.pipe(gulp.dest(config.dist.assets + key + '/src'))
.on('end', function() {
replace({
files: config.dist.assets + key + '/src/layout.scss',
from:
[
/@import "~bootstrap\/scss\/functions";/,
/@import "~bootstrap\/scss\/variables";/,
/@import "~bootstrap\/scss\/mixins";/
],
to: '',
});
});
} else if (fs.existsSync('node_modules/' + key + '/dist')) {
// only copy dist directory, if it exists
gulp.src('node_modules/' + key + '/dist/**/*')
.pipe(gulp.dest(config.dist.assets + key + '/dist'));
} else {
// copy everything
gulp.src('node_modules/' + key + '/**/*')
.pipe(gulp.dest(config.dist.assets + key));
}
}
}
done();
}
function watch() {
// watch all changes and re-run styles
gulp.watch('./interface/**/*.scss', { interval: 1000, mode: 'poll' }, styles);
// watch all changes to css/php files in themes and copy to public
return gulp_watch('./interface/themes/*.{css,php}', { ignoreInitial: false })
.pipe(gulp.dest(config.dest.themes));
}
function sync() {
// copy all leftover root-level components to the theme directory
// hoping this is only temporary
return gulp.src(['interface/themes/*.{css,php}'])
.pipe(gulp.dest(config.dest.themes));
}
// Export watch task
exports.watch = watch;
// Export pertinent default task
// - Note that the default task runs if no other task is chosen,
// which is generally how this script is always used (except in
// rare case where the user is running the watch task).
if (config.install) {
exports.default = gulp.series(install)
} else {
exports.default = gulp.series(clean, ingest, styles, sync);
}