Skip to content

Commit 5e11aa5

Browse files
committed
using babel for building
1 parent 01b6633 commit 5e11aa5

File tree

13 files changed

+1430
-171
lines changed

13 files changed

+1430
-171
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["es2015", "stage-2"],
3+
"plugins": []
4+
}

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__tests__/*
2+
dist/*
3+
node_modules/*

.eslintrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": "airbnb-base",
4+
"plugins": [
5+
"import"
6+
],
7+
"parserOptions": {
8+
"ecmaVersion": 2017,
9+
"sourceType": "module"
10+
},
11+
"env": {
12+
"node": true
13+
},
14+
"rules": {
15+
"camelcase": 0,
16+
"no-param-reassign": 0,
17+
}
18+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# See https://help.github.com/ignore-files/ for more about ignoring files.
22

3+
# dist
4+
/dist
5+
36
# dependencies
47
/node_modules
58

__tests__/doxyjs.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
const localize = require('localize');
2-
const ts = require('../translations/translations.json');
2+
const ts = require('../dist/translations/translations.json');
33

44
const commentSeeds = require('./seeds/commentSeeds');
55
const variableSeeds = require('./seeds/variableSeeds');
66
const functionSeeds = require('./seeds/functionSeeds');
77
const classSeeds = require('./seeds/classSeeds');
88

9-
const doxyjs = require('../doxyjs');
9+
const doxyjs = require('../dist/doxyjs').default;
1010

1111
const translator = new localize(ts);
1212
const linebreak = '\n';
1313

1414
describe('doxyjs', () => {
15-
const testSeeds = seed => {
15+
const testSeeds = (seed) => {
1616
seed.input.forEach((input, index) => {
1717
expect(doxyjs(input, linebreak, translator)).toEqual(seed.output[index]);
1818
});

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@
1818
"localize": "^0.4.7"
1919
},
2020
"devDependencies": {
21+
"babel-cli": "^6.24.1",
22+
"babel-eslint": "^7.2.3",
23+
"babel-preset-es2015": "^6.24.1",
24+
"babel-preset-stage-2": "^6.24.1",
25+
"eslint": "^4.1.1",
26+
"eslint-config-airbnb-base": "^11.2.0",
27+
"eslint-plugin-import": "^2.6.1",
2128
"jest": "^20.0.4"
2229
},
2330
"bin": {
24-
"doxyjs": "./index.js"
31+
"doxyjs": "dist/index.js"
2532
},
26-
"engines": {
27-
"node": ">=7.0.0"
28-
},
29-
"keywords": [
30-
"cli",
31-
"doxygen"
32-
],
33+
"files": ["dist/"],
34+
"keywords": ["cli", "doxygen"],
3335
"scripts": {
36+
"build": "babel src --out-dir dist --source-maps inline --copy-files",
37+
"clean": "rm -rf dist",
38+
"prebuild": "npm run clean",
39+
"prepublish": "npm run build",
40+
"pretest": "npm run build",
3441
"test": "jest"
3542
},
3643
"jest": {
37-
"testMatch": [
38-
"**/__tests__/*.test.js"
39-
],
40-
"collectCoverageFrom": [
41-
"**/*.js",
42-
"!**/seeds/**",
43-
"!**/node_modules/**",
44-
"!**/coverage/**"
45-
]
44+
"testMatch": ["**/__tests__/*.test.js"],
45+
"collectCoverageFrom": ["**/*.js", "!**/seeds/**", "!**/node_modules/**", "!**/coverage/**"]
4646
}
4747
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const inputTokens = require('./src/inputTokens');
2-
const inputStructure = require('./src/inputStructure');
3-
const outputSource = require('./src/outputSource');
1+
import inputTokens from './inputTokens';
2+
import inputStructure from './inputStructure';
3+
import outputSource from './outputSource';
44

