forked from jdf2e/nutui-react
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
130 lines (125 loc) · 3.81 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
const gulp = require('gulp')
const sass = require('gulp-sass')(require('sass'))
const postcss = require('gulp-postcss')
const rename = require('gulp-rename')
const cssvariables = require('postcss-css-variables')
const insert = require('gulp-insert')
const config = require('./src/config.json')
const adaptedNameArray = []
// eslint-disable-next-line array-callback-return
config.nav.map((item) => {
item.packages.forEach((element) => {
const { name, version } = element
if (version !== '3.0.0') return // 未适配不导出
adaptedNameArray.push(name.toLowerCase())
})
})
const argvs = process.argv.splice(4)[0]?.split('/') || adaptedNameArray
console.log(argvs, 'argvs')
// 监视频率 https://www.martin-brennan.com/gulp-watch-high-cpu-usage/
const interval = { interval: 500 }
// 监视文件变化
gulp.task('watch', () => {
argvs.forEach((argv) => {
gulp.watch(
`src/packages/${argv}/demos/taro/*`,
interval,
gulp.series(`${argv}copyDemo`)
)
gulp.watch(
`src/packages/${argv}/*.scss`,
interval,
gulp.series(`${argv}sass`, `${argv}copyCss`)
)
gulp.watch(
`src/packages/${argv}/demo.taro.tsx`,
interval,
gulp.series(`${argv}copyTaroDemo`)
)
gulp.watch(
`src/packages/${argv}/${argv}.taro.tsx`,
interval,
gulp.series(`${argv}copyTaro`)
)
// gulp.watch(
// `src/packages/${argv}/${argv}.rn.tsx`,
// interval,
// gulp.series(`${argv}copyRN`)
// )
})
const watchTasks = []
// eslint-disable-next-line array-callback-return
argvs.map((argv) => {
watchTasks.push(...[`${argv}sass`, `${argv}copyCss`])
})
gulp.watch(
[
`src/styles/variables.scss`,
'src/styles/mixins/text-ellipsis.scss',
'src/styles/theme-default.scss',
],
interval,
gulp.series(watchTasks)
)
})
argvs.forEach((argv) => {
const targetBaseUrl = `${process.cwd()}/packages/nutui-taro-demo/nutui-react/packages/${argv}`
gulp.task(`${argv}copyDemo`, (path) => {
console.log(path, 'path')
return gulp
.src(`src/packages/${argv}/demos/taro/*`)
.pipe(gulp.dest(`${targetBaseUrl}/demos/taro/`))
})
gulp.task(`${argv}sass`, () => {
return gulp
.src([`src/packages/${argv}/${argv}.scss`])
.pipe(
insert.prepend(
`@import '../../styles/theme-default.scss';\n@import '../../styles/mixins/text-ellipsis.scss';\n@import '../../styles/variables.scss';\n`
)
)
.pipe(
sass({
// 导入全局变量文件,不好用
// includePaths: [
// 'src/styles/theme-default.scss',
// 'src/styles/mixins/text-ellipsis.scss',
// 'src/styles/variables.scss',
// ],
}).on('error', sass.logError)
)
.pipe(postcss([cssvariables()]))
.pipe(
rename(function (path) {
path.extname = '.harmony.css'
})
)
.pipe(gulp.dest(`src/packages/${argv}/`))
})
gulp.task(`${argv}copyCss`, () => {
return gulp
.src([
`src/packages/${argv}/*.scss`,
`src/packages/${argv}/*.harmony.css`,
])
.pipe(gulp.dest(`${targetBaseUrl}/`))
})
gulp.task(`${argv}copyTaroDemo`, () => {
return gulp
.src(`src/packages/${argv}/demo.taro.tsx`)
.pipe(insert.prepend(`import '../../../styles/demo.scss';\n`))
.pipe(gulp.dest(`${targetBaseUrl}/`))
})
gulp.task(`${argv}copyTaro`, () => {
return gulp
.src(`src/packages/${argv}/${argv}.taro.tsx`)
.pipe(insert.prepend(`import "./${argv}.harmony.css";\n`))
.pipe(gulp.dest(`${targetBaseUrl}/`))
})
// gulp.task(`${argv}copyRN`, () => {
// return gulp
// .src(`src/packages/${argv}/${argv}.rn.tsx`)
// .pipe(insert.prepend(`import "./${argv}.harmony.css";\n`))
// .pipe(gulp.dest(`${targetBaseUrl}/`))
// })
})