zcatalyst-cli 1.11.1 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/optional-import.toml +10 -0
- package/lib/apig-utils.js +39 -39
- package/lib/archiver.js +13 -9
- package/lib/authentication/index.js +22 -18
- package/lib/authentication/login.js +37 -39
- package/lib/bin/catalyst.js +15 -15
- package/lib/cli_table/src/cell.js +26 -26
- package/lib/cli_table/src/layout-manager.js +44 -45
- package/lib/cli_table/src/table.js +9 -9
- package/lib/cli_table/src/utils.js +35 -36
- package/lib/client-utils.js +18 -18
- package/lib/client.js +1 -1
- package/lib/command_needs/auth.js +7 -7
- package/lib/command_needs/rc.js +24 -24
- package/lib/commands/apig/disable.js +5 -5
- package/lib/commands/apig/enable.js +5 -5
- package/lib/commands/apig/status.js +9 -9
- package/lib/commands/client/delete.js +19 -19
- package/lib/commands/client/setup.js +8 -4
- package/lib/commands/deploy.js +18 -14
- package/lib/commands/ds/export.js +11 -11
- package/lib/commands/ds/import.js +12 -12
- package/lib/commands/ds/status.js +15 -15
- package/lib/commands/event/generate/index.js +21 -17
- package/lib/commands/event/generate/integ.js +7 -3
- package/lib/commands/functions/add.js +8 -4
- package/lib/commands/functions/config.js +5 -5
- package/lib/commands/functions/delete.js +22 -22
- package/lib/commands/functions/setup.js +8 -4
- package/lib/commands/functions/shell.js +12 -5
- package/lib/commands/help.js +4 -4
- package/lib/commands/iac/export.js +8 -8
- package/lib/commands/iac/import.js +29 -21
- package/lib/commands/iac/pack.js +15 -11
- package/lib/commands/iac/status.js +6 -2
- package/lib/commands/index.js +5 -1
- package/lib/commands/init.js +14 -10
- package/lib/commands/login.js +5 -1
- package/lib/commands/logout.js +5 -1
- package/lib/commands/project/list.js +14 -10
- package/lib/commands/project/reset.js +5 -5
- package/lib/commands/project/use.js +9 -9
- package/lib/commands/pull.js +18 -14
- package/lib/commands/run.js +13 -9
- package/lib/commands/serve.js +5 -1
- package/lib/commands/token/generate.js +6 -2
- package/lib/commands/token/list.js +7 -3
- package/lib/commands/token/revoke.js +6 -2
- package/lib/commands/whoami.js +3 -3
- package/lib/dc.js +2 -2
- package/lib/deploy/features/apig.js +6 -6
- package/lib/deploy/features/client.js +1 -1
- package/lib/deploy/features/functions/index.js +9 -9
- package/lib/deploy/features/index.js +5 -1
- package/lib/deploy/index.js +2 -2
- package/lib/endpoints/index.js +17 -13
- package/lib/endpoints/lib/apig.js +5 -5
- package/lib/endpoints/lib/applogic.js +4 -4
- package/lib/endpoints/lib/cache.js +3 -3
- package/lib/endpoints/lib/catalyst-details.js +1 -1
- package/lib/endpoints/lib/client.js +5 -5
- package/lib/endpoints/lib/datastore.js +2 -2
- package/lib/endpoints/lib/ds-bulk.js +5 -5
- package/lib/endpoints/lib/env.js +1 -1
- package/lib/endpoints/lib/event-bus.js +1 -1
- package/lib/endpoints/lib/filestore.js +2 -2
- package/lib/endpoints/lib/functions.js +4 -4
- package/lib/endpoints/lib/iac.js +10 -10
- package/lib/endpoints/lib/project.js +20 -5
- package/lib/endpoints/lib/queue.js +3 -3
- package/lib/endpoints/lib/sdk.js +1 -1
- package/lib/endpoints/lib/zcql.js +1 -1
- package/lib/error.js +11 -9
- package/lib/errorOut.js +2 -2
- package/lib/event_generate/cache.js +5 -5
- package/lib/event_generate/custom.js +2 -2
- package/lib/event_generate/datastore.js +5 -5
- package/lib/event_generate/filestore.js +5 -5
- package/lib/event_generate/integration/cliq.js +3 -3
- package/lib/event_generate/user.js +1 -1
- package/lib/event_generate/webapp.js +5 -5
- package/lib/execute-script.js +19 -15
- package/lib/express_middlewares/authenticator.js +32 -5
- package/lib/express_middlewares/logger.js +2 -2
- package/lib/express_middlewares/unknownReqProxy.js +1 -1
- package/lib/fn-utils/index.js +5 -1
- package/lib/fn-utils/lib/common.js +44 -44
- package/lib/fn-utils/lib/integ.js +9 -9
- package/lib/fn-utils/lib/java.js +48 -46
- package/lib/fn-utils/lib/node.js +8 -8
- package/lib/fn-watcher.js +9 -11
- package/lib/iac/status/bundle.js +5 -5
- package/lib/iac/status/deploy.js +4 -4
- package/lib/index.js +2 -2
- package/lib/init/dependencies/npm-install.js +8 -1
- package/lib/init/dependencies/package-json.js +6 -6
- package/lib/init/features/client/index.js +5 -1
- package/lib/init/features/client/initializers/angular.js +29 -27
- package/lib/init/features/client/initializers/basic.js +10 -6
- package/lib/init/features/client/initializers/lyte.js +12 -13
- package/lib/init/features/client/initializers/react.js +23 -18
- package/lib/init/features/functions/index.js +23 -14
- package/lib/init/features/functions/languages/java.js +10 -10
- package/lib/init/features/functions/languages/node.js +9 -9
- package/lib/init/features/index.js +12 -8
- package/lib/init/features/project.js +20 -20
- package/lib/init/index.js +2 -2
- package/lib/init/util/client.js +12 -7
- package/lib/init/util/functions.js +1 -1
- package/lib/init/util/project.js +4 -4
- package/lib/internal/api.js +19 -19
- package/lib/internal/command.js +20 -16
- package/lib/internal/config.js +5 -5
- package/lib/internal/credential.js +10 -10
- package/lib/internal/crypt.js +5 -5
- package/lib/internal/rc.js +5 -5
- package/lib/migration/global/1.6.2.js +3 -3
- package/lib/migration/index.js +22 -18
- package/lib/option-filter.js +34 -30
- package/lib/optional-import.js +30 -11
- package/lib/plugin-loader.js +28 -13
- package/lib/port-resolver.js +4 -4
- package/lib/progress.js +2 -2
- package/lib/prompt/index.js +6 -2
- package/lib/prompt/types/file-path.js +1 -1
- package/lib/pull/features/apig.js +9 -9
- package/lib/pull/features/client.js +7 -7
- package/lib/pull/features/functions/index.js +15 -15
- package/lib/pull/features/index.js +5 -1
- package/lib/pull/index.js +4 -4
- package/lib/repl-server.js +2 -2
- package/lib/serve/features/apig.js +1 -1
- package/lib/serve/features/index.js +8 -4
- package/lib/serve/index.js +15 -11
- package/lib/serve/server/index.js +34 -27
- package/lib/serve/server/lib/java/JavaaioServer.java +5 -3
- package/lib/serve/server/lib/java/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/lib/catalyst-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/lib/zip4j-2.5.0.jar +0 -0
- package/lib/serve/server/lib/master.js +33 -36
- package/lib/serve/server/lib/node.js +7 -3
- package/lib/serve/server/lib/web_client/index.js +3 -3
- package/lib/serve/server/lib/web_client/server.js +33 -30
- package/lib/shell/dependencies/http-functions.js +38 -33
- package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +14 -3
- package/lib/shell/dependencies/invoker/bio/node.js +5 -2
- package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +7 -2
- package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +7 -2
- package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +7 -2
- package/lib/shell/dependencies/invoker/integ/node.js +8 -4
- package/lib/shell/dependencies/local-function.js +44 -40
- package/lib/shell/index.js +16 -12
- package/lib/shell/prepare/index.js +2 -2
- package/lib/shell/prepare/languages/index.js +5 -1
- package/lib/shell/prepare/languages/java.js +1 -1
- package/lib/throbber/index.js +17 -17
- package/lib/throbber/utils.js +9 -9
- package/lib/track.js +7 -7
- package/lib/util_modules/config/index.js +5 -1
- package/lib/util_modules/config/lib/client.js +18 -21
- package/lib/util_modules/constants/lib/auth.js +6 -6
- package/lib/util_modules/constants/lib/cliq-handlers.js +2 -2
- package/lib/util_modules/constants/lib/template.js +21 -21
- package/lib/util_modules/constants/lib/urls.js +20 -12
- package/lib/util_modules/context-help.js +15 -15
- package/lib/util_modules/fs/index.js +5 -1
- package/lib/util_modules/fs/lib/async.js +4 -4
- package/lib/util_modules/fs/utils.js +1 -1
- package/lib/util_modules/global-space.js +0 -97
- package/lib/util_modules/logger.js +2 -2
- package/lib/util_modules/parser/toml.js +1 -1
- package/lib/util_modules/project.js +6 -6
- package/lib/util_modules/server.js +53 -0
- package/lib/util_modules/shell.js +4 -4
- package/lib/winston.js +5 -5
- package/package.json +40 -40
- package/scripts/postInstall.js +7 -6
- package/templates/init/functions/java/integ/cliq/com/handlers/BotHandler.java +23 -5
- package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +23 -8
- package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +3 -3
- package/templates/init/functions/node/integ/cliq/package.json +2 -1
- package/templates/init/functions/node/integ/cliq/sample.js +3 -1
- package/docs/.DS_Store +0 -0
- package/lib/serve/server/lib/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/templates/.DS_Store +0 -0
- package/templates/init/.DS_Store +0 -0
- package/templates/init/client/.DS_Store +0 -0
- package/templates/init/client/react/.DS_Store +0 -0
package/lib/bin/catalyst.js
CHANGED
|
@@ -16,7 +16,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
const path_1 = require("path");
|
|
17
17
|
const fs_1 = require("../util_modules/fs");
|
|
18
18
|
const runtime_store_1 = __importDefault(require("../runtime-store"));
|
|
19
|
-
const pkg = fs_1.SYNC.readJSONFile(path_1.resolve(__dirname, '../../package.json'), {
|
|
19
|
+
const pkg = fs_1.SYNC.readJSONFile((0, path_1.resolve)(__dirname, '../../package.json'), {
|
|
20
20
|
checkpath: true,
|
|
21
21
|
throws: false
|
|
22
22
|
});
|
|
@@ -34,15 +34,15 @@ const env_1 = require("../util_modules/env");
|
|
|
34
34
|
const js_1 = require("../util_modules/js");
|
|
35
35
|
const logger_1 = require("../util_modules/logger");
|
|
36
36
|
const errorOut_1 = __importDefault(require("../errorOut"));
|
|
37
|
-
logger_1.debug();
|
|
38
|
-
logger_1.debug(js_1.JS.repeat('-', 70));
|
|
39
|
-
logger_1.debug(ansi_colors_1.bold('Command: ') + process.argv.join(' '));
|
|
40
|
-
logger_1.debug(ansi_colors_1.bold('CLI Version: ') + pkg.version);
|
|
41
|
-
logger_1.debug(ansi_colors_1.bold('Platform: ') + process.platform);
|
|
42
|
-
logger_1.debug(ansi_colors_1.bold('Node Version: ') + process.version);
|
|
43
|
-
logger_1.debug(ansi_colors_1.bold('Time: ') + new Date().toString());
|
|
44
|
-
logger_1.debug(js_1.JS.repeat('-', 70));
|
|
45
|
-
logger_1.debug();
|
|
37
|
+
(0, logger_1.debug)();
|
|
38
|
+
(0, logger_1.debug)(js_1.JS.repeat('-', 70));
|
|
39
|
+
(0, logger_1.debug)((0, ansi_colors_1.bold)('Command: ') + process.argv.join(' '));
|
|
40
|
+
(0, logger_1.debug)((0, ansi_colors_1.bold)('CLI Version: ') + pkg.version);
|
|
41
|
+
(0, logger_1.debug)((0, ansi_colors_1.bold)('Platform: ') + process.platform);
|
|
42
|
+
(0, logger_1.debug)((0, ansi_colors_1.bold)('Node Version: ') + process.version);
|
|
43
|
+
(0, logger_1.debug)((0, ansi_colors_1.bold)('Time: ') + new Date().toString());
|
|
44
|
+
(0, logger_1.debug)(js_1.JS.repeat('-', 70));
|
|
45
|
+
(0, logger_1.debug)();
|
|
46
46
|
process.on('beforeExit', (code) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
47
|
code = process.exitCode || code;
|
|
48
48
|
if (code > 0 && process.stdout.isTTY) {
|
|
@@ -53,7 +53,7 @@ process.on('beforeExit', (code) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
53
53
|
const cmd = yield cmdPromise;
|
|
54
54
|
if (code === 1 && cmd) {
|
|
55
55
|
const commandName = js_1.JS.get(js_1.JS.last(cmd.args), '_name', '[command]');
|
|
56
|
-
help = 'Having trouble? Try ' + ansi_colors_1.bold('catalyst ' + commandName + ' --help');
|
|
56
|
+
help = 'Having trouble? Try ' + (0, ansi_colors_1.bold)('catalyst ' + commandName + ' --help');
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
59
59
|
help =
|
|
@@ -71,10 +71,10 @@ process.on('beforeExit', (code) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
71
71
|
process.exit(code);
|
|
72
72
|
}));
|
|
73
73
|
process.on('exit', (code) => {
|
|
74
|
-
if (env_1.isPrimaryShell()) {
|
|
74
|
+
if ((0, env_1.isPrimaryShell)()) {
|
|
75
75
|
fs_1.SYNC.deleteTempDir();
|
|
76
76
|
}
|
|
77
|
-
const logFile = path_1.join(process.cwd(), constants_1.FILENAME.log);
|
|
77
|
+
const logFile = (0, path_1.join)(process.cwd(), constants_1.FILENAME.log);
|
|
78
78
|
if (code < 2 && fs_1.SYNC.fileExists(logFile)) {
|
|
79
79
|
fs_1.SYNC.deleteFile(logFile);
|
|
80
80
|
}
|
|
@@ -84,9 +84,9 @@ process.on('exit', (code) => {
|
|
|
84
84
|
}).notify({ defer: false, isGlobal: true });
|
|
85
85
|
});
|
|
86
86
|
process.on('uncaughtException', (err) => {
|
|
87
|
-
errorOut_1.default(err);
|
|
87
|
+
(0, errorOut_1.default)(err);
|
|
88
88
|
});
|
|
89
89
|
process.on('unhandledRejection', (reason, promise) => {
|
|
90
|
-
errorOut_1.default(util_1.inspect(reason || promise));
|
|
90
|
+
(0, errorOut_1.default)((0, util_1.inspect)(reason || promise));
|
|
91
91
|
});
|
|
92
92
|
const cmdPromise = __1.default.processArgs(process.argv);
|
|
@@ -12,7 +12,7 @@ class Cell {
|
|
|
12
12
|
}
|
|
13
13
|
options = options || {};
|
|
14
14
|
this.options = options;
|
|
15
|
-
|
|
15
|
+
const content = options.content;
|
|
16
16
|
if (['boolean', 'number', 'string'].indexOf(typeof content) !== -1) {
|
|
17
17
|
this.content = String(content);
|
|
18
18
|
}
|
|
@@ -27,15 +27,15 @@ class Cell {
|
|
|
27
27
|
}
|
|
28
28
|
mergeTableOptions(tableOptions, cells) {
|
|
29
29
|
this.cells = cells;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
CHAR_NAMES.forEach(
|
|
30
|
+
const optionsChars = this.options.chars || {};
|
|
31
|
+
const tableChars = tableOptions.chars;
|
|
32
|
+
const chars = (this.chars = {});
|
|
33
|
+
CHAR_NAMES.forEach((name) => {
|
|
34
34
|
setOption(optionsChars, tableChars, name, chars);
|
|
35
35
|
});
|
|
36
36
|
this.truncate = this.options.truncate || tableOptions.truncate;
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const style = (this.options.style = this.options.style || {});
|
|
38
|
+
const tableStyle = tableOptions.style;
|
|
39
39
|
setOption(style, tableStyle, 'padding-left', this);
|
|
40
40
|
setOption(style, tableStyle, 'padding-right', this);
|
|
41
41
|
this.head = style.head || tableStyle.head;
|
|
@@ -59,8 +59,8 @@ class Cell {
|
|
|
59
59
|
this.desiredHeight = this.lines.length;
|
|
60
60
|
}
|
|
61
61
|
init(tableOptions) {
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const x = this.x;
|
|
63
|
+
const y = this.y;
|
|
64
64
|
this.widths = tableOptions.colWidths.slice(x, x + this.colSpan);
|
|
65
65
|
this.heights = tableOptions.rowHeights.slice(y, y + this.rowSpan);
|
|
66
66
|
this.width = this.widths.reduce(sumPlusOne, -1);
|
|
@@ -76,7 +76,7 @@ class Cell {
|
|
|
76
76
|
if (lineNum == 'bottom') {
|
|
77
77
|
return this.drawBottom(this.drawRight);
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
const padLen = Math.max(this.height - this.lines.length, 0);
|
|
80
80
|
let padTop;
|
|
81
81
|
switch (this.vAlign) {
|
|
82
82
|
case 'center':
|
|
@@ -91,11 +91,11 @@ class Cell {
|
|
|
91
91
|
if (lineNum < padTop || lineNum >= padTop + this.lines.length) {
|
|
92
92
|
return this.drawEmpty(this.drawRight, spanningCell);
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
const forceTruncation = this.lines.length > this.height && lineNum + 1 >= this.height;
|
|
95
95
|
return this.drawLine(lineNum - padTop, this.drawRight, forceTruncation, spanningCell);
|
|
96
96
|
}
|
|
97
97
|
drawTop(drawRight) {
|
|
98
|
-
|
|
98
|
+
const content = [];
|
|
99
99
|
if (this.cells) {
|
|
100
100
|
this.widths.forEach(function (width, index) {
|
|
101
101
|
content.push(this._topLeftChar(index));
|
|
@@ -112,7 +112,7 @@ class Cell {
|
|
|
112
112
|
return this.wrapWithStyleColors('border', content.join(''));
|
|
113
113
|
}
|
|
114
114
|
_topLeftChar(offset) {
|
|
115
|
-
|
|
115
|
+
const x = this.x + offset;
|
|
116
116
|
let leftChar;
|
|
117
117
|
if (this.y == 0) {
|
|
118
118
|
leftChar = x == 0 ? 'topLeft' : offset == 0 ? 'topMid' : 'top';
|
|
@@ -124,7 +124,7 @@ class Cell {
|
|
|
124
124
|
else {
|
|
125
125
|
leftChar = offset == 0 ? 'midMid' : 'bottomMid';
|
|
126
126
|
if (this.cells) {
|
|
127
|
-
|
|
127
|
+
const spanAbove = this.cells[this.y - 1][x] instanceof Cell.ColSpanCell;
|
|
128
128
|
if (spanAbove) {
|
|
129
129
|
leftChar = offset == 0 ? 'topMid' : 'mid';
|
|
130
130
|
}
|
|
@@ -170,11 +170,11 @@ class Cell {
|
|
|
170
170
|
left = this.chars.rightMid;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
const leftPadding = utils.repeat(' ', this.paddingLeft);
|
|
174
|
+
const right = drawRight ? this.chars.right : '';
|
|
175
|
+
const rightPadding = utils.repeat(' ', this.paddingRight);
|
|
176
176
|
let line = this.lines[lineNum];
|
|
177
|
-
|
|
177
|
+
const len = this.width - (this.paddingLeft + this.paddingRight);
|
|
178
178
|
if (forceTruncationSymbol) {
|
|
179
179
|
line += this.truncate || '…';
|
|
180
180
|
}
|
|
@@ -192,9 +192,9 @@ class Cell {
|
|
|
192
192
|
return left + content + right;
|
|
193
193
|
}
|
|
194
194
|
drawBottom(drawRight) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
const left = this.chars[this.x == 0 ? 'bottomLeft' : 'bottomMid'];
|
|
196
|
+
const content = utils.repeat(this.chars.bottom, this.width);
|
|
197
|
+
const right = drawRight ? this.chars.bottomRight : '';
|
|
198
198
|
return this.wrapWithStyleColors('border', left + content + right);
|
|
199
199
|
}
|
|
200
200
|
drawEmpty(drawRight, spanningCell) {
|
|
@@ -208,8 +208,8 @@ class Cell {
|
|
|
208
208
|
left = this.chars.rightMid;
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
const right = drawRight ? this.chars.right : '';
|
|
212
|
+
const content = utils.repeat(' ', this.width);
|
|
213
213
|
return this.stylizeLine(left, content, right);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
@@ -226,8 +226,8 @@ class RowSpanCell {
|
|
|
226
226
|
this.originalCell = originalCell;
|
|
227
227
|
}
|
|
228
228
|
init(tableOptions) {
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
const y = this.y;
|
|
230
|
+
const originalY = this.originalCell.y;
|
|
231
231
|
this.cellOffset = y - originalY;
|
|
232
232
|
this.offset = findDimension(tableOptions.rowHeights, originalY, this.cellOffset);
|
|
233
233
|
}
|
|
@@ -263,7 +263,7 @@ function findDimension(dimensionTable, startingIndex, span) {
|
|
|
263
263
|
function sumPlusOne(a, b) {
|
|
264
264
|
return a + b + 1;
|
|
265
265
|
}
|
|
266
|
-
|
|
266
|
+
const CHAR_NAMES = [
|
|
267
267
|
'top',
|
|
268
268
|
'top-mid',
|
|
269
269
|
'top-left',
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const objectAssign = require('object-assign');
|
|
3
2
|
const Cell = require('./cell');
|
|
4
3
|
const { ColSpanCell, RowSpanCell } = Cell;
|
|
5
4
|
(function () {
|
|
6
5
|
function layoutTable(table) {
|
|
7
|
-
table.forEach(
|
|
6
|
+
table.forEach((row, rowIndex) => {
|
|
8
7
|
let prevCell = null;
|
|
9
|
-
row.forEach(
|
|
8
|
+
row.forEach((cell, columnIndex) => {
|
|
10
9
|
cell.y = rowIndex;
|
|
11
10
|
cell.x = prevCell ? prevCell.x + 1 : columnIndex;
|
|
12
11
|
for (let y = rowIndex; y >= 0; y--) {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const row2 = table[y];
|
|
13
|
+
const xMax = y === rowIndex ? columnIndex : row2.length;
|
|
15
14
|
for (let x = 0; x < xMax; x++) {
|
|
16
|
-
|
|
15
|
+
const cell2 = row2[x];
|
|
17
16
|
while (cellsConflict(cell, cell2)) {
|
|
18
17
|
cell.x++;
|
|
19
18
|
}
|
|
@@ -25,8 +24,8 @@ const { ColSpanCell, RowSpanCell } = Cell;
|
|
|
25
24
|
}
|
|
26
25
|
function maxWidth(table) {
|
|
27
26
|
let mw = 0;
|
|
28
|
-
table.forEach(
|
|
29
|
-
row.forEach(
|
|
27
|
+
table.forEach((row) => {
|
|
28
|
+
row.forEach((cell) => {
|
|
30
29
|
mw = Math.max(mw, cell.x + (cell.colSpan || 1));
|
|
31
30
|
});
|
|
32
31
|
});
|
|
@@ -36,23 +35,23 @@ const { ColSpanCell, RowSpanCell } = Cell;
|
|
|
36
35
|
return table.length;
|
|
37
36
|
}
|
|
38
37
|
function cellsConflict(cell1, cell2) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
const yMin1 = cell1.y;
|
|
39
|
+
const yMax1 = cell1.y - 1 + (cell1.rowSpan || 1);
|
|
40
|
+
const yMin2 = cell2.y;
|
|
41
|
+
const yMax2 = cell2.y - 1 + (cell2.rowSpan || 1);
|
|
42
|
+
const yConflict = !(yMin1 > yMax2 || yMin2 > yMax1);
|
|
43
|
+
const xMin1 = cell1.x;
|
|
44
|
+
const xMax1 = cell1.x - 1 + (cell1.colSpan || 1);
|
|
45
|
+
const xMin2 = cell2.x;
|
|
46
|
+
const xMax2 = cell2.x - 1 + (cell2.colSpan || 1);
|
|
47
|
+
const xConflict = !(xMin1 > xMax2 || xMin2 > xMax1);
|
|
49
48
|
return yConflict && xConflict;
|
|
50
49
|
}
|
|
51
50
|
function conflictExists(rows, x, y) {
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const i_max = Math.min(rows.length - 1, y);
|
|
52
|
+
const cell = { x: x, y: y };
|
|
54
53
|
for (let i = 0; i <= i_max; i++) {
|
|
55
|
-
|
|
54
|
+
const row = rows[i];
|
|
56
55
|
for (let j = 0; j < row.length; j++) {
|
|
57
56
|
if (cellsConflict(cell, row[j])) {
|
|
58
57
|
return true;
|
|
@@ -70,10 +69,10 @@ const { ColSpanCell, RowSpanCell } = Cell;
|
|
|
70
69
|
return true;
|
|
71
70
|
}
|
|
72
71
|
function addRowSpanCells(table) {
|
|
73
|
-
table.forEach(
|
|
74
|
-
row.forEach(
|
|
72
|
+
table.forEach((row, rowIndex) => {
|
|
73
|
+
row.forEach((cell) => {
|
|
75
74
|
for (let i = 1; i < cell.rowSpan; i++) {
|
|
76
|
-
|
|
75
|
+
const rowSpanCell = new RowSpanCell(cell);
|
|
77
76
|
rowSpanCell.x = cell.x;
|
|
78
77
|
rowSpanCell.y = cell.y + i;
|
|
79
78
|
rowSpanCell.colSpan = cell.colSpan;
|
|
@@ -84,11 +83,11 @@ const { ColSpanCell, RowSpanCell } = Cell;
|
|
|
84
83
|
}
|
|
85
84
|
function addColSpanCells(cellRows) {
|
|
86
85
|
for (let rowIndex = cellRows.length - 1; rowIndex >= 0; rowIndex--) {
|
|
87
|
-
|
|
86
|
+
const cellColumns = cellRows[rowIndex];
|
|
88
87
|
for (let columnIndex = 0; columnIndex < cellColumns.length; columnIndex++) {
|
|
89
|
-
|
|
88
|
+
const cell = cellColumns[columnIndex];
|
|
90
89
|
for (let k = 1; k < cell.colSpan; k++) {
|
|
91
|
-
|
|
90
|
+
const colSpanCell = new ColSpanCell();
|
|
92
91
|
colSpanCell.x = cell.x + k;
|
|
93
92
|
colSpanCell.y = cell.y;
|
|
94
93
|
cellColumns.splice(columnIndex + 1, 0, colSpanCell);
|
|
@@ -104,12 +103,12 @@ const { ColSpanCell, RowSpanCell } = Cell;
|
|
|
104
103
|
row.splice(x, 0, cell);
|
|
105
104
|
}
|
|
106
105
|
function fillInTable(table) {
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
const h_max = maxHeight(table);
|
|
107
|
+
const w_max = maxWidth(table);
|
|
109
108
|
for (let y = 0; y < h_max; y++) {
|
|
110
109
|
for (let x = 0; x < w_max; x++) {
|
|
111
110
|
if (!conflictExists(table, x, y)) {
|
|
112
|
-
|
|
111
|
+
const opts = { x: x, y: y, colSpan: 1, rowSpan: 1 };
|
|
113
112
|
x++;
|
|
114
113
|
while (x < w_max && !conflictExists(table, x, y)) {
|
|
115
114
|
opts.colSpan++;
|
|
@@ -120,7 +119,7 @@ const { ColSpanCell, RowSpanCell } = Cell;
|
|
|
120
119
|
opts.rowSpan++;
|
|
121
120
|
y2++;
|
|
122
121
|
}
|
|
123
|
-
|
|
122
|
+
const cell = new Cell(opts);
|
|
124
123
|
cell.x = opts.x;
|
|
125
124
|
cell.y = opts.y;
|
|
126
125
|
insertCell(cell, table[y]);
|
|
@@ -129,9 +128,9 @@ const { ColSpanCell, RowSpanCell } = Cell;
|
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
130
|
function generateCells(rows) {
|
|
132
|
-
return rows.map(
|
|
131
|
+
return rows.map((row) => {
|
|
133
132
|
if (!Array.isArray(row)) {
|
|
134
|
-
|
|
133
|
+
const key = Object.keys(row)[0];
|
|
135
134
|
row = row[key];
|
|
136
135
|
if (Array.isArray(row)) {
|
|
137
136
|
row = row.slice();
|
|
@@ -141,13 +140,13 @@ const { ColSpanCell, RowSpanCell } = Cell;
|
|
|
141
140
|
row = [key, row];
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
|
-
return row.map(
|
|
143
|
+
return row.map((cell) => {
|
|
145
144
|
return new Cell(cell);
|
|
146
145
|
});
|
|
147
146
|
});
|
|
148
147
|
}
|
|
149
148
|
function makeTableLayout(rows) {
|
|
150
|
-
|
|
149
|
+
const cellRows = generateCells(rows);
|
|
151
150
|
layoutTable(cellRows);
|
|
152
151
|
fillInTable(cellRows);
|
|
153
152
|
addRowSpanCells(cellRows);
|
|
@@ -166,10 +165,10 @@ const { ColSpanCell, RowSpanCell } = Cell;
|
|
|
166
165
|
})();
|
|
167
166
|
function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) {
|
|
168
167
|
return function (vals, table) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
table.forEach(
|
|
172
|
-
row.forEach(
|
|
168
|
+
const result = [];
|
|
169
|
+
const spanners = [];
|
|
170
|
+
table.forEach((row) => {
|
|
171
|
+
row.forEach((cell) => {
|
|
173
172
|
if ((cell[colSpan] || 1) > 1) {
|
|
174
173
|
spanners.push(cell);
|
|
175
174
|
}
|
|
@@ -178,15 +177,15 @@ function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) {
|
|
|
178
177
|
}
|
|
179
178
|
});
|
|
180
179
|
});
|
|
181
|
-
vals.forEach(
|
|
180
|
+
vals.forEach((val, index) => {
|
|
182
181
|
if (typeof val === 'number') {
|
|
183
182
|
result[index] = val;
|
|
184
183
|
}
|
|
185
184
|
});
|
|
186
185
|
for (let k = spanners.length - 1; k >= 0; k--) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
186
|
+
const cell = spanners[k];
|
|
187
|
+
const span = cell[colSpan];
|
|
188
|
+
const col = cell[x];
|
|
190
189
|
let existingWidth = result[col];
|
|
191
190
|
let editableCols = typeof vals[col] === 'number' ? 0 : 1;
|
|
192
191
|
for (let i = 1; i < span; i++) {
|
|
@@ -199,7 +198,7 @@ function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) {
|
|
|
199
198
|
let i = 0;
|
|
200
199
|
while (editableCols > 0 && cell[desiredWidth] > existingWidth) {
|
|
201
200
|
if (typeof vals[col + i] !== 'number') {
|
|
202
|
-
|
|
201
|
+
const dif = Math.round((cell[desiredWidth] - existingWidth) / editableCols);
|
|
203
202
|
existingWidth += dif;
|
|
204
203
|
result[col + i] += dif;
|
|
205
204
|
editableCols--;
|
|
@@ -208,7 +207,7 @@ function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) {
|
|
|
208
207
|
}
|
|
209
208
|
}
|
|
210
209
|
}
|
|
211
|
-
|
|
210
|
+
Object.assign(vals, result);
|
|
212
211
|
for (let j = 0; j < vals.length; j++) {
|
|
213
212
|
vals[j] = Math.max(forcedMin, vals[j] || 0);
|
|
214
213
|
}
|
|
@@ -8,7 +8,7 @@ class Table extends Array {
|
|
|
8
8
|
}
|
|
9
9
|
toString() {
|
|
10
10
|
let array = this;
|
|
11
|
-
|
|
11
|
+
const headersPresent = this.options.head && this.options.head.length;
|
|
12
12
|
if (headersPresent) {
|
|
13
13
|
array = [this.options.head];
|
|
14
14
|
if (this.length) {
|
|
@@ -18,7 +18,7 @@ class Table extends Array {
|
|
|
18
18
|
else {
|
|
19
19
|
this.options.style.head = [];
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
const cells = tableLayout.makeTableLayout(array);
|
|
22
22
|
cells.forEach(function (row) {
|
|
23
23
|
row.forEach(function (cell) {
|
|
24
24
|
cell.mergeTableOptions(this.options, cells);
|
|
@@ -31,10 +31,10 @@ class Table extends Array {
|
|
|
31
31
|
cell.init(this.options);
|
|
32
32
|
}, this);
|
|
33
33
|
}, this);
|
|
34
|
-
|
|
34
|
+
const result = [];
|
|
35
35
|
for (let rowIndex = 0; rowIndex < cells.length; rowIndex++) {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const row = cells[rowIndex];
|
|
37
|
+
const heightOfRow = this.options.rowHeights[rowIndex];
|
|
38
38
|
if (rowIndex === 0 ||
|
|
39
39
|
!this.options.style.compact ||
|
|
40
40
|
(rowIndex == 1 && headersPresent)) {
|
|
@@ -50,16 +50,16 @@ class Table extends Array {
|
|
|
50
50
|
return result.join('\n');
|
|
51
51
|
}
|
|
52
52
|
get width() {
|
|
53
|
-
|
|
53
|
+
const str = this.toString().split('\n');
|
|
54
54
|
return str[0].length;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
function doDraw(row, lineNum, result) {
|
|
58
|
-
|
|
59
|
-
row.forEach(
|
|
58
|
+
const line = [];
|
|
59
|
+
row.forEach((cell) => {
|
|
60
60
|
line.push(cell.draw(lineNum));
|
|
61
61
|
});
|
|
62
|
-
|
|
62
|
+
const str = line.join('');
|
|
63
63
|
if (str.length) {
|
|
64
64
|
result.push(str);
|
|
65
65
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const objectAssign = require('object-assign');
|
|
3
2
|
const stringWidth = require('string-width');
|
|
4
3
|
function codeRegex(capture) {
|
|
5
4
|
return capture ? /\u001b\[((?:\d*;){0,5}\d*)m/g : /\u001b\[(?:\d*;){0,5}\d*m/g;
|
|
6
5
|
}
|
|
7
6
|
function strlen(str) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return split.reduce(
|
|
7
|
+
const code = codeRegex();
|
|
8
|
+
const stripped = ('' + str).replace(code, '');
|
|
9
|
+
const split = stripped.split('\n');
|
|
10
|
+
return split.reduce((memo, s) => {
|
|
12
11
|
return stringWidth(s) > memo ? stringWidth(s) : memo;
|
|
13
12
|
}, 0);
|
|
14
13
|
}
|
|
@@ -16,17 +15,17 @@ function repeat(str, times) {
|
|
|
16
15
|
return Array(times + 1).join(str);
|
|
17
16
|
}
|
|
18
17
|
function pad(str, len, pad, dir) {
|
|
19
|
-
|
|
18
|
+
const length = strlen(str);
|
|
20
19
|
if (len + 1 >= length) {
|
|
21
|
-
|
|
20
|
+
const padlen = len - length;
|
|
22
21
|
switch (dir) {
|
|
23
22
|
case 'right': {
|
|
24
23
|
str = repeat(pad, padlen) + str;
|
|
25
24
|
break;
|
|
26
25
|
}
|
|
27
26
|
case 'center': {
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const right = Math.ceil(padlen / 2);
|
|
28
|
+
const left = padlen - right;
|
|
30
29
|
str = repeat(pad, left) + str + repeat(pad, right);
|
|
31
30
|
break;
|
|
32
31
|
}
|
|
@@ -38,7 +37,7 @@ function pad(str, len, pad, dir) {
|
|
|
38
37
|
}
|
|
39
38
|
return str;
|
|
40
39
|
}
|
|
41
|
-
|
|
40
|
+
const codeCache = {};
|
|
42
41
|
function addToCodeCache(name, on, off) {
|
|
43
42
|
on = '\u001b[' + on + 'm';
|
|
44
43
|
off = '\u001b[' + off + 'm';
|
|
@@ -52,7 +51,7 @@ addToCodeCache('underline', 4, 24);
|
|
|
52
51
|
addToCodeCache('inverse', 7, 27);
|
|
53
52
|
addToCodeCache('strikethrough', 9, 29);
|
|
54
53
|
function updateState(state, controlChars) {
|
|
55
|
-
|
|
54
|
+
const controlCode = controlChars[1] ? parseInt(controlChars[1].split(';')[0]) : 0;
|
|
56
55
|
if ((controlCode >= 30 && controlCode <= 39) || (controlCode >= 90 && controlCode <= 97)) {
|
|
57
56
|
state.lastForegroundAdded = controlChars[0];
|
|
58
57
|
return;
|
|
@@ -62,22 +61,22 @@ function updateState(state, controlChars) {
|
|
|
62
61
|
return;
|
|
63
62
|
}
|
|
64
63
|
if (controlCode === 0) {
|
|
65
|
-
for (
|
|
64
|
+
for (const i in state) {
|
|
66
65
|
if (Object.prototype.hasOwnProperty.call(state, i)) {
|
|
67
66
|
delete state[i];
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
return;
|
|
71
70
|
}
|
|
72
|
-
|
|
71
|
+
const info = codeCache[controlChars[0]];
|
|
73
72
|
if (info) {
|
|
74
73
|
state[info.set] = info.to;
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
function readState(line) {
|
|
78
|
-
|
|
77
|
+
const code = codeRegex(true);
|
|
79
78
|
let controlChars = code.exec(line);
|
|
80
|
-
|
|
79
|
+
const state = {};
|
|
81
80
|
while (controlChars !== null) {
|
|
82
81
|
updateState(state, controlChars);
|
|
83
82
|
controlChars = code.exec(line);
|
|
@@ -85,11 +84,11 @@ function readState(line) {
|
|
|
85
84
|
return state;
|
|
86
85
|
}
|
|
87
86
|
function unwindState(state, ret) {
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
const lastBackgroundAdded = state.lastBackgroundAdded;
|
|
88
|
+
const lastForegroundAdded = state.lastForegroundAdded;
|
|
90
89
|
delete state.lastBackgroundAdded;
|
|
91
90
|
delete state.lastForegroundAdded;
|
|
92
|
-
Object.keys(state).forEach(
|
|
91
|
+
Object.keys(state).forEach((key) => {
|
|
93
92
|
if (state[key]) {
|
|
94
93
|
ret += codeCache[key].off;
|
|
95
94
|
}
|
|
@@ -103,11 +102,11 @@ function unwindState(state, ret) {
|
|
|
103
102
|
return ret;
|
|
104
103
|
}
|
|
105
104
|
function rewindState(state, ret) {
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
const lastBackgroundAdded = state.lastBackgroundAdded;
|
|
106
|
+
const lastForegroundAdded = state.lastForegroundAdded;
|
|
108
107
|
delete state.lastBackgroundAdded;
|
|
109
108
|
delete state.lastForegroundAdded;
|
|
110
|
-
Object.keys(state).forEach(
|
|
109
|
+
Object.keys(state).forEach((key) => {
|
|
111
110
|
if (state[key]) {
|
|
112
111
|
ret = codeCache[key].on + ret;
|
|
113
112
|
}
|
|
@@ -130,13 +129,13 @@ function truncateWidth(str, desiredLength) {
|
|
|
130
129
|
return str;
|
|
131
130
|
}
|
|
132
131
|
function truncateWidthWithAnsi(str, desiredLength) {
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
const code = codeRegex(true);
|
|
133
|
+
const split = str.split(codeRegex());
|
|
135
134
|
let splitIndex = 0;
|
|
136
135
|
let retLen = 0;
|
|
137
136
|
let ret = '';
|
|
138
137
|
let myArray;
|
|
139
|
-
|
|
138
|
+
const state = {};
|
|
140
139
|
while (retLen < desiredLength) {
|
|
141
140
|
myArray = code.exec(str);
|
|
142
141
|
let toAdd = split[splitIndex];
|
|
@@ -158,12 +157,12 @@ function truncateWidthWithAnsi(str, desiredLength) {
|
|
|
158
157
|
}
|
|
159
158
|
function truncate(str, desiredLength, truncateChar) {
|
|
160
159
|
truncateChar = truncateChar || '…';
|
|
161
|
-
|
|
160
|
+
const lengthOfStr = strlen(str);
|
|
162
161
|
if (lengthOfStr <= desiredLength) {
|
|
163
162
|
return str;
|
|
164
163
|
}
|
|
165
164
|
desiredLength -= strlen(truncateChar);
|
|
166
|
-
|
|
165
|
+
const ret = truncateWidthWithAnsi(str, desiredLength);
|
|
167
166
|
return ret + truncateChar;
|
|
168
167
|
}
|
|
169
168
|
function defaultOptions() {
|
|
@@ -203,19 +202,19 @@ function defaultOptions() {
|
|
|
203
202
|
function mergeOptions(options, defaults) {
|
|
204
203
|
options = options || {};
|
|
205
204
|
defaults = defaults || defaultOptions();
|
|
206
|
-
|
|
207
|
-
ret.chars =
|
|
208
|
-
ret.style =
|
|
205
|
+
const ret = Object.assign({}, defaults, options);
|
|
206
|
+
ret.chars = Object.assign({}, defaults.chars, options.chars);
|
|
207
|
+
ret.style = Object.assign({}, defaults.style, options.style);
|
|
209
208
|
return ret;
|
|
210
209
|
}
|
|
211
210
|
function wordWrap(maxLength, input) {
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
const lines = [];
|
|
212
|
+
const split = input.split(/(\s+)/g);
|
|
214
213
|
let line = [];
|
|
215
214
|
let lineLength = 0;
|
|
216
215
|
let whitespace;
|
|
217
216
|
for (let i = 0; i < split.length; i += 2) {
|
|
218
|
-
|
|
217
|
+
const word = split[i];
|
|
219
218
|
let newLength = lineLength + strlen(word);
|
|
220
219
|
if (lineLength > 0 && whitespace) {
|
|
221
220
|
newLength += whitespace.length;
|
|
@@ -239,7 +238,7 @@ function wordWrap(maxLength, input) {
|
|
|
239
238
|
return lines;
|
|
240
239
|
}
|
|
241
240
|
function multiLineWordWrap(maxLength, input) {
|
|
242
|
-
|
|
241
|
+
const output = [];
|
|
243
242
|
input = input.split('\n');
|
|
244
243
|
for (let i = 0; i < input.length; i++) {
|
|
245
244
|
output.push.apply(output, wordWrap(maxLength, input[i]));
|
|
@@ -248,11 +247,11 @@ function multiLineWordWrap(maxLength, input) {
|
|
|
248
247
|
}
|
|
249
248
|
function colorizeLines(input) {
|
|
250
249
|
let state = {};
|
|
251
|
-
|
|
250
|
+
const output = [];
|
|
252
251
|
for (let i = 0; i < input.length; i++) {
|
|
253
|
-
|
|
252
|
+
const line = rewindState(state, input[i]);
|
|
254
253
|
state = readState(line);
|
|
255
|
-
|
|
254
|
+
const temp = Object.assign({}, state);
|
|
256
255
|
output.push(unwindState(temp, line));
|
|
257
256
|
}
|
|
258
257
|
return output;
|