55
const doxyjs = (input_data, linebreak, ts) => {
66
const input_lines = input_data.split(linebreak).filter(line => line.length);
@@ -11,4 +11,4 @@ const doxyjs = (input_data, linebreak, ts) => {
1111
return output_source;
1212
};
1313

14-
module.exports = doxyjs;
14+
export default doxyjs;

index.js renamed to src/index.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
11
#!/usr/bin/env node
22

3-
const fs = require('fs');
4-
const program = require('commander');
5-
const localize = require('localize');
6-
const doxyjs = require('./doxyjs');
7-
const pkg = require('./package.json');
8-
const ts = require('./translations/translations.json');
3+
import fs from 'fs';
4+
import program from 'commander';
5+
import Localize from 'localize';
6+
import doxyjs from './doxyjs';
7+
import pkg from '../package.json';
8+
import ts from './translations/translations.json';
99

10-
const translator = new localize(ts);
10+
const translator = new Localize(ts);
1111

1212
program
1313
.description(pkg.description)
1414
.version(pkg.version)
1515
.arguments('[files...]')
16-
.option(
17-
'-e, --encoding <encoding>',
18-
'source files encoding (utf8 by default)',
19-
'utf8'
20-
)
16+
.option('-e, --encoding <encoding>', 'source files encoding (utf8 by default)', 'utf8')
2117
.option(
2218
'-b, --line-break <line break>',
2319
'line break symbol [lf|crlf] (lf by default)',
2420
val => (val.match(/^crlf$/i) ? '\r\n' : '\n'),
25-
'\n'
21+
'\n',
2622
)
27-
.option(
28-
'-l, --lang <language code>',
29-
'output language (en by default)',
30-
'en'
31-
);
23+
.option('-l, --lang <language code>', 'output language (en by default)', 'en');
3224

3325
program.parse(process.argv);
3426

35-
if (program.args.length == 0) {
36-
console.error(`doxyjs: no input files provided, aborting`);
27+
if (program.args.length === 0) {
28+
console.error('doxyjs: no input files provided, aborting');
3729
process.exit(1);
3830
}
3931

4032
translator.setLocale(program.lang);
4133

42-
program.args.forEach(file => {
34+
program.args.forEach((file) => {
4335
fs.readFile(file, program.encoding, (error, data) => {
4436
if (error) {
4537
console.error(`doxyjs: can't read file ${file}, aborting`);

src/inputStructure.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
const isDetachedComment = token => {
2-
return token.token_type === 'multiline_comment' && token.filename;
3-
};
1+
const isDetachedComment = token => token.token_type === 'multiline_comment' && token.filename;
42

5-
const isAttachedComment = token => {
6-
return (
7-
token.token_type === 'singleline_comment' ||
8-
(token.token_type === 'multiline_comment' && !isDetachedComment(token))
9-
);
10-
};
3+
const isAttachedComment = token =>
4+
token.token_type === 'singleline_comment' ||
5+
(token.token_type === 'multiline_comment' && !isDetachedComment(token));
116

127
const prev = (array, index) => (index > 0 ? array[index - 1] : null);
138

@@ -34,7 +29,7 @@ const attachVariableComment = (token, comment) => {
3429

3530
const attachFunctionComment = (token, comment) => {
3631
if (comment) {
37-
token.args.forEach(arg => {
32+
token.args.forEach((arg) => {
3833
if (comment.params && arg.name in comment.params) {
3934
arg.type = comment.params[arg.name].type || 'var';
4035
} else {
@@ -45,7 +40,7 @@ const attachFunctionComment = (token, comment) => {
4540
token.type = comment.return ? comment.return.type || 'void' : 'void';
4641
token.comment = comment;
4742
} else {
48-
token.args.forEach(arg => {
43+
token.args.forEach((arg) => {
4944
arg.type = 'var';
5045
});
5146

@@ -56,7 +51,7 @@ const attachFunctionComment = (token, comment) => {
5651

5752
const attachClassConstructorComment = (token, comment) => {
5853
if (comment) {
59-
token.args.forEach(arg => {
54+
token.args.forEach((arg) => {
6055
if (comment.params && arg.name in comment.params) {
6156
arg.type = comment.params[arg.name].type || 'var';
6257
} else {
@@ -66,7 +61,7 @@ const attachClassConstructorComment = (token, comment) => {
6661

6762
token.comment = comment;
6863
} else {
69-
token.args.forEach(arg => {
64+
token.args.forEach((arg) => {
7065
arg.type = 'var';
7166
});
7267
}
@@ -75,7 +70,7 @@ const attachClassConstructorComment = (token, comment) => {
7570

7671
const attachClassMethodComment = (token, comment) => {
7772
if (comment) {
78-
token.args.forEach(arg => {
73+
token.args.forEach((arg) => {
7974
if (comment.params && arg.name in comment.params) {
8075
arg.type = comment.params[arg.name].type || 'var';
8176
} else {
@@ -86,7 +81,7 @@ const attachClassMethodComment = (token, comment) => {
8681
token.type = comment.return ? comment.return.type || 'void' : 'void';
8782
token.comment = comment;
8883
} else {
89-
token.args.forEach(arg => {
84+
token.args.forEach((arg) => {
9085
arg.type = 'var';
9186
});
9287

@@ -95,8 +90,8 @@ const attachClassMethodComment = (token, comment) => {
9590
return token;
9691
};
9792

98-
const inputStructure = tokens => {
99-
let structure = {
93+
const inputStructure = (tokens) => {
94+
const structure = {
10095
comments: [],
10196
variables: [],
10297
functions: [],
@@ -106,27 +101,21 @@ const inputStructure = tokens => {
106101
tokens.forEach((token, index, tokens) => {
107102
switch (token.token_type) {
108103
case 'variable':
109-
structure.variables.push(
110-
attachVariableComment(token, comment(tokens, index))
111-
);
104+
structure.variables.push(attachVariableComment(token, comment(tokens, index)));
112105
break;
113106
case 'function':
114-
structure.functions.push(
115-
attachFunctionComment(token, comment(tokens, index))
116-
);
107+
structure.functions.push(attachFunctionComment(token, comment(tokens, index)));
117108
break;
118109
case 'class_constructor':
119110
prefillClass(structure, token.class_name);
120111
const c = comment(tokens, index);
121-
structure.classes[
122-
token.class_name
123-
].constructor = attachClassConstructorComment(token, c);
112+
structure.classes[token.class_name].constructor = attachClassConstructorComment(token, c);
124113
structure.classes[token.class_name].comment = c || undefined;
125114
break;
126115
case 'class_method':
127116
prefillClass(structure, token.class_name);
128117
structure.classes[token.class_name].methods.push(
129-
attachClassMethodComment(token, comment(tokens, index))
118+
attachClassMethodComment(token, comment(tokens, index)),
130119
);
131120
break;
132121
case 'base_class':
@@ -141,10 +130,12 @@ const inputStructure = tokens => {
141130
structure.comments.push(token);
142131
}
143132
break;
133+
default:
134+
break;
144135
}
145136
});
146137

147138
return structure;
148139
};
149140

150-
module.exports = inputStructure;
141+
export default inputStructure;

0 commit comments

Comments
 (0)