Skip to content

Commit

Permalink
feat(mod): writeAll
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Nov 7, 2023
1 parent e69d213 commit 51c121d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 2 additions & 3 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { $ } from "./lib/x/dax.ts";
import { ensure, is } from "./lib/x/unknownutil.ts";
import { URI } from "./lib/uri.ts";
import { DependencyUpdate } from "./lib/update.ts";
import { FileUpdate } from "./lib/file.ts";
import { writeAll } from "./lib/file.ts";
import { GitCommitSequence } from "./lib/git.ts";
import { Dependency, parseSemVer } from "./lib/dependency.ts";
import {
Expand Down Expand Up @@ -158,9 +158,8 @@ async function _write(
report?: string;
},
) {
const results = FileUpdate.collect(updates);
console.log();
await FileUpdate.write(results, {
await writeAll(updates, {
onWrite: (module) => console.log(`💾 ${URI.relative(module.specifier)}`),
});
if (options?.summary || options?.report) {
Expand Down
23 changes: 23 additions & 0 deletions lib/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ import { DependencyUpdate } from "./update.ts";
import { ImportMapJson } from "./import_map.ts";
import { URI } from "./uri.ts";

/**
* Write the given array of DependencyUpdate to files.
*
* @returns A promise that resolves when all updates are written.
*
* @example
* ```ts
* await writeAll(updates, {
* onWrite: (update) => {
* console.log(`Updated ${update.specifier}`);
* },
* });
* ```
*/
export function writeAll(
updates: DependencyUpdate[],
options?: {
onWrite?: (result: FileUpdate) => void | Promise<void>;
},
) {
return FileUpdate.write(FileUpdate.collect(updates), options);
}

/**
* A collection of updates to dependencies in a file.
*/
Expand Down

0 comments on commit 51c121d

Please sign in to comment.