Skip to content

Commit 473aa72

Browse files
authored
Merge pull request #128 from docsbydoxdox/hotfix/fix-casting-issue
[hotfix] Fix casting issue
2 parents 1b338e2 + 5f45e03 commit 473aa72

File tree

3 files changed

+195
-19
lines changed

3 files changed

+195
-19
lines changed

packages/doxdox-cli/src/index.test.ts

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import { promises as fs } from 'fs';
2+
3+
import { promisify } from 'util';
4+
5+
import { exec } from 'child_process';
6+
7+
const execAsync = promisify(exec);
8+
9+
describe('cli', () => {
10+
it('get version (short flag)', async () => {
11+
const pkg = JSON.parse(await fs.readFile('./package.json', 'utf8'));
12+
13+
const { stdout } = await execAsync(`./dist/src/index.js -v`);
14+
15+
expect(stdout.trim()).toBe(pkg.version);
16+
});
17+
it('get version (long flag)', async () => {
18+
const pkg = JSON.parse(await fs.readFile('./package.json', 'utf8'));
19+
20+
const { stdout } = await execAsync(`./dist/src/index.js --version`);
21+
22+
expect(stdout.trim()).toBe(pkg.version);
23+
});
24+
it('get help (short flag)', async () => {
25+
const { stdout } = await execAsync(`./dist/src/index.js -h`);
26+
27+
expect(stdout).toContain('Usage: doxdox');
28+
});
29+
it('get help (long flag)', async () => {
30+
const { stdout } = await execAsync(`./dist/src/index.js --help`);
31+
32+
expect(stdout).toContain('Usage: doxdox');
33+
});
34+
it('set name (short flag)', async () => {
35+
const { stdout } = await execAsync(
36+
`./dist/src/index.js -n "testing the project name"`
37+
);
38+
39+
expect(stdout).toContain('# testing the project name');
40+
});
41+
it('set name (long flag)', async () => {
42+
const { stdout } = await execAsync(
43+
`./dist/src/index.js --name "testing the project name"`
44+
);
45+
46+
expect(stdout).toContain('# testing the project name');
47+
});
48+
it('set description (short flag)', async () => {
49+
const { stdout } = await execAsync(
50+
`./dist/src/index.js -d "testing the project description"`
51+
);
52+
53+
expect(stdout).toContain('> testing the project description');
54+
});
55+
it('set description (long flag)', async () => {
56+
const { stdout } = await execAsync(
57+
`./dist/src/index.js --description "testing the project description"`
58+
);
59+
60+
expect(stdout).toContain('> testing the project description');
61+
});
62+
it('set renderer (short flag)', async () => {
63+
const { stdout } = await execAsync(`./dist/src/index.js -r bootstrap`);
64+
65+
expect(stdout).toContain('<html>');
66+
});
67+
it('set renderer (long flag)', async () => {
68+
const { stdout } = await execAsync(
69+
`./dist/src/index.js --renderer bootstrap`
70+
);
71+
72+
expect(stdout).toContain('<html>');
73+
});
74+
it('set output (no flag)', async () => {
75+
const { stdout } = await execAsync(`./dist/src/index.js`);
76+
77+
expect(stdout).toContain('# doxdox-cli');
78+
});
79+
it('set output (no directory)', async () => {
80+
const { stdout } = await execAsync(`./dist/src/index.js -o temp.md`);
81+
82+
await fs.stat('./temp.md');
83+
84+
expect(stdout).not.toContain('# doxdox-cli');
85+
86+
expect(await fs.readFile('./temp.md', 'utf8')).toContain(
87+
'# doxdox-cli'
88+
);
89+
90+
await fs.unlink('./temp.md');
91+
});
92+
it('set output (inside exisiting directory)', async () => {
93+
const { stdout } = await execAsync(
94+
`./dist/src/index.js -o src/temp.md`
95+
);
96+
97+
await fs.stat('./src/temp.md');
98+
99+
expect(stdout).not.toContain('# doxdox-cli');
100+
101+
expect(await fs.readFile('./src/temp.md', 'utf8')).toContain(
102+
'# doxdox-cli'
103+
);
104+
105+
await fs.unlink('./src/temp.md');
106+
});
107+
it('set output (inside non-exisiting directory)', async () => {
108+
const { stdout } = await execAsync(
109+
`./dist/src/index.js -o temp/temp.md`
110+
);
111+
112+
await fs.stat('./temp/temp.md');
113+
114+
expect(stdout).not.toContain('# doxdox-cli');
115+
116+
expect(await fs.readFile('./temp/temp.md', 'utf8')).toContain(
117+
'# doxdox-cli'
118+
);
119+
120+
await fs.unlink('./temp/temp.md');
121+
});
122+
it('set output (short flag)', async () => {
123+
const { stdout } = await execAsync(`./dist/src/index.js -o temp.md`);
124+
125+
await fs.stat('./temp.md');
126+
127+
expect(stdout).not.toContain('# doxdox-cli');
128+
129+
expect(await fs.readFile('./temp.md', 'utf8')).toContain(
130+
'# doxdox-cli'
131+
);
132+
133+
await fs.unlink('./temp.md');
134+
});
135+
it('set output (long flag)', async () => {
136+
const { stdout } = await execAsync(
137+
`./dist/src/index.js --output temp.md`
138+
);
139+
140+
await fs.stat('./temp.md');
141+
142+
expect(stdout).not.toContain('# doxdox-cli');
143+
144+
expect(await fs.readFile('./temp.md', 'utf8')).toContain(
145+
'# doxdox-cli'
146+
);
147+
148+
await fs.unlink('./temp.md');
149+
});
150+
it('set package location (no flag)', async () => {
151+
const { stdout } = await execAsync(`./dist/src/index.js`);
152+
153+
expect(stdout).toContain('# doxdox-cli');
154+
});
155+
it('set package location (short flag)', async () => {
156+
const { stdout } = await execAsync(
157+
`./dist/src/index.js -p ../../package.json`
158+
);
159+
160+
expect(stdout).toContain('# doxdox-workspace');
161+
});
162+
it('set package location (long flag)', async () => {
163+
const { stdout } = await execAsync(
164+
`./dist/src/index.js --package ../../package.json`
165+
);
166+
167+
expect(stdout).toContain('# doxdox-workspace');
168+
});
169+
});

