zurik 1.0.2 → 1.0.3

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/bin/zurik.js CHANGED
@@ -1,21 +1,74 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import * as readline from "readline";
3
4
  import encryptFiles from "../lib/encrypt.js";
4
5
  import decryptFiles from "../lib/decrypt.js";
5
6
 
6
7
  const args = process.argv.slice(2);
7
8
 
8
- function extractPassword() {
9
+
10
+ function readPassword() {
11
+ return new Promise((resolve) => {
12
+ const rl = readline.createInterface({
13
+ input: process.stdin,
14
+ output: process.stdout,
15
+ terminal: false
16
+ });
17
+
18
+ if (process.stdin.isTTY) {
19
+ process.stdin.setRawMode(true);
20
+ }
21
+
22
+ process.stdout.write("Password: ");
23
+
24
+ let password = "";
25
+
26
+ process.stdin.on("data", (char) => {
27
+ char = char.toString();
28
+
29
+ if (char === "\n" || char === "\r" || char === "\u0004") {
30
+ process.stdin.pause();
31
+ if (process.stdin.isTTY) {
32
+ process.stdin.setRawMode(false);
33
+ }
34
+ rl.close();
35
+ console.log();
36
+ resolve(password);
37
+ } else if (char === "\u007f" || char === "\b") {
38
+ // Backspace
39
+ if (password.length > 0) {
40
+ password = password.slice(0, -1);
41
+ process.stdout.clearLine(0);
42
+ process.stdout.cursorTo(0);
43
+ process.stdout.write("Password: " + "*".repeat(password.length));
44
+ }
45
+ } else if (char === "\u0003") {
46
+ // Ctrl+C
47
+ console.log();
48
+ process.exit(0);
49
+ } else {
50
+ password += char;
51
+ process.stdout.write("*");
52
+ }
53
+ });
54
+ });
55
+ }
56
+
57
+
58
+ async function extractPassword() {
9
59
  const pIndex = args.indexOf("-p");
10
- if (pIndex !== -1 && args[pIndex + 1]) {
11
- return args[pIndex + 1];
60
+ if (pIndex !== -1) {
61
+ if (args[pIndex + 1] && !args[pIndex + 1].startsWith("-")) {
62
+ return args[pIndex + 1];
63
+ }
64
+
65
+ return await readPassword()
12
66
  }
13
67
  return process.env.ZURIK_PASSWORD || null;
14
68
  }
15
69
 
16
-
17
70
  async function run() {
18
- const password = extractPassword();
71
+ const password = await extractPassword();
19
72
  if (!password) {
20
73
  console.error("Missing password. Use -p <password> or set ZURIK_PASSWORD environment variable.");
21
74
  process.exit(1);
package/lib/encrypt.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import fs from "fs";
2
- import path from "path";
3
2
  import { encryptData } from "./crypto.js";
4
3
 
5
4
  export default async function encryptFiles(password) {
@@ -15,6 +14,10 @@ export default async function encryptFiles(password) {
15
14
  .map(x => x.trim())
16
15
  .filter(Boolean);
17
16
 
17
+ if (fileList.length === 0) {
18
+ throw new Error("No files listed in .gitencrypt");
19
+ }
20
+
18
21
  const bundle = { version: 1, files: {} };
19
22
 
20
23
  for (const filePath of fileList) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zurik",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "CLI tool for encrypting and decrypting sensitive project files into a single .zurik bundle.",
5
5
  "type": "module",
6
6
  "bin": {
package/readme.md CHANGED
@@ -22,6 +22,9 @@ npm install -g zurik
22
22
 
23
23
  # also you can pass the password as an argument
24
24
  npx zurik -e -p "your-password"
25
+
26
+ # or you can type the password interactively
27
+ npx zurik -e -p
25
28
  ```
26
29
 
27
30
  ## Usage