diff --git a/package-lock.json b/package-lock.json index a5500da..1aa607d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -103,6 +103,7 @@ "prettier-plugin-organize-imports": "^3.2.2", "prettier-plugin-tailwindcss": "^0.2.8", "tailwindcss": "^3.3.2", + "toml": "^3.0.0", "ts-node": "^10.9.1", "tsconfig-paths": "^4.2.0", "tsx": "^3.12.7", diff --git a/package.json b/package.json index 585731e..adae3f7 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,9 @@ "typecheck": "tsc", "validate": "run-p lint typecheck test", "lint-staged": "lint-staged", - "build-crd": "ts-node --esm scripts/crd-builder/index.ts /Users/wking/sites/crunchy/savannah/config/crd/bases /Users/wking/sites/crunchy/crunchy-postgres-for-kubernetes-private-docs/public/5.2.2/references/crd", - "migrate-docs": "ts-node --esm scripts/migrate-docs.ts /Users/wking/sites/crunchy/crunchy-postgres-for-kubernetes-private-docs/public/5.2.2" + "build-crd": "ts-node --esm scripts/crd-builder/index.ts /Users/wking/sites/crunchy/savannah/config/crd/bases /Users/wking/sites/crunchy/crunchy-postgres-for-kubernetes-private-docs/public/5.2.0/references/crd", + "migrate-docs": "ts-node --esm scripts/migrate-docs.ts /Users/wking/sites/crunchy/crunchy-postgres-for-kubernetes-private-docs/public/5.2.0", + "build-config": "ts-node --esm scripts/config-builder/index.ts /Users/wking/sites/crunchy/savannah/docs/config.toml /Users/wking/sites/crunchy/crunchy-postgres-for-kubernetes-private-docs/public/5.2.0" }, "lint-staged": { "*.mdx": "npm run lint:files" @@ -129,6 +130,7 @@ "prettier-plugin-organize-imports": "^3.2.2", "prettier-plugin-tailwindcss": "^0.2.8", "tailwindcss": "^3.3.2", + "toml": "^3.0.0", "ts-node": "^10.9.1", "tsconfig-paths": "^4.2.0", "tsx": "^3.12.7", diff --git a/scripts/config-builder/index.ts b/scripts/config-builder/index.ts new file mode 100644 index 0000000..07a0053 --- /dev/null +++ b/scripts/config-builder/index.ts @@ -0,0 +1,59 @@ +import { existsSync, mkdirSync } from 'fs' +import { readFile, writeFile } from 'fs/promises' +import { join } from 'path' +import toml from 'toml' +import { z } from 'zod' + +const configKeys = [ + 'operatorVersion', + 'imageCrunchyPostgres', + 'imageCrunchyPostgresPrivate', + 'imageCrunchyPGBackrest', + 'imageCrunchyPGBackrestPrivate', + 'imageCrunchyPGBouncer', + 'imageCrunchyPGUpgrade', + 'imageCrunchyExporter', + 'imageCrunchyPGAdmin', + 'operatorRepository', + 'operatorRepositoryPrivate', + 'postgresOperatorTag', + 'PGBouncerComponentTagUbi8', + 'PGBouncerTagUbi8', + 'postgres14GIS32ComponentTagUbi8', + 'postgres14GIS32TagUbi8', + 'fromPostgresVersion', + 'postgresVersion', + 'postgresVersion13', + 'postGISVersion', + 'operatorHelmRepository', +] + +async function main(input: string, output: string) { + if (!existsSync(output)) { + mkdirSync(output, { recursive: true }) + } + + try { + const configToml = await readFile(input, 'utf-8') + const data = toml.parse(configToml) + const { params } = configValidator.parse(data) + const config: Record = {} + + for (const key of configKeys) { + const foundParam = params?.[key] + if (foundParam) { + config[key] = foundParam + } + } + + await writeFile(join(output, 'config.json'), JSON.stringify(config)) + } catch (e) { + console.error(e) + } +} + +const configValidator = z.object({ + params: z.record(z.string().or(z.boolean())), +}) + +main(process.argv[2], process.argv[3]) diff --git a/scripts/migrate-docs.ts b/scripts/migrate-docs.ts index 814e971..75086bc 100644 --- a/scripts/migrate-docs.ts +++ b/scripts/migrate-docs.ts @@ -36,6 +36,20 @@ async function transform(rootPath: string) { // Replace the search value with the replace value in the chunk let stringChunk = chunk.toString() + // Adding missing line break from source + stringChunk = stringChunk.replace( + '### Step 2: Install PGO, the Postgres Operator', + '\n### Step 2: Install PGO, the Postgres Operator', + ) + stringChunk = stringChunk.replace( + 'All Pods now have `enableServiceLinks` set to `false` in order to ensure injected environment variables do not conflict with the various applications running within.', + '\nAll Pods now have `enableServiceLinks` set to `false` in order to ensure injected environment variables do not conflict with the various applications running within.', + ) + stringChunk = stringChunk.replace( + /```\n{{% \/notice %}}/gm, + '```\n\n{{% /notice %}}', + ) + stringChunk = replaceBr(stringChunk) stringChunk = replaceParams(stringChunk) stringChunk = replaceRefs(stringChunk, filePath!)