From ada2d805af2a91ec3d9ae970b08eb987271a4fdc Mon Sep 17 00:00:00 2001 From: Pierre Martin Date: Thu, 13 Jun 2024 11:25:17 +0200 Subject: [PATCH] WIP of script generating a JSON used as source of truth --- .../debug-flags/debug-flags.json | 72 +++++++++++++++++++ docs/04-api-reference/debug-flags/index.md | 23 ++++++ genfromcode.mjs | 49 +++++++++++++ package.json | 2 + 4 files changed, 146 insertions(+) create mode 100644 docs/04-api-reference/debug-flags/debug-flags.json create mode 100644 docs/04-api-reference/debug-flags/index.md create mode 100644 genfromcode.mjs diff --git a/docs/04-api-reference/debug-flags/debug-flags.json b/docs/04-api-reference/debug-flags/debug-flags.json new file mode 100644 index 000000000..fbbf0fe30 --- /dev/null +++ b/docs/04-api-reference/debug-flags/debug-flags.json @@ -0,0 +1,72 @@ +{ + "front-commerce:adobe-b2b:companyCredit": "DESCRIPITON OF front-commerce:adobe-b2b:companyCredit", + "front-commerce:adobe-b2b:permissions": "DESCRIPITON OF front-commerce:adobe-b2b:permissions", + "front-commerce:attraqt": "DESCRIPITON OF front-commerce:attraqt", + "front-commerce:authorization": "DESCRIPITON OF front-commerce:authorization", + "front-commerce:big-commerce:address": "DESCRIPITON OF front-commerce:big-commerce:address", + "front-commerce:big-commerce:cache": "DESCRIPITON OF front-commerce:big-commerce:cache", + "front-commerce:big-commerce:cart": "DESCRIPITON OF front-commerce:big-commerce:cart", + "front-commerce:big-commerce:category": "DESCRIPITON OF front-commerce:big-commerce:category", + "front-commerce:big-commerce:checkout": "DESCRIPITON OF front-commerce:big-commerce:checkout", + "front-commerce:big-commerce:core": "DESCRIPITON OF front-commerce:big-commerce:core", + "front-commerce:big-commerce:customer": "DESCRIPITON OF front-commerce:big-commerce:customer", + "front-commerce:big-commerce:hacks": "DESCRIPITON OF front-commerce:big-commerce:hacks", + "front-commerce:big-commerce:layer": "DESCRIPITON OF front-commerce:big-commerce:layer", + "front-commerce:big-commerce:navigation": "DESCRIPITON OF front-commerce:big-commerce:navigation", + "front-commerce:big-commerce:order": "DESCRIPITON OF front-commerce:big-commerce:order", + "front-commerce:big-commerce:product": "DESCRIPITON OF front-commerce:big-commerce:product", + "front-commerce:big-commerce:reset-password": "DESCRIPITON OF front-commerce:big-commerce:reset-password", + "front-commerce:big-commerce:url": "DESCRIPITON OF front-commerce:big-commerce:url", + "front-commerce:big-commerce:wishlist": "DESCRIPITON OF front-commerce:big-commerce:wishlist", + "front-commerce:cache": "DESCRIPITON OF front-commerce:cache", + "front-commerce:cart": "DESCRIPITON OF front-commerce:cart", + "front-commerce:cart:cache": "DESCRIPITON OF front-commerce:cart:cache", + "front-commerce:cluster": "DESCRIPITON OF front-commerce:cluster", + "front-commerce:config": "DESCRIPITON OF front-commerce:config", + "front-commerce:contentful": "DESCRIPITON OF front-commerce:contentful", + "front-commerce:contentful:BlocksContentType": "DESCRIPITON OF front-commerce:contentful:BlocksContentType", + "front-commerce:contentful:preview": "DESCRIPITON OF front-commerce:contentful:preview", + "front-commerce:contribution-mode": "DESCRIPITON OF front-commerce:contribution-mode", + "front-commerce:core:graphql-codegen": "DESCRIPITON OF front-commerce:core:graphql-codegen", + "front-commerce:core:rate-limiter:limitRateByClientIp": "DESCRIPITON OF front-commerce:core:rate-limiter:limitRateByClientIp", + "front-commerce:country": "DESCRIPITON OF front-commerce:country", + "front-commerce:customer": "DESCRIPITON OF front-commerce:customer", + "front-commerce:customer:cache": "DESCRIPITON OF front-commerce:customer:cache", + "front-commerce:dynamic-routes": "DESCRIPITON OF front-commerce:dynamic-routes", + "front-commerce:elasticsearch": "DESCRIPITON OF front-commerce:elasticsearch", + "front-commerce:express": "DESCRIPITON OF front-commerce:express", + "front-commerce:graphql": "DESCRIPITON OF front-commerce:graphql", + "front-commerce:hipay": "DESCRIPITON OF front-commerce:hipay", + "front-commerce:httpauth": "DESCRIPITON OF front-commerce:httpauth", + "front-commerce:image": "DESCRIPITON OF front-commerce:image", + "front-commerce:in-stock-alert": "DESCRIPITON OF front-commerce:in-stock-alert", + "front-commerce:magento2:admin": "DESCRIPITON OF front-commerce:magento2:admin", + "front-commerce:magento2:search": "DESCRIPITON OF front-commerce:magento2:search", + "front-commerce:magento2:user": "DESCRIPITON OF front-commerce:magento2:user", + "front-commerce:maintenance-mode": "DESCRIPITON OF front-commerce:maintenance-mode", + "front-commerce:payment": "DESCRIPITON OF front-commerce:payment", + "front-commerce:payment:adyen": "DESCRIPITON OF front-commerce:payment:adyen", + "front-commerce:payment:buybox": "DESCRIPITON OF front-commerce:payment:buybox", + "front-commerce:payment:stripe": "DESCRIPITON OF front-commerce:payment:stripe", + "front-commerce:performance": "DESCRIPITON OF front-commerce:performance", + "front-commerce:prismic": "DESCRIPITON OF front-commerce:prismic", + "front-commerce:prismic:cache": "DESCRIPITON OF front-commerce:prismic:cache", + "front-commerce:prismic:fetch": "DESCRIPITON OF front-commerce:prismic:fetch", + "front-commerce:prismic:webhook": "DESCRIPITON OF front-commerce:prismic:webhook", + "front-commerce:remix:server:dynamic-routes": "DESCRIPITON OF front-commerce:remix:server:dynamic-routes", + "front-commerce:remote-schemas": "DESCRIPITON OF front-commerce:remote-schemas", + "front-commerce:rma": "DESCRIPITON OF front-commerce:rma", + "front-commerce:routes": "DESCRIPITON OF front-commerce:routes", + "front-commerce:scripts": "DESCRIPITON OF front-commerce:scripts", + "front-commerce:server": "DESCRIPITON OF front-commerce:server", + "front-commerce:server-events:cli": "DESCRIPITON OF front-commerce:server-events:cli", + "front-commerce:server-events:integrations:analytics": "DESCRIPITON OF front-commerce:server-events:integrations:analytics", + "front-commerce:server-events:integrations:webhook": "DESCRIPITON OF front-commerce:server-events:integrations:webhook", + "front-commerce:services:RateLimiter": "DESCRIPITON OF front-commerce:services:RateLimiter", + "front-commerce:services:events": "DESCRIPITON OF front-commerce:services:events", + "front-commerce:services:events:redis": "DESCRIPITON OF front-commerce:services:events:redis", + "front-commerce:shipping:chronorelais": "DESCRIPITON OF front-commerce:shipping:chronorelais", + "front-commerce:shipping:mondialrelay": "DESCRIPITON OF front-commerce:shipping:mondialrelay", + "front-commerce:smart-forms:capency": "DESCRIPITON OF front-commerce:smart-forms:capency", + "front-commerce:store-credit": "DESCRIPITON OF front-commerce:store-credit" +} diff --git a/docs/04-api-reference/debug-flags/index.md b/docs/04-api-reference/debug-flags/index.md new file mode 100644 index 000000000..a9d8129c3 --- /dev/null +++ b/docs/04-api-reference/debug-flags/index.md @@ -0,0 +1,23 @@ +# Debug flags + +Use `DEBUG=xxxx` to add debug flags. + +Available flags are detailed below. + +:::warning + +This is verbose, please don't use in production + +import flags from "./debug-flags.json" + +```mdx-code-block +export const JSONList = () => { + return Object.entries(flags).map(([key, value]) => ( +<> +

