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

Commit 9e37e93

Browse files
author
Je
committed
feat: implement upgrade command
1 parent 683e33a commit 9e37e93

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

cli.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const commands = {
1313
'build': 'Build & Export a static site',
1414
'upgrade': 'Upgrade Aleph.js command'
1515
}
16+
1617
const helpMessage = `Aleph.js v${version}
1718
The React Framework in deno.
1819
@@ -60,13 +61,13 @@ async function main() {
6061
const command = (hasCommand ? String(args.shift()) : 'dev') as keyof typeof commands
6162

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

6869
// prints aleph.js and deno version
69-
if (argOptions.version) {
70+
if (argOptions.version && command != 'upgrade') {
7071
const { deno, v8, typescript } = Deno.version
7172
console.log(`aleph.js ${version}`)
7273
console.log(`deno ${deno}`)
@@ -122,8 +123,8 @@ async function main() {
122123
if (imports['https://deno.land/x/aleph/']) {
123124
const match = String(imports['https://deno.land/x/aleph/']).match(/^http:\/\/(localhost|127.0.0.1):(\d+)\/$/)
124125
if (match) {
125-
const port = parseInt(match[2])
126126
const cwd = Deno.cwd()
127+
const port = parseInt(match[2])
127128
listenAndServe({ port }, async (req: ServerRequest) => {
128129
const url = new URL('http://localhost' + req.url)
129130
const resp = new Request(req, { pathname: util.cleanPath(url.pathname), params: {}, query: url.searchParams })
@@ -160,7 +161,7 @@ async function main() {
160161

161162
import(`./cli/${command}.ts`).then(({ default: cmd }) => {
162163
if (command === 'upgrade') {
163-
cmd()
164+
cmd(argOptions.v || argOptions.version || 'latest')
164165
} else {
165166
const appDir = path.resolve(args[0] || '.')
166167
if (command !== 'init' && !existsDirSync(appDir)) {

cli/upgrade.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1+
import { colors } from '../std.ts'
2+
13
export const helpMessage = `
24
Usage:
35
aleph upgrade
46
57
Options:
6-
-h, --help Prints help message
8+
-v, --version <version> The version to upgrade to
9+
-h, --help Prints help message
710
`
811

9-
export default async function () {
10-
// todo: upgrade
12+
async function run(...cmd: string[]) {
13+
const p = Deno.run({
14+
cmd,
15+
stdout: 'piped',
16+
stderr: 'piped'
17+
})
18+
Deno.stdout.write(await p.output())
19+
Deno.stderr.write(await p.stderrOutput())
20+
p.close()
21+
}
22+
23+
export default async function (version: string) {
24+
const { latest, versions } = await (await fetch('https://cdn.deno.land/aleph/meta/versions.json')).json()
25+
if (version === 'latest') {
26+
version = latest
27+
} else if (!versions.includes(version)) {
28+
version = 'v' + version
29+
if (!versions.includes(version)) {
30+
console.log(`${colors.red('error')}: version(${version}) not found`)
31+
Deno.exit(1)
32+
}
33+
}
34+
await run('deno', 'install', '-A', '-f', '-n', 'aleph', `https://deno.land/x/aleph@${version}/cli.ts`)
1135
Deno.exit(0)
1236
}

0 commit comments

Comments
 (0)