Skip to content

Commit 1e0e9da

Browse files
committed
Refactor to accept version option
1 parent b8ace47 commit 1e0e9da

File tree

20 files changed

+140
-20
lines changed

20 files changed

+140
-20
lines changed

lib/node_modules/@stdlib/_tools/docs/www/readme-database/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ The function accepts the following `options`:
5252
- **dir**: root directory from which to search for package READMEs. May be either an absolute path or a path relative to the current working directory. Default: current working directory.
5353
- **pattern**: glob pattern used to find packages. Default: `'**/package.json'` (note: pattern **must** end with `package.json`).
5454
- **ignore**: list of glob patterns used to exclude matches.
55+
- **version**: semantic versioning number or branch name.
5556

5657
To search from an alternative directory, set the `dir` option.
5758

@@ -110,6 +111,26 @@ function done( error, db ) {
110111
}
111112
```
112113

114+
To have internal URLs of the READMEs link to the correct version of the documentation, set the `version` option.
115+
116+
<!-- run-disable -->
117+
118+
119+
```javascript
120+
var opts = {
121+
'version': '0.0.87'
122+
};
123+
124+
create( opts, done );
125+
126+
function done( error, db ) {
127+
if ( error ) {
128+
throw error;
129+
}
130+
console.log( JSON.stringify( db ) );
131+
}
132+
```
133+
113134
</section>
114135

115136
<!-- /.usage -->
@@ -182,6 +203,7 @@ Options:
182203
-V, --version Print the package version.
183204
--pattern pattern Inclusion glob pattern.
184205
--ignore pattern Exclusion glob pattern.
206+
--semver version Semantic versioning number or branch name.
185207
```
186208

187209
</section>

lib/node_modules/@stdlib/_tools/docs/www/readme-database/bin/cli

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ function main() {
7272
opts.ignore = flags.ignore;
7373
}
7474
}
75+
if ( flags.semver ) {
76+
opts.version = flags.semver;
77+
}
7578
if ( args[ 0 ] ) {
7679
opts.dir = args[ 0 ];
7780
}

lib/node_modules/@stdlib/_tools/docs/www/readme-database/docs/usage.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ Options:
77
-V, --version Print the package version.
88
--pattern pattern Inclusion glob pattern.
99
--ignore pattern Exclusion glob pattern.
10+
--semver version Semantic versioning number or branch name.
1011

lib/node_modules/@stdlib/_tools/docs/www/readme-database/etc/cli_opts.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"string": [
33
"pattern",
4-
"ignore"
4+
"ignore",
5+
"semver"
56
],
67
"boolean": [
78
"help",
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"pattern": "**/package.json",
3-
"ignore": []
3+
"ignore": [],
4+
"version": "develop"
45
}

lib/node_modules/@stdlib/_tools/docs/www/readme-database/lib/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var debug = logger( 'readme-database:async' );
4646
* @param {string} [options.dir] - root directory from which to search for package READMEs
4747
* @param {string} [options.pattern='**\/package.json'] - glob pattern
4848
* @param {StringArray} [options.ignore] - glob pattern(s) to exclude matches
49+
* @param {string} [options.version='develop'] - semantic versioning number or branch name
4950
* @param {Function} clbk - callback
5051
* @throws {TypeError} options argument must be an object
5152
* @throws {TypeError} must provide valid options
@@ -130,7 +131,7 @@ function create( options, clbk ) {
130131
debug( 'Finished reading files.' );
131132

132133
debug( 'Rendering file contents...' );
133-
render( files, done );
134+
render( files, opts.version, done );
134135
}
135136

