@modern-js/module-tools-v2
Version:
The meta-framework suite designed from scratch for frontend-focused modern web development.
107 lines (106 loc) • 7.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.upgradCommand = exports.newCommand = exports.devCommand = exports.buildCommand = void 0;
var _utils = require("@modern-js/utils");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const debug = (0, _utils.createDebugger)('module-tools');
const buildCommand = async (program, api) => {
const local = await Promise.resolve().then(() => _interopRequireWildcard(require("./locale")));
const {
defaultTsConfigPath
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./constants/dts")));
program.command('build').usage('[options]').description(local.i18n.t(local.localeKeys.command.build.describe)).option('-w, --watch', local.i18n.t(local.localeKeys.command.build.watch)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), defaultTsConfigPath).option('-p, --platform [platform...]', local.i18n.t(local.localeKeys.command.build.platform)).option('--no-dts', local.i18n.t(local.localeKeys.command.build.dts)).option('--no-clear', local.i18n.t(local.localeKeys.command.build.no_clear)).option('-c --config <config>', local.i18n.t(local.localeKeys.command.build.config)).action(async options => {
const {
initModuleContext
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./utils/context")));
const context = await initModuleContext(api);
if (options.platform) {
const {
buildPlatform
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./builder/platform")));
await buildPlatform(options, api, context);
return;
}
const runner = api.useHookRunners();
const {
normalizeBuildConfig
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./config/normalize")));
const resolvedBuildConfig = await normalizeBuildConfig(api, context, options);
debug('resolvedBuildConfig', resolvedBuildConfig);
await runner.beforeBuild({
config: resolvedBuildConfig,
options
});
const builder = await Promise.resolve().then(() => _interopRequireWildcard(require("./builder")));
await builder.run({
cmdOptions: options,
resolvedBuildConfig,
context
}, api);
});
};
exports.buildCommand = buildCommand;
const devCommand = async (program, api) => {
const local = await Promise.resolve().then(() => _interopRequireWildcard(require("./locale")));
const runner = api.useHookRunners();
const devToolMetas = await runner.registerDev();
await runner.beforeDev(devToolMetas);
const devProgram = program.command('dev').usage('[options]').description(local.i18n.t(local.localeKeys.command.dev.describe)).action(async (options = {}) => {
const {
initModuleContext
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./utils/context")));
const context = await initModuleContext(api);
const {
dev
} = await Promise.resolve().then(() => _interopRequireWildcard(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 {
initModuleContext
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./utils/context")));
const context = await initModuleContext(api);
await runner.beforeDevTask(meta);
await meta.action(options, {
isTsProject: context.isTsProject
});
});
}
}
};
exports.devCommand = devCommand;
const newCommand = async program => {
const local = await Promise.resolve().then(() => _interopRequireWildcard(require("./locale")));
program.command('new').usage('[options]').description(local.i18n.t(local.localeKeys.command.new.describe)).option('-d, --debug', local.i18n.t(local.localeKeys.command.new.debug), false).option('-c, --config <config>', local.i18n.t(local.localeKeys.command.new.config)).option('--dist-tag <tag>', local.i18n.t(local.localeKeys.command.new.distTag)).option('--registry', local.i18n.t(local.localeKeys.command.new.registry)).action(async options => {
const {
ModuleNewAction
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/new-action')));
const {
getLocaleLanguage
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./utils/language")));
const locale = getLocaleLanguage();
await ModuleNewAction(_objectSpread(_objectSpread({}, options), {}, {
locale
}));
});
};
exports.newCommand = newCommand;
const upgradCommand = async program => {
const {
defineCommand
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/upgrade')));
defineCommand(program.command('upgrade'));
};
exports.upgradCommand = upgradCommand;
//# sourceMappingURL=command.js.map