Skip to content

Commit

Permalink
attempt to get the actual zwitterion version
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Feb 25, 2021
1 parent 4491467 commit e7ceb67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 21 additions & 5 deletions src/command-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -48,4 +46,22 @@ export const commandLineOptions: Readonly<CommandLineOptions> = {
ascOptionsFilePath,
tscOptionsFilePath,
spaRoot
};
};

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;
}
}
}

0 comments on commit e7ceb67

Please sign in to comment.