-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roy Razon
committed
Jan 14, 2024
1 parent
d9a32fa
commit 6436b12
Showing
3 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/dist | ||
node_modules | ||
node_modules | ||
/scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import os from 'os' | ||
|
||
const distDir = 'dist' | ||
const matrix = { | ||
darwin: ['x64', 'arm64'], | ||
linux: ['x64', 'arm64'], | ||
} | ||
|
||
const url = ({ os, arch, version }) => `https://github.com/livecycle/preevy/releases/download/v${version}/preevy-v${version}-${os}-${arch}.tar.gz` | ||
|
||
const template = ctx => `# This file is automatically generated by https://github.com/livecycle/preevy/blob/main/packages/cli/scripts/homebrew.js | ||
# Do not update this file directly; Please update the template instead | ||
class Preevy < Formula | ||
desc "Quickly deploy preview environments to your cloud provider or Kubernetes cluster" | ||
homepage "https://preevy.dev" | ||
url "${ ctx.darwin.x64.url }" | ||
sha256 "${ ctx.darwin.x64.sha }" | ||
license "Apache-2.0" | ||
version "${ ctx.version }" | ||
on_macos do | ||
on_arm do | ||
url "${ ctx.darwin.arm64.url }" | ||
sha256 "${ ctx.darwin.arm64.sha }" | ||
end | ||
end | ||
on_linux do | ||
url "${ ctx.linux.x64.url }" | ||
sha256 "${ ctx.linux.x64.sha }" | ||
on_arm do | ||
url "${ ctx.linux.arm64.url }" | ||
sha256 "${ ctx.linux.arm64.sha }" | ||
end | ||
end | ||
def install | ||
inreplace "bin/preevy", /^CLIENT_HOME=/, "export PREEVY_OCLIF_CLIENT_HOME=#{lib/"client"}\nCLIENT_HOME=" | ||
libexec.install Dir["*"] | ||
bin.install_symlink libexec/"bin/preevy" | ||
end | ||
test do | ||
system bin/"preevy", "version" | ||
end | ||
end | ||
` | ||
|
||
const manifestFiles = fs.readdirSync(distDir) | ||
.filter(file => file.endsWith('-buildmanifest')) | ||
.map(file => path.join(distDir, file)) | ||
|
||
const manifestFilename = ({ os, arch }) => manifestFiles.find(file => file.includes(`-${os}-${arch}-`)) | ||
|
||
const readManifest = ({ os, arch }) => { | ||
const filename = manifestFilename({ os, arch }) | ||
if (!filename) { | ||
throw new Error(`Missing ${os} ${arch} build manifest`) | ||
} | ||
const manifest = JSON.parse(fs.readFileSync(filename, 'utf8')) | ||
const requiredProp = (prop) => { | ||
if (!manifest[prop]) { | ||
throw new Error(`Missing ${prop} in manifest: ${filename}`) | ||
} | ||
return manifest[prop] | ||
} | ||
return { sha: requiredProp('sha256gz'), version: requiredProp('version') } | ||
} | ||
|
||
const main = async () => { | ||
const context = {} | ||
Object.entries(matrix).forEach(([os, archs]) => { | ||
context[os] = context[os] ?? {} | ||
archs.forEach(arch => { | ||
const { sha, version } = readManifest({ os, arch }) | ||
context.version = version | ||
context[os][arch] = { | ||
sha, | ||
url: url({ os, arch, version }) | ||
} | ||
}) | ||
}) | ||
|
||
process.stdout.write(template(context)) | ||
process.stdout.write(os.EOL) | ||
} | ||
|
||
main().catch(err => { | ||
console.error(err) | ||
process.exit(1) | ||
}) | ||
|
||
|