Skip to content

Commit

Permalink
Use labels for select
Browse files Browse the repository at this point in the history
  • Loading branch information
emi2k01 committed Jun 21, 2022
1 parent 8162cb1 commit 06a4800
Show file tree
Hide file tree
Showing 8 changed files with 633 additions and 2 deletions.
15 changes: 15 additions & 0 deletions npm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# `binary-install-example`

This package is not published to npm and is only used for illustrative purposes and for testing `binary-install`.

## `binary.js`

This file contains logic to detect the correct tarball endpoint for [`example-binary`](../example-binary) based on platform (Linux, MacOS, or Windows).

## `install.js`

This file imports the `install` function from `binary.js` and just runs it. `install.js` is referred to by the `postinstall` section in `package.json`.

## `run.test.js`

This file contains just a few tests that make sure that installs work and running commands work.
82 changes: 82 additions & 0 deletions npm/binary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const { Binary } = require("@emi2k01/binary-install");
const os = require("os");
const cTable = require("console.table");

const VERSION = "0.0.4";

const error = (msg) => {
console.error(msg);
process.exit(1);
};

const { version, name, repository } = require("./package.json");

const supportedPlatforms = [
{
TYPE: "Windows_NT",
ARCHITECTURE: "x64",
RUST_TARGET: "x86_64-pc-windows-msvc",
BINARY_NAME: "git-ct.exe",
},
{
TYPE: "Linux",
ARCHITECTURE: "x64",
RUST_TARGET: "x86_64-unknown-linux-musl",
BINARY_NAME: "git-ct",
},
{
TYPE: "Darwin",
ARCHITECTURE: "x64",
RUST_TARGET: "x86_64-apple-darwin",
BINARY_NAME: "git-ct",
},
];

const getPlatformMetadata = () => {
const type = os.type();
const architecture = os.arch();

for (let supportedPlatform of supportedPlatforms) {
if (
type === supportedPlatform.TYPE &&
architecture === supportedPlatform.ARCHITECTURE
) {
return supportedPlatform;
}
}

error(
`Platform with type "${type}" and architecture "${architecture}" is not supported by ${name}.\nYour system must be one of the following:\n\n${cTable.getTable(
supportedPlatforms
)}`
);
};

const getBinary = () => {
const platformMetadata = getPlatformMetadata();
// the url for this binary is constructed from values in `package.json`
// https://github.com/EverlastingBugstopper/binary-install/releases/download/v1.0.0/binary-install-example-v1.0.0-x86_64-apple-darwin.tar.gz
const url = `${repository.url}/releases/download/v${VERSION}/${name}_v${VERSION}_${platformMetadata.RUST_TARGET}.tar.gz`;
return new Binary(platformMetadata.BINARY_NAME, url);
};

const run = () => {
const binary = getBinary();
binary.run();
};

const install = () => {
const binary = getBinary();
binary.install();
};

const uninstall = () => {
const binary = getBinary();
binary.uninstall();
};

module.exports = {
install,
run,
uninstall,
};
4 changes: 4 additions & 0 deletions npm/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

const { install } = require("./binary");
install();
Loading

0 comments on commit 06a4800

Please sign in to comment.