certd/deploy.js

103 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-06-28 06:34:22 +00:00
import http from 'axios'
import fs from 'fs'
//读取 packages/core/pipline/package.json的版本号
import { default as packageJson } from './packages/core/pipeline/package.json' assert { type: "json" };
console.log("certdVersion", packageJson.version)
// 同步npmmirror的包
async function getPackages(directoryPath) {
return new Promise((resolve, reject) => {
// 读取目录下的文件和目录列表
fs.readdir(directoryPath, {withFileTypes: true}, (err, files) => {
if (err) {
console.log('无法读取目录:', err);
reject(err)
return;
2023-05-24 09:38:24 +00:00
}
2023-06-28 06:34:22 +00:00
// 过滤仅保留目录
const directories = files
.filter(file => file.isDirectory())
.map(directory => directory.name);
console.log('目录列表:', directories);
resolve(directories)
2023-05-24 09:38:24 +00:00
});
})
}
2023-06-28 06:34:22 +00:00
async function getAllPackages(){
const base = await getPackages("./packages/core")
const plugins =await getPackages("./packages/plugins")
2023-05-24 09:38:24 +00:00
2023-06-28 06:34:22 +00:00
return base.concat(plugins)
}
2023-05-24 09:38:24 +00:00
2023-06-28 06:34:22 +00:00
async function sync(){
const packages = await getAllPackages()
for(const pkg of packages){
await http({
url: `https://registry-direct.npmmirror.com/@certd/${pkg}/sync?sync_upstream=true`,
method: 'PUT',
headers: {
"Content-Type": "application/json"
},
data: {}
})
console.log(`sync success:${pkg}`)
await sleep(1000)
}
await sleep(60000)
}
2023-05-24 09:38:24 +00:00
2023-06-28 06:34:22 +00:00
// curl -X PUT https://registry-direct.npmmirror.com/@certd/plugin-cert/sync?sync_upstream=true
2023-05-24 09:38:24 +00:00
2023-06-28 06:34:22 +00:00
const certdImageBuild = "http://flow-openapi.aliyun.com/pipeline/webhook/4zgFk3i4RZEMGuQzlOcI"
const webhooks = [certdImageBuild]
2023-05-24 09:38:24 +00:00
2023-06-28 06:34:22 +00:00
async function sleep(time) {
2023-05-24 09:38:24 +00:00
return new Promise(resolve => {
2023-06-28 06:34:22 +00:00
setTimeout(resolve, time)
2023-05-24 09:38:24 +00:00
})
}
2023-06-28 06:34:22 +00:00
async function triggerBuild() {
2023-05-24 09:38:24 +00:00
for (const webhook of webhooks) {
await http({
2023-06-28 06:34:22 +00:00
url: webhook,
method: 'POST',
headers: {
2023-05-24 09:38:24 +00:00
"Content-Type": "application/json"
},
2023-06-28 06:34:22 +00:00
data: {
'CERTD_VERSION': certdVersion
}
2023-05-24 09:38:24 +00:00
})
console.log(`webhook success:${webhook}`)
await sleep(1000)
}
}
2023-06-28 06:34:22 +00:00
async function start() {
2023-05-24 09:38:24 +00:00
// await build()
console.log("等待60秒")
2023-06-28 06:34:22 +00:00
await sleep(60 * 1000)
await sync()
await triggerBuild()
2023-05-24 09:38:24 +00:00
}
start()
/**
* 打包前 修改 lerna
* nodemodules里面搜索如下
* return childProcess.exec("git", ["add", "--", ...files], execOpts);
*
* ('git', ['add', '--', ...files]
* ('git', ['add', '.']
*/