From e46faff11b5f8746cab7160e8d6693205e6f6c22 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 19 Oct 2018 01:10:21 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Add=20command-line=20scripts=20f?= =?UTF-8?q?rom=20ssn=20repo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- package-lock.json | 12 +++++++++--- package.json | 3 +++ src/failWithError.ts | 7 +++++++ src/getManifest.ts | 20 ++++++++++++++++++++ src/getSolidpkg.ts | 30 ++++++++++++++++++++++++++++++ src/getSolidpkgZip.ts | 30 ++++++++++++++++++++++++++++++ src/index.ts | 1 - src/installPatch.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ src/tslint.json | 16 ++++++++++++++++ 10 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 src/failWithError.ts create mode 100644 src/getManifest.ts create mode 100644 src/getSolidpkg.ts create mode 100644 src/getSolidpkgZip.ts delete mode 100644 src/index.ts create mode 100644 src/installPatch.ts create mode 100644 src/tslint.json diff --git a/README.md b/README.md index c781d0a..f770875 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -This repository contains command-line tools for handling patches. It uses the functions exposed by the `ssn` library and makes them available for use on the shell. +This repository contains command-line tools for handling patches. It uses the functions exposed by the [ssn](/swtor/ssn) library and makes them available for use on the shell. # Installation For this tool to work, `tsc` and `tslint` must be globally available, e.g. by running: @@ -16,7 +16,7 @@ npm install && npm start For a better command line experience, add the following to your `~/.bashrc` file: ```bash -alias swtor_install='node /path/to/installation/patcher/dist/installPatch.js' +alias swtor_install='node /path/to/installation/ssn-tools/dist/installPatch.js' complete -W 'assets_swtor_de_de assets_swtor_en_us assets_swtor_fr_fr assets_swtor_main assets_swtor_test_de_de assets_swtor_test_en_us assets_swtor_test_fr_fr assets_swtor_test_main eualas movies_de_de movies_en_us movies_fr_fr patcher2014 patcher2017 retailclient_liveqatest retailclient_swtor retailclient_publictest' 'swtor_install' ``` diff --git a/package-lock.json b/package-lock.json index 046ccea..004a72e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3,21 +3,27 @@ "requires": true, "lockfileVersion": 1, "dependencies": { + "@types/node": { + "version": "10.12.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.0.tgz", + "integrity": "sha512-3TUHC3jsBAB7qVRGxT6lWyYo2v96BMmD2PTcl47H25Lu7UXtFH/2qqmKiVrnel6Ne//0TFYf6uvNX+HW2FRkLQ==", + "dev": true + }, "sax": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" }, "ssn": { - "version": "git+https://git.jedipedia.net/swtor/ssn.git#6d05939ef4c3139d689102544e01e7a849bf196c", + "version": "git+https://git.jedipedia.net/swtor/ssn.git#684a123a7689ae2bc12a7ba00a6466366fc5bc19", "from": "git+https://git.jedipedia.net/swtor/ssn.git", "requires": { - "ssn-installer": "git+https://git.jedipedia.net/swtor/ssn-installer.git#8c8c5cf68a1a74527de5ccd268db0aa34b795e13", + "ssn-installer": "git+https://git.jedipedia.net/swtor/ssn-installer.git#01926cfe97a3166cff46a2061dda519f9c262d40", "xml-js": "^1.6.8" } }, "ssn-installer": { - "version": "git+https://git.jedipedia.net/swtor/ssn-installer.git#8c8c5cf68a1a74527de5ccd268db0aa34b795e13", + "version": "git+https://git.jedipedia.net/swtor/ssn-installer.git#01926cfe97a3166cff46a2061dda519f9c262d40", "from": "git+https://git.jedipedia.net/swtor/ssn-installer.git" }, "xml-js": { diff --git a/package.json b/package.json index 8eb074e..1e02dab 100644 --- a/package.json +++ b/package.json @@ -13,5 +13,8 @@ }, "dependencies": { "ssn": "git+https://git.jedipedia.net/swtor/ssn.git" + }, + "devDependencies": { + "@types/node": "^10.12.0" } } diff --git a/src/failWithError.ts b/src/failWithError.ts new file mode 100644 index 0000000..6520bd0 --- /dev/null +++ b/src/failWithError.ts @@ -0,0 +1,7 @@ +export default function failWithError(usage: string, msg?: string) { + if (msg !== undefined) { + process.stderr.write(`Error: ${msg.trim()}\n`); + } + process.stderr.write(`Usage: ${usage} \n`); + process.exit(1); +} diff --git a/src/getManifest.ts b/src/getManifest.ts new file mode 100644 index 0000000..9a56178 --- /dev/null +++ b/src/getManifest.ts @@ -0,0 +1,20 @@ +import { getManifest, IManifest, Product, verifyProductName } from 'ssn'; +import failWithError from './failWithError'; + +const failFunction = failWithError.bind(null, 'node dist/getManifest.js '); + +if (process.argv.length !== 3) { + failFunction(`Expected 1 argument but ${process.argv.length - 2} arguments were supplied.`); +} + +//Check that product name is valid +const product = process.argv[2]; +if (!verifyProductName(product)) { + failFunction(`"${product} is not a valid product name.`); +} + +//Get manifest and write output to stdout +getManifest(product as Product).then((output: IManifest) => { + process.stdout.write(JSON.stringify(output)); + //process.exit(0); +}); diff --git a/src/getSolidpkg.ts b/src/getSolidpkg.ts new file mode 100644 index 0000000..7ff200f --- /dev/null +++ b/src/getSolidpkg.ts @@ -0,0 +1,30 @@ +import { getSolidpkg, ISolidSimple, Product, verifyProductName } from 'ssn'; +import failWithError from './failWithError'; + +const failFunction = failWithError.bind(null, 'node dist/getSolidpkg.js '); + +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].`); +} + +//Get solidpkg and write output to stdout +getSolidpkg(product as Product, Number(from), Number(to)).then((output: ISolidSimple) => { + process.stdout.write(JSON.stringify(output)); + //process.exit(0); +}); diff --git a/src/getSolidpkgZip.ts b/src/getSolidpkgZip.ts new file mode 100644 index 0000000..50e93b8 --- /dev/null +++ b/src/getSolidpkgZip.ts @@ -0,0 +1,30 @@ +import { getSolidpkgZip, ISsnFileEntry, Product, verifyProductName } from 'ssn'; +import failWithError from './failWithError'; + +const failFunction = failWithError.bind(null, 'node dist/getSolidpkgZip.js '); + +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].`); +} + +//Get solidpkg's .zip file and write output to stdout +getSolidpkgZip(product as Product, Number(from), Number(to)).then((output: ISsnFileEntry[]) => { + process.stdout.write(JSON.stringify(output)); + //process.exit(0); +}); diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 8ad1dfb..0000000 --- a/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -//TODO diff --git a/src/installPatch.ts b/src/installPatch.ts new file mode 100644 index 0000000..fd3d6ac --- /dev/null +++ b/src/installPatch.ts @@ -0,0 +1,43 @@ +import { getPatch, Product, verifyProductName } from 'ssn'; +import failWithError from './failWithError'; + +const failFunction = failWithError.bind(null, 'node dist/installPatch.js '); + +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].`); +} + +//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 */ + }); +})(); diff --git a/src/tslint.json b/src/tslint.json new file mode 100644 index 0000000..6a41014 --- /dev/null +++ b/src/tslint.json @@ -0,0 +1,16 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended" + ], + "jsRules": {}, + "rules": { + "comment-format": false, + "indent": [true, "spaces", 2], + "max-line-length": false, + "no-bitwise": false, + "no-console": false, + "quotemark": [true, "single"] + }, + "rulesDirectory": [] +}