mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Remove ts-rs and add new node handlebar template
This commit is contained in:
25
Cargo.lock
generated
25
Cargo.lock
generated
@@ -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",
|
||||
]
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -55,16 +55,16 @@ var types = new List<TypeMap>() {
|
||||
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;
|
||||
|
||||
12
src/code-generator/Templates/node_types.hbs
Normal file
12
src/code-generator/Templates/node_types.hbs
Normal file
@@ -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}}
|
||||
@@ -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<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, };
|
||||
@@ -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, };
|
||||
@@ -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, };
|
||||
@@ -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, };
|
||||
@@ -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" {
|
||||
|
||||
82
src/lib-nodejs/src/types.ts
Normal file
82
src/lib-nodejs/src/types.ts
Normal file
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
neon.workspace = true
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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 }
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<VelopackAsset> 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).
|
||||
|
||||
Reference in New Issue
Block a user