-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdedep.ts
executable file
·73 lines (61 loc) · 1.79 KB
/
dedep.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env deno
import { colors } from "./deps.ts"
import {
getDeps,
getPkgLatestVersion,
getLatestGitTag,
getLatestStdVersion,
semverCompare,
} from "./utils.ts"
const file = Deno.args[0] || "deps.ts"
if (file === "help") {
console.log(`
${colors.bold("dedep [file]")}
${colors.underline(colors.dim("https://github.com/egoist/dedep"))}
Examples:
$ dedep # Check deps.ts
$ dedep exports.ts # Check exports.ts
`)
Deno.exit()
}
try {
await Deno.stat(file)
} catch (error) {
console.log(colors.red(`${file} does not exist`))
Deno.exit(1)
}
const decoder = new TextDecoder("utf-8")
const data = await Deno.readFile(file)
const text = decoder.decode(data)
// Let's keep this simple for now, no need to use something like babel to parse the file
// Instead just do string replace
const deps = getDeps(text)
console.log(`\n Fetching latest version..\n`)
await Promise.all(
deps
.filter((dep) => dep.type !== "unknown")
.map(async (dep) => {
const latestVersion =
dep.type === "npm"
? await getPkgLatestVersion(dep.name)
: dep.type === "std"
? await getLatestStdVersion()
: await getLatestGitTag(dep.name)
console.log(` ${colors.dim(colors.underline(dep.url))}`)
const needsUpgrade =
dep.emptyVersion || semverCompare(latestVersion, dep.version) === 1
console.log(
` ${colors.bold(dep.name)} Latest: ${colors[
needsUpgrade ? "red" : "green"
](latestVersion)} Current: ${dep.emptyVersion ? "empty" : dep.version}`
)
console.log()
})
)
for (const dep of deps) {
if (dep.type === "unknown") {
console.log(` ${colors.dim(colors.underline(dep.url))}`)
console.log(` ${colors.yellow("unknown this dep")}`)
console.log()
}
}