Skip to content

Commit b1462f0

Browse files
authored
Merge pull request #49 from kalramanoj2002/feature/upgrade-packages
upgrade apidoc-core, fs-extra and use markdown-it
2 parents b73be12 + c8ce291 commit b1462f0

File tree

8 files changed

+6177
-125
lines changed

8 files changed

+6177
-125
lines changed

bin/apidocSwagger.js

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,6 @@ var argv = nomnom
4848
// markdown settings
4949
.option('markdown', { flag: true, 'default': true, help: 'Turn off markdown parser.' })
5050

51-
.option('marked-config', { 'default': '',
52-
help: 'Enable custom markdown parser configs. It will overwite all other marked settings.' })
53-
54-
.option('marked-gfm', { flag: true, 'default': true,
55-
help: 'Enable GitHub flavored markdown.' })
56-
57-
.option('marked-tables', { flag: true, 'default': true,
58-
help: 'Enable GFM tables. This option requires the gfm option to be true.' })
59-
60-
.option('marked-breaks', { flag: true, 'default': false,
61-
help: 'Enable GFM line breaks. This option requires the gfm option to be true.' })
62-
63-
.option('marked-pedantic', { flag: true, 'default': false,
64-
help: 'Conform to obscure parts of markdown.pl as much as possible.' })
65-
66-
.option('marked-sanitize', { flag: true, 'default': false,
67-
help: 'Sanitize the output. Ignore any HTML that has been input.' })
68-
69-
.option('marked-smartLists', { flag: true, 'default': false,
70-
help: 'Use smarter list behavior than the original markdown.' })
71-
72-
.option('marked-smartypants', { flag: true, 'default': false,
73-
help: 'Use \'smart\' typograhic punctuation for things like quotes and dashes.' })
74-
7551
.parse()
7652
;
7753

@@ -99,28 +75,6 @@ function transformToObject(filters) {
9975
return result;
10076
}
10177

