Permalink
Browse files

feat(cli): make a cli bundle in dist/

  • Loading branch information...
RangerRick committed Aug 1, 2017
1 parent 0880cf7 commit 02298d7f87ba626b8291edceead9a2ed2b6dfc07
Showing with 75 additions and 62 deletions.
  1. +1 −0 .gitignore
  2. +5 −2 package.json
  3. +41 −8 src/CLI.ts
  4. +16 −6 webpack.config.js
  5. +12 −46 yarn.lock
View
@@ -34,5 +34,6 @@ profile.cov
grafana
.notouch
dist/cli.*
dist/opennms.*
dist/docs
View
@@ -3,6 +3,9 @@
"version": "0.1.0-alpha.4",
"description": "Client API for the OpenNMS network monitoring platform",
"main": "dist/opennms.js",
"bin": {
"opennms": "dist/cli.node.js"
},
"author": "Benjamin Reed",
"license": "MIT",
"bugs": {
@@ -33,6 +36,7 @@
"babel-preset-es2015": "^6.24.1",
"babel-preset-latest": "^6.24.1",
"chai": "3.5.0",
"child_process": "^1.0.2",
"conventional-changelog-lint": "^1.1.9",
"husky": "^0.13.3",
"jest": "^20.0.3",
@@ -70,8 +74,7 @@
},
"dependencies": {
"axios": "^0.16.1",
"child_process": "^1.0.2",
"cliff": "^0.1.10",
"cli-table": "^0.3.1",
"commander": "^2.9.0",
"fs": "^0.0.1-security",
"ip-address": "^5.8.8",
View
@@ -15,7 +15,7 @@ const CLI = () => {
const catCLI = new Category('cli', catRoot);
// tslint:disable
const cliff = require('cliff');
const Table = require('cli-table');
const colors = require('colors');
const fs = require('fs');
const path = require('path');
@@ -25,6 +25,32 @@ const CLI = () => {
const homedir = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
const defaultConfigFile = path.join(homedir, '.opennms-cli.config.json');
const tableFormat = {
head: [],
/* tslint:disable:object-literal-sort-keys */
chars: {
'middle': ' ',
'top': '',
'top-mid': '',
'top-left': '',
'top-right': '',
'left': '',
'left-mid': '',
'mid': '',
'mid-mid': '',
'right': '',
'right-mid': '',
'bottom': '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': '',
},
style: {
'padding-left': 0,
'padding-right': 0,
},
};
const readConfig = () => {
const configfile = program.config || defaultConfigFile;
let config;
@@ -122,14 +148,14 @@ const CLI = () => {
console.log('');
const caps = res.capabilities();
const rows = [];
const t = new Table(tableFormat);
for (const cap in caps) {
if (cap === 'type') {
continue;
}
rows.push([startCase(cap) + ':', caps[cap]]);
t.push([startCase(cap) + ':', caps[cap]]);
}
console.log(cliff.stringifyRows(rows));
console.log(t.toString());
console.log('');
return res;
@@ -160,9 +186,9 @@ const CLI = () => {
let logMessage = '';
if (alarm.logMessage) {
logMessage = alarm.logMessage.trim();
logMessage = alarm.logMessage.replace('[\r\n].*$').trim();
if (logMessage.length > logMessageLength) {
logMessage = logMessage.slice(0, logMessageLength) + '';
logMessage = logMessage.slice(0, logMessageLength).trim() + '';
}
}
@@ -199,8 +225,15 @@ const CLI = () => {
}
return dao.find(filter).then((alarms) => {
const headers = ['id', 'severity', 'node', 'count', 'time', 'log'];
console.log(cliff.stringifyObjectRows(formatAlarms(alarms), headers, ['red']));
const format = Object.assign({}, tableFormat);
format.head = [ 'ID', 'Severity', 'Node', 'Count', 'Time', 'Log' ];
const t = new Table(format);
const formatted = formatAlarms(alarms);
for (const alarm of formatted) {
t.push([alarm.id, alarm.severity, alarm.node, alarm.count, alarm.time, alarm.log]);
}
console.log(t.toString());
console.log('');
});
}).catch((err) => {
return handleError('Alarm list failed', err);
View
@@ -13,7 +13,7 @@ var justDocs = argv.env === 'docs';
var libraryName = 'opennms';
var variants = {
web: [ true, false ],
target: [ 'web', 'node' ],
};
if (isProduction) {
@@ -22,7 +22,7 @@ if (isProduction) {
if (justDocs) {
variants = {
web: [true],
target: ['node'],
docs: [true],
};
}
@@ -87,16 +87,26 @@ function createConfig(options) {
var myconf = clonedeep(config);
myconf.output.filename = '[name]';
var defs = {
'IS_WEB': options.web,
'IS_WEB': options.target === 'web',
'IS_PRODUCTION': options.production,
};
if (options.web) {
if (options.target === 'web') {
myconf.target = 'web';
} else {
myconf.target = 'node';
myconf.node = { process: false };
}
if (options.target === 'node') {
myconf.output.filename += '.node';
myconf.entry.cli = __dirname + '/src/CLI.ts';
myconf.plugins.push(new webpack.BannerPlugin({
banner: '#!/usr/bin/env node',
raw: true,
entryOnly: true,
include: /cli/i,
}));
}
if (options.production) {
@@ -119,7 +129,7 @@ function createConfig(options) {
myconf.plugins.push(new webpack.ProvidePlugin({X2JS: 'x2js'}));
// build docs either on a dedicated doc build, or during production node.js build
var buildDocs = justDocs || (options.production && !options.web);
var buildDocs = !!(justDocs || (options.production && options.target === 'node'));
if (buildDocs) {
// generate documentation
var tsconfig = require('./tsconfig.json');
@@ -133,7 +143,7 @@ function createConfig(options) {
myconf.output.filename += '.js';
console.log('Building variant: web=' + (!!options.web) + ', production=' + (!!options.production) + ', docs=' + buildDocs);
console.log('Building variant: target=' + options.target + ', production=' + (!!options.production) + ', docs=' + buildDocs);
return myconf;
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 02298d7

Please sign in to comment.