-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
151 lines (138 loc) · 5.03 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
/// <binding ProjectOpened='watch' />
const gulp = require('gulp');
const sass = require('gulp-dart-sass');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const del = require('del');
const cssnano = require('gulp-cssnano');
const header = require('gulp-header');
const rename = require('gulp-rename');
const iconfont = require('gulp-iconfont');
const iconfontCss = require('gulp-iconfont-css');
const clc = require('cli-color');
const run = require('gulp-run-command').default;
const package = require('./package.json');
const config = require("./gulpfile_config.js");
const configdev = require("./gulpfile_configdev.js");
function clean(which) {
if (which == 'css' || which == '*') {
del(config.output_path + "css/*.css");
}
if (which == 'js' || which == '*') {
del(config.output_path + "js/*.js");
}
if (which == 'iconfont' || which == '*') {
del(config.output_path + "fonts/chell-icons.*");
}
if (which == 'robotofont' || which == '*') {
del(config.output_path + "fonts/roboto-latin-300-normal.*");
}
}
function copyProduction(path) {
console.log(clc.green(`Copying to production: ${path}`));
gulp.src(path).pipe(gulp.dest(configdev.production_path));
}
function deleteProduction(path) {
console.log(clc.red(`Deleting from production: ${path}`));
del(configdev.production_path + path, { force: true });
}
function buildScript(path) {
console.log(clc.green(`Building script: ${path}`));
gulp.src(path)
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(header(config.banner.main, { package: package }))
.pipe(gulp.dest(config.output_path))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(header(config.banner.main, { package: package }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.output_path));
}
gulp.task('sass', () => {
clean('css');
return gulp.src(config.styles.sass)
.pipe(sass())
.pipe(header(config.banner.main, { package: package }))
.pipe(gulp.dest(config.output_path + config.styles.output_path))
.pipe(rename({ suffix: '.min' }))
.pipe(
cssnano({
discardComments: {
removeAll: true
},
zindex: false
})
)
.pipe(header(config.banner.main, { package: package }))
.pipe(gulp.dest(config.output_path + config.styles.output_path));
});
gulp.task('styles', () => {
return gulp.src(config.styles.css)
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(header(config.banner.main, { package: package }))
.pipe(rename({ suffix: '.min' }))
.pipe(
cssnano({
reduceIdents: {
keyframes: false
},
discardComments: {
removeAll: true
},
zindex: false
})
)
.pipe(header(config.banner.main, { package: package }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.output_path + config.styles.output_path));
});
gulp.task('scripts', () => {
clean('js');
return gulp.src(config.scripts.src)
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(header(config.banner.main, { package: package }))
.pipe(gulp.dest(config.output_path + config.scripts.output_path))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(header(config.banner.main, { package: package }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.output_path + config.scripts.output_path));
});
gulp.task('iconfont', () => {
clean('iconfont');
const runTimestamp = Math.round(Date.now() / 1000);
const fontName = 'chell-icons';
return gulp.src(config.fonts.src)
.pipe(iconfontCss({
fontName: fontName,
targetPath: '../../css/_icons.scss',
fontPath: '../fonts/',
cssClass: 'fa'
}))
.pipe(iconfont({
fontName: fontName,
prependUnicode: false,
normalize: true,
formats: ['ttf', 'eot', 'woff', 'woff2', 'svg'],
timestamp: runTimestamp,
}))
.pipe(gulp.dest('public/fonts/'));
});
gulp.task('robotofont', () => {
clean('robotofont')
return gulp.src(['node_modules/@fontsource/roboto/files/roboto-latin-300-normal.*'])
.pipe(gulp.dest('public/fonts/'));
});
gulp.task('genrate_migration', run(`vendor/bin/phalcon-migrations generate --config=app/migrations/Config.php --version=${package.version} --skip-ref-schema --no-auto-increment`));
gulp.task('watch', () => {
gulp.watch('css/**/*.scss', gulp.series(['sass', 'styles']));
gulp.watch('js/**/*.js')
.on("change", buildScript)
.on("add", buildScript);
gulp.watch('**')
.on("change", copyProduction)
.on("add", copyProduction)
.on("addDir", copyProduction)
.on("unlink", deleteProduction)
.on("unlinkDir", deleteProduction);
});