1 | let fs = require('fs')
|
2 | let path = require('path')
|
3 |
|
4 | let plugins = fs.readdirSync(fromRootPath('plugins'))
|
5 |
|
6 | for (let plugin of plugins) {
|
7 |
|
8 | let pluginDest = fromRootPath(plugin)
|
9 | if (fs.existsSync(pluginDest)) {
|
10 | fs.rmdirSync(pluginDest, { recursive: true })
|
11 | }
|
12 |
|
13 |
|
14 | copyFolder(fromRootPath('plugins', plugin), pluginDest, (file) => {
|
15 |
|
16 | if (file.endsWith('.test.js')) return false
|
17 |
|
18 | if (file.endsWith('.postcss7.js')) return false
|
19 |
|
20 | if (file.endsWith('.postcss8.js')) return false
|
21 |
|
22 | return true
|
23 | })
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 | function fromRootPath(...paths) {
|
29 | return path.resolve(process.cwd(), ...paths)
|
30 | }
|
31 |
|
32 | function copy(fromPath, toPath) {
|
33 | fs.mkdirSync(path.dirname(toPath), { recursive: true })
|
34 | fs.copyFileSync(fromPath, toPath)
|
35 | }
|
36 |
|
37 | function 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 | }
|