@feflow/cli
Version:
A front-end flow tool.
192 lines • 7.87 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var path_1 = __importDefault(require("path"));
var fs_1 = __importDefault(require("fs"));
var chalk_1 = __importDefault(require("chalk"));
var apply_plugins_1 = require("../plugin/apply-plugins");
var constant_1 = require("../../shared/constant");
exports.default = (function (ctx) {
ctx.commander.register('list', 'Show all plugins installed.', function () {
var list = loadModuleList(ctx);
var universalPlugins = loadUniversalPlugin(ctx);
list.push.apply(list, __spreadArray([], __read(universalPlugins), false));
console.log('You can search more templates or plugins through https://feflowjs.com/encology/');
if (!list.length) {
console.log(chalk_1.default.magenta('No templates and plugins have been installed'));
return;
}
var plugins = [];
var templates = [];
list.forEach(function (item) {
if (/generator-|^@[^/]+\/generator-/.test(item.name)) {
templates.push(item);
}
else {
plugins.push(item);
}
});
console.log('templates');
if (templates.length === 0) {
console.log(chalk_1.default.magenta('No templates have been installed'));
}
else {
templates.forEach(function (item) { return console.log(chalk_1.default.magenta("".concat(item.name, "(").concat(item.version, ")"))); });
}
var storePlugins = [];
var gitPlugins = [];
var localPlugins = [];
plugins.forEach(function (item) {
if (item.name.startsWith(constant_1.FEFLOW_PLUGIN_GIT_PREFIX)) {
gitPlugins.push(item);
}
else if (item.name.startsWith(constant_1.FEFLOW_PLUGIN_LOCAL_PREFIX)) {
localPlugins.push(item);
}
else if (item.name.startsWith(constant_1.FEFLOW_PLUGIN_PREFIX) || /^@[^/]+\/feflow-plugin-/.test(item.name)) {
storePlugins.push(item);
}
});
console.log('plugins');
if (storePlugins.length === 0 && gitPlugins.length === 0) {
console.log(chalk_1.default.magenta('No plugins have been installed'));
}
else {
storePlugins.forEach(function (item) { return console.log(chalk_1.default.magenta("".concat(item.name, "(").concat(item.version, ")"))); });
}
if (gitPlugins.length > 0) {
console.log('git plugins');
gitPlugins.forEach(function (gitPlugin) {
var url = "http://".concat(decodeURIComponent(gitPlugin.name.replace(constant_1.FEFLOW_PLUGIN_GIT_PREFIX, '')));
showPlugin(ctx, url, gitPlugin);
});
}
if (localPlugins.length > 0) {
console.log('local plugins');
localPlugins.forEach(function (localPlugin) {
var localPath = decodeURIComponent(localPlugin.name.replace(constant_1.FEFLOW_PLUGIN_LOCAL_PREFIX, ''));
showPlugin(ctx, localPath, localPlugin);
});
}
});
});
function loadModuleList(ctx) {
var packagePath = ctx.rootPkg;
var pluginDir = path_1.default.join(ctx.root, 'node_modules');
var extend = function (target, source) {
var targetCopy = __assign({}, target);
Object.entries(source).forEach(function (_a) {
var _b = __read(_a, 2), key = _b[0], value = _b[1];
targetCopy[key] = value;
});
return targetCopy;
};
if (fs_1.default.existsSync(packagePath)) {
var content = fs_1.default.readFileSync(packagePath, 'utf8');
var json = JSON.parse(content);
var deps = extend(json.dependencies || {}, json.devDependencies || {});
var keys = Object.keys(deps);
return keys
.filter(function (name) {
if (!/^feflow-plugin-|^@[^/]+\/feflow-plugin-|generator-|^@[^/]+\/generator-/.test(name))
return false;
var pluginPath = path_1.default.join(pluginDir, name);
return fs_1.default.existsSync(pluginPath);
})
.map(function (key) { return ({
name: key,
version: getModuleVersion(pluginDir, key),
}); });
}
return [];
}
function getModuleVersion(dir, name) {
var packagePath = path_1.default.resolve(dir, name, 'package.json');
if (fs_1.default.existsSync(packagePath)) {
var content = fs_1.default.readFileSync(packagePath, 'utf8');
var json = JSON.parse(content);
return (json === null || json === void 0 ? void 0 : json.version) || 'unknown';
}
return 'unknown';
}
function loadUniversalPlugin(ctx) {
var e_1, _a;
var universalPkg = ctx.universalPkg;
var availablePlugins = [];
try {
for (var _b = __values(universalPkg.getInstalled()), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), pkg = _d[0], version = _d[1];
availablePlugins.push({
name: pkg,
version: version,
});
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return availablePlugins;
}
function showPlugin(ctx, from, pluginInfo) {
var repoPath = path_1.default.join(ctx === null || ctx === void 0 ? void 0 : ctx.universalModules, "".concat(pluginInfo.name, "@").concat(pluginInfo.version));
var useCommand = pluginInfo.name.replace(constant_1.FEFLOW_PLUGIN_PREFIX, '');
var plugin = (0, apply_plugins_1.resolvePlugin)(ctx, repoPath);
if (plugin.name) {
useCommand = plugin.name;
}
console.log(chalk_1.default.magenta("".concat(from, "(command: ").concat(useCommand, ", version: ").concat(pluginInfo.version, ")")));
}
//# sourceMappingURL=list.js.map