-
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.
- Loading branch information
Showing
2 changed files
with
27 additions
and
19 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,4 +1,3 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.unstable": true | ||
"deno.enable": true | ||
} |
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 |
---|---|---|
|
@@ -2,33 +2,38 @@ import { Command } from "https://deno.land/x/[email protected]/command/mod.ts"; | |
import { basename, join } from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { findAndReplace } from "./change.ts"; | ||
|
||
export async function recursiveReaddir(path: string, ignore: string[]) { | ||
const files: string[] = []; | ||
const getFiles = async (path: string) => { | ||
for await (const dirEntry of Deno.readDir(path)) { | ||
if (ignore.includes(dirEntry.name)) continue; | ||
if (dirEntry.isDirectory) { | ||
await getFiles(join(path, dirEntry.name)); | ||
} else if (dirEntry.isFile) { | ||
files.push(join(path, dirEntry.name)); | ||
} | ||
export async function* recursiveReaddir( | ||
path: string, | ||
ignore: string[] = [], | ||
): AsyncGenerator<string, void> { | ||
for await (const dirEntry of Deno.readDir(path)) { | ||
if (ignore.includes(dirEntry.name)) continue; | ||
|
||
if (dirEntry.isDirectory) { | ||
yield* recursiveReaddir(join(path, dirEntry.name), ignore); | ||
} else if (dirEntry.isFile) { | ||
yield join(path, dirEntry.name); | ||
} | ||
}; | ||
await getFiles(path); | ||
return files; | ||
} | ||
} | ||
|
||
async function update( | ||
quiet: boolean, | ||
ignore: string[] = [], | ||
lineIgnore: string, | ||
debug = false, | ||
) { | ||
let count = 0; | ||
// TODO .gitignore | ||
const files = await recursiveReaddir(Deno.cwd(), [...ignore, ".git"]); | ||
for (const file of files) { | ||
if (ignore.includes(basename(file))) continue; | ||
for await (const file of recursiveReaddir(Deno.cwd(), [...ignore, ".git"])) { | ||
if (debug) console.log(`Scanning ${file}`); | ||
|
||
if (ignore.includes(basename(file))) { | ||
if (debug) console.log(`Ignoring ${file}`); | ||
continue; | ||
} | ||
|
||
if (debug) console.log(`Attempting to update ${file}`); | ||
const originalSource = await Deno.readTextFile(file); | ||
const newSource = await findAndReplace(originalSource, lineIgnore); | ||
|
||
|
@@ -50,6 +55,9 @@ async function update( | |
await new Command() | ||
.name("deno-outdated") | ||
.version("0.0.1") | ||
.option("-d --debug", "Show all scanned files", { | ||
default: false, | ||
}) | ||
.option("-q --quiet", "Silence any output", { | ||
default: false, | ||
}) | ||
|
@@ -66,11 +74,12 @@ await new Command() | |
.description( | ||
"Check for outdated dependencies for deno.land/x and other various 3rd party vendors", | ||
) | ||
.action(async ({ quiet, ignore, lineIgnore }) => { | ||
.action(async ({ quiet, ignore, lineIgnore, debug }) => { | ||
const count = await update( | ||
quiet, | ||
Array.isArray(ignore) ? ignore : [], | ||
typeof lineIgnore === "string" ? lineIgnore : "i-deno-outdated", | ||
debug, | ||
); | ||
if (!quiet) console.log(`Updated ${count} file${count === 1 ? "" : "s"}`); | ||
}) | ||
|