Skip to content

Commit

Permalink
update: send mail
Browse files Browse the repository at this point in the history
  • Loading branch information
Cnily03 committed Feb 6, 2024
1 parent 541e0d7 commit 2530ac1
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 64 deletions.
52 changes: 52 additions & 0 deletions compile-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const path = require('path')
const fs = require('fs')

let tsconfig_content = fs.readFileSync(path.resolve(__dirname, 'tsconfig.json'), 'utf8')
const tsconfig = eval(`(${tsconfig_content})`)
const rootDir = path.resolve(__dirname, tsconfig.compilerOptions.rootDir)
const outDir = path.resolve(__dirname, tsconfig.compilerOptions.outDir)

function escapeHtml(str) {
return str.replace(/[&<>"' \n]/g, function (tag) {
const lookup = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": "&apos;",
// " ": "&nbsp;",
};
return lookup[tag] || tag;
});
}

// create template output directory
const templateOutDir = path.resolve(outDir, 'template')
if (!fs.existsSync(templateOutDir)) {
fs.mkdirSync(templateOutDir, { recursive: true })
} else if (fs.statSync(templateOutDir).isFile()) {
throw new Error(`"${templateOutDir}" is a file, not a directory`)
}

// get EJS file under template
const templateRootDir = path.resolve(rootDir, 'template')
const templateFiles = fs.readdirSync(templateRootDir).filter(file => file.endsWith('.ejs'))
for (let fn of templateFiles) {
let content = fs.readFileSync(path.resolve(templateRootDir, fn), 'utf8')
// <style inject="css/spectre.min.css" escape="false"></style>
content = content.replace(/<([a-zA-Z\-]+)\s+inject="([^"]+)"\s+escape="([^"]+)"\s*><\/([a-zA-Z\-]+)>/g,
function (substring, tag, inject, escape, closeTag) {
let injectFilePath = path.resolve(templateRootDir, inject)
let injectContent = fs.readFileSync(injectFilePath, 'utf8')
escape = escape === 'true' || escape === '1'
if (escape) {
injectContent = escapeHtml(injectContent)
}
return `<${tag}>${injectContent}</${closeTag}>`
}
)

// write to outDir
let outFilePath = path.resolve(templateOutDir, fn)
fs.writeFileSync(outFilePath, content, 'utf8')
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"build": "rm -rf dist/* dist/.[!.]* dist/..?* && tsc && tsc-alias",
"compile-template": "node compile-template.js",
"build": "rm -rf dist/* dist/.[!.]* dist/..?* && tsc && tsc-alias && npm run compile-template",
"test": "npm run build && node test/index.js"
},
"keywords": [],
Expand All @@ -27,4 +28,4 @@
"tsc-alias": "^1.8.8",
"typescript": "^5.3.3"
}
}
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "@/updater"
export * from "@/updater"
export * from "@/utils/mail-sender"
1 change: 1 addition & 0 deletions src/template/css/spectre-exp.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/template/css/spectre-icons.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/template/css/spectre.min.css

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions src/template/qcloud.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.4.5/spectre.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.4.5/spectre-exp.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.4.5/spectre-icons.min.css">
<style inject="css/spectre.min.css" escape="false"></style>
<style>
body {
padding: 1rem;
Expand Down Expand Up @@ -45,35 +43,35 @@
<!-- ejs for -->
<% for (const info of data) { %>
<p>
<span class="line head"><strong>证书 #<%= info.old_cert_id.content %></strong></span>
<span class="line head"><strong>证书 #<%= info.old_cert_id.text %></strong></span>
<span class="line">
<span class="text-dark thread">新证书 ID</span>
<span class="text-<%= info.new_cert_id.color %>"><%= info.new_cert_id.content %></span>
<span class="text-<%= info.new_cert_id.color %>"><%= info.new_cert_id.text %></span>
</span>
<span class="line">
<span class="text-dark">原证书 ID</span>
<span class="text-<%= info.old_cert_id.color %>"><%= info.old_cert_id.content %></span>
<span class="text-<%= info.old_deleted.color %>"><%= info.old_deleted.content %></span>
<span class="text-<%= info.old_cert_id.color %>"><%= info.old_cert_id.text %></span>
<span class="text-<%= info.old_deleted.color %>"><%= info.old_deleted.text %></span>
</span>
<span class="line">
<span class="text-dark">主域名:</span>
<span class="text-<%= info.domain.color %>"><%= info.domain.content %></span>
<span class="text-<%= info.domain.color %>"><%= info.domain.text %></span>
</span>
<span class="line">
<span class="text-dark">SANS 域名:</span>
<span class="text-<%= info.sans.color %>"><%= info.sans.content %></span>
<span class="text-<%= info.sans.color %>"><%= info.sans.text %></span>
</span>
<span class="line">
<span class="text-dark">证书上传:</span>
<span class="text-<%= info.uploaded.color %>"><%= info.uploaded.content %></span>
<span class="text-<%= info.uploaded.color %>"><%= info.uploaded.text %></span>
</span>
<span class="line">
<span class="text-dark">资源迁移:</span>
<span class="text-<%= info.updated.color %>"><%= info.updated.content %></span>
<span class="text-<%= info.updated.color %>"><%= info.updated.text %></span>
</span>
<span class="line">
<span class="text-dark">备注:</span>
<span class="text-<%= info.comment.color %>"><%= info.comment.content %></span>
<span class="text-<%= info.comment.color %>"><%= info.comment.text %></span>
</span>
</p>
<% } %>
Expand Down
24 changes: 11 additions & 13 deletions src/template/qiniu.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.4.5/spectre.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.4.5/spectre-exp.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.4.5/spectre-icons.min.css">
<style inject="css/spectre.min.css" escape="false"></style>
<style>
body {
padding: 1rem;
Expand Down Expand Up @@ -45,35 +43,35 @@
<!-- ejs for -->
<% for (const info of data) { %>
<p>
<span class="line head"><strong>证书 #<%= info.old_cert_id.content %></strong></span>
<span class="line head"><strong>证书 #<%= info.old_cert_id.text %></strong></span>
<span class="line">
<span class="text-dark thread">新证书 ID</span>
<span class="text-<%= info.new_cert_id.color %>"><%= info.new_cert_id.content %></span>
<span class="text-<%= info.new_cert_id.color %>"><%= info.new_cert_id.text %></span>
</span>
<span class="line">
<span class="text-dark">原证书 ID</span>
<span class="text-<%= info.old_cert_id.color %>"><%= info.old_cert_id.content %></span>
<span class="text-<%= info.old_deleted.color %>"><%= info.old_deleted.content %></span>
<span class="text-<%= info.old_cert_id.color %>"><%= info.old_cert_id.text %></span>
<span class="text-<%= info.old_deleted.color %>"><%= info.old_deleted.text %></span>
</span>
<span class="line">
<span class="text-dark">主域名:</span>
<span class="text-<%= info.domain.color %>"><%= info.domain.content %></span>
<span class="text-<%= info.domain.color %>"><%= info.domain.text %></span>
</span>
<span class="line">
<span class="text-dark">SANS 域名:</span>
<span class="text-<%= info.sans.color %>"><%= info.sans.content %></span>
<span class="text-<%= info.sans.color %>"><%= info.sans.text %></span>
</span>
<span class="line">
<span class="text-dark">证书上传:</span>
<span class="text-<%= info.uploaded.color %>"><%= info.uploaded.content %></span>
<span class="text-<%= info.uploaded.color %>"><%= info.uploaded.text %></span>
</span>
<span class="line">
<span class="text-dark">资源迁移</span>
<span class="text-<%= info.updated.color %>"><%= info.updated.content %></span>
<span class="text-dark">CDN 证书更新</span>
<span class="text-<%= info.cdn_updated.color %>"><%= info.cdn_updated.text %></span>
</span>
<span class="line">
<span class="text-dark">备注:</span>
<span class="text-<%= info.comment.color %>"><%= info.comment.content %></span>
<span class="text-<%= info.comment.color %>"><%= info.comment.text %></span>
</span>
</p>
<% } %>
Expand Down
Loading

0 comments on commit 2530ac1

Please sign in to comment.