-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
41 lines (36 loc) · 1.43 KB
/
Copy pathdeploy.js
File metadata and controls
41 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
import { execSync } from 'child_process'
import { cpSync, rmSync, existsSync, mkdirSync } from 'fs'
import path from 'path'
import os from 'os'
const url = process.env.VITE_UIBUILDER_URL || 'can-monitor'
const CONFIG = {
localTarget:
process.env.DEPLOY_TARGET_PATH ??
path.join(os.homedir(), '.node-red', 'uibuilder', url, 'dist'),
scp: {
user: process.env.DEPLOY_SCP_USER ?? 'pi',
host: process.env.DEPLOY_SCP_HOST ?? '192.168.1.100',
remotePath: process.env.DEPLOY_SCP_PATH ?? `/home/pi/.node-red/uibuilder/${url}/dist`,
},
}
const usesScp = process.argv.includes('--scp')
const distDir = path.resolve('dist')
console.log('\nBuilding dashboard...')
execSync('npm run build', { stdio: 'inherit' })
console.log('Build complete')
if (usesScp) {
const { user, host, remotePath } = CONFIG.scp
console.log(`\nDeploying via SCP to ${user}@${host}:${remotePath}`)
execSync(`ssh ${user}@${host} "mkdir -p ${remotePath}"`, { stdio: 'inherit' })
execSync(`scp -r "${distDir}/." "${user}@${host}:${remotePath}"`, { stdio: 'inherit' })
console.log(`Done: http://${host}:1880/${url}`)
} else {
console.log(`\nDeploying locally to ${CONFIG.localTarget}`)
if (!existsSync(CONFIG.localTarget)) {
mkdirSync(CONFIG.localTarget, { recursive: true })
}
rmSync(CONFIG.localTarget, { recursive: true, force: true })
cpSync(distDir, CONFIG.localTarget, { recursive: true })
console.log('Local deploy complete')
}