Skip to content

Commit

Permalink
fix(cli): cli displays the corrent version number
Browse files Browse the repository at this point in the history
  • Loading branch information
tivie committed Mar 8, 2022
1 parent d5c1b38 commit 8b48882
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@
*/
var fs = require('fs'),
path = require('path'),
json = JSON.parse(fs.readFileSync('package.json', 'utf8')),
version = json.version,
Command = require('commander').Command,
program = new Command(),
path1 = path.resolve(__dirname + '/../dist/showdown.js'),
path2 = path.resolve(__dirname + '/../../.build/showdown.js'),
showdown;
showdown,
version;

// require shodown. We use conditional loading for each use case
if (fs.existsSync(path1)) {
// production. File lives in bin directory
showdown = require(path1);
version = require(path.resolve(__dirname + '/../package.json')).version;
} else if (fs.existsSync(path2)) {
// testing envo, uses the concatenated stuff for testing
showdown = require(path2);
version = require(path.resolve(__dirname + '/../../package.json')).version;
} else {
// cold testing (manual) of cli.js in the src file. We load the dist file
showdown = require('../../dist/showdown');
version = require('../../package.json');
}


program
.name('showdown')
.description('CLI to Showdownjs markdown parser v' + version)
Expand Down

0 comments on commit 8b48882

Please sign in to comment.