forked from postcss/autoprefixer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
123 lines (104 loc) · 3.02 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
let gulp = require('gulp')
let fs = require('fs-extra')
let postcss = require('gulp-postcss')
let rename = require('gulp-rename')
function join (...folderPath) { return folderPath.join('/') }
gulp.task('clean', done => {
fs.remove(join(__dirname, 'autoprefixer.js'), () => {
fs.remove(join(__dirname, 'build'), done)
})
})
gulp.task('build:lib', gulp.series('clean', () => {
let babel = require('gulp-babel')
return gulp.src(['{lib,data}/**/*.js'])
.pipe(babel())
.pipe(gulp.dest('build/'))
}))
gulp.task('build:docs', () => {
let ignore = require('fs').readFileSync('.npmignore').toString()
.trim().split(/\n+/)
.concat([
'.npmignore',
'index.js',
'package.json',
'logo.svg',
'AUTHORS',
'node_modules'
])
.map(i => '!' + i)
return gulp.src(['*'].concat(ignore))
.pipe(gulp.dest('build'))
})
gulp.task('build:bin', () => {
return gulp.src('bin/*').pipe(gulp.dest('build/bin'))
})
gulp.task('build:package', () => {
let editor = require('gulp-json-editor')
return gulp.src('./package.json')
.pipe(editor(json => {
json.main = 'lib/autoprefixer'
delete json.devDependencies
delete json.babel
delete json.scripts
delete json.jest
delete json.browserslist
delete json.eslintConfig
delete json.husky
delete json['size-limit']
delete json['lint-staged']
delete json.dependencies['@babel/register']
return json
}))
.pipe(gulp.dest('build'))
})
gulp.task('build', gulp.series(
'clean',
gulp.parallel('build:lib', 'build:docs', 'build:bin', 'build:package')
))
gulp.task('standalone', gulp.series('clean', 'build:lib', done => {
let builder = require('browserify')({
basedir: join(__dirname, 'build'),
standalone: 'autoprefixer'
})
builder.add('./lib/autoprefixer.js')
builder
.transform('babelify', {
global: true,
presets: [
[
'@babel/env', {
targets: {
node: 6
},
loose: true
}
]
]
})
.bundle((error, build) => {
if (error) throw error
fs.removeSync(join(__dirname, 'build'))
let rails = join(__dirname, '..', 'autoprefixer-rails',
'vendor', 'autoprefixer.js')
if (fs.existsSync(rails)) {
fs.writeFileSync(rails, build)
} else {
let out = join(__dirname, 'autoprefixer.js')
fs.writeFileSync(out, build)
}
done()
})
}))
gulp.task('compile-playground', () => {
let autoprefixer = require('./build')
return gulp.src('./playground/input.css')
.pipe(rename('output.css'))
.pipe(postcss([autoprefixer({ grid: 'autoplace' })]))
.pipe(gulp.dest('./playground'))
})
gulp.task('initialise-playground', gulp.series('build', 'compile-playground'))
gulp.task('watch-playground', () => {
return gulp.watch('./playground/input.css', gulp.series('compile-playground'))
})
gulp.task('play', gulp.series('initialise-playground', 'watch-playground'))
gulp.task('default', gulp.series('build'))