-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgitFile.js
More file actions
41 lines (37 loc) · 1020 Bytes
/
gitFile.js
File metadata and controls
41 lines (37 loc) · 1020 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
37
38
39
40
41
const _ = require('lodash');
const exec = require('shelljs').exec;
const debug = require('debug')('push2cloud-compiler-git-no-archive:gitFile');
const debugCb = (debugFn, cb) => {
return (err, result) => {
if (err) {
debugFn('error', `Errorcode: ${err}`, result);
} else {
debugFn('success', result);
}
return cb(err, result);
};
};
const cmd = (
repo
, reference
, file
, target
) => (
`if [ ! -d ${target}/__tmp/${repo}@${reference} ];
then
mkdir -p ${target}/__tmp;
cd ${target}/__tmp;
git clone ${repo} ${repo}@${reference};
cd ../..;
fi;
cd ${target}/__tmp/${repo}@${reference} && git checkout ${reference} && mkdir -p ${target}/$( dirname ${file} ) && cp ${file} ${target}/$( dirname ${file} )`
);
const gitFile = _.curry((
ctx
, cb
) => {
const command = cmd(ctx.url, ctx.referenceValue, ctx.file, ctx.target);
debug('starting command', command);
exec(command, {silent: false, async:true}, debugCb(debug, cb));
});
module.exports = gitFile;