-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
217 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
"'": "'", | ||
// " ": " ", | ||
}; | ||
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') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "@/updater" | ||
export * from "@/updater" | ||
export * from "@/utils/mail-sender" |
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.