Skip to content

Commit c1fb445

Browse files
committed
minor update
1 parent e84c2a1 commit c1fb445

7 files changed

Lines changed: 229 additions & 10 deletions

File tree

bin/LICENSE

Whitespace-only changes.

bin/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Gitsecure CLI
2+
3+
Gitsecure CLI is a cutting-edge SecretOps infrastructure designed for developers and teams.
4+
5+
## Useful links
6+
7+
- [Github repository](git@github.com:GitsecureHQ/gitsecure-cli.git)
8+
- [Project documentation](https://mirage-collarbone-cf7.notion.site/GitSecure-Model-Structure-c610f335aa07401db311ff44fe4a8758)
9+
10+
## Requirements
11+
12+
- Go version 1.19 or higher
13+
- Cobra version 1.6.1
14+
15+
## Running the application
16+
17+
To run the CLI, follow the steps below:
18+
19+
```sh
20+
# Build the CLI Locally
21+
$ go build
22+
# Install the CLI after the build
23+
$ go install
24+
```
25+
26+
## Contributing
27+
28+
To contribute to Gitsecure CLI, please follow these steps:
29+
30+
1. Pick an issue from the [GitHub repository](https://github.com/GitsecureHQ/gitsecure-cli).
31+
2. Clone the repository using the following command:
32+
33+
```sh
34+
$ git clone https://github.com/GitsecureHQ/gitsecure-cli
35+
```
36+
37+
3. When creating a new branch, use the following naming convention: `GSC-<issue-no>-<short-description>`, for example, `GSC-1-project-setup`. The main branch should be based on `develop`.
38+
4. When creating a pull request, select `develop` as the target branch.
39+
40+
## Pushing changes to the repository
41+
42+
Use the following commands to push changes to the repository:
43+
44+
```sh
45+
# if pushing for the first time
46+
$ git push -u origin <branchname>
47+
48+
# if pushing normally
49+
$ git push
50+
```
51+
## Install the CLI
52+
```
53+
# Scoop For Windows
54+
55+
$ scoop bucket add gitsecurehq https://github.com/GitsecureHQ/scoop-gitsecure
56+
$ scoop install gitsecure-cli
57+
$ gitsecure --version
58+
59+
# Brew For Mac And Linux Users
60+
61+
$ brew tap GitsecureHQ/brew
62+
$ brew install gitsecure
63+
$ gitsecure --version
64+
```
65+
66+

bin/gitsecure.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
import { execFileSync } from "child_process";
3+
import path from "path";
4+
import { exit } from "process";
5+
import { fileURLToPath } from "url";
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
const binName =
10+
process.platform === "win32" ? "gitsecure.exe" : "gitsecure";
11+
try {
12+
execFileSync(path.resolve(`${__dirname}/${binName}`), process.argv.slice(2), {
13+
stdio: "inherit",
14+
});
15+
} catch (e) {
16+
exit(1);
17+
}

npm-install/config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Global configuration
3+
*/
4+
export const CONFIG = {
5+
/**
6+
* The name of the binary
7+
* @type {string}
8+
*/
9+
name: "gitsecure",
10+
11+
/**
12+
* Where to save the unzipped files
13+
* @type {string}
14+
*/
15+
path: "./bin",
16+
17+
/**
18+
* The URL to download the binary form
19+
*
20+
* - `{{arch}}` is one of the Golang achitectures listed below
21+
* - `{{bin_name}}` is the name declared above
22+
* - `{{platform}}` is one of the Golang platforms listed below
23+
* - `{{version}}` is the version number as `0.0.0` (taken from package.json)
24+
*
25+
* @type {string}
26+
*/
27+
url: "https://github.com/GitsecureHQ/gitsecure-cli/releases/download/v{{version}}/{{bin_name}}_v{{version}}_{{triple}}.tar.gz",
28+
};
29+
30+

npm-install/getReleaseInfo.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as fs from "fs/promises";
2+
import os from "os";
3+
4+
function getSystemInfo() {
5+
const type = os.type();
6+
const arch = os.arch();
7+
if (type === "Windows_NT" && arch === "x64") {
8+
return {
9+
platform: "Windows",
10+
arch: "x86_64",
11+
};
12+
}
13+
if (type === "Windows_NT") {
14+
return {
15+
platform: "Windows",
16+
arch: "i386",
17+
};
18+
}
19+
if (type === "Linux" && arch === "x64") {
20+
return {
21+
platform: "Linux",
22+
arch: "arm64",
23+
};
24+
}
25+
if (type === "Linux" && arch === "x32") {
26+
return {
27+
platform: "Linux",
28+
arch: "i386",
29+
};
30+
}
31+
if (type === "Darwin" && arch === "x64") {
32+
return {
33+
platform: "Darwin",
34+
arch: "x64",
35+
};
36+
}
37+
if (type === "Darwin" && arch === "arm64") {
38+
return {
39+
platform: "Darwin",
40+
arch: "arm64",
41+
};
42+
}
43+
44+
throw new Error(`Unsupported platform: ${type} ${arch}`);
45+
}
46+
47+
async function getReleaseInfo() {
48+
const { platform, arch } = getSystemInfo();
49+
const packageJson = await fs.readFile("package.json").then(JSON.parse);
50+
let version = packageJson.version;
51+
const url = `https://github.com/GitsecureHQ/gitsecure-cli/releases/download/v${version}/gitsecure-cli_${version}_${platform}_${arch}.tar.gz`;
52+
const name = "gitsecure-cli";
53+
return { url, name };
54+
}
55+
56+
export default getReleaseInfo;

npm-install/postinstall.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { createWriteStream } from "fs";
2+
import * as fs from "fs/promises";
3+
import fetch from "node-fetch";
4+
import { pipeline } from "stream/promises";
5+
import tar from "tar";
6+
7+
import { CONFIG } from "./config.js";
8+
import getReleaseInfo from "./getReleaseInfo.js";
9+
10+
async function install() {
11+
const packageJson = await fs.readFile("package.json").then(JSON.parse);
12+
let version = packageJson.version;
13+
14+
if (typeof version !== "string") {
15+
throw new Error("Missing version in package.json");
16+
}
17+
18+
if (version[0] === "v") version = version.slice(1);
19+
20+
// Fetch Static Config
21+
let { name: binName, path: binPath } = CONFIG;
22+
const { url } = await getReleaseInfo();
23+
console.log(url);
24+
const response = await fetch(url);
25+
if (!response.ok) {
26+
throw new Error("Failed fetching the binary: " + response.statusText);
27+
}
28+
29+
const tarFile = "downloaded.tar.gz";
30+
31+
await fs.mkdir(binPath, { recursive: true });
32+
await pipeline(response.body, createWriteStream(tarFile));
33+
await tar.x({ file: tarFile, cwd: binPath });
34+
await fs.rm(tarFile);
35+
}
36+
37+
install()
38+
.then(async () => {
39+
process.exit(0);
40+
})
41+
.catch(async (err) => {
42+
console.error(err);
43+
process.exit(1);
44+
});
45+

package.json

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
"name": "@gitsecure/cli",
3-
"version": "0.0.0",
3+
"version": "0.1.2",
44
"description": "Modern SecretOps infrastructure for developers and teams.",
55
"main": "index.js",
6+
"type": "module",
7+
"engines": {
8+
"node": ">=16.0.0"
9+
},
610
"scripts": {
7-
"postinstall": "go-npm install",
8-
"preuninstall": "go-npm uninstall"
11+
"postinstall": "node ./npm-install/postinstall.js"
912
},
1013
"repository": {
1114
"type": "git",
@@ -21,14 +24,16 @@
2124
"url": "https://github.com/GitsecureHQ/gitsecure-cli/issues"
2225
},
2326
"homepage": "https://github.com/GitsecureHQ/gitsecure-cli#readme",
27+
"devDependencies": {},
2428
"dependencies": {
25-
"@gitsecure/cli": "^1.0.0",
26-
"global": "^4.4.0",
27-
"go-npm": "^0.1.9"
29+
"node-fetch": "^3.1.0",
30+
"tar": "^6.1.11"
2831
},
29-
"goBinary": {
30-
"name": "gitsecure",
31-
"path": "./bin",
32-
"url": "https://github.com/GitsecureHQ/gitsecure-cli/releases/download/v{{version}}/simp-cli_v{{version}}-SNAPSHOT_{{platform}}_{{arch}}.tar.gz"
32+
"files": [
33+
"npm-install",
34+
"README.md"
35+
],
36+
"bin": {
37+
"gitsecure-cli": "bin/gitsecure.js"
3338
}
3439
}

0 commit comments

Comments
 (0)