Skip to content

Commit

Permalink
build: Fix README version update (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x authored Jul 21, 2023
1 parent a4f7cc9 commit 340e570
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function App() {
<seam-device-table publishable-key="your_publishable_key"></seam-device-table>
<script
type="module"
src="https://react.seam.co/v/_________VERSION_________/dist/elements.js"
src="https://react.seam.co/v/1.31.0/dist/elements.js"
></script>
</body>
```
Expand Down
22 changes: 9 additions & 13 deletions preversion.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import { readFile, writeFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'

import { $ } from 'execa'

import { readPackageJson } from './vite.config.js'

export const files = ['./README.md']

export const versionPlaceholder = '_________VERSION_________'
import {
readPackageJson,
versionFiles,
versionPlaceholder,
} from './vite.config.js'

const main = async (): Promise<void> => {
await Promise.all(
files.map(async (file) => {
const version = await injectVersionPlaceholder(
versionFiles.map(async (file) => {
await injectVersionPlaceholder(
fileURLToPath(new URL(file, import.meta.url))
)
// eslint-disable-next-line no-console
console.log(`✓ Version ${version} injected into ${file}`)
await $`git add ${file}`
console.log(`✓ Version placeholder injected into ${file}`)
})
)
}

const injectVersionPlaceholder = async (path: string): Promise<string> => {
const injectVersionPlaceholder = async (path: string): Promise<void> => {
const { version } = await readPackageJson()

if (version == null) {
Expand All @@ -32,7 +29,6 @@ const injectVersionPlaceholder = async (path: string): Promise<string> => {
const buff = await readFile(path)
const data = buff.toString().replaceAll(version, versionPlaceholder)
await writeFile(path, data)
return version
}

await main()
12 changes: 9 additions & 3 deletions version.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { readFile, writeFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'

import { files, versionPlaceholder } from './preversion.js'
import { readPackageJson } from './vite.config.js'
import { $ } from 'execa'

import {
readPackageJson,
versionFiles,
versionPlaceholder,
} from './vite.config.js'

const main = async (): Promise<void> => {
await Promise.all(
files.map(async (file) => {
versionFiles.map(async (file) => {
const version = await injectVersion(
fileURLToPath(new URL(file, import.meta.url))
)
// eslint-disable-next-line no-console
console.log(`✓ Version ${version} injected into ${file}`)
await $`git add ${file}`
})
)
}
Expand Down
4 changes: 4 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ export const readPackageJson = async (): Promise<{ version?: string }> => {
)
return JSON.parse(pkgBuff.toString())
}

export const versionFiles = ['./README.md']

export const versionPlaceholder = '_________VERSION_________'

0 comments on commit 340e570

Please sign in to comment.