UNPKG

@ma3-pro-plugins/ma3-ts-plugin-builder

Version:
94 lines 3.89 kB
#! /usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /** * CLI * ===================== * Command Line Interface * * @contributors: Erez Makavy [@hepiyellow] <hepi@ma3-pro-plugins.com> * * @license: MIT License * */ const builder_1 = require("../builder/builder"); const logger_1 = __importDefault(require("../utils/logger")); const fs = __importStar(require("node:fs")); const path = __importStar(require("path")); const BUILD_CONFIG_FILE_NAME = "buildconfig.json"; const MA_CONFIG_FILE_NAME = "maconfig.json"; (() => __awaiter(void 0, void 0, void 0, function* () { const scriptArgs = { pluginFolderPath: "./", isDev: process.argv[2] === "dev", maTargetVersion: "1.8", }; const maconfigJson = parseConfigFile(path.join(scriptArgs.pluginFolderPath, MA_CONFIG_FILE_NAME)); const buildconfigJson = parseConfigFile(path.join(scriptArgs.pluginFolderPath, BUILD_CONFIG_FILE_NAME)); if (!validateBuildConfig(buildconfigJson)) { return; } const builder = (0, builder_1.Builder)({ maconfig: maconfigJson, buildConfig: Object.assign(Object.assign({}, buildconfigJson), scriptArgs), }); yield builder.build(); }))(); function validateBuildConfig(config) { if (!isNonEmptyString(config.maInstallPath)) { logger_1.default.error(`${BUILD_CONFIG_FILE_NAME}: should include a non-empty "maInstallPath" property `); return false; } if (!fs.existsSync(config.maInstallPath)) { logger_1.default.error(`${BUILD_CONFIG_FILE_NAME}: includes "maInstallPath=${config.maInstallPath}, but this path does not exist"`); return false; } return true; } function parseConfigFile(filePath) { try { return JSON.parse(fs.readFileSync(filePath).toString()); } catch (err) { logger_1.default.error(`Could not parse JSON config file: ${filePath}`); } } function isNonEmptyString(s) { return s !== undefined && s !== ""; } //# sourceMappingURL=cli.js.map