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

Commit ea17938

Browse files
author
Je
committed
refactor: update command description
1 parent c51e9ea commit ea17938

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

cli.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Request } from './api.ts'
12
import { createHtml } from './html.ts'
23
import log from './log.ts'
34
import { getContentType } from './mime.ts'
@@ -9,8 +10,8 @@ const commands = {
910
'init': 'Create a new app',
1011
'dev': 'Start the app in development mode',
1112
'start': 'Start the app in production mode',
12-
'build': 'Build&Export a static site',
13-
'upgrade': 'Upgrade Aleph.js'
13+
'build': 'Build & Export a static site',
14+
'upgrade': 'Upgrade Aleph.js command'
1415
}
1516
const helpMessage = `Aleph.js v${version}
1617
The React Framework in deno.
@@ -123,9 +124,10 @@ async function main() {
123124
if (match) {
124125
const port = parseInt(match[2])
125126
listenAndServe({ port }, async (req: ServerRequest) => {
127+
const url = new URL('http://localhost' + req.url)
128+
const resp = new Request(req, { pathname: util.cleanPath(url.pathname), params: {}, query: url.searchParams })
129+
const filepath = path.join(Deno.cwd(), url.pathname)
126130
try {
127-
const url = new URL('http://localhost' + req.url)
128-
let filepath = path.join(Deno.cwd(), url.pathname)
129131
const info = await Deno.lstat(filepath)
130132
if (info.isDirectory) {
131133
const r = Deno.readDir(filepath)
@@ -135,36 +137,19 @@ async function main() {
135137
items.push(`<li><a href='${path.join(url.pathname, encodeURI(item.name))}'>${item.name}${item.isDirectory ? '/' : ''}<a></li>`)
136138
}
137139
}
138-
req.respond({
139-
status: 200,
140-
headers: new Headers({
141-
'Content-Type': 'text/html',
142-
'Content-Length': info.size.toString()
143-
}),
144-
body: createHtml({
145-
head: [`<title>aleph.js/</title>`],
146-
body: `<h1>&nbsp;aleph.js/</h1><ul>${Array.from(items).join('')}</ul>`
147-
})
148-
})
140+
resp.send(createHtml({
141+
head: [`<title>aleph.js/</title>`],
142+
body: `<h1>&nbsp;aleph.js/</h1><ul>${Array.from(items).join('')}</ul>`
143+
}), 'text/html')
149144
return
150145
}
151-
req.respond({
152-
status: 200,
153-
headers: new Headers({ 'Content-Type': getContentType(filepath) }),
154-
body: await Deno.readFile(filepath)
155-
})
146+
resp.send(await Deno.readFile(filepath), getContentType(filepath))
156147
} catch (err) {
157148
if (err instanceof Deno.errors.NotFound) {
158-
req.respond({
159-
status: 404,
160-
body: 'not found'
161-
})
149+
resp.status(404).send('file not found', 'text/plain')
162150
return
163151
}
164-
req.respond({
165-
status: 500,
166-
body: err.message
167-
})
152+
resp.status(500).send(err.message, 'text/plain')
168153
}
169154
})
170155
log.info(`Proxy https://deno.land/x/aleph on http://localhost:${port}`)

cli/init.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export default async function (appDir: string, options: Record<string, string |
4545
const rev = 'master'
4646
log.info('Downloading template...')
4747
const resp = await fetch('https://codeload.github.com/postui/alephjs-templates/tar.gz/' + rev)
48-
log.info('Saving template...')
4948
const gzData = await Deno.readAll(fromStreamReader(resp.body!.getReader()))
49+
log.info('Saving template...')
5050
const tarData = gzipDecode(gzData)
5151
const entryList = new Untar(new Deno.Buffer(tarData))
5252

@@ -73,11 +73,11 @@ export default async function (appDir: string, options: Record<string, string |
7373

7474
log.info('Done')
7575
log.info('---')
76-
log.info(colors.dim('Aleph App is ready to Go.'))
76+
log.info(colors.dim('Aleph.js is ready to Go.'))
7777
log.info(`${colors.dim('$')} cd ` + path.basename(appDir))
78-
log.info(`${colors.dim('$')} aleph ${colors.bold('dev')} ${colors.dim('# start the app in development mode')}`)
79-
log.info(`${colors.dim('$')} aleph ${colors.bold('start')} ${colors.dim('# start the app in production mode')}`)
80-
log.info(`${colors.dim('$')} aleph ${colors.bold('build')} ${colors.dim('# build the app in production mode')}`)
78+
log.info(`${colors.dim('$')} aleph ${colors.bold('dev')} ${colors.dim('# start the app in `development` mode')}`)
79+
log.info(`${colors.dim('$')} aleph ${colors.bold('start')} ${colors.dim('# start the app in `production` mode')}`)
80+
log.info(`${colors.dim('$')} aleph ${colors.bold('build')} ${colors.dim('# build & export a static site')}`)
8181
log.info('---')
8282
Deno.exit(0)
8383
}

server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function start(appDir: string, port: number, isDev = false, reload
1717
for await (const req of s) {
1818
const url = new URL('http://localhost/' + req.url)
1919
const pathname = util.cleanPath(url.pathname)
20-
const resp = new Request(req, { pathname, params: {}, query: new URLSearchParams() })
20+
const resp = new Request(req, { pathname, params: {}, query: url.searchParams })
2121

2222
try {
2323
// serve hmr ws

0 commit comments

Comments
 (0)