Skip to content

Commit

Permalink
Merge pull request #128 from docsbydoxdox/hotfix/fix-casting-issue
Browse files Browse the repository at this point in the history
[hotfix] Fix casting issue
  • Loading branch information
neogeek authored Feb 8, 2022
2 parents 1b338e2 + 5f45e03 commit 473aa72
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 19 deletions.
169 changes: 169 additions & 0 deletions packages/doxdox-cli/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { promises as fs } from 'fs';

import { promisify } from 'util';

import { exec } from 'child_process';

const execAsync = promisify(exec);

describe('cli', () => {
it('get version (short flag)', async () => {
const pkg = JSON.parse(await fs.readFile('./package.json', 'utf8'));

const { stdout } = await execAsync(`./dist/src/index.js -v`);

expect(stdout.trim()).toBe(pkg.version);
});
it('get version (long flag)', async () => {
const pkg = JSON.parse(await fs.readFile('./package.json', 'utf8'));

const { stdout } = await execAsync(`./dist/src/index.js --version`);

expect(stdout.trim()).toBe(pkg.version);
});
it('get help (short flag)', async () => {
const { stdout } = await execAsync(`./dist/src/index.js -h`);

expect(stdout).toContain('Usage: doxdox');
});
it('get help (long flag)', async () => {
const { stdout } = await execAsync(`./dist/src/index.js --help`);

expect(stdout).toContain('Usage: doxdox');
});
it('set name (short flag)', async () => {
const { stdout } = await execAsync(
`./dist/src/index.js -n "testing the project name"`
);

expect(stdout).toContain('# testing the project name');
});
it('set name (long flag)', async () => {
const { stdout } = await execAsync(
`./dist/src/index.js --name "testing the project name"`
);

expect(stdout).toContain('# testing the project name');
});
it('set description (short flag)', async () => {
const { stdout } = await execAsync(
`./dist/src/index.js -d "testing the project description"`
);

expect(stdout).toContain('> testing the project description');
});
it('set description (long flag)', async () => {
const { stdout } = await execAsync(
`./dist/src/index.js --description "testing the project description"`
);

expect(stdout).toContain('> testing the project description');
});
it('set renderer (short flag)', async () => {
const { stdout } = await execAsync(`./dist/src/index.js -r bootstrap`);

expect(stdout).toContain('<html>');
});
it('set renderer (long flag)', async () => {
const { stdout } = await execAsync(
`./dist/src/index.js --renderer bootstrap`
);

expect(stdout).toContain('<html>');
});
it('set output (no flag)', async () => {
const { stdout } = await execAsync(`./dist/src/index.js`);

expect(stdout).toContain('# doxdox-cli');
});
it('set output (no directory)', async () => {
const { stdout } = await execAsync(`./dist/src/index.js -o temp.md`);

await fs.stat('./temp.md');

expect(stdout).not.toContain('# doxdox-cli');

expect(await fs.readFile('./temp.md', 'utf8')).toContain(
'# doxdox-cli'
);

await fs.unlink('./temp.md');
});
it('set output (inside exisiting directory)', async () => {
const { stdout } = await execAsync(
`./dist/src/index.js -o src/temp.md`
);

await fs.stat('./src/temp.md');

expect(stdout).not.toContain('# doxdox-cli');

expect(await fs.readFile('./src/temp.md', 'utf8')).toContain(
'# doxdox-cli'
);

await fs.unlink('./src/temp.md');
});
it('set output (inside non-exisiting directory)', async () => {
const { stdout } = await execAsync(
`./dist/src/index.js -o temp/temp.md`
);

await fs.stat('./temp/temp.md');

expect(stdout).not.toContain('# doxdox-cli');

expect(await fs.readFile('./temp/temp.md', 'utf8')).toContain(
'# doxdox-cli'
);

await fs.unlink('./temp/temp.md');
});
it('set output (short flag)', async () => {
const { stdout } = await execAsync(`./dist/src/index.js -o temp.md`);

await fs.stat('./temp.md');

expect(stdout).not.toContain('# doxdox-cli');

expect(await fs.readFile('./temp.md', 'utf8')).toContain(
'# doxdox-cli'
);

await fs.unlink('./temp.md');
});
it('set output (long flag)', async () => {
const { stdout } = await execAsync(
`./dist/src/index.js --output temp.md`
);

await fs.stat('./temp.md');

expect(stdout).not.toContain('# doxdox-cli');

expect(await fs.readFile('./temp.md', 'utf8')).toContain(
'# doxdox-cli'
);

await fs.unlink('./temp.md');
});
it('set package location (no flag)', async () => {
const { stdout } = await execAsync(`./dist/src/index.js`);

expect(stdout).toContain('# doxdox-cli');
});
it('set package location (short flag)', async () => {
const { stdout } = await execAsync(
`./dist/src/index.js -p ../../package.json`
);

expect(stdout).toContain('# doxdox-workspace');
});
it('set package location (long flag)', async () => {
const { stdout } = await execAsync(
`./dist/src/index.js --package ../../package.json`
);

expect(stdout).toContain('# doxdox-workspace');
});
});
43 changes: 25 additions & 18 deletions packages/doxdox-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,23 @@ const args = parseCmdArgs(null, {

const cwd = process.cwd();

const showHelp = args.flags['-h'] || args.flags['--help'];
const showVersion = args.flags['-v'] || args.flags['--version'];

const overrideName = args.flags['-n'] || args.flags['--name'];
const overrideDescription = args.flags['-d'] || args.flags['--description'];
const overrideIgnore = args.flags['-i'] || args.flags['--ignore'] || '';
const overrideRenderer =
args.flags['-r'] || args.flags['--renderer'] || 'markdown';
const overrideOutput = args.flags['-o'] || args.flags['--output'] || false;
const overridePackage = args.flags['-p'] || args.flags['--package'];
const showHelp = Boolean(args.flags['-h'] || args.flags['--help'] || false);
const showVersion = Boolean(
args.flags['-v'] || args.flags['--version'] || false
);

const overrideName = String(args.flags['-n'] || args.flags['--name'] || '');
const overrideDescription = String(
args.flags['-d'] || args.flags['--description'] || ''
);
const overrideIgnore = String(args.flags['-i'] || args.flags['--ignore'] || '');
const overrideRenderer = String(
args.flags['-r'] || args.flags['--renderer'] || 'markdown'
);
const overrideOutput = String(args.flags['-o'] || args.flags['--output'] || '');
const overridePackage = String(
args.flags['-p'] || args.flags['--package'] || ''
);

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

const paths = await globby(
(args.inputs?.length ? args.inputs : defaultPaths).concat(
parseIgnoreConfig(String(overrideIgnore).split(',').join(EOL))
(args.inputs.length ? args.inputs : defaultPaths).concat(
parseIgnoreConfig(overrideIgnore.split(',').join(EOL))
),
{
cwd,
Expand All @@ -113,7 +120,7 @@ const overridePackage = args.flags['-p'] || args.flags['--package'];
const loadedRenderer = await loadPlugin<(doc: Doc) => Promise<string>>(
nodeModulesDir,
'doxdox-renderer-',
String(overrideRenderer).toLowerCase()
overrideRenderer.toLowerCase()
);

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

const pkg = await getProjectPackage(String(overridePackage) || cwd);
const pkg = await getProjectPackage(overridePackage || cwd);

const output = await doxdox(cwd, paths, loadedParser, loadedRenderer, {
name: String(overrideName) || pkg.name || 'Untitled Project',
description: String(overrideDescription) || pkg.description || '',
name: overrideName || pkg.name || 'Untitled Project',
description: overrideDescription || pkg.description || '',
version: pkg.version
});

if (overrideOutput) {
await fs.mkdir(dirname(String(overrideOutput)), { recursive: true });
await fs.mkdir(dirname(overrideOutput), { recursive: true });

await fs.writeFile(String(overrideOutput), output);
await fs.writeFile(overrideOutput, output);
} else {
process.stdout.write(output);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox-parser-jsdoc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default async (cwd: string, path: string): Promise<File> => {
name: jsdoc.name,
fullName: `${jsdoc.name}(${params
.map(param => param.name)
.filter(name => !name?.match(/\./))
.filter(name => name && !name.match(/\./))
.join(', ')})`,
description: jsdoc.description || '',
params,
Expand Down

0 comments on commit 473aa72

Please sign in to comment.