1616 * limitations under the License.
1717 */
1818
19+ /*
20+ *Usage:
21+ * check-links.ts [options]
22+
23+ * Options:
24+ * --version Show version number [boolean]
25+ * -c, --config Path to markdown-link-check config file [string] [default: ".github/markdown-link-check.jsonc"]
26+ * -i, --ignore Directories to ignore [array] [default: ["node_modules/**"]]
27+ * -m, --checkMarkdown Validate links in markdown files [boolean] [default: true]
28+ * -u, --checkHttp Scan changed files for insecure http URLs [boolean] [default: true]
29+ * -h, --help Show help [boolean]
30+ *
31+ * Example usage:
32+ * npm run check:links
33+ * npm run check:links -- -i "./dist/**" -i "./coverage/**"
34+ * npm run check:links -- -c "./.github/markdown-link-check.jsonc"
35+ * npm run check:links -- -m false -i "./dist/**" -c "./.github/markdown-link-check.jsonc"
36+ */
37+
1938import { execFile as execFileCallback } from "child_process" ;
2039import { readFile as readFileCallback } from "fs" ;
2140import { glob } from "glob" ;
@@ -112,7 +131,14 @@ async function main() {
112131 description : "Directories to ignore" ,
113132 default : [ "node_modules/**" ] ,
114133 } )
134+ . option ( "checkMarkdown" , {
135+ alias : "m" ,
136+ type : "boolean" ,
137+ description : "Validate links in markdown files" ,
138+ default : true ,
139+ } )
115140 . option ( "checkHttp" , {
141+ alias : "u" ,
116142 type : "boolean" ,
117143 description : "Scan changed files for insecure http URLs" ,
118144 default : true ,
@@ -121,27 +147,31 @@ async function main() {
121147 . alias ( "help" , "h" )
122148 . parseSync ( ) ;
123149
124- const configPath = resolve ( argv . config ) ;
125- const mdFiles = await glob ( "**/*.md" , {
126- ignore : argv . ignore as string [ ] ,
127- } ) ;
128-
129- if ( mdFiles . length === 0 ) {
130- console . log ( "No markdown files found." ) ;
131- } else {
132- console . log ( `Checking ${ mdFiles . length } markdown file(s)...` ) ;
133- for ( const file of mdFiles ) {
134- try {
135- const { stdout } = await execFile (
136- "npx" , [ "markdown-link-check" , "-v" , "-c" , configPath , file ] , { shell : true }
137- ) ;
138- console . log ( stdout ) ;
139- } catch ( err : any ) {
140- console . error ( `Error in file: ${ file } ` ) ;
141- console . error ( err . stdout || err . message ) ;
142- process . exitCode = 1 ;
150+ if ( argv . checkMarkdown ) {
151+ const configPath = resolve ( argv . config ) ;
152+ const mdFiles = await glob ( "**/*.md" , {
153+ ignore : argv . ignore as string [ ] ,
154+ } ) ;
155+
156+ if ( mdFiles . length === 0 ) {
157+ console . log ( "No markdown files found." ) ;
158+ } else {
159+ console . log ( `Checking ${ mdFiles . length } markdown file(s)...` ) ;
160+ for ( const file of mdFiles ) {
161+ try {
162+ const { stdout } = await execFile (
163+ "npx" , [ "markdown-link-check" , "-v" , "-c" , configPath , file ] , { shell : true }
164+ ) ;
165+ console . log ( stdout ) ;
166+ } catch ( err : any ) {
167+ console . error ( `Error in file: ${ file } ` ) ;
168+ console . error ( err . stdout || err . message ) ;
169+ process . exitCode = 1 ;
170+ }
143171 }
144172 }
173+ } else {
174+ console . log ( "Skipping markdown link validation." ) ;
145175 }
146176
147177 if ( argv . checkHttp ) {
0 commit comments