import * as fs from 'fs'; import * as jsYaml from 'js-yaml'; import * as path from 'path'; export interface AppContext { appId?: string; displayName?: string; version?: string; vendor?: string; runtime?: string; } export function appContext(appId?: string, vendor?: string, runtime?: string): AppContext { if (appId) { if (appId.includes('@')) { const [id, version] = appId.split('@'); return { appId: id, version, vendor, runtime }; } else { return {appId, vendor, runtime}; } } const yaml = readAppYaml(); if (yaml && yaml.meta) { return { appId: yaml.meta.app_id, displayName: yaml.meta.display_name, version: yaml.meta.version, vendor: yaml.meta.vendor, runtime: yaml.runtime }; } return {}; } export function readAppYaml(): any { const file = path.join(process.cwd(), 'app.yml'); if (!fs.existsSync(file)) { throw new Error( `Can not find app manifest (app.yaml) in working directory. Please run this command from the root of your app.` ); } return jsYaml.safeLoad(fs.readFileSync(file, 'utf8')); }