@ima/cli
Version:
IMA.js CLI tool to build, develop and work with IMA.js applications.
56 lines (55 loc) • 2.06 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.builder = exports.handler = exports.describe = exports.command = void 0;
const logger_1 = require("@ima/dev-utils/logger");
const webpack_1 = __importDefault(require("webpack"));
const cli_1 = require("../lib/cli");
const compiler_1 = require("../lib/compiler");
const languages_1 = require("../webpack/languages");
const utils_1 = require("../webpack/utils");
/**
* Builds ima application.
*
* @param {CliArgs} args
* @returns {Promise<void>}
*/
const build = async (args) => {
try {
// Do cleanup
await (0, utils_1.cleanup)(args);
// Load ima config
const imaConfig = await (0, utils_1.resolveImaConfig)(args);
// Run preProcess hook on IMA CLI Plugins
await (0, utils_1.runImaPluginsHook)(args, imaConfig, 'preProcess');
// Compile language files
logger_1.logger.info(`Compiling language files...`, { trackTime: true });
await (0, languages_1.compileLanguages)(imaConfig, args.rootDir);
logger_1.logger.endTracking();
// Generate webpack config
const config = await (0, utils_1.createWebpackConfig)(args, imaConfig);
logger_1.logger.info('Running webpack compiler...');
// Run webpack compiler
const compiler = (0, webpack_1.default)(config);
await (0, compiler_1.runCompiler)(compiler, args, imaConfig);
}
catch (error) {
(0, compiler_1.handleError)(error);
process.exit(1);
}
};
const CMD = 'build';
exports.command = CMD;
exports.describe = 'Build an application for production';
exports.handler = (0, cli_1.handlerFactory)(build);
exports.builder = {
...(0, cli_1.sharedArgsFactory)(CMD),
profile: {
desc: 'Turn on profiling support in production',
type: 'boolean',
default: false,
},
...(0, cli_1.resolveCliPluginArgs)(CMD),
};