mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: 优化源码方式部署,前端无需编译
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
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" };
|
||||
|
||||
const certdVersion = packageJson.version
|
||||
console.log("certdVersion", certdVersion)
|
||||
|
||||
// 同步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 getAllPackages() {
|
||||
const base = await getPackages("./packages/core")
|
||||
const plugins = await getPackages("./packages/plugins")
|
||||
const libs = await getPackages("./packages/libs")
|
||||
|
||||
return base.concat(plugins).concat(libs)
|
||||
}
|
||||
|
||||
async function sync() {
|
||||
const packages = await getAllPackages()
|
||||
for (const pkg of packages) {
|
||||
await http({
|
||||
url: `http://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(30*1000)
|
||||
}
|
||||
}
|
||||
|
||||
// curl -X PUT https://registry-direct.npmmirror.com/@certd/plugin-cert/sync?sync_upstream=true
|
||||
|
||||
const certdImageBuild = "http://flow-openapi.aliyun.com/pipeline/webhook/4zgFk3i4RZEMGuQzlOcI"
|
||||
const certdImageRun = "http://flow-openapi.aliyun.com/pipeline/webhook/lzCzlGrLCOHQaTMMt0mG"
|
||||
const webhooks = [certdImageBuild,certdImageRun]
|
||||
|
||||
async function sleep(time) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, time)
|
||||
})
|
||||
}
|
||||
|
||||
async function triggerBuild() {
|
||||
await sleep(60000)
|
||||
for (const webhook of webhooks) {
|
||||
await http({
|
||||
url: webhook,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
data: {
|
||||
'CERTD_VERSION': certdVersion
|
||||
}
|
||||
})
|
||||
console.log(`webhook success:${webhook}`)
|
||||
await sleep(30*60*1000)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function start() {
|
||||
// await build()
|
||||
console.log("等待60秒")
|
||||
await sleep(100* 1000)
|
||||
await sync()
|
||||
await sleep(100 * 1000)
|
||||
await triggerBuild()
|
||||
}
|
||||
|
||||
start()
|
||||
|
||||
|
||||
/**
|
||||
* 打包前 修改 lerna
|
||||
* nodemodules里面搜索如下
|
||||
* return childProcess.exec("git", ["add", "--", ...files], execOpts);
|
||||
*
|
||||
* ('git', ['add', '--', ...files]
|
||||
* ('git', ['add', '.']
|
||||
*/
|
||||
@@ -0,0 +1,181 @@
|
||||
import fs from 'fs'
|
||||
import axios from 'axios'
|
||||
|
||||
|
||||
const AtomgitAccessToken = process.env.ATOMGIT_TOKEN
|
||||
// CHANGELOG.md
|
||||
const changelog = fs.readFileSync('./CHANGELOG.md', 'utf8')
|
||||
// 解析CHANGELOG.md
|
||||
let lines = changelog.split('\n')
|
||||
const versionLineIndex = lines.findIndex(line => line.startsWith('## '))
|
||||
const versionLine = lines[versionLineIndex]
|
||||
// ## [1.37.16](https://github.com/certd/certd/compare/v1.37.15...v1.37.16) (2025-12-15)
|
||||
const versionTitle = versionLine.match(/\[(.*?)\]/)[1]
|
||||
|
||||
const contentStart = versionLineIndex + 1
|
||||
lines = lines.slice(contentStart)
|
||||
const contentEnd = lines.findIndex(line => {
|
||||
return line.startsWith('## ')
|
||||
})
|
||||
const content = lines.slice(0, contentEnd).join('\n')
|
||||
console.log("-------title------/n")
|
||||
console.log(versionTitle)
|
||||
console.log("-------content------/n")
|
||||
console.log(content)
|
||||
|
||||
/**
|
||||
* 创建仓库Release
|
||||
POST
|
||||
https://api.atomgit.com/api/v5/repos/:owner/:repo/releases
|
||||
Request
|
||||
Path Parameters
|
||||
owner
|
||||
string
|
||||
required
|
||||
仓库所属空间地址(企业、组织或个人的地址path)
|
||||
|
||||
repo
|
||||
string
|
||||
required
|
||||
仓库路径
|
||||
|
||||
Query Parameters
|
||||
access_token
|
||||
string
|
||||
required
|
||||
用户授权码
|
||||
|
||||
application/json
|
||||
Body
|
||||
tag_name
|
||||
string
|
||||
required
|
||||
tag名称
|
||||
|
||||
name
|
||||
string
|
||||
required
|
||||
release名称
|
||||
|
||||
body
|
||||
string
|
||||
required
|
||||
release描述
|
||||
|
||||
target_commitish
|
||||
string
|
||||
分支名称或者commit SHA,如果tag不存在,需要新建tag则传入该参数,如果不传入该参数,则为默认分支的最新提交
|
||||
*/
|
||||
|
||||
// 创建release
|
||||
async function createRelease() {
|
||||
const response = await axios.request({
|
||||
method: 'POST',
|
||||
url: `https://api.atomgit.com/api/v5/repos/certd/certd/releases`,
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
params: {
|
||||
access_token: AtomgitAccessToken
|
||||
},
|
||||
data: {
|
||||
tag_name: `v${versionTitle}`,
|
||||
name: `v${versionTitle}`,
|
||||
body: content,
|
||||
target_commitish: 'v2'
|
||||
},
|
||||
}
|
||||
)
|
||||
console.log("createRelease success")
|
||||
return response.data
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Release附件上传地址
|
||||
GET
|
||||
https://api.atomgit.com/api/v5/repos/:owner/:repo/releases/:tag/upload_url
|
||||
Request
|
||||
Path Parameters
|
||||
owner
|
||||
string
|
||||
required
|
||||
仓库所属空间地址(企业、组织或个人的地址path)
|
||||
|
||||
repo
|
||||
string
|
||||
required
|
||||
仓库路径
|
||||
|
||||
tag
|
||||
string
|
||||
required
|
||||
tag名称
|
||||
|
||||
Query Parameters
|
||||
access_token
|
||||
string
|
||||
required
|
||||
用户授权码
|
||||
|
||||
file_name
|
||||
string
|
||||
required
|
||||
要上传的文件名称
|
||||
|
||||
Responses
|
||||
200
|
||||
Response Headers
|
||||
application/json
|
||||
Schema
|
||||
Example (auto)
|
||||
Schema
|
||||
url
|
||||
string
|
||||
required
|
||||
上传的地址,使用put请求
|
||||
|
||||
headers
|
||||
object
|
||||
|
||||
*/
|
||||
async function getUploadUrl() {
|
||||
const response = await axios.request({
|
||||
method: 'GET',
|
||||
url: `https://api.atomgit.com/api/v5/repos/certd/certd/releases/v${versionTitle}/upload_url`,
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
params: {
|
||||
access_token: AtomgitAccessToken,
|
||||
file_name: `ui-${versionTitle}.zip`
|
||||
},
|
||||
}
|
||||
)
|
||||
console.log("getUploadUrl success:",response.data?.url)
|
||||
return response.data // {url: string, headers: any}
|
||||
}
|
||||
|
||||
async function uploadFile(url, headers, data) {
|
||||
const response = await axios.request({
|
||||
method: 'PUT',
|
||||
url,
|
||||
headers,
|
||||
data,
|
||||
}
|
||||
)
|
||||
return response.data
|
||||
}
|
||||
|
||||
async function publishToAtomgit() {
|
||||
const release = await createRelease()
|
||||
const uploadUrl = await getUploadUrl()
|
||||
const fileName = `ui.zip`
|
||||
const fileData = fs.createReadStream(fileName)
|
||||
const contentLength = fs.statSync(fileName).size
|
||||
uploadUrl.headers['Content-Length'] = contentLength
|
||||
const response = await uploadFile(uploadUrl.url, uploadUrl.headers, fileData)
|
||||
console.log("uploadFile success:")
|
||||
console.log("publishToAtomgit success")
|
||||
}
|
||||
|
||||
publishToAtomgit()
|
||||
@@ -0,0 +1,92 @@
|
||||
|
||||
import fs from 'fs'
|
||||
import childProcess from 'child_process';
|
||||
import { join } from "path";
|
||||
function check(){
|
||||
const gitAdd = fs.readFileSync("./node_modules/@lerna-lite/version/dist/lib/git-add.js","utf-8")
|
||||
if(gitAdd.indexOf("('git', ['add', '.']") > -1){
|
||||
console.log("git-add 已经修改过了")
|
||||
}else{
|
||||
console.error("git-add 没有修改过")
|
||||
throw new Error("git-add 还没修改过")
|
||||
}
|
||||
|
||||
//GH_TOKEN
|
||||
console.log("检查 GH_TOKEN")
|
||||
if(!process.env.GH_TOKEN){
|
||||
// setx /M GH_TOKEN xxxxx
|
||||
console.error("GH_TOKEN 未设置")
|
||||
throw new Error("GH_TOKEN 未设置")
|
||||
}
|
||||
}
|
||||
|
||||
function checkDist(){
|
||||
|
||||
function scanDir(root,excludes,stopDirName = "src"){
|
||||
//扫描文件,忽略node_modules
|
||||
const files = fs.readdirSync(root)
|
||||
const dirs = []
|
||||
for (const file of files) {
|
||||
if (excludes.includes(file)) {
|
||||
continue;
|
||||
}
|
||||
const filePath = join(root, file);
|
||||
|
||||
if (!fs.statSync(filePath).isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(file === stopDirName){
|
||||
dirs.push(filePath)
|
||||
continue;
|
||||
}
|
||||
|
||||
const res = scanDir(filePath,excludes,stopDirName)
|
||||
for (const item of res){
|
||||
dirs.push(item)
|
||||
}
|
||||
}
|
||||
|
||||
return dirs
|
||||
}
|
||||
|
||||
const srcDirs = scanDir("./packages",["node_modules",".git","dist","certd-client"],"src")
|
||||
|
||||
console.log("检查dist",srcDirs)
|
||||
|
||||
//检查包含 import xxx from "*/dist/*"
|
||||
const hasDistFiles = []
|
||||
for (const srcDir of srcDirs) {
|
||||
const files = fs.readdirSync(srcDir,{recursive:true})
|
||||
for (const file of files) {
|
||||
|
||||
const filePath = join(srcDir, file);
|
||||
if(!file.endsWith(".ts")){
|
||||
continue;
|
||||
}
|
||||
const content = fs.readFileSync(filePath,"utf-8")
|
||||
const lines = content.split("\n")
|
||||
for (const line of lines) {
|
||||
if( line.indexOf("@certd")>-1 && line.indexOf("dist") > -1){
|
||||
hasDistFiles.push({
|
||||
filepath:filePath,
|
||||
line: line
|
||||
})
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(hasDistFiles.length > 0){
|
||||
console.error("dist文件被引用")
|
||||
console.error(hasDistFiles)
|
||||
throw new Error("dist文件被引用")
|
||||
} else {
|
||||
console.log("dist检查通过 √")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
checkDist()
|
||||
check()
|
||||
@@ -0,0 +1,3 @@
|
||||
import fs from 'fs'
|
||||
const pkg = JSON.parse(fs.readFileSync('./packages/ui/certd-server/package.json'))
|
||||
console.log(pkg.version)
|
||||
Reference in New Issue
Block a user