-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(build): jsdoc annotations (#38)
* actions, align push, pull, docs check * build, eslint jsdocs, generate code docs * package, avoid package generated doc
- Loading branch information
Showing
15 changed files
with
1,218 additions
and
17 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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Documentation lint | ||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
|
||
jobs: | ||
Documentation: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: yarn | ||
- name: Node.js modules cache | ||
uses: actions/cache@v3 | ||
id: modules-cache | ||
with: | ||
path: ${{ github.workspace }}/node_modules | ||
key: ${{ runner.os }}-${{ matrix.node-version }}-modules-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.node-version }}-modules | ||
- name: Install Node.js packages | ||
if: ${{ steps.modules-cache.outputs.cache-hit != 'true' }} | ||
run: yarn install | ||
- name: Build | ||
run: yarn build:docs | ||
- name: Git modified files | ||
if: ${{ success() }} | ||
run: | | ||
echo 'GIT_MODIFIED<<EOF' >> $GITHUB_ENV | ||
git ls-files -m >> $GITHUB_ENV | ||
echo 'EOF' >> $GITHUB_ENV | ||
- name: Lint | ||
if: ${{ success() }} | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const actionCommit = require(`${process.env.GITHUB_WORKSPACE}/scripts/actions.documentation.js`) | ||
const { resultsArray, resultsString } = actionCommit(process.env.GIT_MODIFIED) | ||
if (resultsArray.length) { | ||
core.setFailed(resultsString) | ||
} |
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 |
---|---|---|
|
@@ -7,4 +7,3 @@ src/**/*test.js | |
src/**/*.archive | ||
!LICENSE | ||
!README.md | ||
!CHANGELOG.md |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Breakout individual files for filtering. | ||
* | ||
* @param {string} files | ||
* @returns {Array<string>} | ||
*/ | ||
const filterFiles = files => | ||
files | ||
.trim() | ||
.split(/\n/g) | ||
.filter(file => { | ||
const updatedFile = file.trim(); | ||
return updatedFile.length > 0 && /README\.md$/.test(updatedFile); | ||
}) | ||
.map(file => `File > ${file} > is modified. Update README with '$ yarn build:docs'`); | ||
|
||
/** | ||
* If modified files exist, throw an error. | ||
* | ||
* @param {string} files | ||
* @returns {{resultsArray: Array, resultsString: string}} | ||
*/ | ||
module.exports = files => { | ||
const lintResults = { resultsArray: [], resultsString: '' }; | ||
|
||
if (files) { | ||
const parsedResults = filterFiles(files); | ||
lintResults.resultsArray = parsedResults; | ||
lintResults.resultsString = JSON.stringify(parsedResults, null, 2); | ||
} | ||
|
||
return lintResults; | ||
}; |
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,25 @@ | ||
const { writeFileSync } = require('fs'); | ||
const { join } = require('path'); | ||
const jsdoc2md = require('jsdoc-to-markdown'); | ||
|
||
/** | ||
* Run jsdoc2md on files, output a README | ||
* | ||
* @param {object} params | ||
* @param {string} params.input | ||
* @param {string} params.output | ||
*/ | ||
const generateReadMe = ({ input, output } = {}) => { | ||
try { | ||
const outputPath = join(process.cwd(), output); | ||
const docs = jsdoc2md.renderSync({ files: input, 'no-gfm': true }); | ||
writeFileSync(outputPath, docs); | ||
console.info(`Generate README success > ${input}`); | ||
} catch (e) { | ||
console.warn(`Generate README failed > ${input} > `, e.message); | ||
} | ||
}; | ||
|
||
((files = []) => { | ||
Promise.all(files.map(obj => generateReadMe(obj))); | ||
})([{ input: './src/*.js', output: './src/README.md' }]); |
Oops, something went wrong.