forked from galaxy-s10/billd-live-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandleGiteeJenkins.js
75 lines (70 loc) · 2.18 KB
/
handleGiteeJenkins.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
// WARN 该文件只是方便我将当前项目复制一份到我电脑的另一个位置(gitee私有仓库的位置),其他人不需要管这个文件~
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const allFile = [];
const ignore = ['.DS_Store', '.git', '.gitignore', 'node_modules', 'dist'];
const localDir = path.resolve(__filename, '../');
const giteeDir = path.resolve(
__filename,
'../',
'./../../jenkins/billd-live-server'
);
const dir = fs.readdirSync(localDir).filter((item) => {
if (ignore.includes(item)) {
return false;
}
return true;
});
function findFile(inputDir) {
for (let i = 0; i < inputDir.length; i += 1) {
const file = inputDir[i];
const filePath = `${localDir}/${file}`;
const stat = fs.statSync(filePath);
const isDir = stat.isDirectory();
if (!isDir) {
allFile.push(filePath);
} else {
findFile(fs.readdirSync(filePath).map((key) => `${file}/${key}`));
}
}
}
function putFile() {
for (let i = 0; i < allFile.length; i += 1) {
const file = allFile[i];
const arr = [];
const githubFile = file.replace(localDir, '');
const githubFileArr = githubFile.split('/').filter((item) => item !== '');
githubFileArr.forEach((item) => {
if (arr.length) {
arr.push(path.resolve(arr[arr.length - 1], item));
} else {
arr.push(path.resolve(giteeDir, item));
}
});
arr.forEach((item, index) => {
// 数组的最后一个一定是文件,因此不需要判断它是不是目录
if (index !== arr.length - 1) {
const flag = fs.existsSync(item);
// eslint-disable-next-line
!flag && fs.mkdirSync(item);
}
});
fs.copyFileSync(
file,
path.join(giteeDir, './', file.replace(localDir, ''))
);
}
}
if (path.resolve(__dirname) === giteeDir) {
// eslint-disable-next-line
console.log('当前在gitee文件目录,直接退出!');
}
findFile(dir);
putFile();
execSync(`pnpm i`, { cwd: giteeDir });
execSync(`git add .`, { cwd: giteeDir });
execSync(`git commit -m 'feat: ${new Date().toLocaleString()}'`, {
cwd: giteeDir,
});
execSync(`git push`, { cwd: giteeDir });