chore: 同步npm镜像

pull/21/merge
xiaojunnuo 2023-06-28 14:34:22 +08:00
parent 1779e34773
commit f30afac47e
3 changed files with 69 additions and 45 deletions

View File

@ -1,42 +1,61 @@
const http = require("axios")
const exec = require('child_process').exec;
import http from 'axios'
import fs from 'fs'
//builder
function execute(cmd){
//读取 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) => {
console.log("cmd executing: " + cmd)
exec(cmd, function(error, stdout, stderr) {
if(error){
console.error(error);
console.info(stderr)
reject(error)
}
else{
console.info(stdout)
console.log("success");
resolve(true)
// 读取目录下的文件和目录列表
fs.readdir(directoryPath, {withFileTypes: true}, (err, files) => {
if (err) {
console.log('无法读取目录:', err);
reject(err)
return;
}
// 过滤仅保留目录
const directories = files
.filter(file => file.isDirectory())
.map(directory => directory.name);
console.log('目录列表:', directories);
resolve(directories)
});
})
}
async function build(){
await execute("cd ./packages/fast-admin/fs-admin-antdv/ && npm run build")
await execute("cd ./packages/fast-admin/fs-admin-element/ && npm run build")
await execute("cd ./packages/fast-admin/fs-admin-naive-ui/ && npm run build")
await execute("npm run docs:build")
async function getAllPackages(){
const base = await getPackages("./packages/core")
const plugins =await getPackages("./packages/plugins")
return base.concat(plugins)
}
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)
}
// curl -X PUT https://registry-direct.npmmirror.com/@certd/plugin-cert/sync?sync_upstream=true
// trigger
const naive = "http://flow-openapi.aliyun.com/pipeline/webhook/Zm3TJyDtyFZgV4dtJiD1"
const doc = "http://flow-openapi.aliyun.com/pipeline/webhook/soOYdQ5sF3kLjTPJGmIO"
const antdv = "http://flow-openapi.aliyun.com/pipeline/webhook/HiL0uVYxfUnBzIMJZVXB"
const element = "http://flow-openapi.aliyun.com/pipeline/webhook/uFTI0XJ9RgqnofX7jpRD"
const webhooks = [doc,naive,antdv,element]
const certdImageBuild = "http://flow-openapi.aliyun.com/pipeline/webhook/4zgFk3i4RZEMGuQzlOcI"
const webhooks = [certdImageBuild]
async function sleep(time) {
return new Promise(resolve => {
@ -44,7 +63,7 @@ async function sleep(time){
})
}
async function trigger(){
async function triggerBuild() {
for (const webhook of webhooks) {
await http({
url: webhook,
@ -52,7 +71,9 @@ async function trigger(){
headers: {
"Content-Type": "application/json"
},
data:{}
data: {
'CERTD_VERSION': certdVersion
}
})
console.log(`webhook success:${webhook}`)
await sleep(1000)
@ -64,7 +85,8 @@ async function start(){
// await build()
console.log("等待60秒")
await sleep(60 * 1000)
await trigger()
await sync()
await triggerBuild()
}
start()

View File

@ -6,8 +6,8 @@ WORKDIR /app/
#RUN npm install pm2 -g --registry=https://registry.npmmirror.com
#RUN pm2 install pm2-logrotate
ADD ./workspace/certd-server/ /app/
#RUN yarn install --production --registry=https://registry.npmmirror.com
RUN yarn install --production
RUN yarn install --production --registry=https://registry.npmmirror.com
#RUN yarn install --production
RUN npm run build
#CMD ["pm2-runtime", "start", "./bootstrap.js","--name", "certd","-i","1"]
CMD ["npm", "run","start"]

View File

@ -5,20 +5,22 @@
"type": "module",
"devDependencies": {
"@lerna-lite/cli": "^2.4.0",
"@lerna-lite/run": "^2.4.0",
"@lerna-lite/publish": "^2.4.0"
"@lerna-lite/publish": "^2.4.0",
"@lerna-lite/run": "^2.4.0"
},
"scripts": {
"start": "lerna bootstrap --hoist",
"i-all": "lerna link && lerna exec npm install ",
"publish": "npm run proxy && npm run prepublishOnly1 && lerna publish --conventional-commits && npm run afterpublishOnly",
"publish": "npm run proxy && npm run prepublishOnly1 && lerna publish --conventional-commits && npm run afterpublishOnly && npm run deploy",
"afterpublishOnly": "",
"proxy": "npm config set proxy=http://127.0.0.1:10809",
"prepublishOnly1": "npm run before-build && lerna run build ",
"before-build": "cd ./packages/core/acme-client && time /t >build.md && git add ./build.md && git commit -m \"build: prepare to build\""
"before-build": "cd ./packages/core/acme-client && time /t >build.md && git add ./build.md && git commit -m \"build: prepare to build\"",
"deploy": "node deploy.js"
},
"license": "MIT",
"dependencies": {
"axios": "^1.4.0",
"lodash": "^4.17.21"
},
"workspaces": [