Skip to content

Commit

Permalink
Merge pull request #290 from ordo-pink/drop-react
Browse files Browse the repository at this point in the history
Drop react in Ordo core
  • Loading branch information
orlowdev authored Nov 12, 2024
2 parents 640998e + 3fb4c25 commit ba04007
Show file tree
Hide file tree
Showing 246 changed files with 11,802 additions and 10,504 deletions.
67 changes: 52 additions & 15 deletions boot/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set -e
PLATFORM=$(uname -ms)

BUN_VERSION="1.0.30"
DENO_VERSION="2.0.0"
TAILWIND_VERSION="v3.1.6"

# --- Internal ---
Expand All @@ -20,11 +21,14 @@ function download_tailwind {
file=$dir/tailwind-$TAILWIND_VERSION

case $PLATFORM in
'Darwin arm64') curl -fLo $file "https://github.com/tailwindlabs/tailwindcss/releases/download/$TAILWIND_VERSION/tailwindcss-macos-arm64";;
'Darwin x86_64') curl -fLo $file "https://github.com/tailwindlabs/tailwindcss/releases/download/$TAILWIND_VERSION/tailwindcss-macos-x64";;
'Linux arm64' | 'Linux aarch64') curl -fLo $file "https://github.com/tailwindlabs/tailwindcss/releases/download/$TAILWIND_VERSION/tailwindcss-linux-arm64";;
'Linux x86_64') curl -fLo $file "https://github.com/tailwindlabs/tailwindcss/releases/download/$TAILWIND_VERSION/tailwindcss-linux-x64";;
*) echo "Error: Unsupported platform: $PLATFORM"; exit 1;;
'Darwin arm64') curl -fLo $file "https://github.com/tailwindlabs/tailwindcss/releases/download/$TAILWIND_VERSION/tailwindcss-macos-arm64" ;;
'Darwin x86_64') curl -fLo $file "https://github.com/tailwindlabs/tailwindcss/releases/download/$TAILWIND_VERSION/tailwindcss-macos-x64" ;;
'Linux arm64' | 'Linux aarch64') curl -fLo $file "https://github.com/tailwindlabs/tailwindcss/releases/download/$TAILWIND_VERSION/tailwindcss-linux-arm64" ;;
'Linux x86_64') curl -fLo $file "https://github.com/tailwindlabs/tailwindcss/releases/download/$TAILWIND_VERSION/tailwindcss-linux-x64" ;;
*)
echo "Error: Unsupported platform: $PLATFORM"
exit 1
;;
esac

mv $dir/tailwind-$TAILWIND_VERSION opt/tailwind
Expand All @@ -36,20 +40,22 @@ function download_tailwind {
function download_bun {
if [ ! -f ./opt/bun ]; then
if ! command -v unzip >/dev/null; then
echo "Error: unzip is required to proceed"; exit 1
echo "Error: unzip is required to proceed"
exit 1
fi

dir=$(mktemp -d)
zip=$dir/bun-$BUN_VERSION.zip



case $PLATFORM in
'Darwin arm64') NESTED_DIR="bun-darwin-aarch64";;
'Darwin x86_64') NESTED_DIR="bun-darwin-x64";;
'Linux arm64' | 'Linux aarch64') NESTED_DIR="bun-linux-x64";;
'Linux x86_64') NESTED_DIR="bun-linux-x64-baseline";;
*) echo "Error: Unsupported platform: $PLATFORM"; exit 1;;
'Darwin arm64') NESTED_DIR="bun-darwin-aarch64" ;;
'Darwin x86_64') NESTED_DIR="bun-darwin-x64" ;;
'Linux arm64' | 'Linux aarch64') NESTED_DIR="bun-linux-x64" ;;
'Linux x86_64') NESTED_DIR="bun-linux-x64-baseline" ;;
*)
echo "Error: Unsupported platform: $PLATFORM"
exit 1
;;
esac

curl -fLo "$zip" "https://github.com/oven-sh/bun/releases/download/bun-v$BUN_VERSION/$NESTED_DIR.zip"
Expand All @@ -62,6 +68,37 @@ function download_bun {
fi
}

