2018-07-05 02:06:19 +02:00
|
|
|
import failWithError from './failWithError';
|
2018-07-05 00:58:40 +02:00
|
|
|
import { Product } from './interfaces/ISettings';
|
|
|
|
import ISolidSimple from './interfaces/ISolidSimple';
|
|
|
|
import getSolidpkg from './ssn/getSolidpkg';
|
|
|
|
import verifyProductName from './ssn/verify/verifyProductName';
|
|
|
|
|
2018-07-05 02:06:19 +02:00
|
|
|
const failFunction = failWithError.bind(null, 'node dist/getSolidpkg.js <product> <from> <to>');
|
2018-07-05 00:58:40 +02:00
|
|
|
|
2018-07-05 02:06:19 +02:00
|
|
|
if (process.argv.length !== 5) {
|
2018-07-05 02:09:26 +02:00
|
|
|
failFunction(`Expected 3 arguments but ${process.argv.length - 2} arguments were supplied.`);
|
2018-07-05 00:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Check that product name is valid
|
2018-07-05 02:06:19 +02:00
|
|
|
const product = process.argv[2];
|
2018-07-05 00:58:40 +02:00
|
|
|
if (!verifyProductName(product)) {
|
2018-07-05 02:09:26 +02:00
|
|
|
failFunction(`"${product.substring(0, 300)}" is not a valid product name.`);
|
2018-07-05 00:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Check that from and to are valid numbers
|
2018-07-05 02:06:19 +02:00
|
|
|
const from = process.argv[3];
|
|
|
|
const to = process.argv[4];
|
2018-07-05 00:58:40 +02:00
|
|
|
if (!from.match(/^(-1|0|[1-9][0-9]{0,2})$/)) {
|
2018-07-05 02:09:26 +02:00
|
|
|
failFunction(`from value "${from.substring(0, 300)}" is not a valid integer; it must be in range [-1, 999].`);
|
2018-07-05 00:58:40 +02:00
|
|
|
}
|
|
|
|
if (!to.match(/^(0|[1-9][0-9]{0,2})$/)) {
|
2018-07-05 02:09:26 +02:00
|
|
|
failFunction(`to value "${to.substring(0, 300)}" is not a valid integer; it must be in range [0, 999].`);
|
2018-07-05 00:58:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-08 19:55:26 +02:00
|
|
|
//Get solidpkg and write output to stdout
|
2018-07-05 00:58:40 +02:00
|
|
|
getSolidpkg(product as Product, Number(from), Number(to)).then((output: ISolidSimple) => {
|
|
|
|
process.stdout.write(JSON.stringify(output));
|
|
|
|
//process.exit(0);
|
|
|
|
});
|