Skip to content

Commit e03494c

Browse files
committed
Move package, update CLI, and add tests
1 parent 5be89bb commit e03494c

File tree

17 files changed

+767
-120
lines changed

17 files changed

+767
-120
lines changed

tools/benchmarks/html/README.md renamed to lib/node_modules/@stdlib/_tools/benchmarks/html/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
## Usage
1818

1919
```javascript
20-
var build = require( '@stdlib/tools/benchmarks/html' );
20+
var build = require( '@stdlib/_tools/benchmarks/html' );
2121
```
2222

2323
#### build( bundle, \[options,] clbk )
@@ -81,7 +81,7 @@ function clbk( error ) {
8181
<!-- eslint no-undef: "error" -->
8282

8383
```javascript
84-
var build = require( '@stdlib/tools/benchmarks/html' );
84+
var build = require( '@stdlib/_tools/benchmarks/html' );
8585

8686
build( '/foo/bar/bundle.js', onBuild );
8787

@@ -112,7 +112,7 @@ function onBuild( error, html ) {
112112
### Usage
113113

114114
```bash
115-
Usage: benchmarks-html [options] url
115+
Usage: benchmarks-html [options] <url>
116116

117117
Options:
118118

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
// MODULES //
5+
6+
var join = require( 'path' ).join;
7+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
8+
var CLI = require( '@stdlib/tools/cli' );
9+
var html = require( './../lib' );
10+
11+
12+
// FUNCTIONS //
13+
14+
/**
15+
* Callback invoked upon completion.
16+
*
17+
* @private
18+
* @param {(Error|null)} error - error object
19+
* @param {string} html - HTML
20+
*/
21+
function onBuild( error, html ) {
22+
if ( error ) {
23+
throw error;
24+
}
25+
console.log( html ); // eslint-disable-line no-console
26+
}
27+
28+
29+
// MAIN //
30+
31+
/**
32+
* Main execution sequence.
33+
*
34+
* @private
35+
* @returns {void}
36+
*/
37+
function main() {
38+
var flags;
39+
var opts;
40+
var args;
41+
var cli;
42+
43+
// Create a command-line interface:
44+
cli = new CLI({
45+
'pkg': require( './../package.json' ),
46+
'options': require( './../etc/cli_opts.json' ),
47+
'help': readFileSync( join( __dirname, '..', 'docs', 'usage.txt' ), {
48+
'encoding': 'utf8'
49+
})
50+
});
51+
52+
// Get any provided command-line arguments:
53+
args = cli.args();
54+
55+
// Get any provided command-line options:
56+
flags = cli.flags();
57+
58+
opts = {};
59+
if ( flags.title ) {
60+
opts.title = flags.title;
61+
}
62+
html( args[ 0 ], opts, onBuild );
63+
}
64+
65+
main();

tools/benchmarks/html/bin/usage.txt renamed to lib/node_modules/@stdlib/_tools/benchmarks/html/docs/usage.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
Usage: benchmarks-html [options] url
2+
Usage: benchmarks-html [options] <url>
33

44
Options:
55

tools/benchmarks/html/bin/opts.json renamed to lib/node_modules/@stdlib/_tools/benchmarks/html/etc/cli_opts.json

File renamed without changes.

tools/benchmarks/html/examples/index.js renamed to lib/node_modules/@stdlib/_tools/benchmarks/html/examples/index.js

File renamed without changes.

tools/benchmarks/html/lib/build.js renamed to lib/node_modules/@stdlib/_tools/benchmarks/html/lib/build.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ template = readFileSync( template, {
3737
* @throws {TypeError} options argument must be an object
3838
* @throws {TypeError} must provide valid options
3939
* @throws {TypeError} callback argument must be a function
40+
* @returns {void}
4041
*
4142
* @example
4243
* var bundle = '/foo/bar/bundle.js';
@@ -88,7 +89,7 @@ function build( bundle, options, clbk ) {
8889

8990
if ( !opts.out ) {
9091
// Don't release the zaglo...
91-
return process.nextTick( onTick( html ) );
92+
return process.nextTick( onTickFactory( html ) );
9293
}
9394
dir = cwd();
9495
debug( 'Current working directory: %s', dir );
@@ -110,22 +111,25 @@ function build( bundle, options, clbk ) {
110111
* @param {string} html - rendered HTML
111112
* @returns {Callback} callback
112113
*/
113-
function onTick( html ) {
114+
function onTickFactory( html ) {
115+
return onTick;
116+
114117
/**
115118
* Callback invoked on the next tick.
116119
*
117120
* @private
118121
*/
119-
return function onTick() {
122+
function onTick() {
120123
done( null, html );
121-
}; // end FUNCTION onTick()
124+
}
122125
}
123126

124127
/**
125128
* Callback invoked upon writing to file.
126129
*
127130
* @private
128131
* @param {(Error|null)} error - error object
132+
* @returns {void}
129133
*/
130134
function onWrite( error ) {
131135
if ( error ) {
@@ -142,6 +146,7 @@ function build( bundle, options, clbk ) {
142146
* @private
143147
* @param {(Error|null)} error - error object
144148
* @param {string} html - rendered HTML
149+
* @returns {void}
145150
*/
146151
function done( error, html ) {
147152
if ( error ) {

tools/benchmarks/html/lib/defaults.json renamed to lib/node_modules/@stdlib/_tools/benchmarks/html/lib/defaults.json

File renamed without changes.

tools/benchmarks/html/lib/index.js renamed to lib/node_modules/@stdlib/_tools/benchmarks/html/lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/**
44
* Generate an HTML file for running benchmarks.
55
*
6-
* @module @stdlib/tools/benchmarks/html
6+
* @module @stdlib/_tools/benchmarks/html
77
*
88
* @example
9-
* var build = require( '@stdlib/tools/benchmarks/html' );
9+
* var build = require( '@stdlib/_tools/benchmarks/html' );
1010
*
1111
* var bundle = '/foo/bar/bundle.js';
1212
* var opts = {
@@ -22,7 +22,7 @@
2222
* }
2323
*
2424
* @example
25-
* var build = require( '@stdlib/tools/benchmarks/html' );
25+
* var build = require( '@stdlib/_tools/benchmarks/html' );
2626
*
2727
* var bundle = '/foo/bar/bundle.js';
2828
*

tools/benchmarks/html/lib/validate.js renamed to lib/node_modules/@stdlib/_tools/benchmarks/html/lib/validate.js

File renamed without changes.

tools/benchmarks/html/package.json renamed to lib/node_modules/@stdlib/_tools/benchmarks/html/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@stdlib/tools/benchmarks/html",
2+
"name": "@stdlib/_tools/benchmarks/html",
33
"version": "0.0.0",
44
"description": "Generate an HTML file for running benchmarks.",
55
"author": {

0 commit comments

Comments
 (0)