forked from peichhorn-netgo/formio.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
161 lines (148 loc) · 6.57 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
'use strict';
const gulp = require('gulp');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const babel = require('gulp-babel');
const filter = require('gulp-filter');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const replace = require('gulp-replace');
const rename = require('gulp-rename');
const cleanCSS = require('gulp-clean-css');
const eslint = require('gulp-eslint');
// Clean lib folder.
gulp.task('clean', require('del').bind(null, ['dist', 'lib']));
// ESLint
gulp.task('eslint', function eslintTask() {
return gulp.src(['./src/**/*.js', '!./src/**/*.spec.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
// Run babel on source code.
gulp.task('babel', gulp.series('eslint', function babelTask() {
return gulp.src(['./src/**/*.js', '!./src/**/*.spec.js'])
.pipe(babel())
.pipe(gulp.dest('lib'));
}));
// Move font-awesome fonts into dist folder.
gulp.task('builder-fonts', function builderFonts() {
return gulp.src('node_modules/font-awesome/fonts/*').pipe(gulp.dest('dist/fonts'));
});
// Generate styles
const compileStyles = (styles, file) => {
const sassFilter = filter('**/*.scss', { restore: true });
return gulp.src(styles)
.pipe(sassFilter)
.pipe(sass().on('error', sass.logError))
.pipe(sassFilter.restore)
.pipe(concat(`${file}.css`))
.pipe(replace(/\.\.\/\.\.\/icons\/\/?/g, 'icons/'))
/* eslint-disable quotes */
.pipe(replace('icons/cross.svg', `'data:image/svg+xml;charset=utf8,%3Csvg width="21" height="21" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="%23FFF" fill-rule="evenodd"%3E%3Cpath d="M2.592.044l18.364 18.364-2.548 2.548L.044 2.592z"/%3E%3Cpath d="M0 18.364L18.364 0l2.548 2.548L2.548 20.912z"/%3E%3C/g%3E%3C/svg%3E'`))
.pipe(replace('icons/cross-inverse.svg', `'data:image/svg+xml;charset=utf8,%3Csvg width="21" height="21" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="%23000" fill-rule="evenodd"%3E%3Cpath d="M2.592.044l18.364 18.364-2.548 2.548L.044 2.592z"/%3E%3Cpath d="M0 18.364L18.364 0l2.548 2.548L2.548 20.912z"/%3E%3C/g%3E%3C/svg%3E'`))
/* eslint-enable quotes */
.pipe(replace(/\.\.\/fonts\/\/?/g, 'fonts/'))
.pipe(gulp.dest('dist'))
.pipe(rename(`${file}.min.css`))
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(gulp.dest('dist'));
};
gulp.task('styles-form', function formStyles() {
return compileStyles([
'./node_modules/flatpickr/dist/flatpickr.min.css',
'./node_modules/choices.js/public/assets/styles/choices.min.css',
'./node_modules/dialog-polyfill/dialog-polyfill.css',
'./src/sass/formio.form.scss'
], 'formio.form');
});
gulp.task('styles-builder', function builderStyles() {
return compileStyles([
'./node_modules/flatpickr/dist/flatpickr.min.css',
'./node_modules/choices.js/public/assets/styles/choices.min.css',
'./node_modules/dialog-polyfill/dialog-polyfill.css',
'./node_modules/dragula/dist/dragula.css',
'./src/sass/formio.form.scss',
'./src/sass/formio.form.builder.scss'
], 'formio.builder');
});
gulp.task('styles-full', gulp.series('builder-fonts', function fullStyles() {
return compileStyles([
'./node_modules/flatpickr/dist/flatpickr.min.css',
'./node_modules/choices.js/public/assets/styles/choices.min.css',
'./node_modules/dialog-polyfill/dialog-polyfill.css',
'./node_modules/dragula/dist/dragula.css',
'./node_modules/font-awesome/css/font-awesome.css',
'./src/sass/formio.form.scss',
'./src/sass/formio.form.builder.scss'
], 'formio.full');
}));
// Script builds.
const webpackDev = require('./config/webpack.dev');
const webpackProd = require('./config/webpack.prod');
const buildDev = (input, output) => webpackStream(webpackDev(input, output), webpack).pipe(gulp.dest('dist'));
const buildProd = (input, output) => webpackStream(webpackProd(input, output), webpack).pipe(gulp.dest('dist'));
const build = (input, output) => {
const prodFile = output.replace(/\.js$/, '.min.js');
gulp.task(output, () => buildDev(input, output));
gulp.task(prodFile, () => buildProd(input, prodFile));
return gulp.parallel(output, prodFile);
};
gulp.task('scripts-formio', build('Formio.js', 'formio.js'));
gulp.task('scripts-utils', build('utils/utils.js', 'formio.utils.js'));
gulp.task('scripts-full', build('index.js', 'formio.full.js'));
gulp.task('scripts-form', build('formio.form.js', 'formio.form.js'));
gulp.task('formio.embed.min.js', () => buildProd('formio.embed.js', 'formio.embed.min.js'));
gulp.task('formio.embed.js', () =>
gulp.src('./dist/formio.embed.min.js')
.pipe(rename('formio.embed.js'))
.pipe(gulp.dest('dist')));
gulp.task('scripts-embed', gulp.series('formio.embed.min.js', 'formio.embed.js'));
gulp.task('scripts-contrib', build('contrib/index.js', 'formio.contrib.js'));
gulp.task('jquery', () => gulp.src('./node_modules/jquery/dist/**/*.*').pipe(gulp.dest('./app/jquery')));
gulp.task('fontawesome', () => gulp.src('./node_modules/font-awesome/**/*.*').pipe(gulp.dest('./app/fontawesome')));
gulp.task('bootstrap', () => gulp.src('./node_modules/bootstrap/dist/**/*.*').pipe(gulp.dest('./app/bootstrap')));
gulp.task('bootswatch', () => gulp.src('./node_modules/bootswatch/**/*.*').pipe(gulp.dest('./app/bootswatch')));
// Copy the version and dependencies into the distribution package.json file.
gulp.task('package-version', function() {
const pkg = require('./package.json');
return gulp.src([
'src/package.json'
])
.pipe(replace(/"version": ""/, `"version": "${pkg.version}"`))
.pipe(replace(/"dependencies": {}/, `"dependencies": ${JSON.stringify(pkg.dependencies)}`))
.pipe(gulp.dest('lib'));
});
// Copy over the dist folder into the lib folder.
gulp.task('dist', () => gulp.src(['dist/**/*.*']).pipe(gulp.dest('lib/dist')));
// Watch for changes.
gulp.task('watch', () => gulp.watch(['./src/*.js', './src/**/*.js'], gulp.series('scripts-full')));
// Copy over the moment-timezones to the resource folder.
gulp.task('timezones', () => gulp.src('./node_modules/moment-timezone/data/packed/latest.json').pipe(gulp.dest('./resources')));
// Create a new build.
gulp.task('build', gulp.series(
'clean',
'babel',
'package-version',
gulp.parallel(
'jquery',
'timezones',
'fontawesome',
'bootstrap',
'bootswatch'
),
gulp.parallel(
'styles-form',
'styles-builder',
'styles-full',
'scripts-formio',
'scripts-utils',
'scripts-embed',
'scripts-contrib',
'scripts-form',
'scripts-full'
),
'dist'
));
// Default task. Build and watch.
gulp.task('default', gulp.series('babel', 'scripts-full', 'watch'));