Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added ability to pass a custom message #19

Merged
merged 9 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ warns if there is a newer version of CLI released
[![License](https://img.shields.io/npm/l/@oclif/plugin-warn-if-update-available.svg)](https://github.com/oclif/plugin-warn-if-update-available/blob/master/package.json)

<!-- toc -->
* [What is this?](#what-is-this)
* [How it works](#how-it-works)
* [Installation](#installation)
* [Configuration](#configuration)
- [@oclif/plugin-warn-if-update-available](#oclifplugin-warn-if-update-available)
- [What is this?](#what-is-this)
- [How it works](#how-it-works)
- [Installation](#installation)
- [Configuration](#configuration)
- [Example configuration](#example-configuration)
<!-- tocstop -->

# What is this?
Expand Down Expand Up @@ -48,6 +50,7 @@ In `package.json`, set `oclif['warn-if-update-available']` to an object with
any of the following configuration properties:

- `timeoutInDays` - Duration between update checks. Defaults to 60.
- `message` - Customize update message.
- `registry` - URL of registry. Defaults to the public npm registry: `https://registry.npmjs.org`
- `authorization` - Authorization header value for registries that require auth.

Expand All @@ -61,6 +64,7 @@ any of the following configuration properties:
],
"warn-if-update-available": {
"timeoutInDays": 7,
"message": "<%= config.name %> update available from <%= chalk.greenBright(config.version) %> to <%= chalk.greenBright(latest) %>.",
"registry": "https://my.example.com/module/registry",
"authorization": "Basic <SOME READ ONLY AUTH TOKEN>"
}
Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@
"author": "Jeff Dickey @jdxcode",
"bugs": "https://github.com/oclif/plugin-warn-if-update-available/issues",
"dependencies": {
"@oclif/command": "^1.5.3",
"@oclif/config": "^1.8.7",
"@oclif/command": "^1.5.10",
"@oclif/config": "^1.12.8",
"@oclif/errors": "^1.2.2",
"chalk": "^2.4.1",
"debug": "^4.1.0",
"fs-extra": "^7.0.0",
"http-call": "^5.2.2",
"lodash.template": "^4.4.0",
"semver": "^5.6.0"
},
"devDependencies": {
"@oclif/dev-cli": "^1.19.1",
"@oclif/test": "^1.2.1",
"@oclif/test": "^1.2.4",
"@oclif/tslint": "^3.1.0",
"@types/chai": "^4.1.6",
"@types/fs-extra": "^5.0.4",
"@types/mocha": "^5.2.5",
"@types/node": "^10.11.7",
"@types/fs-extra": "^5.0.5",
"@types/lodash.template": "^4.4.5",
"@types/mocha": "^5.2.6",
"@types/node": "^11.9.4",
"@types/semver": "^5.5.0",
"chai": "^4.2.0",
"globby": "^8.0.1",
"mocha": "^5.2.0",
"ts-node": "^7.0.1",
"globby": "^9.0.0",
"mocha": "^6.0.0",
"ts-node": "^8.0.2",
"tslib": "^1.9.3",
"tslint": "^5.11.0",
"typescript": "^3.1.3"
"typescript": "^3.3.3"
},
"engines": {
"node": ">=8.0.0"
Expand Down
10 changes: 9 additions & 1 deletion src/hooks/init/check-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Hook} from '@oclif/config'
import Chalk from 'chalk'
import {spawn} from 'child_process'
import * as fs from 'fs-extra'
import Template = require('lodash.template')
import * as path from 'path'
import * as semver from 'semver'

Expand All @@ -13,6 +14,7 @@ const hook: Hook<'init'> = async function ({config}) {
// Destructure package.json configuration with defaults
const {
timeoutInDays = 60,
message = '<%= config.name %> update available from <%= chalk.greenBright(config.version) %> to <%= chalk.greenBright(latest) %>.',
registry = 'https://registry.npmjs.org',
authorization = '',
} = (config.pjson.oclif as any)['warn-if-update-available'] || {}
Expand All @@ -28,7 +30,13 @@ const hook: Hook<'init'> = async function ({config}) {
}
if (distTags && distTags.latest && semver.gt(distTags.latest.split('-')[0], config.version.split('-')[0])) {
const chalk: typeof Chalk = require('chalk')
this.warn(`${config.name} update available from ${chalk.greenBright(config.version)} to ${chalk.greenBright(distTags.latest)}`)
const template: typeof Template = require('lodash.template')
// Default message if the user doesn't provide one
this.warn(template(message)({
chalk,
config,
...distTags,
}))
}
} catch (err) {
if (err.code !== 'ENOENT') throw err
Expand Down
Loading