Skip to content

Commit

Permalink
chore: 去除ejs依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
zonemeen committed Jan 29, 2024
1 parent dec1fb2 commit a45e14f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 58 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"cac": "^6.7.14",
"cli-progress": "3.11.2",
"colorette": "2.0.19",
"ejs": "^3.1.9",
"express": "^4.18.2",
"got": "12.3.1",
"inquirer": "^9.2.9",
Expand Down
49 changes: 4 additions & 45 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions src/qrcode/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fileURLToPath } from 'node:url'
import { resolve, dirname, join } from 'node:path'
import { pipeline } from 'node:stream/promises'
import { existsSync, mkdirSync, createWriteStream } from 'node:fs'
import { existsSync, mkdirSync, createWriteStream, readFileSync } from 'node:fs'
import got from 'got'
import portfinder from 'portfinder'
import qrcode from 'qrcode-terminal'
Expand Down Expand Up @@ -39,23 +39,25 @@ const config = {
}

export default async (options: CommandOptions) => {
const { port, open: isOpen, path, lyric: withLyric, base = '' } = options
const app = express()
let { port, open: isOpen, path, lyric: withLyric, base = '' } = options

app.set('view engine', 'ejs')
const indexPath = resolve(
__dirname,
process.env.IS_DEV === 'true' ? '../../views/index.html' : '../views/index.html'
)

let htmlContent = readFileSync(indexPath, 'utf8')

htmlContent = htmlContent.replace(/{{base}}/g, base?.length ? `/${base}` : '')

app.use(
`/${base}`,
express.static(resolve(__dirname, process.env.IS_DEV === 'true' ? '../../public' : '../public'))
)

app.get(`/${base}`, (_, res) => {
res.render(
resolve(__dirname, process.env.IS_DEV === 'true' ? '../../views/index' : '../views/index'),
{
base,
}
)
res.send(htmlContent)
})

app.get(
Expand Down
6 changes: 3 additions & 3 deletions views/index.ejs → views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Music Player</title>
<link rel="icon" type="image/svg+xml" href="<%= base?.length ? `/${base}` : '' %>/music.svg" />
<link rel="icon" type="image/png" href="<%= base?.length ? `/${base}` : '' %>/music.png" />
<link rel="icon" type="image/svg+xml" href="{{base}}/music.svg" />
<link rel="icon" type="image/png" href="{{base}}/music.png" />
<link href="https://cdn.bootcdn.net/ajax/libs/ant-design-vue/1.7.7/antd.min.css" rel="stylesheet" />
<link href="https://cdn.bootcdn.net/ajax/libs/aplayer/1.10.1/APlayer.min.css" rel="stylesheet" />
<link href="<%= base?.length ? `/${base}` : '' %>/index.css" rel="stylesheet" />
<link href="{{base}}/index.css" rel="stylesheet" />
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/ant-design-vue/1.7.7/antd.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/aplayer/1.10.1/APlayer.min.js"></script>
Expand Down

0 comments on commit a45e14f

Please sign in to comment.