diff --git a/packages/edam-cli/bin/__tests__/main.spec.test.js b/packages/edam-cli/bin/__tests__/main.test.js similarity index 94% rename from packages/edam-cli/bin/__tests__/main.spec.test.js rename to packages/edam-cli/bin/__tests__/main.test.js index 7e9d4a1..e510f08 100644 --- a/packages/edam-cli/bin/__tests__/main.spec.test.js +++ b/packages/edam-cli/bin/__tests__/main.test.js @@ -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') diff --git a/packages/edam-cli/bin/__tests__/update-notifier.test.js b/packages/edam-cli/bin/__tests__/update-notifier.test.js new file mode 100644 index 0000000..df32160 --- /dev/null +++ b/packages/edam-cli/bin/__tests__/update-notifier.test.js @@ -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() + }) +}) diff --git a/packages/edam-cli/bin/edam.js b/packages/edam-cli/bin/edam.js index 9cb2487..4aa41a1 100755 --- a/packages/edam-cli/bin/edam.js +++ b/packages/edam-cli/bin/edam.js @@ -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 @@ -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) }) })() diff --git a/packages/edam-cli/postInstall.js b/packages/edam-cli/postInstall.js index db624c1..a942b5e 100644 --- a/packages/edam-cli/postInstall.js +++ b/packages/edam-cli/postInstall.js @@ -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!') diff --git a/packages/edam/__mocks__/inquirer.js b/packages/edam/src/__mocks__/inquirer.js similarity index 100% rename from packages/edam/__mocks__/inquirer.js rename to packages/edam/src/__mocks__/inquirer.js diff --git a/packages/edam/__mocks__/readline.js b/packages/edam/src/__mocks__/readline.js similarity index 100% rename from packages/edam/__mocks__/readline.js rename to packages/edam/src/__mocks__/readline.js diff --git a/packages/edam/src/core/pull/npm.ts b/packages/edam/src/core/pull/npm.ts index 79f7c86..ee924f3 100644 --- a/packages/edam/src/core/pull/npm.ts +++ b/packages/edam/src/core/pull/npm.ts @@ -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( @@ -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 : '') ) } @@ -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' }) } @@ -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) ) }