-
-
Notifications
You must be signed in to change notification settings - Fork 284
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
Showing
5 changed files
with
234 additions
and
40 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "carbonyl", | ||
"version": "0.0.1", | ||
"license": "BSD-3-Clause" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import fs from 'fs/promises' | ||
import path from 'path' | ||
import { fileURLToPath } from 'url' | ||
|
||
const dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
const pkg = JSON.parse(await fs.readFile(path.resolve(dirname, '../package.json'), 'utf-8')) | ||
const version = `${pkg.version}-next.${process.env.VERSION_ID}` | ||
const manifest = { | ||
version, | ||
license: 'BSD-3-Clause', | ||
description: 'Chromium running in your terminal', | ||
homepage: 'https://github.com/fathyb/carbonyl', | ||
repository: 'fathyb/carbonyl', | ||
bugs: 'https://github.com/fathyb/carbonyl/issues', | ||
author: { | ||
name: 'Fathy Boundjadj', | ||
email: '[email protected]', | ||
url: 'https://fathy.fr' | ||
} | ||
} | ||
|
||
async function buildMain() { | ||
const root = path.resolve(dirname, '../build/packages/carbonyl') | ||
|
||
await fs.rm(root, { recursive: true, force: true }) | ||
await fs.mkdir(root, { recursive: true }) | ||
await Promise.all([ | ||
Promise.all( | ||
['readme.md', 'license.md'].map(file => | ||
fs.cp(path.join(dirname, '..', file), path.join(root, file)), | ||
) | ||
), | ||
fs.writeFile( | ||
path.join(root, 'package.json'), | ||
JSON.stringify( | ||
{ | ||
name: 'carbonyl', | ||
...manifest, | ||
files: ['index.js', 'index.sh'], | ||
bin: { carbonyl: 'index.sh' }, | ||
optionalDependencies: { | ||
'@fathyb/carbonyl-linux-amd64': version, | ||
'@fathyb/carbonyl-linux-arm64': version, | ||
'@fathyb/carbonyl-macos-amd64': version, | ||
'@fathyb/carbonyl-macos-arm64': version | ||
} | ||
}, | ||
null, | ||
4 | ||
) | ||
), | ||
fs.writeFile( | ||
path.join(root, 'index.js'), | ||
` | ||
function tryModule(name) { | ||
try { | ||
return require(name) | ||
} catch { | ||
return null | ||
} | ||
} | ||
const path = ( | ||
tryModule('@fathyb/carbonyl-linux-amd64') || | ||
tryModule('@fathyb/carbonyl-linux-arm64') || | ||
tryModule('@fathyb/carbonyl-macos-amd64') || | ||
tryModule('@fathyb/carbonyl-macos-arm64') | ||
) | ||
if (path) { | ||
module.exports = path | ||
} else { | ||
throw new Error('Could not find a Carbonyl runtime installed') | ||
} | ||
` | ||
), | ||
fs.writeFile( | ||
path.join(root, 'index.sh'), | ||
[ | ||
'#!/usr/bin/env bash', | ||
`"$(node -p "require('@fathyb/carbonyl')")" "$@"` | ||
].join('\n'), | ||
{ mode: '755' } | ||
) | ||
|
||
]) | ||
|
||
return root | ||
} | ||
async function buildPlatform([os, npmOs, llvmOs], [cpu, npmCpu, llvmCpu]) { | ||
const pkg = `carbonyl-${os}-${cpu}` | ||
const root = path.resolve(dirname, `../build/packages/${pkg}`) | ||
|
||
await fs.rm(root, { recursive: true, force: true }) | ||
await fs.mkdir(root, { recursive: true }) | ||
await Promise.all([ | ||
Promise.all( | ||
['readme.md', 'license.md'].map(file => | ||
fs.cp(path.join(dirname, '..', file), path.join(root, file)), | ||
) | ||
), | ||
fs.cp( | ||
path.join(dirname, `../build/pre-built/${llvmCpu}-${llvmOs}`), | ||
path.join(root, 'build'), | ||
{ recursive: true } | ||
), | ||
fs.writeFile( | ||
path.join(root, 'package.json'), | ||
JSON.stringify( | ||
{ | ||
name: `@fathyb/${pkg}`, | ||
...manifest, | ||
files: ['build', 'index.js'], | ||
os: [npmOs], | ||
cpu: [npmCpu], | ||
}, | ||
null, | ||
4 | ||
) | ||
), | ||
fs.writeFile( | ||
path.join(root, 'index.js'), | ||
`module.exports = __dirname + '/build/carbonyl'` | ||
) | ||
]) | ||
|
||
return root | ||
} | ||
|
||
const [root, platforms] = await Promise.all([ | ||
buildMain(), | ||
|
||
Promise.all([ | ||
['macos', 'darwin', 'apple-darwin'], | ||
['linux', 'linux', 'unknown-linux-gnu'] | ||
].map(async (os) => | ||
await Promise.all( | ||
[ | ||
['arm64', 'arm64', 'aarch64'], | ||
['amd64', 'x64', 'x86_64'] | ||
].map(async (cpu) => await buildPlatform(os, cpu)) | ||
) | ||
)), | ||
]) | ||
|
||
|
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,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd)) | ||
export SKIP_DEPOT_TOOLS="true" | ||
|
||
cd "$CARBONYL_ROOT" | ||
source "scripts/env.sh" | ||
|
||
"$CARBONYL_ROOT/scripts/runtime-pull.sh" aarch64-unknown-linux-gnu | ||
"$CARBONYL_ROOT/scripts/runtime-pull.sh" x86_64-unknown-linux-gnu | ||
"$CARBONYL_ROOT/scripts/runtime-pull.sh" aarch64-apple-darwin | ||
"$CARBONYL_ROOT/scripts/runtime-pull.sh" x86_64-apple-darwin | ||
|
||
VERSION_ID="$(git rev-parse --short HEAD)" \ | ||
node "$CARBONYL_ROOT/scripts/npm-publish.mjs" | ||
|
||
cd "$CARBONYL_ROOT/build/packages" | ||
|
||
cd carbonyl-linux-amd64 | ||
yarn publish --non-interactive --access public "$@" | ||
|
||
cd ../carbonyl-linux-arm64 | ||
yarn publish --non-interactive --access public "$@" | ||
|
||
cd ../carbonyl-macos-amd64 | ||
yarn publish --non-interactive --access public "$@" | ||
|
||
cd ../carbonyl-macos-arm64 | ||
yarn publish --non-interactive --access public "$@" | ||
|
||
cd ../carbonyl | ||
yarn publish --non-interactive --access public "$@" |
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