frontity
Version:
Frontity cli and entry point to other packages
37 lines (36 loc) • 1.63 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const dev_1 = __importDefault(require("../commands/dev"));
const utils_1 = require("../utils");
/**
* The dev CLI command, usually run with `npx frontity dev`.
*
* It takes args from the CLI and checks for the presence of environment
* variables. Then, it runs the dev command programatically.
*
* @param options - Defined in {@link DevOptions}.
*/
const dev = async ({ target = process.env.FRONTITY_DEV_TARGET || "module", port = process.env.FRONTITY_DEV_PORT || "3000", https = !!process.env.FRONTITY_DEV_HTTPS, production = !!process.env.FRONTITY_DEV_PRODUCTION, publicPath = process.env.FRONTITY_DEV_PUBLIC_PATH || "/static/", dontOpenBrowser = !!process.env.FRONTITY_DEV_DONT_OPEN_BROWSER, analyze = !!process.env.FRONTITY_DEV_ANALYZE, }) => {
// Check `target` parameter.
if (target && target !== "es5" && target !== "module") {
(0, utils_1.errorLogger)(new Error(`The target specified is invalid: "${target}". Use either "module" or "es5".`));
}
// Check `port` parameter.
if (port && Number.isNaN(parseInt(port, 10))) {
(0, utils_1.errorLogger)(new Error(`The port number specified is not valid: ${port}.`));
}
// Execute `dev` command.
(0, dev_1.default)({
target: target,
port: parseInt(port, 10),
production,
https,
publicPath,
dontOpenBrowser,
analyze,
});
};
exports.default = dev;