Skip to content

Commit

Permalink
feat: add badges for gh-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Jul 16, 2024
1 parent 40b195f commit 8f55fb6
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# thought

[![NPM version](https://img.shields.io/npm/v/thought.svg)](https://npmjs.com/package/thought)
[![Github Actions Status](https://github.com/nknapp/thought/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/nknapp/thought/actions/workflow/ci.yml)
[![Greenkeeper badge](https://badges.greenkeeper.io/nknapp/thought.svg)](https://greenkeeper.io/)

> A customizable documentation generator for github projects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The following **partials** exist by default:
│ ├── <a href="../handlebars/partials/badge/appveyor.md.hbs">appveyor.md.hbs</a>
│ ├── <a href="../handlebars/partials/badge/codecov.md.hbs">codecov.md.hbs</a>
│ ├── <a href="../handlebars/partials/badge/coveralls.md.hbs">coveralls.md.hbs</a>
│ ├── <a href="../handlebars/partials/badge/gh-workflows.md.hbs">gh-workflows.md.hbs</a>
│ ├── <a href="../handlebars/partials/badge/greenkeeper.md.hbs">greenkeeper.md.hbs</a>
│ ├── <a href="../handlebars/partials/badge/npm.md.hbs">npm.md.hbs</a>
│ └── <a href="../handlebars/partials/badge/travis.md.hbs">travis.md.hbs</a>
Expand Down
31 changes: 31 additions & 0 deletions docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

The following helpers are built-in for use in templates and partials

## Members

<dl>
<dt><a href="#helpers">helpers</a></dt>
<dd><p>Default Handlebars-helpers for Thought</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#glob">glob(pattern, options)</a> ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code></dt>
<dd><p>Resolves files via glob pattern</p>
</dd>
</dl>

<a name="helpers"></a>

## helpers
Expand Down Expand Up @@ -337,5 +353,20 @@ to provide array-arguments to other helpers.
| --- | --- | --- |
| ...args | <code>\*</code> | a list of arguments |
<a name="glob"></a>
## glob(pattern, options) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
Resolves files via glob pattern
**Kind**: global function
**Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> - a list of files
| Param | Type | Description |
| --- | --- | --- |
| pattern | <code>string</code> | the glob |
| options | <code>object</code> | |
| options.hash | <code>object</code> | |
| options.hash.root | <code>string</code> | the path to the directory that acts are root dir for this glob-query |
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The following partials can be overwritten in `.thought/partials`:
│ ├── appveyor.md.hbs
│ ├── codecov.md.hbs
│ ├── coveralls.md.hbs
│ ├── gh-workflows.md.hbs
│ ├── greenkeeper.md.hbs
│ ├── npm.md.hbs
│ └── travis.md.hbs
Expand Down
22 changes: 21 additions & 1 deletion handlebars/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const { resolvePackageRoot } = require('../../lib/utils/resolve-package-root')
const Handlebars = require('handlebars')
const fs = require('fs-extra')
const util = require('util')
const pify = require('pify')
const _glob = pify(require('glob'))

/**
* Default Handlebars-helpers for Thought
Expand All @@ -31,7 +33,8 @@ module.exports = {
hasCoveralls,
hasCodecov,
hasGreenkeeper,
arr
arr,
glob
}

/**
Expand Down Expand Up @@ -547,3 +550,20 @@ function _relativePathWithinRepository(packageJson, fileRelativeToPackageJson) {
}
return fileRelativeToPackageJson
}

/**
* Resolves files via glob pattern
*
* @param {string} pattern the glob
* @param {object} options
* @param {object} options.hash
* @param {string} options.hash.root the path to the directory that acts are root dir for this glob-query
* @returns {Promise<string[]>} a list of files
*/
async function glob(pattern, options) {
if (options && options.hash && options.hash.root) {
return _glob(pattern, { ignore: 'node_modules/', cwd: options.hash.root })
} else {
return _glob(pattern, { ignore: 'node_modules/' })
}
}
3 changes: 3 additions & 0 deletions handlebars/partials/badge/gh-workflows.md.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{~#each ( glob '*.yml' root='.github/workflows' ) as |workflowFile| ~}}
[![Github Actions Status](https://github.com/{{githubRepo}}/actions/workflows/{{workflowFile}}/badge.svg?branch=master)](https://github.com/{{githubRepo}}/actions/workflows/{{workflowFile}})
{{/each~}}
1 change: 1 addition & 0 deletions handlebars/partials/badges.md.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{>badge/npm.md}}
{{>badge/travis.md}}
{{>badge/gh-workflows.md}}
{{>badge/appveyor.md}}
{{>badge/coveralls.md}}
{{>badge/codecov.md}}
Expand Down
5 changes: 0 additions & 5 deletions test/fixtures/scenarios/with-all-badges/.thought/config.js

This file was deleted.

2 changes: 2 additions & 0 deletions test/fixtures/scenarios/with-all-badges/expected/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![NPM version](https://img.shields.io/npm/v/simple-project.svg)](https://npmjs.com/package/simple-project)
[![Travis Build Status](https://travis-ci.org/bootprint/bootprint.svg?branch=master)](https://travis-ci.org/bootprint/bootprint)
[![Github Actions Status](https://github.com/bootprint/bootprint/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/bootprint/bootprint/actions/workflows/ci.yml)
[![Github Actions Status](https://github.com/bootprint/bootprint/actions/workflows/deploy.yml/badge.svg?branch=master)](https://github.com/bootprint/bootprint/actions/workflows/deploy.yml)
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/bootprint/bootprint?svg=true&branch=master)](https://ci.appveyor.com/project/bootprint/bootprint)
[![Coverage Status](https://img.shields.io/coveralls/bootprint/bootprint.svg)](https://coveralls.io/r/bootprint/bootprint)
[![Coverage Status](https://img.shields.io/codecov/bootprint/bootprint.svg)](https://codecov.io/github/bootprint/bootprint)
Expand Down
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions test/helper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,20 @@ describe('thought-helpers:', function () {
return expect(helpers.repoWebUrl('git+ssh://git@example.com/nknapp/thought-plugin-jsdoc.git')).to.equal(null)
})
})

describe("The 'glob' helper", function () {
it('returns a list of files matching the glob', async function () {
expect(await helpers.glob('test/fixtures/dir-tree/**/bFile.txt')).to.deep.equal([
'test/fixtures/dir-tree/subdirA/bDir/bFile.txt',
'test/fixtures/dir-tree/subdirB/subdirC/bFile.txt'
])
})

it('returns paths starting with root dir', async function () {
expect(await helpers.glob('dir-tree/**/bFile.txt', { hash: { root: 'test/fixtures' } })).to.deep.equal([
'dir-tree/subdirA/bDir/bFile.txt',
'dir-tree/subdirB/subdirC/bFile.txt'
])
})
})
})

0 comments on commit 8f55fb6

Please sign in to comment.