Takazudo Modular Docs

Type to search...

to open search from anywhere

l-sync-mercari-ids

Sync Mercari product IDs from downloaded CSV to product-master-data.mjs. Use when: (1) After downloading a new CSV from Mercari Shops, (2) Before running csv-to-md to avoid unknown__ files, (3) User s...

Sync Mercari Product IDs

Backfill missing mercariProductId values in src/data/product-master-data.mjs by matching products to rows in a Mercari Shops CSV export.

When to Use

Run this after downloading a new CSV from Mercari Shops and before running csv-to-md. This ensures newly registered products get their IDs in master data, so csv-to-md produces properly named {slug}__*.md files instead of unknown__* files.

How It Works

The skill ships a Node script that does the matching and (optionally) the editing. The script is the source of truth for the matching logic — read it before deviating.

Script: .claude/skills/l-sync-mercari-ids/sync.mjs

It:

  1. Picks up the CSV (positional arg, or the latest mercari-data/product_data_*.csv if omitted).
  2. Parses with PapaParse (from sub-packages/mercari-viewer/node_modules/papaparse), pulling 商品ID and 商品名 from each row.
  3. Loads master data + brand list:
    • import { allProducts } from 'src/data/product-master-data.mjs' (named export)
    • import { allBrands } from 'src/data/brands.mjs' (named export)
    • The brand lookup key is brand.slug (matched against product.brand); the human-facing name used in the CSV is brand.name.
  4. For each product missing mercariProductId, builds the expected CSV name as "{brand.name}: {product.name}" (e.g., "Weston Precision Audio: Trivium") and looks it up in the CSV.
  5. Reports three sections:
    • Matched — products that will (or would) be filled in.
    • No CSV match — products still missing mercariProductId after the run; usually means the product isn’t listed on Mercari Shops yet.
    • Orphan CSV rows — CSV entries whose name doesn’t match any product’s "{brand.name}: {product.name}". Often indicates new products not yet added to master data, or products whose Mercari name diverged from master.name (those still get matched directly when their mercariProductId is already set, so orphans here are mostly informational).
  6. With --apply, edits product-master-data.mjs in place: scoped regex replacement of mercariProductId: '' to mercariProductId: '<id>' within the matched product’s object literal.

Usage

# Dry-run against the latest CSV (default)
node .claude/skills/l-sync-mercari-ids/sync.mjs

# Dry-run against a specific CSV
node .claude/skills/l-sync-mercari-ids/sync.mjs mercari-data/product_data_2026-05-01.csv

# Apply edits to product-master-data.mjs
node .claude/skills/l-sync-mercari-ids/sync.mjs --apply
node .claude/skills/l-sync-mercari-ids/sync.mjs mercari-data/product_data_2026-05-01.csv --apply

Always start with a dry-run, eyeball the report, then re-run with --apply only if the matches look right.

After Applying

  1. Validate the file still parses:

    node --input-type=module -e "import('./src/data/product-master-data.mjs').then(() => console.log('OK'))"
  2. git diff src/data/product-master-data.mjs and confirm only the intended mercariProductId lines changed.

  3. Commit with [data] scope, e.g. [data] Sync Mercari product IDs from <date> CSV.

Notes

  • The script only fills products that are already in master data with mercariProductId: ''. It does not add new products — that needs /l-add-product-page first.
  • “No CSV match” entries usually mean the product is not yet listed on Mercari Shops; no action needed unless you expected it to be there.
  • Brand and product schemas (brand.slug, brand.name, allProducts / allBrands named exports) are validated at startup; the script exits with a clear error if they drift.
  • If the regex apply fails for any matched slug, the script aborts without writing — fall back to manual Edit for that entry, or fix the script.
  • Run csv-to-md after this skill to regenerate markdown files with proper slugs.