Commit 2aa179dd by Lin Wang

feat: upload the nav info to google sheet

parent d95ef784
......@@ -15,15 +15,24 @@ async function uploadAllToSheets() {
});
const sheets = google.sheets({ version: 'v4', auth });
const dir = join(__dirname, useAiSelectors ? 'diffAIWithBaseline' : 'diffWithBaseline');
const files = readdirSync(dir).filter(f => f.endsWith('.json'));
// Determine directories to upload: both diff and nav folders for AI or baseline
const dirNames = useAiSelectors
? ['diffAINavWithBaseline', 'diffAIWithBaseline']
: ['diffNavWithBaseline', 'diffWithBaseline'];
const files = dirNames.flatMap(subdir => {
const d = join(__dirname, subdir);
return readdirSync(d)
.filter(f => f.endsWith('.json'))
.map(f => ({ subdir, file: f, path: join(d, f) }));
});
// Fetch existing sheet names
const { data: spreadsheet } = await sheets.spreadsheets.get({ spreadsheetId });
const existing = spreadsheet.sheets?.map((s: any) => s.properties?.title || '') || [];
for (const file of files) {
const sheetName = file.replace(/\.json$/, '');
for (const { subdir, file, path } of files) {
// Prefix sheet name with directory to distinguish diff vs nav
const sheetName = `${subdir}-${file.replace(/\.json$/, '')}`;
if (!existing.includes(sheetName)) {
// Create new sheet
await sheets.spreadsheets.batchUpdate({
......@@ -34,7 +43,7 @@ async function uploadAllToSheets() {
});
}
const raw = readFileSync(join(dir, file), 'utf-8');
const raw = readFileSync(path, 'utf-8');
const data = JSON.parse(raw);
// Always clear existing values, even for empty data, to overwrite the sheet
await sheets.spreadsheets.values.clear({ spreadsheetId, range: `'${sheetName}'` });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment