UNPKG

@modern-js/module-tools-v2

Version:

The meta-framework suite designed from scratch for frontend-focused modern web development.

88 lines (87 loc) 3.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = void 0; 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 run = async (options, api) => { const { chalk } = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/utils'))); const { resolvedBuildConfig, context, cmdOptions } = options; const runner = api.useHookRunners(); if (resolvedBuildConfig.length !== 0) { const { buildSuccessText } = await Promise.resolve().then(() => _interopRequireWildcard(require("../constants/log"))); // eslint-disable-next-line no-console !cmdOptions.watch && console.time(buildSuccessText); const { runBuildTask } = await Promise.resolve().then(() => _interopRequireWildcard(require("./build"))); const { default: pMap } = await Promise.resolve().then(() => _interopRequireWildcard(require("../../compiled/p-map"))); const { clearBuildConfigPaths, clearDtsTemp } = await Promise.resolve().then(() => _interopRequireWildcard(require("./clear"))); await clearBuildConfigPaths(resolvedBuildConfig); await clearDtsTemp(); const { getSourceConfig } = await Promise.resolve().then(() => _interopRequireWildcard(require("../utils/source"))); const sourceConfig = await getSourceConfig(api, context); const { getStyleConfig } = await Promise.resolve().then(() => _interopRequireWildcard(require("../utils/style"))); const styleConfig = await getStyleConfig(api); if (cmdOptions.watch) { console.info(chalk.blue.underline('start build in watch mode...\n')); } try { await pMap(resolvedBuildConfig, async config => { await runner.beforeBuildTask({ config, options: cmdOptions }); await runBuildTask({ buildConfig: config, sourceConfig, buildCmdOptions: cmdOptions, context, styleConfig }, api); await runner.afterBuildTask({ status: 'success', config }); }); // eslint-disable-next-line no-console !cmdOptions.watch && console.timeEnd(buildSuccessText); } catch (e) { const { isInternalError, ModuleBuildError } = await Promise.resolve().then(() => _interopRequireWildcard(require("../error"))); if (isInternalError(e)) { throw new ModuleBuildError(e); } else { throw e; } } } else { console.warn(chalk.yellow(`No build configuration found! Please configure \`buildConfig\` or \`buildPreset\``)); } await runner.afterBuild({ status: 'success', config: resolvedBuildConfig }); }; exports.run = run; //# sourceMappingURL=index.js.map