From b0722a5ba14020849678eb38c74d88aa1e9a29b5 Mon Sep 17 00:00:00 2001 From: Goran Gligorin Date: Tue, 11 Apr 2017 21:36:41 +0200 Subject: [PATCH] feat: add cli support closes #3 --- package.json | 4 ++++ src/cli.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/cli.js diff --git a/package.json b/package.json index c34b4bd4..b3da9af7 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ "latest" ] }, + "bin": { + "cordova-set-version": "dist/cli.js" + }, "bugs": { "url": "https://github.com/gligoran/cordova-set-version/issues" }, @@ -14,6 +17,7 @@ } }, "dependencies": { + "meow": "3.7.0", "mz": "2.6.0", "read-pkg": "2.0.0", "xml2js": "0.4.17", diff --git a/src/cli.js b/src/cli.js new file mode 100644 index 00000000..1ed8b221 --- /dev/null +++ b/src/cli.js @@ -0,0 +1,42 @@ +#!/usr/bin/env node + +import meow from 'meow'; + +import setCordovaVersion from './index'; + +const help = ` + Usage + $ cordova-set-version [-v|--version ] [-b|--build-number ] [config.xml] + + Options + -v, --version Version to set + -b, --build-number Build number to set + + Examples + $ cordova-set-version -v 2.4.9 + $ cordova-set-version -b 86 + $ cordova-set-version -v 2.4.9 -b 86 +`; + +const cli = meow( + { + version: false, + help + }, { + alias: { + v: 'version', + b: 'buildNumber' + } + } +); + +const filename = cli.input[0] || 'config.xml'; +let promise = Promise.resolve(); + +if (cli.flags.version) { + promise = promise.then(() => setCordovaVersion.setVersion(filename, cli.flags.version)); +} + +if (cli.flags.buildNumber) { + promise = promise.then(() => setCordovaVersion.setBuildNumber(filename, cli.flags.buildNumber)); +} \ No newline at end of file