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

Lines changed: 22 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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",
Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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 );

0 commit comments

Comments
 (0)