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

Commit d41e07b

Browse files
author
Je
committed
chore: Merge
2 parents 8b6ef5a + 07d0f6a commit d41e07b

15 files changed

+55
-33
lines changed

cli.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { listenAndServe, path, ServerRequest } from './deps.ts'
21
import { createHtml } from './html.ts'
32
import log from './log.ts'
43
import { getContentType } from './server/mime.ts'
4+
import { listenAndServe, path, ServerRequest, walk } from './std.ts'
55
import util from './util.ts'
66
import { version } from './version.ts'
77

@@ -23,7 +23,7 @@ Options:
2323
-v, --version Prints version number
2424
`
2525

26-
function main() {
26+
async function main() {
2727
// parse deno args
2828
const args: Array<string> = []
2929
const argOptions: Record<string, string | boolean> = {}
@@ -80,8 +80,9 @@ function main() {
8080
}
8181

8282
// sets log level
83-
if (argOptions.l || argOptions.log) {
84-
log.setLevel(String(argOptions.l || argOptions.log))
83+
const l = argOptions.l || argOptions.log
84+
if (util.isNEString(l)) {
85+
log.setLevel(l)
8586
}
8687

8788
// proxy https://deno.land/x/aleph
@@ -142,6 +143,23 @@ function main() {
142143
}
143144
}
144145

146+
if (!hasCommand) {
147+
const walkOptions = { includeDirs: false, exts: ['.js', '.jsx', '.mjs', '.ts', '.tsx'], skip: [/\.d\.ts$/i], dep: 1 }
148+
const pagesDir = path.join(path.resolve(args[0] || '.'), 'pages')
149+
let hasIndexPage = false
150+
if (util.existsDir(pagesDir)) {
151+
for await (const { path: p } of walk(pagesDir, walkOptions)) {
152+
if (path.basename(p).split('.')[0] === 'index') {
153+
hasIndexPage = true
154+
}
155+
}
156+
}
157+
if (!hasIndexPage) {
158+
console.log(helpMessage)
159+
Deno.exit(0)
160+
}
161+
}
162+
145163
// execute command
146164
const command = hasCommand ? args.shift() : 'dev'
147165
import(`./cli/${command}.ts`).then(({ default: cmd }) => {

cli/dev.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ Options:
1414
-h, --help Prints help message
1515
`
1616

17-
export default function (appDir: string, options: Record<string, string | boolean>) {
18-
start(appDir, parseInt(String(options.port || options.p)) || 8080, true)
17+
export default function (appDir: string, options: { port?: string, p?: string }) {
18+
start(appDir, parseInt(options.port || options.p || '8080') || 8080, true)
1919
}

cli/init.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { colors, ensureDir, ensureFile, fromStreamReader, gzipDecode, path, Untar } from '../deps.ts'
1+
import { gzipDecode } from 'https://deno.land/x/[email protected]/mod.ts'
22
import log from '../log.ts'
3+
import { colors, ensureDir, ensureFile, fromStreamReader, path, Untar } from '../std.ts'
34
import util from '../util.ts'
45

56
export const helpMessage = `Initiate a new aleph app.
@@ -38,11 +39,11 @@ export default async function (appDir: string, options: Record<string, string |
3839
}
3940
}
4041

42+
log.info('Done')
4143
log.info('---')
4244
log.info(`start(dev): ` + colors.bold(`aleph`) + ' dev ' + path.basename(appDir))
4345
log.info(`start(prod): ` + colors.bold(`aleph`) + ' start ' + path.basename(appDir))
4446
log.info(`build(prod): ` + colors.bold(`aleph`) + ' build ' + path.basename(appDir))
4547
log.info('---')
46-
log.info('Done')
4748
Deno.exit(0)
4849
}

deps.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

hmr.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ socket.addEventListener('open', () => {
6868
messageQueue.splice(0, messageQueue.length)
6969
})
7070

71+
socket.addEventListener('close', () => {
72+
location.reload()
73+
})
74+
7175
socket.addEventListener('message', ({ data: rawData }: { data?: string }) => {
7276
if (rawData) {
7377
try {

log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { colors } from './deps.ts'
1+
import { colors } from './std.ts'
22

33
export enum Level {
44
Debug = 0,

project.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { colors, ensureDir, less, minify, path, Sha1, walk } from './deps.ts'
1+
import { minify } from 'https://esm.sh/terser'
22
import { EventEmitter } from './events.ts'
33
import { createHtml } from './html.ts'
44
import log from './log.ts'
55
import route from './route.ts'
6+
import { colors, ensureDir, path, Sha1, walk } from './std.ts'
67
import { compile } from './tsc/compile.ts'
78
import type { APIHandle, Config, Location, RouterURL } from './types.ts'
89
import util, { hashShort } from './util.ts'
10+
import './vendor/clean-css-builds/v4.2.2.js'
11+
import less from './vendor/less/less.js'
912

1013
const reHttp = /^https?:\/\//i
1114
const reModuleExt = /\.(js|jsx|mjs|ts|tsx)$/i
@@ -378,7 +381,7 @@ export default class Project {
378381
const pagesDir = path.join(this.srcDir, 'pages')
379382

380383
if (!(util.existsDir(pagesDir))) {
381-
log.fatal('please create some pages.')
384+
log.fatal(`'pages' directory not found.`)
382385
}
383386

384387
Object.assign(globalThis, {

server/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ServerRequest } from '../deps.ts'
1+
import type { ServerRequest } from '../std.ts'
22
import type { APIRequest, APIResponse } from '../types.ts'
33

44
export class PostAPIRequest implements APIRequest {

server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { path, serve, ws } from '../deps.ts'
21
import { createHtml } from '../html.ts'
32
import log from '../log.ts'
43
import Project from '../project.ts'
54
import route from '../route.ts'
5+
import { path, serve, ws } from '../std.ts'
66
import util, { hashShort } from '../util.ts'
77
import { PostAPIRequest, PostAPIResponse } from './api.ts'
88
import { getContentType } from './mime.ts'

std.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export { Untar } from 'https://deno.land/[email protected]/archive/tar.ts'
2+
export * as colors from 'https://deno.land/[email protected]/fmt/colors.ts'
3+
export { ensureDir } from 'https://deno.land/[email protected]/fs/ensure_dir.ts'
4+
export { ensureFile } from 'https://deno.land/[email protected]/fs/ensure_file.ts'
5+
export { walk } from 'https://deno.land/[email protected]/fs/walk.ts'
6+
export { Sha1 } from 'https://deno.land/[email protected]/hash/sha1.ts'
7+
export * from 'https://deno.land/[email protected]/http/server.ts'
8+
export { fromStreamReader } from 'https://deno.land/[email protected]/io/mod.ts'
9+
export * as path from 'https://deno.land/[email protected]/path/mod.ts'
10+
export * as ws from 'https://deno.land/[email protected]/ws/mod.ts'
11+

0 commit comments

Comments
 (0)