-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathprecompile.mjs
30 lines (26 loc) · 1.02 KB
/
precompile.mjs
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
// This script updates packageVersion.ts to contain the version from
// package.json. That file is gitignored and this script gets run by
// "precompile".
//
// This assumes that we always publish packages from a fresh checkout rather
// than running `changeset version` and then `changeset publish` from the same
// checkout without `npm run compile` in between.
//
// This script expects to be run from the project root (as `npm run` does).
import assert from 'assert';
import path from 'path';
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
const { version } = JSON.parse(
readFileSync(path.join('packages', 'server', 'package.json'), 'utf-8'),
);
assert.strictEqual(
typeof version,
'string',
'"version" field missing from package.json',
);
const versionTSDirectory = path.join('packages', 'server', 'src', 'generated');
mkdirSync(versionTSDirectory, { recursive: true });
writeFileSync(
path.join(versionTSDirectory, 'packageVersion.ts'),
`export const packageVersion = ${JSON.stringify(version)};\n`,
);