UNPKG

1.88 kBJavaScriptView Raw
1// node
2const fs = require('fs')
3const path = require('path')
4
5// npm
6const fetch = require('node-fetch')
7const semver = require('semver')
8
9// pkg
10const pkg = require('../package.json')
11
12const ghBase = 'https://api.github.com'
13const repoUrlPath = 'fomantic/Fomantic-UI'
14const npmBase = 'https://registry.npmjs.org'
15const npmPackage = 'fomantic-ui'
16
17
18const 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
24const getCurrentNpmVersion = async function () {
25 return fetch(`${npmBase}/${npmPackage}`)
26 .then(r => r.json())
27 .then(p => p['dist-tags'].nightly)
28}
29
30const 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
38const 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
57getNightlyVersion()
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})`))