@releaseotto/core
Version:
OTTO performs your action on new versioning of APIs, packages, schemas, etc. Keepings things nice and neatly automated.
54 lines • 2.24 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());
});
};
import * as fs from 'fs';
import * as Shell from 'shelljs';
import { temporaryLocation } from '../utils/globals';
import * as path from 'path';
export function loadPackageInformation({ location }) {
return __awaiter(this, void 0, void 0, function* () {
try {
const data = fs.readFileSync(location, 'utf8');
const jsonData = JSON.parse(data);
return jsonData;
}
catch (e) {
throw new Error("Could not load package file");
}
});
}
export function runScript({ location, script }) {
return __awaiter(this, void 0, void 0, function* () {
if (!Shell.which('npm')) {
Shell.echo('Sorry, this script requires npm');
Shell.exit(1);
}
Shell.cd(location);
const install = Shell.exec(`npm ci`);
if (install.code !== 0) {
throw new Error(install.stderr);
}
const run = Shell.exec(`npm run ${script}`);
if (run.code !== 0) {
throw new Error(run.stderr);
}
});
}
export function runAction(config, packageConfig) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const location = (_a = config.location) === null || _a === void 0 ? void 0 : _a.config;
const packageDirLocation = path.dirname(path.resolve(temporaryLocation, location.repo, location.metaMinusLocation));
runScript({
location: packageDirLocation,
script: packageConfig.script
});
});
}
//# sourceMappingURL=npm.js.map