Skip to content

Commit

Permalink
chore: migrate to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
rnmeow committed Mar 17, 2024
1 parent 5d1b5be commit 6fa7a2c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ author: Yu-huan Kuo <touch@rnmeow.com>
description: Get a quote and save as a file, API by Elegant TW. Works with GitHub Gist.
runs:
using: 'node20'
main: 'dist/index.js'
main: 'dist/index.mjs'
branding:
icon: 'file-text'
color: 'yellow'
7 changes: 0 additions & 7 deletions dist/index.js

This file was deleted.

7 changes: 7 additions & 0 deletions dist/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import{join as n}from"path";import{writeFile as r}from"fs/promises";var e=await fetch("https://v0.elegant.tw/all").then(t=>t.json()),o=`${e.sentence}
\u2014\u2014${e.author!==null?e.author:e.cite}
\u65BC ${new Date().toLocaleString("zh-TW",{timeZone:"Asia/Taipei",hourCycle:"h23"})} \u66F4\u65B0`;console.log(`
${o}
`);try{await r(n(process.cwd(),"quote.txt"),o)}catch(t){console.error(`FATAL: ${t}`),process.exit(1)}console.log(`INFO: \u6210\u529F\u5132\u5B58\u3002
`);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "quote-box-zh_tw",
"private": true,
"version": "0.1.0",
"version": "0.1.2",
"description": "Get a quote and save as a file, API by Elegant TW. Works with GitHub Gist.",
"main": "dist/index.js",
"main": "dist/index.mjs",
"scripts": {
"format": "prettier --check src/index.ts",
"format:fix": "prettier --check src/index.ts --write",
"build": "esbuild src/index.ts --bundle --platform=node --minify --outfile=dist/index.js"
"build": "esbuild src/index.ts --bundle --platform=node --minify --outfile=dist/index.mjs --format=esm"
},
"author": "Yu-huan Kuo <touch@rnmeow.com>",
"license": "MIT",
Expand Down
32 changes: 15 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@ export interface Resp {
sentence: string
}

;(async () => {
const data: Resp = await fetch('https://v0.elegant.tw/all').then((res) =>
res.json(),
)
const data: Resp = await fetch('https://v0.elegant.tw/all').then((res) =>
res.json(),
)

const content = `${data.sentence}
const content = `${data.sentence}
——${data.author !== null ? data.author : data.cite}
${new Date().toLocaleString('zh-TW', {
timeZone: 'Asia/Taipei',
hourCycle: 'h23',
})} 更新`
timeZone: 'Asia/Taipei',
hourCycle: 'h23',
})} 更新`

console.log(`\n${content}\n`)
console.log(`\n${content}\n`)

try {
await writeFile(join(process.cwd(), 'quote.txt'), content)
} catch (err) {
console.error(`FATAL: ${err}`)
process.exit(1)
}
try {
await writeFile(join(process.cwd(), 'quote.txt'), content)
} catch (err) {
console.error(`FATAL: ${err}`)
process.exit(1)
}

console.log('INFO: 成功儲存。\n')
})()
console.log('INFO: 成功儲存。\n')

0 comments on commit 6fa7a2c

Please sign in to comment.