This commit is contained in:
2024-11-13 18:10:46 -05:00
parent 8890ccf3ea
commit b3ddbc6e8e
6 changed files with 157 additions and 11 deletions
+57
View File
@@ -1,6 +1,9 @@
import AES from 'crypto-js/AES';
import CryptoJS from 'crypto-js';
import crypto from "crypto"
import * as hashFolderModule from "folder-hash"
export const jjDecrypt = (encryptedText, key) => {
const bytes = CryptoJS.AES.decrypt(encryptedText, key);
@@ -14,3 +17,57 @@ export const jjEncrypt = (text, key) => {
return AES.encrypt(text, key).toString();
};
export const generateMD5 = (input) => {
return crypto.createHash("md5").update(input).digest("hex");
};
export function generateSha1(str) {
return crypto.createHash("sha1").update(str).digest("hex")
}
export async function generateHasDir(dir, excludeFoldersExtra = [], excludeFilesExtra = []) {
// @see https://www.npmjs.com/package/folder-hash
let sourceHashes = null
try {
sourceHashes = await hashFolderModule.hashElement(dir, {
encoding: "hex",
folders: {
ignoreRootName: true,
exclude: [
"node_modules",
"dist",
"build",
".next",
".git",
"*~~",
...excludeFoldersExtra
],
},
files: {
exclude: [
".DS_Store",
"**.DS_Store",
".env",
...excludeFilesExtra
],
matchBasename: true,
matchPath: false,
ignoreRootName: true,
},
symbolicLinks: {
ignoreTargetPath: false,
ignoreTargetContent: true,
},
})
} catch (err) {
if (err.code === "EMFILE") {
throw new Error(`Too many open file descriptors! Increase the max open file descriptors limit for your operating system.`)
}
throw err
}
return sourceHashes
}
+28
View File
@@ -0,0 +1,28 @@
import { bashRunAndReturnSync } from "./bashUtils"
import { makeJJlogger } from "./jjLogger"
const logger = makeJJlogger({
filename: 'helpers/gitSubRepoUtils.ts'
})
export const subRepositoryClean = async (subRepoRelPath) => {
const repo = `${process.env.JJ_WORKSPACE_DIR}/${subRepoRelPath}`
logger.log(`clean repository ${repo} start`)
const command = `
pushd "${repo}" > /dev/null
git stash --include-untracked || true
git clean -f -X -e ".~envFormat" -e ".~jsonFormat" -e ".~shellFormat" || true
git clean -f -x -e ".~envFormat" -e ".~jsonFormat" -e ".~shellFormat" || true
git clean -xdf -e ".~envFormat" -e ".~jsonFormat" -e ".~shellFormat" || true
git reset --hard || true
popd > /dev/null
`
const res = await bashRunAndReturnSync({
command: ""
})
logger.log(res)
logger.success(`clean repository ${repo} done`)
}
+1 -1
View File
@@ -78,7 +78,7 @@ export const jjCliYargs = (cli = true) => {
envsObj[`JJ_CLI_OPTIONS`] = JSON.stringify(allOptionsMap)
if(!envsObj['JJ_CLI_OPTION_COMMIT']){
envsObj['JJ_CLI_SELECTED_COMMIT'] = envsObj['JJ_WORKSPACE_CURRENT_COMMIT']
envsObj['JJ_CLI_SELECTED_COMMIT'] = process.env['JJ_WORKSPACE_CURRENT_COMMIT']
} else {
envsObj['JJ_CLI_SELECTED_COMMIT'] = envsObj['JJ_CLI_OPTION_COMMIT']
}