* This takes the json files generated by the buildBranchAPI and buildPublishedAPI and * reconstructs our interfaces and create a graph of all dependencies between interfaces. * From there, we diff the reconstructed interfaces and track all that have changes. * We use the graph to communicate what
()
| 63 | * as well as the local console. |
| 64 | */ |
| 65 | async function compare() { |
| 66 | let branchDir = args.values['branch-api-dir'] || path.join(__dirname, '..', 'dist', 'branch-api'); |
| 67 | let publishedDir = args.values['base-api-dir'] || path.join(__dirname, '..', 'dist', 'base-api'); |
| 68 | if (!(fs.existsSync(branchDir) && fs.existsSync(publishedDir))) { |
| 69 | console.log( |
| 70 | chalk.redBright(`you must have both a branchDir ${branchDir} and baseDir ${publishedDir}`) |
| 71 | ); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | let branchAPIs = fg.sync(`${branchDir}/**/api.json`); |
| 76 | let publishedAPIs = fg.sync(`${publishedDir}/**/api.json`); |
| 77 | let pairs = []; |
| 78 | |
| 79 | // find all matching pairs based on what's been published |
| 80 | for (let pubApi of publishedAPIs) { |
| 81 | let pubApiPath = pubApi.split(path.sep); |
| 82 | let pkgJson = readJsonSync( |
| 83 | path.join('/', ...pubApiPath.slice(0, pubApiPath.length - 2), 'package.json') |
| 84 | ); |
| 85 | let name = pkgJson.name; |
| 86 | let sharedPath = path.join(name, 'dist', 'api.json'); |
| 87 | let found = false; |
| 88 | for (let branchApi of branchAPIs) { |
| 89 | if (branchApi.includes(sharedPath)) { |
| 90 | found = true; |
| 91 | pairs.push({pubApi, branchApi}); |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | if (!found) { |
| 96 | pairs.push({pubApi, branchApi: null}); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // don't care about private APIs, but we do care if we're about to publish a new one |
| 101 | for (let branchApi of branchAPIs) { |
| 102 | let branchApiPath = branchApi.split(path.sep); |
| 103 | let pkgJson = readJsonSync( |
| 104 | path.join('/', ...branchApiPath.slice(0, branchApiPath.length - 2), 'package.json') |
| 105 | ); |
| 106 | let name = pkgJson.name; |
| 107 | let sharedPath = path.join(name, 'dist', 'api.json'); |
| 108 | let found = false; |
| 109 | for (let pubApi of publishedAPIs) { |
| 110 | if (pubApi.includes(sharedPath)) { |
| 111 | found = true; |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | let json = readJsonSync(path.join(branchApi, '..', '..', 'package.json')); |
| 116 | if (!found && !json.private) { |
| 117 | pairs.push({pubApi: null, branchApi}); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | let allDiffs = {}; |
| 122 | for (let pair of pairs) { |
no test coverage detected