♻ Use argument-parser for installPatch
This commit is contained in:
parent
48d9a4803d
commit
08173fe495
3 changed files with 21 additions and 43 deletions
|
@ -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);
|
||||
}
|
|
@ -1,45 +1,30 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import parseArguments from 'argument-parser';
|
||||
import { getPatch, Product, verifyProductName } from 'ssn';
|
||||
import failWithError from './funcs/failWithError';
|
||||
|
||||
const failFunction = failWithError.bind(null, 'node dist/installPatch.js <product> <from> <to>');
|
||||
|
||||
if (process.argv.length !== 5) {
|
||||
failFunction(`Expected 3 arguments but ${process.argv.length - 2} arguments were supplied.`);
|
||||
}
|
||||
|
||||
//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].`);
|
||||
}
|
||||
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.` },
|
||||
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) },
|
||||
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));
|
||||
|
||||
//TODO: set directory with existing patch data
|
||||
//TODO: set target directory where patch should be installed
|
||||
//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 to=manifest/current to install whatever is the current version in manifest/on CDN
|
||||
|
||||
(async () => {
|
||||
await getPatch({
|
||||
/* tslint:disable:object-literal-sort-keys */
|
||||
product: product as Product,
|
||||
from: Number(from),
|
||||
to: Number(to),
|
||||
sourceDirectory: process.cwd(),
|
||||
targetDirectory: process.cwd(),
|
||||
/* tslint:enable:object-literal-sort-keys */
|
||||
});
|
||||
try {
|
||||
await getPatch({
|
||||
product: args.product as Product,
|
||||
from: Number(args.from),
|
||||
to: Number(args.to),
|
||||
sourceDirectory: process.cwd(),
|
||||
targetDirectory: process.cwd(),
|
||||
});
|
||||
} catch (error) {
|
||||
fail(error);
|
||||
}
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue