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

Commit 3331543

Browse files
authored
Merge pull request #113 from alephjs/split-code
bugfix
2 parents d70ad1c + 9fb283b commit 3331543

Some content is hidden

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

87 files changed

+6186
-5750
lines changed

.vscode/settings.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
{
2-
"files.eol": "\n",
3-
"files.trimTrailingWhitespace": true,
4-
"typescript.format.semicolons": "remove",
5-
"typescript.preferences.quoteStyle": "single",
6-
"[javascript]": {
7-
"editor.defaultFormatter": "vscode.typescript-language-features"
8-
},
9-
"[typescript]": {
10-
"editor.defaultFormatter": "vscode.typescript-language-features",
11-
"editor.formatOnSave": true,
12-
"editor.codeActionsOnSave": {
13-
"source.organizeImports": true,
14-
}
15-
},
16-
"[typescriptreact]": {
17-
"editor.defaultFormatter": "vscode.typescript-language-features",
18-
"editor.formatOnSave": true,
19-
"editor.codeActionsOnSave": {
20-
"source.organizeImports": true,
21-
}
22-
},
23-
"[rust]": {
24-
"editor.defaultFormatter": "rust-lang.rust",
25-
"editor.formatOnSave": true,
26-
},
27-
"deno.enable": true,
28-
"deno.unstable": true,
29-
"deno.import_map": "./import_map.json",
30-
"deno.import_intellisense_autodiscovery": false
2+
"files.eol": "\n",
3+
"files.trimTrailingWhitespace": true,
4+
"typescript.format.semicolons": "remove",
5+
"typescript.preferences.quoteStyle": "single",
6+
"[javascript]": {
7+
"editor.defaultFormatter": "vscode.typescript-language-features"
8+
},
9+
"[typescript]": {
10+
"editor.defaultFormatter": "vscode.typescript-language-features",
11+
"editor.formatOnSave": true,
12+
"editor.codeActionsOnSave": {
13+
"source.organizeImports": true,
14+
}
15+
},
16+
"[typescriptreact]": {
17+
"editor.defaultFormatter": "vscode.typescript-language-features",
18+
"editor.formatOnSave": true,
19+
"editor.codeActionsOnSave": {
20+
"source.organizeImports": true,
21+
}
22+
},
23+
"[rust]": {
24+
"editor.defaultFormatter": "rust-lang.rust",
25+
"editor.formatOnSave": true,
26+
},
27+
"deno.enable": true,
28+
"deno.unstable": true,
29+
"deno.import_map": "./import_map.json",
30+
"deno.import_intellisense_autodiscovery": false
3131
}

