-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfsFileAs.js
More file actions
36 lines (31 loc) · 862 Bytes
/
fsFileAs.js
File metadata and controls
36 lines (31 loc) · 862 Bytes
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
const _ = require('lodash');
const path = require('path');
const exec = require('shelljs').exec;
const debug = require('debug')('push2cloud-compiler-fs:fsFileAs');
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
, targetFile
) => (
`cp ${sourceFile} ${targetFile}`
);
const fsFile = _.curry((
ctx
, cb
) => {
const targetFile = ctx.targetFile || ctx.file;
const sourceFile = path.join(!path.isAbsolute(ctx.url || '') ? ctx.rootDir || '' : '', ctx.url || '', ctx.file);
const command = cmd(sourceFile, targetFile);
debug('starting command', command);
exec(command, {silent: false, async: true}, debugCb(debug, cb));
});
module.exports = fsFile;