Skip to content

Commit

Permalink
Publish scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius de Bruijn committed Feb 4, 2022
1 parent 8b843a0 commit f0b5385
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target/
tmp/
Cargo.lock
.DS_Store
result
136 changes: 136 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ authors = [
wasm-opt = ["-Oz", "--enable-mutable-globals"]

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

[dev-dependencies]

[lib]
crate-type = ["cdylib", "lib"]

[profile.release]
lto = true
67 changes: 67 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
description = "ADO.net and JDBC Connection String Parser.";

inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};

outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system: let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
inherit (pkgs) wasm-bindgen-cli rustPlatform nodejs;
in {
defaultPackage = rustPlatform.buildRustPackage {
name = "connection-string";
src = builtins.path { path = ./.; name = "connection-string"; };

cargoLock = {
lockFile = ./Cargo.lock;
};

nativeBuildInputs = [ rust wasm-bindgen-cli nodejs ];

buildPhase = ''
RUST_BACKTRACE=1
cargo build --release --target=wasm32-unknown-unknown
echo 'Creating out dir...'
mkdir -p $out/src;
echo 'Copying package.json...'
cp ./package.json $out/;
echo 'Copying README.md...'
cp README.md $out/;
echo 'Generating node module...'
wasm-bindgen \
--target nodejs \
--out-dir $out/src \
target/wasm32-unknown-unknown/release/connection_string.wasm;
'';
checkPhase = "echo 'Check phase: skipped'";
installPhase = "echo 'Install phase: skipped'";
};

packages = {
cargo = {
type = "app";
program = "${rust}/bin/cargo";
};

# Takes the new package version as first and only argument, and updates package.json
updatePackageVersion = pkgs.writeShellScriptBin "updateNpmPackageVersion" ''
${pkgs.jq}/bin/jq ".version = \"$1\"" package.json > /tmp/package.json
rm package.json
cp /tmp/package.json package.json
sed -i "s/^version\ =.*$/version = \"$1\"/" Cargo.toml
'';
publishRust = pkgs.writeShellScriptBin "publishRust" ''
${rust}/bin/cargo publish
'';
publishJavascript = pkgs.writeShellScriptBin "publishRust" ''
${nodejs}/bin/npm publish ./result --access public --tag latest
'';
npm = {
type = "app";
program = "${nodejs}/bin/npm";
};
wasm-bindgen = {
type = "app";
program = "${wasm-bindgen-cli}/bin/wasm-bindgen";
};
syncWasmBindgenVersions = pkgs.writeShellScriptBin "updateWasmBindgenVersion" ''
echo 'Syncing wasm-bindgen version in crate with that of the installed CLI...'
sed -i "s/^wasm-bindgen\ =.*$/wasm-bindgen = \"=${wasm-bindgen-cli.version}\"/" Cargo.toml
'';
};
devShell = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
nodePackages.prisma
nodePackages.npm
nodejs-slim
];
};
});
}
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@pimeys/connection-string",
"version": "0.1.14",
"description": "A parser for ADO.net and JDBC connection strings",
"main": "src/connection_string.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/prisma/connection-string"
},
"author": "Prisma",
"license": "MIT OR Apache-2.0",
"homepage": "https://github.com/prisma/connection-string"
}
5 changes: 5 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
channel = "stable"
components = []
targets = [ "wasm32-unknown-unknown" ]
profile = "default"
1 change: 1 addition & 0 deletions src/ado.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fn read_ident(lexer: &mut Lexer) -> crate::Result<String> {
#[derive(Debug, Clone)]
struct Token {
kind: TokenKind,
#[allow(dead_code)] // for future use...
loc: Location,
}

Expand Down
1 change: 1 addition & 0 deletions src/jdbc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ impl Location {
/// A pair of `Location` and `TokenKind`.
#[derive(Debug, Clone)]
struct Token {
#[allow(dead_code)] // for future use...
loc: Location,
kind: TokenKind,
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ macro_rules! ensure {
#[macro_export]
macro_rules! bail {
($msg:literal) => {
return Err($crate::Error::new($msg.into()));
return Err($crate::Error::new($msg.into()))
};

($msg:expr) => {
return Err($crate::Error::new($msg.into()));
return Err($crate::Error::new($msg.into()))
};

($fmt:expr, $($arg:tt)*) => {
return Err($crate::Error::new(&*format!($fmt, $($arg)*)));
return Err($crate::Error::new(&*format!($fmt, $($arg)*)))
};
}

0 comments on commit f0b5385

Please sign in to comment.