mirror of
https://github.com/wassname/talk.git
synced 2026-07-28 11:27:05 +08:00
cleaned up cli
This commit is contained in:
+23
-8
@@ -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')
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user