generated from parzh/package-javascript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
compose-version-number.impl.ts
45 lines (35 loc) · 1 KB
/
compose-version-number.impl.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
39
40
41
42
43
44
45
import data from "./data.json";
import packageJson from "./package.json";
/** @private */
interface DateSimple {
readonly year: string;
readonly month: string;
readonly day: string;
}
/** @private */
function pad(padding: 2 | 4, input: string | number): string {
const output = String(input).padStart(padding, "0");
return output
}
/** @private */
function createDateSimple(date: Date): DateSimple {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return {
year: pad(4, year),
month: pad(2, month),
day: pad(2, day),
};
}
export default function composeVersionNumber(): string {
const dataVersionDate = new Date(data.$attr.Pblshd)
const { year, month, day } = createDateSimple(dataVersionDate);
const [ version ] = packageJson.version.split(/[+-]/, 1);
const [ , minor, patch ] = version.split(".");
const result = `${year}${month}${day}.${minor}.${patch}`;
return result;
}
if (require.main === module) {
console.log(composeVersionNumber());
}