Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose cli entrance #1237

Merged
merged 1 commit into from
Dec 4, 2022
Merged

feat: expose cli entrance #1237

merged 1 commit into from
Dec 4, 2022

Conversation

zanminkian
Copy link
Contributor

Expose cli entrance will be convenient for developers who want to integrate lint-stage cli.

@iiroj
Copy link
Member

iiroj commented Dec 4, 2022

Hello, can you give an example on what can be done with this?

@codecov
Copy link

codecov bot commented Dec 4, 2022

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (b4048c4) compared to base (a987e6a).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1237   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines          735       735           
  Branches       198       198           
=========================================
  Hits           735       735           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@zanminkian
Copy link
Contributor Author

Hi. I have a convenient cli tool that integrates lint-staged, commitlint and husky. By setting up postinstall, this tools can init all the things in zero configs. commitlint is easy to integrate because it don't have exports field in its package.json. But lint-staged have this limitation. I have to write a function getLintStagedCliPath in my tool, which is not elegant.

import { existsSync } from 'fs'
import { join } from 'path'

export function getLintStagedCliPath(from: string, paths = ['.']): string {
  if (!from.startsWith('/'))
    throw new Error('First param `from` must be absolute path')

  const dirAbsolutePath = join(from, ...paths)
  const filePath = 'node_modules/lint-staged/bin/lint-staged.js'
  const isExisting = existsSync(join(dirAbsolutePath, filePath))
  if (isExisting) {
    const result = join(...paths, filePath)
    return result.startsWith('.') ? result : `./${result}`
  }
  if (dirAbsolutePath === '/')
    throw new Error('`lint-staged` cli file not found!')

  return getLintStagedCliPath(from, [...paths, '..'])
}

package.json Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants