mirror of
https://github.com/JosunLP/BrowserExtensionTemplate.git
synced 2025-06-21 18:11:08 +00:00
adding more detailed conversion to v2
This commit is contained in:
parent
6a15036e29
commit
56b73f1baa
5 changed files with 58 additions and 19 deletions
|
@ -19,5 +19,11 @@
|
||||||
"email": "info@josunlp.de"
|
"email": "info@josunlp.de"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"htmlTemplatePairs": [
|
||||||
|
{
|
||||||
|
"key": "{{BET}}",
|
||||||
|
"value": "Browser Extension Template"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
|
@ -8,7 +8,9 @@
|
||||||
"deploy-v2": "npm run deploy-v3 && node ./tools/v2.js",
|
"deploy-v2": "npm run deploy-v3 && node ./tools/v2.js",
|
||||||
"build-js": "tsc -p tsconfig.json",
|
"build-js": "tsc -p tsconfig.json",
|
||||||
"build-css": "sass ./src/sass/:./dist/css/",
|
"build-css": "sass ./src/sass/:./dist/css/",
|
||||||
"build-tooling": "tsc ./tools/v2.ts --target esnext --module esnext && tsc ./tools/syncConfig.ts --target esnext --module esnext && tsc ./tools/deploy.ts --target esnext --module esnext",
|
"build-tooling": "tsc ./tools/v2.ts --target esnext --module esnext --lib ESNext && tsc ./tools/syncConfig.ts --target esnext --module esnext --lib ESNext && tsc ./tools/deploy.ts --target esnext --module esnext --lib ESNext",
|
||||||
|
"watch-ts": "tsc -w -p tsconfig.json",
|
||||||
|
"watch-sass": "sass --watch ./src/sass/:./dist/css/",
|
||||||
"sync": "npm run build-tooling && node ./tools/syncConfig.js"
|
"sync": "npm run build-tooling && node ./tools/syncConfig.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -6,7 +6,7 @@ var DEPLOY_TARGET = "./dist/";
|
||||||
|
|
||||||
function deleteFolderRecursive(path: string) {
|
function deleteFolderRecursive(path: string) {
|
||||||
if (fs.existsSync(path)) {
|
if (fs.existsSync(path)) {
|
||||||
fs.readdirSync(path).forEach(function(file: string) {
|
fs.readdirSync(path).forEach(function (file: string) {
|
||||||
var curPath = path + "/" + file;
|
var curPath = path + "/" + file;
|
||||||
if (fs.lstatSync(curPath).isDirectory()) {
|
if (fs.lstatSync(curPath).isDirectory()) {
|
||||||
deleteFolderRecursive(curPath);
|
deleteFolderRecursive(curPath);
|
||||||
|
@ -21,7 +21,7 @@ function deleteFolderRecursive(path: string) {
|
||||||
function findHtmlFilesRecursive(source: string): string[] {
|
function findHtmlFilesRecursive(source: string): string[] {
|
||||||
var files: string[] = [];
|
var files: string[] = [];
|
||||||
var dir = fs.readdirSync(source);
|
var dir = fs.readdirSync(source);
|
||||||
dir.forEach(function(file: any) {
|
dir.forEach(function (file: any) {
|
||||||
var sourceFile = path.join(source, file);
|
var sourceFile = path.join(source, file);
|
||||||
var stat = fs.lstatSync(sourceFile);
|
var stat = fs.lstatSync(sourceFile);
|
||||||
if (stat.isDirectory()) {
|
if (stat.isDirectory()) {
|
||||||
|
@ -35,33 +35,35 @@ function findHtmlFilesRecursive(source: string): string[] {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceKeywordsInHtmlFile(file: string, keywords: string[], values: string[]) {
|
function replaceKeywordsInHtmlFile(file: string) {
|
||||||
var content = fs.readFileSync(file, 'utf8');
|
var content = fs.readFileSync(file, 'utf8');
|
||||||
for (var i = 0; i < keywords.length; i++) {
|
let pairs = appConfig.htmlTemplatePairs;
|
||||||
content = content.replace(new RegExp(keywords[i], 'g'), values[i]);
|
pairs.forEach(function (pair: any) {
|
||||||
}
|
// @ts-ignore
|
||||||
|
content = content.replaceAll(pair.key, pair.value);
|
||||||
|
});
|
||||||
file = file.replace("public\\", DEPLOY_TARGET);
|
file = file.replace("public\\", DEPLOY_TARGET);
|
||||||
fs.writeFileSync(file, content);
|
fs.writeFileSync(file, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildHtmlFiles(source: string, keywords: string[], values: string[]) {
|
function buildHtmlFiles(source: string) {
|
||||||
var files = findHtmlFilesRecursive(source);
|
let files = findHtmlFilesRecursive(source);
|
||||||
files.forEach(function(file: string) {
|
files.forEach(function (file: string) {
|
||||||
replaceKeywordsInHtmlFile(file, keywords, values);
|
replaceKeywordsInHtmlFile(file);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function mkdirSync(path: string) {
|
function mkdirSync(path: string) {
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(path);
|
fs.mkdirSync(path);
|
||||||
} catch(e: any) {
|
} catch (e: any) {
|
||||||
if ( e.code != 'EEXIST' ) throw e;
|
if (e.code != 'EEXIST') throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyFiles(source: string, target: string) {
|
function copyFiles(source: string, target: string) {
|
||||||
var files = fs.readdirSync(source);
|
var files = fs.readdirSync(source);
|
||||||
files.forEach(function(file: any) {
|
files.forEach(function (file: any) {
|
||||||
var sourceFile = path.join(source, file);
|
var sourceFile = path.join(source, file);
|
||||||
var targetFile = path.join(target, file);
|
var targetFile = path.join(target, file);
|
||||||
var stat = fs.lstatSync(sourceFile);
|
var stat = fs.lstatSync(sourceFile);
|
||||||
|
@ -77,6 +79,6 @@ function copyFiles(source: string, target: string) {
|
||||||
deleteFolderRecursive(DEPLOY_TARGET);
|
deleteFolderRecursive(DEPLOY_TARGET);
|
||||||
mkdirSync(DEPLOY_TARGET);
|
mkdirSync(DEPLOY_TARGET);
|
||||||
copyFiles(DEPLOY_ENTRY, DEPLOY_TARGET);
|
copyFiles(DEPLOY_ENTRY, DEPLOY_TARGET);
|
||||||
buildHtmlFiles(DEPLOY_ENTRY, ["{{BET}}"], [appConfig.AppData.name]);
|
buildHtmlFiles(DEPLOY_ENTRY);
|
||||||
|
|
||||||
console.log("Deployed to " + DEPLOY_TARGET);
|
console.log("Deployed to " + DEPLOY_TARGET);
|
31
tools/v2.ts
31
tools/v2.ts
|
@ -2,6 +2,35 @@ import * as fs from 'fs';
|
||||||
|
|
||||||
const manifest = JSON.parse(fs.readFileSync('./dist/manifest.json', 'utf8'));
|
const manifest = JSON.parse(fs.readFileSync('./dist/manifest.json', 'utf8'));
|
||||||
|
|
||||||
manifest.manifest_version = 2;
|
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
|
||||||
|
manifest.permissions += manifest.host_permissions
|
||||||
|
manifest.permissions += 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 + " "
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
newContentSecurityPolicy = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest.content_security_policy = newContentSecurityPolicy
|
||||||
|
|
||||||
|
try {
|
||||||
|
manifest.web_accessible_resources = manifest.web_accessible_resources.resources
|
||||||
|
} catch (e) {
|
||||||
|
manifest.web_accessible_resources = []
|
||||||
|
}
|
||||||
|
|
||||||
fs.writeFileSync('./dist/manifest.json', JSON.stringify(manifest, null, 2));
|
fs.writeFileSync('./dist/manifest.json', JSON.stringify(manifest, null, 2));
|
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
/* Basic Options */
|
/* Basic Options */
|
||||||
// "incremental": true, /* Enable incremental compilation */
|
// "incremental": true, /* Enable incremental compilation */
|
||||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
|
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
|
||||||
"module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
"module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
// "lib": ["ESNext"], /* Specify library files to be included in the compilation. */
|
||||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
// "checkJs": true, /* Report errors in .js files. */
|
// "checkJs": true, /* Report errors in .js files. */
|
||||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
||||||
|
|
Loading…
Add table
Reference in a new issue