♻ Use argument-parser for installPatch

This commit is contained in:
C-3PO 2018-10-25 03:05:53 +02:00
parent 48d9a4803d
commit 08173fe495
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
3 changed files with 21 additions and 43 deletions

8
package-lock.json generated
View file

@ -10,7 +10,7 @@
"dev": true "dev": true
}, },
"argument-parser": { "argument-parser": {
"version": "git+https://git.jedipedia.net/swtor/argument-parser.git#7b757e53771dfea2326b2c8d6901e39c66e23230", "version": "git+https://git.jedipedia.net/swtor/argument-parser.git#20315cc64f7c576f7dc078e3d82e4045c063620f",
"from": "git+https://git.jedipedia.net/swtor/argument-parser.git" "from": "git+https://git.jedipedia.net/swtor/argument-parser.git"
}, },
"sax": { "sax": {
@ -19,15 +19,15 @@
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
}, },
"ssn": { "ssn": {
"version": "git+https://git.jedipedia.net/swtor/ssn.git#0a8e1b361e54581b53dc0f7e1f74bfae614fc890", "version": "git+https://git.jedipedia.net/swtor/ssn.git#c5f6335483fd114c060535ca84aba40bd68ab83e",
"from": "git+https://git.jedipedia.net/swtor/ssn.git", "from": "git+https://git.jedipedia.net/swtor/ssn.git",
"requires": { "requires": {
"ssn-installer": "git+https://git.jedipedia.net/swtor/ssn-installer.git#34c8da24e619cd2edea09e1f4318c939a36560f8", "ssn-installer": "git+https://git.jedipedia.net/swtor/ssn-installer.git#442fcd7d0cb0622959ad47047e3c187a16dbd1da",
"xml-js": "^1.6.8" "xml-js": "^1.6.8"
} }
}, },
"ssn-installer": { "ssn-installer": {
"version": "git+https://git.jedipedia.net/swtor/ssn-installer.git#34c8da24e619cd2edea09e1f4318c939a36560f8", "version": "git+https://git.jedipedia.net/swtor/ssn-installer.git#442fcd7d0cb0622959ad47047e3c187a16dbd1da",
"from": "git+https://git.jedipedia.net/swtor/ssn-installer.git" "from": "git+https://git.jedipedia.net/swtor/ssn-installer.git"
}, },
"xml-js": { "xml-js": {

View file

@ -1,7 +0,0 @@
export default function failWithError(usage: string, msg?: string) {
if (msg !== undefined) {
process.stderr.write(`Error: ${String(msg).trim()}\n`);
}
process.stderr.write(`Usage: ${usage} \n`);
process.exit(1);
}

View file

@ -1,45 +1,30 @@
#!/usr/bin/env node #!/usr/bin/env node
import parseArguments from 'argument-parser';
import { getPatch, Product, verifyProductName } from 'ssn'; import { getPatch, Product, verifyProductName } from 'ssn';
import failWithError from './funcs/failWithError';
const failFunction = failWithError.bind(null, 'node dist/installPatch.js <product> <from> <to>'); const { args, fail } = parseArguments({
product: { short: 'p', description: 'Name of the product we want to get the patch info on', verify: verifyProductName, message: (value) => `"${value}" is not a valid product name.` },
if (process.argv.length !== 5) { from: { short: 'f', description: 'Number of the from release, must be an integer in the range [-1, 999]', verify: (str) => (str.match(/^(-1|0|[1-9][0-9]{0,2})$/) !== null) },
failFunction(`Expected 3 arguments but ${process.argv.length - 2} arguments were supplied.`); to: { short: 't', description: 'Number of the to release, must be an integer in the range [0, 999]', verify: (str) => (str.match(/^(0|[1-9][0-9]{0,2})$/) !== null) },
} }, (origArgs) => ((origArgs.length === 3) ? ['--product', origArgs[0], '--from', origArgs[1], '--to', origArgs[2]] : undefined));
//Check that product name is valid
const product = process.argv[2];
if (!verifyProductName(product)) {
failFunction(`"${product.substring(0, 300)}" is not a valid product name.`);
}
//Check that from and to are valid numbers
const from = process.argv[3];
const to = process.argv[4];
if (!from.match(/^(-1|0|[1-9][0-9]{0,2})$/)) {
failFunction(`from value "${from.substring(0, 300)}" is not a valid integer; it must be in range [-1, 999].`);
}
if (!to.match(/^(0|[1-9][0-9]{0,2})$/)) {
failFunction(`to value "${to.substring(0, 300)}" is not a valid integer; it must be in range [0, 999].`);
}
//TODO: set directory with existing patch data //TODO: set directory with existing patch data
//TODO: set target directory where patch should be installed //TODO: set target directory where patch should be installed
//TODO: set temp directory where patch files should be stored. //TODO: set temp directory where patch files should be stored.
//TODO: set location of xdelta3 executable
//TODO: set from=any so it detects current version automatically (based on .version files) //TODO: set from=any so it detects current version automatically (based on .version files)
//TODO: set to=manifest/current to install whatever is the current version in manifest/on CDN //TODO: set to=manifest/current to install whatever is the current version in manifest/on CDN
(async () => { (async () => {
await getPatch({ try {
/* tslint:disable:object-literal-sort-keys */ await getPatch({
product: product as Product, product: args.product as Product,
from: Number(from), from: Number(args.from),
to: Number(to), to: Number(args.to),
sourceDirectory: process.cwd(), sourceDirectory: process.cwd(),
targetDirectory: process.cwd(), targetDirectory: process.cwd(),
/* tslint:enable:object-literal-sort-keys */ });
}); } catch (error) {
fail(error);
}
})(); })();