This repository was archived by the owner on Sep 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (49 loc) · 1.3 KB
/
index.js
File metadata and controls
56 lines (49 loc) · 1.3 KB
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
const fse = require('fs-extra')
const globby = require('globby')
const {dirname, join} = require('path')
const DEFAULT_CONFIG = {
from: 'node_modules',
to: '_sass',
packages: '@primer',
files: '**/*.{scss,woff}'
}
module.exports = function sync(options) {
const cwd = process.cwd()
const config = Object.assign(
{},
DEFAULT_CONFIG,
options
)
console.warn('config:', JSON.stringify(config))
return getTasks(config)
.then(tasks => {
if (config.dryRun) {
return tasks
} else {
return Promise.all(
tasks.map(({source, dest}) => copy(source, dest))
).then(() => tasks)
}
})
}
module.exports.defaults = DEFAULT_CONFIG
function getTasks({from, to, packages, files}) {
return globby(packages, {cwd: from, expandDirectories: false, onlyFiles: false})
.then(packageDirs => {
const globs = [
'!**/node_modules',
...packageDirs.map(dir => join(dir, files))
]
return globby(globs, {cwd: from, onlyFiles: true})
})
.then(paths => paths.map(path => ({
source: join(from, path),
dest: join(to, path)
})))
}
function copy(from, to) {
return fse.exists(to)
.then(exists => exists ? fse.unlink(to) : true)
.then(() => fse.ensureDir(dirname(to)))
.then(() => fse.copy(from, to))
}