mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 00:57:53 +02:00
refactor(content-docs): use shelljs instead of execa (#5904)
This commit is contained in:
parent
13d07eff13
commit
334b4397e7
3 changed files with 7 additions and 15 deletions
|
@ -40,7 +40,7 @@ describe('lastUpdate', () => {
|
|||
expect(await getFileLastUpdate(nonExistingFilePath)).toBeNull();
|
||||
expect(consoleMock).toHaveBeenCalledTimes(1);
|
||||
expect(consoleMock.mock.calls[0][0].message).toContain(
|
||||
`Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFileName}`,
|
||||
`fatal: ambiguous argument '${nonExistingFilePath}': unknown revision or path not in the working tree.`,
|
||||
);
|
||||
expect(await getFileLastUpdate(null)).toBeNull();
|
||||
expect(await getFileLastUpdate(undefined)).toBeNull();
|
||||
|
|
|
@ -6,12 +6,10 @@
|
|||
*/
|
||||
|
||||
import shell from 'shelljs';
|
||||
import execa from 'execa';
|
||||
import path from 'path';
|
||||
|
||||
type FileLastUpdateData = {timestamp?: number; author?: string};
|
||||
|
||||
const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(\d+), (.+)$/;
|
||||
const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(\d+),(.+)$/;
|
||||
|
||||
let showedGitRequirementError = false;
|
||||
|
||||
|
@ -44,16 +42,11 @@ export async function getFileLastUpdate(
|
|||
return null;
|
||||
}
|
||||
|
||||
const fileBasename = path.basename(filePath);
|
||||
const fileDirname = path.dirname(filePath);
|
||||
const {stdout} = await execa(
|
||||
'git',
|
||||
['log', '-1', '--format=%ct, %an', fileBasename],
|
||||
{
|
||||
cwd: fileDirname,
|
||||
},
|
||||
);
|
||||
return getTimestampAndAuthor(stdout);
|
||||
const result = shell.exec(`git log -1 --format=%ct,%an ${filePath}`);
|
||||
if (result.stderr) {
|
||||
throw new Error(result.stderr);
|
||||
}
|
||||
return getTimestampAndAuthor(result.stdout.trim());
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue