Skip to content

Commit

Permalink
refactor: use lodash.template
Browse files Browse the repository at this point in the history
  • Loading branch information
Aghassi committed Jan 27, 2019
1 parent b9e3196 commit e4475a8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +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` - A custome message to display after the update notification.
- `message` - A custom message to display after the update notification.
- `registry` - URL of registry. Defaults to the public npm registry: `https://registry.npmjs.org`
- `authorization` - Authorization header value for registries that require auth.

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"@oclif/command": "^1.5.3",
"@oclif/config": "^1.8.7",
"@oclif/errors": "^1.2.2",
"@types/lodash.template": "4.4.4",
"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": {
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/init/check-update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Hook} from '@oclif/config'
import Chalk from 'chalk'
import {spawn} from 'child_process'
import template = require('lodash.template');
import * as fs from 'fs-extra'
import * as path from 'path'
import * as semver from 'semver'
Expand Down Expand Up @@ -30,12 +31,12 @@ 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')
// Default message if the user doesn't provide one
const defaultMessage = `${config.name} update available from ${chalk.greenBright(config.version)} to ${chalk.greenBright(distTags.latest)}`;
const messageTemplate = template(`${config.name} update available from ${chalk.greenBright(config.version)} to ${chalk.greenBright(distTags.latest)}. <%= message %>`);
if (message.length !== 0) {
this.warn(defaultMessage)
this.warn(messageTemplate({message: ''}))
} else {
// Append the custom message to a new line
this.warn(`${defaultMessage}\n${message}`)
this.warn(messageTemplate({message}))
}
}
} catch (err) {
Expand Down
16 changes: 14 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@
dependencies:
"@types/node" "*"

"@types/[email protected]":
version "4.4.4"
resolved "https://registry.npmjs.intuit.com:443/artifactory/api/npm/npm-intuit/@types/lodash.template/-/lodash.template-4.4.4.tgz#75fddd12297fb12683f9be42e05c646c359a1ff7"
integrity sha1-df3dEil/sSaD+b5C4FxkbDWaH/c=
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.14.120"
resolved "https://registry.npmjs.intuit.com:443/artifactory/api/npm/npm-intuit/@types/lodash/-/lodash-4.14.120.tgz#cf265d06f6c7a710db087ed07523ab8c1a24047b"
integrity sha1-zyZdBvbHpxDbCH7QdSOrjBokBHs=

"@types/lodash@^4.14.116":
version "4.14.116"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.116.tgz#5ccf215653e3e8c786a58390751033a9adca0eb9"
Expand Down Expand Up @@ -1258,9 +1270,9 @@ lodash._reinterpolate@~3.0.0:
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=

lodash.template@^4.4.0:
lodash.template@4.4.0, lodash.template@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0"
resolved "https://registry.npmjs.intuit.com:443/artifactory/api/npm/npm-intuit/lodash.template/-/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0"
integrity sha1-5zoDhcg1VZF0bgILmWecaQ5o+6A=
dependencies:
lodash._reinterpolate "~3.0.0"
Expand Down

0 comments on commit e4475a8

Please sign in to comment.