@kitql/eslint-config 0.4.0-next.3 → 0.4.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmd.js +61 -37
- package/package.json +2 -1
package/cmd.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { spawn } from 'node:child_process'
|
|
3
3
|
import { Option, program } from 'commander'
|
|
4
|
+
import ora from 'ora'
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
+
import { bgBlueBright, gray, red } from '@kitql/helpers'
|
|
6
7
|
|
|
7
8
|
import { findFileOrUp } from './helper/findFileOrUp.js'
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
+
const spinner = ora({
|
|
11
|
+
// hideCursor: true,
|
|
12
|
+
prefixText: bgBlueBright(` kitql-lint `),
|
|
13
|
+
text: 'check config',
|
|
14
|
+
})
|
|
15
|
+
spinner.start()
|
|
10
16
|
|
|
11
17
|
program.addOption(new Option('-f, --format', 'format'))
|
|
12
18
|
program.addOption(new Option('-g, --glob <type>', 'file/dir/glob (. by default)', '.'))
|
|
@@ -39,34 +45,36 @@ if (pre === 'npm') {
|
|
|
39
45
|
preToUse = ''
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
preToUse +
|
|
45
|
-
`prettier` +
|
|
46
|
-
` --list-different` +
|
|
47
|
-
// ignore?
|
|
48
|
-
` --ignore-path ${pathPrettierIgnore}` +
|
|
49
|
-
// config
|
|
50
|
-
` --config ${pathPrettierCjs}` +
|
|
51
|
-
// format or not
|
|
52
|
-
`${format ? ' --write' : ''}` +
|
|
53
|
-
// exec
|
|
54
|
-
` ${glob}`
|
|
55
|
-
|
|
56
|
-
if (verbose) {
|
|
57
|
-
log.info(cmdPrettier)
|
|
58
|
-
}
|
|
59
|
-
const result_prettier = spawnSync(cmdPrettier, {
|
|
48
|
+
async function customSpawn(cmd) {
|
|
49
|
+
const child = spawn(cmd, {
|
|
60
50
|
shell: true,
|
|
61
51
|
cwd: process.cwd(),
|
|
62
52
|
stdio: 'inherit',
|
|
63
53
|
})
|
|
54
|
+
// console.log(`child`, child)
|
|
55
|
+
|
|
56
|
+
let data = ''
|
|
57
|
+
// for await (const chunk of child?.stdout) {
|
|
58
|
+
// console.log('stdout chunk: ' + chunk)
|
|
59
|
+
// data += chunk
|
|
60
|
+
// }
|
|
61
|
+
let error = ''
|
|
62
|
+
// for await (const chunk of child?.stderr) {
|
|
63
|
+
// console.error('stderr chunk: ' + chunk)
|
|
64
|
+
// error += chunk
|
|
65
|
+
// }
|
|
66
|
+
const exitCode = await new Promise((resolve, reject) => {
|
|
67
|
+
child.on('close', resolve)
|
|
68
|
+
})
|
|
64
69
|
|
|
65
|
-
|
|
70
|
+
if (exitCode) {
|
|
71
|
+
// throw new Error(`subprocess error exit ${exitCode}, ${error}`)
|
|
72
|
+
return { status: exitCode, error }
|
|
73
|
+
}
|
|
74
|
+
return data
|
|
66
75
|
}
|
|
67
76
|
|
|
68
|
-
function eslintRun() {
|
|
69
|
-
// Then eslint
|
|
77
|
+
async function eslintRun() {
|
|
70
78
|
const cmdEsLint =
|
|
71
79
|
preToUse +
|
|
72
80
|
`eslint` +
|
|
@@ -75,30 +83,46 @@ function eslintRun() {
|
|
|
75
83
|
// exec
|
|
76
84
|
` ${glob}`
|
|
77
85
|
|
|
78
|
-
|
|
79
|
-
log.info(cmdEsLint)
|
|
80
|
-
}
|
|
86
|
+
spinner.text = verbose ? 'eslint ' + gray(`(${cmdEsLint})`) : 'eslint'
|
|
81
87
|
|
|
82
|
-
const result_eslint =
|
|
83
|
-
shell: true,
|
|
84
|
-
cwd: process.cwd(),
|
|
85
|
-
stdio: 'inherit',
|
|
86
|
-
})
|
|
88
|
+
const result_eslint = await customSpawn(cmdEsLint)
|
|
87
89
|
|
|
88
90
|
return result_eslint
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
async function prettierRun() {
|
|
94
|
+
const cmdPrettier =
|
|
95
|
+
preToUse +
|
|
96
|
+
`prettier` +
|
|
97
|
+
` --list-different` +
|
|
98
|
+
// ignore?
|
|
99
|
+
` --ignore-path ${pathPrettierIgnore}` +
|
|
100
|
+
// config
|
|
101
|
+
` --config ${pathPrettierCjs}` +
|
|
102
|
+
// format or not
|
|
103
|
+
`${format ? ' --write' : ''}` +
|
|
104
|
+
// exec
|
|
105
|
+
` ${glob}`
|
|
106
|
+
|
|
107
|
+
spinner.text = verbose ? 'prettier ' + gray(`(${cmdPrettier})`) : 'prettier'
|
|
108
|
+
|
|
109
|
+
const result_prettier = await customSpawn(cmdPrettier)
|
|
110
|
+
|
|
111
|
+
return result_prettier
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const eslintCode = await eslintRun()
|
|
92
115
|
if (eslintCode.status) {
|
|
93
|
-
|
|
116
|
+
spinner.fail(red(`eslint failed, check logs above.`))
|
|
94
117
|
process.exit(eslintCode.status)
|
|
95
118
|
}
|
|
96
119
|
|
|
97
|
-
const prettierCode = prettierRun()
|
|
120
|
+
const prettierCode = await prettierRun()
|
|
98
121
|
if (prettierCode.status) {
|
|
99
|
-
|
|
122
|
+
spinner.fail(red(`prettier failed, check logs above.`))
|
|
100
123
|
process.exit(eslintCode.status)
|
|
101
124
|
}
|
|
102
125
|
|
|
103
|
-
|
|
126
|
+
spinner.succeed(`All good, your files looks great!`)
|
|
127
|
+
spinner.stop()
|
|
104
128
|
process.exit(0)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitql/eslint-config",
|
|
3
|
-
"version": "0.4.0-next.
|
|
3
|
+
"version": "0.4.0-next.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "opinionated linting and formatting for projects",
|
|
6
6
|
"repository": {
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"eslint-plugin-svelte": "2.43.0",
|
|
42
42
|
"eslint-plugin-unused-imports": "^4.1.3",
|
|
43
43
|
"globals": "15.9.0",
|
|
44
|
+
"ora": "^8.1.0",
|
|
44
45
|
"prettier": "3.3.3",
|
|
45
46
|
"prettier-plugin-svelte": "3.2.6",
|
|
46
47
|
"prettier-plugin-tailwindcss": "0.6.6",
|