@mlaursen/release-script 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -59,8 +59,23 @@ await release({
59
59
  // If the version message needs to be customized. The following is the default
60
60
  // versionMessage: "build(version): version package",
61
61
 
62
- // An optional `.env` file path that includes the `GITLAB_TOKEN` environment variable.
62
+ // An optional `.env` file path that includes the `GITLAB_TOKEN` environment
63
+ // variable.
63
64
  // envPath: ".env.local",
65
+
66
+ // An optional async function to get the next release tag name. The default
67
+ // is shown below:
68
+ // getTagName: async () => {
69
+ // const latestTag = await (
70
+ // await import("@react-md/release-script")
71
+ // ).getLatestTag();
72
+ // let tagName =
73
+ // mainPackage && /@\d/.test(latestTag)
74
+ // ? latestTag.replace(/.+(@\d)/, `${mainPackage}$1`)
75
+ // : latestTag;
76
+ //
77
+ // return tagName;
78
+ // },
64
79
  });
65
80
  ```
66
81
 
@@ -0,0 +1 @@
1
+ export declare function createGetTagName(mainPackage: string | undefined): () => Promise<string>;
@@ -0,0 +1,19 @@
1
+ import confirm from "@inquirer/confirm";
2
+ import input from "@inquirer/input";
3
+ import { getLatestTag } from "./getLatestTag.js";
4
+ export function createGetTagName(mainPackage) {
5
+ return async function getTagName() {
6
+ const latestTag = getLatestTag();
7
+ let tagName = mainPackage && /@\d/.test(latestTag)
8
+ ? // most likely a monorepo
9
+ latestTag.replace(/.+(@\d)/, `${mainPackage}$1`)
10
+ : latestTag;
11
+ while (!tagName ||
12
+ !(await confirm({ message: `Use "${tagName}" for the next tag name?` }))) {
13
+ tagName = await input({
14
+ message: "Enter the tag name",
15
+ });
16
+ }
17
+ return tagName;
18
+ };
19
+ }
@@ -13,9 +13,8 @@ export interface ConfigurableCreateReleaseOptions {
13
13
  }
14
14
  export interface CreateReleaseOptions extends ConfigurableCreateReleaseOptions {
15
15
  body: string;
16
- version: string;
17
16
  override?: boolean;
18
- tagPrefix: string;
17
+ tagName: string;
19
18
  prerelease: boolean;
20
19
  }
21
20
  export declare function createRelease(options: CreateReleaseOptions): Promise<void>;
@@ -2,14 +2,14 @@ import confirm from "@inquirer/confirm";
2
2
  import { Octokit } from "@octokit/core";
3
3
  import dotenv from "dotenv";
4
4
  export async function createRelease(options) {
5
- const { version, body, tagPrefix, override, owner = "mlaursen", repo, prerelease, envPath = ".env.local", } = options;
6
- dotenv.config({ path: envPath, override });
5
+ const { body, override, owner = "mlaursen", repo, prerelease, envPath = ".env.local", tagName, } = options;
6
+ dotenv.config({ path: envPath, override, quiet: true });
7
7
  const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
8
8
  try {
9
9
  const response = await octokit.request("POST /repos/{owner}/{repo}/releases", {
10
10
  owner,
11
11
  repo,
12
- tag_name: `${tagPrefix}@${version}`,
12
+ tag_name: tagName,
13
13
  body,
14
14
  prerelease,
15
15
  });
@@ -0,0 +1 @@
1
+ export declare function getLatestTag(): string;
@@ -0,0 +1,4 @@
1
+ import { execSync } from "node:child_process";
2
+ export function getLatestTag() {
3
+ return execSync("git tag --sort=-creatordate | head -1").toString().trim();
4
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./release.js";
2
+ export * from "./getLatestTag.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./release.js";
2
+ export * from "./getLatestTag.js";
package/dist/release.d.ts CHANGED
@@ -5,5 +5,6 @@ export interface ReleaseOptions extends ConfigurableCreateReleaseOptions {
5
5
  buildCommand?: string;
6
6
  mainPackage?: string;
7
7
  versionMessage?: string;
8
+ getTagName?: () => Promise<string>;
8
9
  }
9
10
  export declare function release(options: ReleaseOptions): Promise<void>;
package/dist/release.js CHANGED
@@ -1,16 +1,15 @@
1
1
  import { execSync } from "node:child_process";
2
2
  import { continueRelease } from "./continueRelease.js";
3
+ import { createGetTagName } from "./createGetTagName.js";
4
+ import { createRelease, } from "./createRelease.js";
3
5
  import { getCurrentChangeset } from "./getCurrentChangeset.js";
4
6
  import { getPackageManager } from "./getPackageManager.js";
5
- import { getReleaseVersion } from "./getReleaseVersion.js";
6
- import { createRelease, } from "./createRelease.js";
7
- import { getTagPrefix } from "./getTagPrefix.js";
8
7
  const exec = (command, opts) => {
9
8
  console.log(command);
10
9
  execSync(command, opts);
11
10
  };
12
11
  export async function release(options) {
13
- const { owner, repo, envPath, skipBuild, cleanCommand = "clean", buildCommand = "build", mainPackage, versionMessage = "build(version): version package", } = options;
12
+ const { owner, repo, envPath, skipBuild, cleanCommand = "clean", buildCommand = "build", mainPackage, getTagName = createGetTagName(mainPackage), versionMessage = "build(version): version package", } = options;
14
13
  const pkgManager = await getPackageManager();
15
14
  if (!skipBuild) {
16
15
  exec(`${pkgManager} ${cleanCommand}`);
@@ -22,21 +21,19 @@ export async function release(options) {
22
21
  exec("git add .changeset");
23
22
  const changeset = await getCurrentChangeset();
24
23
  exec("pnpm changeset version", { stdio: "inherit" });
25
- // handle the first release
26
- exec("git add CHANGELOG.md");
27
24
  exec("git add -u");
28
- const version = await getReleaseVersion(mainPackage);
29
25
  await continueRelease();
30
26
  exec(`git commit -m "${versionMessage}"`);
31
27
  exec(`${pkgManager} changeset publish`, { stdio: "inherit" });
28
+ const tagName = await getTagName();
29
+ await continueRelease();
32
30
  exec("git push --follow-tags");
33
31
  await createRelease({
34
32
  owner,
35
33
  repo,
36
34
  body: changeset,
37
- tagPrefix: await getTagPrefix(mainPackage),
38
- version,
35
+ tagName,
39
36
  envPath,
40
- prerelease: version.includes("next"),
37
+ prerelease: /-(alpha|next|beta)\.\d+$/.test(tagName),
41
38
  });
42
39
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mlaursen/release-script",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "description": "The release script I normally use for packages I publish to npm",
6
6
  "repository": "https://github.com/mlaursen/release-script.git",
7
7
  "author": "Mikkel Laursen <mlaursen03@gmail.com>",
@@ -10,7 +10,7 @@
10
10
  "dist/"
11
11
  ],
12
12
  "exports": {
13
- ".": "./dist/release.js",
13
+ ".": "./dist/index.js",
14
14
  "./package.json": "./package.json"
15
15
  },
16
16
  "bugs": {
@@ -1 +0,0 @@
1
- export declare function getReleaseVersion(mainPackage?: string): Promise<string>;
@@ -1,21 +0,0 @@
1
- import confirm from "@inquirer/confirm";
2
- import input from "@inquirer/input";
3
- import { readFile } from "node:fs/promises";
4
- import { resolve } from "node:path";
5
- export async function getReleaseVersion(mainPackage) {
6
- let packageJsonPath = "package.json";
7
- if (mainPackage) {
8
- packageJsonPath = `packages/${mainPackage}.json`;
9
- }
10
- packageJsonPath = resolve(process.cwd(), packageJsonPath);
11
- const packageJson = await readFile(packageJsonPath, "utf8");
12
- const { version } = JSON.parse(packageJson);
13
- if (await confirm({
14
- message: `Is "${version}" the next github release version?`,
15
- })) {
16
- return version;
17
- }
18
- return await input({
19
- message: "Input the next release version for Github",
20
- });
21
- }
@@ -1 +0,0 @@
1
- export declare function getTagPrefix(mainPackage?: string): Promise<string>;
@@ -1,24 +0,0 @@
1
- import confirm from "@inquirer/confirm";
2
- import input from "@inquirer/input";
3
- import { readFile } from "node:fs/promises";
4
- import { resolve } from "node:path";
5
- async function getPkgName() {
6
- const pkgJson = await readFile(resolve(process.cwd(), "package.json"), "utf8");
7
- return JSON.parse(pkgJson).name || "";
8
- }
9
- export async function getTagPrefix(mainPackage) {
10
- let pkg = "";
11
- try {
12
- pkg = mainPackage ?? (await getPkgName());
13
- }
14
- catch {
15
- console.error("Unable to get package name from package.json");
16
- }
17
- while (!pkg ||
18
- !(await confirm({ message: `Use ${pkg} as the next tag name?` }))) {
19
- pkg = await input({
20
- message: "Enter the next tag name prefix",
21
- });
22
- }
23
- return pkg;
24
- }