test02/node_modules/@vuepress/plugin-git/lib/node/utils/getUpdatedTime.js
罗佳鸿 6aa1ebe342
Some checks are pending
部署文档 / deploy-gh-pages (push) Waiting to run
first commit
2024-08-13 10:11:19 +08:00

19 lines
534 B
JavaScript

import { execa } from 'execa';
/**
* Get unix timestamp in milliseconds of the last commit
*/
export const getUpdatedTime = async (filePaths, cwd) => {
const { stdout } = await execa('git', [
'--no-pager',
'log',
'--format=%at',
// if there is only one file to be included, add `-1` option
...(filePaths.length > 1 ? [] : ['-1']),
...filePaths,
], {
cwd,
});
return (Math.max(...stdout.split('\n').map((item) => Number.parseInt(item, 10))) *
1000);
};