-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.ts
73 lines (67 loc) · 2.48 KB
/
gulpfile.ts
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
import { imagesCopy, jsCopy, jsonCopy, miniprogramSourceCopy, projectconfigCopy, wxmlCopy, wxsCopy, wxssCopy } from './gulp/Copy'
import { imgFiles, jsFiles, jsonFiles, miniprogramSource, projectconfig, sassFiles, tsFiles, wxmlFiles, wxsFiles, wxssFiles } from './gulp/SourcePath'
import child_process from 'child_process'
import { cleanDistDir } from './gulp/Clean'
import colors from 'colors'
import fs from 'fs'
import gulp from 'gulp'
import { initProjectConfig } from './gulp/InitProjectConfig'
import { sassParser } from './gulp/Sass'
import { tsParser } from './gulp/Typescript'
// const postcss = require('gulp-postcss');
// const cssnano = require('cssnano');
// const concat = require('gulp-concat');
// const uglify = require('gulp-uglify');
async function install_npm() {
const cmd = 'cd app/miniprogram && npm install'
try {
await fs.accessSync('app/miniprogram/package.json')
} catch (err) {
console.log(colors.red('miniprogram不存在package.json, 自动创建...'))
await child_process.execSync('cd app/miniprogram && npm init -y')
}
// 使用npm安装依赖
try {
await child_process.execSync(cmd)
console.log(colors.green('install_npm完成'))
} catch (err) {
console.log(colors.red(err.stack))
}
}
gulp.task(cleanDistDir)
gulp.task(projectconfigCopy)
gulp.task(miniprogramSourceCopy)
gulp.task(jsCopy)
gulp.task(wxssCopy)
gulp.task(wxmlCopy)
gulp.task(wxsCopy)
gulp.task(jsonCopy)
gulp.task(imagesCopy)
gulp.task(tsParser)
gulp.task(sassParser)
gulp.task(install_npm)
gulp.task(initProjectConfig)
// parallel
gulp.task(
'build',
gulp.series(
'cleanDistDir',
gulp.parallel('projectconfigCopy', 'miniprogramSourceCopy', 'jsCopy', 'wxssCopy', 'wxmlCopy', 'wxsCopy', 'jsonCopy', 'imagesCopy', 'tsParser', 'sassParser'),
'initProjectConfig',
'install_npm'
)
)
// watch
gulp.task('watch', () => {
gulp.watch(imgFiles, { alwaysStat: true }, imagesCopy)
gulp.watch(wxssFiles, { alwaysStat: true }, wxssCopy)
gulp.watch(jsFiles, { alwaysStat: true }, jsCopy)
gulp.watch(wxsFiles, { alwaysStat: true }, wxsCopy)
gulp.watch(jsonFiles, { alwaysStat: true }, jsonCopy)
gulp.watch(wxmlFiles, { alwaysStat: true }, wxmlCopy)
gulp.watch(tsFiles, { alwaysStat: true }, tsParser)
gulp.watch(sassFiles, { alwaysStat: true }, sassParser)
gulp.watch(miniprogramSource, { alwaysStat: true }, miniprogramSourceCopy)
gulp.watch(projectconfig, { alwaysStat: true }, projectconfigCopy)
})
gulp.task('start', gulp.series('build', 'watch'))