-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgitFileAs.js
More file actions
44 lines (39 loc) · 1.03 KB
/
gitFileAs.js
File metadata and controls
44 lines (39 loc) · 1.03 KB
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
42
43
44
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
, targetDir
, targetFile
) => (
`if [ ! -d ${targetDir}/__tmp/${repo}@${reference} ];
then
mkdir -p ${targetDir}/__tmp;
cd ${targetDir}/__tmp;
git clone ${repo} ${repo}@${reference};
cd ../..;
fi;
cd ${targetDir}/__tmp/${repo}@${reference} && git checkout ${reference} && cp ${file} ${targetFile}`
);
const gitFile = _.curry((
ctx
, cb
) => {
ctx.targetFile = ctx.targetFile || ctx.file;
const command = cmd(ctx.url, ctx.referenceValue, ctx.file, ctx.targetDir, ctx.targetFile);
debug('starting command', command);
exec(command, {silent: false, async:true}, debugCb(debug, cb));
});
module.exports = gitFile;