Skip to content

Commit

Permalink
log build deps
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs committed Nov 30, 2023
1 parent 375a97d commit 482f841
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
9 changes: 5 additions & 4 deletions src/commands/src/helpers/dependency-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function createEnvProdFile(
);
} catch (e) {
console.error(`ERROR! Could not write to .env.production`);
logger(`ERROR! Could not write to .env.production: ${e}`);
throw e;
}
}
Expand All @@ -62,9 +63,9 @@ export async function prepareBuildAndGetDependencies(

// doing these in parallel
const commandPromises = [
getCommitHash(repoDir),
getCommitBranch(repoDir),
getPatchId(repoDir),
getCommitHash(repoDir, preppedLogger),
getCommitBranch(repoDir, preppedLogger),
getPatchId(repoDir, preppedLogger),
existsAsync(path.join(process.cwd(), 'config/redirects')),
createEnvProdFile(repoDir, projectName, baseUrl, preppedLogger),
];
Expand All @@ -83,7 +84,7 @@ export async function prepareBuildAndGetDependencies(
};
} catch (error) {
console.error('ERROR! Could not get build dependencies');
preppedLogger(`error, could not get build deps`);
preppedLogger(`error, could not get build deps: ${error}`);
throw error;
}
}
49 changes: 30 additions & 19 deletions src/commands/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,38 +255,49 @@ export async function readFileAndExec({
return response;
}

export async function getPatchId(repoDir: string): Promise<string | undefined> {
export async function getPatchId(repoDir: string, logger: (msg: string) => void): Promise<string | undefined> {
const filePath = path.join(repoDir, 'myPatch.patch');
try {
const { outputText: gitPatchId } = await readFileAndExec({ command: 'git', filePath, args: ['patch-id'] });

return gitPatchId.slice(0, 7);
} catch (err) {
console.warn('No patch ID found');
console.warn('No patch ID found: ', +filePath);
logger('No patch ID found: ' + filePath + ' ' + err);
}
}

export async function getCommitBranch(repoDir: string): Promise<string> {
// equivalent to git rev-parse --abbrev-ref HEAD
const response = await executeCliCommand({
command: 'git',
args: ['rev-parse', '--abbrev-ref', 'HEAD'],
options: { cwd: repoDir },
});
export async function getCommitBranch(repoDir: string, logger: (msg: string) => void): Promise<string | undefined> {
try {
// equivalent to git rev-parse --abbrev-ref HEAD
const response = await executeCliCommand({
command: 'git',
args: ['rev-parse', '--abbrev-ref', 'HEAD'],
options: { cwd: repoDir },
});

return response.outputText;
return response.outputText;
} catch (err) {
logger(`commit branch fail: ${err}`);
throw Error;
}
}

export async function getCommitHash(repoDir: string): Promise<string> {
// equivalent to git rev-parse --short HEAD
const response = await executeCliCommand({
command: 'git',
args: ['rev-parse', '--short', 'HEAD'],
options: { cwd: repoDir },
});
console.log('commit hash ', response);
export async function getCommitHash(repoDir: string, logger: (msg: string) => void): Promise<string | undefined> {
try {
// equivalent to git rev-parse --short HEAD
const response = await executeCliCommand({
command: 'git',
args: ['rev-parse', '--short', 'HEAD'],
options: { cwd: repoDir },
});
console.log('commit hash ', response);

return response.outputText;
return response.outputText;
} catch (err) {
logger(`commit hash fail: ${err}`);
throw Error;
}
}

export const checkIfPatched = async (repoDir: string) => !existsAsync(path.join(repoDir, 'myPatch.patch'));
Expand Down

0 comments on commit 482f841

Please sign in to comment.