Skip to content

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
Signed-off-by: Diógenes Fernandes <[email protected]>

deploy

Signed-off-by: Diógenes Fernandes <[email protected]>
  • Loading branch information
diofeher committed Feb 27, 2025
1 parent bf8278b commit 5176c73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
4 changes: 2 additions & 2 deletions search/worker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 10 additions & 25 deletions search/worker/scripts/feed-data-r2.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// This script is used to retrieve data generated by `go run generate.go` at backend folder.
// It will generate registry data that will be used by this script to feed into wrangler dev folder, mimicking a R2 bucket.
// This script expects data will be at /tmp/registry.
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const fs = require('fs');
const path = require('path');
const { exec } = require('node:child_process');

const BATCH_SIZE = 10
const DIR_PATH = '/tmp/registry';
const directoryPath = '/tmp/registry';

const putObject = (directoryPath) => (filename) => {
return new Promise((resolve) => {
const realFilePath = path.join(directoryPath, filename);
fs.readdir(directoryPath, { recursive: true }, (err, files) => {
if (err) {
console.error('Error reading directory:', err);
return;
}

files.forEach(fileName => {
const realFilePath = path.join(directoryPath, fileName);
const r2Name = realFilePath.replace(directoryPath, "");

const cmd = `npx wrangler r2 object put registry-ui-api${r2Name} --file ${realFilePath} --local`
Expand All @@ -21,23 +23,6 @@ const putObject = (directoryPath) => (filename) => {
console.log(stdout);
console.error(stderr);
});
resolve();
});
}

const run = async () => {
fs.readdir(DIR_PATH, { recursive: true }, async (err, files) => {
if (err) {
console.error('Error reading directory:', err);
return;
}

let i = 1;
while (files.length) {
await Promise.all(files.splice(0, BATCH_SIZE).map(putObject(DIR_PATH)));
i++;
}
});
}

await run()
});

0 comments on commit 5176c73

Please sign in to comment.