11#!/usr/bin/env node
22
3- 'use strict'
4-
5- const exec = require ( 'child_process' ) . exec
6- const fs = require ( 'fs' )
7- const http = require ( 'http' )
8- const https = require ( 'https' )
9- const nopt = require ( 'nopt' )
10- const path = require ( 'path' )
11- const pretty = require ( '../lib/format-pretty' )
12- const formatTap = require ( '../lib/format-tap' )
13- const Validator = require ( '../lib' )
14- const Tap = require ( '../lib/tap' )
15- const utils = require ( '../lib/utils' )
16- const subsystem = require ( '../lib/rules/subsystem' )
3+ import { exec } from 'node:child_process'
4+ import fs from 'node:fs'
5+ import http from 'node:http'
6+ import https from 'node:https'
7+ import path from 'node:path'
8+ import nopt from 'nopt'
9+ import pretty from '../lib/format-pretty.js'
10+ import formatTap from '../lib/format-tap.js'
11+ import Validator from '../lib/validator.js'
12+ import Tap from '../lib/tap.js'
13+ import * as utils from '../lib/utils.js'
14+ import subsystem from '../lib/rules/subsystem.js'
15+
1716const knownOpts = {
1817 help : Boolean ,
1918 version : Boolean ,
@@ -34,14 +33,19 @@ const shortHand = {
3433}
3534
3635const parsed = nopt ( knownOpts , shortHand )
37- const usage = require ( 'help' ) ( )
3836
3937if ( parsed . help ) {
40- usage ( )
38+ const usagePath = path . join ( new URL ( import . meta. url ) . pathname , '../usage.txt' )
39+ const help = await fs . promises . readFile ( usagePath , 'utf8' )
40+ console . log ( help )
41+ process . exit ( 0 )
4142}
4243
4344if ( parsed . version ) {
44- console . log ( 'core-validate-commit' , 'v' + require ( '../package' ) . version )
45+ const pkgJsonPath = path . join ( new URL ( import . meta. url ) . pathname , '../../package.json' )
46+ const pkgJson = await fs . promises . readFile ( pkgJsonPath , 'utf8' )
47+ const { version } = JSON . parse ( pkgJson )
48+ console . log ( `core-validate-commit v${ version } ` )
4549 process . exit ( 0 )
4650}
4751
0 commit comments