@kitql/eslint-config 0.4.0-next.2 → 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 CHANGED
@@ -1,12 +1,18 @@
1
1
  #!/usr/bin/env node
2
- import { spawnSync } from 'node:child_process'
2
+ import { spawn } from 'node:child_process'
3
3
  import { Option, program } from 'commander'
4
+ import ora from 'ora'
4
5
 
5
- import { Log, red } from '@kitql/helpers'
6
+ import { bgBlueBright, gray, red } from '@kitql/helpers'
6
7
 
7
8
  import { findFileOrUp } from './helper/findFileOrUp.js'
8
9
 
9
- const log = new Log('kitql-lint')
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 prettierRun() {
43
- const cmdPrettier =
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
- return result_prettier
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
- if (verbose) {
79
- log.info(cmdEsLint)
80
- }
86
+ spinner.text = verbose ? 'eslint ' + gray(`(${cmdEsLint})`) : 'eslint'
81
87
 
82
- const result_eslint = spawnSync(cmdEsLint, {
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
- const eslintCode = eslintRun()
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
- log.error(red(`eslint failed, check logs above.`))
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
- log.error(red(`prettier failed, check logs above.`))
122
+ spinner.fail(red(`prettier failed, check logs above.`))
100
123
  process.exit(eslintCode.status)
101
124
  }
102
125
 
103
- log.success(`All good, your files looks great!`)
126
+ spinner.succeed(`All good, your files looks great!`)
127
+ spinner.stop()
104
128
  process.exit(0)
@@ -0,0 +1,22 @@
1
+ import { statSync } from 'fs'
2
+ import { resolve } from 'path'
3
+
4
+ export const findFileOrUp = (fileName, options) => {
5
+ // Find file recursively 4 levels max up
6
+ for (let i = 0; i < 4; i++) {
7
+ try {
8
+ const pathFound = '../'.repeat(i) + fileName
9
+ if (statSync(pathFound)) {
10
+ if (options?.absolute) {
11
+ return resolve(pathFound)
12
+ }
13
+ return pathFound
14
+ }
15
+ } catch (error) {
16
+ // nothing to do
17
+ }
18
+ }
19
+
20
+ console.error(`"${fileName}" not found`)
21
+ return null
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitql/eslint-config",
3
- "version": "0.4.0-next.2",
3
+ "version": "0.4.0-next.4",
4
4
  "type": "module",
5
5
  "description": "opinionated linting and formatting for projects",
6
6
  "repository": {
@@ -19,7 +19,8 @@
19
19
  "cmd.js",
20
20
  "cmd.sh",
21
21
  "eslint.config.js",
22
- "eslint.config.d.ts"
22
+ "eslint.config.d.ts",
23
+ "helper/findFileOrUp.js"
23
24
  ],
24
25
  "keywords": [
25
26
  "cli",
@@ -40,6 +41,7 @@
40
41
  "eslint-plugin-svelte": "2.43.0",
41
42
  "eslint-plugin-unused-imports": "^4.1.3",
42
43
  "globals": "15.9.0",
44
+ "ora": "^8.1.0",
43
45
  "prettier": "3.3.3",
44
46
  "prettier-plugin-svelte": "3.2.6",
45
47
  "prettier-plugin-tailwindcss": "0.6.6",