Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
traviskuhl committed Oct 24, 2024
1 parent aa6ce3f commit 824d0fd
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 123 deletions.
23 changes: 18 additions & 5 deletions bin/ffr.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
console.log("poop");

import { parseArgs } from "jsr:@std/cli/parse-args";

import { main } from "../src/cli/ffr/main.ts";

let VERSION = "0.0.0";

try {
const versionFile = "./version.ts";
const v = await import(versionFile) as {
default: {
version: string;
};
};
VERSION = v.default.version;
} catch (_) {
// do nothing and assume we're not in the compiled version
}

const {
_,
cwd,
["remote-url"]: remoteUrl,
verbose,
version,
} = parseArgs(
Deno.args,
{
Expand All @@ -17,14 +29,15 @@ const {
r: "report",
c: "cwd",
},
boolean: ["verbose"],
boolean: ["verbose", "version"],
},
);

await main({
await main(VERSION, {
_,
raw: Deno.args,
cwd,
verbose,
version,
remoteUrl,
});
200 changes: 120 additions & 80 deletions build/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,128 @@ import { format, increment, parse } from "jsr:@std/semver";

const __dirname = new URL(".", import.meta.url).pathname;

async function compile(src: string, dest: string) {
console.log(`Compiling ${src} to ${dest}`);

const cmd = new Deno.Command(Deno.execPath(), {
cwd: join(__dirname, "../"),
args: [
"compile",
"-A",
"--unstable-worker-options",
"--include",
join(__dirname, "../src/libs/expression/worker.ts"),
"--output",
dest,
src,
],
stderr: "inherit",
stdout: "inherit",
});

const result = await cmd.output();

console.log(` > Compile Exit Code: ${result.code}`);

if (result.code !== 0) {
return;
}

const zip = new Deno.Command(Deno.execPath(), {
cwd: join(__dirname, "../dist"),
args: [
"zip",
`${basename(dest)}.zip`,
basename(dest),
],
stderr: "inherit",
stdout: "inherit",
});
const appleDeveloperId = Deno.env.get("APPLE_DEVELOPER_ID");
const currentVersion =
await (await fetch("https://elwood.run/ffremote/release/latest.txt")).text();
const nextVersion = format(increment(parse(currentVersion), "patch"));

const zipResult = await cmd.output();
const dist = join(__dirname, "../dist");
const versionFile = join(__dirname, "../bin/version.ts");

try {
// clean out our dist folder
// we don't want to leave any old files around
// that will get pushed with the release
await Deno.remove(dist, { recursive: true });
await Deno.mkdir(
dist,
{ recursive: true },
);

// write out our new version file
// this will be included in the compiled binaries
await Deno.writeTextFile(
versionFile,
`export default { version: "${nextVersion}" };\n`,
);

// generate builds for `elwood-run` and `ffr`
await Promise.all([
compile(
join(__dirname, "../bin/cli.ts"),
join(dist, "elwood-run"),
),
compile(
join(__dirname, "../bin/ffr.ts"),
join(dist, "ffr"),
),
]);
} catch (err) {
console.log(`%c${(err as Error).message}`, "color:red");
Deno.exit(1);
} finally {
// remove the version file
await Deno.remove(versionFile);
}

console.log(` > Zip Exit Code: ${zipResult.code}`);
async function compile(src: string, dest: string) {
console.log(`Compiling ${src} to ${dest}`);

if (zipResult.code !== 0) {
return;
const targets = [
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"aarch64-unknown-linux-gnu",
];

for (const target of targets) {
const cmd = new Deno.Command(Deno.execPath(), {
cwd: join(__dirname, "../"),
args: [
"compile",
"-A",
"--unstable-worker-options",
"--include",
join(__dirname, "../src/libs/expression/worker.ts"),
"--include",
versionFile,
"--target",
target,
"--output",
dest,
src,
],
stderr: "inherit",
stdout: "inherit",
});

const result = await cmd.output();

console.log(` > Compile Exit Code: ${result.code}`);

if (result.code !== 0) {
return;
}

if (target.includes("darwin") && appleDeveloperId) {
const sign = new Deno.Command("codesign", {
cwd: dist,
args: [
"-s",
appleDeveloperId,
basename(dest),
],
stderr: "inherit",
stdout: "inherit",
});

const result = await sign.output();

console.log(` > Sign Exit Code: ${result.code}`);

if (result.code !== 0) {
return;
}
}

const zip = new Deno.Command("zip", {
cwd: join(__dirname, "../dist"),
args: [
`${basename(dest)}-${target}.zip`,
basename(dest),
],
stderr: "inherit",
stdout: "inherit",
});

const zipResult = await zip.output();

console.log(` > Zip Exit Code: ${zipResult.code}`);

if (zipResult.code !== 0) {
return;
}

await Deno.remove(dest);
}

// // output
// const output = await Deno.open(`${dest}.zip`, {
// create: true,
// write: true,
// read: true,
// });

// const source = await Deno.open(dest, { read: true });

// const zipWriter = new zip.ZipWriter(output.writable);
// await zipWriter.add(basename(dest), source.readable);
// await zipWriter.close();

await Deno.remove(dest);
}

const dest = join(__dirname, "../dist");

await Deno.mkdir(
dest,
{ recursive: true },
);

await Promise.all([
compile(
join(__dirname, "../bin/cli.ts"),
join(dest, "elwood-run"),
),
compile(
join(__dirname, "../bin/ffr.ts"),
join(dest, "ffr"),
),
]);

const currentVersion =
await (await fetch("https://elwood.run/ffremote/release/latest.txt")).text();
const nextVersion = format(increment(parse(currentVersion), "patch"));

console.log(`new_version=${nextVersion}`);
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test": "deno test -A --unstable-worker-options ./**/*.test.ts",
"compile": "deno compile -A --unstable-worker-options --include ./src/libs/expression/worker.ts -o ./dist/elwood-run ./src/launch.ts",
"build-image": "packer build build/run.pkr.hcl",
"build-cli": "deno run -A ./build/bin.ts",
"build-cli": "deno run --env-file=./.env -A ./build/bin.ts",
"generate-schemas": "deno run --allow-read --allow-write ./schema/generate.ts",
"cli": "deno run -A --unstable-worker-options ./bin/cli.ts",
"ffr": "deno run -A --unstable-worker-options ./bin/ffr.ts"
Expand Down
8 changes: 4 additions & 4 deletions install-ffr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
set -e

if ! command -v unzip >/dev/null && ! command -v 7z >/dev/null; then
echo "Error: either unzip or 7z is required to install FFr (see: https://github.com/denoland/ffr_install#either-unzip-or-7z-is-required )." 1>&2
echo "Error: either unzip or 7z is required to install FFremote." 1>&2
exit 1
fi

Expand Down Expand Up @@ -39,7 +39,7 @@ for arg in "$@"; do
"--help")
print_help_and_exit
;;
"-"*) ;;
"-"*) ;;w
*)
if [ -z "$ffr_version" ]; then
ffr_version="$arg"
Expand All @@ -49,10 +49,10 @@ for arg in "$@"; do
done

if [ -z "$ffr_version" ]; then
ffr_version="$(curl -s https://elwood.run/ffr/release/latest.txt)"
ffr_version="$(curl -s https://elwood.run/ffremote/release/latest.txt)"
fi

ffr_uri="https://elwood.run/ffr/release/${ffr_version}.zip"
ffr_uri="https://elwood.run/ffremote/release/${target}@${ffr_version}.zip"
ffr_install="${FFR_INSTALL:-$HOME/.elwood/run}"
bin_dir="$ffr_install/bin"
exe="$bin_dir/ffr"
Expand Down
12 changes: 9 additions & 3 deletions src/cli/ffr/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ import watch from "./watch.ts";
import auth from "./auth.ts";
import { printError } from "../lib.ts";

export async function main(args: FFrArgs) {
export async function main(compiledVersion: string, args: FFrArgs) {
if (args.version) {
console.log(`ffremote ${compiledVersion}`);
Deno.exit(0);
}

if (args.raw.length === 0) {
[
"",
"./ffr - FFremote: The Remote FFmpeg Runner",
`ffremote (${compiledVersion}) - FFremote: The Remote FFmpeg Runner`,
"",
"Usage:",
" ffr --size=<size> <...ffmpeg-args>",
" ffr <...ffmpeg-args>",
" ffr --size=<size> --include=<file> -- <...ffmpeg-args>",
" ffr get <id>",
" ffr watch <id>",
" ffr status <id>",
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export type CliArgs = {
verbose?: boolean;
reportFile?: string;
remoteUrl?: string;
version?: boolean;
};

export type FFrArgs = Omit<
Expand Down
20 changes: 20 additions & 0 deletions www/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ const nextConfig = {
source: '/ffr/:slug',
destination: '/ffremote/:slug',
permanent: true
},
{
source: '/ffr/docs/:slug',
destination: '/docs/ffremote/:slug',
permanent: true
},
{
source: '/ffr/docs',
destination: '/docs/ffremote',
permanent: true
},
{
source: '/ffremote/docs/:slug',
destination: '/docs/ffremote/:slug',
permanent: true
},
{
source: '/ffremote/docs',
destination: '/docs/ffremote',
permanent: true
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion www/src/app/docs/ffremote/pricing/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {useMDXComponents} from '../../../../mdx-components';
import Content from './content.mdx';

export default async function Page() {
const apiUrl = process.env.API_URL ?? 'https://api.elwood.run';
const apiUrl = 'https://api.elwood.run';
const response = await fetch(`${apiUrl}/billing/prices`, {
next: {revalidate: 60},
});
Expand Down
12 changes: 0 additions & 12 deletions www/src/app/ffremote/docs/[...slug]/route.ts

This file was deleted.

5 changes: 0 additions & 5 deletions www/src/app/ffremote/docs/route.ts

This file was deleted.

Loading

0 comments on commit 824d0fd

Please sign in to comment.