UNPKG

cobolget

Version:
52 lines (51 loc) 2.27 kB
"use strict"; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.add = void 0; const api_1 = require("./api"); const path = require("path"); const fs = require("fs"); function add(dependency, version = '*', options) { return __awaiter(this, void 0, void 0, function* () { try { const manifestFile = path.join(process.cwd(), api_1.MANIFEST_NAME); // manifest exists? if (!fs.existsSync(manifestFile)) { console.log(`No manifest ${api_1.MANIFEST_NAME} found. Please run 'init' command.`); return; } let manifest = JSON.parse(fs.readFileSync(manifestFile).toString()); // package exists? yield api_1.getPackage(dependency); if (options.debug) { manifest['dependencies-debug'][dependency] = version; } else { manifest['dependencies'][dependency] = version; } // manifest valid? manifest = JSON.stringify(manifest, null, 2); yield api_1.validateManifest(manifest); // save fs.writeFileSync(manifestFile, manifest); if (options.debug) { console.log(`Debug dependency '${dependency}' has been added to the manifest.`); } else { console.log(`Dependency '${dependency}' has been added to the manifest.`); } } catch (e) { console.log(`An error occurred: ${e}.`); } }); } exports.add = add;