102-
/**
103-
* Sets configuration for markdown
104-
*
105-
* @param {Array} argv
106-
* @returns {Object}
107-
*/
108-
function resolveMarkdownOptions(argv) {
109-
if (argv['marked-config']) {
110-
return require(path.resolve(argv['marked-config']));
111-
} else {
112-
return {
113-
gfm : argv['marked-gfm'],
114-
tables : argv['marked-tables'],
115-
breaks : argv['marked-breaks'],
116-
pedantic : argv['marked-pedantic'],
117-
sanitize : argv['marked-sanitize'],
118-
smartLists : argv['marked-smartLists'],
119-
smartypants: argv['marked-smartypants']
120-
};
121-
}
122-
}
123-
12478
var options = {
12579
excludeFilters: argv['exclude-filters'],
12680
includeFilters: argv['file-filters'],
@@ -136,8 +90,7 @@ var options = {
13690
workers : transformToObject(argv['parse-workers']),
13791
silent : argv['silent'],
13892
simulate : argv['simulate'],
139-
markdown : argv['markdown'],
140-
marked : resolveMarkdownOptions(argv)
93+
markdown : argv['markdown']
14194
};
14295

14396
if (apidocSwagger.createApidocSwagger(options) === false) {

lib/apidocToSwagger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ function createPathParameters(verbs, pathKeys) {
293293
function groupByUrl(apidocJson) {
294294
return _.chain(apidocJson)
295295
.groupBy("url")
296-
.pairs()
296+
.toPairs()
297297
.map(function (element) {
298-
return _.object(_.zip(["url", "verbs"], element));
298+
return _.zipObject(["url", "verbs"], element);
299299
})
300300
.value();
301301
}

lib/index.js

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,35 @@
1-
var _ = require('lodash');
2-
var apidoc = require('apidoc-core');
3-
var winston = require('winston');
4-
var path = require('path');
5-
var markdown = require('marked');
6-
var nomnom = require('nomnom');
7-
var fs = require('fs-extra');
1+
var _ = require('lodash');
2+
var apidoc = require('apidoc-core');
3+
var winston = require('winston');
4+
var path = require('path');
5+
var markdown = require('markdown-it');
6+
var nomnom = require('nomnom');
7+
var fs = require('fs-extra');
88
var PackageInfo = require('./package_info');
99

1010
var apidocSwagger = require('./apidocToSwagger');
1111

1212
var defaults = {
13-
dest : path.join(__dirname, '../doc/'),
13+
dest: path.join(__dirname, '../doc/'),
1414
template: path.join(__dirname, '../template/'),
1515

16-
debug : false,
17-
silent : false,
18-
verbose : false,
16+
debug: false,
17+
silent: false,
18+
verbose: false,
1919
simulate: false,
20-
parse : false, // only parse and return the data, no file creation
20+
parse: false, // only parse and return the data, no file creation
2121
colorize: true,
22-
markdown: true,
23-
24-
marked: {
25-
gfm : true,
26-
tables : true,
27-
breaks : false,
28-
pedantic : false,
29-
sanitize : false,
30-
smartLists : false,
31-
smartypants: false
32-
}
22+
markdown: true
3323
};
3424

3525
var app = {
36-
log : {},
26+
log: {},
3727
markdown: false,
38-
options : {}
28+
options: {}
3929
};
4030

4131
// uncaughtException
42-
process.on('uncaughtException', function(err) {
32+
process.on('uncaughtException', function (err) {
4333
console.error((new Date()).toUTCString() + ' uncaughtException:', err.message);
4434
console.error(err.stack);
4535
process.exit(1);
@@ -53,7 +43,7 @@ function createApidocSwagger(options) {
5343
options = _.defaults({}, options, defaults);
5444

5545
// paths
56-
options.dest = path.join(options.dest, './');
46+
options.dest = path.join(options.dest, './');
5747

5848
// options
5949
app.options = options;
@@ -62,30 +52,34 @@ function createApidocSwagger(options) {
6252
app.log = new (winston.Logger)({
6353
transports: [
6454
new (winston.transports.Console)({
65-
level : app.options.debug ? 'debug' : app.options.verbose ? 'verbose' : 'info',
66-
silent : app.options.silent,
55+
level: app.options.debug ? 'debug' : app.options.verbose ? 'verbose' : 'info',
56+
silent: app.options.silent,
6757
prettyPrint: true,
68-
colorize : app.options.colorize,
69-
timestamp : false
58+
colorize: app.options.colorize,
59+
timestamp: false
7060
}),
7161
]
7262
});
7363

7464
// markdown
75-
if(app.options.markdown === true) {
76-
app.markdown = markdown;
77-
app.markdown.setOptions(app.options.marked);
65+
if (app.options.markdown === true) {
66+
app.markdown = new markdown({
67+
breaks: false,
68+
html: true,
69+
linkify: false,
70+
typographer: false
71+
});
7872
}
7973

8074
try {
8175
packageInfo = new PackageInfo(app);
8276

8377
// generator information
84-
var json = JSON.parse( fs.readFileSync(apidocPath + 'package.json', 'utf8') );
78+
var json = JSON.parse(fs.readFileSync(apidocPath + 'package.json', 'utf8'));
8579
apidoc.setGeneratorInfos({
86-
name : json.name,
87-
time : new Date(),
88-
url : json.homepage,
80+
name: json.name,
81+
time: new Date(),
82+
url: json.homepage,
8983
version: json.version
9084
});
9185
apidoc.setLogger(app.log);
@@ -101,35 +95,35 @@ function createApidocSwagger(options) {
10195
if (api === false)
10296
return false;
10397

104-
if (app.options.parse !== true){
98+
if (app.options.parse !== true) {
10599
var apidocData = JSON.parse(api.data);
106100
var projectData = JSON.parse(api.project);
107-
api["swaggerData"] = JSON.stringify(apidocSwagger.toSwagger(apidocData , projectData));
101+
api["swaggerData"] = JSON.stringify(apidocSwagger.toSwagger(apidocData, projectData));
108102
createOutputFile(api);
109103
}
110104

111105
app.log.info('Done.');
112106
return api;
113-
} catch(e) {
107+
} catch (e) {
114108
app.log.error(e.message);
115109
if (e.stack)
116110
app.log.debug(e.stack);
117111
return false;
118112
}
119113
}
120114

121-
function createOutputFile(api){
115+
function createOutputFile(api) {
122116
if (app.options.simulate)
123117
app.log.warn('!!! Simulation !!! No file or dir will be copied or created.');
124118

125119
app.log.verbose('create dir: ' + app.options.dest);
126-
if ( ! app.options.simulate)
120+
if (!app.options.simulate)
127121
fs.mkdirsSync(app.options.dest);
128122

129123
//Write swagger
130124
app.log.verbose('write swagger json file: ' + app.options.dest + 'swagger.json');
131-
if( ! app.options.simulate)
132-
fs.writeFileSync(app.options.dest + './swagger.json', api.swaggerData);
125+
if (!app.options.simulate)
126+
fs.writeFileSync(app.options.dest + './swagger.json', api.swaggerData);
133127
}
134128

135129
module.exports = {

0 commit comments

Comments
 (0)