@typinghare/trick 1.0.3 → 1.0.6

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/dist/app.js CHANGED
@@ -6,7 +6,7 @@ import { TRICK_ENCRYPTED_DIR } from './constant.js';
6
6
  import fsExtra from 'fs-extra';
7
7
  import chalk from 'chalk';
8
8
  const program = new Command();
9
- program.version('Trick v1.0.3 \nby James Chen (jameschan312.cn@gmail.com)');
9
+ program.version('Trick v1.0.6');
10
10
  program.description('Save credential files to remote safely.');
11
11
  program
12
12
  .command('add')
package/dist/encrypt.js CHANGED
@@ -36,7 +36,7 @@ export async function encryptFile(srcFilePath, destFilePath, secret, iteration_c
36
36
  '-out',
37
37
  destFilePath,
38
38
  '-pass',
39
- `pass:${secret}`,
39
+ `'pass:${secret}'`,
40
40
  ].join(' ');
41
41
  await fsExtra.ensureDir(path.dirname(destFilePath));
42
42
  try {
@@ -47,7 +47,7 @@ export async function encryptFile(srcFilePath, destFilePath, secret, iteration_c
47
47
  throw new FailToEncryptFileError(srcFilePath, err.stderr);
48
48
  }
49
49
  else {
50
- throw new FailToDecryptFileError(srcFilePath, "Unknown error when encrypting the file.");
50
+ throw new FailToDecryptFileError(srcFilePath, 'Unknown error when encrypting the file.');
51
51
  }
52
52
  }
53
53
  }
@@ -69,7 +69,7 @@ export async function decryptFile(srcFilePath, destFilePath, secret, iteration_c
69
69
  '-out',
70
70
  srcFilePath,
71
71
  '-pass',
72
- `pass:${secret}`,
72
+ `'pass:${secret}'`,
73
73
  ].join(' ');
74
74
  await fsExtra.ensureDir(path.dirname(srcFilePath));
75
75
  try {
@@ -80,20 +80,20 @@ export async function decryptFile(srcFilePath, destFilePath, secret, iteration_c
80
80
  throw new FailToDecryptFileError(srcFilePath, err['stderr']);
81
81
  }
82
82
  else {
83
- throw new FailToDecryptFileError(srcFilePath, "Unknown error when decrypting the file.");
83
+ throw new FailToDecryptFileError(srcFilePath, 'Unknown error when decrypting the file.');
84
84
  }
85
85
  }
86
86
  }
87
87
  export async function encryptFiles(srcFilePaths, destDir, secret, iteration_count) {
88
88
  for (const srcFilePath of srcFilePaths) {
89
- const destFilePath = path.join(destDir, srcFilePath);
89
+ const destFilePath = path.join(destDir, srcFilePath + '.enc');
90
90
  await encryptFile(srcFilePath, destFilePath, secret, iteration_count);
91
91
  console.log(`[ENCRYPTED] ${srcFilePath} -> ${destFilePath}`);
92
92
  }
93
93
  }
94
94
  export async function decryptFiles(srcFilePaths, destDir, secret, iteration_count) {
95
95
  for (const srcFilePath of srcFilePaths) {
96
- const destFilePath = path.join(destDir, srcFilePath);
96
+ const destFilePath = path.join(destDir, srcFilePath + '.enc');
97
97
  await decryptFile(srcFilePath, destFilePath, secret, iteration_count);
98
98
  console.log(`[DECRYPTED] ${destFilePath} -> ${srcFilePath}`);
99
99
  }
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@typinghare/trick",
3
3
  "description": "Save credential files to remote safely.",
4
- "version": "1.0.3",
4
+ "version": "1.0.6",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "bin": {
9
9
  "trick": "bin/trick"
10
10
  },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "publish": "rm -rf dist && tsc && pnpm publish --access public"
14
+ },
11
15
  "author": {
12
16
  "name": "James Chen",
13
17
  "email": "jameschan312.cn@gmail.com"
@@ -23,8 +27,5 @@
23
27
  "devDependencies": {
24
28
  "@types/fs-extra": "^11.0.4",
25
29
  "prettier": "^3.3.3"
26
- },
27
- "scripts": {
28
- "build": "tsc"
29
30
  }
30
- }
31
+ }
package/src/app.ts CHANGED
@@ -20,7 +20,7 @@ import chalk from 'chalk'
20
20
 
21
21
  const program = new Command()
22
22
 
23
- program.version('Trick v1.0.3 \nby James Chen (jameschan312.cn@gmail.com)')
23
+ program.version('Trick v1.0.6')
24
24
  program.description('Save credential files to remote safely.')
25
25
 
26
26
  program
package/src/encrypt.ts CHANGED
@@ -1,15 +1,21 @@
1
- import {execa} from 'execa'
1
+ import { execa } from 'execa'
2
2
  import * as path from 'node:path'
3
3
  import fsExtra from 'fs-extra'
4
4
 
