|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -const fs = require('fs-extra'); |
| 3 | +const fs = require('fs-promise'); |
4 | 4 | const spawn = require('child-process-promise').spawn; |
5 | 5 | const glob = require('glob'); |
6 | 6 | const path = require('path'); |
@@ -66,18 +66,18 @@ const asyncGlob = (pattern, opts) => new Promise( |
66 | 66 | ); |
67 | 67 |
|
68 | 68 | /** |
69 | | - * @func copy |
70 | | - * @desc Copies multiple files snychronously from one dir to another according to a glob pattern specified |
| 69 | + * @func copyWithPattern |
| 70 | + * @desc Copies multiple files asynchronously from one dir to another according to a glob pattern specified |
71 | 71 | * @param {string} cwd - The path to search for file(s) at |
72 | 72 | * @param {string} pattern - A glob pattern to match the file(s) |
73 | 73 | * @param {string} dest - The destination dir path |
74 | 74 | * @return {Promise} |
75 | 75 | */ |
76 | | -const copy = (cwd, pattern, dest) => wrapAsync(function*() { |
| 76 | +const copyWithPattern = (cwd, pattern, dest) => wrapAsync(function*() { |
77 | 77 | const files = yield asyncGlob(pattern, {cwd: cwd}); |
78 | 78 | if (files.length === 0) debug('patternlab→util→copy: Nothing to copy'); |
79 | 79 | // Copy concurrently |
80 | | - const promises = files.map(file => copyAsync( |
| 80 | + const promises = files.map(file => fs.copy( |
81 | 81 | path.join(cwd, file), |
82 | 82 | path.join(dest, file)) |
83 | 83 | ); |
@@ -126,57 +126,13 @@ const checkAndInstallPackage = (packageName, url) => wrapAsync(function*() { |
126 | 126 | */ |
127 | 127 | const noop = () => {}; |
128 | 128 |
|
129 | | -/** |
130 | | - * Promisified helper functions based on fs-extra |
131 | | - * 1. copyAsync |
132 | | - * 2. mkdirsAsync |
133 | | - * 3. moveAsync |
134 | | - * 4. writeJsonAsync |
135 | | - * 5. readJsonAsync |
136 | | - */ |
137 | | - |
138 | | -const copyAsync = (src, target) => new Promise((resolve, reject) => { |
139 | | - fs.copy(src, target, function (err) { |
140 | | - if (err) return reject(err); |
141 | | - return resolve(); |
142 | | - }) |
143 | | -}); |
144 | | - |
145 | | -const mkdirsAsync = dir => new Promise((resolve, reject) => { |
146 | | - fs.mkdirs(dir, function (err) { |
147 | | - if (err) return reject(err); |
148 | | - return resolve(); |
149 | | - }) |
150 | | -}); |
151 | | - |
152 | | -const moveAsync = (dir, target) => new Promise((resolve, reject) => { |
153 | | - fs.move(dir, target, function (err) { |
154 | | - if (err) return reject(err); |
155 | | - return resolve(); |
156 | | - }) |
157 | | -}); |
158 | | - |
159 | | -const writeJsonAsync = (file, data) => new Promise((resolve, reject) => { |
160 | | - fs.outputJson(file, data, function (err) { |
161 | | - if (err) return reject(err); |
162 | | - return resolve(); |
163 | | - }); |
164 | | -}); |
165 | | - |
166 | | -const readJsonAsync = file => new Promise((resolve, reject) => { |
167 | | - fs.readJson(file, function (err, data) { |
168 | | - if (err) return reject(err); |
169 | | - return resolve(data); |
170 | | - }); |
171 | | -}); |
172 | | - |
173 | 129 | module.exports = { |
174 | | - copy, |
175 | | - copyAsync, |
176 | | - mkdirsAsync, |
177 | | - moveAsync, |
178 | | - writeJsonAsync, |
179 | | - readJsonAsync, |
| 130 | + copyWithPattern, |
| 131 | + copyAsync: fs.copy, |
| 132 | + mkdirsAsync: fs.mkdirs, |
| 133 | + moveAsync: fs.move, |
| 134 | + writeJsonAsync: fs.outputJson, |
| 135 | + readJsonAsync: fs.readJson, |
180 | 136 | error, |
181 | 137 | debug, |
182 | 138 | wrapAsync, |
|
0 commit comments