-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for newer skuba versions (#300)
- Loading branch information
Showing
10 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'skuba': minor | ||
--- | ||
|
||
**configure, help, init:** Check for newer skuba versions | ||
|
||
skuba will now print an upgrade command if there is a newer version available. You can now use a global installation without worrying that you're setting up new repos using outdated templates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { showHelp } from '../utils/help'; | ||
import { showLogo } from '../utils/logo'; | ||
import { showLogoAndVersionInfo } from '../utils/logo'; | ||
|
||
export const help = async () => { | ||
await showLogo(); | ||
await showLogoAndVersionInfo(); | ||
|
||
showHelp(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,59 @@ | ||
import latestVersion from 'latest-version'; | ||
|
||
import { getSkubaManifest } from './manifest'; | ||
|
||
const sleep = (ms: number) => | ||
new Promise<void>((resolve) => setTimeout(resolve, ms)); | ||
|
||
const latestSkubaVersion = async (): Promise<string | null> => { | ||
try { | ||
// Don't pull an Apple; bail out before holding up the command for too long | ||
const result = await Promise.race([latestVersion('skuba'), sleep(2_000)]); | ||
|
||
return typeof result === 'string' ? result : null; | ||
} catch { | ||
return null; | ||
} | ||
}; | ||
|
||
export const getSkubaVersion = async (): Promise<string> => { | ||
const { version } = await getSkubaManifest(); | ||
|
||
return version; | ||
}; | ||
|
||
type SkubaVersionInfo = | ||
| { | ||
isStale: true; | ||
|
||
local: string; | ||
latest: string; | ||
} | ||
| { | ||
isStale: false; | ||
|
||
local: string; | ||
latest: string | null; | ||
}; | ||
|
||
export const getSkubaVersionInfo = async (): Promise<SkubaVersionInfo> => { | ||
const [local, latest] = await Promise.all([ | ||
getSkubaVersion(), | ||
latestSkubaVersion(), | ||
]); | ||
|
||
if (latest === null) { | ||
// Assume we're up to date if we can't reach the npm registry | ||
return { | ||
isStale: false, | ||
local, | ||
latest, | ||
}; | ||
} | ||
|
||
return { | ||
isStale: latest !== local, | ||
local, | ||
latest, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters