Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit 356b8e2

Browse files
chore: replace cliff table formatter, liv-6540 (#24)
* chore: replace cliff table formatter use chalk + console-table-printer combo instead * chore: add lodash support * fix: rows mapping build * fix(test): mock envs list data
1 parent a18d8bf commit 356b8e2

File tree

6 files changed

+99
-105
lines changed

6 files changed

+99
-105
lines changed

__tests__/cmds/envs/list.spec.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ jest.mock('configstore')
66
const mockedConfigstore = jest.mocked(configStore, true)
77

88
describe('List command', () => {
9+
const get = mockedConfigstore.mock.instances[0].get as jest.Mock
10+
const envsData = { 'boron': { 'endpoint': 'endpoint_url' } }
11+
12+
get.mockReturnValue(envsData)
913
envs({
1014
_: ['list']
1115
})
1216

1317
it('should call correctly the config store to get all entries of envs', () => {
14-
const get = mockedConfigstore.mock.instances[0].get as jest.Mock
1518
expect(get).toHaveBeenCalled()
1619

17-
const [ key ] = get.mock.calls[0]
20+
const [ key ] = get.mock.calls[0]
1821
expect(key).toBe(`envs`)
19-
});
22+
})
2023
})

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@livestorm/cli",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "CLI that allows you to build and deploy your Livestorm plugin",
55
"main": "index.js",
66
"bin": {
@@ -15,10 +15,12 @@
1515
},
1616
"dependencies": {
1717
"adm-zip": "^0.5.5",
18-
"cliff": "^0.1.10",
18+
"chalk": "4.1.2",
1919
"command-line-args": "^5.1.1",
2020
"configstore": "^5.0.1",
21+
"console-table-printer": "^2.11.0",
2122
"debounce": "^1.2.1",
23+
"lodash": "^4.17.21",
2224
"minimist": "^1.2.5",
2325
"node-fetch": "^2.6.1",
2426
"node-watch": "^0.7.2",

src/cmds/envs.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const cliff = require('cliff')
1+
const { Table } = require('console-table-printer')
2+
const chalk = require('chalk')
3+
const zibObject = require('lodash/zipObject')
24
const configStore = require('../helpers/configStore.js')
35

46
const ENV_CONFIG_FIELDS = [
@@ -63,11 +65,20 @@ function list() {
6365
return console.log('There are no stored environments.')
6466
}
6567

66-
const rows = [
67-
['name', ...ENV_CONFIG_FIELDS],
68-
...envsKeys.map(envName => [envName, ...ENV_CONFIG_FIELDS.map(key => envs[envName][key] ?? '(Not Set)')])
69-
]
70-
console.log(cliff.stringifyRows(rows, ['blue']))
68+
const headers = ['name', ...ENV_CONFIG_FIELDS]
69+
const table = new Table({
70+
columns: headers.map(field => {
71+
return {
72+
name: field,
73+
title: chalk.blue(field),
74+
alignment: 'left'
75+
}
76+
})
77+
})
78+
const rowArrays = envsKeys.map(envName => [envName, ...ENV_CONFIG_FIELDS.map(key => envs[envName][key] ?? '(Not Set)')])
79+
const rows = rowArrays.map(row => zibObject(headers, row))
80+
table.addRows(rows)
81+
table.printTable()
7182
}
7283

7384
module.exports = function envs(argv) {

src/cmds/help.js

+32-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
const cliff = require('cliff')
1+
const { Table } = require('console-table-printer')
2+
const chalk = require('chalk')
3+
4+
const table = new Table({
5+
columns: [
6+
{
7+
name: 'command',
8+
alignment: 'left',
9+
title: chalk.blue('Command'),
10+
},
11+
{
12+
name: 'description',
13+
alignment: 'left',
14+
title: chalk.blue('Description'),
15+
}
16+
]
17+
})
218

319
module.exports = () => {
420
console.log(`
@@ -12,23 +28,22 @@ _ /____/ / __ |/ / _ /___ ____/ /_ / / /_/ /_ _, _/_ / / /
1228
console.log('Take your events to the next level with Livestorm plugins, a powerful SDK designed to let you build amazing experiences, on top of a platform you already love.')
1329
console.log('This CLI allows you to build, publish and manage your Livestorm plugins.')
1430
console.log('\n')
15-
console.log(
16-
cliff.stringifyRows([
17-
['command','description'],
18-
['create', 'Generate a new plugin'],
19-
['publish <environment>', 'Publish your plugin'],
20-
['watch <environment>', 'Publish your plugin each time you make a change'],
21-
['review', 'Ask Livestorm a review to publish your plugin to our marketplace or access private APIs'],
22-
['remove <environment>', 'Unpublish the plugin'],
23-
['asset <file>', 'Upload files and use them in your plugins'],
24-
['list [--environment|--api-token]', 'List the published plugins'],
25-
['envs [add|remove|list] <environment> [--api-token|--endpoint]', 'Manage your environments'],
26-
['upgrade', 'Upgrade Livestorm Plugins CLI'],
27-
['version', 'Output the current version of the CLI'],
28-
], ['blue', 'blue'])
29-
)
3031

31-
console.log(`\n`)
32+
table.addRows([
33+
{ command: 'create', description: 'Generate a new plugin' },
34+
{ command: 'publish <environment>', description: 'Publish your plugin' },
35+
{ command: 'watch <environment>', description: 'Publish your plugin each time you make a change' },
36+
{ command: 'review', description: 'Ask Livestorm a review to publish your plugin to our marketplace or access private APIs' },
37+
{ command: 'remove <environment>', description: 'Unpublish the plugin' },
38+
{ command: 'asset <file>', description: 'Upload files and use them in your plugins' },
39+
{ command: 'list [--environment|--api-token]', description: 'List the published plugins' },
40+
{ command: 'envs [add|remove|list] <environment> [--api-token|--endpoint]', description: 'Manage your environments' },
41+
{ command: 'upgrade', description: 'Upgrade Livestorm Plugins CLI' },
42+
{ command: 'version', description: 'Output the current version of the CLI' },
43+
])
44+
table.printTable()
45+
46+
console.log('')
3247
console.log(`Check out our getting started guide: https://developers.livestorm.co/docs/getting-started-with-plugins-sdk`)
3348
console.log('and our offical video course: https://fast.wistia.net/embed/channel/azooxwj070')
3449
console.log('Love developing plugins? Check out our open positions: https://jobs.livestorm.co/')

src/cmds/list.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { default: fetch } = require('node-fetch')
22
const commandLineArgs = require('command-line-args')
3-
const cliff = require('cliff')
3+
const { Table } = require('console-table-printer')
4+
const chalk = require('chalk')
45

56
const getLivestormConfig = require('../helpers/getLivestormConfig')
67
const setLocalProxyIfNeeded = require('../helpers/setLocalProxyIfNeeded')
@@ -53,10 +54,22 @@ function handleResponse(response) {
5354
return console.log('No plugins found on this organization.')
5455
}
5556

57+
const table = new Table({
58+
columns: [
59+
{
60+
name: 'id',
61+
title: chalk.blue('ID'),
62+
alignment: 'left'
63+
},
64+
{
65+
name: 'name',
66+
title: chalk.blue('Name'),
67+
alignment: 'left'
68+
}
69+
]
70+
})
5671

57-
const rows = [
58-
['ID', 'Name'],
59-
...response.plugins.map((plugin) => [plugin.id, plugin.name])
60-
]
61-
console.log(cliff.stringifyRows(rows, ['blue', 'blue']))
72+
const rows = response.plugins.map((plugin) => ({ id: plugin.id, name: plugin.name }))
73+
table.addRows(rows)
74+
table.printTable()
6275
}

yarn.lock

+21-71
Original file line numberDiff line numberDiff line change
@@ -1355,11 +1355,6 @@ array-union@^2.1.0:
13551355
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
13561356
integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==
13571357

1358-
1359-
version "0.2.10"
1360-
resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1"
1361-
integrity sha1-trvgsGdLnXGXCMo43owjfLUmw9E=
1362-
13631358
asynckit@^0.4.0:
13641359
version "0.4.0"
13651360
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
@@ -1533,6 +1528,14 @@ caniuse-lite@^1.0.30001286:
15331528
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001304.tgz#38af55ed3fc8220cb13e35e6e7309c8c65a05559"
15341529
integrity sha512-bdsfZd6K6ap87AGqSHJP/s1V+U6Z5lyrcbBu3ovbCCf8cSYpwTtGrCBObMpJqwxfTbLW6YTIdbb1jEeTelcpYQ==
15351530

1531+
[email protected], chalk@^4.0.0:
1532+
version "4.1.2"
1533+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
1534+
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
1535+
dependencies:
1536+
ansi-styles "^4.1.0"
1537+
supports-color "^7.1.0"
1538+
15361539
chalk@^2.0.0:
15371540
version "2.4.2"
15381541
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
@@ -1542,14 +1545,6 @@ chalk@^2.0.0:
15421545
escape-string-regexp "^1.0.5"
15431546
supports-color "^5.3.0"
15441547

1545-
chalk@^4.0.0:
1546-
version "4.1.2"
1547-
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
1548-
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
1549-
dependencies:
1550-
ansi-styles "^4.1.0"
1551-
supports-color "^7.1.0"
1552-
15531548
char-regex@^1.0.2:
15541549
version "1.0.2"
15551550
resolved "https://registry.yarnpkg.com/char-regex/-/char-regex-1.0.2.tgz#d744358226217f981ed58f479b1d6bcc29545dcf"
@@ -1570,15 +1565,6 @@ clean-stack@^2.0.0:
15701565
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
15711566
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==
15721567

1573-
cliff@^0.1.10:
1574-
version "0.1.10"
1575-
resolved "https://registry.yarnpkg.com/cliff/-/cliff-0.1.10.tgz#53be33ea9f59bec85609ee300ac4207603e52013"
1576-
integrity sha1-U74z6p9ZvshWCe4wCsQgdgPlIBM=
1577-
dependencies:
1578-
colors "~1.0.3"
1579-
eyes "~0.1.8"
1580-
winston "0.8.x"
1581-
15821568
cliui@^7.0.2:
15831569
version "7.0.4"
15841570
resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f"
@@ -1622,16 +1608,6 @@ color-name@~1.1.4:
16221608
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
16231609
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
16241610

1625-
1626-
version "0.6.2"
1627-
resolved "https://registry.yarnpkg.com/colors/-/colors-0.6.2.tgz#2423fe6678ac0c5dae8852e5d0e5be08c997abcc"
1628-
integrity sha1-JCP+ZnisDF2uiFLl0OW+CMmXq8w=
1629-
1630-
colors@~1.0.3:
1631-
version "1.0.3"
1632-
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
1633-
integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=
1634-
16351611
combined-stream@^1.0.8:
16361612
version "1.0.8"
16371613
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
@@ -1666,6 +1642,13 @@ configstore@^5.0.1:
16661642
write-file-atomic "^3.0.0"
16671643
xdg-basedir "^4.0.0"
16681644

1645+
console-table-printer@^2.11.0:
1646+
version "2.11.0"
1647+
resolved "https://registry.yarnpkg.com/console-table-printer/-/console-table-printer-2.11.0.tgz#704a74cb56d66267a2527f500fedcaa78ca76259"
1648+
integrity sha512-F5H5/lFciTV2OBI/xDh/x7nZAM6YPqkbkoIxr8px4B/nSvUV4ymsi4BL0bwRwrRcOgtp/LqGJGgGmkicAMd8LQ==
1649+
dependencies:
1650+
simple-wcswidth "^1.0.1"
1651+
16691652
convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
16701653
version "1.8.0"
16711654
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.8.0.tgz#f3373c32d21b4d780dd8004514684fb791ca4369"
@@ -1712,11 +1695,6 @@ cssstyle@^2.3.0:
17121695
dependencies:
17131696
cssom "~0.3.6"
17141697

1715-
1716-
version "1.0.3"
1717-
resolved "https://registry.yarnpkg.com/cycle/-/cycle-1.0.3.tgz#21e80b2be8580f98b468f379430662b046c34ad2"
1718-
integrity sha1-IegLK+hYD5i0aPN5QwZisEbDStI=
1719-
17201698
data-urls@^2.0.0:
17211699
version "2.0.0"
17221700
resolved "https://registry.yarnpkg.com/data-urls/-/data-urls-2.0.0.tgz#156485a72963a970f5d5821aaf642bef2bf2db9b"
@@ -1902,11 +1880,6 @@ expect@^27.4.6:
19021880
jest-matcher-utils "^27.4.6"
19031881
jest-message-util "^27.4.6"
19041882

1905-
[email protected], eyes@~0.1.8:
1906-
version "0.1.8"
1907-
resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0"
1908-
integrity sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A=
1909-
19101883
fast-glob@^3.2.9:
19111884
version "3.2.11"
19121885
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
@@ -2253,11 +2226,6 @@ isexe@^2.0.0:
22532226
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
22542227
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
22552228

2256-
2257-
version "0.1.2"
2258-
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
2259-
integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=
2260-
22612229
istanbul-lib-coverage@^3.0.0, istanbul-lib-coverage@^3.2.0:
22622230
version "3.2.0"
22632231
resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.0.tgz#189e7909d0a39fa5a3dfad5b03f71947770191d3"
@@ -2802,7 +2770,7 @@ lodash.debounce@^4.0.8:
28022770
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
28032771
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=
28042772

2805-
lodash@^4.7.0:
2773+
lodash@^4.17.21, lodash@^4.7.0:
28062774
version "4.17.21"
28072775
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
28082776
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
@@ -3041,11 +3009,6 @@ pkg-dir@^4.2.0:
30413009
dependencies:
30423010
find-up "^4.0.0"
30433011

3044-
3045-
version "0.3.1"
3046-
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.3.1.tgz#5b29f6a81f70717142e09e765bbeab97b4f81e21"
3047-
integrity sha1-Wyn2qB9wcXFC4J52W76rl7T4HiE=
3048-
30493012
prelude-ls@~1.1.2:
30503013
version "1.1.2"
30513014
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
@@ -3245,6 +3208,11 @@ signal-exit@^3.0.2, signal-exit@^3.0.3:
32453208
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.6.tgz#24e630c4b0f03fea446a2bd299e62b4a6ca8d0af"
32463209
integrity sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ==
32473210

3211+
simple-wcswidth@^1.0.1:
3212+
version "1.0.1"
3213+
resolved "https://registry.yarnpkg.com/simple-wcswidth/-/simple-wcswidth-1.0.1.tgz#8ab18ac0ae342f9d9b629604e54d2aa1ecb018b2"
3214+
integrity sha512-xMO/8eNREtaROt7tJvWJqHBDTMFN4eiQ5I4JRMuilwfnFcV5W9u7RUkueNkdw0jPqGMX36iCywelS5yilTuOxg==
3215+
32483216
sisteransi@^1.0.5:
32493217
version "1.0.5"
32503218
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
@@ -3283,11 +3251,6 @@ sprintf-js@~1.0.2:
32833251
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
32843252
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=
32853253

3286-
3287-
version "0.0.10"
3288-
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
3289-
integrity sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=
3290-
32913254
stack-utils@^2.0.3:
32923255
version "2.0.5"
32933256
resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-2.0.5.tgz#d25265fca995154659dbbfba3b49254778d2fdd5"
@@ -3560,19 +3523,6 @@ which@^2.0.1:
35603523
dependencies:
35613524
isexe "^2.0.0"
35623525

3563-
3564-
version "0.8.3"
3565-
resolved "https://registry.yarnpkg.com/winston/-/winston-0.8.3.tgz#64b6abf4cd01adcaefd5009393b1d8e8bec19db0"
3566-
integrity sha1-ZLar9M0Brcrv1QCTk7HY6L7BnbA=
3567-
dependencies:
3568-
async "0.2.x"
3569-
colors "0.6.x"
3570-
cycle "1.0.x"
3571-
eyes "0.1.x"
3572-
isstream "0.1.x"
3573-
pkginfo "0.3.x"
3574-
stack-trace "0.0.x"
3575-
35763526
word-wrap@~1.2.3:
35773527
version "1.2.3"
35783528
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"

0 commit comments

Comments
 (0)