Skip to content

Commit

Permalink
Upgrade chalk to version v5 to enable support for Deno #40
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Feb 14, 2023
1 parent cc37fea commit bc66209
Show file tree
Hide file tree
Showing 32 changed files with 734 additions and 1,524 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [8, 10, 12, 14, 16, 17]
node-version: [12, 14, 16, 18, 19]

steps:
- uses: actions/checkout@v2
Expand All @@ -24,5 +24,5 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: FORCE_COLOR=3 npm test
- run: npm install
- run: FORCE_COLOR=3 npm test # FORCE_COLOR=3 enables full 16,777,216 colour support
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-22 Lloyd Brookes <75pound@gmail.com>
Copyright (c) 2015-23 Lloyd Brookes <75pound@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ The [polymer-cli](https://github.com/Polymer/tools/tree/master/packages/cli) usa

* * *

&copy; 2015-22 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown).
&copy; 2015-23 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown).
2 changes: 1 addition & 1 deletion example/alias-opts-only.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'

const usage = commandLineUsage([
{
Expand Down
4 changes: 2 additions & 2 deletions example/chalk-escaping.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'

const usage = commandLineUsage([
{
Expand All @@ -8,7 +8,7 @@ const usage = commandLineUsage([
{
header: 'Options',
optionList: [
{ name: 'files', typeLabel: '\\{something\\}', description: 'This is not \\{red red\\}.'}
{ name: 'files', typeLabel: ' \\{something\\} ', description: ''}
]
}
])
Expand Down
2 changes: 1 addition & 1 deletion example/chalk-formatting.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'

const usage = commandLineUsage([
{
Expand Down
2 changes: 1 addition & 1 deletion example/command-list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'

const sections = [
{
Expand Down
2 changes: 1 addition & 1 deletion example/description-columns.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'
const ussr = require('./assets/ascii-ussr')
const optionDefinitions = require('./assets/example-options')

Expand Down
2 changes: 1 addition & 1 deletion example/examples.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'
const optionDefinitions = [
{
name: 'help',
Expand Down
2 changes: 1 addition & 1 deletion example/footer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'
const wales = require('./assets/ansi-wales')
const optionDefinitions = require('./assets/example-options')

Expand Down
2 changes: 1 addition & 1 deletion example/groups.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'

const optionDefinitions = [
{
Expand Down
2 changes: 1 addition & 1 deletion example/header-only.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'

const sections = [
{
Expand Down
2 changes: 1 addition & 1 deletion example/header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'
const header = require('./assets/ansi-header')
const chalk = require('chalk')

Expand Down
2 changes: 1 addition & 1 deletion example/hide.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'

const usage = commandLineUsage([
{
Expand Down
2 changes: 1 addition & 1 deletion example/option-list-options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'
const optionDefinitions = require('./assets/example-options')

const sections = [
Expand Down
2 changes: 1 addition & 1 deletion example/simple-reverse-name-order.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'
const optionDefinitions = require('./assets/example-options')

const usage = commandLineUsage([
Expand Down
2 changes: 1 addition & 1 deletion example/simple-width.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'
const optionDefinitions = require('./assets/example-options')

const usage = commandLineUsage([
Expand Down
2 changes: 1 addition & 1 deletion example/simple.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'

const usage = commandLineUsage([
{
Expand Down
2 changes: 1 addition & 1 deletion example/special-characters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'

const sections = [
{
Expand Down
2 changes: 1 addition & 1 deletion example/synopsis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'

const sections = [
{
Expand Down
2 changes: 1 addition & 1 deletion example/whitespace.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const commandLineUsage = require('../')
import commandLineUsage from 'command-line-usage'
let sections, usage

/* When using default options, the whitespace before the bullets is trimmed */
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import OptionList from './lib/section/option-list.js'
import ContentSection from './lib/section/content.js'
import arrayify from 'array-back'

/**
* @module command-line-usage
*/
Expand All @@ -9,11 +13,8 @@
* @alias module:command-line-usage
*/
function commandLineUsage (sections) {
const arrayify = require('array-back')
sections = arrayify(sections)
if (sections.length) {
const OptionList = require('./lib/section/option-list')
const ContentSection = require('./lib/section/content')
const output = sections.map(section => {
if (section.optionList) {
return new OptionList(section)
Expand All @@ -27,4 +28,4 @@ function commandLineUsage (sections) {
}
}

module.exports = commandLineUsage
export default commandLineUsage
7 changes: 4 additions & 3 deletions lib/chalk-format.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import chalkTemplate from 'chalk-template'

function chalkFormat (str) {
if (str) {
str = str.replace(/`/g, '\\`')
const chalk = require('chalk')
return chalk(Object.assign([], { raw: [str] }))
return chalkTemplate(Object.assign([], { raw: [str] }))
} else {
return ''
}
}

module.exports = chalkFormat
export default chalkFormat
9 changes: 5 additions & 4 deletions lib/section.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import arrayify from 'array-back'
import chalk from 'chalk'
import os from 'node:os'

class Section {
constructor () {
this.lines = []
}

add (lines) {
if (lines) {
const arrayify = require('array-back')
arrayify(lines).forEach(line => this.lines.push(line))
} else {
this.lines.push('')
}
}

toString () {
const os = require('os')
return this.lines.join(os.EOL)
}

header (text) {
const chalk = require('chalk')
if (text) {
this.add(chalk.underline.bold(text))
this.add()
}
}
}

module.exports = Section
export default Section
12 changes: 6 additions & 6 deletions lib/section/content.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const Section = require('../section')
const t = require('typical')
const Table = require('table-layout')
const chalkFormat = require('../chalk-format')
import Section from '../section.js'
import t from 'typical'
import Table from 'table-layout'
import chalkFormat from '../chalk-format.js'
import arrayify from 'array-back'

class ContentSection extends Section {
constructor (section) {
Expand All @@ -11,7 +12,6 @@ class ContentSection extends Section {
if (section.content) {
/* add content without indentation or wrapping */
if (section.raw) {
const arrayify = require('array-back')
const content = arrayify(section.content).map(line => chalkFormat(line))
this.add(content)
} else {
Expand Down Expand Up @@ -91,7 +91,7 @@ function ansiFormatRow (row) {
return row
}

module.exports = ContentSection
export default ContentSection

/**
* A Content section comprises a header and one or more lines of content.
Expand Down
12 changes: 6 additions & 6 deletions lib/section/option-list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const Section = require('../section')
const Table = require('table-layout')
const chalk = require('../chalk-format')
const t = require('typical')
const arrayify = require('array-back')
import Section from '../section.js'
import Table from 'table-layout'
import chalk from '../chalk-format.js'
import t from 'typical'
import arrayify from 'array-back'

class OptionList extends Section {
constructor (data) {
Expand Down Expand Up @@ -86,7 +86,7 @@ function intersect (arr1, arr2) {
})
}

module.exports = OptionList
export default OptionList

/**
* An OptionList section adds a table displaying the supplied option definitions.
Expand Down
Loading

0 comments on commit bc66209

Please sign in to comment.