Skip to content

Commit

Permalink
refactor: support node >=14
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jan 17, 2024
1 parent f9b4222 commit 0671342
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 57 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "MIT",
"packageManager": "yarn@3.6.4",
"engines": {
"node": ">=14.8.0"
"node": ">=14"
},
"bin": "lib/cli.mjs",
"main": "lib/index.js",
Expand All @@ -28,7 +28,8 @@
"files": [
"bin",
"img",
"lib"
"lib",
"!**/*.tsbuildinfo"
],
"keywords": [
"git",
Expand Down
109 changes: 58 additions & 51 deletions src/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,69 @@ const args = mri(process.argv.slice(2), {
},
})

const prettyQuickResult = await prettyQuick(process.cwd(), {
...args,
onFoundSinceRevision: (scm, revision) => {
console.log(
`🔍 Finding changed files since ${picocolors.bold(
scm,
)} revision ${picocolors.bold(revision)}.`,
)
},
const main = async () => {
const prettyQuickResult = await prettyQuick(process.cwd(), {
...args,
onFoundSinceRevision: (scm, revision) => {
console.log(
`🔍 Finding changed files since ${picocolors.bold(
scm,
)} revision ${picocolors.bold(revision)}.`,
)
},

onFoundChangedFiles: changedFiles => {
console.log(
`🎯 Found ${picocolors.bold(changedFiles.length)} changed ${
changedFiles.length === 1 ? 'file' : 'files'
}.`,
)
},
onFoundChangedFiles: changedFiles => {
console.log(
`🎯 Found ${picocolors.bold(changedFiles.length)} changed ${
changedFiles.length === 1 ? 'file' : 'files'
}.`,
)
},

onPartiallyStagedFile: file => {
console.log(`✗ Found ${picocolors.bold('partially')} staged file ${file}.`)
},
onPartiallyStagedFile: file => {
console.log(
`✗ Found ${picocolors.bold('partially')} staged file ${file}.`,
)
},

onWriteFile: file => {
console.log(`✍️ Fixing up ${picocolors.bold(file)}.`)
},
onWriteFile: file => {
console.log(`✍️ Fixing up ${picocolors.bold(file)}.`)
},

onCheckFile: (file, isFormatted) => {
if (!isFormatted) {
console.log(`⛔️ Check failed: ${picocolors.bold(file)}`)
}
},
onCheckFile: (file, isFormatted) => {
if (!isFormatted) {
console.log(`⛔️ Check failed: ${picocolors.bold(file)}`)
}
},

onExamineFile: file => {
console.log(`🔍 Examining ${picocolors.bold(file)}.`)
},
})
onExamineFile: file => {
console.log(`🔍 Examining ${picocolors.bold(file)}.`)
},
})

if (prettyQuickResult.success) {
console.log('✅ Everything is awesome!')
} else {
if (prettyQuickResult.errors.includes('PARTIALLY_STAGED_FILE')) {
console.log(
'✗ Partially staged files were fixed up.' +
` ${picocolors.bold('Please update stage before committing')}.`,
)
}
if (prettyQuickResult.errors.includes('BAIL_ON_WRITE')) {
console.log(
'✗ File had to be prettified and prettyQuick was set to bail mode.',
)
}
if (prettyQuickResult.errors.includes('CHECK_FAILED')) {
console.log(
'✗ Code style issues found in the above file(s). Forgot to run Prettier?',
)
if (prettyQuickResult.success) {
console.log('✅ Everything is awesome!')
} else {
if (prettyQuickResult.errors.includes('PARTIALLY_STAGED_FILE')) {
console.log(
'✗ Partially staged files were fixed up.' +
` ${picocolors.bold('Please update stage before committing')}.`,
)
}
if (prettyQuickResult.errors.includes('BAIL_ON_WRITE')) {
console.log(
'✗ File had to be prettified and prettyQuick was set to bail mode.',
)
}
if (prettyQuickResult.errors.includes('CHECK_FAILED')) {
console.log(
'✗ Code style issues found in the above file(s). Forgot to run Prettier?',
)
}
// eslint-disable-next-line n/no-process-exit
process.exit(1) // ensure git hooks abort
}
// eslint-disable-next-line n/no-process-exit
process.exit(1) // ensure git hooks abort
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
main()
5 changes: 1 addition & 4 deletions tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
// used by all files but do not includes paths
"extends": "@1stg/tsconfig/node16",
"compilerOptions": {
"target": "ES2017"
}
"extends": "@1stg/tsconfig/node16"
}

0 comments on commit 0671342

Please sign in to comment.