🚑 Fix utility scripts
This commit is contained in:
parent
d79e7d289c
commit
58963160c2
3 changed files with 23 additions and 26 deletions
7
src/failWithError.ts
Normal file
7
src/failWithError.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export default function failWithError(usage: string, msg?: string) {
|
||||||
|
if (msg !== undefined) {
|
||||||
|
process.stderr.write(`${msg.trim()}\n`);
|
||||||
|
}
|
||||||
|
process.stderr.write(`Usage: ${usage} \n`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
|
@ -1,24 +1,19 @@
|
||||||
|
import failWithError from './failWithError';
|
||||||
import IManifest from './interfaces/IManifest';
|
import IManifest from './interfaces/IManifest';
|
||||||
import { Product } from './interfaces/ISettings';
|
import { Product } from './interfaces/ISettings';
|
||||||
import getManifest from './ssn/getManifest';
|
import getManifest from './ssn/getManifest';
|
||||||
import verifyProductName from './ssn/verify/verifyProductName';
|
import verifyProductName from './ssn/verify/verifyProductName';
|
||||||
|
|
||||||
function failWithError(msg?: string) {
|
const failFunction = failWithError.bind(null, 'node dist/getManifest.js <product>');
|
||||||
if (msg !== undefined) {
|
|
||||||
process.stderr.write(msg);
|
|
||||||
}
|
|
||||||
process.stderr.write('Usage: node dist/getManifest.js <product>');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.argv.length !== 2) {
|
if (process.argv.length !== 3) {
|
||||||
failWithError(`Error: Expected 1 argument but ${process.argv.length - 1} arguments were supplied.`);
|
failFunction(`Error: Expected 1 argument but ${process.argv.length - 2} arguments were supplied.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check that product name is valid
|
//Check that product name is valid
|
||||||
const product = process.argv[1];
|
const product = process.argv[2];
|
||||||
if (!verifyProductName(product)) {
|
if (!verifyProductName(product)) {
|
||||||
failWithError(`Error: "${product} is not a valid product name.`);
|
failFunction(`Error: "${product} is not a valid product name.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get manifest and write output to console
|
//Get manifest and write output to console
|
||||||
|
|
|
@ -1,34 +1,29 @@
|
||||||
|
import failWithError from './failWithError';
|
||||||
import { Product } from './interfaces/ISettings';
|
import { Product } from './interfaces/ISettings';
|
||||||
import ISolidSimple from './interfaces/ISolidSimple';
|
import ISolidSimple from './interfaces/ISolidSimple';
|
||||||
import getSolidpkg from './ssn/getSolidpkg';
|
import getSolidpkg from './ssn/getSolidpkg';
|
||||||
import verifyProductName from './ssn/verify/verifyProductName';
|
import verifyProductName from './ssn/verify/verifyProductName';
|
||||||
|
|
||||||
function failWithError(msg?: string) {
|
const failFunction = failWithError.bind(null, 'node dist/getSolidpkg.js <product> <from> <to>');
|
||||||
if (msg !== undefined) {
|
|
||||||
process.stderr.write(msg);
|
|
||||||
}
|
|
||||||
process.stderr.write('Usage: node dist/getSolidpkg.js <product> <from> <to>');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.argv.length !== 4) {
|
if (process.argv.length !== 5) {
|
||||||
failWithError(`Error: Expected 3 arguments but ${process.argv.length - 1} arguments were supplied.`);
|
failFunction(`Error: Expected 3 arguments but ${process.argv.length - 2} arguments were supplied.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check that product name is valid
|
//Check that product name is valid
|
||||||
const product = process.argv[1];
|
const product = process.argv[2];
|
||||||
if (!verifyProductName(product)) {
|
if (!verifyProductName(product)) {
|
||||||
failWithError(`Error: "${product.substring(0, 300)}" is not a valid product name.`);
|
failFunction(`Error: "${product.substring(0, 300)}" is not a valid product name.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check that from and to are valid numbers
|
//Check that from and to are valid numbers
|
||||||
const from = process.argv[4];
|
const from = process.argv[3];
|
||||||
const to = process.argv[3];
|
const to = process.argv[4];
|
||||||
if (!from.match(/^(-1|0|[1-9][0-9]{0,2})$/)) {
|
if (!from.match(/^(-1|0|[1-9][0-9]{0,2})$/)) {
|
||||||
failWithError(`Error: from value "${from.substring(0, 300)}" is not a valid integer; it must be in range [-1, 999].`);
|
failFunction(`Error: 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})$/)) {
|
if (!to.match(/^(0|[1-9][0-9]{0,2})$/)) {
|
||||||
failWithError(`Error: to value "${to.substring(0, 300)}" is not a valid integer; it must be in range [0, 999].`);
|
failFunction(`Error: to value "${to.substring(0, 300)}" is not a valid integer; it must be in range [0, 999].`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get solidpkg and write output to console
|
//Get solidpkg and write output to console
|
||||||
|
|
Loading…
Reference in a new issue