diff --git a/tasks/build.ts b/tasks/build.ts index 3f54d64..8a05b0c 100644 --- a/tasks/build.ts +++ b/tasks/build.ts @@ -9,11 +9,7 @@ const sass = require('node-sass') const sassPluginNodeImport = require('node-sass-package-importer') const typescript = require('typescript') -async function build_manifest() { - const manifest = JSON.parse(await fs.readFileSync('src/manifest.json')) - - manifest['version'] = process.env.npm_package_version - +function getDomains() { // because nodejs is nodejs, the simple commented out code below cannot be used. // thus, the following bloated regexes must be used /*const manifestMatches = [] @@ -24,7 +20,7 @@ async function build_manifest() { } manifest['content_scripts']['matches'] = manifestMatches*/ - manifest['content_scripts']['matches'] = [] + let domains = [] const matchesRegex = new RegExp(/export\s+const\s+matches\s+=\s+(?\[.*?])/gms) const matchesClassesRegex = new RegExp(/new\s+(?\w+)\(\)/gms) @@ -47,19 +43,39 @@ async function build_manifest() { if (mm.groups.domains !== undefined) { const matches = [] - for (const domain of JSON.parse(mm.groups.domains.replaceAll('\'', '"', -1))) { - matches.push(`*://*.${domain}/*`) + for (const domain of JSON.parse(mm.groups.domains.replace(/'/g, '"', -1))) { + matches.push(domain) } - manifest['content_scripts'][0]['matches'] = manifest['content_scripts'][0]['matches'].concat(matches) + domains = domains.concat(matches) } } } } - await fs.writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2)) + return domains } -async function build_misc() { +async function buildManifest() { + const manifest = JSON.parse(fs.readFileSync('src/manifest.json')) + + manifest['version'] = process.env.npm_package_version + + manifest['content_scripts']['matches'] = getDomains().map((domain) => {`*://*.${domain}/*`}) + + fs.writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2)) +} + +async function buildReadme() { + let readme = fs.readFileSync('README.md') + + readme = readme.toString().replace(/