|
| 1 | +#!/usr/bin/env node |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const process = require('process'); |
| 5 | +const path = require('path'); |
| 6 | +const fs = require('fs'); |
| 7 | + |
| 8 | +const { readdir } = fs.promises; |
| 9 | + |
| 10 | +const tree = { |
| 11 | + arch: { |
| 12 | + inst: { // TODO update this object to index new extension |
| 13 | + A: {}, |
| 14 | + B: {}, |
| 15 | + F: {}, |
| 16 | + H: {}, |
| 17 | + I: {}, |
| 18 | + M: {}, |
| 19 | + Q: {}, |
| 20 | + S: {}, |
| 21 | + Svinval: {}, |
| 22 | + V: {}, |
| 23 | + Zabha: {}, |
| 24 | + Zacas: {}, |
| 25 | + Zalasr: {}, |
| 26 | + Zawrs: {}, |
| 27 | + Zfbfmin: {}, |
| 28 | + Zfh: {}, |
| 29 | + Zicbom: {}, |
| 30 | + Zicboz: {}, |
| 31 | + Zicfiss: {}, |
| 32 | + Zicond: {}, |
| 33 | + Zicsr: {}, |
| 34 | + Zifencei: {} |
| 35 | + } |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +const rec = async (node, branch, root) => { |
| 40 | + const keys = Object.keys(node); |
| 41 | + if (keys.length === 0) { |
| 42 | + const fullPath = path.resolve(root, ...branch); |
| 43 | + const files = await readdir(fullPath); |
| 44 | + for (const file of files) { |
| 45 | + const baseName = path.basename(file, '.yaml'); |
| 46 | + node[baseName] = {$ref: path.join(...branch, file)}; |
| 47 | + } |
| 48 | + } else { |
| 49 | + for (const key of keys) { |
| 50 | + const newBranch = [...branch, key]; |
| 51 | + await rec(node[key], newBranch, root); |
| 52 | + } |
| 53 | + } |
| 54 | + return node; |
| 55 | +}; |
| 56 | + |
| 57 | +const main = async () => { |
| 58 | + const [, , root] = process.argv; |
| 59 | + if (root === undefined) { |
| 60 | + console.error('usage: ./index-unifieddb.js <path-to-unifieddb-root>'); |
| 61 | + return; |
| 62 | + } |
| 63 | + const rootPath = path.resolve('.', root); |
| 64 | + await rec(tree, [], rootPath); |
| 65 | + console.log(JSON.stringify(tree, null, 2)); |
| 66 | +}; |
| 67 | + |
| 68 | +main(); |
0 commit comments