1 |
|
2 | const fs = require('fs')
|
3 | const path = require('path')
|
4 |
|
5 |
|
6 | const fetch = require('node-fetch')
|
7 | const semver = require('semver')
|
8 |
|
9 |
|
10 | const pkg = require('../package.json')
|
11 |
|
12 | const ghBase = 'https://api.github.com'
|
13 | const repoUrlPath = 'fomantic/Fomantic-UI'
|
14 | const npmBase = 'https://registry.npmjs.org'
|
15 | const npmPackage = 'fomantic-ui'
|
16 |
|
17 |
|
18 | const getGitHubVersion = async function () {
|
19 | return fetch(`${ghBase}/repos/${repoUrlPath}/milestones`)
|
20 | .then(r => r.json())
|
21 | .then(milestones => milestones.filter(m => m.title.indexOf('x') === -1).map(m => m.title).sort()[0])
|
22 | }
|
23 |
|
24 | const getCurrentNpmVersion = async function () {
|
25 | return fetch(`${npmBase}/${npmPackage}`)
|
26 | .then(r => r.json())
|
27 | .then(p => p['dist-tags'].nightly)
|
28 | }
|
29 |
|
30 | const getNpmPreRelease = async function () {
|
31 | return fetch(`${npmBase}/${npmPackage}`)
|
32 | .then(r => r.json())
|
33 | .then(p => p['dist-tags'].nightly)
|
34 | .then(v => semver.prerelease(v))
|
35 | .then(pr => pr === null ? ['beta', 0] : pr)
|
36 | }
|
37 |
|
38 | const getNightlyVersion = async function () {
|
39 | const nextVersion = await getGitHubVersion()
|
40 | const currentNightlyWithPre = semver.parse(await getCurrentNpmVersion())
|
41 | const currentNightly = `${currentNightlyWithPre.major}.${currentNightlyWithPre.minor}.${currentNightlyWithPre.patch}`
|
42 |
|
43 | if (!semver.gt(nextVersion, currentNightly)) {
|
44 | if (semver.minor(nextVersion) === semver.minor(currentNightly)) {
|
45 | const preRelease = await getNpmPreRelease()
|
46 |
|
47 | return semver.inc(
|
48 | `${nextVersion}-${preRelease[0]}.${preRelease[1]}`,
|
49 | 'prerelease'
|
50 | )
|
51 | }
|
52 | }
|
53 |
|
54 | return `${nextVersion}-beta.0`
|
55 | }
|
56 |
|
57 | getNightlyVersion()
|
58 | .then(nightlyVersion => {
|
59 | pkg.version = nightlyVersion
|
60 | })
|
61 | .then(() => {
|
62 | fs.writeFileSync(
|
63 | path.resolve(__dirname, '../package.json'),
|
64 | JSON.stringify(pkg, null, 2)
|
65 | )
|
66 | })
|
67 | .then(() => console.log(`Done (${pkg.version})`))
|