Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ junit.xml
oclif.manifest.json
.vscode
.idea
.claude
41 changes: 41 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2019 Adobe Inc. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

const aioConfig = require('@adobe/eslint-config-aio-lib-config')
const jestPlugin = require('eslint-plugin-jest')

const testGlobals = {
fixtureFile: 'readonly',
fixtureFileWithTimeZoneAdjustment: 'readonly',
fixtureJson: 'readonly',
fixtureZip: 'readonly',
fakeFileSystem: 'readonly',
createTestBaseFlagsFunction: 'readonly',
createTestFlagsFunction: 'readonly'
}

module.exports = [
...aioConfig,
{
ignores: ['node_modules/**', 'coverage/**']
},
{
files: ['test/**/*.js', 'e2e/**/*.js'],
...jestPlugin.configs['flat/recommended'],
languageOptions: {
globals: {
...jestPlugin.configs['flat/recommended'].languageOptions.globals,
...testGlobals
}
}
}
]
17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@adobe/aio-lib-env": "^3.0.1",
"@adobe/aio-lib-ims": "^8.0.1",
"@adobe/aio-lib-runtime": "^7.1.0",
"@oclif/core": "^2.8.12",
"@oclif/core": "^4.0.0",
"@types/jest": "^29.5.3",
"chalk": "^4.1.2",
"dayjs": "^1.10.4",
Expand All @@ -27,26 +27,21 @@
"sha1": "^1.1.1"
},
"devDependencies": {
"@adobe/eslint-config-aio-lib-config": "^4.0.0",
"@adobe/eslint-config-aio-lib-config": "5.0.0",
"@babel/core": "^7.16.12",
"@babel/preset-env": "^7.16.11",
"babel-jest": "^29.5.0",
"babel-runtime": "^6.26.0",
"dedent-js": "^1.0.1",
"eol": "^0.10.0",
"eslint": "^8.57.1",
"eslint-config-oclif": "^5.2.2",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^27.9.0",
"eslint": "^9.0.0",
"eslint-plugin-jest": "^29.0.0",
"eslint-plugin-jsdoc": "^48.11.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.6.0",
"execa": "^4.0.0",
"jest": "^29.6.2",
"jest-junit": "^16.0.0",
"oclif": "^3.2.0",
"neostandard": "^0",
"oclif": "^4.0.0",
"stdout-stderr": "^0.1.9"
},
"engines": {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/runtime/action/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ governing permissions and limitations under the License.
const moment = require('dayjs')
const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
const { parsePackageName } = require('@adobe/aio-lib-runtime').utils
const { Args, Flags, ux } = require('@oclif/core')
const { Args, Flags } = require('@oclif/core')
const { table } = require('../../../ux-table')
const decorators = require('../../../decorators').decorators()

class ActionList extends RuntimeBaseCommand {
Expand Down Expand Up @@ -86,7 +87,7 @@ class ActionList extends RuntimeBaseCommand {
}
}
}
ux.table(result, columns)
table(result, columns)
}
} catch (err) {
await this.handleError('failed to list the actions', err)
Expand Down
5 changes: 3 additions & 2 deletions src/commands/runtime/activation/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ governing permissions and limitations under the License.

const moment = require('dayjs')
const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
const { Args, Flags, ux } = require('@oclif/core')
const { Args, Flags } = require('@oclif/core')
const { table } = require('../../../ux-table')
const decorators = require('../../../decorators').decorators()
const statusStrings = ['success', 'app error', 'dev error', 'sys error']

Expand Down Expand Up @@ -187,7 +188,7 @@ class ActivationList extends RuntimeBaseCommand {
}
}
if (listActivation) {
ux.table(listActivation, columns, {
table(listActivation, columns, {
'no-truncate': true
})
}
Expand Down
12 changes: 4 additions & 8 deletions src/commands/runtime/api/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ governing permissions and limitations under the License.
*/

const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
const { Args, Flags, ux } = require('@oclif/core')
const { Args, Flags } = require('@oclif/core')
const { table } = require('../../../ux-table')

/** @private */
function processApi (api) {
Expand Down Expand Up @@ -40,13 +41,8 @@ function processApi (api) {

class ApiList extends RuntimeBaseCommand {
async run () {
// Workaround for oclif v2 parsing issue: capture argv before parse() when multiple optional args are present
// oclif v2 doesn't properly parse --json flag when command has 3+ optional positional arguments
// Related: https://github.com/oclif/core/issues/854 (workaround: search argv directly)
const argvBeforeParse = [...(this.argv ?? [])]
const { args, flags } = await this.parse(ApiList)
const hasJsonInArgv = argvBeforeParse.includes('--json')
const shouldOutputJson = flags.json || hasJsonInArgv
const shouldOutputJson = flags.json

try {
const ow = await this.wsk()
Expand Down Expand Up @@ -74,7 +70,7 @@ class ApiList extends RuntimeBaseCommand {
}, data)
})

ux.table(data, {
table(data, {
Action: { minWidth: 10 },
Verb: { minWidth: 10 },
APIName: { header: 'API Name', minWidth: 10 },
Expand Down
11 changes: 6 additions & 5 deletions src/commands/runtime/namespace/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ governing permissions and limitations under the License.
*/

const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
const { Flags, ux } = require('@oclif/core')
const { Flags } = require('@oclif/core')
const { table } = require('../../../ux-table')

/** @private */
function createColumns (columnName) {
Expand Down Expand Up @@ -79,10 +80,10 @@ class NamespaceGet extends RuntimeBaseCommand {
} else {
this.log('Entities in namespace:')

ux.table(data.packages, createColumns('packages'))
ux.table(data.actions, createColumns('actions'))
ux.table(data.triggers, createColumns('triggers'))
ux.table(data.rules, createColumns('rules'))
table(data.packages, createColumns('packages'))
table(data.actions, createColumns('actions'))
table(data.triggers, createColumns('triggers'))
table(data.rules, createColumns('rules'))
}
} catch (err) {
await this.handleError('failed to get the data for a namespace', err)
Expand Down
5 changes: 3 additions & 2 deletions src/commands/runtime/namespace/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ governing permissions and limitations under the License.
*/

const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
const { Flags, ux } = require('@oclif/core')
const { Flags } = require('@oclif/core')
const { table } = require('../../../ux-table')

class NamespaceList extends RuntimeBaseCommand {
async run () {
Expand All @@ -29,7 +30,7 @@ class NamespaceList extends RuntimeBaseCommand {
get: row => row
}
}
ux.table(result, columns)
table(result, columns)
}
} catch (err) {
await this.handleError('failed to list namespaces', err)
Expand Down
5 changes: 3 additions & 2 deletions src/commands/runtime/package/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ governing permissions and limitations under the License.

const moment = require('dayjs')
const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
const { Args, Flags, ux } = require('@oclif/core')
const { Args, Flags } = require('@oclif/core')
const { table } = require('../../../ux-table')

class PackageList extends RuntimeBaseCommand {
async run () {
Expand Down Expand Up @@ -78,7 +79,7 @@ class PackageList extends RuntimeBaseCommand {
get: row => row.name
}
}
ux.table(result, columns)
table(result, columns)
}
} catch (err) {
await this.handleError('failed to list the packages', err)
Expand Down
5 changes: 3 additions & 2 deletions src/commands/runtime/property/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ governing permissions and limitations under the License.
*/

const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
const { Flags, ux } = require('@oclif/core')
const { Flags } = require('@oclif/core')
const { table } = require('../../../ux-table')
const { createFetch } = require('@adobe/aio-lib-core-networking')
const { PropertyKey, PropertyDefault, propertiesFile, PropertyEnv } = require('../../../properties')
const debug = require('debug')('aio-cli-plugin-runtime/property')
Expand Down Expand Up @@ -90,7 +91,7 @@ class PropertyGet extends RuntimeBaseCommand {
data.push({ Property: PropertyGet.flags.apibuildno.description, Value: result.buildno })
}
}
ux.table(data,
table(data,
{
Property: { minWidth: 10 },
Value: { minWidth: 20 }
Expand Down
5 changes: 3 additions & 2 deletions src/commands/runtime/rule/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ governing permissions and limitations under the License.

const moment = require('dayjs')
const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
const { Flags, ux } = require('@oclif/core')
const { Flags } = require('@oclif/core')
const { table } = require('../../../ux-table')

class RuleList extends RuntimeBaseCommand {
async run () {
Expand Down Expand Up @@ -68,7 +69,7 @@ class RuleList extends RuntimeBaseCommand {
get: row => row.name
}
}
ux.table(resultsWithStatus, columns)
table(resultsWithStatus, columns)
}
})
return p
Expand Down
5 changes: 3 additions & 2 deletions src/commands/runtime/trigger/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ governing permissions and limitations under the License.

const moment = require('dayjs')
const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
const { Flags, ux } = require('@oclif/core')
const { Flags } = require('@oclif/core')
const { table } = require('../../../ux-table')

class TriggerList extends RuntimeBaseCommand {
async run () {
Expand Down Expand Up @@ -84,7 +85,7 @@ class TriggerList extends RuntimeBaseCommand {
get: row => row.name
}
}
ux.table(resultsWithStatus, columns)
table(resultsWithStatus, columns)
}
})
} catch (err) {
Expand Down
79 changes: 79 additions & 0 deletions src/ux-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright 2019 Adobe Inc. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

/**
* Print a simple text table to stdout.
*
* Replaces ux.table from @oclif/core v1-v3 (removed in v4).
*
* @param {Array} data - Array of data objects
* @param {object} columns - Column definitions. Each key maps to a column. Supports:
* - header {string}: column header (defaults to key, capitalized)
* - get {function}: accessor function (defaults to row[key])
* - minWidth {number}: minimum column width
* @param {object} [options] - Options:
* - printLine {function}: function to print a line (defaults to process.stdout.write)
* - 'no-header' {boolean}: skip printing the header row
* - 'no-truncate' {boolean}: ignored (included for API compatibility)
*/
function table (data, columns, options = {}) {
const printLine = options.printLine || ((s) => process.stdout.write(s + '\n'))

const cols = Object.keys(columns).map(key => {
const col = columns[key]
const header = typeof col.header === 'string' ? col.header : key.charAt(0).toUpperCase() + key.slice(1)
const getValue = col.get || ((row) => row[key])
const minWidth = Math.max(col.minWidth || 0, col.maxWidth || 0, header.length + 1)
return { key, header, getValue, minWidth }
})

// Compute string values for all rows
const rows = data.map(row => {
const result = {}
for (const col of cols) {
const val = col.getValue(row)
result[col.key] = val != null ? String(val) : ''
}
return result
})

// Compute column widths: max of minWidth and widest value + 1
const widths = {}
for (const col of cols) {
const maxDataWidth = rows.length > 0 ? Math.max(...rows.map(r => r[col.key].length)) : 0
widths[col.key] = Math.max(col.minWidth, maxDataWidth + 1)
}

const rowStart = ' '

// Print header and divider
let header = rowStart
let divider = rowStart
for (const col of cols) {
const w = widths[col.key]
header += col.header.padEnd(w)
divider += ''.padEnd(w - 1, '─') + ' '
}
printLine(header)
printLine(divider)

// Print rows
for (const row of rows) {
let line = rowStart
for (const col of cols) {
line += row[col.key].padEnd(widths[col.key])
}
printLine(line)
}
}

module.exports = { table }
Loading
Loading