Skip to content

Commit

Permalink
auto sync issue fixed (consider package-lock.json changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
randilfernando committed Apr 1, 2024
1 parent bcb649d commit 889b940
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 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.1",
"version": "2.33.2",
"description": "CloudImpl Project Manager",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
20 changes: 10 additions & 10 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if (cwd !== process.cwd()) {
export const folderPath = `${cwd}/.cpm`;
export const configFilePath = `${cwd}/cpm.yml`;
export const packageJsonFile = `${folderPath}/package.json`;
export const packageLockJsonFile = `${folderPath}/package-lock.json`;
export const variablesFilePath = `${folderPath}/variables.json`;
export const secretsFilePath = `${folderPath}/_secrets.json`;
export const pluginRoot = `${folderPath}/node_modules`;
Expand All @@ -32,6 +33,7 @@ export const isProjectRepo = existsSync(configFilePath);
export const globalFolderPath = `${os.homedir()}/.cpm`;
export const globalConfigFilePath = `${globalFolderPath}/cpm.yml`;
export const globalPackageJsonFile = `${globalFolderPath}/package.json`;
export const globalPackageLockJsonFile = `${globalFolderPath}/package-lock.json`;
export const globalVariablesFilePath = `${globalFolderPath}/variables.json`;
export const globalSecretsFilePath = `${globalFolderPath}/_secrets.json`;
export const globalPluginRoot = `${globalFolderPath}/node_modules`;
Expand Down Expand Up @@ -417,10 +419,13 @@ export const syncProject = async (config: CPMConfig) => {
}
}

export const calculateFileMD5Sync = (filePath: string): string => {
export const calculateFilesMD5Sync = (filePaths: string[]): string => {
try {
const fileData = fs.readFileSync(filePath);
const hash = crypto.createHash('md5').update(fileData);
const hash = crypto.createHash('md5');
for (const filePath of filePaths) {
const fileData = fs.readFileSync(filePath);
hash.update(fileData);
}
return hash.digest('hex');
} catch (error) {
throw new Error(`Error calculating MD5 hash: ${error}`);
Expand All @@ -437,7 +442,8 @@ export const autoSync = async (config: CPMConfig) => {
}

if (isProjectRepo) {
const fileHash = calculateFileMD5Sync(configFilePath).trim();
const files = [configFilePath, variablesFilePath, packageLockJsonFile];
const fileHash = calculateFilesMD5Sync(files).trim();
const savedHash = (existsSync(hashFilePath))
? readFileSync(hashFilePath).toString().trim()
: '';
Expand All @@ -450,12 +456,6 @@ export const autoSync = async (config: CPMConfig) => {
}
}

// Function to determine the shell
const getShell = (): 'zsh' | 'bash' => {
const shellPath: string = process.env.SHELL || '';
return shellPath.includes('zsh') ? 'zsh' : 'bash';
};

export const getSelection = async (message: string, list: { id: string, name: string }[]) => {
const options: string[] = [];
const idMapping: Record<string, string> = {};
Expand Down

0 comments on commit 889b940

Please sign in to comment.