Skip to content

Commit

Permalink
Finalizing temp updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wking-io committed Aug 30, 2023
1 parent 305b005 commit 85deb29
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
59 changes: 59 additions & 0 deletions scripts/config-builder/index.ts
Original file line number Diff line number Diff line change
@@ -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<string, string | boolean> = {}

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])
14 changes: 14 additions & 0 deletions scripts/migrate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand Down

0 comments on commit 85deb29

Please sign in to comment.