Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(deps): remove dependency on table (#171)
- Loading branch information
Showing
5 changed files
with
60 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"aws-sdk-js-codemod": patch | ||
--- | ||
|
||
Remove dependency 'table' |
This file contains 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 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 |
---|---|---|
@@ -1,23 +1,17 @@ | ||
import { getBorderCharacters, table } from "table"; | ||
|
||
import { AwsSdkJsCodemodTransform } from "../transforms"; | ||
import { getTransformDescription } from "./getTransformDescription"; | ||
|
||
const separator = "-".repeat(95); | ||
|
||
export const getHelpParagraph = (transforms: AwsSdkJsCodemodTransform[]) => | ||
`---------------------------------------------------------------------------------------------------- | ||
`${separator} | ||
aws-sdk-js-codemod is a lightweight wrapper over jscodeshift. | ||
It processes --help, --version and --transform options before passing them downstream. | ||
You can provide names of the custom transforms instead of a local path or url: | ||
${table( | ||
transforms.map(({ name, description }) => [name, description]), | ||
{ | ||
border: getBorderCharacters("void"), | ||
columns: [ | ||
{ width: 12, alignment: "right" }, | ||
{ width: 88, wrapWord: true }, | ||
], | ||
} | ||
)}Example: aws-sdk-js-codemod -t v2-to-v3 example.js | ||
${transforms.map((transform) => getTransformDescription(transform).join("\n"))} | ||
Example: aws-sdk-js-codemod -t v2-to-v3 example.js | ||
----------------------------------------------------------------------------------------------------\n\n`; | ||
${separator}\n\n`; |
This file contains 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,46 @@ | ||
import { AwsSdkJsCodemodTransform } from "../transforms"; | ||
|
||
const getWrappedBlocks = (sentence: string, blockLength: number): string[] => { | ||
const words = sentence.split(" "); | ||
const blocks = []; | ||
let currentBlock = ""; | ||
|
||
// iterate over the words and add them to blocks | ||
for (const word of words) { | ||
// if the current block plus the next word is longer than the block length, | ||
// add the current block to the list of blocks and start a new block | ||
if (currentBlock.length + word.length > blockLength) { | ||
blocks.push(currentBlock); | ||
currentBlock = ""; | ||
} | ||
|
||
// add the word to the current block | ||
currentBlock += word + " "; | ||
} | ||
|
||
// add the final block to the list of blocks | ||
blocks.push(currentBlock); | ||
|
||
return blocks; | ||
}; | ||
|
||
export const getTransformDescription = (transform: AwsSdkJsCodemodTransform): string[] => { | ||
const descriptionArr: string[] = []; | ||
|
||
const columnLength = 15; | ||
const borderLength = 2; | ||
|
||
descriptionArr[0] = | ||
" ".repeat(columnLength - borderLength - transform.name.length) + | ||
transform.name + | ||
" ".repeat(borderLength); | ||
|
||
const wrappedBlocks = getWrappedBlocks(transform.description, 80); | ||
|
||
descriptionArr[0] += wrappedBlocks[0]; | ||
for (let i = 1; i < wrappedBlocks.length; i++) { | ||
descriptionArr.push(" ".repeat(columnLength) + wrappedBlocks[i]); | ||
} | ||
|
||
return descriptionArr; | ||
}; |
This file contains 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