@coko/lint 3.0.0-alpha.16 → 3.0.0-alpha.18

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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [3.0.0-alpha.18](https://gitlab.coko.foundation/cokoapps/lint/compare/v3.0.0-alpha.17...v3.0.0-alpha.18) (2026-01-20)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * fix commit command ([9934d20](https://gitlab.coko.foundation/cokoapps/lint/commit/9934d2075bfea115265400df4d6be864f1f8eed8))
11
+
12
+ ## [3.0.0-alpha.17](https://gitlab.coko.foundation/cokoapps/lint/compare/v3.0.0-alpha.16...v3.0.0-alpha.17) (2026-01-20)
13
+
14
+
15
+ ### Features
16
+
17
+ * add lint-staged and commit commands ([dcff789](https://gitlab.coko.foundation/cokoapps/lint/commit/dcff78993000a4df6ef0e35f67057d5de05682d7))
18
+
5
19
  ## [3.0.0-alpha.16](https://gitlab.coko.foundation/cokoapps/lint/compare/v3.0.0-alpha.15...v3.0.0-alpha.16) (2026-01-19)
6
20
 
7
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coko/lint",
3
- "version": "3.0.0-alpha.16",
3
+ "version": "3.0.0-alpha.18",
4
4
  "description": "Linter configurations and dependencies for coko's projects",
5
5
  "keywords": [
6
6
  "lint",
@@ -24,7 +24,7 @@
24
24
  "src"
25
25
  ],
26
26
  "scripts": {
27
- "cz": "git-cz",
27
+ "commit": "./src/cli.mjs commit --skip-stylelint",
28
28
  "prepare": "husky install",
29
29
  "release": "standard-version",
30
30
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -42,6 +42,7 @@
42
42
  "@commitlint/config-conventional": "^20.3.1",
43
43
  "@eslint/js": "^9.39.2",
44
44
  "@vitest/eslint-plugin": "^1.6.6",
45
+ "chalk": "^5.6.2",
45
46
  "commander": "^14.0.2",
46
47
  "commitizen": "^4.3.1",
47
48
  "conventional-commit-types": "^3.0.0",
package/src/cli.mjs CHANGED
@@ -1,11 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- /* eslint-disable no-console, n/no-process-exit */
3
+ /* eslint-disable n/no-process-exit */
4
+
5
+ import { execSync } from 'node:child_process'
6
+ import path from 'node:path'
7
+ import { createRequire } from 'node:module'
4
8
 
5
- import { execSync } from 'child_process'
6
9
  import { program } from 'commander'
10
+ import lintStagedLib from 'lint-staged'
7
11
 
8
12
  import pkg from '../package.json' with { type: 'json' }
13
+ import logger from './logger.mjs'
14
+
15
+ const require = createRequire(import.meta.url)
16
+ const cz = require('commitizen/dist/cli/git-cz')
17
+ const czPath = require.resolve('commitizen')
9
18
 
10
19
  const ESLINT = 'ESLint'
11
20
  const STYLELINT = 'Stylelint'
@@ -14,16 +23,16 @@ const filler = '>>>> '
14
23
 
15
24
  // #region actions
16
25
  const printVersion = () => {
17
- console.log(`Coko lint version: ${program.version()}`)
26
+ logger.info(`Coko lint version: ${program.version()}\n`)
18
27
  }
19
28
 
20
29
  const runCommand = (name, command, isSubprocess) => {
21
- console.log(`\n${filler}Running ${name}...`)
30
+ logger.info(`\n${filler}Running ${name}...`)
22
31
 
23
32
  try {
24
33
  execSync(command, { stdio: 'inherit' })
25
34
  } catch (error) {
26
- console.error(`Error running ${name}: ${error.message}`)
35
+ logger.error(`Error running ${name}: ${error.message}`)
27
36
 
28
37
  if (isSubprocess) {
29
38
  throw new Error()
@@ -36,7 +45,7 @@ const runCommand = (name, command, isSubprocess) => {
36
45
  const runSubprocess = (fn, name, skip) => {
37
46
  try {
38
47
  if (skip) {
39
- console.log(`\n${filler}Skipping ${name}...`)
48
+ logger.info(`\n${filler}Skipping ${name}...`)
40
49
  return
41
50
  }
42
51
 
@@ -79,11 +88,46 @@ const runAll = (options = {}) => {
79
88
  }
80
89
 
81
90
  if (hasErrors) {
82
- console.error('\nError: Linting checks did not pass!')
91
+ logger.error('\nError: Linting checks did not pass!')
83
92
  process.exit(1)
84
93
  }
85
94
 
86
- console.log(`\nLinting checks successfully passed`)
95
+ logger.info(`\nLinting checks successfully passed`)
96
+ }
97
+
98
+ const lintStaged = async options => {
99
+ const jsArray = ['eslint']
100
+ if (!options.skipStylelint) jsArray.push('stylelint')
101
+
102
+ const success = await lintStagedLib({
103
+ cwd: process.cwd(),
104
+ config: {
105
+ '*.{js,mjs}': jsArray,
106
+ '*.{js,graphql,json,yml,md,html}': ['prettier --check'],
107
+ },
108
+ })
109
+
110
+ logger.newLine()
111
+ if (!success) throw new Error('Lint staged failed!')
112
+ logger.info('Lint staged successfully completed')
113
+ }
114
+
115
+ const commit = async options => {
116
+ execSync('git add -A', { stdio: 'inherit' })
117
+ execSync('git status', { stdio: 'inherit' })
118
+
119
+ await lintStaged(options)
120
+ logger.newLine()
121
+
122
+ // filter out
123
+ // - the 'commit' command
124
+ // - the --skip-stylelint flag
125
+ // if we don't do this, cz will pass them onto git (which will throw)
126
+ process.argv = process.argv.slice(0, 2)
127
+
128
+ cz.bootstrap({
129
+ cliPath: path.join(czPath, '..', '..'),
130
+ })
87
131
  }
88
132
  // #endregion actions
89
133
 
@@ -127,4 +171,30 @@ program
127
171
  runAll(options)
128
172
  })
129
173
 
174
+ program
175
+ .command('lint-staged')
176
+ .description('Lint staged files')
177
+ .option('--skip-stylelint', 'Skip stylelint')
178
+ .action(async options => {
179
+ try {
180
+ printVersion()
181
+ await lintStaged(options)
182
+ } catch (e) {
183
+ throw new Error(e)
184
+ }
185
+ })
186
+
187
+ program
188
+ .command('commit')
189
+ .description('Launch interactive commit builder')
190
+ .option('--skip-stylelint', 'Skip stylelint')
191
+ .action(async options => {
192
+ try {
193
+ printVersion()
194
+ await commit(options)
195
+ } catch (e) {
196
+ throw new Error(e)
197
+ }
198
+ })
199
+
130
200
  program.parse(process.argv)
package/src/logger.mjs ADDED
@@ -0,0 +1,21 @@
1
+ /* eslint-disable no-console */
2
+
3
+ import chalk from 'chalk'
4
+
5
+ const pre = chalk.cyan.underline('[coko lint]')
6
+ const primary = chalk.cyan
7
+ const error = chalk.red
8
+
9
+ const logger = {
10
+ error: str => {
11
+ console.log(error(`${pre} ${str}`))
12
+ },
13
+ info: str => {
14
+ console.log(primary(`${pre} ${str}`))
15
+ },
16
+ newLine: () => {
17
+ console.log('')
18
+ },
19
+ }
20
+
21
+ export default logger