-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·70 lines (57 loc) · 1.45 KB
/
index.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var rimraf = require('rimraf');
var mkdirp = require('mkdirp');
var semver = require('semver');
var path = require('path');
var ncp = require('ncp').ncp;
function filterDotFiles(path) {
var pathParts = path.split('/');
var filename = pathParts[pathParts.length - 1];
if (filename[0] === '.') {
return false;
}
return true;
}
function getCommitHash() {
return require('child_process')
.execSync('git rev-parse HEAD')
.toString().trim();
}
module.exports = function (
version, latest, input, output, onlyDeployMajor, ignoreDotFiles, deployCommitHash
) {
var folderName = '';
var options = {};
if (version && !deployCommitHash) {
semver.valid(version);
if (onlyDeployMajor) {
folderName = semver.major(version);
} else {
folderName = version;
}
}
if (deployCommitHash) {
folderName = getCommitHash();
}
if(ignoreDotFiles === true) {
options.filter = filterDotFiles;
}
var pathToCreate = path.join(output, String(folderName));
rimraf.sync(pathToCreate);
mkdirp.sync(pathToCreate);
ncp(path.join(input), pathToCreate, options, function(err) {
if (err) {
return console.error(err);
}
});
if (latest) {
var pathToLatest = path.join(latest);
rimraf.sync(pathToLatest);
mkdirp.sync(pathToLatest);
ncp(path.join(input), pathToLatest, options, function(err) {
if (err) {
return console.error(err);
}
});
}
console.log('done!');
};