Skip to content

Commit

Permalink
Emit file://url from main wrapper program
Browse files Browse the repository at this point in the history
This seems more convenient than emitting a relative URL and forcing the
user to either run a command or open it another way.

This was made pretty easy thanks to Node's url.pathToFileURL().
  • Loading branch information
mbland committed Dec 30, 2023
1 parent fa479fb commit 6f2cd96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ the path to your JSDoc config file):

### Opening the link

Running the wrapper will generate the link to the generated `index.html` file, e.g.:
Running the wrapper will generate the local `file://` URL to the generated
`index.html` file, e.g.:

```text
jsdoc/jsdoc-cli-wrapper/1.0.0/index.html
file:///Users/.../jsdoc/jsdoc-cli-wrapper/1.0.0/index.html
```

You can open this link from the command line via the following commands,
replacing `path/to/index.html` with your actual `index.html` path:
You can click on or copy this link to open it in your browser. You can also open
this link from the command line via the following commands, replacing
`path/to/index.html` with your actual `index.html` path:

- **macOS**: `open path/to/index.html`
- **Linux**: `xdg-open path/to/index.html`
- **Windows**: `start path\to\index.html`
- **macOS**: `open file:///path/to/index.html`
- **Linux**: `xdg-open file:///path/to/index.html`
- **Windows**: `start file:///C:/path/to/index.html`

## Motivation

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

import { runJsdoc } from './lib/index.js'
import { exit, stdout } from 'node:process'
import { pathToFileURL } from 'node:url'

try {
const {exitCode, indexHtml} = await runJsdoc(
process.argv.slice(2), process.env, process.platform
)
if (indexHtml !== undefined) stdout.write(`${indexHtml}\n`)
if (indexHtml !== undefined) stdout.write(`${pathToFileURL(indexHtml)}\n`)
exit(exitCode)

} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import DestDirHelper from './DestDirHelper'
import { afterEach, describe, expect, test } from 'vitest'
import { spawn } from 'node:child_process'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { fileURLToPath, pathToFileURL } from 'node:url'

const PATH_KEY = pathKey(process.platform)

Expand Down Expand Up @@ -69,10 +69,10 @@ describe('jsdoc-cli-wrapper', () => {
const { destDir, indexPath } = await destDirHelper.createIndexHtml(
'jsdoc-cli-wrapper-test-', 'old-subdir', 'Old and Busted'
)
const result = pathToFileURL(indexPath.replace('old-subdir', 'new-subdir'))

await expect(runMain('-d', destDir)).resolves.toStrictEqual({
exitCode: 0,
stdout: `${indexPath.replace('old-subdir', 'new-subdir')}\n`
exitCode: 0, stdout: `${result}\n`
})
})

Expand Down

0 comments on commit 6f2cd96

Please sign in to comment.