-
Notifications
You must be signed in to change notification settings - Fork 4
feat: copy oclif/core ux methods #537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
36d7506
feat: copy oclif/core ux methods
mdonnalley 4fa9d7e
feat: use cli-progress instead of ux.progress
mdonnalley 03568ce
test: add integration tests for table
mdonnalley 32597dd
test: remove test
mdonnalley 8efcdb8
refactor: re-enable eslint rules
mdonnalley 9e07e9c
refactor: use AnyJson for styledObject
mdonnalley 18dcba8
feat!: use next major of oclif/core
mdonnalley 2a5c355
chore: use ux.stdout from core
mdonnalley a56f19a
chore: bump @oclif/core
mdonnalley bdb8301
chore(release): 9.0.3-beta.0 [skip ci]
svc-cli-bot 005e598
chore: bump @oclif/core
mdonnalley 428c34a
chore(release): 9.0.3-beta.1 [skip ci]
svc-cli-bot 4307176
ci: update preBuildCommands
mdonnalley 80e989b
ci: update preBuildCommands
mdonnalley 5f9dadc
chore: bump core
mdonnalley 309ed32
chore: bump core
mdonnalley 193057b
Merge branch 'main' into mdonnalley/ux
mdonnalley 8c90989
chore(release): 9.0.14-beta.1 [skip ci]
svc-cli-bot edf5d39
fix: core v4
mdonnalley a75de29
Merge branch 'main' into mdonnalley/ux
mdonnalley 59c8067
chore(release): 9.1.1-beta.1 [skip ci]
svc-cli-bot e7fbd29
test: dont rm oclif/core for external nuts
mdonnalley 44191a1
test: remove ocilf/core in prebuild
mdonnalley 5f0b39f
chore: make new major
mdonnalley 704b2cf
chore(release): 10.0.0-beta.1 [skip ci]
svc-cli-bot aa63615
chore: code review
mdonnalley 744666f
style: todo for mutation bug
mshanemc ad634d1
test: try slow integration test
mshanemc 7832d2b
chore: sfdx-core bump for xnuts
mshanemc 0ea459c
test: re-skip
mshanemc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { createRequire } from 'node:module'; | ||
import { highlight, CardinalTheme } from 'cardinal'; | ||
import chalk from 'chalk'; | ||
|
||
// @oclif/core v4 will have native support for coloring JSON so we won't need this then. | ||
export default function styledJSON(obj: unknown): string { | ||
const json = JSON.stringify(obj, null, 2); | ||
if (!chalk.level) { | ||
return json; | ||
} | ||
|
||
const require = createRequire(import.meta.url); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const theme = require('cardinal/themes/jq') as CardinalTheme; | ||
return highlight(json, { theme }); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { inspect } from 'node:util'; | ||
import chalk from 'chalk'; | ||
import { AnyJson } from '@salesforce/ts-types'; | ||
|
||
function prettyPrint(obj: AnyJson): string { | ||
if (!obj) return inspect(obj); | ||
if (typeof obj === 'string') return obj; | ||
if (typeof obj === 'number') return obj.toString(); | ||
if (typeof obj === 'boolean') return obj.toString(); | ||
if (typeof obj === 'object') { | ||
return Object.entries(obj) | ||
.map(([key, value]) => `${key}: ${inspect(value)}`) | ||
.join(', '); | ||
} | ||
|
||
return inspect(obj); | ||
} | ||
|
||
export default function styledObject(obj: AnyJson, keys?: string[]): string { | ||
if (!obj) return inspect(obj); | ||
if (typeof obj === 'string') return obj; | ||
if (typeof obj === 'number') return obj.toString(); | ||
if (typeof obj === 'boolean') return obj.toString(); | ||
|
||
const output: string[] = []; | ||
const keyLengths = Object.keys(obj).map((key) => key.toString().length); | ||
const maxKeyLength = Math.max(...keyLengths) + 2; | ||
|
||
const logKeyValue = (key: string, value: AnyJson): string => | ||
`${chalk.blue(key)}:` + ' '.repeat(maxKeyLength - key.length - 1) + prettyPrint(value); | ||
|
||
for (const [key, value] of Object.entries(obj)) { | ||
if (keys && !keys.includes(key)) continue; | ||
if (Array.isArray(value)) { | ||
if (value.length > 0) { | ||
output.push(logKeyValue(key, value[0])); | ||
for (const e of value.slice(1)) { | ||
output.push(' '.repeat(maxKeyLength) + prettyPrint(e)); | ||
} | ||
} | ||
} else if (value !== null && value !== undefined) { | ||
output.push(logKeyValue(key, value)); | ||
} | ||
} | ||
|
||
return output.join('\n'); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.