-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatchall.js
30 lines (25 loc) · 865 Bytes
/
catchall.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
'use strict';
const fse = require('fs-extra');
const path = require('path');
const recursive = require('recursive-readdir');
module.exports = function (options, callback) {
let packageName = options.package;
if (packageName.indexOf('@') > -1) {
packageName = packageName.substring(0, packageName.indexOf('@'));
}
const distPath = path.join(options.tempDir, `./node_modules/${packageName}/dist`);
recursive(distPath, (error, files) => {
if (error) {
return callback(error);
}
files.forEach(file => {
let distFile = file.replace(distPath, '');
let outputPath = path.dirname(distFile);
outputPath = path.join(options.outputDir, outputPath);
fse.mkdirpSync(outputPath);
let outputFile = path.join(options.outputDir, distFile);
fse.copySync(file, outputFile);
});
callback(null);
});
};