Skip to content

Commit

Permalink
🎨 UPDATE: with more styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jycouet committed Sep 12, 2024
1 parent d728bba commit d6eef51
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-years-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kitql/eslint-config': patch
---

add some spin
98 changes: 61 additions & 37 deletions packages/eslint-config/cmd.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/usr/bin/env node
import { spawnSync } from 'node:child_process'
import { spawn } from 'node:child_process'
import { Option, program } from 'commander'
import ora from 'ora'

import { Log, red } from '@kitql/helpers'
import { bgBlueBright, gray, red } from '@kitql/helpers'

import { findFileOrUp } from './helper/findFileOrUp.js'

const log = new Log('kitql-lint')
const spinner = ora({
// hideCursor: true,
prefixText: bgBlueBright(` kitql-lint `),
text: 'check config',
})
spinner.start()

program.addOption(new Option('-f, --format', 'format'))
program.addOption(new Option('-g, --glob <type>', 'file/dir/glob (. by default)', '.'))
Expand Down Expand Up @@ -39,34 +45,36 @@ if (pre === 'npm') {
preToUse = ''
}

function prettierRun() {
const cmdPrettier =
preToUse +
`prettier` +
` --list-different` +
// ignore?
` --ignore-path ${pathPrettierIgnore}` +
// config
` --config ${pathPrettierCjs}` +
// format or not
`${format ? ' --write' : ''}` +
// exec
` ${glob}`

if (verbose) {
log.info(cmdPrettier)
}
const result_prettier = spawnSync(cmdPrettier, {
async function customSpawn(cmd) {
const child = spawn(cmd, {
shell: true,
cwd: process.cwd(),
stdio: 'inherit',
})
// console.log(`child`, child)

let data = ''
// for await (const chunk of child?.stdout) {
// console.log('stdout chunk: ' + chunk)
// data += chunk
// }
let error = ''
// for await (const chunk of child?.stderr) {
// console.error('stderr chunk: ' + chunk)
// error += chunk
// }
const exitCode = await new Promise((resolve, reject) => {
child.on('close', resolve)
})

return result_prettier
if (exitCode) {
// throw new Error(`subprocess error exit ${exitCode}, ${error}`)
return { status: exitCode, error }
}
return data
}

function eslintRun() {
// Then eslint
async function eslintRun() {
const cmdEsLint =
preToUse +
`eslint` +
Expand All @@ -75,30 +83,46 @@ function eslintRun() {
// exec
` ${glob}`

if (verbose) {
log.info(cmdEsLint)
}
spinner.text = verbose ? 'eslint ' + gray(`(${cmdEsLint})`) : 'eslint'

const result_eslint = spawnSync(cmdEsLint, {
shell: true,
cwd: process.cwd(),
stdio: 'inherit',
})
const result_eslint = await customSpawn(cmdEsLint)

return result_eslint
}

const eslintCode = eslintRun()
async function prettierRun() {
const cmdPrettier =
preToUse +
`prettier` +
` --list-different` +
// ignore?
` --ignore-path ${pathPrettierIgnore}` +
// config
` --config ${pathPrettierCjs}` +
// format or not
`${format ? ' --write' : ''}` +
// exec
` ${glob}`

spinner.text = verbose ? 'prettier ' + gray(`(${cmdPrettier})`) : 'prettier'

const result_prettier = await customSpawn(cmdPrettier)

return result_prettier
}

const eslintCode = await eslintRun()
if (eslintCode.status) {
log.error(red(`eslint failed, check logs above.`))
spinner.fail(red(`eslint failed, check logs above.`))
process.exit(eslintCode.status)
}

const prettierCode = prettierRun()
const prettierCode = await prettierRun()
if (prettierCode.status) {
log.error(red(`prettier failed, check logs above.`))
spinner.fail(red(`prettier failed, check logs above.`))
process.exit(eslintCode.status)
}

log.success(`All good, your files looks great!`)
spinner.succeed(`All good, your files looks great!`)
spinner.stop()
process.exit(0)
1 change: 1 addition & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"eslint-plugin-svelte": "2.43.0",
"eslint-plugin-unused-imports": "^4.1.3",
"globals": "15.9.0",
"ora": "^8.1.0",
"prettier": "3.3.3",
"prettier-plugin-svelte": "3.2.6",
"prettier-plugin-tailwindcss": "0.6.6",
Expand Down
Loading

0 comments on commit d6eef51

Please sign in to comment.