-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
52 lines (42 loc) · 1.55 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
const dotenv = require('dotenv').config()
const { src, dest, watch } = require('gulp')
const rename = require('gulp-rename')
const postcss = require('gulp-postcss')
const postcssNested = require('postcss-nested')
const postcssImport = require('postcss-import')
// What filename does the target program expect to use?
const expectedFilenames = {}
const source = process.env.SRC || 'theme'
const sourcePath = `./${process.env.TARGET}/src/${source}.css`
let destinationPath = `./${process.env.TARGET}/out/`
// If there are any custom paths set in the .env, use those
const customLabeledDest = process.env[`DEST_${process.env.TARGET}_${process.env.SRC}`]
const customUnlabeledDest = process.env[`DEST_${process.env.TARGET}`]
if (customLabeledDest) destinationPath = customLabeledDest
else if (customUnlabeledDest) destinationPath = customUnlabeledDest
function compile() {
const plugins = [postcssImport(), postcssNested()]
return (
src(sourcePath)
.pipe(postcss(plugins))
.pipe(
// No expected file rename in expectedFilenames for the target? Just use the source
rename(expectedFilenames[process.env.TARGET] || `${source}.css`)
)
.pipe(
dest(destinationPath, {
overwrite: true,
})
)
// Copies the file to out also, for hosting in the repo
.pipe(rename(`${source}.css`))
.pipe(
dest(`./${process.env.TARGET}/out/`, {
overwrite: true,
})
)
)
}
exports.default = function () {
watch(sourcePath, {ignoreInitial: false, usePolling: true}, compile)
}