From f30afac47e5de3cfc7ed389e9a490edcaf37c943 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Wed, 28 Jun 2023 14:34:22 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=90=8C=E6=AD=A5npm=E9=95=9C?= =?UTF-8?q?=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.js | 100 ++++++++++++++++++++++++---------------- docker/image/Dockerfile | 4 +- package.json | 10 ++-- 3 files changed, 69 insertions(+), 45 deletions(-) diff --git a/deploy.js b/deploy.js index 3fb70ab6..71a3cef9 100644 --- a/deploy.js +++ b/deploy.js @@ -1,58 +1,79 @@ -const http = require("axios") -const exec = require('child_process').exec; +import http from 'axios' +import fs from 'fs' -//builder -function execute(cmd){ - 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) +//读取 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; } + + // 过滤仅保留目录 + 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 certdImageBuild = "http://flow-openapi.aliyun.com/pipeline/webhook/4zgFk3i4RZEMGuQzlOcI" +const webhooks = [certdImageBuild] -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] - -async function sleep(time){ +async function sleep(time) { return new Promise(resolve => { - setTimeout(resolve,time) + setTimeout(resolve, time) }) } -async function trigger(){ +async function triggerBuild() { for (const webhook of webhooks) { await http({ - url:webhook, - method:'POST', - headers:{ + url: webhook, + method: 'POST', + headers: { "Content-Type": "application/json" }, - data:{} + data: { + 'CERTD_VERSION': certdVersion + } }) console.log(`webhook success:${webhook}`) await sleep(1000) @@ -60,11 +81,12 @@ async function trigger(){ } -async function start(){ +async function start() { // await build() console.log("等待60秒") - await sleep(60*1000) - await trigger() + await sleep(60 * 1000) + await sync() + await triggerBuild() } start() diff --git a/docker/image/Dockerfile b/docker/image/Dockerfile index c40c5557..32b44350 100644 --- a/docker/image/Dockerfile +++ b/docker/image/Dockerfile @@ -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"] diff --git a/package.json b/package.json index 2b09e8e0..b56ce3e6 100644 --- a/package.json +++ b/package.json @@ -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": [