🐛 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

@ -17,7 +17,6 @@ import {
ActiveWorkflows,
ActiveWebhooks,
NodeExecuteFunctions,
WorkflowExecute,
} from 'n8n-core';
import {

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
*

View file

@ -259,6 +259,11 @@ export interface IN8nUISettings {
}
export interface IPackageVersions {
cli: string;
}
export interface IPushData {
data: IPushDataExecutionFinished | IPushDataNodeExecuteAfter | IPushDataNodeExecuteBefore | IPushDataTestWebhook;
type: IPushDataType;

View file

@ -6,7 +6,6 @@ import {
import * as bodyParser from 'body-parser';
import * as history from 'connect-history-api-fallback';
import * as requestPromise from 'request-promise-native';
import { version as versionCli } from '../package.json';
import {
ActiveExecutions,
@ -28,6 +27,7 @@ import {
IExecutionsStopData,
IExecutionsSummary,
IN8nUISettings,
IPackageVersions,
IWorkflowBase,
IWorkflowShortResponse,
IWorkflowResponse,
@ -74,7 +74,6 @@ import * as config from '../config';
// @ts-ignore
import * as timezones from 'google-timezones-json';
import * as parseUrl from 'parseurl';
import { version } from '@oclif/command/lib/flags';
class App {
@ -90,6 +89,7 @@ class App {
timezone: string;
activeExecutionsInstance: ActiveExecutions.ActiveExecutions;
push: Push.Push;
versions: IPackageVersions | undefined;
constructor() {
this.app = express();
@ -122,6 +122,8 @@ class App {
async config(): Promise<void> {
this.versions = await GenericHelpers.getVersions();
// Check for basic auth credentials if activated
const basicAuthActive = config.get('security.basicAuth.active') as boolean;
if (basicAuthActive === true) {
@ -1005,7 +1007,7 @@ class App {
saveManualExecutions: this.saveManualExecutions,
timezone: this.timezone,
urlBaseWebhook: WebhookHelpers.getWebhookBaseUrl(),
versionCli,
versionCli: this.versions!.cli,
};
}));
@ -1118,7 +1120,9 @@ export async function start(): Promise<void> {
await app.config();
app.app.listen(PORT, () => {
console.log('n8n ready on port ' + PORT);
app.app.listen(PORT, async () => {
const versions = await GenericHelpers.getVersions();
console.log(`n8n ready on port ${PORT}`);
console.log(`Version: ${versions.cli}`);
});
}

View file

@ -14,7 +14,6 @@
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"preserveConstEnums": true,
"resolveJsonModule": true,
"declaration": true,
"outDir": "./dist/",
"target": "es2017",