Skip to content
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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?
Expand Down
21 changes: 16 additions & 5 deletions scripts/build-and-score-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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));

Expand All @@ -246,7 +250,7 @@ async function buildAndScoreData() {
);
}

if (!USE_DEBUG_REPOS) {
if (!(USE_DEBUG_REPOS || ONLY_WRITE_LOCAL_DATA_FILE)) {
await uploadToStore(fileContent);
}

Expand Down Expand Up @@ -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) {
Expand Down