-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
102 lines (86 loc) · 2.44 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
const gulp = require('gulp'),
sass = require('gulp-sass')(require('sass')),
autoprefixer = require('gulp-autoprefixer'),
cssimport = require('gulp-cssimport'),
replace = require('gulp-replace'),
cssbeautify = require('gulp-cssbeautify'),
bump = require('gulp-bump');
const exec = require('child_process').exec;
const sassFiles = 'libs/ng-library/src/lib/styles.scss',
baseDest = 'dist/ng-library',
fontDest = `${baseDest}/fonts`,
cssDest = `${baseDest}`,
imgDest = `${baseDest}/images`,
libraryDist = '../ui-library-demo/node_modules/@fourjs/ng-library';
function styles() {
return gulp
.src(sassFiles)
.pipe(
sass.sync({ includePaths: ['node_modules'] }).on('error', sass.logError)
)
.pipe(cssimport({ includePaths: ['node_modules'] }))
.pipe(replace('@charset "UTF-8";', ''))
.pipe(replace('../fonts', './fonts'))
.pipe(autoprefixer())
.pipe(cssbeautify())
.pipe(gulp.dest(cssDest));
}
function moveStyles() {
return gulp
.src(['projects/ng-library/src/styles/**.scss'])
.pipe(gulp.dest(`${cssDest}/styles`));
}
function font() {
return gulp
.src([
'projects/ng-library/src/assets/fonts/**/*',
])
.pipe(gulp.dest(fontDest));
}
function moveReadme() {
return gulp.src(['README.md']).pipe(gulp.dest(baseDest));
}
function moveLicense() {
return gulp.src('LICENSE').pipe(gulp.dest(baseDest));
}
function executeBuild(cb) {
return exec('ng build ng-library', (err) => {
cb(err);
});
}
function moveBuildFolder() {
return gulp.src(['dist/ng-library/**/**.*']).pipe(gulp.dest(libraryDist));
}
function watchFiles() {
return gulp.watch(
['projects/ng-library/src/**/*.*'],
{ ignoreInitial: false },
gulp.series(executeBuild, defaultTask, moveBuildFolder)
);
}
function cleanup() {
return import('del').then((del) => {
return del.deleteSync(`${libraryDist}/**`, {
force: true,
});
});
}
function bumpVersion(cb) {
const date = new Date(),
year = date.toLocaleDateString('en', { year: '2-digit' }),
version = `${year}.${date.getMonth() + 1}.${date.getDate()}`;
gulp
.src('./projects/ng-library/package.json')
.pipe(bump({ version, key: 'version' }))
.pipe(gulp.dest('./projects/ng-library/'), cb());
}
exports.watch = gulp.series(cleanup, watchFiles);
exports.bump = gulp.series(bumpVersion);
const defaultTask = gulp.parallel(
styles,
font,
moveStyles,
moveReadme,
moveLicense
);
exports.default = defaultTask;