function download_deno {
if [ ! -f ./opt/deno ]; then
if ! command -v unzip >/dev/null; then
echo "Error: unzip is required to proceed"
exit 1
fi

dir=$(mktemp -d)
zip=$dir/bun-$DENO_VERSION.zip

case $PLATFORM in
'Darwin arm64') NESTED_DIR="deno-aarch64-apple-darwin" ;;
'Darwin x86_64') NESTED_DIR="deno-x86_64-apple-darwin" ;;
'Linux arm64' | 'Linux aarch64') NESTED_DIR="deno-aarch64-unknown-linux-gnu" ;;
'Linux x86_64') NESTED_DIR="deno-x86_64-unknown-linux-gnu" ;;
*)
echo "Error: Unsupported platform: $PLATFORM"
exit 1
;;
esac

curl -fLo "$zip" "https://github.com/denoland/deno/releases/download/v$DENO_VERSION/$NESTED_DIR.zip"

unzip -o $zip -d opt &>/dev/null
mv opt/$NESTED_DIR/deno opt/deno
rm -rf opt/$NESTED_DIR
chmod +x opt/deno
rm $zip
fi
}

# Build a binary from given source with Bun and puts it to the bin directory.
function compile_init_script {
opt/bun build boot/src/init/index.ts --compile --outfile init && mv -f init bin/init
Expand Down Expand Up @@ -89,12 +126,12 @@ if [ ! -d ./bin ]; then
mkdir ./bin
fi

## Download TailwindCSS
download_tailwind

## Download Bun
download_bun

download_deno

## Install bin dependencies
opt/bun i

Expand Down
44 changes: 22 additions & 22 deletions boot/src/build/src/build.impl.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
// SPDX-FileCopyrightText: Copyright 2024, 谢尔盖||↓ and the Ordo.pink contributors
// SPDX-License-Identifier: Unlicense

import { Oath, invokers0, ops0 } from "@ordo-pink/oath"
import {
checkFilesExist0,
createProgress,
direntsToDirs,
getExistingPaths,
getNames,
runBunCommand0,
check_files_exist,
create_progress,
dirents_to_dirs,
get_dirent_names,
get_existing_paths,
run_bun_command,
} from "@ordo-pink/binutil"
import { Oath } from "@ordo-pink/oath"
import { readdir0 } from "@ordo-pink/fs"

export const compile = () =>
readdir0("./srv", { withFileTypes: true })
.map(direntsToDirs)
.map(getNames)
.map(namesToCompileScriptPaths)
.chain(checkFilesExist0)
.map(getExistingPaths)
.tap(startProgress)
.chain(runCompileScripts)
.map(finishProgress)
.orElse(console.error)
.pipe(ops0.map(dirents_to_dirs))
.pipe(ops0.map(get_dirent_names))
.pipe(ops0.map(names_to_compile_script_paths))
.pipe(ops0.chain(check_files_exist))
.pipe(ops0.map(get_existing_paths))
.pipe(ops0.tap(start_progress))
.pipe(ops0.chain(run_compile_scripts))
.pipe(ops0.map(finish_progress))
.invoke(invokers0.or_else(console.error))

// --- Internal ---

const progress = createProgress()
const progress = create_progress()

const startProgress = () => progress.start("Compiling binaries")
const start_progress = () => progress.start("Compiling binaries")
const incProgress = () => progress.inc()
const finishProgress = () => progress.finish()
const finish_progress = () => progress.finish()

const namesToCompileScriptPaths = (names: string[]) =>
const names_to_compile_script_paths = (names: string[]) =>
names.map(name => `./srv/${name}/bin/compile.ts`)
const runCompileScript = (path: string) =>
runBunCommand0(`run ${path}`, { stdout: "pipe", stderr: "pipe" }).tap(incProgress)
const runCompileScripts = (paths: string[]) => Oath.all(paths.map(runCompileScript))
run_bun_command(`run ${path}`, { stdout: "pipe", stderr: "pipe" }).pipe(ops0.tap(incProgress))
const run_compile_scripts = (paths: string[]) => Oath.Merge(paths.map(runCompileScript))
61 changes: 37 additions & 24 deletions boot/src/exec/src/impl.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
// SPDX-FileCopyrightText: Copyright 2024, 谢尔盖||↓ and the Ordo.pink contributors
// SPDX-License-Identifier: Unlicense

import { Oath } from "@ordo-pink/oath"
import { Oath, invokers0, ops0 } from "@ordo-pink/oath"
import { dir_exists0 } from "@ordo-pink/fs"
import { runAsyncCommand0 } from "@ordo-pink/binutil"
import { run_async_command } from "@ordo-pink/binutil"

export const exec = (location?: string, command?: string) =>
Oath.fromNullable(location)
.map(location => (location.startsWith("./") ? location.slice(2) : location))
.rejectedMap(() => "Location not provided")
.chain(location =>
Oath.fromBoolean(
() => location.startsWith("lib") || location.startsWith("srv"),
() => location,
() =>
`Provided location "${location}" is invalid. Only "lib/*" or "srv/*" locations are supported.`,
Oath.FromNullable(location)
.pipe(ops0.map(location => (location.startsWith("./") ? location.slice(2) : location)))
.pipe(ops0.rejected_map(() => "Location not provided"))
.pipe(
ops0.chain(location =>
Oath.If(location.startsWith("lib") || location.startsWith("srv"), {
T: () => location,
F: () =>
`Provided location "${location}" is invalid. Only "lib/*" or "srv/*" locations are supported.`,
}),
),
)
.chain(location =>
Oath.fromNullable(command)
.rejectedMap(() => "Command not provided")
.chain(command =>
dir_exists0(location).chain(exists =>
Oath.fromBoolean(
() => exists,
() => ({ location, command }),
() => `Path "${location}" does not exist`,
.pipe(
ops0.chain(location =>
Oath.FromNullable(command)
.pipe(ops0.rejected_map(() => "Command not provided"))
.pipe(
ops0.chain(command =>
dir_exists0(location).pipe(
ops0.chain(exists =>
Oath.If(exists, {
T: () => ({ location, command }),
F: () => `Path "${location}" does not exist`,
}),
),
),
),
),
),
),
)
.chain(({ location, command }) =>
runAsyncCommand0(command, { cwd: location, stdin: "pipe", stdout: "pipe", stderr: "pipe" }),
.pipe(
ops0.chain(({ location, command }) =>
run_async_command(command, {
cwd: location,
stdin: "pipe",
stdout: "pipe",
stderr: "pipe",
}),
),
)
.orElse(console.error)
.invoke(invokers0.or_else(console.error))
14 changes: 7 additions & 7 deletions boot/src/init/src/_compile-bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ type _F = Thunk<Oath<void, void>>
export const compileBin: _F = () =>
readdir0("./boot/src", { withFileTypes: true })
.tap(startCompileBinsProgress)
.map(util.direntsToDirs)
.map(util.getNames)
.map(util.dirents_to_dirs)
.map(util.get_dirent_names)
.chain(checkBinIndexFilesExist0)
.chain(runCompileBinCommands0)
.bimap(breakCompileBinsProgress, finishCompileBinsProgress)

// --- Internal ---

const _compileBinsProgress = util.createProgress()
const _compileBinsProgress = util.create_progress()
const startCompileBinsProgress = () => _compileBinsProgress.start("Compiling binaries")
const incCompileBinsProgress = _compileBinsProgress.inc
const finishCompileBinsProgress = _compileBinsProgress.finish
Expand All @@ -36,14 +36,14 @@ const namesToBinIndexPaths: Unary<string[], string[]> = map(_nameToBinIndexPath)

const checkBinIndexFilesExist0: Unary<string[], Oath<string[]>> = names =>
Oath.of(namesToBinIndexPaths(names))
.chain(util.checkFilesExist0)
.map(util.getExistingPaths)
.chain(util.check_files_exist)
.map(util.get_existing_paths)
.map(binIndexPathsToNames)

const _runCompileBinCommand0: Unary<string, Oath<void, Error>> = file =>
util
.runBunCommand0(`build boot/src/${file}/index.ts --compile --outfile ${file}`)
.chain(() => util.runCommand0(`mv -f ${file} bin/${file}`))
.run_bun_command(`build boot/src/${file}/index.ts --compile --outfile ${file}`)
.chain(() => util.run_command(`mv -f ${file} bin/${file}`))
.tap(incCompileBinsProgress)
const runCompileBinCommands0: Unary<string[], Oath<void[], Error>> = pipe(
map(_runCompileBinCommand0),
Expand Down
8 changes: 4 additions & 4 deletions boot/src/init/src/_create-symlinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ type _F = Thunk<Oath<void, void>>
export const createSymlinks: _F = () =>
readdir0("./etc/init", { withFileTypes: true })
.tap(startSymlinksProgress)
.map(util.direntsToFiles)
.map(util.getNames)
.map(util.dirents_to_files)
.map(util.get_dirent_names)
.chain(runSymlinkCommands0)
.bimap(breakSymlinksProgress, finishSymlinksProgress)

// --- Internal ---

const _symlinksProgress = util.createProgress()
const _symlinksProgress = util.create_progress()
const startSymlinksProgress = () => _symlinksProgress.start("Creating symbolic links")
const incSymlinksProgress = _symlinksProgress.inc
const finishSymlinksProgress = _symlinksProgress.finish
const breakSymlinksProgress = _symlinksProgress.break

const _runSymlinkCommand0: Unary<string, Oath<void, Error>> = file =>
util.runCommand0(`ln -snf ./etc/init/${file} ${file}`).tap(incSymlinksProgress)
util.run_command(`ln -snf ./etc/init/${file} ${file}`).tap(incSymlinksProgress)
const runSymlinkCommands0: Unary<string[], Oath<void[], Error>> = pipe(
map(_runSymlinkCommand0),
Oath.all,
Expand Down
12 changes: 6 additions & 6 deletions boot/src/init/src/_init-srv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ type _F = Thunk<Oath<void, void>>
export const initSrv: _F = () =>
readdir0("./srv", { withFileTypes: true })
.tap(startInitSrvProgress)
.map(util.direntsToDirs)
.map(util.getNames)
.map(util.dirents_to_dirs)
.map(util.get_dirent_names)
.map(dirsToInitFilePaths)
.chain(util.checkFilesExist0)
.map(util.getExistingPaths)
.chain(util.check_files_exist)
.map(util.get_existing_paths)
.chain(runInitCommands0)
.bimap(breakInitSrvProgress, finishInitSrvProgress)

// --- Internal ---

const _intSrvProgress = util.createProgress()
const _intSrvProgress = util.create_progress()
const startInitSrvProgress = () => _intSrvProgress.start("Initializing server applications")
const incInitSrvProgress = _intSrvProgress.inc
const finishInitSrvProgress = _intSrvProgress.finish
Expand All @@ -34,5 +34,5 @@ const _dirToInitFilePath: Unary<string, string> = dir => `./srv/${dir}/bin/init.
const dirsToInitFilePaths: Unary<string[], string[]> = map(_dirToInitFilePath)

const _runInitCommand0: Unary<string, Oath<void, Error>> = path =>
util.runBunCommand0(`run ${path}`).tap(incInitSrvProgress)
util.run_bun_command(`run ${path}`).tap(incInitSrvProgress)
const runInitCommands0: Unary<string[], Oath<void[], Error>> = pipe(map(_runInitCommand0), Oath.all)
6 changes: 3 additions & 3 deletions boot/src/mkbin/src/impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { expect, test } from "bun:test"
import { is_dir0, is_file0, read_file0, rmdir0 } from "@ordo-pink/fs"
import { getLicense } from "@ordo-pink/binutil"
import { get_license } from "@ordo-pink/binutil"

import { mkbin } from "./impl"

Expand All @@ -23,7 +23,7 @@ test("should license the files with Unlicense", async () => {
await mkbin("test-mkbin", "Unlicense")

const text = await read_file0("./boot/src/test-mkbin/license", "utf-8").orNothing()
expect(text).toEqual(getLicense("Unlicense"))
expect(text).toEqual(get_license("Unlicense"))

await rmdir0("./boot/src/test-mkbin", { recursive: true }).orNothing()
})
Expand All @@ -32,7 +32,7 @@ test("should license the files with AGPL-3.0-only", async () => {
await mkbin("test-mkbin", "AGPL-3.0-only")

const text = await read_file0("./boot/src/test-mkbin/license", "utf-8").orNothing()
expect(text).toEqual(getLicense("AGPL-3.0-only"))
expect(text).toEqual(get_license("AGPL-3.0-only"))

await rmdir0("./boot/src/test-mkbin", { recursive: true }).orNothing()
})
Expand Down
Loading

0 comments on commit ba04007

Please sign in to comment.