Skip to content

Commit 87c68b3

Browse files
authored
Merge pull request #16 from seamapi/inject-version-script
Add SDK headers
2 parents 3e2d8c9 + 92c72a8 commit 87c68b3

File tree

7 files changed

+237
-46
lines changed

7 files changed

+237
-46
lines changed

package-lock.json

Lines changed: 169 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"test:debug": "ava debug --break",
6161
"lint": "eslint --ignore-path .gitignore .",
6262
"prelint": "prettier --check --ignore-path .gitignore .",
63+
"prepack": "tsx ./prepack.ts",
6364
"postversion": "git push --follow-tags",
6465
"example": "tsx examples",
6566
"example:inspect": "tsx --inspect examples",
@@ -104,6 +105,7 @@
104105
"eslint-config-standard-with-typescript": "^39.0.0",
105106
"eslint-plugin-simple-import-sort": "^10.0.0",
106107
"eslint-plugin-unused-imports": "^3.0.0",
108+
"execa": "^8.0.1",
107109
"landlubber": "^1.0.0",
108110
"node-fetch": "^3.3.2",
109111
"prettier": "^3.0.0",

prepack.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { readFile, writeFile } from 'node:fs/promises'
2+
import { fileURLToPath } from 'node:url'
3+
4+
import { $ } from 'execa'
5+
6+
const versionFile = './src/lib/version.ts'
7+
8+
const main = async (): Promise<void> => {
9+
const version = await injectVersion(
10+
fileURLToPath(new URL(versionFile, import.meta.url)),
11+
)
12+
// eslint-disable-next-line no-console
13+
console.log(`✓ Version ${version} injected into ${versionFile}`)
14+
15+
const { command } = await $`tsc --project tsconfig.version.json`
16+
// eslint-disable-next-line no-console
17+
console.log(`✓ Rebuilt with '${command}'`)
18+
}
19+
20+
const injectVersion = async (path: string): Promise<string> => {
21+
const { version } = await readPackageJson()
22+
23+
if (version == null) {
24+
throw new Error('Missing version in package.json')
25+
}
26+
27+
const buff = await readFile(path)
28+
29+
const data = buff
30+
.toString()
31+
.replace(
32+
'const seamapiJavascriptHttpVersion = null',
33+
`const seamapiJavascriptHttpVersion = '${version}'`,
34+
)
35+
36+
await writeFile(path, data)
37+
38+
return version
39+
}
40+
41+
const readPackageJson = async (): Promise<{ version?: string }> => {
42+
const pkgBuff = await readFile(
43+
fileURLToPath(new URL('package.json', import.meta.url)),
44+
)
45+
return JSON.parse(pkgBuff.toString())
46+
}
47+
48+
await main()

0 commit comments

Comments
 (0)