@cyberalien/deploy-utils 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { connectToSSH } from "./ssh/connect.js";
2
+ import { readSFTPDir } from "./ssh/readdir.js";
3
+ import { uploadSFTPFile } from "./ssh/upload.js";
4
+ import { initTokens } from "./misc/tokens.js";
5
+ export { connectToSSH, initTokens, readSFTPDir, uploadSFTPFile };
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { connectToSSH } from "./ssh/connect.js";
2
+ import { readSFTPDir } from "./ssh/readdir.js";
3
+ import { uploadSFTPFile } from "./ssh/upload.js";
4
+ import { initTokens } from "./misc/tokens.js";
5
+ export { connectToSSH, initTokens, readSFTPDir, uploadSFTPFile };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Init tokens, variation of dotenv with custom file
3
+ */
4
+ declare function initTokens(): void;
5
+ export { initTokens };
@@ -0,0 +1,16 @@
1
+ import { readFileSync } from "node:fs";
2
+ /**
3
+ * Init tokens, variation of dotenv with custom file
4
+ */
5
+ function initTokens() {
6
+ const lines = readFileSync(".vars", "utf-8").split("\n");
7
+ for (const line of lines) {
8
+ if (!line.trim() || line.startsWith("#")) continue;
9
+ const [key, value] = line.split("=");
10
+ if (key && value) {
11
+ const actualValue = value.trim().replace(/(^['"]|['"]$)/g, "");
12
+ process.env[key.trim()] = actualValue;
13
+ }
14
+ }
15
+ }
16
+ export { initTokens };
@@ -0,0 +1,6 @@
1
+ import { Client, ConnectConfig } from "ssh2";
2
+ /**
3
+ * Connect to SSH
4
+ */
5
+ declare function connectToSSH(config: ConnectConfig): Promise<Client>;
6
+ export { connectToSSH };
@@ -0,0 +1,19 @@
1
+ import { Client } from "ssh2";
2
+ /**
3
+ * Connect to SSH
4
+ */
5
+ function connectToSSH(config) {
6
+ const conn = new Client();
7
+ return new Promise((resolve, reject) => {
8
+ try {
9
+ conn.on("ready", () => {
10
+ resolve(conn);
11
+ }).on("error", (err) => {
12
+ reject(err);
13
+ }).connect(config);
14
+ } catch (err) {
15
+ reject(err);
16
+ }
17
+ });
18
+ }
19
+ export { connectToSSH };
@@ -0,0 +1,11 @@
1
+ import { Client, Stats } from "ssh2";
2
+ interface FilesListItem {
3
+ filename: string;
4
+ longname: string;
5
+ attrs: Stats;
6
+ }
7
+ /**
8
+ * Read remote directory
9
+ */
10
+ declare function readSFTPDir(client: Client, path: string): Promise<FilesListItem[]>;
11
+ export { readSFTPDir };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Read remote directory
3
+ */
4
+ function readSFTPDir(client, path) {
5
+ return new Promise((resolve, reject) => {
6
+ client.sftp((err, sftp) => {
7
+ if (err) {
8
+ reject(err);
9
+ return;
10
+ }
11
+ sftp.readdir(path, (err, list) => {
12
+ if (err) {
13
+ reject(err);
14
+ return;
15
+ }
16
+ resolve(list);
17
+ });
18
+ });
19
+ });
20
+ }
21
+ export { readSFTPDir };
@@ -0,0 +1,6 @@
1
+ import { Client } from "ssh2";
2
+ /**
3
+ * Upload file
4
+ */
5
+ declare function uploadSFTPFile(client: Client, path: string, content: string): Promise<void>;
6
+ export { uploadSFTPFile };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Upload file
3
+ */
4
+ function uploadSFTPFile(client, path, content) {
5
+ return new Promise((resolve, reject) => {
6
+ client.sftp((err, sftp) => {
7
+ if (err) {
8
+ reject(err);
9
+ return;
10
+ }
11
+ sftp.writeFile(path, content, (err) => {
12
+ if (err) {
13
+ reject(err);
14
+ return;
15
+ }
16
+ resolve();
17
+ });
18
+ });
19
+ });
20
+ }
21
+ export { uploadSFTPFile };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@cyberalien/deploy-utils",
3
+ "type": "module",
4
+ "description": "Functions for deploying stuff.",
5
+ "author": "Vjacheslav Trushkin",
6
+ "version": "0.0.1",
7
+ "license": "UNLICENSED",
8
+ "homepage": "https://cyberalien.dev/",
9
+ "sideEffects": false,
10
+ "main": "lib/index.js",
11
+ "module": "lib/index.js",
12
+ "types": "lib/index.d.ts",
13
+ "files": [
14
+ "lib",
15
+ "*.d.ts"
16
+ ],
17
+ "devDependencies": {
18
+ "@types/node": "^25.6.0",
19
+ "@types/ssh2": "^1.15.5",
20
+ "oxlint": "^1.60.0",
21
+ "tsdown": "^0.21.9",
22
+ "typescript": "^6.0.3",
23
+ "vitest": "^4.1.4"
24
+ },
25
+ "dependencies": {
26
+ "@cyberalien/git-utils": "^0.0.8",
27
+ "ssh2": "^1.17.0"
28
+ },
29
+ "scripts": {
30
+ "lint": "oxlint --fix src/**/*.ts && tsc --noemit",
31
+ "prebuild": "pnpm run lint",
32
+ "build": "tsdown",
33
+ "test": "vitest"
34
+ }
35
+ }