-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsFile.js
41 lines (36 loc) · 991 Bytes
/
fsFile.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
31
32
33
34
35
36
37
38
39
40
41
const _ = require('lodash');
const exec = require('shelljs').exec;
const path = require('path');
const debug = require('debug')('push2cloud-compiler-fs:fsFile');
const debugCb = (debugFn, cb) => {
return (err, result) => {
if (err) {
debugFn('error', `Errorcode: ${err}`, result);
} else {
debugFn('success', result);
}
return cb(err, result);
};
};
const cmd = (
sourceFile
, targetDir
, file
) => (
`if [ ! -d ${targetDir}/$( dirname ${file} ) ];
then
mkdir -p ${targetDir}/$( dirname ${file} );
fi;
cp ${sourceFile} ${targetDir}/$( dirname ${file} )/`
);
const fsFile = _.curry((
ctx
, cb
) => {
const targetDir = ctx.target;
const sourceFile = path.join(!path.isAbsolute(ctx.url || '') ? ctx.rootDir || '' : '', ctx.url || '', ctx.file);
const command = cmd(sourceFile, targetDir, ctx.file);
debug('starting command', command);
exec(command, {silent: false, async: true}, debugCb(debug, cb));
});
module.exports = fsFile;