Initial commit
This commit is contained in:
commit
ac40ec106d
33 changed files with 1651 additions and 0 deletions
72
tools/parse.ts
Normal file
72
tools/parse.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
const appConfig = JSON.parse(fs.readFileSync("./app.config.json", "utf8"));
|
||||
const DEPLOY_TARGET = "./dist/";
|
||||
|
||||
function findCssFileNames(source: string): string[] {
|
||||
let files: string[] = [];
|
||||
const dir = fs.readdirSync(source);
|
||||
dir.forEach(function (file: string) {
|
||||
const sourceFile = path.join(source, file);
|
||||
const stat = fs.lstatSync(sourceFile);
|
||||
if (stat.isDirectory()) {
|
||||
files = files.concat(findCssFileNames(sourceFile));
|
||||
} else {
|
||||
if (path.extname(sourceFile) == ".css") {
|
||||
files.push(file);
|
||||
}
|
||||
}
|
||||
});
|
||||
return files;
|
||||
}
|
||||
|
||||
function findHtmlFilesRecursive(source: string): string[] {
|
||||
let files: string[] = [];
|
||||
const dir = fs.readdirSync(source);
|
||||
dir.forEach(function (file: string) {
|
||||
const sourceFile = path.join(source, file);
|
||||
const stat = fs.lstatSync(sourceFile);
|
||||
if (stat.isDirectory()) {
|
||||
files = files.concat(findHtmlFilesRecursive(sourceFile));
|
||||
} else {
|
||||
if (path.extname(sourceFile) == ".html") {
|
||||
files.push(sourceFile);
|
||||
}
|
||||
}
|
||||
});
|
||||
return files;
|
||||
}
|
||||
|
||||
function replaceKeywordsInHtmlFile(file: string) {
|
||||
let content = fs.readFileSync(file, "utf8");
|
||||
const pairs: { key: string; value: string }[] = appConfig.htmlTemplatePairs;
|
||||
pairs.forEach(function (pair: { key: string; value: string }) {
|
||||
//@ts-ignore
|
||||
content = content.replaceAll(pair.key, pair.value);
|
||||
});
|
||||
file = file.replace("public\\", DEPLOY_TARGET);
|
||||
fs.writeFileSync(file, content);
|
||||
}
|
||||
|
||||
function buildHtmlFiles(source: string) {
|
||||
const files = findHtmlFilesRecursive(source);
|
||||
files.forEach(function (file: string) {
|
||||
replaceKeywordsInHtmlFile(file);
|
||||
});
|
||||
}
|
||||
|
||||
findCssFileNames(DEPLOY_TARGET).forEach((file: string) => {
|
||||
const files = findHtmlFilesRecursive(DEPLOY_TARGET);
|
||||
files.forEach(function (htmlFile: string) {
|
||||
let content = fs.readFileSync(htmlFile, "utf8");
|
||||
content = content.replace(
|
||||
"</head>",
|
||||
`<link rel="stylesheet" href="./assets/${file}">\n</head>`
|
||||
);
|
||||
fs.writeFileSync(htmlFile, content);
|
||||
});
|
||||
});
|
||||
|
||||
buildHtmlFiles(DEPLOY_TARGET);
|
||||
|
||||
console.log("Parsed Files: ", findHtmlFilesRecursive(DEPLOY_TARGET));
|
23
tools/syncConfig.ts
Normal file
23
tools/syncConfig.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
// @ts-ignore
|
||||
const fs = require('fs');
|
||||
|
||||
const appConfig = JSON.parse(fs.readFileSync('./app.config.json', 'utf8'));
|
||||
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||||
const manifestJson = JSON.parse(fs.readFileSync('./public/manifest.json', 'utf8'));
|
||||
|
||||
pkg.version = appConfig.AppData.version;
|
||||
pkg.name = appConfig.AppData.id;
|
||||
pkg.authors = appConfig.AppData.authors;
|
||||
pkg.description = appConfig.AppData.description;
|
||||
pkg.homepage = appConfig.AppData.homepage;
|
||||
pkg.license = appConfig.AppData.license;
|
||||
pkg.repository = appConfig.AppData.repository;
|
||||
pkg.bugs = appConfig.AppData.bugs;
|
||||
|
||||
manifestJson.version = appConfig.AppData.version;
|
||||
manifestJson.name = appConfig.AppData.name;
|
||||
manifestJson.description = appConfig.AppData.description;
|
||||
manifestJson.homepage_url = appConfig.AppData.homepage;
|
||||
|
||||
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
|
||||
fs.writeFileSync('./public/manifest.json', JSON.stringify(manifestJson, null, 2));
|
46
tools/v2.ts
Normal file
46
tools/v2.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
// @ts-ignore
|
||||
const fs = require('fs');
|
||||
|
||||
const manifest = JSON.parse(fs.readFileSync('./dist/manifest.json', 'utf8'));
|
||||
|
||||
manifest.manifest_version = 2
|
||||
|
||||
manifest.background.scripts = []
|
||||
|
||||
manifest.background.scripts.push(manifest.background.service_worker)
|
||||
delete manifest.background.type
|
||||
delete manifest.background.service_worker
|
||||
manifest.background.persistent = true
|
||||
if (manifest.host_permissions) {
|
||||
manifest.permissions.push(manifest.host_permissions)
|
||||
}
|
||||
if (manifest.optional_host_permissions) {
|
||||
manifest.permissions.push(manifest.optional_host_permissions)
|
||||
}
|
||||
delete manifest.host_permissions
|
||||
delete manifest.optional_host_permissions
|
||||
|
||||
let newContentSecurityPolicy = ""
|
||||
|
||||
try {
|
||||
for (const policy of manifest.content_security_policy) {
|
||||
newContentSecurityPolicy += policy.key + "'" + policy.value + "'" + " "
|
||||
}
|
||||
} catch (e) {
|
||||
newContentSecurityPolicy = "default-src 'self'"
|
||||
}
|
||||
|
||||
manifest.content_security_policy = newContentSecurityPolicy
|
||||
|
||||
try {
|
||||
manifest.web_accessible_resources = manifest.web_accessible_resources.resources
|
||||
} catch (e) {
|
||||
manifest.web_accessible_resources = []
|
||||
}
|
||||
|
||||
if (manifest.action) {
|
||||
manifest.browser_action = manifest.action
|
||||
}
|
||||
delete manifest.action
|
||||
|
||||
fs.writeFileSync('./dist/manifest.json', JSON.stringify(manifest, null, 2));
|
Loading…
Add table
Add a link
Reference in a new issue