SEO chat gippity style
This commit is contained in:
+75
-18
@@ -125,25 +125,69 @@ function executableExists(filePath) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cargoCommand() {
|
function cargoExecutableName() {
|
||||||
if (process.env.CARGO && executableExists(process.env.CARGO)) return process.env.CARGO
|
|
||||||
|
|
||||||
const homeCargo = path.join(os.homedir(), '.cargo', 'bin', process.platform === 'win32' ? 'cargo.exe' : 'cargo')
|
|
||||||
if (executableExists(homeCargo)) return homeCargo
|
|
||||||
|
|
||||||
for (const candidate of [
|
|
||||||
'/usr/local/cargo/bin/cargo',
|
|
||||||
'/usr/local/bin/cargo',
|
|
||||||
'/usr/bin/cargo',
|
|
||||||
]) {
|
|
||||||
if (executableExists(candidate)) return candidate
|
|
||||||
}
|
|
||||||
|
|
||||||
return process.platform === 'win32' ? 'cargo.exe' : 'cargo'
|
return process.platform === 'win32' ? 'cargo.exe' : 'cargo'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pathDirectories() {
|
||||||
|
const pathValue = process.env.PATH || process.env.Path || ''
|
||||||
|
return pathValue.split(path.delimiter).filter(Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
|
function cargoCandidates() {
|
||||||
|
const executableName = cargoExecutableName()
|
||||||
|
const candidates = []
|
||||||
|
|
||||||
|
if (process.env.CARGO) {
|
||||||
|
candidates.push(process.env.CARGO)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.CARGO_HOME) {
|
||||||
|
candidates.push(path.join(process.env.CARGO_HOME, 'bin', executableName))
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates.push(path.join(os.homedir(), '.cargo', 'bin', executableName))
|
||||||
|
|
||||||
|
if (process.platform !== 'win32') {
|
||||||
|
try {
|
||||||
|
for (const homeEntry of fs.readdirSync('/home', { withFileTypes: true })) {
|
||||||
|
if (homeEntry.isDirectory()) {
|
||||||
|
candidates.push(path.join('/home', homeEntry.name, '.cargo', 'bin', executableName))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Some hosts do not expose /home to this process; the fixed paths below still cover system installs.
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates.push(
|
||||||
|
'/root/.cargo/bin/cargo',
|
||||||
|
'/usr/local/cargo/bin/cargo',
|
||||||
|
'/usr/local/bin/cargo',
|
||||||
|
'/usr/bin/cargo',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const directory of pathDirectories()) {
|
||||||
|
candidates.push(path.join(directory, executableName))
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...new Set(candidates)]
|
||||||
|
}
|
||||||
|
|
||||||
|
function cargoCommand() {
|
||||||
|
for (const candidate of cargoCandidates()) {
|
||||||
|
if (executableExists(candidate)) return candidate
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
function commandFor(command) {
|
function commandFor(command) {
|
||||||
if (command === 'cargo') return cargoCommand()
|
if (command === 'cargo') {
|
||||||
|
const resolvedCommand = cargoCommand()
|
||||||
|
if (!resolvedCommand) throw new Error(commandNotFoundMessage(command))
|
||||||
|
return resolvedCommand
|
||||||
|
}
|
||||||
if (process.platform !== 'win32') return command
|
if (process.platform !== 'win32') return command
|
||||||
if (command === 'npm') return 'npm.cmd'
|
if (command === 'npm') return 'npm.cmd'
|
||||||
if (command === 'pm2') return 'pm2.cmd'
|
if (command === 'pm2') return 'pm2.cmd'
|
||||||
@@ -155,7 +199,7 @@ function commandNotFoundMessage(command) {
|
|||||||
return [
|
return [
|
||||||
'cargo was not found by the deploy webhook',
|
'cargo was not found by the deploy webhook',
|
||||||
'Install Rust on the host, or set CARGO to the absolute cargo binary path',
|
'Install Rust on the host, or set CARGO to the absolute cargo binary path',
|
||||||
`Checked PATH plus ${path.join(os.homedir(), '.cargo', 'bin', process.platform === 'win32' ? 'cargo.exe' : 'cargo')}`,
|
`Checked ${cargoCandidates().join(', ')}`,
|
||||||
].join('. ')
|
].join('. ')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +208,13 @@ function run(command, args, options = {}) {
|
|||||||
const label = [command, ...args].join(' ')
|
const label = [command, ...args].join(' ')
|
||||||
console.log(`deploy step started: ${label}`)
|
console.log(`deploy step started: ${label}`)
|
||||||
|
|
||||||
const resolvedCommand = commandFor(command)
|
let resolvedCommand
|
||||||
|
try {
|
||||||
|
resolvedCommand = commandFor(command)
|
||||||
|
} catch (error) {
|
||||||
|
reject(error)
|
||||||
|
return
|
||||||
|
}
|
||||||
const child = spawn(resolvedCommand, args, {
|
const child = spawn(resolvedCommand, args, {
|
||||||
cwd: __dirname,
|
cwd: __dirname,
|
||||||
env: { ...process.env, ...options.env },
|
env: { ...process.env, ...options.env },
|
||||||
@@ -193,7 +243,14 @@ function run(command, args, options = {}) {
|
|||||||
function runCapture(command, args, options = {}) {
|
function runCapture(command, args, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const label = [command, ...args].join(' ')
|
const label = [command, ...args].join(' ')
|
||||||
const child = spawn(commandFor(command), args, {
|
let resolvedCommand
|
||||||
|
try {
|
||||||
|
resolvedCommand = commandFor(command)
|
||||||
|
} catch (error) {
|
||||||
|
reject(error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const child = spawn(resolvedCommand, args, {
|
||||||
cwd: __dirname,
|
cwd: __dirname,
|
||||||
env: { ...process.env, ...options.env },
|
env: { ...process.env, ...options.env },
|
||||||
shell: process.platform === 'win32',
|
shell: process.platform === 'win32',
|
||||||
|
|||||||
Reference in New Issue
Block a user