Skip to content

Commit

Permalink
fixed autoSync issue
Browse files Browse the repository at this point in the history
  • Loading branch information
randilfernando committed Apr 1, 2024
1 parent af685c1 commit fdd3701
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudimpl-inc/cpm",
"version": "2.33.3",
"version": "2.33.4",
"description": "CloudImpl Project Manager",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
18 changes: 14 additions & 4 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ export const createFile = (path: string, def: string | (() => string)) => {
}
}

export const readFile = (path: string, def: string | (() => string)) => {
if (existsSync(path)) {
return readFileSync(path).toString();
} else {
if (typeof def === 'function') {
return def();
} else {
return def;
}
}
}

export const readJson = (path: string, def: any | (() => any)): any => {
if (existsSync(path)) {
const data = readFileSync(path);
Expand Down Expand Up @@ -423,7 +435,7 @@ export const calculateFilesMD5Sync = (filePaths: string[]): string => {
try {
const hash = crypto.createHash('md5');
for (const filePath of filePaths) {
const fileData = fs.readFileSync(filePath);
const fileData = Buffer.from(readFile(filePath, ''));
hash.update(fileData);
}
return hash.digest('hex');
Expand All @@ -444,9 +456,7 @@ export const autoSync = async (config: CPMConfig) => {
if (isProjectRepo) {
const files = [configFilePath, variablesFilePath, packageLockJsonFile];
const fileHash = calculateFilesMD5Sync(files).trim();
const savedHash = (existsSync(hashFilePath))
? readFileSync(hashFilePath).toString().trim()
: '';
const savedHash = readFile(hashFilePath, '');

if (fileHash !== savedHash) {
await syncProject(config);
Expand Down

0 comments on commit fdd3701

Please sign in to comment.