extension
Version:
Create cross-browser extensions with no build configuration.
151 lines (139 loc) • 13 kB
JavaScript
#!/usr/bin/env node
"use strict";
var __webpack_require__ = {};
(()=>{
__webpack_require__.n = (module)=>{
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
__webpack_require__.d(getter, {
a: getter
});
return getter;
};
})();
(()=>{
__webpack_require__.d = (exports1, definition)=>{
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
get: definition[key]
});
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
var __webpack_exports__ = {};
const external_commander_namespaceObject = require("commander");
const external_extension_create_namespaceObject = require("extension-create");
const external_extension_develop_namespaceObject = require("extension-develop");
const external_pintor_namespaceObject = require("pintor");
var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_namespaceObject);
function updateFailed(err) {
return "\uD83E\uDDE9\n" + external_pintor_default().red(`Failed to check for updates: ${err.message}`);
}
function checkUpdates(packageJson, update) {
return `\u{1F9E9}\n${external_pintor_default().yellow('Notice:')} A new version of ${external_pintor_default().green('Extension.js')} is available!\nYou are currently using version ${external_pintor_default().yellow(packageJson.version)}.\nThe latest stable version is ${external_pintor_default().yellow(update.latest)}.\nPlease update to the latest version to enjoy new features and improvements.\n`;
}
function programHelp() {
return `\u{1F9E9}
${external_pintor_default().underline('Help center for the Extension.js program')}
${external_pintor_default().yellow('Usage:')} extension [command] [options]
${external_pintor_default().yellow('Note:')} If you are looking for a specific list of options,
all high-level commands offer their own \`--help\` file with
information about usage and a list of command flags available.
For example:
${external_pintor_default().green('extension create --help')}
outputs information about the "create" command.
Options available:
${external_pintor_default().green('extension create <extension-name>')}
Creates a new extension from a template. The "create" command
is optional and can be omitted.
${external_pintor_default().green('extension dev <extension-path>')}
Starts a new browser instance in development mode, with the target
extension loaded and auto-reloaded based on file changes.
${external_pintor_default().green('extension start <extension-path>')}
Starts a new browser instance in production mode, with the target
extension compiled based on the browser choice.
${external_pintor_default().green('extension build <extension-path>')}
Builds the target extension with browser defaults, ready for packaging.
${external_pintor_default().green('extension --help')}
This command ;) Outputs a help file with key command options.
${external_pintor_default().yellow('Feels something is wrong? Help by reporting a bug:')}
${external_pintor_default().underline('https://github.com/cezaraugusto/extension/issues/new')}
`;
}
const external_update_check_namespaceObject = require("update-check");
var external_update_check_default = /*#__PURE__*/ __webpack_require__.n(external_update_check_namespaceObject);
function isStableVersion(version) {
return !/[a-zA-Z]/.test(version);
}
async function check_updates_checkUpdates(packageJson) {
let update = null;
try {
update = await external_update_check_default()(packageJson);
} catch (err) {
if ('development' === process.env.EXTENSION_ENV) console.error(updateFailed(err));
}
if (update && isStableVersion(update.latest)) console.log(checkUpdates(packageJson, update));
}
var package_namespaceObject = JSON.parse('{"license":"MIT","repository":{"type":"git","url":"https://github.com/extension-js/extension.js.git","directory":"programs/cli"},"engines":{"node":">=18"},"exports":{".":{"types":"./dist/cli.d.ts","import":"./dist/cli.js","require":"./dist/cli.js"}},"main":"./dist/cli.js","types":"./dist/cli.d.ts","files":["dist","types"],"bin":{"extension":"./dist/cli.js"},"name":"extension","version":"2.0.0-rc.38","description":"Create cross-browser extensions with no build configuration.","author":{"name":"Cezar Augusto","email":"boss@cezaraugusto.net","url":"https://cezaraugusto.com"},"scripts":{"watch":"rslib build --watch","compile:types":"bash install_scripts.sh","compile:cli":"rslib build","compile":"pnpm compile:cli && pnpm compile:types","clean":"rm -rf dist","test":"echo \\"Note: no test specified\\" && exit 0","test:cli":"vitest run"},"keywords":["zero-config","build","develop","browser","extension","chrome extension","edge extension","firefox extension","safari extension","web","react","typescript"],"dependencies":{"@types/chrome":"^0.0.287","@types/node":"^22.10.1","@types/react":"^19.0.1","@types/react-dom":"^19.0.1","@types/webextension-polyfill":"0.12.3","commander":"^12.1.0","extension-create":"workspace:*","extension-develop":"workspace:*","pintor":"0.3.0","semver":"^7.6.3","update-check":"^1.5.4","webextension-polyfill":"^0.12.0"},"devDependencies":{"@rslib/core":"^0.6.9","@types/mock-fs":"^4.13.4","@types/semver":"^7.5.8","mock-fs":"^5.4.1","tsconfig":"*","typescript":"5.7.2","vitest":"3.2.2"}}');
check_updates_checkUpdates(package_namespaceObject);
const extensionJs = external_commander_namespaceObject.program;
const vendors = (browser)=>'all' === browser ? 'chrome,edge,firefox'.split(',') : browser.split(',');
extensionJs.name(package_namespaceObject.name).description(package_namespaceObject.description).version(package_namespaceObject.version).addHelpText('after', programHelp());
extensionJs.command('create').arguments('<project-name|project-path>').usage('create <project-name|project-path> [options]').description('Creates a new extension.').option('-t, --template <template-name>', 'specify a template for the created project').option('--install', 'whether or not to install the dependencies after creating the project').action(async function(pathOrRemoteUrl, { template, install }) {
await (0, external_extension_create_namespaceObject.extensionCreate)(pathOrRemoteUrl, {
template,
install,
cliVersion: package_namespaceObject.version
});
});
extensionJs.command('dev').arguments('[project-path|remote-url]').usage('dev [project-path|remote-url] [options]').description('Starts the development server (development mode)').option('--profile <path-to-file | boolean>', 'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile').option('--browser <chrome | edge | firefox>', 'specify a browser to preview your extension in production mode. Defaults to `chrome`').option('--chromium-binary <path-to-binary>', 'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default').option('--gecko-binary <path-to-binary>', 'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default').option('--polyfill [boolean]', 'whether or not to apply the cross-browser polyfill. Defaults to `false`').option('--open [boolean]', 'whether or not to open the browser automatically. Defaults to `true`').option('--starting-url <url>', 'specify the starting URL for the browser. Defaults to `undefined`').option('--port <port>', 'specify the port to use for the development server. Defaults to `8080`').action(async function(pathOrRemoteUrl, { browser = 'chrome', ...devOptions }) {
for (const vendor of vendors(browser)){
var _devOptions_polyfill;
await (0, external_extension_develop_namespaceObject.extensionDev)(pathOrRemoteUrl, {
...devOptions,
profile: devOptions.profile,
browser: vendor,
chromiumBinary: devOptions.chromiumBinary,
geckoBinary: devOptions.geckoBinary,
polyfill: (null == (_devOptions_polyfill = devOptions.polyfill) ? void 0 : _devOptions_polyfill.toString()) !== 'false',
open: devOptions.open,
startingUrl: devOptions.startingUrl
});
}
});
extensionJs.command('start').arguments('[project-path|remote-url]').usage('start [project-path|remote-url] [options]').description('Starts the development server (production mode)').option('--profile <path-to-file | boolean>', 'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile').option('--browser <chrome | edge | firefox>', 'specify a browser to preview your extension in production mode. Defaults to `chrome`').option('--polyfill [boolean]', 'whether or not to apply the cross-browser polyfill. Defaults to `true`').option('--chromium-binary <path-to-binary>', 'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default').option('--gecko-binary <path-to-binary>', 'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default').option('--starting-url <url>', 'specify the starting URL for the browser. Defaults to `undefined`').option('--port <port>', 'specify the port to use for the development server. Defaults to `8080`').action(async function(pathOrRemoteUrl, { browser = 'chrome', ...startOptions }) {
for (const vendor of vendors(browser))await (0, external_extension_develop_namespaceObject.extensionStart)(pathOrRemoteUrl, {
mode: 'production',
profile: startOptions.profile,
browser: vendor,
chromiumBinary: startOptions.chromiumBinary,
geckoBinary: startOptions.geckoBinary,
startingUrl: startOptions.startingUrl
});
});
extensionJs.command('preview').arguments('[project-name]').usage('preview [path-to-remote-extension] [options]').description('Preview the extension in production mode').option('--profile <path-to-file | boolean>', 'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile').option('--browser <chrome | edge | firefox>', 'specify a browser to preview your extension in production mode. Defaults to `chrome`').option('--chromium-binary <path-to-binary>', 'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default').option('--gecko-binary <path-to-binary>', 'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default').option('--starting-url <url>', 'specify the starting URL for the browser. Defaults to `undefined`').option('--port <port>', 'specify the port to use for the development server. Defaults to `8080`').action(async function(pathOrRemoteUrl, { browser = 'chrome', ...previewOptions }) {
for (const vendor of vendors(browser))await (0, external_extension_develop_namespaceObject.extensionPreview)(pathOrRemoteUrl, {
mode: 'production',
profile: previewOptions.profile,
browser: vendor,
chromiumBinary: previewOptions.chromiumBinary,
geckoBinary: previewOptions.geckoBinary,
startingUrl: previewOptions.startingUrl
});
});
extensionJs.command('build').arguments('[project-name]').usage('build [path-to-remote-extension] [options]').description('Builds the extension for production').option('--browser <chrome | edge | firefox>', 'specify a browser to preview your extension in production mode. Defaults to `chrome`').option('--polyfill [boolean]', 'whether or not to apply the cross-browser polyfill. Defaults to `false`').option('--zip [boolean]', 'whether or not to compress the extension into a ZIP file. Defaults to `false`').option('--zip-source [boolean]', 'whether or not to include the source files in the ZIP file. Defaults to `false`').option('--zip-filename <string>', 'specify the name of the ZIP file. Defaults to the extension name and version').option('--silent [boolean]', 'whether or not to open the browser automatically. Defaults to `false`').action(async function(pathOrRemoteUrl, { browser = 'chrome', ...buildOptions }) {
for (const vendor of vendors(browser))await (0, external_extension_develop_namespaceObject.extensionBuild)(pathOrRemoteUrl, {
browser: vendor,
polyfill: buildOptions.polyfill,
zip: buildOptions.zip,
zipSource: buildOptions.zipSource,
zipFilename: buildOptions.zipFilename,
silent: buildOptions.silent
});
});
extensionJs.parse();
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
value: true
});