UNPKG

1.26 kBJavaScriptView Raw
1let fs = require('fs')
2let path = require('path')
3
4let plugins = fs.readdirSync(fromRootPath('plugins'))
5
6for (let plugin of plugins) {
7 // Cleanup
8 let pluginDest = fromRootPath(plugin)
9 if (fs.existsSync(pluginDest)) {
10 fs.rmdirSync(pluginDest, { recursive: true })
11 }
12
13 // Copy plugin over
14 copyFolder(fromRootPath('plugins', plugin), pluginDest, (file) => {
15 // Ignore test files
16 if (file.endsWith('.test.js')) return false
17 // Ignore postcss7 files
18 if (file.endsWith('.postcss7.js')) return false
19 // Ignore postcss8 files
20 if (file.endsWith('.postcss8.js')) return false
21
22 return true
23 })
24}
25
26// ---
27
28function fromRootPath(...paths) {
29 return path.resolve(process.cwd(), ...paths)
30}
31
32function copy(fromPath, toPath) {
33 fs.mkdirSync(path.dirname(toPath), { recursive: true }) // Ensure folder exists
34 fs.copyFileSync(fromPath, toPath)
35}
36
37function copyFolder(fromPath, toPath, shouldCopy = () => true) {
38 let stats = fs.statSync(fromPath)
39 if (stats.isDirectory()) {
40 let filesAndFolders = fs.readdirSync(fromPath)
41 for (let file of filesAndFolders) {
42 copyFolder(path.resolve(fromPath, file), path.resolve(toPath, file), shouldCopy)
43 }
44 } else if (shouldCopy(fromPath)) {
45 copy(fromPath, toPath)
46 }
47}