Skip to content

Commit ea59e22

Browse files
committed
fix(date): using the date-fns lib
1 parent 7133eb0 commit ea59e22

File tree

4 files changed

+84
-4016
lines changed

4 files changed

+84
-4016
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"chalk-template": "1.1.0",
101101
"chrome-trace-event": "^1.0.4",
102102
"color-name": "2.0.0",
103+
"date-fns": "4.1.0",
103104
"dotenv": "^16.4.7",
104105
"dotenv-flow": "4.1.0",
105106
"download": "8.0.0",

pnpm-lock.yaml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/kit.ts

+58-58
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ export async function initTrace() {
107107
}
108108

109109
global.trace ||= {
110-
begin: () => {},
111-
end: () => {},
112-
instant: () => {},
113-
flush: () => {},
110+
begin: () => { },
111+
end: () => { },
112+
instant: () => { },
113+
flush: () => { },
114114
enabled: false
115115
}
116116

@@ -147,10 +147,10 @@ export let errorPrompt = async (error: Error) => {
147147
if (secondLine?.match('at file://')) {
148148
if (isWin) {
149149
errorFile = path.normalize(secondLine.replace('at file:///', '').replace(/:\d+/g, '').trim())
150-
;[, , line, col] = secondLine.replace('at file:///', '').split(':')
150+
;[, , line, col] = secondLine.replace('at file:///', '').split(':')
151151
} else {
152152
errorFile = secondLine.replace('at file://', '').replace(/:.*/, '').trim()
153-
;[, line, col] = secondLine.replace('at file://', '').split(':')
153+
;[, line, col] = secondLine.replace('at file://', '').split(':')
154154
}
155155
}
156156

@@ -264,7 +264,7 @@ global.silentAttemptImport = async (scriptPath, ..._args) => {
264264
let href = pathToFileURL(scriptPath).href
265265
let kitImport = `${href}?now=${Date.now()}.kit`
266266
importResult = await import(kitImport)
267-
} catch (error) {}
267+
} catch (error) { }
268268

269269
return importResult
270270
}
@@ -1085,23 +1085,23 @@ export let actions: Action[] = [
10851085
let helpActions: Action[] = [
10861086
...(loggedIn
10871087
? [
1088-
{
1089-
name: 'Sign Out',
1090-
description: 'Sign out of Script Kit',
1091-
onAction: async () => {
1092-
await deauthenticate()
1093-
}
1088+
{
1089+
name: 'Sign Out',
1090+
description: 'Sign out of Script Kit',
1091+
onAction: async () => {
1092+
await deauthenticate()
10941093
}
1095-
]
1094+
}
1095+
]
10961096
: [
1097-
{
1098-
name: 'Sign In',
1099-
description: 'Sign in to Script Kit',
1100-
onAction: async () => {
1101-
await run(kitPath('main', 'account-v2.js'))
1102-
}
1097+
{
1098+
name: 'Sign In',
1099+
description: 'Sign in to Script Kit',
1100+
onAction: async () => {
1101+
await run(kitPath('main', 'account-v2.js'))
11031102
}
1104-
]),
1103+
}
1104+
]),
11051105
{
11061106
name: 'Read Docs',
11071107
description: 'Read the docs',
@@ -1190,8 +1190,8 @@ export let scriptFlags: FlagsObject = {
11901190
let compileMessage = stamp?.compileMessage?.trim() || ''
11911191
let compileStamp = stamp?.compileStamp
11921192
? `Last compiled: ${formatDistanceToNow(new Date(stamp?.compileStamp), {
1193-
addSuffix: false
1194-
})} ago`
1193+
addSuffix: false
1194+
})} ago`
11951195
: ''
11961196
let executionTime = stamp?.executionTime ? `Last run duration: ${stamp?.executionTime}ms` : ''
11971197
let runCount = stamp?.runCount ? `Run count: ${stamp?.runCount}` : ''
@@ -1213,13 +1213,13 @@ export let scriptFlags: FlagsObject = {
12131213
let lastRunDate = new Date(stamp.timestamp)
12141214
lastRunBlock = `### Last Run
12151215
- ${lastRunDate.toLocaleString()}
1216-
- ${formatDistanceToNow(lastRunDate)} ago
1216+
- ${formatDistanceToNow(lastRunDate, { addSuffix: false })} ago
12171217
`.trim()
12181218
}
12191219

12201220
let modifiedBlock = `### Last Modified
12211221
- ${lastModified.toLocaleString()}
1222-
- ${formatDistanceToNow(lastModified)} ago`
1222+
- ${formatDistanceToNow(lastModified, { addSuffix: false })} ago`
12231223

