From 8bed8a185c0c33734c12009b0a3c149dd7faeba4 Mon Sep 17 00:00:00 2001 From: Caelan Sayler Date: Sun, 15 Jun 2025 23:01:57 +0100 Subject: [PATCH] Remove ts-rs and add new node handlebar template --- Cargo.lock | 25 ------ Cargo.toml | 1 - src/code-generator/Program.cs | 34 +++++--- src/code-generator/Templates/node_types.hbs | 12 +++ src/lib-nodejs/src/bindings/UpdateInfo.ts | 25 ------ src/lib-nodejs/src/bindings/UpdateOptions.ts | 28 ------- src/lib-nodejs/src/bindings/VelopackAsset.ts | 42 ---------- .../src/bindings/VelopackLocatorConfig.ts | 30 ------- src/lib-nodejs/src/index.ts | 6 +- src/lib-nodejs/src/types.ts | 82 +++++++++++++++++++ src/lib-nodejs/velopack_nodeffi/Cargo.toml | 6 +- src/lib-nodejs/velopack_nodeffi/build.rs | 12 --- src/lib-rust/Cargo.toml | 4 - src/lib-rust/src/locator.rs | 1 - src/lib-rust/src/manager.rs | 3 - 15 files changed, 120 insertions(+), 191 deletions(-) create mode 100644 src/code-generator/Templates/node_types.hbs delete mode 100644 src/lib-nodejs/src/bindings/UpdateInfo.ts delete mode 100644 src/lib-nodejs/src/bindings/UpdateOptions.ts delete mode 100644 src/lib-nodejs/src/bindings/VelopackAsset.ts delete mode 100644 src/lib-nodejs/src/bindings/VelopackLocatorConfig.ts create mode 100644 src/lib-nodejs/src/types.ts delete mode 100644 src/lib-nodejs/velopack_nodeffi/build.rs diff --git a/Cargo.lock b/Cargo.lock index a5b424a5..cf00b6f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2228,29 +2228,6 @@ version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" -[[package]] -name = "ts-rs" -version = "10.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e640d9b0964e9d39df633548591090ab92f7a4567bc31d3891af23471a3365c6" -dependencies = [ - "lazy_static", - "thiserror 2.0.12", - "ts-rs-macros", -] - -[[package]] -name = "ts-rs-macros" -version = "10.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e9d8656589772eeec2cf7a8264d9cda40fb28b9bc53118ceb9e8c07f8f38730" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.103", - "termcolor", -] - [[package]] name = "typenum" version = "1.18.0" @@ -2388,7 +2365,6 @@ dependencies = [ "tempfile", "thiserror 2.0.12", "time 0.3.41", - "ts-rs", "ureq", "url", "uuid", @@ -2476,7 +2452,6 @@ dependencies = [ "semver", "serde_json", "simplelog", - "ts-rs", "velopack", ] diff --git a/Cargo.toml b/Cargo.toml index 4432c795..72778172 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ regex = "1.10" normpath = "1.3" bitflags = "2.9" rand = "0.9" -ts-rs = "10.0" zstd = "0.13" async-std = "1.13" anyhow = "1.0" diff --git a/src/code-generator/Program.cs b/src/code-generator/Program.cs index 8c0b1245..9a473c39 100644 --- a/src/code-generator/Program.cs +++ b/src/code-generator/Program.cs @@ -55,16 +55,16 @@ var types = new List() { TypeMap.RustStruct("VelopackLocatorConfig", "vpkc_locator_config_t"), TypeMap.SystemType("String", "char", "string", "c_char"), TypeMap.SystemType("PathBuf", "char", "string", "c_char"), - TypeMap.Primitive("bool", "bool"), - TypeMap.Primitive("i32", "int32_t"), - TypeMap.Primitive("i64", "int64_t"), - TypeMap.Primitive("u32", "uint32_t"), - TypeMap.Primitive("u64", "uint64_t"), + TypeMap.Primitive("bool", "bool", "boolean"), + TypeMap.Primitive("i32", "int32_t", "number"), + TypeMap.Primitive("i64", "int64_t", "number"), + TypeMap.Primitive("u32", "uint32_t", "number"), + TypeMap.Primitive("u64", "uint64_t", "number"), }.ToDictionary(v => v.rustType, v => v); var handlebarData = availableStructs.Select(s => { var fields = s.Fields.Select(f => { - var isString = types[f.Type].rustType == "PathBuf" || types[f.Type].rustType == "String"; + //var isString = types[f.Type].rustType == "PathBuf" || types[f.Type].rustType == "String"; var field = new RustStruct_Field { rust_comment = f.DocComment.ToRustComment(), cpp_comment = f.DocComment.ToCppComment(), @@ -74,6 +74,7 @@ var handlebarData = availableStructs.Select(s => { field_rust_type = f.Type, field_c_type = types[f.Type].interopType, field_cpp_type = types[f.Type].cppType, + field_node_type = types[f.Type].nodeType, field_system = types[f.Type].system, field_primitive = types[f.Type].primitive, field_normal = !f.Vec && !types[f.Type].primitive, @@ -97,24 +98,30 @@ var handlebarData = availableStructs.Select(s => { return stru; }).ToArray(); +// --- rust generation --- string rustTypes = Path.Combine(libcppDir, "src", "types.rs"); var rustCTypesTemplate = Handlebars.Compile(File.ReadAllText(Path.Combine(templatesDir, "rust_types.hbs"))); var rustCTypes = rustCTypesTemplate(handlebarData); +Util.ReplaceTextInFile(rustTypes, "RUST_TYPES", rustCTypes.ToString().ReplaceLineEndings("\n")); +// --- C++ generation --- string rustCppInclude = Path.Combine(libcppDir, "include", "Velopack.hpp"); var cppTypesTemplate = Handlebars.Compile(File.ReadAllText(Path.Combine(templatesDir, "cpp_mapping.hbs"))); var cppTypes = cppTypesTemplate(handlebarData); - -Console.WriteLine("Writing all to file"); -Util.ReplaceTextInFile(rustTypes, "RUST_TYPES", rustCTypes.ToString().ReplaceLineEndings("\n")); Util.ReplaceTextInFile(rustCppInclude, "CPP_TYPES", cppTypes.ToString().ReplaceLineEndings("\n")); -// --- Python asset.rs generation --- +// --- python generation --- string pythonAssetRs = Path.Combine(scriptsDir, "..", "lib-python", "src", "types.rs"); var pythonAssetTemplate = Handlebars.Compile(File.ReadAllText(Path.Combine(templatesDir, "python_asset.hbs"))); var pythonAsset = pythonAssetTemplate(handlebarData); File.WriteAllText(pythonAssetRs, pythonAsset.ToString().ReplaceLineEndings("\n")); +// --- nodejs generation --- +var libnodeTypesFile = Path.Combine(scriptsDir, "..", "lib-nodejs", "src", "types.ts"); +var nodeTemplate = Handlebars.Compile(File.ReadAllText(Path.Combine(templatesDir, "node_types.hbs"))); +var nodeData = nodeTemplate(handlebarData); +File.WriteAllText(libnodeTypesFile, nodeData.ToString().ReplaceLineEndings("\n")); + return 0; class TypeMap @@ -122,6 +129,7 @@ class TypeMap public string rustType; public string cType; public string cppType; + public string nodeType; public string interopType; public bool primitive; public bool system; @@ -132,18 +140,20 @@ class TypeMap rustType = rustName, cType = cType, cppType = rustName, + nodeType = rustName, interopType = cType, primitive = false, system = false, }; } - public static TypeMap Primitive(string rustName, string cType) + public static TypeMap Primitive(string rustName, string cType, string nodeType) { return new TypeMap() { rustType = rustName, cType = cType, cppType = cType, + nodeType = nodeType, interopType = rustName, primitive = true, system = false, @@ -156,6 +166,7 @@ class TypeMap rustType = rustName, cType = cType, cppType = cppType, + nodeType = cppType, interopType = interopType, primitive = false, system = true, @@ -179,6 +190,7 @@ class RustStruct_Field public string field_c_type; public string field_cpp_type; public string field_rust_type; + public string field_node_type; public bool field_primitive; public bool field_optional; public bool field_vector; diff --git a/src/code-generator/Templates/node_types.hbs b/src/code-generator/Templates/node_types.hbs new file mode 100644 index 00000000..69cbf161 --- /dev/null +++ b/src/code-generator/Templates/node_types.hbs @@ -0,0 +1,12 @@ +// This file is auto-generated. Do not edit by hand. + +{{#each this}} +{{cpp_comment}} +export type {{struct_rust_name}} = { + {{#each fields}} + {{#indent "cpp_comment" " "}} + {{field_name}}{{#if field_optional}}?{{/if}}: {{field_node_type}}{{#if field_vector}}[]{{/if}}, + {{/each}} +} + +{{/each}} \ No newline at end of file diff --git a/src/lib-nodejs/src/bindings/UpdateInfo.ts b/src/lib-nodejs/src/bindings/UpdateInfo.ts deleted file mode 100644 index 6e5319de..00000000 --- a/src/lib-nodejs/src/bindings/UpdateInfo.ts +++ /dev/null @@ -1,25 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -import type { VelopackAsset } from "./VelopackAsset"; - -/** - * Holds information about the current version and pending updates, such as how many there are, and access to release notes. - */ -export type UpdateInfo = { -/** - * The available version that we are updating to. - */ -TargetFullRelease: VelopackAsset, -/** - * The base release that this update is based on. This is only available if the update is a delta update. - */ -BaseRelease: VelopackAsset | null, -/** - * The list of delta updates that can be applied to the base version to get to the target version. - */ -DeltasToTarget: Array, -/** - * True if the update is a version downgrade or lateral move (such as when switching channels to the same version number). - * In this case, only full updates are allowed, and any local packages on disk newer than the downloaded version will be - * deleted. - */ -IsDowngrade: boolean, }; diff --git a/src/lib-nodejs/src/bindings/UpdateOptions.ts b/src/lib-nodejs/src/bindings/UpdateOptions.ts deleted file mode 100644 index 877e2dec..00000000 --- a/src/lib-nodejs/src/bindings/UpdateOptions.ts +++ /dev/null @@ -1,28 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -/** - * Options to customise the behaviour of UpdateManager. - */ -export type UpdateOptions = { -/** - * Allows UpdateManager to update to a version that's lower than the current version (i.e. downgrading). - * This could happen if a release has bugs and was retracted from the release feed, or if you're using - * ExplicitChannel to switch channels to another channel where the latest version on that - * channel is lower than the current version. - */ -AllowVersionDowngrade: boolean, -/** - * **This option should usually be left None**. - * Overrides the default channel used to fetch updates. - * The default channel will be whatever channel was specified on the command line when building this release. - * For example, if the current release was packaged with '--channel beta', then the default channel will be 'beta'. - * This allows users to automatically receive updates from the same channel they installed from. This options - * allows you to explicitly switch channels, for example if the user wished to switch back to the 'stable' channel - * without having to reinstall the application. - */ -ExplicitChannel: string | null, -/** - * Sets the maximum number of deltas to consider before falling back to a full update. - * The default is 10. Set to a negative number (eg. -1) to disable deltas. - */ -MaximumDeltasBeforeFallback: number, }; diff --git a/src/lib-nodejs/src/bindings/VelopackAsset.ts b/src/lib-nodejs/src/bindings/VelopackAsset.ts deleted file mode 100644 index 71336830..00000000 --- a/src/lib-nodejs/src/bindings/VelopackAsset.ts +++ /dev/null @@ -1,42 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -/** - * An individual Velopack asset, could refer to an asset on-disk or in a remote package feed. - */ -export type VelopackAsset = { -/** - * The name or Id of the package containing this release. - */ -PackageId: string, -/** - * The version of this release. - */ -Version: string, -/** - * The type of asset (eg. "Full" or "Delta"). - */ -Type: string, -/** - * The filename of the update package containing this release. - */ -FileName: string, -/** - * The SHA1 checksum of the update package containing this release. - */ -SHA1: string, -/** - * The SHA256 checksum of the update package containing this release. - */ -SHA256: string, -/** - * The size in bytes of the update package containing this release. - */ -Size: bigint, -/** - * The release notes in markdown format, as passed to Velopack when packaging the release. This may be an empty string. - */ -NotesMarkdown: string, -/** - * The release notes in HTML format, transformed from Markdown when packaging the release. This may be an empty string. - */ -NotesHtml: string, }; diff --git a/src/lib-nodejs/src/bindings/VelopackLocatorConfig.ts b/src/lib-nodejs/src/bindings/VelopackLocatorConfig.ts deleted file mode 100644 index d9195bda..00000000 --- a/src/lib-nodejs/src/bindings/VelopackLocatorConfig.ts +++ /dev/null @@ -1,30 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -/** - * VelopackLocator provides some utility functions for locating the current app important paths (eg. path to packages, update binary, and so forth). - */ -export type VelopackLocatorConfig = { -/** - * The root directory of the current app. - */ -RootAppDir: string, -/** - * The path to the Update.exe binary. - */ -UpdateExePath: string, -/** - * The path to the packages' directory. - */ -PackagesDir: string, -/** - * The current app manifest. - */ -ManifestPath: string, -/** - * The directory containing the application's user binaries. - */ -CurrentBinaryDir: string, -/** - * Whether the current application is portable or installed. - */ -IsPortable: boolean, }; diff --git a/src/lib-nodejs/src/index.ts b/src/lib-nodejs/src/index.ts index 68331fe8..c3e18936 100644 --- a/src/lib-nodejs/src/index.ts +++ b/src/lib-nodejs/src/index.ts @@ -1,9 +1,7 @@ import * as addon from "./load"; -import type { UpdateInfo } from "./bindings/UpdateInfo"; -import type { UpdateOptions } from "./bindings/UpdateOptions"; -import type { VelopackLocatorConfig } from "./bindings/VelopackLocatorConfig"; -export { UpdateInfo, UpdateOptions, VelopackLocatorConfig }; +import type { UpdateInfo, UpdateOptions, VelopackLocatorConfig, VelopackAsset } from "./types"; +export { UpdateInfo, UpdateOptions, VelopackLocatorConfig, VelopackAsset }; type UpdateManagerOpaque = {}; declare module "./load" { diff --git a/src/lib-nodejs/src/types.ts b/src/lib-nodejs/src/types.ts new file mode 100644 index 00000000..43bf7211 --- /dev/null +++ b/src/lib-nodejs/src/types.ts @@ -0,0 +1,82 @@ +// This file is auto-generated. Do not edit by hand. + +/** VelopackLocator provides some utility functions for locating the current app important paths (eg. path to packages, update binary, and so forth). */ +export type VelopackLocatorConfig = { + /** The root directory of the current app. */ + RootAppDir: string, + /** The path to the Update.exe binary. */ + UpdateExePath: string, + /** The path to the packages' directory. */ + PackagesDir: string, + /** The current app manifest. */ + ManifestPath: string, + /** The directory containing the application's user binaries. */ + CurrentBinaryDir: string, + /** Whether the current application is portable or installed. */ + IsPortable: boolean, +} + +/** An individual Velopack asset, could refer to an asset on-disk or in a remote package feed. */ +export type VelopackAsset = { + /** The name or Id of the package containing this release. */ + PackageId: string, + /** The version of this release. */ + Version: string, + /** The type of asset (eg. "Full" or "Delta"). */ + Type: string, + /** The filename of the update package containing this release. */ + FileName: string, + /** The SHA1 checksum of the update package containing this release. */ + SHA1: string, + /** The SHA256 checksum of the update package containing this release. */ + SHA256: string, + /** The size in bytes of the update package containing this release. */ + Size: number, + /** The release notes in markdown format, as passed to Velopack when packaging the release. This may be an empty string. */ + NotesMarkdown: string, + /** The release notes in HTML format, transformed from Markdown when packaging the release. This may be an empty string. */ + NotesHtml: string, +} + +/** Holds information about the current version and pending updates, such as how many there are, and access to release notes. */ +export type UpdateInfo = { + /** The available version that we are updating to. */ + TargetFullRelease: VelopackAsset, + /** The base release that this update is based on. This is only available if the update is a delta update. */ + BaseRelease?: VelopackAsset, + /** The list of delta updates that can be applied to the base version to get to the target version. */ + DeltasToTarget: VelopackAsset[], + /** + * True if the update is a version downgrade or lateral move (such as when switching channels to the same version number). + * In this case, only full updates are allowed, and any local packages on disk newer than the downloaded version will be + * deleted. + */ + IsDowngrade: boolean, +} + +/** Options to customise the behaviour of UpdateManager. */ +export type UpdateOptions = { + /** + * Allows UpdateManager to update to a version that's lower than the current version (i.e. downgrading). + * This could happen if a release has bugs and was retracted from the release feed, or if you're using + * ExplicitChannel to switch channels to another channel where the latest version on that + * channel is lower than the current version. + */ + AllowVersionDowngrade: boolean, + /** + * **This option should usually be left None**. + * Overrides the default channel used to fetch updates. + * The default channel will be whatever channel was specified on the command line when building this release. + * For example, if the current release was packaged with '--channel beta', then the default channel will be 'beta'. + * This allows users to automatically receive updates from the same channel they installed from. This options + * allows you to explicitly switch channels, for example if the user wished to switch back to the 'stable' channel + * without having to reinstall the application. + */ + ExplicitChannel?: string, + /** + * Sets the maximum number of deltas to consider before falling back to a full update. + * The default is 10. Set to a negative number (eg. -1) to disable deltas. + */ + MaximumDeltasBeforeFallback: number, +} + diff --git a/src/lib-nodejs/velopack_nodeffi/Cargo.toml b/src/lib-nodejs/velopack_nodeffi/Cargo.toml index 85d87e56..752326ca 100644 --- a/src/lib-nodejs/velopack_nodeffi/Cargo.toml +++ b/src/lib-nodejs/velopack_nodeffi/Cargo.toml @@ -24,8 +24,4 @@ semver.workspace = true log.workspace = true simplelog.workspace = true lazy_static.workspace = true -neon.workspace = true - -[build-dependencies] -velopack = { workspace = true, features = ["typescript"] } -ts-rs.workspace = true \ No newline at end of file +neon.workspace = true \ No newline at end of file diff --git a/src/lib-nodejs/velopack_nodeffi/build.rs b/src/lib-nodejs/velopack_nodeffi/build.rs deleted file mode 100644 index 4f8f343b..00000000 --- a/src/lib-nodejs/velopack_nodeffi/build.rs +++ /dev/null @@ -1,12 +0,0 @@ -use std::{env, path::Path}; -use locator::VelopackLocatorConfig; -use ts_rs::TS; -use velopack::*; - -fn main() { - let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - let bindings_dir = Path::new(&manifest_dir).join("..").join("src").join("bindings"); - UpdateInfo::export_all_to(&bindings_dir).unwrap(); - UpdateOptions::export_all_to(&bindings_dir).unwrap(); - VelopackLocatorConfig::export_all_to(&bindings_dir).unwrap(); -} \ No newline at end of file diff --git a/src/lib-rust/Cargo.toml b/src/lib-rust/Cargo.toml index 7070d2d6..94c96cdb 100644 --- a/src/lib-rust/Cargo.toml +++ b/src/lib-rust/Cargo.toml @@ -16,7 +16,6 @@ rust-version.workspace = true [features] default = [] async = ["async-std"] -typescript = ["ts-rs"] file-logging = ["log-panics", "simplelog", "time"] [package.metadata.docs.rs] @@ -50,9 +49,6 @@ sha1.workspace = true sha2.workspace = true uuid.workspace = true -# typescript -ts-rs = { workspace = true, optional = true } - # async async-std = { workspace = true, optional = true } diff --git a/src/lib-rust/src/locator.rs b/src/lib-rust/src/locator.rs index b8ebb679..d307b747 100644 --- a/src/lib-rust/src/locator.rs +++ b/src/lib-rust/src/locator.rs @@ -59,7 +59,6 @@ impl ShortcutLocationFlags { /// VelopackLocator provides some utility functions for locating the current app important paths (eg. path to packages, update binary, and so forth). #[allow(non_snake_case)] #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Default)] -#[cfg_attr(feature = "typescript", derive(ts_rs::TS))] pub struct VelopackLocatorConfig { /// The root directory of the current app. pub RootAppDir: PathBuf, diff --git a/src/lib-rust/src/manager.rs b/src/lib-rust/src/manager.rs index fd6233e9..62f02110 100644 --- a/src/lib-rust/src/manager.rs +++ b/src/lib-rust/src/manager.rs @@ -52,7 +52,6 @@ impl VelopackAssetFeed { /// An individual Velopack asset, could refer to an asset on-disk or in a remote package feed. #[allow(non_snake_case)] #[derive(Serialize, Deserialize, Debug, Clone, Default)] -#[cfg_attr(feature = "typescript", derive(ts_rs::TS))] #[serde(default)] pub struct VelopackAsset { /// The name or Id of the package containing this release. @@ -78,7 +77,6 @@ pub struct VelopackAsset { /// Holds information about the current version and pending updates, such as how many there are, and access to release notes. #[allow(non_snake_case)] #[derive(Serialize, Deserialize, Debug, Clone, Default)] -#[cfg_attr(feature = "typescript", derive(ts_rs::TS))] #[serde(default)] pub struct UpdateInfo { /// The available version that we are updating to. @@ -118,7 +116,6 @@ impl AsRef for VelopackAsset { /// Options to customise the behaviour of UpdateManager. #[allow(non_snake_case)] #[derive(Serialize, Deserialize, Debug, Clone, Default)] -#[cfg_attr(feature = "typescript", derive(ts_rs::TS))] #[serde(default)] pub struct UpdateOptions { /// Allows UpdateManager to update to a version that's lower than the current version (i.e. downgrading).