🐛 Fix issue that reading version caused problems with build

This commit is contained in:
Jan Oberhauser
2019-09-19 13:21:10 +02:00
parent 291320f817
commit 52808ea460
5 changed files with 42 additions and 7 deletions

View File

@@ -1,13 +1,19 @@
import * as config from '../config';
import * as express from 'express';
import { join as pathJoin } from 'path';
import {
readFile as fsReadFile,
} from 'fs';
import { promisify } from "util";
import { IDataObject } from 'n8n-workflow';
import { IPackageVersions } from './';
const fsReadFileAsync = promisify(fsReadFile);
let versionCache: IPackageVersions | undefined;
/**
* Displays a message to the user
*
@@ -54,6 +60,28 @@ export function getSessionId(req: express.Request): string | undefined {
}
/**
* Returns information which version of the packages are installed
*
* @export
* @returns {Promise<IPackageVersions>}
*/
export async function getVersions(): Promise<IPackageVersions> {
if (versionCache !== undefined) {
return versionCache;
}
const packageFile = await fsReadFileAsync(pathJoin(__dirname, '../../package.json'), 'utf8') as string;
const packageData = JSON.parse(packageFile);
versionCache = {
cli: packageData.version,
};
return versionCache;
}
/**
* Gets value from config with support for "_FILE" environment variables
*