diff --git a/.github/release.yaml b/.github/release.yaml new file mode 100644 index 0000000..2898cc8 --- /dev/null +++ b/.github/release.yaml @@ -0,0 +1,31 @@ +changelog: + categories: + - title: 🏕 Features + labels: + - '*' + exclude: + labels: + - dependencies + - title: 👒 Dependencies + labels: + - dependencies + +# changelog: +# exclude: +# labels: +# - ignore-for-release +# authors: +# - octocat +# categories: +# - title: Breaking Changes 🛠 +# labels: +# - Semver-Major +# - breaking-change +# - title: Exciting New Features 🎉 +# labels: +# - Semver-Minor +# - enhancement +# - title: Other Changes +# labels: +# - "*" +# diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml new file mode 100644 index 0000000..f01a35c --- /dev/null +++ b/.github/workflows/cd.yaml @@ -0,0 +1,6 @@ +name: "Continuous Deployment" + +on: + push: + tags: + - 'v*.*.*' diff --git a/bin/build.rs b/bin/build.rs index f0bdb7f..1cfb834 100644 --- a/bin/build.rs +++ b/bin/build.rs @@ -12,11 +12,12 @@ pub fn main() -> anyhow::Result<()> { let config = specta::ts::ExportConfiguration::new() .bigint(specta::ts::BigIntExportBehavior::Number); - #[rustfmt::skip] - let mut file = File::create( - Path::new(&std::env::var("OUT_DIR").unwrap()) - .join("../../../../../lib/generated/rustTypes.d.ts"), - )?; + // The directory of the binary crate + let crate_dir = std::env::var("CARGO_MANIFEST_DIR")?; + + let out = Path::new(&crate_dir).join("../lib/generated/rustTypes.d.ts"); + + let mut file = File::create(Path::new(&out))?; let contents = [ "/* THIS FILE HAS BEEN AUTOMATICALLY GENERATED AND CONTAINS TYPES THAT CORESPOND WITH THE RUST BINARY */\n".to_owned(), diff --git a/lib/.npmignore b/lib/.npmignore new file mode 100644 index 0000000..62bb78f --- /dev/null +++ b/lib/.npmignore @@ -0,0 +1,7 @@ +src +node_modules +.gitignore +.npmignore +.npmrc +download +dist/tsconfig.tsbuildinfo diff --git a/lib/bin/index.ts b/lib/bin/index.ts new file mode 100644 index 0000000..f9e95ba --- /dev/null +++ b/lib/bin/index.ts @@ -0,0 +1,41 @@ +#! /usr/bin/env node + +import { spawnSync } from "child_process"; + +/** + * Returns the executable path which is located inside `node_modules` + * The naming convention is app-${os}-${arch} + * If the platform is `win32` or `cygwin`, executable will include a `.exe` extension. + * @see https://nodejs.org/api/os.html#osarch + * @see https://nodejs.org/api/os.html#osplatform + * @example "x/xx/node_modules/app-darwin-arm64" + */ +function getExePath() { + const arch = process.arch; + let os = process.platform as string; + let extension = ""; + if (["win32", "cygwin"].includes(process.platform)) { + os = "windows"; + extension = ".exe"; + } + + try { + // Since the binary will be located inside `node_modules`, we can simply call `require.resolve` + return require.resolve(`@next-typed-routes/bin-${os}-${arch}/bin/app${extension}`); + } catch (e) { + throw new Error( + `Couldn't find application binary inside node_modules for ${os}-${arch}` + ); + } +} + +/** + * Runs the application with args using nodejs spawn + */ +function run() { + const args = process.argv.slice(2); + const processResult = spawnSync(getExePath(), args, { stdio: "inherit" }); + process.exit(processResult.status ?? 0); +} + +run(); diff --git a/lib/package.json b/lib/package.json index 2410b0f..e8b92c6 100644 --- a/lib/package.json +++ b/lib/package.json @@ -26,5 +26,7 @@ }, "peerDependencies": { "next": "^13.4.13" + }, + "optionalDependencies": { } } diff --git a/lib/tsconfig.json b/lib/tsconfig.json index 03dc8e5..c2c2172 100644 --- a/lib/tsconfig.json +++ b/lib/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "outDir": "dist", "target": "ESNext", "lib": [ "dom", @@ -27,6 +28,7 @@ "../playground/generated/routes.ts" ], "exclude": [ - "node_modules" + "node_modules", + "dist" ] } diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..70ca9f2 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,12 @@ +[toolchain] +channel = "nightly" +# components = [ "rustfmt", "rustc-dev" ] +targets = [ + "x86_64-unknown-linux-gnu", + # "aarch64-unknown-linux-gnu", + # "x86_64-pc-windows-msvc" + # "aarch64-pc-windows-msvc" + "x86_64-apple-darwin" + # "aarch64-apple-darwin" +] +