Skip to content

Commit

Permalink
custom output directory and baseURL
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespohalloran committed Nov 13, 2022
1 parent ac1ad81 commit 66d3e20
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 19 deletions.
14 changes: 14 additions & 0 deletions packages/link-proofer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ jobs:
CI: true
```
## CLI Usage
```
Usage: linkproofer [options]

Options:
-h, --help display help for command
-V, --version output the version number
-f, --files <files> Filepath pattern for files in which linkproofer should check for links
-v, --verbose <verbose> Log out all checked links (not just the failures)
-o, --outputDir <outputDir> Directory to put the compiled output files. (Default dist). This directory should be added to your .gitignore
-b, --baseURL <baseURL> baseURL to use for relative links.
```

## Checking links on local deployment

TODO
2 changes: 1 addition & 1 deletion packages/link-proofer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linkproofer",
"version": "0.0.4",
"version": "0.0.5",
"description": "Tool to check for broken links in a project",
"source": "src/index.ts",
"files": [
Expand Down
7 changes: 7 additions & 0 deletions packages/link-proofer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ export async function init(args: any) {
"-v, --verbose <verbose>",
"Log out all checked links (not just the failures)"
)
.option(
"-o, --outputDir <outputDir>",
"Directory to put the compiled output files. (Default dist). This directory should be added to your .gitignore"
)
.option("-b, --baseURL <baseURL>", "baseURL to use for relative links.")
.action(async (options) => {
await checkFiles({
filePattern: options.files,
verbose: options.verbose,
outputDir: options.outputDir,
baseURL: options.baseURL,
});
});

Expand Down
41 changes: 23 additions & 18 deletions packages/link-proofer/src/link-proofer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ interface LinkList {
}

const getLinkProofFile = async (
filePattern: string | string[]
filePattern: string | string[],
outputDir: string,
baseURL: string
): Promise<LinkList[]> => {
const linkproofFilename = "linkproof";
const outputDir = "dist";

const defaultPattern = `**/*.${linkproofFilename}.{ts,js}`;
//glob for all files ending in .linkproof.ts or linkproof.js outside of dist
Expand Down Expand Up @@ -50,24 +51,13 @@ const getLinkProofFile = async (
)
);

// if (fs.existsSync(path.join(process.cwd(), `${linkproofFilename}.ts`))) {
// hasTs = true;
// } else if (
// fs.existsSync(!path.join(process.cwd(), `${linkproofFilename}.js`) as any)
// ) {
// throw new Error(
// `No ${linkproofFilename}.ts or linkproof.js file found in project root`
// );
// }

await build({
entryPoints: entries,
bundle: true,
platform: "node",
target: "node17",
outdir: path.join(process.cwd(), "dist"),
outdir: path.join(process.cwd(), outputDir),
allowOverwrite: true,
//outfile: path.join(process.cwd(), "dist", `${linkproofFilename}.out.js`),
});

let result: LinkList[] = [];
Expand All @@ -78,12 +68,20 @@ const getLinkProofFile = async (

const linkProofFile = await require(path.join(
process.cwd(),
"dist",
outputDir,
entryJs
)).default;

const valueKeys = Object.keys(linkProofFile).map((key: any) => {
return { key, value: linkProofFile[key] } as LinkList;
//join baseUrl and linkProofFile[key] without messing up http:// or https://

const val = linkProofFile[key].startsWith("/")
? baseURL.replace(/\/$/, "") + linkProofFile[key]
: linkProofFile[key];
return {
key: key,
value: val,
} as LinkList;
});
result = [...result, ...valueKeys];
})
Expand All @@ -95,10 +93,17 @@ const getLinkProofFile = async (
export interface CheckFilesProps {
filePattern: string | string[];
verbose: boolean;
outputDir: string;
baseURL: string;
}

export const checkFiles = async ({ filePattern, verbose }: CheckFilesProps) => {
const linkproofFile = await getLinkProofFile(filePattern);
export const checkFiles = async ({
filePattern,
verbose,
outputDir = "dist",
baseURL,
}: CheckFilesProps) => {
const linkproofFile = await getLinkProofFile(filePattern, outputDir, baseURL);
await checkLinkProofFile(linkproofFile, verbose);
};

Expand Down
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ jobs:
CI: true
```
## CLI Usage
```
Usage: linkproofer [options]

Options:
-h, --help display help for command
-V, --version output the version number
-f, --files <files> Filepath pattern for files in which linkproofer should check for links
-v, --verbose <verbose> Log out all checked links (not just the failures)
-o, --outputDir <outputDir> Directory to put the compiled output files. (Default dist). This directory should be added to your .gitignore
-b, --baseURL <baseURL> baseURL to use for relative links.
```

## Checking links on local deployment

TODO

0 comments on commit 66d3e20

Please sign in to comment.