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:
- Picks up the CSV (positional arg, or the latest
mercari-data/product_data_*.csvif omitted). - Parses with PapaParse (from
sub-packages/mercari-viewer/node_modules/papaparse), pulling商品IDand商品名from each row. - 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 againstproduct.brand); the human-facing name used in the CSV isbrand.name.
- 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. - Reports three sections:
- Matched — products that will (or would) be filled in.
- No CSV match — products still missing
mercariProductIdafter 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 frommaster.name(those still get matched directly when theirmercariProductIdis already set, so orphans here are mostly informational).
- With
--apply, editsproduct-master-data.mjsin place: scoped regex replacement ofmercariProductId: ''tomercariProductId: '<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
-
Validate the file still parses:
node --input-type=module -e "import('./src/data/product-master-data.mjs').then(() => console.log('OK'))" -
git diff src/data/product-master-data.mjsand confirm only the intendedmercariProductIdlines changed. -
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-pagefirst. - “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/allBrandsnamed 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
Editfor that entry, or fix the script. - Run
csv-to-mdafter this skill to regenerate markdown files with proper slugs.