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

Commit 600a2ac

Browse files
authored
Merge pull request #98 from alephjs/bundler-improvement
Compiler&Bundler improvement
2 parents c0cbc2a + 8216224 commit 600a2ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+3200
-14842
lines changed

.github/workflows/aleph_in_deno.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
6-
name: compiler
1+
name: Aleph.js Testing
72

83
on:
94
push:
@@ -13,16 +8,21 @@ on:
138

149
jobs:
1510
test:
16-
runs-on: ${{ matrix.os }} # runs a test on macOS, Windows and Ubuntu
11+
runs-on: ${{ matrix.os }}
1712

1813
strategy:
1914
matrix:
2015
os: [macOS-latest, windows-latest, ubuntu-latest]
2116

2217
steps:
23-
- name: Setup repo
18+
- name: Checkout
2419
uses: actions/checkout@v2
2520

21+
- name: Setup deno
22+
uses: denolib/setup-deno@v2
23+
with:
24+
deno-version: v1.x
25+
2626
- name: Setup rust
2727
uses: hecrj/setup-rust-action@v1
2828
with:
@@ -33,5 +33,11 @@ jobs:
3333
with:
3434
version: latest
3535

36-
- name: Run tests
36+
- name: Cache deps
37+
run: deno cache deps.ts
38+
39+
- name: Deno test
40+
run: deno test -A --unstable --location "http://localhost/"
41+
42+
- name: Cargo test
3743
run: cd compiler && cargo test --all

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
Thumbs.db
33
compiler/target/
44
compiler/pkg/
5-
.aleph/
6-
dist/
5+
examples/**/.aleph/
6+
examples/**/dist/

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"files.eol": "\n",
33
"files.trimTrailingWhitespace": true,
44
"typescript.format.semicolons": "remove",
5+
"typescript.preferences.quoteStyle": "single",
56
"[javascript]": {
67
"editor.defaultFormatter": "vscode.typescript-language-features"
78
},

