Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 2435339

Browse files
author
Je
committed
refactor: cleanup
1 parent a978ab5 commit 2435339

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

cli.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { listenAndServe, path, ServerRequest, walk } from './std.ts'
55
import util, { existsDirSync, existsFileSync } from './util.ts'
66
import { version } from './version.ts'
77

8-
const commands = ['init', 'fetch', 'dev', 'start', 'build']
8+
const commands = ['init', 'fetch', 'dev', 'start', 'build', 'upgrade']
99
const helpMessage = `Aleph.js v${version}
10-
The radical new Front-End Framework in deno.
10+
The React Framework in deno.
1111
1212
Docs: https://alephjs.org/docs
1313
Bugs: https://github.com/postui/aleph.js/issues
@@ -88,8 +88,28 @@ async function main() {
8888
log.setLevel(l)
8989
}
9090

91+
if (!hasCommand) {
92+
const walkOptions = { includeDirs: false, exts: ['.js', '.jsx', '.mjs', '.ts', '.tsx'], skip: [/\.d\.ts$/i], dep: 1 }
93+
const pagesDir = path.join(path.resolve(args[0] || '.'), 'pages')
94+
let hasIndexPage = false
95+
if (existsDirSync(pagesDir)) {
96+
for await (const { path: p } of walk(pagesDir, walkOptions)) {
97+
if (path.basename(p).split('.')[0] === 'index') {
98+
hasIndexPage = true
99+
}
100+
}
101+
}
102+
if (!hasIndexPage) {
103+
console.log(helpMessage)
104+
Deno.exit(0)
105+
}
106+
}
107+
108+
// get command, default is 'dev'
109+
const command = hasCommand ? String(args.shift()) : 'dev'
110+
91111
// proxy https://deno.land/x/aleph
92-
if (existsFileSync('./import_map.json')) {
112+
if (['dev', 'start', 'build'].includes(command) && existsFileSync('./import_map.json')) {
93113
const { imports } = JSON.parse(Deno.readTextFileSync('./import_map.json'))
94114
Object.assign(globalThis, { ALEPH_IMPORT_MAP: { imports } })
95115
if (imports['https://deno.land/x/aleph/']) {
@@ -112,7 +132,7 @@ async function main() {
112132
req.respond({
113133
status: 200,
114134
headers: new Headers({
115-
'Content-Type': getContentType('.html'),
135+
'Content-Type': 'text/html',
116136
'Content-Length': info.size.toString()
117137
}),
118138
body: createHtml({
@@ -146,25 +166,6 @@ async function main() {
146166
}
147167
}
148168

149-
if (!hasCommand) {
150-
const walkOptions = { includeDirs: false, exts: ['.js', '.jsx', '.mjs', '.ts', '.tsx'], skip: [/\.d\.ts$/i], dep: 1 }
151-
const pagesDir = path.join(path.resolve(args[0] || '.'), 'pages')
152-
let hasIndexPage = false
153-
if (existsDirSync(pagesDir)) {
154-
for await (const { path: p } of walk(pagesDir, walkOptions)) {
155-
if (path.basename(p).split('.')[0] === 'index') {
156-
hasIndexPage = true
157-
}
158-
}
159-
}
160-
if (!hasIndexPage) {
161-
console.log(helpMessage)
162-
Deno.exit(0)
163-
}
164-
}
165-
166-
// execute command
167-
const command = hasCommand ? args.shift() : 'dev'
168169
import(`./cli/${command}.ts`).then(({ default: cmd }) => {
169170
const appDir = path.resolve(args[0] || '.')
170171
if (command !== 'init' && !existsDirSync(appDir)) {

server/mime.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// mime types for web
12
const mimeTypes: Record<string, string[]> = {
23
'application/javascript': ['js', 'mjs'],
34
'application/wasm': ['wasm'],
45
'application/json': ['json', 'map'],
56
'application/json5': ['json5'],
67
'application/pdf': ['pdf'],
78
'application/xml': ['xml', 'xsl'],
8-
9+
// text
910
'text/html': ['html', 'htm'],
1011
'text/markdown': ['markdown', 'md'],
1112
'text/typescript': ['ts', 'tsx'],
@@ -17,27 +18,27 @@ const mimeTypes: Record<string, string[]> = {
1718
'text/stylus': ['stylus', 'styl'],
1819
'text/csv': ['csv'],
1920
'text/plain': ['txt', 'text', 'conf', 'ini', 'log'],
20-
21+
// font
2122
'font/ttf': ['ttf'],
2223
'font/otf': ['otf'],
2324
'font/woff': ['woff'],
2425
'font/woff2': ['woff2'],
2526
'font/collection': ['ttc'],
26-
27+
// image
2728
'image/jpeg': ['jpeg', 'jpg', 'jpe'],
2829
'image/png': ['png'],
2930
'image/apng': ['apng'],
3031
'image/gif': ['gif'],
3132
'image/webp': ['webp'],
3233
'image/svg+xml': ['svg', 'svgz'],
3334
'image/x-icon': ['ico'],
34-
35+
// audio
3536
'audio/mp4': ['m4a', 'mp4a'],
3637
'audio/mpeg': ['mp3', 'm3a'],
3738
'audio/ogg': ['oga', 'ogg', 'spx'],
3839
'audio/wav': ['wav'],
3940
'audio/webm': ['weba'],
40-
41+
// video
4142
'video/mp4': ['mp4', 'm4v', 'mp4v', 'mpg4'],
4243
'video/ogg': ['ogv'],
4344
'video/webm': ['webm'],

0 commit comments

Comments
 (0)