Skip to content

Commit

Permalink
refactor(preset): catch doc updated time get logic
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Mar 2, 2020
1 parent a44e9c8 commit e47c2ac
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/preset-dumi/src/transformer/remark/yaml.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs';
import path from 'path';
import yaml from 'js-yaml';
import slash from 'slash2';
Expand All @@ -11,16 +12,19 @@ export default function yamlProcessor() {
const filePath = slash(path.relative(process.cwd(), this.data('fileAbsPath')));

// append file info
Object.assign(vFile.data, {
filePath,
updatedTime:
vFile.data.filePath = filePath;

try {
vFile.data.updatedTime =
parseInt(
execSync(`git log -1 --format=%at ${this.data('fileAbsPath')}`, {
stdio: 'pipe',
}).toString(),
10,
) * 1000,
});
) * 1000;
} catch (err) {
vFile.data.updatedTime = Math.floor(fs.lstatSync(this.data('fileAbsPath')).mtimeMs);
}
}

visit(ast, 'yaml', node => {
Expand Down

0 comments on commit e47c2ac

Please sign in to comment.