From cd97d618f238a2309458378cf15da5c6fc5e554e Mon Sep 17 00:00:00 2001 From: dword Date: Thu, 18 Mar 2021 14:49:49 +0000 Subject: [PATCH] fix: fix createdAt calculation --- package.json | 2 +- src/index.js | 5 ++++- src/index.spec.js | 9 ++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 0551982..7580cfe 100644 --- a/package.json +++ b/package.json @@ -20,11 +20,11 @@ "test": "base test" }, "dependencies": { + "@dword-design/functions": "^1.2.2", "simple-git": "^2.37.0" }, "devDependencies": { "@dword-design/base": "^7.9.0", - "@dword-design/functions": "^1.2.2", "@dword-design/puppeteer": "^3.0.1", "@dword-design/tester": "^1.2.1", "@dword-design/tester-plugin-puppeteer": "^1.0.3", diff --git a/src/index.js b/src/index.js index da49896..9d13187 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ +import { last, property } from '@dword-design/functions' import P from 'path' import simpleGit from 'simple-git' @@ -14,7 +15,9 @@ export default options => { file: P.join(database.dir, `${file.path}${file.extension}`), }) file[options.createdAtName] = - log.all.length > 0 ? new Date(log.all[0].date) : file.createdAt + log.all.length > 0 + ? new Date(log.all |> last |> property('date')) + : file.createdAt file[options.updatedAtName] = log.latest === null ? file.updatedAt : new Date(log.latest.date) }, diff --git a/src/index.spec.js b/src/index.spec.js index 52c2dce..f587719 100644 --- a/src/index.spec.js +++ b/src/index.spec.js @@ -1,9 +1,9 @@ -import { endent } from '@dword-design/functions' +import { endent, last, property } from '@dword-design/functions' import tester from '@dword-design/tester' import testerPluginPuppeteer from '@dword-design/tester-plugin-puppeteer' import packageName from 'depcheck-package-name' import execa from 'execa' -import { stat } from 'fs-extra' +import { outputFile, stat } from 'fs-extra' import { Builder, Nuxt } from 'nuxt' import outputFiles from 'output-files' import P from 'path' @@ -146,9 +146,12 @@ export default tester( }) await execa.command('git add .') await execa.command('git commit -m init') + await outputFile(P.join('content', 'home.md'), 'foo') + await execa.command('git add .') + await execa.command('git commit -m update') const git = simpleGit() const log = await git.log({ file: P.join('content', 'home.md') }) - const createdAt = new Date(log.all[0].date) + const createdAt = new Date(log.all |> last |> property('date')) const updatedAt = new Date(log.latest.date) const nuxt = new Nuxt({ createRequire: 'native',