-
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.
Merge pull request #8 from mbland/support-node-v18
Support node >= v18, update JSDoc, add npm badge
- Loading branch information
Showing
10 changed files
with
120 additions
and
84 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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
Copyright (c) 2023 Mike Bland <[email protected]> | ||
|
||
Mozilla Public License Version 2.0 | ||
================================== | ||
|
||
|
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
* Removes the existing destination directory if it exists, runs JSDoc, and | ||
* emits the relative path to the generated index.html file. | ||
* @author Mike Bland <[email protected]> | ||
* @license MPL-2.0 | ||
*/ | ||
|
||
import { runJsdoc } from './lib/index.js' | ||
|
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 |
---|---|---|
|
@@ -10,13 +10,17 @@ | |
"test:ci": "eslint --color --max-warnings 0 . && vitest run -c ci/vitest.config.js", | ||
"jsdoc": "node index.js -c jsdoc.json ." | ||
}, | ||
"files": [ "lib/**" ], | ||
"keywords": [ | ||
"jsdoc", | ||
"JavaScript" | ||
], | ||
"author": "Mike Bland <[email protected]> (https://mike-bland.com/)", | ||
"license": "MPL-2.0", | ||
"type": "module", | ||
"engines": { | ||
"node": ">= 18.0.0" | ||
}, | ||
"homepage": "https://github.com/mbland/jsdoc-cli-wrapper", | ||
"repository": "https://github.com/mbland/jsdoc-cli-wrapper", | ||
"bugs": "https://github.com/mbland/jsdoc-cli-wrapperr/issues", | ||
|
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,69 +1,31 @@ | ||
#!/usr/bin/env node | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
/** | ||
* Fake jsdoc implementation for testing | ||
*/ | ||
|
||
import { mkdir, writeFile } from 'node:fs/promises' | ||
import path from 'node:path' | ||
import { exit } from 'node:process' | ||
|
||
try { | ||
const {willGenerate, destination, exitCode} = parseArgs(process.argv.slice(2)) | ||
|
||
if (willGenerate && exitCode === 0) { | ||
const newSubDir = path.join(destination, 'new-subdir') | ||
await mkdir(newSubDir, {recursive: true}) | ||
await writeFile(path.join(newSubDir, 'index.html'), 'New Hotness') | ||
} | ||
exit(exitCode) | ||
|
||
} catch (err) { | ||
console.error(err) | ||
exit(1) | ||
} | ||
|
||
/** | ||
* The parameters parsed from process.argv by parseArgs() | ||
* @typedef {object} ArgsResult | ||
* @property {string} destination - the JSDoc destination directory | ||
* @property {boolean} willGenerate - true unless -h or --no-input-files present | ||
* @property {number} exitCode - the value of --exit-code or 0 by default | ||
*/ | ||
|
||
/** | ||
* Parses fake jsdoc arguments | ||
* @param {string[]} argv - command line arguments | ||
* @returns {ArgsResult} - parameters determining fake jsdoc behavior | ||
*/ | ||
function parseArgs(argv) { | ||
let destination = null | ||
let willGenerate = true | ||
let exitCode = 0 | ||
|
||
for (let i = 0; i !== argv.length; ++i) { | ||
const arg = argv[i] | ||
const nextArg = argv[i+1] | ||
|
||
switch (arg) { | ||
case '-d': | ||
destination = nextArg | ||
break | ||
|
||
case '-h': | ||
case '--no-input-files': | ||
willGenerate = false | ||
break | ||
|
||
case '--exit-code': | ||
exitCode = nextArg | ||
break | ||
} | ||
} | ||
return {willGenerate, destination, exitCode} | ||
} | ||
#!/bin/sh | ||
# | ||
# Wraps the jsdoc.js command on non-Windows platforms. | ||
# | ||
# This is necessary to support older Node versions as package.json engines | ||
# without removing the `"type": "module"` specifier. Without this shim, running | ||
# `pnpm test` under many older verions caused runJsdoc.test.js and main.test.js | ||
# to fail on the spawn(jsdocPath) call within runJsdoc(). | ||
# | ||
# These older versions couldn't grok that the previous `jsdoc` stub was really | ||
# written in ECMAScript Module style without a file extension: | ||
# | ||
# TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for | ||
# .../jsdoc-cli-wrapper/test/fixtures/jsdocStub/jsdoc. Loading extensionless | ||
# files is not supported inside of "type":"module" package.json contexts. The | ||
# package.json file .../jsdoc-cli-wrapper/package.json caused this | ||
# "type":"module" context. Try changing | ||
# .../jsdoc-cli-wrapper/test/fixtures/jsdocStub/jsdoc to have a file | ||
# extension. Note the "bin" field of package.json can point to a file with an | ||
# extension, for example | ||
# {"type":"module","bin":{"jsdoc":"./test/fixtures/jsdocStub/jsdoc.js"}} | ||
# | ||
# I tried adding the `--experimental-default-type=module` flag to the shebang | ||
# line of the former `jsdoc` stub. Only after trying that did I realize that | ||
# `#!/usr/bin/env` style shebangs don't support passing command line arguments | ||
# to the specified interpreter. | ||
# | ||
# Hence moving the original `jsdoc` stub to `jsdoc.js` and invoking it via this | ||
# one-line wrapper. | ||
|
||
exec node "${0}.js" "$@" |
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,69 @@ | ||
#!/usr/bin/env node | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
/** | ||
* Fake jsdoc implementation for testing | ||
*/ | ||
|
||
import { mkdir, writeFile } from 'node:fs/promises' | ||
import path from 'node:path' | ||
import { exit } from 'node:process' | ||
|
||
try { | ||
const {willGenerate, destination, exitCode} = parseArgs(process.argv.slice(2)) | ||
|
||
if (willGenerate && exitCode === 0) { | ||
const newSubDir = path.join(destination, 'new-subdir') | ||
await mkdir(newSubDir, {recursive: true}) | ||
await writeFile(path.join(newSubDir, 'index.html'), 'New Hotness') | ||
} | ||
exit(exitCode) | ||
|
||
} catch (err) { | ||
console.error(err) | ||
exit(1) | ||
} | ||
|
||
/** | ||
* The parameters parsed from process.argv by parseArgs() | ||
* @typedef {object} ArgsResult | ||
* @property {string} destination - the JSDoc destination directory | ||
* @property {boolean} willGenerate - true unless -h or --no-input-files present | ||
* @property {number} exitCode - the value of --exit-code or 0 by default | ||
*/ | ||
|
||
/** | ||
* Parses fake jsdoc arguments | ||
* @param {string[]} argv - command line arguments | ||
* @returns {ArgsResult} - parameters determining fake jsdoc behavior | ||
*/ | ||
function parseArgs(argv) { | ||
let destination = null | ||
let willGenerate = true | ||
let exitCode = 0 | ||
|
||
for (let i = 0; i !== argv.length; ++i) { | ||
const arg = argv[i] | ||
const nextArg = argv[i+1] | ||
|
||
switch (arg) { | ||
case '-d': | ||
destination = nextArg | ||
break | ||
|
||
case '-h': | ||
case '--no-input-files': | ||
willGenerate = false | ||
break | ||
|
||
case '--exit-code': | ||
exitCode = nextArg | ||
break | ||
} | ||
} | ||
return {willGenerate, destination, exitCode} | ||
} |
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