Skip to content

Commit

Permalink
feat: add --import-map option (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Aug 26, 2024
1 parent f21af28 commit 17820b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
16 changes: 13 additions & 3 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,31 @@ import { bumpWorkspaces } from "./mod.ts";
* The CLI entrypoint of the package. You can directly perform the version bump behavior from CLI:
*
* ```sh
* deno run -A jsr:@deno/bump-workspaces
* deno run -A jsr:@deno/bump-workspaces/cli
* ```
*
* The endpoint supports --dry-run option:
*
* ```sh
* deno run -A jsr:@deno/bump-workspaces --dry-run
* deno run -A jsr:@deno/bump-workspaces/cli --dry-run
* ```
*
* You can specify import map path by `--import-map` option (Default is deno.json(c) at the root):
*
* ```sh
* deno run -A jsr:@deno/bump-workspaces/cli --import-map ./import_map.json
* ```
*
* @module
*/

if (import.meta.main) {
const args = parseArgs(Deno.args, {
string: ["import-map"],
boolean: ["dry-run"],
});
await bumpWorkspaces({ dryRun: args["dry-run"] });
await bumpWorkspaces({
dryRun: "git",
importMap: args["import-map"],
});
}
20 changes: 15 additions & 5 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export type BumpWorkspaceOptions = {
* Doesn't perform file edits and network operations when true.
* Perform fs ops, but doesn't perform git operations when "network" */
dryRun?: boolean | "git";
/** The import map path. Default is deno.json(c) at the root. */
importMap?: string;
/** The path to release note markdown file. The dfault is `Releases.md` */
releaseNotePath?: string;
};
Expand Down Expand Up @@ -96,6 +98,7 @@ export async function bumpWorkspaces(
githubToken,
githubRepo,
dryRun = false,
importMap,
releaseNotePath = "Releases.md",
root = ".",
}: BumpWorkspaceOptions = {},
Expand Down Expand Up @@ -174,19 +177,26 @@ export async function bumpWorkspaces(
}

console.log(`Updating the versions:`);
let importMapPath: string;
if (importMap) {
console.log(`Using the import map: ${cyan(importMap)}`);
importMapPath = importMap;
} else {
importMapPath = configPath;
}
const updates: Record<string, VersionUpdateResult> = {};
let denoJson = await Deno.readTextFile(configPath);
let importMapJson = await Deno.readTextFile(importMapPath);
for (const summary of summaries) {
const module = getModule(summary.module, modules)!;
const oldModule = getModule(summary.module, oldModules);
const [denoJson_, versionUpdate] = await applyVersionBump(
const [importMapJson_, versionUpdate] = await applyVersionBump(
summary,
module,
oldModule,
denoJson,
importMapJson,
dryRun === true,
);
denoJson = denoJson_;
importMapJson = importMapJson_;
updates[module.name] = versionUpdate;
}
console.table(updates, ["diff", "from", "to", "path"]);
Expand All @@ -208,7 +218,7 @@ export async function bumpWorkspaces(
console.log(cyan("Skip making a pull request."));
} else {
// Updates deno.json
await Deno.writeTextFile(configPath, denoJson);
await Deno.writeTextFile(importMapPath, importMapJson);

// Prepend release notes
await ensureFile(releaseNotePath);
Expand Down

0 comments on commit 17820b5

Please sign in to comment.