UNPKG

@levimc-lse/scaffold

Version:

A utility for assisting in the development of Legacy Script Engine plugins.

98 lines (97 loc) 4.08 kB
"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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Manifest = void 0; const Path = __importStar(require("path")); const File = __importStar(require("fs")); const ManifestFileNotFoundError_1 = require("./exceptions/ManifestFileNotFoundError"); const ManifestConfigurationMissingError_1 = require("./exceptions/ManifestConfigurationMissingError"); const NodeJsConfigurationMainError_1 = require("../nodejs/exceptions/NodeJsConfigurationMainError"); class Manifest { constructor(project) { this.project = project; } getPath() { return Path.join(this.project.getBuiltPath(), "manifest.json"); } getName() { if (!File.existsSync(this.getPath())) { throw new ManifestFileNotFoundError_1.ManifestFileNotFoundError(this.project.getBuiltPath()); } const manifest = JSON.parse(File.readFileSync(this.getPath(), "utf-8")); const name = manifest.name; if (!name) { throw new ManifestConfigurationMissingError_1.ManifestConfigurationMissingError(this.getPath(), "name"); } return name; } generate() { const nodeJsConfiguration = this.project.getNodeJsConfiguration(); const name = nodeJsConfiguration.getName().replace("/", "-").replace("@", ""); const version = nodeJsConfiguration.getVersion(); const absoluteEntry = Path.join(this.project.getPath(), nodeJsConfiguration.getMainEntry()); const relativeEntry = absoluteEntry.split(`${this.project.getBuiltPath()}\\`).join(""); if (relativeEntry === absoluteEntry) { throw new NodeJsConfigurationMainError_1.NodeJsConfigurationMainError(); } const manifest = { "name": name, "version": version, "type": "lse-nodejs", "entry": relativeEntry, "dependencies": [{ "name": "legacy-script-engine-nodejs" }] }; File.writeFileSync(this.getPath(), JSON.stringify(manifest, null, 2), "utf-8"); return `The manifest has been generated at ${this.getPath()}.`; } static isValid(filePath) { if (!File.existsSync(filePath)) { return false; } try { const data = File.readFileSync(filePath, "utf-8"); const manifest = JSON.parse(data); return manifest.hasOwnProperty("name") && manifest.hasOwnProperty("version") && manifest.hasOwnProperty("type") && manifest.hasOwnProperty("entry") && manifest.hasOwnProperty("dependencies"); } catch (error) { return false; } } } exports.Manifest = Manifest;