|
| 1 | +#!npx ts-node |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2025 Arm Limited |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +import yargs from "yargs"; |
| 20 | +import { hideBin } from "yargs/helpers"; |
| 21 | +import fs from "fs"; |
| 22 | + |
| 23 | +async function main() { |
| 24 | + |
| 25 | + const { json, report, header } = yargs(hideBin(process.argv)) |
| 26 | + .usage('Usage: $0 <json> <report> [--header <header>]') |
| 27 | + .options('header', { |
| 28 | + describe: 'Header to add to the report', |
| 29 | + type: 'string' |
| 30 | + }) |
| 31 | + .command('$0 <json> <report>', '', y => { |
| 32 | + y.positional('json', { |
| 33 | + describe: 'JSON file to parse', |
| 34 | + type: 'string' |
| 35 | + }); |
| 36 | + y.positional('report', { |
| 37 | + describe: 'Report file to generate', |
| 38 | + type: 'string' |
| 39 | + }); |
| 40 | + }) |
| 41 | + .help('h') |
| 42 | + .version(false) |
| 43 | + .strict() |
| 44 | + .parseSync(); |
| 45 | + |
| 46 | + const tpipJson = JSON.parse(fs.readFileSync(json as string, "utf8")); |
| 47 | + |
| 48 | + var data: string = ''; |
| 49 | + if (header && fs.existsSync(header as string)) { |
| 50 | + data += fs.readFileSync(header as string, "utf8"); |
| 51 | + } else { |
| 52 | + data += "# TPIP Report\n\n"; |
| 53 | + } |
| 54 | + |
| 55 | + data += `Report prepared at: ${new Date().toLocaleString('en-GB')}\n\n`; |
| 56 | + data += '| *Package* | *Version* | *Repository* | *License* |\n'; |
| 57 | + data += '|---|---|---|---|\n'; |
| 58 | + |
| 59 | + for(const value of tpipJson) { |
| 60 | + data += `| ${value.name} | ${value.version} | ${value.url} | ${value.license} |\n`; |
| 61 | + } |
| 62 | + |
| 63 | + fs.writeFileSync(report as string, data); |
| 64 | +} |
| 65 | + |
| 66 | +main().catch(error => { |
| 67 | + console.error(error); |
| 68 | + process.exit(1); |
| 69 | +}); |
0 commit comments