This commit is contained in:
2025-09-02 13:05:14 -04:00
parent 7aa1d7d879
commit 7b8a026849
2 changed files with 32 additions and 3 deletions
+31 -2
View File
@@ -31,10 +31,40 @@ export const getEncryptionKeyForEnv = (envKey) => {
return encryptionKey;
};
export async function isFileOlder(fileA, fileB) {
try {
// Check if both files exist
await fs.access(fileA);
await fs.access(fileB);
// Get stats for both
const statA = await fs.stat(fileA);
const statB = await fs.stat(fileB);
// Compare modification times
return statA.mtime > statB.mtime;
} catch (err) {
console.error('Error:', err.message);
return false; // or throw err depending on use case
}
}
export const decryptFile = async (absFilePath) => {
if (!fs.existsSync(absFilePath)) {
logger.error(`Secret ${absFilePath} is not exist`);
}
const absDirPath = path.dirname(absFilePath);
const fileName = path.basename(absFilePath).replace(".json", "");
const decryptFileJsonPath = `${absDirPath}/~~decrypt/${fileName}.json`
if (fs.existsSync(decryptFileJsonPath) ) {
const isOlderThanOriginal = await isFileOlder(decryptFileJsonPath, absFilePath)
if(isOlderThanOriginal) {
logger.log(`decrypt file-secret for ${absFilePath} no need skip`);
const decryptedSecretObj = await fs.readJSON(decryptFileJsonPath )
return decryptedSecretObj
}
}
logger.log(`decrypt file-secret for ${absFilePath} start`);
const secretFileObjRaw = await fs.readFile(absFilePath, "utf8");
@@ -59,8 +89,7 @@ export const decryptFile = async (absFilePath) => {
shFormatDecrypt += `export ${key}="${decryptedSecretObj[key]}"\n`;
});
const absDirPath = path.dirname(absFilePath);
const fileName = path.basename(absFilePath).replace(".json", "");
if (!fs.existsSync(`${absDirPath}/~~decrypt`)) {
fs.mkdirSync(`${absDirPath}/~~decrypt`, { recursive: true });
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "jj-command-line",
"description": "jj cli",
"version": "1.0.28",
"version": "1.0.29",
"author": "Jason Jafari",
"bin": {
"jj": "./jj.sh"