2023-08-15 02:37:45 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
// @ts-check
|
|
|
|
|
2023-08-27 03:54:14 +02:00
|
|
|
const { spawn } = require('child_process')
|
2023-08-15 02:37:45 +02:00
|
|
|
|
|
|
|
;(async function () {
|
|
|
|
const target = process.argv[process.argv.length - 1]
|
|
|
|
|
2023-08-27 03:54:14 +02:00
|
|
|
let turboResult = ''
|
|
|
|
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
const child = spawn(
|
|
|
|
'/bin/bash',
|
|
|
|
['-c', `pnpm turbo run cache-build-native --dry=json -- ${target}`],
|
|
|
|
{
|
|
|
|
stdio: 'pipe',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
child.stdout.on('data', (data) => {
|
|
|
|
turboResult += data.toString()
|
|
|
|
})
|
|
|
|
|
|
|
|
child.on('exit', (code, signal) => {
|
|
|
|
if (code || signal) {
|
|
|
|
return reject(
|
|
|
|
new Error(`invalid exit code ${code} or signal ${signal}`)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
resolve(0)
|
|
|
|
})
|
|
|
|
})
|
2023-08-15 02:37:45 +02:00
|
|
|
|
|
|
|
const turboData = JSON.parse(turboResult)
|
|
|
|
|
|
|
|
const task = turboData.tasks.find((t) => t.command !== '<NONEXISTENT>')
|
|
|
|
|
|
|
|
if (!task) {
|
|
|
|
console.warn(`Failed to find related turbo task`, turboResult)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// pull cache if it was available
|
|
|
|
if (task.cache.local || task.cache.remote) {
|
2024-04-15 12:42:28 +02:00
|
|
|
console.log('Cache Status', task.taskId, task.hash, task.cache)
|
2023-08-27 03:54:14 +02:00
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
const child = spawn(
|
|
|
|
'/bin/bash',
|
|
|
|
['-c', `pnpm turbo run cache-build-native -- ${target}`],
|
|
|
|
{
|
|
|
|
stdio: 'inherit',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
child.on('exit', (code, signal) => {
|
|
|
|
if (code || signal) {
|
|
|
|
return reject(
|
|
|
|
new Error(`invalid exit code ${code} or signal ${signal}`)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
resolve(0)
|
|
|
|
})
|
|
|
|
})
|
2023-08-15 02:37:45 +02:00
|
|
|
} else {
|
|
|
|
console.warn(`No turbo cache was available, continuing...`)
|
|
|
|
console.warn(task)
|
|
|
|
}
|
|
|
|
})()
|