5
5
  export class FailToEncryptFileError extends Error {
6
- public constructor(public readonly srcFilePath: string, public readonly opensslErrMessage?: string) {
6
+ public constructor(
7
+ public readonly srcFilePath: string,
8
+ public readonly opensslErrMessage?: string
9
+ ) {
7
10
  super(`Fail to encrypt source file: ${srcFilePath}`)
8
11
  }
9
12
  }
10
13
 
11
14
  export class FailToDecryptFileError extends Error {
12
- public constructor(public readonly destFilePath: string, public readonly opensslErrMessage?: string) {
15
+ public constructor(
16
+ public readonly destFilePath: string,
17
+ public readonly opensslErrMessage?: string
18
+ ) {
13
19
  super(`Fail to decrypt destination file: ${destFilePath}`)
14
20
  }
15
21
  }
@@ -37,18 +43,28 @@ export async function encryptFile(
37
43
  '-out',
38
44
  destFilePath,
39
45
  '-pass',
40
- `pass:${secret}`,
46
+ `'pass:${secret}'`,
41
47
  ].join(' ')
42
48
 
43
49
  await fsExtra.ensureDir(path.dirname(destFilePath))
44
50
 
45
51
  try {
46
- await execa(`${command}`, {shell: true})
52
+ await execa(`${command}`, { shell: true })
47
53
  } catch (err) {
48
54
  if (typeof err == 'object' && err && Object.hasOwn(err, 'stderr')) {
49
- throw new FailToEncryptFileError(srcFilePath, (err as { stderr: string }).stderr)
55
+ throw new FailToEncryptFileError(
56
+ srcFilePath,
57
+ (
58
+ err as {
59
+ stderr: string
60
+ }
61
+ ).stderr
62
+ )
50
63
  } else {
51
- throw new FailToDecryptFileError(srcFilePath, "Unknown error when encrypting the file.")
64
+ throw new FailToDecryptFileError(
65
+ srcFilePath,
66
+ 'Unknown error when encrypting the file.'
67
+ )
52
68
  }
53
69
  }
54
70
  }
@@ -77,18 +93,28 @@ export async function decryptFile(
77
93
  '-out',
78
94
  srcFilePath,
79
95
  '-pass',
80
- `pass:${secret}`,
96
+ `'pass:${secret}'`,
81
97
  ].join(' ')
82
98
 
83
99
  await fsExtra.ensureDir(path.dirname(srcFilePath))
84
100
 
85
101
  try {
86
- await execa(`${command}`, {shell: true})
102
+ await execa(`${command}`, { shell: true })
87
103
  } catch (err) {
88
104
  if (typeof err == 'object' && err && Object.hasOwn(err, 'stderr')) {
89
- throw new FailToDecryptFileError(srcFilePath, (err as { stderr: string })['stderr'])
105
+ throw new FailToDecryptFileError(
106
+ srcFilePath,
107
+ (
108
+ err as {
109
+ stderr: string
110
+ }
111
+ )['stderr']
112
+ )
90
113
  } else {
91
- throw new FailToDecryptFileError(srcFilePath, "Unknown error when decrypting the file.")
114
+ throw new FailToDecryptFileError(
115
+ srcFilePath,
116
+ 'Unknown error when decrypting the file.'
117
+ )
92
118
  }
93
119
  }
94
120
  }
@@ -100,7 +126,7 @@ export async function encryptFiles(
100
126
  iteration_count: number
101
127
  ): Promise<void> {
102
128
  for (const srcFilePath of srcFilePaths) {
103
- const destFilePath: string = path.join(destDir, srcFilePath)
129
+ const destFilePath: string = path.join(destDir, srcFilePath + '.enc')
104
130
  await encryptFile(srcFilePath, destFilePath, secret, iteration_count)
105
131
  console.log(`[ENCRYPTED] ${srcFilePath} -> ${destFilePath}`)
106
132
  }
@@ -113,7 +139,7 @@ export async function decryptFiles(
113
139
  iteration_count: number
114
140
  ): Promise<void> {
115
141
  for (const srcFilePath of srcFilePaths) {
116
- const destFilePath: string = path.join(destDir, srcFilePath)
142
+ const destFilePath: string = path.join(destDir, srcFilePath + '.enc')
117
143
  await decryptFile(srcFilePath, destFilePath, secret, iteration_count)
118
144
  console.log(`[DECRYPTED] ${destFilePath} -> ${srcFilePath}`)
119
145
  }
package/trick.config.json CHANGED
@@ -2,12 +2,19 @@
2
2
  "iteration_count": 114514,
3
3
  "targets": [
4
4
  {
5
- "secret_name": "ROBLOX_PROJECT_TRICK_SECRET",
5
+ "secret_name": "TRICK_SECRET_NAME",
6
6
  "files": [
7
7
  "test/resources/really.json",
8
8
  "test/resources/task.yml"
9
9
  ]
10
+ },
11
+ {
12
+ "secret_name": "SUPERVISOR_SERVER_TRICK_SECRET_NAME",
13
+ "files": [
14
+ "test/main/resources/database.properties",
15
+ "test/main/resources/password.properties"
16
+ ]
10
17
  }
11
18
  ],
12
- "default_secret_name": "ROBLOX_PROJECT_TRICK_SECRET"
19
+ "default_secret_name": "SUPERVISOR_SERVER_TRICK_SECRET_NAME"
13
20
  }
@@ -1 +0,0 @@
1
- Salted__�;��a��S�K�9ℑ���2�����4�'Q���\0]�G~G01�߯G���
@@ -1 +0,0 @@
1
- Salted__�)�"�K 7�bk��aQ��ܰ^�B9��������.3.�g�!g�$�XjM�q�~q�c76C�i����0�S