Skip to content

Commit

Permalink
fix: updateNotify is not working
Browse files Browse the repository at this point in the history
closed #10
  • Loading branch information
imcuttle committed Oct 22, 2018
1 parent b0cb8b7 commit fab3586
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const exec = function(argString, { cwd = gCwd } = {}) {

describe('main.spec', function() {

// beforeEach(function () {
// rimraf.sync(join(__dirname, 'fixture/output'))
// })
beforeEach(function () {
rimraf.sync(join(__dirname, 'fixture/output'))
})

it('should `--help` flag works', async () => {
const sp = exec('--help')
Expand Down
26 changes: 26 additions & 0 deletions packages/edam-cli/bin/__tests__/update-notifier.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @file update-notifier
* @author Cuttle Cong
* @date 2018/10/22
* @description
*/
const upt = require('update-notifier')

describe('update-notifier', function() {
afterEach(() => {
})

it('should update-notifier', () => {
const notifier = upt({
pkg: { name: 'edam', version: '1.0.0' },
updateCheckInterval: 0
})

const old = process.stdout.isTTY
process.stdout.isTTY = true
notifier.notify({ defer: false })
process.stdout.isTTY = old

expect(notifier.update).not.toBeNull()
})
})
37 changes: 20 additions & 17 deletions packages/edam-cli/bin/edam.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ ${generateFlagHelp(flags, ' ')}
}
)

if (config.updateNotify) {
const notifier = updateNotify({
pkg
})
const upt = notifier.update

if (upt) {
notifier.notify({
message:
'Update available ' +
c.dim(upt.current) +
c.reset(' → ') +
c.greenBright(upt.latest) +
' \nRun ' +
c.cyanBright('npm install edam@latest -g') +
' to update'
})
}
}

const edam = require('edam').default
const Edam = require('edam').Edam
// default
Expand Down Expand Up @@ -304,23 +324,6 @@ ${generateFlagHelp(flags, ' ')}
code = 1
})
.then(function() {
if (config.updateNotify) {
const notifier = updateNotify({ pkg })
const upt = updateNotify.update
if (upt) {
notifier.notify({
message:
'Update available ' +
c.dim(upt.current) +
c.reset(' → ') +
c.green(upt.latest) +
' \nRun ' +
c.cyan('npm install edam@latest -g') +
' to update'
})
}
}

process.exit(code)
})
})()
2 changes: 1 addition & 1 deletion packages/edam-cli/postInstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* @date 2018/8/13
* @description
*/
console.log('\x1b[36m%s\x1b[0m\x1b[33m\x1b[1m%s\x1b[0m\x1b[36m%s\x1b[0m', '🎈 Thanks for using edam, We recommand ', '`npm install -g edam-completer`', ' to support completing automatically!')
console.log('\x1b[36m%s\x1b[0m\x1b[33m\x1b[1m%s\x1b[0m\x1b[36m%s\x1b[0m', '🎈 Thanks for using edam, We recommend ', '`npm install -g edam-completer`', ' to support completing automatically!')
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions packages/edam/src/core/pull/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const updateNotifier = require('update-notifier')
const c = require('chalk')
const debug = require('debug')('edam:pull:npm')
const semver = require('semver')

const yarnInstall = require('../../lib/yarnInstall')

module.exports = async function npmPull(
Expand Down Expand Up @@ -47,7 +48,7 @@ module.exports = async function npmPull(
} catch (err) {
throw new EdamError(
`Install package "${name}" failed. \n` +
(err && err.stack)
(err ? err.stack : '')
)
}

Expand All @@ -68,9 +69,9 @@ module.exports = async function npmPull(
'Update available ' +
chalk.dim(upt.current) +
chalk.reset(' → ') +
chalk.green(upt.latest) +
chalk.greenBright(upt.latest) +
' \nRun ' +
chalk.cyan(`edam ${source.url}@latest ${output}`) +
chalk.cyanBright(`edam ${source.url}@latest -o ${output}`) +
' to update'
})
}
Expand All @@ -82,7 +83,7 @@ module.exports = async function npmPull(
log(
'Installed %s from NPM, and the actual version is %s.',
c.magenta.bold(name),
c.green(installedVersion)
c.greenBright(installedVersion)
)
}

Expand Down

0 comments on commit fab3586

Please sign in to comment.