Skip to content

Commit 44009e9

Browse files
authored
fixes for development purposes & locally stored data (#1730)
1 parent 83710df commit 44009e9

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ You should be able to visit `localhost:3000` in your browser.
166166

167167
- Visit https://github.com/settings/developers to get your keys (don't worry about the callback URL, put whatever you want).
168168
- Load the `GITHUB_TOKEN` environment variable into your shell.
169+
- 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.
169170

170171
This command creates site data in `./assets/data.json`
171172

@@ -220,7 +221,7 @@ https://reactnative.directory/api/libraries
220221

221222
## I don't like how you calculate scores.
222223

223-
- Submit a PR with changes to `scripts/calculate-score.js`.
224+
- Submit a PR with changes to `scripts/calculate-score.ts`.
224225
- You have all the power! Tell us what you want.
225226

226227
## How do I deploy my own version of this?

scripts/build-and-score-data.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const SCRAPE_GH_IMAGES = false;
3030
const DATA_PATH = path.resolve('assets', 'data.json');
3131
const GITHUB_RESULTS_PATH = path.join('scripts', 'raw-github-results.json');
3232

33+
// If script should only write to the local data file and not upload to the store.
34+
// This is useful for debugging and testing purposes.
35+
const ONLY_WRITE_LOCAL_DATA_FILE = false;
36+
3337
const invalidRepos = [];
3438
const mismatchedRepos = [];
3539

@@ -228,10 +232,10 @@ async function buildAndScoreData() {
228232
Object.keys(entry.npm).length > 0
229233
? entry
230234
: {
231-
...entry,
232-
npm:
233-
latestData.libraries.find(prevEntry => entry.npmPkg === prevEntry.npmPkg)?.npm ?? {},
234-
}
235+
...entry,
236+
npm:
237+
latestData.libraries.find(prevEntry => entry.npmPkg === prevEntry.npmPkg)?.npm ?? {},
238+
}
235239
);
236240
const finalData = dataWithFallback.filter(npmPkg => !existingPackages.includes(npmPkg));
237241

@@ -246,7 +250,7 @@ async function buildAndScoreData() {
246250
);
247251
}
248252

249-
if (!USE_DEBUG_REPOS) {
253+
if (!(USE_DEBUG_REPOS || ONLY_WRITE_LOCAL_DATA_FILE)) {
250254
await uploadToStore(fileContent);
251255
}
252256

@@ -328,6 +332,13 @@ async function loadRepositoryDataAsync() {
328332
}
329333

330334
async function fetchLatestData() {
335+
if (ONLY_WRITE_LOCAL_DATA_FILE) {
336+
console.log('⚠️ Only writing to local data file, skipping blob store fetch');
337+
return {
338+
latestData: JSON.parse(fs.readFileSync(DATA_PATH, 'utf8')),
339+
};
340+
}
341+
331342
const { blobs } = await list();
332343

333344
if (blobs?.length > 0) {

0 commit comments

Comments
 (0)