CONTRIBUTING.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,32 @@ You will need [Deno](https://deno.land/) 1.7+.
1919

2020
```bash
2121
# ssr
22-
deno run -A --unstable --import-map=import_map.json cli.ts dev ./examples/hello-world -L debug
22+
deno run -A --unstable --import-map=import_map.json --location=http://localhost cli.ts dev ./examples/hello-world -L debug
2323
# ssg
24-
deno run -A --unstable --import-map=import_map.json cli.ts build ./examples/hello-world -L debug
24+
deno run -A --unstable --import-map=import_map.json --location=http://localhost cli.ts build ./examples/hello-world -L debug
2525
```
2626

2727
## Testing
2828

2929
Run all tests:
3030

3131
```bash
32-
deno test -A
32+
deno test -A --location=http://localhost
3333
```
3434

3535
## Project Structure
3636

37-
- **/cli** command code
38-
- **/compiler** compiler in rust with swc
39-
- **/framework** framework code
37+
- **/cli** commands code
38+
- **/compiler** compiler in rust powered by swc
39+
- **/framework**
40+
- **core** framework core
41+
- **react** react framework code
4042
- **/design** design drawings and assets
4143
- **/examples** examples
4244
- **/plugins** official plugins
4345
- **/server** server code
4446
- **/shared** shared code
4547
- **/test** testings
46-
- **/vendor** packages from npm
4748

4849
## Code of Conduct
4950

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Aleph.js: The Full-stack Framework in Deno.](./design/poster.svg)
1+
[![Aleph.js: The Full-stack Framework in Deno.](./design/poster.svg)](https://alephjs.org)
22

33
<p>
44
<span>&nbsp;&nbsp;&nbsp;<span>

cli.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { listenAndServe, path, ServerRequest, walk } from './deps.ts'
1+
import { listenAndServe, path, walk } from './deps.ts'
22
import { Request } from './server/api.ts'
3-
import log from './server/log.ts'
43
import { getContentType } from './server/mime.ts'
5-
import { createHtml, existsDirSync, existsFileSync } from './server/util.ts'
4+
import { createHtml } from './server/util.ts'
5+
import { existsDirSync, existsFileSync } from './shared/fs.ts'
6+
import log from './shared/log.ts'
67
import util from './shared/util.ts'
8+
import { ServerRequest } from './types.ts'
79
import { VERSION } from './version.ts'
810

911
const commands = {
@@ -15,7 +17,7 @@ const commands = {
1517
}
1618

1719
const helpMessage = `Aleph.js v${VERSION}
18-
The React Framework in deno.
20+
The Full-stack Framework in Deno.
1921
2022
Docs: https://alephjs.org/docs
2123
Bugs: https://github.com/alephjs/aleph.js/issues
@@ -27,47 +29,46 @@ Commands:
2729
${Object.entries(commands).map(([name, desc]) => `${name.padEnd(15)}${desc}`).join('\n ')}
2830
2931
Options:
30-
-h, --help Prints help message
3132
-v, --version Prints version number
33+
-h, --help Prints help message
3234
`
3335

3436
async function main() {
3537
// parse deno args
3638
const args: Array<string> = []
37-
const argOptions: Record<string, string | boolean> = {}
39+
const flags: Record<string, string | boolean> = {}
3840
for (let i = 0; i < Deno.args.length; i++) {
3941
const arg = Deno.args[i]
4042
if (arg.startsWith('-')) {
4143
if (arg.includes('=')) {
4244
const [key, value] = arg.replace(/^-+/, '').split('=', 2)
43-
argOptions[key] = value
45+
flags[key] = value
4446
} else {
4547
const key = arg.replace(/^-+/, '')
4648
const nextArg = Deno.args[i + 1]
4749
if (nextArg && !nextArg.startsWith('-')) {
48-
argOptions[key] = nextArg
50+
flags[key] = nextArg
4951
i++
5052
} else {
51-
argOptions[key] = true
53+
flags[key] = true
5254
}
5355
}
5456
} else {
5557
args.push(arg)
5658
}
5759
}
5860

59-
// get command, default is 'dev'
6061
const hasCommand = args.length > 0 && args[0] in commands
6162
const command = (hasCommand ? String(args.shift()) : 'dev') as keyof typeof commands
6263

6364
// prints aleph.js version
64-
if (argOptions.v && command != 'upgrade') {
65+
if (flags.v && command != 'upgrade') {
6566
console.log(`aleph.js v${VERSION}`)
6667
Deno.exit(0)
6768
}
6869

6970
// prints aleph.js and deno version
70-
if (argOptions.version && command != 'upgrade') {
71+
if (flags.version && command != 'upgrade') {
7172
const { deno, v8, typescript } = Deno.version
7273
console.log(`aleph.js ${VERSION}`)
7374
console.log(`deno ${deno}`)
@@ -77,7 +78,7 @@ async function main() {
7778
}
7879

7980
// prints help message
80-
if (argOptions.h || argOptions.help) {
81+
if (flags.h || flags.help) {
8182
if (hasCommand) {
8283
import(`./cli/${command}.ts`).then(({ helpMessage }) => {
8384
console.log(commands[command])
@@ -94,7 +95,7 @@ async function main() {
9495
}
9596

9697
// sets log level
97-
const l = argOptions.L || argOptions['log-level']
98+
const l = flags.L || flags['log-level']
9899
if (util.isNEString(l)) {
99100
log.setLevel(l)
100101
}
@@ -116,7 +117,7 @@ async function main() {
116117
}
117118
}
118119

119-
// proxy https://deno.land/x/aleph for framework dev
120+
// proxy https://deno.land/x/aleph for aleph.js dev
120121
if (['dev', 'start', 'build'].includes(command) && existsFileSync('./import_map.json')) {
121122
const { imports } = JSON.parse(Deno.readTextFileSync('./import_map.json'))
122123
if (imports['https://deno.land/x/aleph/']) {
@@ -161,14 +162,14 @@ async function main() {
161162

162163
const { default: cmd } = await import(`./cli/${command}.ts`)
163164
if (command === 'upgrade') {
164-
await cmd(argOptions.v || argOptions.version || 'latest')
165-
} else {
166-
const appDir = path.resolve(args[0] || '.')
167-
if (command !== 'init' && !existsDirSync(appDir)) {
168-
log.fatal('No such directory:', appDir)
169-
}
170-
await cmd(appDir, argOptions)
165+
await cmd(flags.v || flags.version || args[0] || 'latest')
166+
return
167+
}
168+
const appDir = path.resolve(args[0] || '.')
169+
if (command !== 'init' && !existsDirSync(appDir)) {
170+
log.fatal('No such directory:', appDir)
171171
}
172+
await cmd(appDir, flags)
172173
}
173174

174175
if (import.meta.main) {

cli/build.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Project } from '../server/project.ts'
1+
import { Appliaction } from '../server/mod.ts'
22

33
export const helpMessage = `
44
Usage:
@@ -8,13 +8,13 @@ Usage:
88
if the <dir> is empty, the current directory will be used.
99
1010
Options:
11-
-L, --log-level Set log level [possible values: debug, info]
12-
-r, --reload Reload source code cache
13-
-h, --help Prints help message
11+
-L, --log-level <log-level> Set log level [possible values: debug, info]
12+
-r, --reload Reload source code cache
13+
-h, --help Prints help message
1414
`
1515

16-
export default async function (appDir: string, options: Record<string, string | boolean>) {
17-
const project = new Project(appDir, 'production', Boolean(options.r || options.reload))
18-
await project.build()
16+
export default async function (workingDir: string, options: Record<string, string | boolean>) {
17+
const app = new Appliaction(workingDir, 'production', Boolean(options.r || options.reload))
18+
await app.build()
1919
Deno.exit(0)
2020
}

cli/dev.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import log from '../server/log.ts'
2-
import { start } from '../server/server.ts'
1+
import { Appliaction, parsePortNumber, serve } from '../server/mod.ts'
32

43
export const helpMessage = `
54
Usage:
@@ -9,19 +8,14 @@ Usage:
98
if the <dir> is empty, the current directory will be used.
109
1110
Options:
12-
-hn, --host A host to start the Aleph.js app, default is localhost
13-
-p, --port A port number to start the Aleph.js app, default is 8080
14-
-L, --log-level Set log level [possible values: debug, info]
15-
-r, --reload Reload source code cache
16-
-h, --help Prints help message
11+
-p, --port <port> A port number to start the Aleph.js app, default is 8080
12+
-L, --log-level <log-level> Set log level [possible values: debug, info]
13+
-r, --reload Reload source code cache
14+
-h, --help Prints help message
1715
`
1816

19-
export default async function (appDir: string, options: Record<string, string | boolean>) {
20-
const host = String(options.hn || options.host || 'localhost')
21-
const port = parseInt(String(options.p || options.port || '8080'))
22-
if (isNaN(port) || port <= 0 || !Number.isInteger(port)) {
23-
log.error(`invalid port '${options.port || options.p}'`)
24-
Deno.exit(1)
25-
}
26-
start(appDir, host, port, true, Boolean(options.r || options.reload))
17+
export default async function (workingDir: string, options: Record<string, string | boolean>) {
18+
const port = parsePortNumber(String(options.p || options.port || '8080'))
19+
const app = new Appliaction(workingDir, 'development', Boolean(options.r || options.reload))
20+
serve('localhost', port, app)
2721
}

0 commit comments

Comments
 (0)