From c4edab9bbdc653a2744be41477a4b48012572439 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 31 Mar 2017 16:09:56 -0600 Subject: [PATCH] cleaned up cli --- bin/cli-plugins | 31 +++++++++++++++++++++++-------- package.json | 1 + yarn.lock | 10 ++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/bin/cli-plugins b/bin/cli-plugins index 581631573..673f6c058 100755 --- a/bin/cli-plugins +++ b/bin/cli-plugins @@ -8,7 +8,9 @@ const program = require('./commander'); // Make things colorful! require('colors'); +const emoji = require('node-emoji'); +const dir = process.cwd(); const fs = require('fs'); const path = require('path'); const spawn = require('cross-spawn'); @@ -17,7 +19,7 @@ const {plugins, isInternal} = require('../plugins'); function existsInNodeModules(name) { try { - resolve.sync(name, {basedir: process.cwd()}); + resolve.sync(name, {basedir: dir}); return true; } catch (e) { @@ -27,11 +29,11 @@ function existsInNodeModules(name) { const EXTERNAL = /^\w[a-z\-0-9\.]+$/; // Match "react", "path", "fs", "lodash.random", etc. -async function reconcileRemotePlugins(dryRun) { +function reconcilePackages() { const linkable = []; const fetchable = []; - console.log('\n[1/3] 🔍 Reconciling plugins...\n'.yellow); + console.log(); console.log(' +local (l) packages in your project\n +external (e) referenced packages in node_modules but not in current project\n +missing (m) referenced packages but not found\n +symlinked (sl) symlinked external packages\n'); for (let i in plugins) { let section = plugins[i]; @@ -50,7 +52,7 @@ async function reconcileRemotePlugins(dryRun) { } if (isInternal(dep)) { - let stat = fs.lstatSync(path.join(process.cwd(), 'plugins', name)); + let stat = fs.lstatSync(path.join(dir, 'plugins', name)); if (stat.isSymbolicLink()) { console.log(` sl ${name.cyan}`); } else { @@ -69,8 +71,16 @@ async function reconcileRemotePlugins(dryRun) { } } } + console.log(); - console.log('\n[2/3] 🚚 Fetching plugins...\n'.yellow); + return {linkable, fetchable}; +} + +async function reconcileRemotePlugins(dryRun) { + console.log(`\n[1/3] ${emoji.get('mag')} Reconciling plugins...`.yellow); + const {linkable, fetchable} = reconcilePackages(); + + console.log(`[2/3] ${emoji.get('truck')} Fetching plugins...\n`.yellow); if (fetchable.length > 0) { @@ -101,13 +111,13 @@ async function reconcileRemotePlugins(dryRun) { // TODO fetch the plugins using yarn - console.log('\n[3/3] 🔗 Linking plugins...\n'.yellow); + console.log(`\n[3/3] ${emoji.get('link')} Linking plugins...\n`.yellow); for (let i in linkable) { let {name} = linkable[i]; - let src = path.join(process.cwd(), 'node_modules', name); - let dst = path.join(process.cwd(), 'plugins', name); + let src = path.join(dir, 'node_modules', name); + let dst = path.join(dir, 'plugins', name); console.log(`$ link ${src.cyan} -> ${dst.cyan}`); @@ -177,6 +187,11 @@ async function reconcilePluginDeps(options) { // Setting up the program command line arguments. //============================================================================== +program + .command('list') + .description('') + .action(reconcilePackages); + program .command('reconcile') .description('reconciles local plugin dependencies and downloads external plugins') diff --git a/package.json b/package.json index 17dabb747..cca869dac 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "mongoose": "^4.9.1", "morgan": "^1.8.1", "natural": "^0.4.0", + "node-emoji": "^1.5.1", "node-fetch": "^1.6.3", "nodemailer": "^2.6.4", "parse-duration": "^0.1.1", diff --git a/yarn.lock b/yarn.lock index 49a633adb..82af883c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5156,6 +5156,12 @@ node-dir@^0.1.10: dependencies: minimatch "^3.0.2" +node-emoji@^1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.5.1.tgz#fd918e412769bf8c448051238233840b2aff16a1" + dependencies: + string.prototype.codepointat "^0.2.0" + node-fetch@^1.0.1, node-fetch@^1.3.3, node-fetch@^1.6.3: version "1.6.3" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.6.3.tgz#dc234edd6489982d58e8f0db4f695029abcd8c04" @@ -7345,6 +7351,10 @@ string-width@^2.0.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^3.0.0" +string.prototype.codepointat@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/string.prototype.codepointat/-/string.prototype.codepointat-0.2.0.tgz#6b26e9bd3afcaa7be3b4269b526de1b82000ac78" + string_decoder@^0.10.25, string_decoder@~0.10.x: version "0.10.31" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"