Skip to content

Commit

Permalink
feature: Add install command to 'lefthook' npm package (#310)
Browse files Browse the repository at this point in the history
* feature: Add install script to lefthook NPM package

Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com>

* fix: Require path in install.js

Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com>

* fix: Print error too

Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com>
  • Loading branch information
mrexox authored Aug 8, 2022
1 parent 3b176a9 commit 5a19619
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 6 deletions.
21 changes: 21 additions & 0 deletions packaging/npm/lefthook-darwin-arm64/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require("path")
const { spawnSync } = require("child_process")

function install() {
if (process.env.CI) {
return
}

const lefthook = path.join(__dirname, "bin", "lefthook")

spawnSync(lefthook, ["install", "-f"], {
cwd: process.env.INIT_CWD || process.cwd(),
stdio: "inherit",
})
}

try {
install()
} catch(e) {
console.warn("'lefthook install' command failed. Try running it manually.\n" + e)
}
5 changes: 4 additions & 1 deletion packaging/npm/lefthook-darwin-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
],
"cpu": [
"arm64"
]
],
"scripts": {
"install": "node install.js"
}
}
21 changes: 21 additions & 0 deletions packaging/npm/lefthook-darwin-x64/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require("path")
const { spawnSync } = require("child_process")

function install() {
if (process.env.CI) {
return
}

const lefthook = path.join(__dirname, "bin", "lefthook")

spawnSync(lefthook, ["install", "-f"], {
cwd: process.env.INIT_CWD || process.cwd(),
stdio: "inherit",
})
}

try {
install()
} catch(e) {
console.warn("'lefthook install' command failed. Try running it manually.\n" + e)
}
5 changes: 4 additions & 1 deletion packaging/npm/lefthook-darwin-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
],
"cpu": [
"x64"
]
],
"scripts": {
"install": "node install.js"
}
}
21 changes: 21 additions & 0 deletions packaging/npm/lefthook-linux-arm64/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require("path")
const { spawnSync } = require("child_process")

function install() {
if (process.env.CI) {
return
}

const lefthook = path.join(__dirname, "bin", "lefthook")

spawnSync(lefthook, ["install", "-f"], {
cwd: process.env.INIT_CWD || process.cwd(),
stdio: "inherit",
})
}

try {
install()
} catch(e) {
console.warn("'lefthook install' command failed. Try running it manually.\n" + e)
}
5 changes: 4 additions & 1 deletion packaging/npm/lefthook-linux-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
],
"cpu": [
"arm64"
]
],
"scripts": {
"install": "node install.js"
}
}
21 changes: 21 additions & 0 deletions packaging/npm/lefthook-linux-x64/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require("path")
const { spawnSync } = require("child_process")

function install() {
if (process.env.CI) {
return
}

const lefthook = path.join(__dirname, "bin", "lefthook")

spawnSync(lefthook, ["install", "-f"], {
cwd: process.env.INIT_CWD || process.cwd(),
stdio: "inherit",
})
}

try {
install()
} catch(e) {
console.warn("'lefthook install' command failed. Try running it manually.\n" + e)
}
5 changes: 4 additions & 1 deletion packaging/npm/lefthook-linux-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
],
"cpu": [
"x64"
]
],
"scripts": {
"install": "node install.js"
}
}
21 changes: 21 additions & 0 deletions packaging/npm/lefthook-windows-arm64/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require("path")
const { spawnSync } = require("child_process")

function install() {
if (process.env.CI) {
return
}

const lefthook = path.join(__dirname, "bin", "lefthook.exe")

spawnSync(lefthook, ["install", "-f"], {
cwd: process.env.INIT_CWD || process.cwd(),
stdio: "inherit",
})
}

try {
install()
} catch(e) {
console.warn("'lefthook install' command failed. Try running it manually.\n" + e)
}
5 changes: 4 additions & 1 deletion packaging/npm/lefthook-windows-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
],
"cpu": [
"arm64"
]
],
"scripts": {
"install": "node install.js"
}
}
21 changes: 21 additions & 0 deletions packaging/npm/lefthook-windows-x64/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require("path")
const { spawnSync } = require("child_process")

function install() {
if (process.env.CI) {
return
}

const lefthook = path.join(__dirname, "bin", "lefthook.exe")

spawnSync(lefthook, ["install", "-f"], {
cwd: process.env.INIT_CWD || process.cwd(),
stdio: "inherit",
})
}

try {
install()
} catch(e) {
console.warn("'lefthook install' command failed. Try running it manually.\n" + e)
}
5 changes: 4 additions & 1 deletion packaging/npm/lefthook-windows-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
],
"cpu": [
"x64"
]
],
"scripts": {
"install": "node install.js"
}
}

0 comments on commit 5a19619

Please sign in to comment.