This repository has been archived by the owner on May 19, 2023. It is now read-only.
/
script.js
81 lines (70 loc) · 2.07 KB
/
script.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
const { src, dest, watch } = require('gulp')
const eslint = require('gulp-eslint')
const gutil = require('gulp-util')
const babel = require('gulp-babel')
const include = require('gulp-include')
const sourcemaps = require('gulp-sourcemaps')
const uglify = require('gulp-uglify')
const rename = require('gulp-rename')
const standard = require('gulp-standard')
const { helpers } = require('./helpers')
const eslintConfig = {
configFile: `${helpers.proot()}/.eslintrc.json`,
fix: true,
quiet: true
}
const includeConfig = {
hardFail: true,
includePaths: [
`${helpers.proot()}/node_modules`
]
}
const babelConfig = {
presets: ['@babel/env']
}
const standardConfig = {
breakOnError: false,
showRuleNames: true,
standard: {
globals: [
'requestAnimationFrame',
'sessionStorage'
]
}
}
const renameConfig = {
suffix: '.min'
}
const watchConfig = {
ignoreInitial: false
}
const sourcemapsConfig = `${helpers.src()}/${helpers.trim(global.config.js.dist)}`
function jsStart () {
return src(`${helpers.src()}/${helpers.trim(global.config.js.src)}/*.js`)
.pipe(sourcemaps.init())
.pipe(standard())
.pipe(standard.reporter('default', standardConfig))
.pipe(eslint(eslintConfig))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.pipe(eslint.result((result) => {
gutil.log(gutil.colors.blue(`ESLint result: ${result.filePath}`))
gutil.log(gutil.colors.green(`# Messages: ${result.messages.length}`))
gutil.log(gutil.colors.yellow(`# Warnings: ${result.warningCount}`))
gutil.log(gutil.colors.red(`# Errors: ${result.errorCount}`))
}))
.pipe(include(includeConfig))
.pipe(babel(babelConfig))
.pipe(dest(`${helpers.dist()}/${helpers.trim(global.config.js.dist)}`))
.pipe(uglify())
.pipe(rename(renameConfig))
.pipe(sourcemaps.write(sourcemapsConfig))
.pipe(dest(`${helpers.dist()}/${helpers.trim(global.config.js.dist)}`))
}
function jsListen () {
watch(`${helpers.src()}/${helpers.trim(global.config.js.src)}/*.js`, watchConfig, jsStart)
}
exports.js = {
jsStart,
jsListen
}