-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathupdate-meta.ts
38 lines (34 loc) · 991 Bytes
/
update-meta.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import fs from "fs"
import path from "path"
import { ESLint } from "eslint"
import { name, version } from "../package.json"
import { getNewVersion } from "./lib/changesets-util"
const META_PATH = path.join(__dirname, "../src/meta.ts")
void main()
/** main */
async function main() {
if (!fs.existsSync(META_PATH)) {
fs.writeFileSync(META_PATH, "", "utf8")
}
const eslint = new ESLint({ fix: true })
const [result] = await eslint.lintText(
`/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "yarn update"
*/
export const name = ${JSON.stringify(name)} as const;
export const version = ${JSON.stringify(await getVersion())} as const;
`,
{ filePath: META_PATH },
)
fs.writeFileSync(META_PATH, result.output!, "utf8")
}
/** Get version */
function getVersion() {
// eslint-disable-next-line no-process-env -- ignore
if (process.env.IN_VERSION_CI_SCRIPT) {
return getNewVersion()
}
return version
}