diff --git a/README.md b/README.md index 080393877..16d27d012 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,7 @@ You should be able to visit `localhost:3000` in your browser. - Visit https://github.com/settings/developers to get your keys (don't worry about the callback URL, put whatever you want). - Load the `GITHUB_TOKEN` environment variable into your shell. +- Set `ONLY_WRITE_LOCAL_DATA_FILE` to `true` in *scripts/build-and-score-data.ts* to skip fetching and updating store blob from Vercel and instead use and update the local `assets/data.json` file. This command creates site data in `./assets/data.json` @@ -220,7 +221,7 @@ https://reactnative.directory/api/libraries ## I don't like how you calculate scores. -- Submit a PR with changes to `scripts/calculate-score.js`. +- Submit a PR with changes to `scripts/calculate-score.ts`. - You have all the power! Tell us what you want. ## How do I deploy my own version of this? diff --git a/scripts/build-and-score-data.ts b/scripts/build-and-score-data.ts index aba1c2162..9b75eb182 100644 --- a/scripts/build-and-score-data.ts +++ b/scripts/build-and-score-data.ts @@ -30,6 +30,10 @@ const SCRAPE_GH_IMAGES = false; const DATA_PATH = path.resolve('assets', 'data.json'); const GITHUB_RESULTS_PATH = path.join('scripts', 'raw-github-results.json'); +// If script should only write to the local data file and not upload to the store. +// This is useful for debugging and testing purposes. +const ONLY_WRITE_LOCAL_DATA_FILE = false; + const invalidRepos = []; const mismatchedRepos = []; @@ -228,10 +232,10 @@ async function buildAndScoreData() { Object.keys(entry.npm).length > 0 ? entry : { - ...entry, - npm: - latestData.libraries.find(prevEntry => entry.npmPkg === prevEntry.npmPkg)?.npm ?? {}, - } + ...entry, + npm: + latestData.libraries.find(prevEntry => entry.npmPkg === prevEntry.npmPkg)?.npm ?? {}, + } ); const finalData = dataWithFallback.filter(npmPkg => !existingPackages.includes(npmPkg)); @@ -246,7 +250,7 @@ async function buildAndScoreData() { ); } - if (!USE_DEBUG_REPOS) { + if (!(USE_DEBUG_REPOS || ONLY_WRITE_LOCAL_DATA_FILE)) { await uploadToStore(fileContent); } @@ -328,6 +332,13 @@ async function loadRepositoryDataAsync() { } async function fetchLatestData() { + if (ONLY_WRITE_LOCAL_DATA_FILE) { + console.log('⚠️ Only writing to local data file, skipping blob store fetch'); + return { + latestData: JSON.parse(fs.readFileSync(DATA_PATH, 'utf8')), + }; + } + const { blobs } = await list(); if (blobs?.length > 0) {