packages/doxdox-cli/src/index.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,23 @@ const args = parseCmdArgs(null, {
5151

5252
const cwd = process.cwd();
5353

54-
const showHelp = args.flags['-h'] || args.flags['--help'];
55-
const showVersion = args.flags['-v'] || args.flags['--version'];
56-
57-
const overrideName = args.flags['-n'] || args.flags['--name'];
58-
const overrideDescription = args.flags['-d'] || args.flags['--description'];
59-
const overrideIgnore = args.flags['-i'] || args.flags['--ignore'] || '';
60-
const overrideRenderer =
61-
args.flags['-r'] || args.flags['--renderer'] || 'markdown';
62-
const overrideOutput = args.flags['-o'] || args.flags['--output'] || false;
63-
const overridePackage = args.flags['-p'] || args.flags['--package'];
54+
const showHelp = Boolean(args.flags['-h'] || args.flags['--help'] || false);
55+
const showVersion = Boolean(
56+
args.flags['-v'] || args.flags['--version'] || false
57+
);
58+
59+
const overrideName = String(args.flags['-n'] || args.flags['--name'] || '');
60+
const overrideDescription = String(
61+
args.flags['-d'] || args.flags['--description'] || ''
62+
);
63+
const overrideIgnore = String(args.flags['-i'] || args.flags['--ignore'] || '');
64+
const overrideRenderer = String(
65+
args.flags['-r'] || args.flags['--renderer'] || 'markdown'
66+
);
67+
const overrideOutput = String(args.flags['-o'] || args.flags['--output'] || '');
68+
const overridePackage = String(
69+
args.flags['-p'] || args.flags['--package'] || ''
70+
);
6471

6572
(async () => {
6673
const pkgPath = await findFileInPath(
@@ -88,8 +95,8 @@ const overridePackage = args.flags['-p'] || args.flags['--package'];
8895
}
8996

9097
const paths = await globby(
91-
(args.inputs?.length ? args.inputs : defaultPaths).concat(
92-
parseIgnoreConfig(String(overrideIgnore).split(',').join(EOL))
98+
(args.inputs.length ? args.inputs : defaultPaths).concat(
99+
parseIgnoreConfig(overrideIgnore.split(',').join(EOL))
93100
),
94101
{
95102
cwd,
@@ -113,7 +120,7 @@ const overridePackage = args.flags['-p'] || args.flags['--package'];
113120
const loadedRenderer = await loadPlugin<(doc: Doc) => Promise<string>>(
114121
nodeModulesDir,
115122
'doxdox-renderer-',
116-
String(overrideRenderer).toLowerCase()
123+
overrideRenderer.toLowerCase()
117124
);
118125

119126
if (!loadedParser) {
@@ -124,18 +131,18 @@ const overridePackage = args.flags['-p'] || args.flags['--package'];
124131
throw new Error('Renderer missing!');
125132
}
126133

127-
const pkg = await getProjectPackage(String(overridePackage) || cwd);
134+
const pkg = await getProjectPackage(overridePackage || cwd);
128135

129136
const output = await doxdox(cwd, paths, loadedParser, loadedRenderer, {
130-
name: String(overrideName) || pkg.name || 'Untitled Project',
131-
description: String(overrideDescription) || pkg.description || '',
137+
name: overrideName || pkg.name || 'Untitled Project',
138+
description: overrideDescription || pkg.description || '',
132139
version: pkg.version
133140
});
134141

135142
if (overrideOutput) {
136-
await fs.mkdir(dirname(String(overrideOutput)), { recursive: true });
143+
await fs.mkdir(dirname(overrideOutput), { recursive: true });
137144

138-
await fs.writeFile(String(overrideOutput), output);
145+
await fs.writeFile(overrideOutput, output);
139146
} else {
140147
process.stdout.write(output);
141148
}

packages/doxdox-parser-jsdoc/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default async (cwd: string, path: string): Promise<File> => {
5757
name: jsdoc.name,
5858
fullName: `${jsdoc.name}(${params
5959
.map(param => param.name)
60-
.filter(name => !name?.match(/\./))
60+
.filter(name => name && !name.match(/\./))
6161
.join(', ')})`,
6262
description: jsdoc.description || '',
6363
params,

0 commit comments

Comments
 (0)