forked from 18226598153/JD_tencent_scf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.js
32 lines (29 loc) · 995 Bytes
/
upgrade.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
const { existsSync, readdirSync, copyFile } = require("fs");
const { extname } = require("path");
const chalk = require('chalk');
const { execSync, exec } = require("child_process");
const syncDir = __dirname + "/sync";
if (!existsSync(syncDir)) {
chalk.red('未发现脚本仓库, 取消同步..')
process.exit();
}
const files = readdirSync(syncDir)
const newFiles=[];
for (const file of files) {
const ext = extname(file).toLowerCase();
if (file == 'package.json' || (ext == '.js' && file.startsWith("jd") && file!='jdCookie.js')) {
const nFile = `${syncDir}/${file}`;
const oFile = `${__dirname}/src/${file}`;
const hasOld=existsSync(oFile);
if (hasOld) {
console.log(chalk.blue(`更新脚本${file}`))
} else {
newFiles.push(file)
}
copyFile(nFile, oFile, () => { })
}
}
for (const file of newFiles) {
console.log(chalk.green(`新增脚本${file}`))
exec(`git add src/${file}`)
}