feat: simplify installation with custom Node.js script
This commit is contained in:
+1
-1
@@ -82,7 +82,7 @@ LEON_AFTER_SPEECH=false
|
||||
|
||||
# Enable/disable skills to be available over HTTP
|
||||
LEON_OVER_HTTP=true
|
||||
# HTTP API key (use "npm run generate:http-api-key" to regenerate one)
|
||||
# HTTP API key (use "pnpm run generate:http-api-key" to regenerate one)
|
||||
LEON_HTTP_API_KEY=
|
||||
# Language used for the HTTP API
|
||||
LEON_HTTP_API_LANG=en-US
|
||||
|
||||
+1
-8
@@ -1,8 +1 @@
|
||||
if ! [ -x "$(command -v npm)" ]; then
|
||||
echo "npm: command not found"
|
||||
echo "If you use a version manager tool such as nvm and a git GUI such as GitKraken, please read: https://typicode.github.io/husky/how-to.html#node-version-managers-and-guis" >&2
|
||||
exit 1
|
||||
else
|
||||
npx tsx scripts/commit-msg.js
|
||||
fi
|
||||
|
||||
tsx scripts/commit-msg.js
|
||||
|
||||
+1
-7
@@ -1,7 +1 @@
|
||||
if ! [ -x "$(command -v npm)" ]; then
|
||||
echo "npm: command not found"
|
||||
echo "If you use a version manager tool such as nvm and a git GUI such as GitKraken, please read: https://typicode.github.io/husky/how-to.html#node-version-managers-and-guis" >&2
|
||||
exit 1
|
||||
else
|
||||
npm run pre-commit
|
||||
fi
|
||||
lint-staged
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"*": ["npm run lint"]
|
||||
"*": ["pnpm run lint"]
|
||||
}
|
||||
|
||||
@@ -164,11 +164,10 @@ git clone https://github.com/leon-ai/leon.git
|
||||
# Go to the project root
|
||||
cd leon
|
||||
|
||||
# Install pnpm
|
||||
npm install --global pnpm@latest
|
||||
# Install
|
||||
node install.mjs
|
||||
|
||||
# Install dependencies and run Leon
|
||||
pnpm install
|
||||
# Run Leon
|
||||
pnpm start
|
||||
```
|
||||
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
import { spawn, spawnSync } from 'node:child_process'
|
||||
|
||||
const isWindows = process.platform === 'win32'
|
||||
const npmCommand = isWindows ? 'npm.cmd' : 'npm'
|
||||
const pnpmCommand = isWindows ? 'pnpm.cmd' : 'pnpm'
|
||||
const voltaCommand = isWindows ? 'volta.cmd' : 'volta'
|
||||
|
||||
function exitWithError(message) {
|
||||
console.error(`\x1b[31m✖ ${message}\x1b[0m`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
function getNodeMajorVersion() {
|
||||
const [majorVersion] = process.versions.node.split('.')
|
||||
|
||||
return Number.parseInt(majorVersion, 10)
|
||||
}
|
||||
|
||||
function getCommandOutput(command, args) {
|
||||
const result = spawnSync(command, args, {
|
||||
encoding: 'utf8',
|
||||
stdio: ['ignore', 'pipe', 'pipe']
|
||||
})
|
||||
|
||||
if (result.error || result.status !== 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
return result.stdout.trim()
|
||||
}
|
||||
|
||||
async function runCommand(command, args) {
|
||||
await new Promise((resolve, reject) => {
|
||||
const child = spawn(command, args, {
|
||||
stdio: 'inherit'
|
||||
})
|
||||
|
||||
child.on('error', reject)
|
||||
child.on('exit', (code, signal) => {
|
||||
if (signal) {
|
||||
reject(new Error(`Command interrupted by ${signal}`))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (code === 0) {
|
||||
resolve()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
reject(new Error(`${command} exited with code ${code}`))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (getNodeMajorVersion() < 24) {
|
||||
exitWithError(
|
||||
`I require Node.js >= 24.0.0. Detected ${process.version}.`
|
||||
)
|
||||
}
|
||||
|
||||
console.info('\x1b[36m➡ %s\x1b[0m', 'I\'m checking pnpm...')
|
||||
|
||||
const hasVolta = getCommandOutput(voltaCommand, ['--version']) !== null
|
||||
|
||||
console.info('\x1b[36m➡ %s\x1b[0m', 'I\'m installing pnpm...')
|
||||
|
||||
if (hasVolta) {
|
||||
await runCommand(voltaCommand, ['install', 'pnpm@latest'])
|
||||
} else {
|
||||
await runCommand(npmCommand, ['install', '--global', 'pnpm@latest'])
|
||||
}
|
||||
|
||||
await runCommand(pnpmCommand, ['install'])
|
||||
@@ -20,6 +20,16 @@
|
||||
"engines": {
|
||||
"node": ">=24.0.0"
|
||||
},
|
||||
"devEngines": {
|
||||
"runtime": {
|
||||
"name": "node",
|
||||
"onFail": "error"
|
||||
},
|
||||
"packageManager": {
|
||||
"name": "pnpm",
|
||||
"onFail": "error"
|
||||
}
|
||||
},
|
||||
"volta": {
|
||||
"node": "24.13.1"
|
||||
},
|
||||
|
||||
@@ -1 +1 @@
|
||||
console.info('\x1b[36m➡ %s\x1b[0m', 'Running my installation...')
|
||||
console.info('\x1b[36m➡ %s\x1b[0m', 'I\'m installing myself...')
|
||||
|
||||
Reference in New Issue
Block a user