Skip to content

Commit f0b5385

Browse files
author
Julius de Bruijn
committed
Publish scripts
1 parent 8b843a0 commit f0b5385

File tree

10 files changed

+325
-5
lines changed

10 files changed

+325
-5
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
target/
22
tmp/
3-
Cargo.lock
43
.DS_Store
4+
result

Cargo.lock

Lines changed: 136 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ authors = [
1919
wasm-opt = ["-Oz", "--enable-mutable-globals"]
2020

2121
[target.'cfg(target_arch = "wasm32")'.dependencies]
22-
wasm-bindgen = "0.2"
22+
wasm-bindgen = "=0.2.79"
2323
js-sys = "0.3.56"
2424

2525
[dev-dependencies]
2626

2727
[lib]
2828
crate-type = ["cdylib", "lib"]
29+
30+
[profile.release]
31+
lto = true

flake.lock

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
description = "ADO.net and JDBC Connection String Parser.";
3+
4+
inputs = {
5+
flake-utils.url = "github:numtide/flake-utils";
6+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
7+
rust-overlay = {
8+
url = "github:oxalica/rust-overlay";
9+
inputs.nixpkgs.follows = "nixpkgs";
10+
inputs.flake-utils.follows = "flake-utils";
11+
};
12+
};
13+
14+
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
15+
flake-utils.lib.eachDefaultSystem (system: let
16+
overlays = [ (import rust-overlay) ];
17+
pkgs = import nixpkgs { inherit system overlays; };
18+
rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
19+
inherit (pkgs) wasm-bindgen-cli rustPlatform nodejs;
20+
in {
21+
defaultPackage = rustPlatform.buildRustPackage {
22+
name = "connection-string";
23+
src = builtins.path { path = ./.; name = "connection-string"; };
24+
25+
cargoLock = {
26+
lockFile = ./Cargo.lock;
27+
};
28+
29+
nativeBuildInputs = [ rust wasm-bindgen-cli nodejs ];
30+
31+
buildPhase = ''
32+
RUST_BACKTRACE=1
33+
cargo build --release --target=wasm32-unknown-unknown
34+
echo 'Creating out dir...'
35+
mkdir -p $out/src;
36+
echo 'Copying package.json...'
37+
cp ./package.json $out/;
38+
echo 'Copying README.md...'
39+
cp README.md $out/;
40+
echo 'Generating node module...'
41+
wasm-bindgen \
42+
--target nodejs \
43+
--out-dir $out/src \
44+
target/wasm32-unknown-unknown/release/connection_string.wasm;
45+
'';
46+
checkPhase = "echo 'Check phase: skipped'";
47+
installPhase = "echo 'Install phase: skipped'";
48+
};
49+
50+
packages = {
51+
cargo = {
52+
type = "app";
53+
program = "${rust}/bin/cargo";
54+
};
55+
56+
# Takes the new package version as first and only argument, and updates package.json
57+
updatePackageVersion = pkgs.writeShellScriptBin "updateNpmPackageVersion" ''
58+
${pkgs.jq}/bin/jq ".version = \"$1\"" package.json > /tmp/package.json
59+
rm package.json
60+
cp /tmp/package.json package.json
61+
sed -i "s/^version\ =.*$/version = \"$1\"/" Cargo.toml
62+
'';
63+
publishRust = pkgs.writeShellScriptBin "publishRust" ''
64+
${rust}/bin/cargo publish
65+
'';
66+
publishJavascript = pkgs.writeShellScriptBin "publishRust" ''
67+
${nodejs}/bin/npm publish ./result --access public --tag latest
68+
'';
69+
npm = {
70+
type = "app";
71+
program = "${nodejs}/bin/npm";
72+
};
73+
wasm-bindgen = {
74+
type = "app";
75+
program = "${wasm-bindgen-cli}/bin/wasm-bindgen";
76+
};
77+
syncWasmBindgenVersions = pkgs.writeShellScriptBin "updateWasmBindgenVersion" ''
78+
echo 'Syncing wasm-bindgen version in crate with that of the installed CLI...'
79+
sed -i "s/^wasm-bindgen\ =.*$/wasm-bindgen = \"=${wasm-bindgen-cli.version}\"/" Cargo.toml
80+
'';
81+
};
82+
devShell = pkgs.mkShell {
83+
nativeBuildInputs = [ pkgs.bashInteractive ];
84+
buildInputs = with pkgs; [
85+
nodePackages.prisma
86+
nodePackages.npm
87+
nodejs-slim
88+
];
89+
};
90+
});
91+
}

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "@pimeys/connection-string",
3+
"version": "0.1.14",
4+
"description": "A parser for ADO.net and JDBC connection strings",
5+
"main": "src/connection_string.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/prisma/connection-string"
12+
},
13+
"author": "Prisma",
14+
"license": "MIT OR Apache-2.0",
15+
"homepage": "https://github.com/prisma/connection-string"
16+
}

rust-toolchain.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[toolchain]
2+
channel = "stable"
3+
components = []
4+
targets = [ "wasm32-unknown-unknown" ]
5+
profile = "default"

src/ado.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ fn read_ident(lexer: &mut Lexer) -> crate::Result<String> {
164164
#[derive(Debug, Clone)]
165165
struct Token {
166166
kind: TokenKind,
167+
#[allow(dead_code)] // for future use...
167168
loc: Location,
168169
}
169170

src/jdbc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ impl Location {
351351
/// A pair of `Location` and `TokenKind`.
352352
#[derive(Debug, Clone)]
353353
struct Token {
354+
#[allow(dead_code)] // for future use...
354355
loc: Location,
355356
kind: TokenKind,
356357
}

src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ macro_rules! ensure {
2020
#[macro_export]
2121
macro_rules! bail {
2222
($msg:literal) => {
23-
return Err($crate::Error::new($msg.into()));
23+
return Err($crate::Error::new($msg.into()))
2424
};
2525

2626
($msg:expr) => {
27-
return Err($crate::Error::new($msg.into()));
27+
return Err($crate::Error::new($msg.into()))
2828
};
2929

3030
($fmt:expr, $($arg:tt)*) => {
31-
return Err($crate::Error::new(&*format!($fmt, $($arg)*)));
31+
return Err($crate::Error::new(&*format!($fmt, $($arg)*)))
3232
};
3333
}

0 commit comments

Comments
 (0)