lambdaorm-cli
Version:
The lambdaorm command line interface
64 lines • 2.67 kB
JavaScript
;
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 });
exports.OrmCliH3lp = void 0;
const lambdaorm_1 = require("lambdaorm");
const path_1 = __importDefault(require("path"));
class CliHelper {
// eslint-disable-next-line no-useless-constructor
constructor(utils, fs) {
this.utils = utils;
this.fs = fs;
}
readData(data) {
return __awaiter(this, void 0, void 0, function* () {
// read Data
if (typeof data === 'string') {
const _data = this.utils.tryParse(data);
if (_data !== null) {
return _data;
}
else {
try {
const strData = yield this.fs.read(path_1.default.join(process.cwd(), data));
return JSON.parse(strData);
}
catch (error) {
throw new Error(`Error to read context: ${error}`);
}
}
}
});
}
nameFromFile(filePath) {
const parsedPath = path_1.default.parse(filePath);
return parsedPath.name;
}
getPackage(name, workspace) {
return __awaiter(this, void 0, void 0, function* () {
const exp = new RegExp(`${name}@(.*)\n`);
const localNpmList = yield this.utils.exec('npm list --depth=0', workspace);
const localMatches = localNpmList.match(exp);
return (localMatches && localMatches[1] ? localMatches[1] : '').replace(/"invalid"/gi, '').trim();
});
}
}
class OrmCliH3lp extends lambdaorm_1.OrmH3lp {
constructor(h3lp, logger) {
super(h3lp, logger);
this.cli = new CliHelper(h3lp.utils, h3lp.fs);
}
}
exports.OrmCliH3lp = OrmCliH3lp;
//# sourceMappingURL=helper.js.map