Added cli option to build extension for other browsers

master
Guusvanmeerveld 3 years ago
parent 414fefd0fa
commit c245c62e0b

@ -2,13 +2,14 @@
"dependencies": { "dependencies": {
"chalk": "^4.1.1", "chalk": "^4.1.1",
"chokidar": "^3.5.2", "chokidar": "^3.5.2",
"commander": "^8.1.0",
"fs-extra": "^10.0.0", "fs-extra": "^10.0.0",
"minify": "^7.0.2", "minify": "^7.0.2",
"prettier": "^2.3.2", "prettier": "^2.3.2",
"sass": "^1.36.0" "sass": "^1.36.0"
}, },
"scripts": { "scripts": {
"dev": "node src/builder/watch ", "dev": "node src/builder/watch",
"build": "node src/builder", "build": "node src/builder",
"prettify": "prettier --write src" "prettify": "prettier --write src"
}, },

@ -61,7 +61,7 @@ const fileBuilder = async (file, outPath, fileType) => {
const path = file.split('/'); const path = file.split('/');
const fileName = path[path.length - 1]; const fileName = path[path.length - 1];
const withPaths = replacePaths(compiled); const withPaths = replaceFileContents(compiled);
await fs.ensureDir(outPath); await fs.ensureDir(outPath);
@ -101,7 +101,7 @@ const compile = async (file, fileType) => {
* @param {string} data - The data that needs its paths replaced * @param {string} data - The data that needs its paths replaced
* @returns * @returns
*/ */
const replacePaths = (data) => { const replaceFileContents = (data) => {
if (config.paths) { if (config.paths) {
Object.keys(config.paths).forEach((key) => { Object.keys(config.paths).forEach((key) => {
data = data.replace(new RegExp(key, 'g'), '/' + config.paths[key]); data = data.replace(new RegExp(key, 'g'), '/' + config.paths[key]);
@ -111,6 +111,10 @@ const replacePaths = (data) => {
data = data.replace(new RegExp(sassExtension, 'g'), '.min.css'); data = data.replace(new RegExp(sassExtension, 'g'), '.min.css');
if (process.env.TARGET_BROWSER != 'chrome') {
data = data.replace(new RegExp('chrome.', 'g'), 'browser.')
}
return data; return data;
}; };

@ -1,13 +1,32 @@
const { join } = require('path'); const { join } = require('path');
const fs = require('fs-extra');
const { program } = require('commander');
const config = require(join(process.cwd(), 'builder.config.js')); const config = require(join(process.cwd(), 'builder.config.js'));
const validBrowsers = ['chrome', 'firefox', 'edge']
const srcDir = join(process.cwd(), config.root); const srcDir = join(process.cwd(), config.root);
const distDir = join(process.cwd(), config.out); const distDir = join(process.cwd(), config.out);
const { builder } = require('./builders'); const { builder } = require('./builders');
program
.option(`-t, --target <${validBrowsers.join(' | ')}>`, 'set the target browser')
program.parse(process.argv);
const options = program.opts();
const target = options.target.toLowerCase() || 'chrome'
if (!validBrowsers.includes(target)) {
console.log('Error: invalid target browser, please specify one of the following: ' + validBrowsers.join(', '));
process.exit();
}
process.env.TARGET_BROWSER = target;
if (config.interpreter) { if (config.interpreter) {
config.interpreter.forEach((interpreter) => { config.interpreter.forEach((interpreter) => {
const input = join(srcDir, interpreter.input); const input = join(srcDir, interpreter.input);

@ -205,6 +205,11 @@ commander@^4.1.1:
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068" resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"
integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA== integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==
commander@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-8.1.0.tgz#db36e3e66edf24ff591d639862c6ab2c52664362"
integrity sha512-mf45ldcuHSYShkplHHGKWb4TrmwQadxOn7v4WuhDJy0ZVoY5JFajaRDKD0PNe5qXzBX0rhovjTnP6Kz9LETcuA==
concat-map@0.0.1: concat-map@0.0.1:
version "0.0.1" version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"

Loading…
Cancel
Save