Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit 755b8da

Browse files
committed
update CLI
1 parent 1bfc7c5 commit 755b8da

File tree

4 files changed

+83
-29
lines changed

4 files changed

+83
-29
lines changed

bin/index.js

100644100755
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,42 @@ const path = require('path');
33
const fs = require('fs');
44
const parseComments = require('./../dist/openapi-comment-parser');
55

6+
let openapiConfig = {};
7+
8+
try {
9+
openapiConfig = require(path.resolve('.openapirc.js'));
10+
} catch {}
11+
12+
if (process.argv[2] === '--init') {
13+
fs.writeFileSync(
14+
'.openapirc.js',
15+
`module.exports = {
16+
extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.yaml', '.yml'],
17+
include: ['**'],
18+
exclude: [
19+
'coverage/**',
20+
'packages/*/test{,s}/**',
21+
'**/*.d.ts',
22+
'test{,s}/**',
23+
'test{,-*}.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}',
24+
'**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}',
25+
'**/__tests__/**',
26+
'**/{ava,babel,nyc}.config.{js,cjs,mjs}',
27+
'**/jest.config.{js,cjs,mjs,ts}',
28+
'**/{karma,rollup,webpack}.config.js',
29+
'**/.{eslint,mocha}rc.{js,cjs}',
30+
'**/.{travis,yarnrc}.yml',
31+
'**/{docker-compose}.yml',
32+
],
33+
excludeNodeModules: true,
34+
verbose: true,
35+
throwLevel: 'off',
36+
};
37+
`
38+
);
39+
return;
40+
}
41+
642
if (process.argv[2] === undefined || process.argv[3] === undefined) {
743
console.log('Usage:');
844
console.log(' openapi-comment-parser SRC_PATH OUTPUT');
@@ -15,6 +51,6 @@ if (process.argv[2] === undefined || process.argv[3] === undefined) {
1551
const inputPath = path.resolve(process.argv[2]);
1652
const outputPath = path.resolve(process.argv[3]);
1753

18-
const spec = parseComments({ cwd: inputPath });
54+
const spec = parseComments({ ...openapiConfig, cwd: inputPath });
1955

2056
fs.writeFileSync(outputPath, JSON.stringify(spec));

rollup.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,20 @@ export default [
2323
{ file: pkg.module, format: 'es' },
2424
],
2525
},
26+
{
27+
input: 'src/options.ts',
28+
plugins: [
29+
resolve(), // so Rollup can find external packages
30+
commonjs({ ignoreGlobal: true }), // so Rollup can convert external packages to ES modules
31+
sucrase({
32+
// so Rollup can convert TypeScript to JavaScript
33+
exclude: ['node_modules/**', '**/?(*.)test.ts'],
34+
transforms: ['typescript'],
35+
}),
36+
],
37+
output: [
38+
{ file: 'dist/options.js', format: 'cjs' },
39+
{ file: 'dist/options.esm.js', format: 'es' },
40+
],
41+
},
2642
];

src/index.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import SpecBuilder from './SpecBuilder';
1414
import { ParserOptions, OpenApiObject } from './exported';
1515
import yamlLOC from './util/yamlLOC';
1616
import formatter from './util/formatter';
17+
import DEFAULT_OPTIONS from './options';
1718

1819
function getCallerPath() {
1920
const filename = callerCallsite()?.getFileName();
@@ -23,34 +24,6 @@ function getCallerPath() {
2324
return '';
2425
}
2526

26-
const DEFAULT_OPTIONS = {
27-
cwd: undefined,
28-
extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.yaml', '.yml'],
29-
include: ['**'],
30-
exclude: [
31-
'coverage/**',
32-
'packages/*/test{,s}/**',
33-
'**/*.d.ts',
34-
'test{,s}/**',
35-
`test{,-*}.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}`,
36-
`**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}`,
37-
'**/__tests__/**',
38-
39-
/* Exclude common development tool configuration files */
40-
'**/{ava,babel,nyc}.config.{js,cjs,mjs}',
41-
'**/jest.config.{js,cjs,mjs,ts}',
42-
'**/{karma,rollup,webpack}.config.js',
43-
'**/.{eslint,mocha}rc.{js,cjs}',
44-
'**/.{travis,yarnrc}.yml',
45-
'**/{docker-compose}.yml',
46-
47-
// always ignore '**/node_modules/**'
48-
],
49-
excludeNodeModules: true,
50-
verbose: true,
51-
throwLevel: 'off',
52-
};
53-
5427
function parseComments(options: ParserOptions = {}): OpenApiObject {
5528
const definition = {
5629
openapi: '',

src/options.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const DEFAULT_OPTIONS = {
2+
cwd: undefined,
3+
extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.yaml', '.yml'],
4+
include: ['**'],
5+
exclude: [
6+
'coverage/**',
7+
'packages/*/test{,s}/**',
8+
'**/*.d.ts',
9+
'test{,s}/**',
10+
`test{,-*}.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}`,
11+
`**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}`,
12+
'**/__tests__/**',
13+
14+
/* Exclude common development tool configuration files */
15+
'**/{ava,babel,nyc}.config.{js,cjs,mjs}',
16+
'**/jest.config.{js,cjs,mjs,ts}',
17+
'**/{karma,rollup,webpack}.config.js',
18+
'**/.{eslint,mocha}rc.{js,cjs}',
19+
'**/.{travis,yarnrc}.yml',
20+
'**/{docker-compose}.yml',
21+
22+
// always ignore '**/node_modules/**'
23+
],
24+
excludeNodeModules: true,
25+
verbose: true,
26+
throwLevel: 'off',
27+
};
28+
29+
export default DEFAULT_OPTIONS;

0 commit comments

Comments
 (0)