{key}

+

{value}

+ +))}; +``` + + diff --git a/genfromcode.mjs b/genfromcode.mjs new file mode 100644 index 000000000..902e5b3b0 --- /dev/null +++ b/genfromcode.mjs @@ -0,0 +1,49 @@ +const CODE_PATH = "/home/pierre/Code/core/main"; + +import { execSync } from "node:child_process"; +// const command = `rg -iF '"front-commerce:' | awk -F'd\\\\("' '{print $2}' | awk -F'"' '{print $1}' | sort -u`; +const command = `rg -F '"front-commerce:' .`; +// run the command and get output as array +const result = execSync(command, { + cwd: CODE_PATH, + encoding: "utf-8", + stdio: "pipe", +}); + +const lines = result.split("\n"); + +// extract the namespace of d() function +const res = lines + .map((line) => { + const match = line.match(/\("([^"]+)"/); + return match && match[1]; + }) + .filter(Boolean) + .sort(); + +// unique scopes +const unique = [...new Set(res)]; + +// read existing debug flags from docs/04-api-reference/debug-flags.json and update with the new ones +// warn if one doesn't exist +import { readFileSync, writeFileSync } from "node:fs"; +const debugFlags = JSON.parse( + readFileSync( + `${process.cwd()}/docs/04-api-reference/debug-flags/debug-flags.json`, + "utf-8" + ) +); + +const newFlags = unique.filter((flag) => { + if (debugFlags[flag]) { + return false; + } + return true; +}); +if (newFlags.length) { + console.log("New flags must be documented:"); + console.log(newFlags); + process.exit(1); +} + +console.log(unique); diff --git a/package.json b/package.json index 0ebb63296..23539aa40 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,10 @@ "private": true, "scripts": { "docusaurus": "docusaurus", + "predev": "pnpm run genfromcode", "dev": "pnpm run start", "start": "pnpm run docusaurus start", + "genfromcode": "node ./genfromcode.mjs", "build": "pnpm run docusaurus build", "swizzle": "pnpm run docusaurus swizzle", "deploy": "pnpm run docusaurus deploy",