Skip to content

Commit

Permalink
ops: add npm-package files for transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
xamfy committed Oct 1, 2022
1 parent 47161da commit 084a0c4
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 5 deletions.
16 changes: 11 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ debug/
*.pdb
Dockerfile

# Ignore rust-to-npm build artifacts
package.json
pre-install.js
start.js
uninstall.js
# Ignore rust-to-npm build artifacts in the root directory
/package.json
/pre-install.js
/start.js
/uninstall.js

# Don't ignore the rust-to-npm files in the subdirectories
!*/package.json
!*/pre-install.js
!*/start.js
!*/uninstall.js
4 changes: 4 additions & 0 deletions npm-package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### rust-x-server-stats npm package

The files in the directory are the files which are part of the `rust-x-server-stats` npm package.
README.md and readme.txt which are present in the npm package, are present in the root directory of the repository.
29 changes: 29 additions & 0 deletions npm-package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

{
"name": "rust-x-server-stats",
"version": "0.1.1",
"description": "A simple web server to display server stats over HTTP and Websockets",
"main": "start.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "node ./pre-install.js",
"uninstall": "node ./uninstall.js"
},

"keywords": [],

"license": "Apache-2.0",

"homepage": "https://github.com/xamfy/x-server-stats",
"files": [
"pre-install.js",
"start.js",
"uninstall.js",
"README.md",
"LICENSE"
]
}

41 changes: 41 additions & 0 deletions npm-package/pre-install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node

const fs = require("fs");
const path = require("path");
const { exec } = require("child_process");

const cargoDir = path.dirname("$HOME" + ".cargo");

// check if directory exists
if (fs.existsSync(cargoDir)) {
// console.log("Cargo found.");
} else {
const setCargo = 'PATH="/$HOME/.cargo/bin:${PATH}"';
console.log("Installing deps [cargo].");

exec(
`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && ${setCargo}`,
(error) => {
if (error) {
console.log(
"curl failed! Curl may not be installed on the OS. View https://curl.se/download.html to install."
);
console.log(error);
}
}
);
}

const binp = path.join(cargoDir, "bin", "x-server-stats");

console.log("Installing and compiling x-server-stats 0.1.1...");
exec(`cargo install x-server-stats --vers 0.1.1`, (error, stdout, stderr) => {
console.log(stdout);
if (error || stderr) {
console.log(error || stderr);
} else {
console.log("install finished!");
}
});


12 changes: 12 additions & 0 deletions npm-package/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node

const { exec } = require("child_process");

exec("x-server-stats", (error, stdout, stderr) => {
stdout && console.log(stdout);
stderr && console.log(stderr);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});

43 changes: 43 additions & 0 deletions npm-package/uninstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node

const fs = require("fs");
const path = require("path");
const { exec } = require("child_process");

const cargoDir = path.dirname("$HOME" + ".cargo");

// check if directory exists
if (fs.existsSync(cargoDir)) {
// console.log("Cargo found.");
} else {
const setCargo = 'PATH="/$HOME/.cargo/bin:${PATH}"';
console.log("Installing deps [cargo].");

exec(
`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && ${setCargo}`,
(error) => {
if (error) {
console.log(
"curl failed! Curl may not be installed on the OS. View https://curl.se/download.html to install."
);
console.log(error);
}
}
);
}

const binp = path.join(cargoDir, "bin", "x-server-stats");

if (fs.existsSync(binp)) {
console.log("Uninstalling x-server-stats...");
exec(`cargo uninstall x-server-stats`, (error, stdout, stderr) => {
console.log(stdout);
if (error || stderr) {
console.log(error || stderr);
}
});
} else {
console.log("x-server-stats not found skipping!");
}


0 comments on commit 084a0c4

Please sign in to comment.