mirror of
https://github.com/JosunLP/BrowserExtensionTemplate.git
synced 2025-10-15 08:30:10 +00:00
feat: Implement ErrorBoundary class for global error handling
feat: Refactor Session class to use LocalStorageService for session management feat: Enhance BasicButton component with configuration options and event handling style: Update SASS variables to CSS custom properties for better theming support style: Modify app.sass to include Bootstrap with legacy import chore: Update settings.ts to handle session initialization and error notifications fix: Improve buttonType definition for better readability chore: Refactor parse.ts for cleaner file handling and keyword replacement chore: Enhance syncConfig.ts with TypeScript interfaces and async file operations chore: Update v2.ts to modify manifest.json for compatibility with manifest version 2 chore: Revise tsconfig.json for stricter type checking and improved module resolution chore: Refactor vite.config.ts for better build configuration and asset management
This commit is contained in:
parent
8f99895c88
commit
482151f980
24 changed files with 1321 additions and 418 deletions
108
tools/parse.ts
108
tools/parse.ts
|
@ -1,72 +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/";
|
||||
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;
|
||||
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;
|
||||
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);
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
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));
|
||||
console.log('Parsed Files: ', findHtmlFilesRecursive(DEPLOY_TARGET));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue