Skip to content

Commit 09d5aff

Browse files
committed
feat(build options): allow file updates
new updateApi build option allows users to force NODe to update the document files with every request
1 parent bac37c3 commit 09d5aff

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,31 @@ If you need to change the desired build directory, build folder name, or build v
6262
```
6363
var buildOptions = require('node-offline-api').buildOptions;
6464
65-
buildOptions.buildDir: '/Users/username/Documents';
66-
buildOptions.buildName: 'MyAPIDocs';
67-
buildOptions.version: '4.4.0';
65+
buildOptions.buildDir = '/Users/username/Documents';
66+
buildOptions.buildName = 'MyAPIDocs';
67+
buildOptions.version = '4.4.0';
6868
6969
createDocs();
7070
```
7171

7272
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.
7373

7474
```
75-
buildOptions.buildQuiet: true
75+
buildOptions.buildQuiet = true;
7676
```
7777

78+
The way that NODe is written protects already generated documents by ignoring future requests when documents already exist. If you plan to update your documents many times with the same build name directory you will want to use the updateApi option.
79+
80+
```
81+
buildOptions.updateApi = true;
82+
```
83+
84+
Setting this option to _true_ tells NODe to create and overwrite the existing documents with each request.
85+
7886

7987
### As a Script
8088

81-
You can also use NODe as your own script simply to pull and create Node.js documentation.
89+
You can also use NODe as your own script simply to pull and create Node.js documentation, but with less options. Even though this feature has less options, the options that do not exist can be easily scripted.
8290

8391
```
8492
$ npm start

app/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var buildOptions = {
2828
buildVersion: process.version.slice(1),
2929
buildName: 'node-documents',
3030
buildQuiet: false,
31+
updateApi: false
3132
}
3233

3334
var options = process.argv.slice(2);
@@ -56,7 +57,7 @@ function convertFile(file) {
5657
var filename = file.slice(0,-3);
5758
if (!buildOptions.buildQuiet) console.log('Creating doc ' + filename);
5859
var pathname = buildOptions.buildDir + filename + '.html';
59-
var fileStream = fs.createWriteStream(pathname);
60+
var fileStream = fs.createWriteStream(pathname, {flag: 'w'});
6061
var createFile = spawn('node', flags);
6162
createFile.stdout.pipe(fileStream);
6263
createFile.on('close', (code) => {
@@ -88,9 +89,9 @@ function copyAssets() {
8889
function checkFolders() {
8990
fs.stat(buildOptions.buildDir, function(err, out) {
9091
if (out) {
91-
if (!buildOptions.buildQuiet) console.log('NODe API: build folder exists');
92-
fs.stat(buildOptions.buildDir + 'assets', function(err, out) {
92+
fs.stat(buildOptions.buildDir + 'assets', function(err, out) {
9393
if (err) { copyAssets(); }
94+
if (buildOptions.updateApi) { copyAssets(); }
9495
});
9596
} else {
9697
if (!buildOptions.buildQuiet) console.log('NODe API: creating build folder');

example/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ buildOptions.buildVersion = '4.4.0';
1313
buildOptions.buildName = 'apidoc';
1414
buildOptions.buildQuiet = true;
1515

16+
// Use this to overwrite existing API documents
17+
// buildOptions.updateApi = true;
18+
1619
createDocs();

0 commit comments

Comments
 (0)