Skip to content

Commit a7178f3

Browse files
committed
feat(build options): silent building
Additional option to silence builds, clean up wild test logging, and code cleanup
1 parent c7a7ce5 commit a7178f3

File tree

3 files changed

+60
-57
lines changed

3 files changed

+60
-57
lines changed

README.md

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,46 @@
55
[![Build Status](https://travis-ci.org/3DEsprit/node-offline-api.svg?branch=master)](https://travis-ci.org/3DEsprit/node-offline-api)
66
[![codecov](https://codecov.io/gh/3DEsprit/node-offline-api/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/3DEsprit/node-offline-api)
77
[![dependencies](https://img.shields.io/david/expressjs/express.svg?style=flat-square)](https://codecov.io/gh/3DEsprit/node-offline-api)
8-
[![dev-dependencies](https://img.shields.io/david/dev/expressjs/express.svg?style=flat-square)](https://codecov.io/gh/3DEsprit/node-offline-api)
9-
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()
108

11-
The Node.js Offline Document API (NODe API) module allows anyone to create an offline version of the Node.js documentation.
9+
10+
The Node.js Offline Document API (NODe API) module allows anyone to create an offline version of the Node.js documentation for any version of Node.js.
1211

1312
## Requirements
1413

15-
This module has been created to work with Node.js versions greater than 4.0.0, but many older versions will work, but it has not been tested or created to support these older versions.
14+
While you can create documentation for any version of Node.js, this module has been created versions greater than 4.0.0 in mind. Since it has been created with ES5 for compatibility, older versions will work, but it has not been tested or created to support these older versions.
15+
16+
17+
### Installation
18+
19+
You can clone this repository, or install via NPM.
20+
21+
*Via Source*
22+
23+
```
24+
$ git clone https://github.com/3DEsprit/node-offline-api.git
25+
26+
$ npm i
27+
```
28+
29+
*Via NPM*
30+
31+
```
32+
$ npm i node-offline-api
33+
```
34+
35+
_or_
36+
37+
```
38+
$ yarn add node-offline-api
39+
```
40+
1641

1742
## Usage
1843

1944
There are two different ways to use the NODe API, through the CLI, and as an added module to your Node.js applications.
2045

46+
47+
2148
### As a module in your JavaScript code
2249

2350
To use the NODe API in your own code, all that is needed is to require the module's createDoc method, and call it.
@@ -42,21 +69,16 @@ buildOptions.version: '4.4.0';
4269
createDocs();
4370
```
4471

45-
### As a Script
46-
47-
You can also use NODe as your own script simply to pull and create Node.js documentation.
48-
49-
After cloning the repository: https://github.com/3DEsprit/node-offline-api.git
72+
By default the build can be quite verbose when creating the documents. If you would prefer that the builds be silent, the buildQuiet option is offered allowing the build to complete silently, except when actual errors occur.
5073

5174
```
52-
$ npm i
75+
buildOptions.buildQuiet: true
5376
```
5477

55-
_or_
5678

57-
```
58-
$ yarn install
59-
```
79+
### As a Script
80+
81+
You can also use NODe as your own script simply to pull and create Node.js documentation.
6082

6183
```
6284
$ npm start
@@ -84,6 +106,6 @@ $ node app/ -f [folder]
84106

85107
## License
86108

87-
The Node Offline Doucmentation API is under the MIT license.
109+
The Node Offline Doucmentation API has been written with the [![license](https://img.shields.io/github/license/mashape/apistatus.svg)]().
88110

89111
The Node.js Document API is property of the [Node.js Project](https://github.com/nodejs/node). [Node.js License](https://github.com/nodejs/node/blob/master/LICENSE)

app/index.js

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,25 @@ var child;
2626
var buildOptions = {
2727
buildDir: process.cwd(),
2828
buildVersion: process.version.slice(1),
29-
buildName: 'node-documents'
29+
buildName: 'node-documents',
30+
buildQuiet: false,
3031
}
3132

3233
var options = process.argv.slice(2);
33-
console.log(options);
3434

3535
// check for command line scripting options
3636
if(options[0] !== []) {
3737
options.forEach(function(ops, index) {
38-
console.log(ops);
3938
if (ops.startsWith('-v')) {
40-
var version = options[index + 1];
41-
buildOptions.buildVersion = version;
39+
buildOptions.buildVersion = options[index + 1];
4240
flags[3] = '--node-version=' + version;
4341
} else if (ops.startsWith('-f')) {
4442
buildDir = options[index + 1];
45-
if (buildDir.slice(-1) !== docEnd) {
46-
buildDir += docEnd;
47-
}
43+
if (buildDir.slice(-1) !== docEnd) { buildDir += docEnd; }
4844
buildOptions.buildDir = buildDir + buildOptions.buildName;
49-
console.log('Custom build dir: ', buildOptions.buildDir);
50-
}
51-
if (index === options.length - 1) {
52-
checkOptions();
45+
if (!buildOptions.buildQuiet) console.log('Custom build dir: ', buildOptions.buildDir);
5346
}
47+
if (index === options.length - 1) { checkOptions(); }
5448
});
5549
}
5650

@@ -60,36 +54,32 @@ function convertFile(file) {
6054
count++;
6155
flags[2] = apiDir + file;
6256
var filename = file.slice(0,-3);
63-
console.log('Creating doc ' + filename);
57+
if (!buildOptions.buildQuiet) console.log('Creating doc ' + filename);
6458
var pathname = buildOptions.buildDir + filename + '.html';
6559
var fileStream = fs.createWriteStream(pathname);
6660
var createFile = spawn('node', flags);
6761
createFile.stdout.pipe(fileStream);
6862
createFile.on('close', (code) => {
69-
if (code !== 0) {
70-
console.log('NODe API: process exited with code ' + code);
71-
}
63+
if (code !== 0) { if (!buildOptions.buildQuiet) console.log('NODe API: process exited with code ' + code); }
7264
});
73-
createFile.on('error', (err) => console.log('Error writing: ', err));
65+
createFile.on('error', (err) => console.error('Error writing: ', err));
7466
}
7567

7668
// grab template file and assets
7769
function checkFiles() {
7870
fs.readdir(apiDir, function(err, res) {
7971
var ext = path.extname('*.md');
80-
if (err) console.error(err.stack);
72+
if (err) { console.error(err.stack); }
8173
res.forEach((file) => {
82-
if (path.extname(file) === ext) {
83-
convertFile(file);
84-
}
74+
if (path.extname(file) === ext) { convertFile(file); }
8575
});
8676
});
8777
}
8878

8979
function copyAssets() {
9080
fsx.copy(apiAssets, buildOptions.buildDir + 'assets', function(err) {
91-
if (err) return console.error('copy', err);
92-
console.log('NODe: asset copy success');
81+
if (err) { return console.error('copy', err); }
82+
if (!buildOptions.buildQuiet) { console.log('NODe: asset copy success'); }
9383
});
9484
checkFiles();
9585
}
@@ -98,34 +88,24 @@ function copyAssets() {
9888
function checkFolders() {
9989
fs.stat(buildOptions.buildDir, function(err, out) {
10090
if (out) {
101-
console.log('NODe API: build folder exists');
91+
if (!buildOptions.buildQuiet) console.log('NODe API: build folder exists');
10292
fs.stat(buildOptions.buildDir + 'assets', function(err, out) {
103-
if (err) {
104-
copyAssets();
105-
}
93+
if (err) { copyAssets(); }
10694
});
10795
} else {
108-
console.log('NODe API: creating build folder');
96+
if (!buildOptions.buildQuiet) console.log('NODe API: creating build folder');
10997
fs.mkdirSync(buildOptions.buildDir);
11098
copyAssets();
11199
}
112100
});
113101
}
114102

115103
function checkOptions() {
116-
console.log(buildOptions.buildVersion);
117-
var version = buildOptions.buildVersion;
118-
flags[3] = '--node-version=' + version;
119-
120-
if(buildOptions.buildDir.slice(0,1)) {
121-
buildOptions.buildDir = buildOptions.buildDir.replace(/^~/, os.homedir);
122-
}
123-
124-
if (buildOptions.buildDir.slice(-1) !== docEnd) {
125-
buildOptions.buildDir += docEnd;
126-
}
104+
flags[3] = '--node-version=' + buildOptions.buildVersion;
105+
if(buildOptions.buildDir.slice(0,1)) { buildOptions.buildDir = buildOptions.buildDir.replace(/^~/, os.homedir); }
106+
if (buildOptions.buildDir.slice(-1) !== docEnd) { buildOptions.buildDir += docEnd; }
127107
buildOptions.buildDir += buildOptions.buildName + docEnd;
128-
console.log('NODe API: Building to Directory: %s', buildOptions.buildDir);
108+
if (!buildOptions.buildQuiet) { console.log('NODe API: Building to Directory: %s', buildOptions.buildDir); }
129109
checkFolders();
130110
}
131111

example/test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ var buildOptions = require('../app/index.js').buildOptions;
99
// buildOptions.buildDir = '~\\My Documents'
1010

1111
// Test version change
12-
buildOptions.buildVersion = '4.4.0'
13-
buildOptions.buildName = 'apidoc'
12+
buildOptions.buildVersion = '4.4.0';
13+
buildOptions.buildName = 'apidoc';
14+
buildOptions.buildQuiet = true;
1415

1516
createDocs();

0 commit comments

Comments
 (0)