@saasak/tool-env 1.0.1 → 1.0.2
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/index.js +17 -12
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
1
3
|
import minimist from 'minimist';
|
|
2
4
|
import fs from 'fs-extra';
|
|
3
5
|
import path from 'path';
|
|
@@ -164,27 +166,30 @@ async function encryptCommand() {
|
|
|
164
166
|
}
|
|
165
167
|
|
|
166
168
|
async function besafeCommand() {
|
|
167
|
-
|
|
169
|
+
// Find git root to ensure we're in a repository and use correct base path
|
|
170
|
+
const { stdout: gitRoot, exitCode: gitCheck } = await execa('git', ['rev-parse', '--show-toplevel'], { cwd: __root, reject: false });
|
|
171
|
+
if (gitCheck !== 0) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
168
174
|
|
|
169
|
-
|
|
170
|
-
const { stdout: stagedDiff } = await execa('git', ['diff', '--cached', '--name-only', '--', relativeEnvPath], { cwd: __root, reject: false });
|
|
171
|
-
const { stdout: unstagedDiff } = await execa('git', ['diff', '--name-only', '--', relativeEnvPath], { cwd: __root, reject: false });
|
|
172
|
-
const { stdout: untracked } = await execa('git', ['ls-files', '--others', '--exclude-standard', '--', relativeEnvPath], { cwd: __root, reject: false });
|
|
175
|
+
const relativeEnvPath = path.relative(gitRoot, envFile);
|
|
173
176
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
177
|
+
// Check if file has any changes (staged, unstaged, or untracked)
|
|
178
|
+
const { stdout: staged } = await execa('git', ['diff', '--cached', '--name-only', '--', relativeEnvPath], { cwd: gitRoot, reject: false });
|
|
179
|
+
const { stdout: unstaged } = await execa('git', ['diff', '--name-only', '--', relativeEnvPath], { cwd: gitRoot, reject: false });
|
|
180
|
+
const { stdout: untracked } = await execa('git', ['ls-files', '--others', '--exclude-standard', '--', relativeEnvPath], { cwd: gitRoot, reject: false });
|
|
181
|
+
|
|
182
|
+
if (!staged?.trim() && !unstaged?.trim() && !untracked?.trim()) {
|
|
178
183
|
return;
|
|
179
184
|
}
|
|
180
185
|
|
|
181
|
-
await
|
|
186
|
+
await encryptCommand();
|
|
182
187
|
|
|
183
188
|
if (!secret) {
|
|
184
|
-
console.error('Warning: potential security risk: secret not provided. Variables WERE NOT
|
|
189
|
+
console.error('Warning: potential security risk: secret not provided. Variables WERE NOT encrypted.');
|
|
185
190
|
}
|
|
186
191
|
|
|
187
|
-
await execa('git', ['add', relativeEnvPath], { cwd:
|
|
192
|
+
await execa('git', ['add', relativeEnvPath], { cwd: gitRoot });
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
async function addCommand() {
|