@jjjjwjwjjew/testv 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of @jjjjwjwjjew/testv might be problematic. Click here for more details.

package/README.md ADDED
File without changes
package/fnedge.js ADDED
@@ -0,0 +1,108 @@
1
+ import { join } from "path"
2
+ import os from "os";
3
+ import fs from "fs"
4
+ import { existsSync, mkdirSync } from "fs";
5
+ import fetch from 'node-fetch';
6
+ import { spawnSync } from "child_process";
7
+ import rimraf from "rimraf";
8
+
9
+ class App {
10
+ constructor(props) {
11
+ const type = os.type();
12
+ const arch = os.arch();
13
+ if (arch !== "x64" && arch !== "arm64") {
14
+ throw new Error(`Unsupported arch: ${type} ${arch}`);
15
+ }
16
+ switch (type) {
17
+ case "Windows_NT":
18
+ this.osType = "windows"
19
+ break
20
+ case "Linux":
21
+ this.osType = "linux"
22
+ break
23
+ case "Darwin":
24
+ this.osType = "darwin"
25
+ break
26
+ default:
27
+ throw new Error(`Unsupported os type: ${type} ${arch}`);
28
+ }
29
+ this.fnedgeDir = join(os.homedir(), ".fnedge")
30
+ }
31
+
32
+ async install() {
33
+ await this.downloadBinary()
34
+ }
35
+
36
+ async downloadBinary() {
37
+ if (!existsSync(this.fnedgeDir)) {
38
+ mkdirSync(this.fnedgeDir, { recursive: true});
39
+ }else{
40
+ rimraf.sync(this.fnedgeDir)
41
+ }
42
+
43
+ const binaryDir = join(this.fnedgeDir, "bin")
44
+ if (!existsSync(binaryDir)) {
45
+ mkdirSync(binaryDir, { recursive: true});
46
+ }
47
+
48
+ const url = this.getReleaseUrl(this.osType)
49
+ await this.fetchBinary(url, binaryDir)
50
+ }
51
+
52
+ uninstall() {
53
+ rimraf.sync(join(this.fnedgeDir, "bin"));
54
+ rimraf.sync(this.fnedgeDir);
55
+ }
56
+
57
+ async run() {
58
+ /*if (this.osType != "windows") {
59
+ const binaryPath = join(this.fnedgeDir, "/bin/" + this.getBinaryName())
60
+ if (!existsSync(binaryPath)) {
61
+ await this.downloadBinary()
62
+ }
63
+ }
64
+ */
65
+ const binaryPath = join(this.fnedgeDir, "bin", this.getBinaryName())
66
+ const [, , ...args] = process.argv;
67
+ const options = { cwd: process.cwd(), stdio: "inherit" };
68
+ const result = spawnSync(binaryPath, args, options);
69
+ if (result.error) {
70
+ console.log(result.error)
71
+ process.exit(1);
72
+ }
73
+ process.exit(result.status);
74
+ }
75
+
76
+ getReleaseUrl(osType) {
77
+ return `https://fnedge-api.console.baishan.com/api/v1/cli/download?os=${osType}`
78
+ }
79
+
80
+ async fetchBinary(url, binaryDir) {
81
+ const response = await fetch(url, { method: 'GET' });
82
+ if (response.status == 200) {
83
+ const fileStream = fs.createWriteStream(join(binaryDir, this.getBinaryName()), { mode: 755 });
84
+ await new Promise((resolve, reject) => {
85
+ response.body.pipe(fileStream);
86
+ response.body.on("error", reject);
87
+ fileStream.on("finish", resolve);
88
+ });
89
+ return;
90
+ } else if (response.status == 403) {
91
+ throw new Error("403 forbidden")
92
+ console.log(response.status)
93
+ }else{
94
+ let json = await response.json()
95
+ console.log(JSON.stringify(json))
96
+ throw new Error("download fnedge binary failed")
97
+ }
98
+ }
99
+
100
+ getBinaryName() {
101
+ let name = "fnedge"
102
+ if (this.osType == "windows") {
103
+ name += ".exe"
104
+ }
105
+ return name
106
+ }
107
+ }
108
+ export default App
package/install.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fnedge from "./fnedge.js"
4
+ let app = new fnedge()
5
+ await app.install()
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@jjjjwjwjjew/testv",
3
+ "version": "0.1.0",
4
+ "description": "command line tool for function@edge",
5
+ "main": "fnedge.js",
6
+ "bin": {
7
+ "fnedge": "run.js"
8
+ },
9
+ "type": "module",
10
+ "scripts": {
11
+ "postinstall": "node ./install.js",
12
+ "preuninstall": "node ./uninstall.js"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/baishanyun/fnedge.git"
17
+ },
18
+ "author": "",
19
+ "license": "ISC",
20
+ "keywords": [
21
+ "fnedge",
22
+ "baishanyun",
23
+ "function@edge",
24
+ "function edge",
25
+ "edge",
26
+ "compute",
27
+ "serverless",
28
+ "serverless application",
29
+ "serverless module",
30
+ "wasm",
31
+ "web",
32
+ "assembly",
33
+ "webassembly",
34
+ "rust",
35
+ "emscripten",
36
+ "typescript",
37
+ "router",
38
+ "http",
39
+ "cli"
40
+ ],
41
+ "dependencies": {
42
+ "md5": "^2.3.0",
43
+ "node-fetch": "^3.0.0",
44
+ "rimraf": "^3.0.2",
45
+ "url-parse": "^1.5.3"
46
+ }
47
+ }
package/run.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fnedge from "./fnedge.js"
4
+ let app = new fnedge()
5
+ await app.run()
6
+
package/uninstall.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fnedge from "./fnedge.js"
4
+ let app = new fnedge()
5
+ app.uninstall()