-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathgen-version.js
38 lines (30 loc) · 996 Bytes
/
gen-version.js
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
'use strict';
const { version } = require('../package.json');
const { writeGeneratedFile } = require('./utils.js');
const versionMatch = /^(\d+)\.(\d+)\.(\d+)-?(.*)?$/.exec(version);
if (!versionMatch) {
throw new Error('Version does not match semver spec: ' + version);
}
const [, major, minor, patch, preReleaseTag] = versionMatch;
const body = `
// Note: This file is autogenerated using "resources/gen-version.js" script and
// automatically updated by "npm version" command.
/**
* A string containing the version of the GraphQL.js library
*/
export const version = '${version}' as string;
/**
* An object containing the components of the GraphQL.js version string
*/
export const versionInfo = Object.freeze({
major: ${major} as number,
minor: ${minor} as number,
patch: ${patch} as number,
preReleaseTag: ${
preReleaseTag ? `'${preReleaseTag}'` : 'null'
} as string | null,
});
`;
if (require.main === module) {
writeGeneratedFile('./src/version.ts', body);
}