-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e945a7
commit 0dc26c0
Showing
5 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ Pipfile.lock | |
tests/__pycache__/ | ||
testing/__pycache__/ | ||
pre_commit_hooks/__pycache__/ | ||
|
||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@turo:registry=https://turo.jfrog.io/turo/api/npm/npm/ | ||
//turo.jfrog.io/turo/api/npm/npm/:_auth="${NPM_AUTH_TOKEN}" | ||
//turo.jfrog.io/turo/api/npm/npm/:always-auth=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env node | ||
|
||
import { execSync } from 'child_process'; | ||
import fs from 'fs'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
|
||
// Function to get the installed version of a package | ||
function getInstalledVersion(packageName, dir) { | ||
try { | ||
const packageJsonPath = path.join(dir, 'node_modules', packageName, 'package.json'); | ||
if (fs.existsSync(packageJsonPath)) { | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); | ||
return packageJson.version; | ||
} | ||
} catch (error) { | ||
return null; | ||
} | ||
} | ||
|
||
// Function to get the latest version of a package from npm | ||
function getLatestVersion(packageName) { | ||
try { | ||
const result = execSync(`npm show ${packageName} version`, { encoding: 'utf8' }); | ||
return result.trim(); | ||
} catch (error) { | ||
return null; | ||
} | ||
} | ||
|
||
// Get or create the fixed directory | ||
const fixedDir = path.join(os.homedir(), '.cspell-local-dir'); | ||
const packageName = '@turo/cspell'; | ||
|
||
try { | ||
const installedVersion = getInstalledVersion(packageName, fixedDir); | ||
const latestVersion = getLatestVersion(packageName); | ||
|
||
if (!installedVersion || installedVersion !== latestVersion) { | ||
// Install the desired dependency in the fixed directory | ||
execSync(`npm install --prefix ${fixedDir} ${packageName} --no-package-lock --prefer-online`); | ||
} | ||
} catch (error) { | ||
console.error(`Failed to install or use ${packageName}:`, error); | ||
process.exit(1); | ||
} | ||
|
||
import "cspell/bin"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"author": "Turo engineering <[email protected]>", | ||
"bin": { | ||
"cspell-cli": "./hooks/cspell/index.js" | ||
}, | ||
"dependencies": { | ||
"cspell": "8.10.0" | ||
}, | ||
"homepage": "https://github.com/turo/pre-commit-hooks#readme", | ||
"name": "@turo/pre-commit-hooks", | ||
"private": true, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/turo/pre-commit-hooks.git" | ||
}, | ||
"type": "module", | ||
"version": "4.0.0" | ||
} |