From e7ceb6728a43e4ca908f66deef525b44adf5b20d Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Thu, 25 Feb 2021 15:42:39 -0700 Subject: [PATCH] attempt to get the actual zwitterion version --- package-lock.json | 2 +- src/command-line.ts | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5b301622..991a09a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "zwitterion", - "version": "0.45.0", + "version": "0.46.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/command-line.ts b/src/command-line.ts index 0b74bc0d..d0d2e124 100644 --- a/src/command-line.ts +++ b/src/command-line.ts @@ -2,12 +2,10 @@ import * as program from 'commander'; import * as fs from 'fs-extra'; import { CommandLineOptions } from '../index.d'; -const packageJSON: { - version: string; -} = JSON.parse(fs.readFileSync('./package.json').toString()); +const zwitterionVersion: string = getZwitterionVersion(); program - .version(packageJSON.version) + .version(zwitterionVersion) .option('--port [port]', 'Specify the server\'s port') // .option('-nw, --no-watch-files', 'Do not watch files in current directory and do not reload browser on changes') // .option('--ts-warning', 'Report TypeScript errors in the browser console as warnings') @@ -48,4 +46,22 @@ export const commandLineOptions: Readonly = { ascOptionsFilePath, tscOptionsFilePath, spaRoot -}; \ No newline at end of file +}; + +function getZwitterionVersion(): string { + try { + const packageJSON: { + version: string; + } = JSON.parse(fs.readFileSync(require.resolve('zwitterion/package.json')).toString()); + + return packageJSON.version; + } + catch(error) { + if (error.code === 'MODULE_NOT_FOUND') { + return '0.0.0'; + } + else { + throw error; + } + } +} \ No newline at end of file