Skip to content
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

refactor!: tsc/ESM/Deno support #82

Merged
merged 9 commits into from Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions .eslintrc
@@ -0,0 +1,21 @@
{
"overrides": [
{
"files": "*.ts",
"parser": "@typescript-eslint/parser",
"rules": {
"no-unused-vars": "off",
"no-useless-constructor": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-useless-constructor": "error"
}
}
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint/eslint-plugin"
]
}
24 changes: 24 additions & 0 deletions .github/workflows/ci.yaml
Expand Up @@ -43,3 +43,27 @@ jobs:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- run: npm test
- run: npm run coverage
esm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm run test:esm
deno:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm run compile
- uses: denolib/setup-deno@v2
with:
deno-version: v1.x
- run: |
deno --version
deno test test/deno/cliui-test.ts
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -3,4 +3,4 @@ node_modules
.nyc_output
package-lock.json
coverage

build
6 changes: 3 additions & 3 deletions .nycrc
Expand Up @@ -7,7 +7,7 @@
"html",
"text"
],
"lines": 98.0,
"branches": "98",
"statements": "98.0"
"lines": 99.0,
"branches": "95",
"statements": "99.0"
}
30 changes: 28 additions & 2 deletions README.md
Expand Up @@ -10,13 +10,13 @@ easily create complex multi-column command-line-interfaces.
## Example

```js
var ui = require('cliui')()
const ui = require('cliui')()

ui.div('Usage: $0 [command] [options]')

ui.div({
text: 'Options:',
padding: [2, 0, 2, 0]
padding: [2, 0, 1, 0]
})

ui.div(
Expand All @@ -40,6 +40,32 @@ ui.div(
console.log(ui.toString())
```

## Deno/ESM Support

As of `v7` `cliui` supports [Deno](https://github.com/denoland/deno) and
[ESM](https://nodejs.org/api/esm.html#esm_ecmascript_modules):

```typescript
import cliui from "https://deno.land/x/cliui/deno.ts";

const ui = cliui({})

ui.div('Usage: $0 [command] [options]')

ui.div({
text: 'Options:',
padding: [2, 0, 1, 0]
})

ui.div({
text: "-f, --file",
width: 20,
padding: [0, 4, 0, 4]
})

console.log(ui.toString())
```

<img width="500" src="screenshot.png">

## Layout DSL
Expand Down
13 changes: 13 additions & 0 deletions deno.ts
@@ -0,0 +1,13 @@
// Bootstrap cliui with CommonJS dependencies:
import { cliui, UIOptions, UI } from './build/lib/index.js'
import { wrap, stripAnsi } from './build/lib/string-utils.js'

export default function ui (opts: UIOptions): UI {
return cliui(opts, {
stringWidth: (str: string) => {
return [...str].length
},
stripAnsi,
wrap
})
}
13 changes: 13 additions & 0 deletions index.mjs
@@ -0,0 +1,13 @@
// Bootstrap cliui with CommonJS dependencies:
import { cliui } from './build/lib/index.js'
import { wrap, stripAnsi } from './build/lib/string-utils.js'

export default function ui (opts) {
return cliui(opts, {
stringWidth: (str) => {
return [...str].length
},
stripAnsi,
wrap
})
}
12 changes: 12 additions & 0 deletions lib/cjs.ts
@@ -0,0 +1,12 @@
// Bootstrap cliui with CommonJS dependencies:
import { cliui, UIOptions } from './index.js'
const stringWidth = require('string-width')
const stripAnsi = require('strip-ansi')
const wrap = require('wrap-ansi')
export default function ui (opts: UIOptions) {
return cliui(opts, {
stringWidth,
stripAnsi,
wrap
})
}