@mlaursen/release-script 0.0.1 → 0.0.3
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 +16 -1
- package/dist/createGetTagName.d.ts +1 -0
- package/dist/createGetTagName.js +19 -0
- package/dist/createRelease.d.ts +1 -2
- package/dist/createRelease.js +3 -3
- package/dist/getLatestTag.d.ts +1 -0
- package/dist/getLatestTag.js +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/release.d.ts +1 -0
- package/dist/release.js +9 -8
- package/package.json +1 -1
- package/dist/getReleaseVersion.d.ts +0 -1
- package/dist/getReleaseVersion.js +0 -21
- package/dist/getTagPrefix.d.ts +0 -1
- package/dist/getTagPrefix.js +0 -24
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
|
|
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
|
+
}
|
package/dist/createRelease.d.ts
CHANGED
|
@@ -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
|
-
|
|
17
|
+
tagName: string;
|
|
19
18
|
prerelease: boolean;
|
|
20
19
|
}
|
|
21
20
|
export declare function createRelease(options: CreateReleaseOptions): Promise<void>;
|
package/dist/createRelease.js
CHANGED
|
@@ -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 {
|
|
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:
|
|
12
|
+
tag_name: tagName,
|
|
13
13
|
body,
|
|
14
14
|
prerelease,
|
|
15
15
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getLatestTag(): string;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/release.d.ts
CHANGED
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,19 +21,21 @@ 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" });
|
|
24
|
+
// handle the first release
|
|
25
|
+
exec("git add CHANGELOG.md");
|
|
25
26
|
exec("git add -u");
|
|
26
|
-
const version = await getReleaseVersion(mainPackage);
|
|
27
27
|
await continueRelease();
|
|
28
28
|
exec(`git commit -m "${versionMessage}"`);
|
|
29
29
|
exec(`${pkgManager} changeset publish`, { stdio: "inherit" });
|
|
30
|
+
const tagName = await getTagName();
|
|
31
|
+
await continueRelease();
|
|
30
32
|
exec("git push --follow-tags");
|
|
31
33
|
await createRelease({
|
|
32
34
|
owner,
|
|
33
35
|
repo,
|
|
34
36
|
body: changeset,
|
|
35
|
-
|
|
36
|
-
version,
|
|
37
|
+
tagName,
|
|
37
38
|
envPath,
|
|
38
|
-
prerelease:
|
|
39
|
+
prerelease: /-(alpha|next|beta)\.\d+$/.test(tagName),
|
|
39
40
|
});
|
|
40
41
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlaursen/release-script",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
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>",
|
|
@@ -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
|
-
}
|
package/dist/getTagPrefix.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getTagPrefix(mainPackage?: string): Promise<string>;
|
package/dist/getTagPrefix.js
DELETED
|
@@ -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
|
-
if (!pkg ||
|
|
18
|
-
!(await confirm({ message: `Use ${pkg} as the next tag name?` }))) {
|
|
19
|
-
return await input({
|
|
20
|
-
message: "Enter the next tag name prefix",
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|