@modern-js/plugin-changeset 2.4.0 → 2.5.0
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/CHANGELOG.md +17 -0
- package/dist/cjs/commands/bump.js +67 -0
- package/dist/cjs/commands/change.js +53 -0
- package/dist/{js/node → cjs}/commands/index.js +0 -0
- package/dist/{js/node → cjs}/commands/pre.js +6 -28
- package/dist/cjs/commands/release-note.js +171 -0
- package/dist/cjs/commands/release.js +78 -0
- package/dist/{js/node → cjs}/commands/status.js +15 -37
- package/dist/{js/node → cjs}/index.js +0 -0
- package/dist/{js/node → cjs}/locale/en.js +0 -0
- package/dist/{js/node → cjs}/locale/index.js +0 -0
- package/dist/{js/node → cjs}/locale/zh.js +0 -0
- package/dist/{js/node → cjs}/utils/changeset.js +0 -0
- package/dist/{js/node → cjs}/utils/index.js +0 -0
- package/dist/{js/node → cjs}/utils/language.js +0 -0
- package/dist/esm/commands/bump.js +44 -0
- package/dist/esm/commands/change.js +35 -0
- package/dist/{js/modern → esm}/commands/index.js +0 -0
- package/dist/esm/commands/pre.js +11 -0
- package/dist/esm/commands/release-note.js +140 -0
- package/dist/esm/commands/release.js +54 -0
- package/dist/esm/commands/status.js +20 -0
- package/dist/{js/modern → esm}/index.js +0 -0
- package/dist/{js/modern → esm}/locale/en.js +0 -0
- package/dist/{js/modern → esm}/locale/index.js +0 -0
- package/dist/{js/modern → esm}/locale/zh.js +0 -0
- package/dist/{js/modern → esm}/utils/changeset.js +0 -0
- package/dist/{js/modern → esm}/utils/index.js +0 -0
- package/dist/{js/modern → esm}/utils/language.js +0 -0
- package/package.json +11 -12
- package/dist/js/modern/commands/bump.js +0 -66
- package/dist/js/modern/commands/change.js +0 -57
- package/dist/js/modern/commands/pre.js +0 -33
- package/dist/js/modern/commands/release-note.js +0 -162
- package/dist/js/modern/commands/release.js +0 -76
- package/dist/js/modern/commands/status.js +0 -42
- package/dist/js/node/commands/bump.js +0 -89
- package/dist/js/node/commands/change.js +0 -75
- package/dist/js/node/commands/release-note.js +0 -193
- package/dist/js/node/commands/release.js +0 -100
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import resolveFrom from "resolve-from";
|
|
3
|
+
import { fs, execa } from "@modern-js/utils";
|
|
4
|
+
import readChangesets from "@changesets/read";
|
|
5
|
+
function getReleaseInfo(commit, commitObj) {
|
|
6
|
+
const commitRegex = /(.*)\(#(\d*)\)/;
|
|
7
|
+
const [, message, author] = commit.split("--");
|
|
8
|
+
commitObj.author = author;
|
|
9
|
+
if ((message || commitObj.summary).match(commitRegex)) {
|
|
10
|
+
const [, messageShort, pullRequestId] = (message || commitObj.summary).match(commitRegex);
|
|
11
|
+
commitObj.pullRequestId = pullRequestId;
|
|
12
|
+
commitObj.message = messageShort.trim();
|
|
13
|
+
}
|
|
14
|
+
return commitObj;
|
|
15
|
+
}
|
|
16
|
+
function formatSummary(summary, pullRequestId) {
|
|
17
|
+
const [firstLine, ...futureLines] = summary.split("\n").map((l) => l.trimRight());
|
|
18
|
+
let returnVal = firstLine;
|
|
19
|
+
if (futureLines.length > 0) {
|
|
20
|
+
if (pullRequestId) {
|
|
21
|
+
returnVal = `
|
|
22
|
+
|
|
23
|
+
${returnVal}`;
|
|
24
|
+
} else {
|
|
25
|
+
returnVal = `
|
|
26
|
+
${returnVal}`;
|
|
27
|
+
}
|
|
28
|
+
returnVal += `
|
|
29
|
+
|
|
30
|
+
${futureLines.filter((l) => Boolean(l)).map((l) => l).join("\n\n")}`;
|
|
31
|
+
}
|
|
32
|
+
return returnVal;
|
|
33
|
+
}
|
|
34
|
+
function getReleaseNoteLine(commit, customReleaseNoteFunction) {
|
|
35
|
+
if (customReleaseNoteFunction == null ? void 0 : customReleaseNoteFunction.getReleaseNoteLine) {
|
|
36
|
+
return customReleaseNoteFunction.getReleaseNoteLine(commit);
|
|
37
|
+
}
|
|
38
|
+
const { repository, pullRequestId, summary } = commit;
|
|
39
|
+
if (pullRequestId && repository) {
|
|
40
|
+
return `- [#${pullRequestId}](https://github.com/${repository}/pull/${pullRequestId}) ${formatSummary(
|
|
41
|
+
summary,
|
|
42
|
+
pullRequestId
|
|
43
|
+
)}
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
if (pullRequestId) {
|
|
47
|
+
return `#${pullRequestId} ${formatSummary(summary, pullRequestId)}
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
return `${formatSummary(summary, pullRequestId)}
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
async function genReleaseNote(options) {
|
|
54
|
+
const cwd = process.cwd();
|
|
55
|
+
const { repo, custom } = options;
|
|
56
|
+
let repository = repo;
|
|
57
|
+
let customReleaseNoteFunction;
|
|
58
|
+
if (!repo) {
|
|
59
|
+
const pkg = await fs.readJSON(path.join(cwd, "package.json"));
|
|
60
|
+
({ repository } = pkg);
|
|
61
|
+
}
|
|
62
|
+
if (custom) {
|
|
63
|
+
let possibleReleaseNoteFunc;
|
|
64
|
+
const releasenotePath = resolveFrom(cwd, custom);
|
|
65
|
+
possibleReleaseNoteFunc = require(releasenotePath);
|
|
66
|
+
if (possibleReleaseNoteFunc.default) {
|
|
67
|
+
possibleReleaseNoteFunc = possibleReleaseNoteFunc.default;
|
|
68
|
+
}
|
|
69
|
+
if (typeof possibleReleaseNoteFunc.getReleaseInfo === "function" && typeof possibleReleaseNoteFunc.getReleaseNoteLine === "function") {
|
|
70
|
+
customReleaseNoteFunction = possibleReleaseNoteFunc;
|
|
71
|
+
} else {
|
|
72
|
+
throw new Error("Could not resolve relesae note generation functions");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const changesets = await readChangesets(cwd);
|
|
76
|
+
if (changesets.length === 0) {
|
|
77
|
+
console.warn("No unreleased changesets found.");
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
const features = [];
|
|
81
|
+
const bugFix = [];
|
|
82
|
+
for (const changeset of changesets) {
|
|
83
|
+
const { stdout } = await execa("git", [
|
|
84
|
+
"log",
|
|
85
|
+
"--pretty=format:%h--%s--%an",
|
|
86
|
+
`.changeset/${changeset.id}.md`
|
|
87
|
+
]);
|
|
88
|
+
const [id, message] = stdout.split("--");
|
|
89
|
+
let commitObj = {
|
|
90
|
+
id,
|
|
91
|
+
type: (message || changeset.summary).startsWith("fix") ? "fix" : "feature",
|
|
92
|
+
repository,
|
|
93
|
+
message: (message || changeset.summary).trim(),
|
|
94
|
+
summary: changeset.summary
|
|
95
|
+
};
|
|
96
|
+
if (customReleaseNoteFunction == null ? void 0 : customReleaseNoteFunction.getReleaseInfo) {
|
|
97
|
+
commitObj = await customReleaseNoteFunction.getReleaseInfo(
|
|
98
|
+
stdout,
|
|
99
|
+
commitObj
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
commitObj = getReleaseInfo(stdout, commitObj);
|
|
103
|
+
}
|
|
104
|
+
if (commitObj.type === "fix") {
|
|
105
|
+
bugFix.push(commitObj);
|
|
106
|
+
} else {
|
|
107
|
+
features.push(commitObj);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (!features.length && !bugFix.length) {
|
|
111
|
+
console.warn(
|
|
112
|
+
"no release note found, you can run `pnpm run add` to add changeset"
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
if (features.length) {
|
|
116
|
+
console.info("## Features:\n");
|
|
117
|
+
for (const commit of features) {
|
|
118
|
+
const releaseNote = await getReleaseNoteLine(
|
|
119
|
+
commit,
|
|
120
|
+
customReleaseNoteFunction
|
|
121
|
+
);
|
|
122
|
+
console.info(releaseNote);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (bugFix.length) {
|
|
126
|
+
console.info("## Bug Fix:\n");
|
|
127
|
+
for (const commit of bugFix) {
|
|
128
|
+
const relesaeNote = await getReleaseNoteLine(
|
|
129
|
+
commit,
|
|
130
|
+
customReleaseNoteFunction
|
|
131
|
+
);
|
|
132
|
+
console.info(relesaeNote);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
genReleaseNote,
|
|
138
|
+
getReleaseInfo,
|
|
139
|
+
getReleaseNoteLine
|
|
140
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import {
|
|
3
|
+
getPackageManager,
|
|
4
|
+
isMonorepo,
|
|
5
|
+
fs,
|
|
6
|
+
getPnpmVersion
|
|
7
|
+
} from "@modern-js/utils";
|
|
8
|
+
import { tag as gitTag } from "@changesets/git";
|
|
9
|
+
import { CHANGESET_PATH, execaWithStreamLog } from "../utils";
|
|
10
|
+
async function release(options) {
|
|
11
|
+
const appDir = process.cwd();
|
|
12
|
+
const packageManager = await getPackageManager(process.cwd());
|
|
13
|
+
const params = ["publish"];
|
|
14
|
+
const { tag, otp, ignoreScripts, gitChecks } = options;
|
|
15
|
+
if (tag) {
|
|
16
|
+
params.push("--tag");
|
|
17
|
+
params.push(tag);
|
|
18
|
+
}
|
|
19
|
+
if (otp) {
|
|
20
|
+
params.push("--otp");
|
|
21
|
+
params.push(otp);
|
|
22
|
+
}
|
|
23
|
+
if (!isMonorepo(appDir) || packageManager === "yarn" || packageManager === "npm") {
|
|
24
|
+
await execaWithStreamLog(process.execPath, [CHANGESET_PATH, ...params]);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
params.push("-r");
|
|
28
|
+
params.push("--filter");
|
|
29
|
+
const pnpmVersion = await getPnpmVersion();
|
|
30
|
+
if (pnpmVersion.startsWith("6")) {
|
|
31
|
+
params.push("./packages/");
|
|
32
|
+
} else {
|
|
33
|
+
params.push("{./packages/**}");
|
|
34
|
+
}
|
|
35
|
+
params.push("--report-summary");
|
|
36
|
+
if (ignoreScripts) {
|
|
37
|
+
params.push("--ignore-scripts");
|
|
38
|
+
}
|
|
39
|
+
if (!gitChecks) {
|
|
40
|
+
params.push("--no-git-checks");
|
|
41
|
+
}
|
|
42
|
+
await execaWithStreamLog(packageManager, params);
|
|
43
|
+
const pnpmPublishSummaryFile = path.join(appDir, "pnpm-publish-summary.json");
|
|
44
|
+
const publishInfo = await fs.readJSON(pnpmPublishSummaryFile, "utf-8");
|
|
45
|
+
await Promise.all(
|
|
46
|
+
(publishInfo.publishedPackages || []).map(
|
|
47
|
+
(pkg) => gitTag(`${pkg.name}@${pkg.version}`, appDir)
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
await fs.remove(pnpmPublishSummaryFile);
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
release
|
|
54
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CHANGESET_PATH, execaWithStreamLog } from "../utils";
|
|
2
|
+
async function status(options) {
|
|
3
|
+
const params = [CHANGESET_PATH, "status"];
|
|
4
|
+
const { verbose, output, since } = options;
|
|
5
|
+
if (verbose) {
|
|
6
|
+
params.push("--verbose");
|
|
7
|
+
}
|
|
8
|
+
if (output) {
|
|
9
|
+
params.push("--output");
|
|
10
|
+
params.push(output);
|
|
11
|
+
}
|
|
12
|
+
if (since) {
|
|
13
|
+
params.push("--since");
|
|
14
|
+
params.push(since);
|
|
15
|
+
}
|
|
16
|
+
await execaWithStreamLog(process.execPath, params);
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
status
|
|
20
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -11,23 +11,22 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.5.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
|
-
"main": "./dist/
|
|
18
|
-
"jsnext:modern": "./dist/js/modern/index.js",
|
|
17
|
+
"main": "./dist/cjs/index.js",
|
|
19
18
|
"exports": {
|
|
20
19
|
".": {
|
|
21
20
|
"node": {
|
|
22
21
|
"jsnext:source": "./src/index.ts",
|
|
23
|
-
"import": "./dist/
|
|
24
|
-
"require": "./dist/
|
|
22
|
+
"import": "./dist/esm/index.js",
|
|
23
|
+
"require": "./dist/cjs/index.js"
|
|
25
24
|
},
|
|
26
|
-
"default": "./dist/
|
|
25
|
+
"default": "./dist/cjs/index.js"
|
|
27
26
|
},
|
|
28
27
|
"./cli": {
|
|
29
28
|
"jsnext:source": "./src/index.ts",
|
|
30
|
-
"default": "./dist/
|
|
29
|
+
"default": "./dist/cjs/index.js"
|
|
31
30
|
}
|
|
32
31
|
},
|
|
33
32
|
"dependencies": {
|
|
@@ -36,17 +35,17 @@
|
|
|
36
35
|
"@changesets/git": "^1.3.2",
|
|
37
36
|
"@changesets/read": "^0.5.5",
|
|
38
37
|
"resolve-from": "^5.0.0",
|
|
39
|
-
"@modern-js/plugin-i18n": "2.
|
|
40
|
-
"@modern-js/utils": "2.
|
|
38
|
+
"@modern-js/plugin-i18n": "2.5.0",
|
|
39
|
+
"@modern-js/utils": "2.5.0"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@types/jest": "^27",
|
|
44
43
|
"@types/node": "^14",
|
|
45
44
|
"typescript": "^4",
|
|
46
45
|
"jest": "^27",
|
|
47
|
-
"@modern-js/core": "2.
|
|
48
|
-
"@scripts/jest-config": "2.
|
|
49
|
-
"@scripts/build": "2.
|
|
46
|
+
"@modern-js/core": "2.5.0",
|
|
47
|
+
"@scripts/jest-config": "2.5.0",
|
|
48
|
+
"@scripts/build": "2.5.0"
|
|
50
49
|
},
|
|
51
50
|
"sideEffects": false,
|
|
52
51
|
"publishConfig": {
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import { CHANGESET_PATH, execaWithStreamLog } from "../utils";
|
|
22
|
-
function bump(options) {
|
|
23
|
-
return __async(this, null, function* () {
|
|
24
|
-
const { snapshot, canary, preid, ignore } = options;
|
|
25
|
-
const params = [CHANGESET_PATH, "version"];
|
|
26
|
-
if (snapshot) {
|
|
27
|
-
params.push("--snapshot");
|
|
28
|
-
if (typeof snapshot === "string") {
|
|
29
|
-
params.push(snapshot);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (ignore) {
|
|
33
|
-
ignore.forEach((pkg) => {
|
|
34
|
-
params.push("--ignore");
|
|
35
|
-
params.push(pkg);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (canary) {
|
|
39
|
-
yield execaWithStreamLog(process.execPath, [
|
|
40
|
-
CHANGESET_PATH,
|
|
41
|
-
"pre",
|
|
42
|
-
"enter",
|
|
43
|
-
preid || "next"
|
|
44
|
-
]);
|
|
45
|
-
try {
|
|
46
|
-
yield execaWithStreamLog(process.execPath, params);
|
|
47
|
-
yield execaWithStreamLog(process.execPath, [
|
|
48
|
-
CHANGESET_PATH,
|
|
49
|
-
"pre",
|
|
50
|
-
"exit"
|
|
51
|
-
]);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
yield execaWithStreamLog(process.execPath, [
|
|
54
|
-
CHANGESET_PATH,
|
|
55
|
-
"pre",
|
|
56
|
-
"exit"
|
|
57
|
-
]);
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
yield execaWithStreamLog(process.execPath, params);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
export {
|
|
65
|
-
bump
|
|
66
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import {
|
|
22
|
-
isMonorepo,
|
|
23
|
-
getMonorepoPackages,
|
|
24
|
-
getPackageManager,
|
|
25
|
-
logger
|
|
26
|
-
} from "@modern-js/utils";
|
|
27
|
-
import { CHANGESET_PATH, execaWithStreamLog } from "../utils";
|
|
28
|
-
import { i18n, localeKeys } from "../locale";
|
|
29
|
-
function change(options) {
|
|
30
|
-
return __async(this, null, function* () {
|
|
31
|
-
const appDir = process.cwd();
|
|
32
|
-
if (isMonorepo(appDir)) {
|
|
33
|
-
const packages = getMonorepoPackages(appDir);
|
|
34
|
-
if (packages.length === 0) {
|
|
35
|
-
const packageManager = yield getPackageManager(appDir);
|
|
36
|
-
logger.warn(
|
|
37
|
-
i18n.t(localeKeys.command.change.no_packages, {
|
|
38
|
-
packageManager: packageManager === "yarn" ? "yarn" : `${packageManager} run`
|
|
39
|
-
})
|
|
40
|
-
);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const { empty, open } = options;
|
|
45
|
-
const params = [CHANGESET_PATH, "add"];
|
|
46
|
-
if (empty) {
|
|
47
|
-
params.push("--empty");
|
|
48
|
-
}
|
|
49
|
-
if (open) {
|
|
50
|
-
params.push("--open");
|
|
51
|
-
}
|
|
52
|
-
yield execaWithStreamLog(process.execPath, params);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
export {
|
|
56
|
-
change
|
|
57
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import { CHANGESET_PATH, execaWithStreamLog } from "../utils";
|
|
22
|
-
function pre(type, tag = "next") {
|
|
23
|
-
return __async(this, null, function* () {
|
|
24
|
-
const params = [CHANGESET_PATH, "pre", type];
|
|
25
|
-
if (type === "enter") {
|
|
26
|
-
params.push(tag);
|
|
27
|
-
}
|
|
28
|
-
yield execaWithStreamLog(process.execPath, params);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
export {
|
|
32
|
-
pre
|
|
33
|
-
};
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import path from "path";
|
|
22
|
-
import resolveFrom from "resolve-from";
|
|
23
|
-
import { fs, execa } from "@modern-js/utils";
|
|
24
|
-
import readChangesets from "@changesets/read";
|
|
25
|
-
function getReleaseInfo(commit, commitObj) {
|
|
26
|
-
const commitRegex = /(.*)\(#(\d*)\)/;
|
|
27
|
-
const [, message, author] = commit.split("--");
|
|
28
|
-
commitObj.author = author;
|
|
29
|
-
if ((message || commitObj.summary).match(commitRegex)) {
|
|
30
|
-
const [, messageShort, pullRequestId] = (message || commitObj.summary).match(commitRegex);
|
|
31
|
-
commitObj.pullRequestId = pullRequestId;
|
|
32
|
-
commitObj.message = messageShort.trim();
|
|
33
|
-
}
|
|
34
|
-
return commitObj;
|
|
35
|
-
}
|
|
36
|
-
function formatSummary(summary, pullRequestId) {
|
|
37
|
-
const [firstLine, ...futureLines] = summary.split("\n").map((l) => l.trimRight());
|
|
38
|
-
let returnVal = firstLine;
|
|
39
|
-
if (futureLines.length > 0) {
|
|
40
|
-
if (pullRequestId) {
|
|
41
|
-
returnVal = `
|
|
42
|
-
|
|
43
|
-
${returnVal}`;
|
|
44
|
-
} else {
|
|
45
|
-
returnVal = `
|
|
46
|
-
${returnVal}`;
|
|
47
|
-
}
|
|
48
|
-
returnVal += `
|
|
49
|
-
|
|
50
|
-
${futureLines.filter((l) => Boolean(l)).map((l) => l).join("\n\n")}`;
|
|
51
|
-
}
|
|
52
|
-
return returnVal;
|
|
53
|
-
}
|
|
54
|
-
function getReleaseNoteLine(commit, customReleaseNoteFunction) {
|
|
55
|
-
if (customReleaseNoteFunction == null ? void 0 : customReleaseNoteFunction.getReleaseNoteLine) {
|
|
56
|
-
return customReleaseNoteFunction.getReleaseNoteLine(commit);
|
|
57
|
-
}
|
|
58
|
-
const { repository, pullRequestId, summary } = commit;
|
|
59
|
-
if (pullRequestId && repository) {
|
|
60
|
-
return `- [#${pullRequestId}](https://github.com/${repository}/pull/${pullRequestId}) ${formatSummary(
|
|
61
|
-
summary,
|
|
62
|
-
pullRequestId
|
|
63
|
-
)}
|
|
64
|
-
`;
|
|
65
|
-
}
|
|
66
|
-
if (pullRequestId) {
|
|
67
|
-
return `#${pullRequestId} ${formatSummary(summary, pullRequestId)}
|
|
68
|
-
`;
|
|
69
|
-
}
|
|
70
|
-
return `${formatSummary(summary, pullRequestId)}
|
|
71
|
-
`;
|
|
72
|
-
}
|
|
73
|
-
function genReleaseNote(options) {
|
|
74
|
-
return __async(this, null, function* () {
|
|
75
|
-
const cwd = process.cwd();
|
|
76
|
-
const { repo, custom } = options;
|
|
77
|
-
let repository = repo;
|
|
78
|
-
let customReleaseNoteFunction;
|
|
79
|
-
if (!repo) {
|
|
80
|
-
const pkg = yield fs.readJSON(path.join(cwd, "package.json"));
|
|
81
|
-
({ repository } = pkg);
|
|
82
|
-
}
|
|
83
|
-
if (custom) {
|
|
84
|
-
let possibleReleaseNoteFunc;
|
|
85
|
-
const releasenotePath = resolveFrom(cwd, custom);
|
|
86
|
-
possibleReleaseNoteFunc = require(releasenotePath);
|
|
87
|
-
if (possibleReleaseNoteFunc.default) {
|
|
88
|
-
possibleReleaseNoteFunc = possibleReleaseNoteFunc.default;
|
|
89
|
-
}
|
|
90
|
-
if (typeof possibleReleaseNoteFunc.getReleaseInfo === "function" && typeof possibleReleaseNoteFunc.getReleaseNoteLine === "function") {
|
|
91
|
-
customReleaseNoteFunction = possibleReleaseNoteFunc;
|
|
92
|
-
} else {
|
|
93
|
-
throw new Error("Could not resolve relesae note generation functions");
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const changesets = yield readChangesets(cwd);
|
|
97
|
-
if (changesets.length === 0) {
|
|
98
|
-
console.warn("No unreleased changesets found.");
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
101
|
-
const features = [];
|
|
102
|
-
const bugFix = [];
|
|
103
|
-
for (const changeset of changesets) {
|
|
104
|
-
const { stdout } = yield execa("git", [
|
|
105
|
-
"log",
|
|
106
|
-
"--pretty=format:%h--%s--%an",
|
|
107
|
-
`.changeset/${changeset.id}.md`
|
|
108
|
-
]);
|
|
109
|
-
const [id, message] = stdout.split("--");
|
|
110
|
-
let commitObj = {
|
|
111
|
-
id,
|
|
112
|
-
type: (message || changeset.summary).startsWith("fix") ? "fix" : "feature",
|
|
113
|
-
repository,
|
|
114
|
-
message: (message || changeset.summary).trim(),
|
|
115
|
-
summary: changeset.summary
|
|
116
|
-
};
|
|
117
|
-
if (customReleaseNoteFunction == null ? void 0 : customReleaseNoteFunction.getReleaseInfo) {
|
|
118
|
-
commitObj = yield customReleaseNoteFunction.getReleaseInfo(
|
|
119
|
-
stdout,
|
|
120
|
-
commitObj
|
|
121
|
-
);
|
|
122
|
-
} else {
|
|
123
|
-
commitObj = getReleaseInfo(stdout, commitObj);
|
|
124
|
-
}
|
|
125
|
-
if (commitObj.type === "fix") {
|
|
126
|
-
bugFix.push(commitObj);
|
|
127
|
-
} else {
|
|
128
|
-
features.push(commitObj);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (!features.length && !bugFix.length) {
|
|
132
|
-
console.warn(
|
|
133
|
-
"no release note found, you can run `pnpm run add` to add changeset"
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
if (features.length) {
|
|
137
|
-
console.info("## Features:\n");
|
|
138
|
-
for (const commit of features) {
|
|
139
|
-
const releaseNote = yield getReleaseNoteLine(
|
|
140
|
-
commit,
|
|
141
|
-
customReleaseNoteFunction
|
|
142
|
-
);
|
|
143
|
-
console.info(releaseNote);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (bugFix.length) {
|
|
147
|
-
console.info("## Bug Fix:\n");
|
|
148
|
-
for (const commit of bugFix) {
|
|
149
|
-
const relesaeNote = yield getReleaseNoteLine(
|
|
150
|
-
commit,
|
|
151
|
-
customReleaseNoteFunction
|
|
152
|
-
);
|
|
153
|
-
console.info(relesaeNote);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
export {
|
|
159
|
-
genReleaseNote,
|
|
160
|
-
getReleaseInfo,
|
|
161
|
-
getReleaseNoteLine
|
|
162
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import path from "path";
|
|
22
|
-
import {
|
|
23
|
-
getPackageManager,
|
|
24
|
-
isMonorepo,
|
|
25
|
-
fs,
|
|
26
|
-
getPnpmVersion
|
|
27
|
-
} from "@modern-js/utils";
|
|
28
|
-
import { tag as gitTag } from "@changesets/git";
|
|
29
|
-
import { CHANGESET_PATH, execaWithStreamLog } from "../utils";
|
|
30
|
-
function release(options) {
|
|
31
|
-
return __async(this, null, function* () {
|
|
32
|
-
const appDir = process.cwd();
|
|
33
|
-
const packageManager = yield getPackageManager(process.cwd());
|
|
34
|
-
const params = ["publish"];
|
|
35
|
-
const { tag, otp, ignoreScripts, gitChecks } = options;
|
|
36
|
-
if (tag) {
|
|
37
|
-
params.push("--tag");
|
|
38
|
-
params.push(tag);
|
|
39
|
-
}
|
|
40
|
-
if (otp) {
|
|
41
|
-
params.push("--otp");
|
|
42
|
-
params.push(otp);
|
|
43
|
-
}
|
|
44
|
-
if (!isMonorepo(appDir) || packageManager === "yarn" || packageManager === "npm") {
|
|
45
|
-
yield execaWithStreamLog(process.execPath, [CHANGESET_PATH, ...params]);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
params.push("-r");
|
|
49
|
-
params.push("--filter");
|
|
50
|
-
const pnpmVersion = yield getPnpmVersion();
|
|
51
|
-
if (pnpmVersion.startsWith("6")) {
|
|
52
|
-
params.push("./packages/");
|
|
53
|
-
} else {
|
|
54
|
-
params.push("{./packages/**}");
|
|
55
|
-
}
|
|
56
|
-
params.push("--report-summary");
|
|
57
|
-
if (ignoreScripts) {
|
|
58
|
-
params.push("--ignore-scripts");
|
|
59
|
-
}
|
|
60
|
-
if (!gitChecks) {
|
|
61
|
-
params.push("--no-git-checks");
|
|
62
|
-
}
|
|
63
|
-
yield execaWithStreamLog(packageManager, params);
|
|
64
|
-
const pnpmPublishSummaryFile = path.join(appDir, "pnpm-publish-summary.json");
|
|
65
|
-
const publishInfo = yield fs.readJSON(pnpmPublishSummaryFile, "utf-8");
|
|
66
|
-
yield Promise.all(
|
|
67
|
-
(publishInfo.publishedPackages || []).map(
|
|
68
|
-
(pkg) => gitTag(`${pkg.name}@${pkg.version}`, appDir)
|
|
69
|
-
)
|
|
70
|
-
);
|
|
71
|
-
yield fs.remove(pnpmPublishSummaryFile);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
export {
|
|
75
|
-
release
|
|
76
|
-
};
|