CONTRIBUTING.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ You will need [Deno](https://deno.land/) 1.7+.
1616
2. Clone the repository to your local device.
1717
3. Create a new branch `git checkout -b BRANCH_NAME`.
1818
4. Change code then run our examples.
19+
5. Push your changes to Github.
20+
6. Make a [pull request](https://github.com/alephjs/aleph.js/pulls).
21+
8. Marge to master branch.
1922

2023
```bash
21-
# ssr
22-
deno run -A --unstable --import-map=import_map.json --location=http://localhost cli.ts dev ./examples/hello-world -L debug
24+
# ssr/development
25+
deno run -A --unstable --import-map=import_map.json cli.ts dev ./examples/hello-world -L debug
26+
# ssr/production
27+
deno run -A --unstable --import-map=import_map.json cli.ts build ./examples/hello-world -L debug
2328
# ssg
24-
deno run -A --unstable --import-map=import_map.json --location=http://localhost cli.ts build ./examples/hello-world -L debug
29+
deno run -A --unstable --import-map=import_map.json cli.ts build ./examples/hello-world -L debug
2530
```
2631

2732
## Testing
@@ -37,14 +42,13 @@ deno test -A --location=http://localhost
3742
- **/cli** commands code
3843
- **/compiler** compiler in rust powered by swc
3944
- **/framework**
40-
- **core** framework core
41-
- **react** react framework code
45+
- **core** framework core code
46+
- **react** framework react code
4247
- **/design** design drawings and assets
4348
- **/examples** examples
4449
- **/plugins** official plugins
4550
- **/server** server code
4651
- **/shared** shared code
47-
- **/test** testings
4852

4953
## Code of Conduct
5054

cli.ts

Lines changed: 130 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import type { ServerRequest } from './types.ts'
1010
import { VERSION } from './version.ts'
1111

1212
const commands = {
13-
'init': 'Create a new application',
14-
'dev': 'Start the app in development mode',
15-
'start': 'Start the app in production mode',
16-
'build': 'Build the app to a static site (SSG)',
17-
'upgrade': 'Upgrade Aleph.js command'
13+
'init': 'Create a new application',
14+
'dev': 'Start the app in development mode',
15+
'start': 'Start the app in production mode',
16+
'build': 'Build the app to a static site (SSG)',
17+
'upgrade': 'Upgrade Aleph.js command'
1818
}
1919

2020
const helpMessage = `Aleph.js v${VERSION}
@@ -35,144 +35,144 @@ Options:
3535
`
3636

3737
async function main() {
38-
// parse deno args
39-
const args: Array<string> = []
40-
const flags: Record<string, string | boolean> = {}
41-
for (let i = 0; i < Deno.args.length; i++) {
42-
const arg = Deno.args[i]
43-
if (arg.startsWith('-')) {
44-
if (arg.includes('=')) {
45-
const [key, value] = arg.replace(/^-+/, '').split('=', 2)
46-
flags[key] = value
47-
} else {
48-
const key = arg.replace(/^-+/, '')
49-
const nextArg = Deno.args[i + 1]
50-
if (nextArg && !nextArg.startsWith('-')) {
51-
flags[key] = nextArg
52-
i++
53-
} else {
54-
flags[key] = true
55-
}
56-
}
38+
// parse deno args
39+
const args: Array<string> = []
40+
const flags: Record<string, string | boolean> = {}
41+
for (let i = 0; i < Deno.args.length; i++) {
42+
const arg = Deno.args[i]
43+
if (arg.startsWith('-')) {
44+
if (arg.includes('=')) {
45+
const [key, value] = arg.replace(/^-+/, '').split('=', 2)
46+
flags[key] = value
47+
} else {
48+
const key = arg.replace(/^-+/, '')
49+
const nextArg = Deno.args[i + 1]
50+
if (nextArg && !nextArg.startsWith('-')) {
51+
flags[key] = nextArg
52+
i++
5753
} else {
58-
args.push(arg)
54+
flags[key] = true
5955
}
56+
}
57+
} else {
58+
args.push(arg)
6059
}
61-
62-
const hasCommand = args.length > 0 && args[0] in commands
63-
const command = (hasCommand ? String(args.shift()) : 'dev') as keyof typeof commands
64-
65-
// prints aleph.js version
66-
if (flags.v && command != 'upgrade') {
67-
console.log(`aleph.js v${VERSION}`)
68-
Deno.exit(0)
69-
}
70-
71-
// prints aleph.js and deno version
72-
if (flags.version && command != 'upgrade') {
73-
const { deno, v8, typescript } = Deno.version
74-
console.log(`aleph.js ${VERSION}`)
75-
console.log(`deno ${deno}`)
76-
console.log(`v8 ${v8}`)
77-
console.log(`typescript ${typescript}`)
60+
}
61+
62+
const hasCommand = args.length > 0 && args[0] in commands
63+
const command = (hasCommand ? String(args.shift()) : 'dev') as keyof typeof commands
64+
65+
// prints aleph.js version
66+
if (flags.v && command != 'upgrade') {
67+
console.log(`aleph.js v${VERSION}`)
68+
Deno.exit(0)
69+
}
70+
71+
// prints aleph.js and deno version
72+
if (flags.version && command != 'upgrade') {
73+
const { deno, v8, typescript } = Deno.version
74+
console.log(`aleph.js ${VERSION}`)
75+
console.log(`deno ${deno}`)
76+
console.log(`v8 ${v8}`)
77+
console.log(`typescript ${typescript}`)
78+
Deno.exit(0)
79+
}
80+
81+
// prints help message
82+
if (flags.h || flags.help) {
83+
if (hasCommand) {
84+
import(`./cli/${command}.ts`).then(({ helpMessage }) => {
85+
console.log(commands[command])
86+
if (util.isNEString(helpMessage)) {
87+
console.log(helpMessage)
88+
}
7889
Deno.exit(0)
90+
})
91+
return
92+
} else {
93+
console.log(helpMessage)
94+
Deno.exit(0)
7995
}
80-
81-
// prints help message
82-
if (flags.h || flags.help) {
83-
if (hasCommand) {
84-
import(`./cli/${command}.ts`).then(({ helpMessage }) => {
85-
console.log(commands[command])
86-
if (util.isNEString(helpMessage)) {
87-
console.log(helpMessage)
88-
}
89-
Deno.exit(0)
90-
})
91-
return
92-
} else {
93-
console.log(helpMessage)
94-
Deno.exit(0)
96+
}
97+
98+
// sets log level
99+
const l = flags.L || flags['log-level']
100+
if (util.isNEString(l)) {
101+
log.setLevel(l.toLowerCase() as LevelNames)
102+
}
103+
104+
if (!hasCommand && !args[0]) {
105+
const walkOptions = { includeDirs: false, exts: ['.js', '.jsx', '.mjs', '.ts', '.tsx'], skip: [/\.d\.ts$/i], dep: 1 }
106+
const pagesDir = path.join(path.resolve('.'), 'pages')
107+
let hasIndexPage = false
108+
if (existsDirSync(pagesDir)) {
109+
for await (const { path: p } of walk(pagesDir, walkOptions)) {
110+
if (path.basename(p).split('.')[0] === 'index') {
111+
hasIndexPage = true
95112
}
113+
}
96114
}
97-
98-
// sets log level
99-
const l = flags.L || flags['log-level']
100-
if (util.isNEString(l)) {
101-
log.setLevel(l.toLowerCase() as LevelNames)
115+
if (!hasIndexPage) {
116+
console.log(helpMessage)
117+
Deno.exit(0)
102118
}
103-
104-
if (!hasCommand && !args[0]) {
105-
const walkOptions = { includeDirs: false, exts: ['.js', '.jsx', '.mjs', '.ts', '.tsx'], skip: [/\.d\.ts$/i], dep: 1 }
106-
const pagesDir = path.join(path.resolve('.'), 'pages')
107-
let hasIndexPage = false
108-
if (existsDirSync(pagesDir)) {
109-
for await (const { path: p } of walk(pagesDir, walkOptions)) {
110-
if (path.basename(p).split('.')[0] === 'index') {
111-
hasIndexPage = true
119+
}
120+
121+
// proxy https://deno.land/x/aleph for aleph.js dev
122+
if (['dev', 'start', 'build'].includes(command) && existsFileSync('./import_map.json')) {
123+
const { imports } = JSON.parse(Deno.readTextFileSync('./import_map.json'))
124+
if (imports['https://deno.land/x/aleph/']) {
125+
const match = String(imports['https://deno.land/x/aleph/']).match(/^http:\/\/localhost:(\d+)\/$/)
126+
if (match) {
127+
const cwd = Deno.cwd()
128+
const port = parseInt(match[1])
129+
listenAndServe({ port }, async (req: ServerRequest) => {
130+
const url = new URL('http://localhost' + req.url)
131+
const resp = new Request(req, util.cleanPath(url.pathname), {}, url.searchParams)
132+
const filepath = path.join(cwd, url.pathname)
133+
try {
134+
const info = await Deno.lstat(filepath)
135+
if (info.isDirectory) {
136+
const r = Deno.readDir(filepath)
137+
const items: string[] = []
138+
for await (const item of r) {
139+
if (!item.name.startsWith('.')) {
140+
items.push(`<li><a href='${path.join(url.pathname, encodeURI(item.name))}'>${item.name}${item.isDirectory ? '/' : ''}<a></li>`)
112141
}
142+
}
143+
resp.send(createHtml({
144+
head: [`<title>aleph.js/</title>`],
145+
body: `<h1>&nbsp;aleph.js/</h1><ul>${Array.from(items).join('')}</ul>`
146+
}), 'text/html')
147+
return
113148
}
114-
}
115-
if (!hasIndexPage) {
116-
console.log(helpMessage)
117-
Deno.exit(0)
118-
}
119-
}
120-
121-
// proxy https://deno.land/x/aleph for aleph.js dev
122-
if (['dev', 'start', 'build'].includes(command) && existsFileSync('./import_map.json')) {
123-
const { imports } = JSON.parse(Deno.readTextFileSync('./import_map.json'))
124-
if (imports['https://deno.land/x/aleph/']) {
125-
const match = String(imports['https://deno.land/x/aleph/']).match(/^http:\/\/localhost:(\d+)\/$/)
126-
if (match) {
127-
const cwd = Deno.cwd()
128-
const port = parseInt(match[1])
129-
listenAndServe({ port }, async (req: ServerRequest) => {
130-
const url = new URL('http://localhost' + req.url)
131-
const resp = new Request(req, util.cleanPath(url.pathname), {}, url.searchParams)
132-
const filepath = path.join(cwd, url.pathname)
133-
try {
134-
const info = await Deno.lstat(filepath)
135-
if (info.isDirectory) {
136-
const r = Deno.readDir(filepath)
137-
const items: string[] = []
138-
for await (const item of r) {
139-
if (!item.name.startsWith('.')) {
140-
items.push(`<li><a href='${path.join(url.pathname, encodeURI(item.name))}'>${item.name}${item.isDirectory ? '/' : ''}<a></li>`)
141-
}
142-
}
143-
resp.send(createHtml({
144-
head: [`<title>aleph.js/</title>`],
145-
body: `<h1>&nbsp;aleph.js/</h1><ul>${Array.from(items).join('')}</ul>`
146-
}), 'text/html')
147-
return
148-
}
149-
resp.send(await Deno.readFile(filepath), getContentType(filepath))
150-
} catch (err) {
151-
if (err instanceof Deno.errors.NotFound) {
152-
resp.status(404).send('file not found')
153-
return
154-
}
155-
resp.status(500).send(err.message)
156-
}
157-
})
158-
Object.assign(globalThis, { __ALEPH_DEV_PORT: port })
159-
log.info(`Proxy https://deno.land/x/aleph on http://localhost:${port}`)
149+
resp.send(await Deno.readFile(filepath), getContentType(filepath))
150+
} catch (err) {
151+
if (err instanceof Deno.errors.NotFound) {
152+
resp.status(404).send('file not found')
153+
return
160154
}
161-
}
162-
}
163-
164-
const { default: cmd } = await import(`./cli/${command}.ts`)
165-
if (command === 'upgrade') {
166-
await cmd(flags.v || flags.version || args[0] || 'latest')
167-
return
168-
}
169-
const appDir = path.resolve(args[0] || '.')
170-
if (command !== 'init' && !existsDirSync(appDir)) {
171-
log.fatal('No such directory:', appDir)
155+
resp.status(500).send(err.message)
156+
}
157+
})
158+
Object.assign(globalThis, { __ALEPH_DEV_PORT: port })
159+
log.info(`Proxy https://deno.land/x/aleph on http://localhost:${port}`)
160+
}
172161
}
173-
await cmd(appDir, flags)
162+
}
163+
164+
const { default: cmd } = await import(`./cli/${command}.ts`)
165+
if (command === 'upgrade') {
166+
await cmd(flags.v || flags.version || args[0] || 'latest')
167+
return
168+
}
169+
const appDir = path.resolve(args[0] || '.')
170+
if (command !== 'init' && !existsDirSync(appDir)) {
171+
log.fatal('No such directory:', appDir)
172+
}
173+
await cmd(appDir, flags)
174174
}
175175

176176
if (import.meta.main) {
177-
main()
177+
main()
178178
}

cli/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Options:
1414
`
1515

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

0 commit comments

Comments
 (0)