-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all commands into commands directory. Add the
local
command.
- Loading branch information
1 parent
ca80abf
commit 1958198
Showing
6 changed files
with
119 additions
and
40 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { copy, exists } from "jsr:@std/fs"; | ||
|
||
import { readVersion } from "../utils/read-version.ts"; | ||
|
||
export class NotInstalled extends Error { | ||
version: string; | ||
|
||
constructor(version: string) { | ||
super(`drenv: version '${version}' not installed`); | ||
|
||
this.name = "NotInstalled"; | ||
this.version = version; | ||
} | ||
} | ||
|
||
export default async function local(version: string | undefined = undefined) { | ||
if (version) { | ||
return setLocalVersion(version); | ||
} else { | ||
return getLocalVersion(); | ||
} | ||
} | ||
|
||
const setLocalVersion = async (version: string) => { | ||
const sourceDirectory = `${Deno.env.get("HOME")}/.drenv/versions/${version}`; | ||
|
||
if (!await exists(sourceDirectory)) { | ||
throw new NotInstalled(version); | ||
} | ||
|
||
const items = await Deno.readDir(sourceDirectory); | ||
|
||
for await (const item of items) { | ||
if (item.name == "mygame") { | ||
continue; | ||
} | ||
|
||
await copy(sourceDirectory + "/" + item.name, "./" + item.name, { | ||
overwrite: true, | ||
}); | ||
} | ||
}; | ||
|
||
const getLocalVersion = async () => { | ||
return readVersion("./CHANGELOG-CURR.txt"); | ||
}; |
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 @@ | ||
import { copy } from "jsr:@std/fs"; | ||
|
||
import { readVersion } from "../utils/read-version.ts"; | ||
|
||
import global from "./global.ts"; | ||
|
||
export default async function newCommand(name: string | undefined = undefined) { | ||
return copy( | ||
`${Deno.env.get("HOME")}/.drenv/versions/${await global()}`, | ||
name, | ||
); | ||
} |
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,13 @@ | ||
import { readVersion } from "../utils/read-version.ts"; | ||
|
||
export default async function register(path: string | undefined = undefined) { | ||
// TODO: Validate that directory is a DragonRuby installation | ||
|
||
const version = await readVersion(path + "/CHANGELOG-CURR.txt"); | ||
|
||
if (!version) { | ||
throw new Error("drenv: DragonRuby installation is missing version"); | ||
} | ||
|
||
return move(path, `${Deno.env.get("HOME")}/.drenv/versions/${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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { readVersion } from "../utils/read-version.ts"; | ||
|
||
export default async function versions() { | ||
const directories = await Deno.readDir( | ||
`${Deno.env.get("HOME")}/.drenv/versions/`, | ||
); | ||
|
||
const currentVersion = await readVersion("./CHANGELOG-CURR.txt"); | ||
|
||
for await (const directory of directories) { | ||
if (directory.name == currentVersion) { | ||
console.log("* " + directory.name); | ||
} else { | ||
console.log(" " + directory.name); | ||
} | ||
} | ||
} |
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,13 @@ | ||
import { readFirstLine } from "./read-first-line.ts"; | ||
|
||
export const readVersion = async (path: string): Promise<string> => { | ||
let currentVersion; | ||
|
||
try { | ||
const content = await readFirstLine(path); | ||
|
||
currentVersion = content.match(/[0-9\.]+/)?.[0]; | ||
} catch (error) {} | ||
|
||
return currentVersion; | ||
}; |