This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
88 lines (74 loc) · 3.4 KB
/
gulpfile.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
71
72
73
74
75
76
77
78
79
80
81
82
83
var fs = require('fs');
var gulp = require('gulp');
var glob = require('glob');
var shelljs = require('shelljs');
var path = require('path');
var branch = 'master';
var user = process.env.GIT_USER;
var token = process.env.GIT_TOKEN;
var user_mail = process.env.GIT_MAIL;
var is_temp = process.env.IS_TEMP;
var changedFileNames;
var changes;
/**
* Source shipping to gitlab
*/
gulp.task('ship-to-gitlab', function (done) {
changedFileNames = changedFileNameList();
console.log('--changedFileNames----' + changedFileNames);
var gitPath = 'https://' + user + ':' + token + `@gitlab.syncfusion.com/content/asp.netwebforms-docs`;
console.log('Clone has been started...!');
var clone = shelljs.exec('git clone ' + gitPath + ' -b ' + branch + ' ' + `../../../gitlabRepo/asp.netwebforms-docs`, {
silent: false
});
if (clone.code !== 0) {
console.log(clone.stderr);
done();
return;
} else {
console.log('Clone has been completed...!');
// update src from github to gitlab - replace files from cloned repo
for (var changedFileName of changedFileNames.split(',')) {
if (changedFileName !== null && changedFileName !== '' && changedFileName !== '.gitignore' && changedFileName !== 'Jenkinsfile' && changedFileName !== 'README.md' && !changedFileName.includes('.gitlab')) {
if (fs.existsSync('../asp.netwebforms-docs/' + changedFileName)) {
// It will update the modified files
if (fs.existsSync('../../../gitlabRepo/asp.netwebforms-docs/' + changedFileName)) {
shelljs.cp('-rf', `../asp.netwebforms-docs/` + changedFileName, `../../../gitlabRepo/asp.netwebforms-docs/` + changedFileName);
}
else {
// It will update the newly added files
if (fs.existsSync('../../../gitlabRepo/asp.netwebforms-docs/')) {
shelljs.cp('-rf', `../asp.netwebforms-docs/` + changedFileName, `../../../gitlabRepo/asp.netwebforms-docs/` + changedFileName);
}
}
}
else {
// It will remove the deleted files
if (fs.existsSync('../../../gitlabRepo/asp.netwebforms-docs/' + changedFileName)) {
shelljs.rm('-rf', `../../../gitlabRepo/asp.netwebforms-docs/` + changedFileName);
}
}
}
}
shelljs.cd(`../../../gitlabRepo/asp.netwebforms-docs`);
shelljs.exec('git add .');
shelljs.exec('git pull');
shelljs.exec('git commit -m \"source updation from github repo \" --no-verify');
shelljs.exec('git push');
shelljs.cd('../../');
}
})
// Controls List
function changedFileNameList() {
shelljs.exec(`git config --global user.email "${user_mail}"`);
shelljs.exec(`git config --global user.name "${user}"`);
changes = shelljs.exec(`git diff --name-status HEAD^ HEAD`);
var controls = '';
var changesList = changes.stdout.split('\n');
if (changesList !== null && changesList !== '') {
for (var comp of changesList) {
controls += comp.replace(/A\s+/g, "").replace(/M\s+/g, "").replace(/D\s+/g, "").replace(/R100\s+/g, "").split(/\s+/g) + ',';
}
return controls;
}
}