12241224
let info = md(
12251225
`# Stats
@@ -1497,9 +1497,9 @@ export let getApps = async () => {
14971497
export let splitEnvVarIntoArray = (envVar: string | undefined, fallback: string[]) => {
14981498
return envVar
14991499
? envVar
1500-
.split(',')
1501-
.map((s) => s.trim())
1502-
.filter(Boolean)
1500+
.split(',')
1501+
.map((s) => s.trim())
1502+
.filter(Boolean)
15031503
: fallback
15041504
}
15051505

@@ -1803,49 +1803,49 @@ export let processPreviewPath = (s: Script) => {
18031803

18041804
export let processScriptPreview =
18051805
(script: Script, infoBlock = '') =>
1806-
async () => {
1807-
if ((script as Scriptlet)?.scriptlet) {
1808-
return script.preview
1809-
}
1810-
let previewPath = getPreviewPath(script)
1811-
let preview = ``
1806+
async () => {
1807+
if ((script as Scriptlet)?.scriptlet) {
1808+
return script.preview
1809+
}
1810+
let previewPath = getPreviewPath(script)
1811+
let preview = ``
18121812

1813-
if (await isFile(previewPath)) {
1814-
preview = await processWithPreviewFile(script, previewPath, infoBlock)
1815-
} else if (typeof script?.preview === 'string') {
1816-
preview = await processWithStringPreview(script, infoBlock)
1817-
} else {
1818-
preview = await processWithNoPreview(script, infoBlock)
1819-
}
1813+
if (await isFile(previewPath)) {
1814+
preview = await processWithPreviewFile(script, previewPath, infoBlock)
1815+
} else if (typeof script?.preview === 'string') {
1816+
preview = await processWithStringPreview(script, infoBlock)
1817+
} else {
1818+
preview = await processWithNoPreview(script, infoBlock)
1819+
}
18201820

1821-
return preview
1822-
}
1821+
return preview
1822+
}
18231823

18241824
// TODO: The logic around scripts + stats/timestamps is confusing. Clean it up.
18251825
export let processScript =
18261826
(timestamps: Stamp[] = []) =>
1827-
async (s: Script): Promise<Script> => {
1828-
let stamp = timestamps.find((t) => t.filePath === s.filePath)
1827+
async (s: Script): Promise<Script> => {
1828+
let stamp = timestamps.find((t) => t.filePath === s.filePath)
18291829

1830-
let infoBlock = ``
1831-
if (stamp) {
1832-
s.compileStamp = stamp.compileStamp
1833-
s.compileMessage = stamp.compileMessage
1834-
s.timestamp = stamp.timestamp
1830+
let infoBlock = ``
1831+
if (stamp) {
1832+
s.compileStamp = stamp.compileStamp
1833+
s.compileMessage = stamp.compileMessage
1834+
s.timestamp = stamp.timestamp
18351835

1836-
if (stamp.compileMessage && stamp.compileStamp) {
1837-
infoBlock = `~~~
1836+
if (stamp.compileMessage && stamp.compileStamp) {
1837+
infoBlock = `~~~
18381838
⚠️ Last compiled ${formatDistanceToNow(new Date(stamp.compileStamp), {
18391839
addSuffix: false
18401840
})} ago`
1841+
}
1842+
}
1843+
if (!(s as Scriptlet)?.scriptlet) {
1844+
s.preview = processScriptPreview(s, infoBlock) as () => Promise<string>
18411845
}
1842-
}
1843-
if (!(s as Scriptlet)?.scriptlet) {
1844-
s.preview = processScriptPreview(s, infoBlock) as () => Promise<string>
1845-
}
18461846

1847-
return s
1848-
}
1847+
return s
1848+
}
18491849

18501850
export let getPreviewPath = (s: Script): string => {
18511851
if (s?.previewPath) {

0 commit comments

Comments
 (0)