@modern-js/module-tools
Version:
Simple, powerful, high-performance modern npm package development solution.
102 lines (101 loc) • 5.7 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var command_exports = {};
__export(command_exports, {
buildCommand: () => buildCommand,
devCommand: () => devCommand,
newCommand: () => newCommand,
upgradeCommand: () => upgradeCommand
});
module.exports = __toCommonJS(command_exports);
var import_utils = require("@modern-js/utils");
var import_locale = require("./locale");
const initModuleContext = async (api) => {
const { isTypescript } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
const { appDirectory, srcDirectory } = api.useAppContext();
const isTsProject = isTypescript(appDirectory);
return {
isTsProject,
appDirectory,
srcDirectory
};
};
const buildCommand = async (program, api) => {
program.command("build").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.build.describe)).option("-w, --watch", import_locale.i18n.t(import_locale.localeKeys.command.build.watch), false).option("--tsconfig [tsconfig]", import_locale.i18n.t(import_locale.localeKeys.command.build.tsconfig)).option("-p, --platform [platform...]", import_locale.i18n.t(import_locale.localeKeys.command.build.platform)).option("--no-dts", import_locale.i18n.t(import_locale.localeKeys.command.build.dts)).option("--no-clear", import_locale.i18n.t(import_locale.localeKeys.command.build.noClear)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async (options) => {
const context = await initModuleContext(api);
const { build } = await Promise.resolve().then(() => __toESM(require("./build")));
await build(api, options, context);
});
};
const devCommand = async (program, api) => {
const runner = api.useHookRunners();
const devToolMetas = await runner.registerDev();
await runner.beforeDev(devToolMetas);
const devProgram = program.command("dev").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("--tsconfig [tsconfig]", import_locale.i18n.t(import_locale.localeKeys.command.dev.tsconfig)).option("-c, --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async (options) => {
const context = await initModuleContext(api);
const { dev } = await Promise.resolve().then(() => __toESM(require("./dev")));
await dev(options, devToolMetas, api, context);
});
for (const meta of devToolMetas) {
if (!meta.subCommands) {
continue;
}
for (const subCmd of meta.subCommands) {
devProgram.command(subCmd).action(async (options) => {
const context = await initModuleContext(api);
await runner.beforeDevTask(meta);
await meta.action(options, {
isTsProject: context.isTsProject
});
});
}
}
};
const newCommand = async (program) => {
program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("--config-file <configFile>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--lang <lang>", import_locale.i18n.t(import_locale.localeKeys.command.new.lang)).option("-c, --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.new.config)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option("--dist-tag <tag>", import_locale.i18n.t(import_locale.localeKeys.command.new.distTag)).option("--registry", import_locale.i18n.t(import_locale.localeKeys.command.new.registry)).option("--no-need-install", import_locale.i18n.t(import_locale.localeKeys.command.shared.noNeedInstall)).action(async (options) => {
const { getLocaleLanguage } = await Promise.resolve().then(() => __toESM(require("@modern-js/plugin-i18n/language-detector")));
const locale = getLocaleLanguage();
await (0, import_utils.newAction)({
...options,
locale: options.lang || locale
}, "module");
});
};
const upgradeCommand = async (program) => {
program.command("upgrade").allowUnknownOption().option("-h --help", "Show help").action(async () => {
await (0, import_utils.upgradeAction)();
});
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
buildCommand,
devCommand,
newCommand,
upgradeCommand
});