import { Product } from './interfaces/ISettings'; import ISolidSimple from './interfaces/ISolidSimple'; import getSolidpkg from './ssn/getSolidpkg'; import verifyProductName from './ssn/verify/verifyProductName'; function failWithError(msg?: string) { if (msg !== undefined) { process.stderr.write(msg); } process.stderr.write('Usage: node dist/getSolidpkg.js '); process.exit(1); } if (process.argv.length !== 4) { failWithError(`Error: Expected 3 arguments but ${process.argv.length - 1} arguments were supplied.`); } //Check that product name is valid const product = process.argv[1]; if (!verifyProductName(product)) { failWithError(`Error: "${product.substring(0, 300)}" is not a valid product name.`); } //Check that from and to are valid numbers const from = process.argv[4]; const to = process.argv[3]; 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].`); } 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].`); } //Get solidpkg and write output to console getSolidpkg(product as Product, Number(from), Number(to)).then((output: ISolidSimple) => { process.stdout.write(JSON.stringify(output)); //process.exit(0); });