-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d593c3
commit 57e6aec
Showing
5 changed files
with
17 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,10 @@ | ||
import { log } from "../core/utils/log.ts"; | ||
import { | ||
getCurrentVersion, | ||
getLatestDevelopmentVersion, | ||
getLatestVersion, | ||
} from "../core/utils/lume_version.ts"; | ||
import { | ||
readDenoConfig, | ||
updateLumeVersion, | ||
writeDenoConfig, | ||
} from "../core/utils/deno_config.ts"; | ||
import { upgrade } from "../deps/init.ts"; | ||
|
||
interface Options { | ||
dev?: boolean; | ||
version?: string; | ||
} | ||
export default function ({ dev, version }: Options) { | ||
return upgrade(dev, version); | ||
} | ||
|
||
/** Upgrade the Lume installation to the latest version */ | ||
export async function upgrade(dev: boolean | string = false, version?: string) { | ||
const latest = version | ||
? version | ||
: dev | ||
? await getLatestDevelopmentVersion() | ||
: await getLatestVersion(); | ||
const url = getVersionUrl(latest, dev); | ||
|
||
if (latest === getCurrentVersion()) { | ||
const message = version | ||
? `You're already using this version of Lume:` | ||
: dev | ||
? "You're using the latest version of Lume:" | ||
: "You're using the latest development version of Lume:"; | ||
|
||
log.info(`${message} <green>${latest}</green>`); | ||
return; | ||
} | ||
|
||
log.info( | ||
version | ||
? `Updating Lume to <green>${latest}</green>...` | ||
: `New version available. Updating Lume to <green>${latest}</green>...`, | ||
); | ||
|
||
const denoConfig = await readDenoConfig(); | ||
|
||
if (!denoConfig) { | ||
throw new Error("No Deno config file found"); | ||
} | ||
|
||
updateLumeVersion(url, denoConfig); | ||
|
||
// Remove deno.lock file | ||
try { | ||
await Deno.remove("deno.lock"); | ||
} catch { | ||
// Ignore | ||
} | ||
|
||
await writeDenoConfig(denoConfig); | ||
|
||
log.info("Update successful!"); | ||
|
||
if (!dev) { | ||
log.info( | ||
`See the changes in <gray>https://github.com/lumeland/lume/blob/${latest}/CHANGELOG.md</gray>`, | ||
); | ||
} | ||
} | ||
|
||
function getVersionUrl(version: string, dev: boolean | string = false): URL { | ||
// Prepend automatically "v" to the version if it's missing | ||
if (!dev && !version.startsWith("v")) { | ||
version = `v${version}`; | ||
} | ||
|
||
return new URL( | ||
dev | ||
? `https://cdn.jsdelivr.net/gh/lumeland/lume@${version}/` | ||
: `https://deno.land/x/lume@${version}/`, | ||
); | ||
export default function ({ dev, version }: Options) { | ||
return upgrade({ dev, version }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const res = await fetch( | ||
`https://cdn.deno.land/lume_init/meta/versions.json`, | ||
); | ||
const versions = await res.json(); | ||
const { run } = await import( | ||
`https://deno.land/x/lume_init@${versions.latest}/mod.ts` | ||
); | ||
const { default: upgrade } = await import( | ||
`https://deno.land/x/lume_init@${versions.latest}/upgrade.ts` | ||
); | ||
|
||
export { run, upgrade }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
import { run } from "./deps/init.ts"; | ||
|
||
console.warn( | ||
"This module is deprecated. Use `deno run -A https://lume.land/init.ts` instead.", | ||
); | ||
|
||
const res = await fetch( | ||
`https://cdn.deno.land/lume_init/meta/versions.json`, | ||
); | ||
const versions = await res.json(); | ||
const { run } = await import( | ||
`https://deno.land/x/lume_init@${versions.latest}/mod.ts` | ||
); | ||
run(); |