136137
/**

lib/node_modules/@stdlib/_tools/docs/www/readme-database/lib/render.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ var RE_HEADER = headerRegExp( 'Apache-2.0', 'markdown' );
4343
*
4444
* @private
4545
* @param {ObjectArray} files - Markdown files
46+
* @param {string} version - semantic versioning number or branch name
4647
* @param {Callback} clbk - callback to invoke upon completion
4748
* @returns {void}
4849
*/
49-
function render( files, clbk ) {
50+
function render( files, version, clbk ) {
5051
var total;
5152
var i;
5253

@@ -67,7 +68,7 @@ function render( files, clbk ) {
6768

6869
debug( 'Rendering file %d of %d: %s', i+1, total, files[ i ].file );
6970
str = removeHeader( files[ i ].data, RE_HEADER );
70-
toHTML( str, onRender );
71+
toHTML( str, version, onRender );
7172

7273
/**
7374
* Callback invoked after rendering a file.

lib/node_modules/@stdlib/_tools/docs/www/readme-database/lib/validate.js

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var RE = /package\.json$/;
4242
* @param {string} [options.dir] - root directory from which to search for package READMEs
4343
* @param {string} [options.pattern] - glob pattern
4444
* @param {StringArray} [options.ignore] - glob pattern(s) to exclude matches
45+
* @param {string} [options.version] - semantic versioning number or branch name
4546
* @returns {(Error|null)} error object or null
4647
*
4748
* @example
@@ -81,6 +82,12 @@ function validate( opts, options ) {
8182
return new TypeError( 'invalid option. `ignore` option must be a string array. Option: `' + opts.ignore + '`.' );
8283
}
8384
}
85+
if ( hasOwnProp( options, 'version' ) ) {
86+
opts.version = options.version;
87+
if ( !isString( opts.version ) ) {
88+
return new TypeError( 'invalid option. `version` option must be a primitive string. Option: `' + opts.dir + '`.' );
89+
}
90+
}
8491
return null;
8592
}
8693

lib/node_modules/@stdlib/_tools/docs/www/readme-fragment-file-tree/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ The function accepts the following `options`:
5252
- **dir**: root directory from which to search for package READMEs. May be either an absolute path or a path relative to the current working directory. Default: current working directory.
5353
- **pattern**: glob pattern used to find packages. Default: `'**/package.json'` (note: pattern **must** end with `package.json`).
5454
- **ignore**: list of glob patterns used to exclude matches.
55+
- **version**: semantic versioning number or branch name.
5556

5657
To search from an alternative directory, set the `dir` option.
5758

@@ -110,6 +111,26 @@ function done( error ) {
110111
}
111112
```
112113

114+
To have internal URLs of the READMEs link to the correct version of the documentation, set the `version` option.
115+
116+
<!-- run-disable -->
117+
118+
119+
```javascript
120+
var opts = {
121+
'version': '0.0.87'
122+
};
123+
124+
build( './build', opts, done );
125+
126+
function done( error ) {
127+
if ( error ) {
128+
throw error;
129+
}
130+
console.log( 'Finished' );
131+
}
132+
```
133+
113134
</section>
114135

115136
<!-- /.usage -->

lib/node_modules/@stdlib/_tools/docs/www/readme-fragment-file-tree/bin/cli

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ function main() {
7373
opts.ignore = flags.ignore;
7474
}
7575
}
76+
if ( flags.version ) {
77+
opts.version = flags.version;
78+
}
7679
if ( !flags.out ) {
7780
err = new Error( 'insufficient arguments. Must provide an output directory.' );
7881
return cli.error( err, 1 );

lib/node_modules/@stdlib/_tools/docs/www/readme-fragment-file-tree/docs/usage.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ Options:
77
-V, --version Print the package version.
88
--pattern pattern Inclusion glob pattern.
99
--ignore pattern Exclusion glob pattern.
10+
--semver version Semantic versioning number or branch name.
1011
-o, --out directory Output directory.
1112

lib/node_modules/@stdlib/_tools/docs/www/readme-fragment-file-tree/etc/cli_opts.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"string": [
33
"pattern",
44
"ignore",
5-
"out"
5+
"out",
6+
"semver"
67
],
78
"boolean": [
89
"help",
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"pattern": "**/package.json",
3-
"ignore": []
3+
"ignore": [],
4+
"version": "develop"
45
}

lib/node_modules/@stdlib/_tools/docs/www/readme-fragment-file-tree/lib/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var debug = logger( 'readme-fragment-file-tree:async' );
4747
* @param {string} [options.dir] - root directory from which to search for package READMEs
4848
* @param {string} [options.pattern='**\/package.json'] - glob pattern
4949
* @param {StringArray} [options.ignore] - glob pattern(s) to exclude matches
50+
* @param {string} [options.version='develop'] - semantic versioning number or branch name
5051
* @param {Function} clbk - callback
5152
* @throws {TypeError} first argument must be a string
5253
* @throws {TypeError} options argument must be an object

lib/node_modules/@stdlib/_tools/docs/www/readme-fragment-file-tree/lib/validate.js

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var RE = /package\.json$/;
4242
* @param {string} [options.dir] - root directory from which to search for package READMEs
4343
* @param {string} [options.pattern] - glob pattern
4444
* @param {StringArray} [options.ignore] - glob pattern(s) to exclude matches
45+
* @param {string} [options.version] - semantic versioning number or branch name
4546
* @returns {(Error|null)} error object or null
4647
*
4748
* @example
@@ -81,6 +82,12 @@ function validate( opts, options ) {
8182
return new TypeError( 'invalid option. `ignore` option must be a string array. Option: `' + opts.ignore + '`.' );
8283
}
8384
}
85+
if ( hasOwnProp( options, 'version' ) ) {
86+
opts.version = options.version;
87+
if ( !isString( opts.version ) ) {
88+
return new TypeError( 'invalid option. `version` option must be a primitive string. Option: `' + opts.dir + '`.' );
89+
}
90+
}
8491
return null;
8592
}
8693

lib/node_modules/@stdlib/_tools/markdown/to-html/README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ limitations under the License.
4040
var toHTML = require( '@stdlib/_tools/markdown/to-html' );
4141
```
4242

43-
#### toHTML( markdown, done )
43+
#### toHTML( markdown\[, version], done )
4444

4545
Converts a Markdown `string` or [`Buffer`][node-buffer] to HTML.
4646

@@ -56,6 +56,20 @@ function done( error, html ) {
5656
}
5757
```
5858

59+
By default, the plugin resolves package identifiers to the `develop` documentation. To specify an alternative version, set the `version` option.
60+
61+
```javascript
62+
toHtml( '[@stdlib/boop](https://github.com/stdlib-js/stdlib)', 'v0.0.87', done );
63+
64+
function done( error, html ) {
65+
if ( error ) {
66+
throw error;
67+
}
68+
console.log( html );
69+
// => '<a href="https://stdlib.io/v0.0.87/docs/api/@stdlib/boop">@stdlib/boop</a>'
70+
}
71+
```
72+
5973
</section>
6074

6175
<!-- /.usage -->
@@ -125,6 +139,7 @@ Options:
125139

126140
-h, --help Print this message.
127141
-V, --version Print the package version.
142+
--semver version Semantic versioning number or branch name.
128143
```
129144

130145
</section>

lib/node_modules/@stdlib/_tools/markdown/to-html/bin/cli

+10-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ function main() {
6565
if ( !process.stdin.isTTY ) {
6666
return stdin( onRead );
6767
}
68-
toHTML( replace( args[ 0 ], /\\n/g, '\n' ), done );
68+
if ( flags.semver ) {
69+
toHTML( replace( args[ 0 ], /\\n/g, '\n' ), flags.semver, done );
70+
} else {
71+
toHTML( replace( args[ 0 ], /\\n/g, '\n' ), done );
72+
}
6973

7074
/**
7175
* Callback invoked upon reading from `stdin`.
@@ -79,7 +83,11 @@ function main() {
7983
if ( error ) {
8084
return done( error );
8185
}
82-
toHTML( data.toString(), done );
86+
if ( flags.semver ) {
87+
toHTML( data.toString(), flags.semver, done );
88+
} else {
89+
toHTML( data.toString(), done );
90+
}
8391
}
8492

8593
/**

lib/node_modules/@stdlib/_tools/markdown/to-html/docs/usage.txt

+2
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ Options:
55

66
-h, --help Print this message.
77
-V, --version Print the package version.
8+
--semver version Semantic versioning number or branch name.
9+
810

lib/node_modules/@stdlib/_tools/markdown/to-html/etc/cli_opts.json

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"string": [
3+
"semver"
4+
],
25
"boolean": [
36
"help",
47
"version"

lib/node_modules/@stdlib/_tools/markdown/to-html/lib/convert.js

+30-10
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ var postProcess = require( './post_process.js' );
3636

3737
// VARIABLES //
3838

39-
var mTransform = remark()
40-
.use( headings )
41-
.use( linkify )
42-
.use( equations )
43-
.use( toHTML )
44-
.process;
45-
4639
var hopts = {
4740
'fragment': true
4841
};
@@ -59,6 +52,7 @@ var hTransform = rehype()
5952
* Converts Markdown to HTML.
6053
*
6154
* @param {(string|Buffer)} markdown - markdown to convert
55+
* @param {string} [version='develop'] - semantic versioning number or branch name
6256
* @param {Function} clbk - callback to invoke on completion
6357
* @throws {TypeError} first argument must be either a string or a Buffer
6458
* @throws {TypeError} last argument must be a function
@@ -75,16 +69,42 @@ var hTransform = rehype()
7569
* console.log( html );
7670
* }
7771
*/
78-
function convert( markdown, clbk ) {
72+
function convert( markdown ) {
73+
var mTransform;
74+
var version;
75+
var clbk;
7976
if (
8077
!isString( markdown ) &&
8178
!isBuffer( markdown )
8279
) {
8380
throw new TypeError( 'invalid argument. First argument must be either a string or a Buffer. Value: `'+markdown+'`.' );
8481
}
85-
if ( !isFunction( clbk ) ) {
86-
throw new TypeError( 'invalid argument. Last argument must be a callback function. Value: `'+clbk+'`.' );
82+
if ( arguments.length === 2 ) {
83+
version = 'develop';
84+
clbk = arguments[ 1 ];
85+
if ( !isFunction( clbk ) ) {
86+
throw new TypeError( 'invalid argument. Last argument must be a callback function. Value: `'+clbk+'`.' );
87+
}
8788
}
89+
else {
90+
version = arguments[ 1 ];
91+
clbk = arguments[ 2 ];
92+
if ( !isString( version ) ) {
93+
throw new TypeError( 'invalid argument. Version argument must be a string primitive. Value: `'+version+'`.' );
94+
}
95+
if ( !isFunction( clbk ) ) {
96+
throw new TypeError( 'invalid argument. Last argument must be a callback function. Value: `'+clbk+'`.' );
97+
}
98+
}
99+
mTransform = remark()
100+
.use( headings )
101+
.use( linkify, {
102+
'version': version
103+
})
104+
.use( equations )
105+
.use( toHTML )
106+
.process;
107+
88108
// Convert the Markdown to HTML:
89109
mTransform( markdown.toString(), onMarkdownTransform );
90110

0 commit comments

Comments
 (0)