@cmflow/cli 1.1.0 → 2.0.0-alpha.1
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/.prettierignore +5 -0
- package/.prettierrc +10 -0
- package/README.md +130 -32
- package/bin/cm-changelog.js +20 -12
- package/bin/cm-clean.js +4 -7
- package/bin/cm-config.js +8 -8
- package/bin/cm-deploy.js +4 -8
- package/bin/cm-fetch.js +7 -7
- package/bin/cm-finish.js +9 -9
- package/bin/cm-merge.js +7 -7
- package/bin/cm-publish.js +10 -10
- package/bin/cm-push.js +10 -10
- package/bin/cm-rebase.js +10 -10
- package/bin/cm-republish.js +7 -7
- package/bin/cm-start.js +10 -10
- package/bin/cm.js +20 -20
- package/bin/cmrelease.js +2 -2
- package/eslint.config.mjs +67 -0
- package/package.json +27 -21
- package/release.config.mjs +36 -19
- package/src/commands/changelog.js +23 -23
- package/src/commands/clean.js +13 -13
- package/src/commands/config.js +8 -8
- package/src/commands/deploy.js +15 -20
- package/src/commands/fetch.js +7 -10
- package/src/commands/finish.js +18 -19
- package/src/commands/index.js +10 -11
- package/src/commands/merge.js +30 -14
- package/src/commands/prompts/branches.js +20 -20
- package/src/commands/push.js +11 -14
- package/src/commands/rebase.js +17 -19
- package/src/commands/release.js +10 -11
- package/src/commands/republish.js +11 -14
- package/src/commands/start.js +52 -48
- package/src/commands/tasks/merge-branch.js +41 -37
- package/src/commands/tasks/push-branch.js +5 -11
- package/src/commands/tasks/rebase-all-branches.js +19 -24
- package/src/commands/tasks/refresh-repository.js +26 -24
- package/src/commands/tasks/run-test.js +11 -17
- package/src/commands/tasks/update-branch.js +33 -30
- package/src/commands/tasks/update-dependencies.js +38 -32
- package/src/commands/utils/check-install.js +16 -15
- package/src/common/cli/cli.js +55 -57
- package/src/common/cli/docker.js +31 -28
- package/src/common/cli/docker.test.js +94 -96
- package/src/common/cli/git.js +59 -68
- package/src/common/cli/git.test.js +187 -189
- package/src/common/cli/lerna.js +12 -12
- package/src/common/cli/lerna.test.js +38 -40
- package/src/common/cli/npm.js +17 -17
- package/src/common/cli/npm.test.js +38 -40
- package/src/common/cli/yarn.js +17 -17
- package/src/common/cli/yarn.test.js +40 -40
- package/src/common/configure-git-workspace.js +11 -17
- package/src/common/get-config.js +63 -119
- package/src/common/get-package-json.js +4 -4
- package/src/common/get-release-config.js +4 -5
- package/src/common/index.js +10 -10
- package/src/common/run-command.js +26 -28
- package/src/common/run-command.test.js +35 -39
- package/src/index.js +10 -1
- package/src/semantic/core/analyze-commits.js +17 -0
- package/src/semantic/core/conditional.js +25 -0
- package/src/semantic/core/fail.js +21 -0
- package/src/semantic/core/generate-notes.js +11 -0
- package/src/semantic/core/prepare/bump-version.js +38 -0
- package/src/semantic/core/prepare/post.js +38 -0
- package/src/semantic/core/prepare/run.js +22 -0
- package/src/semantic/core/success.js +33 -0
- package/src/semantic/core/verify-conditions.js +32 -0
- package/src/semantic/core/verify-release.js +9 -0
- package/src/semantic/define-config.js +68 -0
- package/src/semantic/docker/publish.js +5 -0
- package/src/semantic/docker/success.js +9 -0
- package/src/semantic/utils/bump-packages-version.js +52 -0
- package/src/semantic/utils/bump-packages-version.test.js +75 -0
- package/src/semantic/utils/calculate-snapshot-version.js +15 -0
- package/src/semantic/utils/calculate-snapshot-version.test.js +67 -0
- package/src/semantic/utils/display-package-info.js +11 -0
- package/src/semantic/utils/display-release-info.js +12 -0
- package/src/semantic/utils/docker-clean-tags.js +51 -0
- package/src/semantic/utils/docker-clean-tags.test.js +61 -0
- package/src/semantic/utils/docker-publish.js +23 -0
- package/src/semantic/utils/docker-publish.test.js +44 -0
- package/src/semantic/utils/log-section.js +5 -0
- package/src/semantic/utils/release-rules.js +15 -0
- package/src/semantic/utils/transform-writer.js +75 -0
- package/src/workflow/index.js +22 -22
- package/tsconfig.json +54 -0
- package/vitest.config.mts +10 -0
- package/bin/cm-publish-pages.js +0 -12
- package/semantic.js +0 -1
- package/src/commands/publish-pages.js +0 -29
- package/src/common/cli/heroku.js +0 -21
- package/src/common/cli/heroku.test.js +0 -62
- package/src/main.js +0 -10
- package/src/semantic-release/actions/analyze-commits.js +0 -14
- package/src/semantic-release/actions/fail.js +0 -16
- package/src/semantic-release/actions/generate-notes.js +0 -12
- package/src/semantic-release/actions/index.js +0 -8
- package/src/semantic-release/actions/prepare.js +0 -114
- package/src/semantic-release/actions/publish.js +0 -17
- package/src/semantic-release/actions/success.js +0 -32
- package/src/semantic-release/actions/verify-conditions.js +0 -30
- package/src/semantic-release/actions/verify-release.js +0 -9
- package/src/semantic-release/get-semantic-config.js +0 -115
- package/src/semantic-release/utils/bump-packages-version.js +0 -51
- package/src/semantic-release/utils/bump-packages-version.test.js +0 -78
- package/src/semantic-release/utils/calculate-snapshot-version.js +0 -10
- package/src/semantic-release/utils/calculate-snapshot-version.test.js +0 -69
- package/src/semantic-release/utils/display-package-info.js +0 -11
- package/src/semantic-release/utils/display-release-info.js +0 -12
- package/src/semantic-release/utils/docker-clean-tags.js +0 -45
- package/src/semantic-release/utils/docker-clean-tags.test.js +0 -63
- package/src/semantic-release/utils/docker-publish.js +0 -47
- package/src/semantic-release/utils/docker-publish.test.js +0 -67
- package/src/semantic-release/utils/ghpages-publish.js +0 -16
- package/src/semantic-release/utils/log-section.js +0 -5
- /package/src/{semantic-release → semantic}/utils/__mock__/test1/package.json +0 -0
- /package/src/{semantic-release → semantic}/utils/__mock__/test1/packages/a/package.json +0 -0
- /package/src/{semantic-release → semantic}/utils/__mock__/test1/packages/b/package.json +0 -0
- /package/src/{semantic-release → semantic}/utils/__mock__/test2/package.json +0 -0
- /package/src/{semantic-release → semantic}/utils/__mock__/test2/packages/a/package.json +0 -0
- /package/src/{semantic-release → semantic}/utils/__mock__/test2/packages/b/package.json +0 -0
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import chalk from
|
|
2
|
-
import figures from
|
|
3
|
-
import inquirer from
|
|
4
|
-
import Listr from
|
|
5
|
-
import { getReleaseConfig } from './get-release-config.js'
|
|
6
|
-
import { getConfig } from './get-config.js'
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import figures from "figures";
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
import Listr from "listr";
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
import { getConfig } from "./get-config.js";
|
|
7
|
+
import { getReleaseConfig } from "./get-release-config.js";
|
|
8
|
+
|
|
9
|
+
function createTasksRunner(tasks, ctx) {
|
|
9
10
|
return new Listr(tasks, {
|
|
10
11
|
concurrent: false,
|
|
11
|
-
renderer: !ctx.verbose ?
|
|
12
|
-
}).run(ctx)
|
|
12
|
+
renderer: !ctx.verbose ? "default" : "verbose"
|
|
13
|
+
}).run(ctx);
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export async function runCommand
|
|
16
|
+
export async function runCommand(klass, commander) {
|
|
16
17
|
try {
|
|
17
|
-
const config = getConfig()
|
|
18
|
+
const config = getConfig();
|
|
18
19
|
let context = {
|
|
19
20
|
...getReleaseConfig(),
|
|
20
21
|
...config,
|
|
@@ -22,45 +23,42 @@ export async function runCommand (klass, commander) {
|
|
|
22
23
|
config,
|
|
23
24
|
logger: console,
|
|
24
25
|
verbose: commander.verbose
|
|
25
|
-
}
|
|
26
|
+
};
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
const command = new klass()
|
|
28
|
+
const command = new klass();
|
|
29
29
|
|
|
30
30
|
// Map context from commander and current context
|
|
31
31
|
if (command.mapContext) {
|
|
32
|
-
context = command.mapContext(commander, context)
|
|
32
|
+
context = command.mapContext(commander, context);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// show prompts
|
|
36
36
|
if (command.prompt) {
|
|
37
37
|
context = {
|
|
38
38
|
...context,
|
|
39
|
-
...await inquirer.prompt(command.prompt(context))
|
|
40
|
-
}
|
|
39
|
+
...(await inquirer.prompt(command.prompt(context)))
|
|
40
|
+
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Verify conditions
|
|
44
|
-
command.verifyConditions && command.verifyConditions(context)
|
|
44
|
+
command.verifyConditions && command.verifyConditions(context);
|
|
45
45
|
|
|
46
46
|
// Get tasks
|
|
47
|
-
const tasks = command.getTasks(context)
|
|
47
|
+
const tasks = command.getTasks(context);
|
|
48
48
|
|
|
49
49
|
// Run tasks
|
|
50
|
-
await createTasksRunner(tasks, context)
|
|
50
|
+
await createTasksRunner(tasks, context);
|
|
51
51
|
|
|
52
|
-
command.success && command.success(context)
|
|
52
|
+
command.success && command.success(context);
|
|
53
53
|
} catch (er) {
|
|
54
|
-
|
|
55
|
-
console.error(chalk.red(figures.cross + ' ' + String(er)))
|
|
54
|
+
console.error(chalk.red(figures.cross + " " + String(er)));
|
|
56
55
|
if (commander.verbose) {
|
|
57
|
-
|
|
58
|
-
console.error(String(er.stack).replace(String(er), ''))
|
|
56
|
+
console.error(String(er.stack).replace(String(er), ""));
|
|
59
57
|
}
|
|
60
|
-
process.exit(-1)
|
|
58
|
+
process.exit(-1);
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
process.on(
|
|
62
|
+
process.on("unhandledRejection", () => {
|
|
65
63
|
// avoid extra promise rejection when using toObservable
|
|
66
|
-
})
|
|
64
|
+
});
|
|
@@ -1,69 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
vi.mock("listr", () => {
|
|
2
|
+
return { default: vi.fn() };
|
|
3
|
+
});
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})
|
|
6
|
-
const { default: Listr } = await import('listr')
|
|
7
|
-
const { runCommand } = await import('./run-command.js')
|
|
5
|
+
const { default: Listr } = await import("listr");
|
|
6
|
+
const { runCommand } = await import("./run-command.js");
|
|
8
7
|
|
|
9
|
-
describe(
|
|
8
|
+
describe("runCommand", () => {
|
|
10
9
|
beforeEach(() => {
|
|
11
10
|
Listr.mockReturnValue({
|
|
12
|
-
run
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
it('should call runCommand', async () => {
|
|
11
|
+
run() {}
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it("should call runCommand", async () => {
|
|
17
15
|
class Cmd {
|
|
18
|
-
mapContext
|
|
16
|
+
mapContext(ctx) {
|
|
19
17
|
return {
|
|
20
18
|
...ctx,
|
|
21
19
|
test: true
|
|
22
|
-
}
|
|
20
|
+
};
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
getTasks
|
|
26
|
-
return []
|
|
23
|
+
getTasks() {
|
|
24
|
+
return [];
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
vi.spyOn(Cmd.prototype, "mapContext");
|
|
29
|
+
vi.spyOn(Cmd.prototype, "getTasks");
|
|
32
30
|
|
|
33
31
|
await runCommand(Cmd, {
|
|
34
|
-
prop:
|
|
35
|
-
})
|
|
32
|
+
prop: "1"
|
|
33
|
+
});
|
|
36
34
|
|
|
37
|
-
expect(Cmd.prototype.mapContext).toHaveBeenCalledWith({ prop:
|
|
35
|
+
expect(Cmd.prototype.mapContext).toHaveBeenCalledWith({ prop: "1" }, expect.any(Object));
|
|
38
36
|
expect(Cmd.prototype.getTasks).toHaveBeenCalledWith({
|
|
39
|
-
prop:
|
|
37
|
+
prop: "1",
|
|
40
38
|
test: true
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
it(
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it("should call runCommand and catch error", async () => {
|
|
44
42
|
class Cmd {
|
|
45
|
-
mapContext
|
|
43
|
+
mapContext(ctx) {
|
|
46
44
|
return {
|
|
47
45
|
...ctx,
|
|
48
46
|
test: true
|
|
49
|
-
}
|
|
47
|
+
};
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
getTasks
|
|
53
|
-
throw new Error(
|
|
50
|
+
getTasks() {
|
|
51
|
+
throw new Error("Error");
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
})
|
|
55
|
+
vi.spyOn(console, "error").mockReturnValue(undefined);
|
|
56
|
+
vi.spyOn(process, "exit").mockImplementation(() => {});
|
|
60
57
|
|
|
61
58
|
await runCommand(Cmd, {
|
|
62
|
-
prop:
|
|
63
|
-
})
|
|
59
|
+
prop: "1"
|
|
60
|
+
});
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
expect(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
})
|
|
62
|
+
expect(console.error).toHaveBeenCalled();
|
|
63
|
+
expect(process.exit).toHaveBeenCalledWith(-1);
|
|
64
|
+
});
|
|
65
|
+
});
|
package/src/index.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as commands from "./commands/index.js";
|
|
2
|
+
|
|
3
|
+
export * from "./commands/release.js";
|
|
4
|
+
export * from "./common/index.js";
|
|
5
|
+
export * from "./semantic/define-config.js";
|
|
6
|
+
export * from "./semantic/utils/release-rules.js";
|
|
7
|
+
export * from "./semantic/utils/transform-writer.js";
|
|
8
|
+
export * from "./workflow/index.js";
|
|
9
|
+
|
|
10
|
+
export { commands };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as commitAnalyzerPlugins from "@semantic-release/commit-analyzer";
|
|
2
|
+
|
|
3
|
+
import { calculateSnapshotVersion } from "../utils/calculate-snapshot-version.js";
|
|
4
|
+
|
|
5
|
+
export async function analyzeCommits(pluginConfig, context) {
|
|
6
|
+
if (context.branch && context.branch.type !== "prerelease") {
|
|
7
|
+
return commitAnalyzerPlugins.analyzeCommits(pluginConfig, context);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const analyzedCommits = await commitAnalyzerPlugins.analyzeCommits(pluginConfig, context);
|
|
11
|
+
context.nextRelease = context.nextRelease || {};
|
|
12
|
+
context.nextRelease.type = analyzedCommits;
|
|
13
|
+
context.nextRelease.version = calculateSnapshotVersion(context);
|
|
14
|
+
context.lastRelease.version = null;
|
|
15
|
+
|
|
16
|
+
return "patch";
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getConfig } from "../../common/index.js";
|
|
2
|
+
export function success(pluginConfig, context) {
|
|
3
|
+
return runAll(pluginConfig, context, context.branch?.type === "release");
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function publish(pluginConfig, context) {
|
|
7
|
+
return runAll(pluginConfig, context, context.branch?.type === "release");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function fail(pluginConfig, context) {
|
|
11
|
+
return runAll(pluginConfig, context, context.branch?.type === "release");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function runAll(pluginConfig, context, defaultCondition) {
|
|
15
|
+
context.config = getConfig();
|
|
16
|
+
|
|
17
|
+
const condition = pluginConfig.when !== undefined ? pluginConfig.if(context) : defaultCondition;
|
|
18
|
+
|
|
19
|
+
if (condition && pluginConfig.run) {
|
|
20
|
+
const tasks = [].concat(pluginConfig.run);
|
|
21
|
+
for (const task of tasks) {
|
|
22
|
+
await task(pluginConfig, context);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { git } from "../../common/index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Remove the tag from the git repository if the release is not a prerelease.
|
|
5
|
+
*
|
|
6
|
+
* @param pluginConfig
|
|
7
|
+
* @param context
|
|
8
|
+
* @return {Promise<void>}
|
|
9
|
+
*/
|
|
10
|
+
export async function fail(pluginConfig, context) {
|
|
11
|
+
if (context.branch && context.branch.type !== "prerelease") {
|
|
12
|
+
const {
|
|
13
|
+
tagFormat,
|
|
14
|
+
config: { ORIGIN }
|
|
15
|
+
} = context;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
await git.push("--delete", ORIGIN, tagFormat.replace("${version}", context.nextRelease.version));
|
|
19
|
+
} catch {}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as releaseNotesPlugins from "@semantic-release/release-notes-generator";
|
|
2
|
+
|
|
3
|
+
import { getConfig } from "../../common/index.js";
|
|
4
|
+
|
|
5
|
+
export async function generateNotes(pluginConfig, context) {
|
|
6
|
+
context.config = getConfig();
|
|
7
|
+
|
|
8
|
+
if (context.branch.type === "release") {
|
|
9
|
+
return releaseNotesPlugins.generateNotes(pluginConfig, context);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getConfig, lerna, npm, yarn } from "../../../common/index.js";
|
|
2
|
+
import { bumpPackagesVersion } from "../../utils/bump-packages-version.js";
|
|
3
|
+
|
|
4
|
+
export async function prepare(pluginConfig, context) {
|
|
5
|
+
context.config = getConfig();
|
|
6
|
+
const {
|
|
7
|
+
config: { HAS_YARN, HAS_LERNA, BUMP_METHOD, WORKSPACES },
|
|
8
|
+
logger
|
|
9
|
+
} = context;
|
|
10
|
+
const pkgManager = HAS_YARN ? yarn : npm;
|
|
11
|
+
|
|
12
|
+
logger.info(`Start bump version for all packages using method: ${BUMP_METHOD}`);
|
|
13
|
+
|
|
14
|
+
switch (BUMP_METHOD) {
|
|
15
|
+
case "native":
|
|
16
|
+
logger.info("Using package manager");
|
|
17
|
+
npm.newVersion(context.nextRelease.version);
|
|
18
|
+
break;
|
|
19
|
+
case "lerna":
|
|
20
|
+
if (HAS_LERNA) {
|
|
21
|
+
await lerna.newVersion(context.nextRelease.version);
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
case "cmflow":
|
|
25
|
+
await bumpPackagesVersion(context.nextRelease.version, WORKSPACES);
|
|
26
|
+
await pkgManager.install();
|
|
27
|
+
break;
|
|
28
|
+
case "native:lerna":
|
|
29
|
+
default:
|
|
30
|
+
npm.newVersion(context.nextRelease.version);
|
|
31
|
+
|
|
32
|
+
if (HAS_LERNA) {
|
|
33
|
+
await lerna.newVersion(context.nextRelease.version);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
logger.info("Bump version finished with success...");
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { configureGitWorkspace, getConfig, git } from "../../../common/index.js";
|
|
2
|
+
|
|
3
|
+
export async function prepare(pluginConfig, context) {
|
|
4
|
+
context.config = getConfig();
|
|
5
|
+
const { branch } = context;
|
|
6
|
+
|
|
7
|
+
if (branch.type === "release") {
|
|
8
|
+
context.config = getConfig();
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
logger,
|
|
12
|
+
config: { CI_NAME, BUILD_NUMBER }
|
|
13
|
+
} = context;
|
|
14
|
+
|
|
15
|
+
logger.info("Prepare release");
|
|
16
|
+
|
|
17
|
+
configureGitWorkspace(context);
|
|
18
|
+
|
|
19
|
+
logger.info("Adding files to commit");
|
|
20
|
+
git.add("-A").sync();
|
|
21
|
+
|
|
22
|
+
logger.info("Get commit stage status");
|
|
23
|
+
git.status();
|
|
24
|
+
|
|
25
|
+
const revisionMessage = `${CI_NAME} build: ${context.branch.name} ${BUILD_NUMBER} ${context.nextRelease.gitTag} [ci skip]`;
|
|
26
|
+
|
|
27
|
+
logger.info("Commit changes with revision message: ");
|
|
28
|
+
logger.info(revisionMessage);
|
|
29
|
+
|
|
30
|
+
git.commit("-m", revisionMessage).sync();
|
|
31
|
+
|
|
32
|
+
logger.success("Change committed");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// avoid next semantic-release steps when is a prerelease or release branch with SKIP_GITHUB_PUBLISH
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getConfig, npm, yarn } from "../../../common/index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param pluginConfig {{command: string}}
|
|
5
|
+
* @param context
|
|
6
|
+
* @return {Promise<void>}
|
|
7
|
+
*/
|
|
8
|
+
export async function prepare(pluginConfig, context) {
|
|
9
|
+
context.config = getConfig();
|
|
10
|
+
const {
|
|
11
|
+
config: { HAS_YARN },
|
|
12
|
+
logger
|
|
13
|
+
} = context;
|
|
14
|
+
|
|
15
|
+
const pkgManager = HAS_YARN ? yarn : npm;
|
|
16
|
+
|
|
17
|
+
logger.info(`Start ${pluginConfig.command} task`);
|
|
18
|
+
|
|
19
|
+
await pkgManager.run(pluginConfig.command);
|
|
20
|
+
|
|
21
|
+
logger.info(`${pluginConfig.command} task finished with success...`);
|
|
22
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getConfig } from "../../common/get-config.js";
|
|
2
|
+
import { git } from "../../common/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Add runAfter property with the semantic-release plugin name to run after the success task
|
|
6
|
+
* depending on the branch type.
|
|
7
|
+
*
|
|
8
|
+
* @param pluginConfig {{}}
|
|
9
|
+
* @param context
|
|
10
|
+
* @return {Promise<void>}
|
|
11
|
+
*/
|
|
12
|
+
export async function success(pluginConfig, context) {
|
|
13
|
+
context.config = getConfig();
|
|
14
|
+
const {
|
|
15
|
+
branch,
|
|
16
|
+
logger,
|
|
17
|
+
config: { PRODUCTION_BRANCH, ORIGIN, DEVELOP_BRANCH }
|
|
18
|
+
} = context;
|
|
19
|
+
|
|
20
|
+
const condition = pluginConfig.when !== undefined ? pluginConfig.when(context) : branch.type !== "prerelease";
|
|
21
|
+
|
|
22
|
+
if (condition) {
|
|
23
|
+
await git.push("--quiet", "--set-upstream", ORIGIN, PRODUCTION_BRANCH);
|
|
24
|
+
|
|
25
|
+
if (PRODUCTION_BRANCH !== DEVELOP_BRANCH) {
|
|
26
|
+
logger.start(`Reset HEAD of ${ORIGIN}/${DEVELOP_BRANCH} branch to HEAD of ${ORIGIN}/${PRODUCTION_BRANCH} `);
|
|
27
|
+
|
|
28
|
+
await git.push("-f", ORIGIN, `refs/remotes/${ORIGIN}/${PRODUCTION_BRANCH}:refs/heads/${DEVELOP_BRANCH}`);
|
|
29
|
+
|
|
30
|
+
logger.success(`${ORIGIN}/${DEVELOP_BRANCH} branch correctly updated`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
|
|
3
|
+
import { getConfig, git } from "../../common/index.js";
|
|
4
|
+
|
|
5
|
+
export function verifyConditions(pluginConfig, context) {
|
|
6
|
+
if (pluginConfig.dryRun) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
context.config = getConfig();
|
|
11
|
+
const {
|
|
12
|
+
branch,
|
|
13
|
+
config: { USER, EMAIL, ORIGIN }
|
|
14
|
+
} = context;
|
|
15
|
+
|
|
16
|
+
if (USER && EMAIL) {
|
|
17
|
+
context.logger.info("Configure git with username");
|
|
18
|
+
|
|
19
|
+
git.config("--global", "user.name", USER);
|
|
20
|
+
git.config("--global", "user.email", EMAIL);
|
|
21
|
+
|
|
22
|
+
context.logger.info("Configure git branch");
|
|
23
|
+
context.logger.success("Workspace is correctly configured");
|
|
24
|
+
} else {
|
|
25
|
+
context.logger.error(chalk.red("Ignore git configuration (Empty GIT_USER_EMAIL or/and GIT_USER_NAME variables)"));
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
git.fetch().sync();
|
|
30
|
+
git.checkout(branch.name).sync();
|
|
31
|
+
git.branch(`--set-upstream-to=${ORIGIN}/${branch.name}`, branch.name).sync();
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getConfig } from "../../common/index.js";
|
|
2
|
+
import { displayPackageInfo } from "../utils/display-package-info.js";
|
|
3
|
+
import { displayReleaseInfo } from "../utils/display-release-info.js";
|
|
4
|
+
|
|
5
|
+
export function verifyRelease(pluginConfig, context) {
|
|
6
|
+
context.config = getConfig();
|
|
7
|
+
displayPackageInfo(context);
|
|
8
|
+
displayReleaseInfo(context);
|
|
9
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { getConfig } from "../common/get-config.js";
|
|
2
|
+
import { releaseRules } from "./utils/release-rules.js";
|
|
3
|
+
import { transformWriter } from "./utils/transform-writer.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Define the semantic-release configuration based on the ClubMed API configuration.
|
|
7
|
+
* @param {import('semantic-release').GlobalConfig} opts
|
|
8
|
+
* @returns {import('semantic-release').GlobalConfig}
|
|
9
|
+
*/
|
|
10
|
+
export function defineConfig(opts = {}) {
|
|
11
|
+
const { PRODUCTION_BRANCH: productBranch, BRANCH_NAME: branchName } = getConfig();
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
noCi: productBranch !== branchName,
|
|
15
|
+
branches: [
|
|
16
|
+
{
|
|
17
|
+
name: productBranch,
|
|
18
|
+
channel: "release"
|
|
19
|
+
},
|
|
20
|
+
// Use this hack to always run semantic-release (as prerelease for feature/fix branch)
|
|
21
|
+
{
|
|
22
|
+
name: branchName,
|
|
23
|
+
channel: "prerelease",
|
|
24
|
+
prerelease: true
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
verifyConditions: ["@cmflow/cli/semantic/verify-conditions"],
|
|
28
|
+
analyzeCommits: ["@cmflow/cli/semantic/analyze-commits"],
|
|
29
|
+
verifyRelease: ["@cmflow/cli/semantic/verify-release"],
|
|
30
|
+
generateNotes: ["@cmflow/cli/semantic/generate-notes"],
|
|
31
|
+
prepare: [
|
|
32
|
+
"@cmflow/cli/semantic/prepare/bump-version",
|
|
33
|
+
// '@cmflow/cli/semantic/prepare/build',
|
|
34
|
+
// '@cmflow/cli/semantic/prepare/e2e',
|
|
35
|
+
"@cmflow/cli/semantif/prepare/post" // need to avoid semantic next step
|
|
36
|
+
],
|
|
37
|
+
publish: [
|
|
38
|
+
[
|
|
39
|
+
"@cmflow/cli/semantic/publish",
|
|
40
|
+
{
|
|
41
|
+
runAfter: opts.runAfter
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
],
|
|
45
|
+
success: [
|
|
46
|
+
[
|
|
47
|
+
"@cmflow/cli/semantic/success",
|
|
48
|
+
{
|
|
49
|
+
runAfter: opts.runAfter
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
],
|
|
53
|
+
fail: [
|
|
54
|
+
[
|
|
55
|
+
"@cmflow/cli/semantic/fail",
|
|
56
|
+
{
|
|
57
|
+
runAfter: opts.runAfter
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
],
|
|
61
|
+
releaseRules,
|
|
62
|
+
parserOpts: {
|
|
63
|
+
noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES"]
|
|
64
|
+
},
|
|
65
|
+
writerOpts: { transform: transformWriter },
|
|
66
|
+
...opts
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import globby from "globby";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
|
|
5
|
+
const PACKAGE_JSON_PROPS = ["dependencies", "devDependencies", "peerDependencies"];
|
|
6
|
+
|
|
7
|
+
export async function bumpPackagesVersion(version, workspaces, cwd = process.cwd()) {
|
|
8
|
+
const patterns = workspaces.map((path) => `${path}/package.json`).concat("package.json");
|
|
9
|
+
|
|
10
|
+
const files = await globby(patterns, {
|
|
11
|
+
cwd,
|
|
12
|
+
absolute: true
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const names = new Set();
|
|
16
|
+
|
|
17
|
+
const packages = await Promise.all(
|
|
18
|
+
files.map(async (file) => {
|
|
19
|
+
const pkg = await fs.readJson(file);
|
|
20
|
+
|
|
21
|
+
names.add(pkg.name);
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
file,
|
|
25
|
+
pkg
|
|
26
|
+
};
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return Promise.all(
|
|
31
|
+
packages.map(({ pkg, file }) => {
|
|
32
|
+
pkg.version = version;
|
|
33
|
+
|
|
34
|
+
PACKAGE_JSON_PROPS.forEach((key) => bumpDependencies(pkg, key, version, names));
|
|
35
|
+
|
|
36
|
+
fs.ensureDirSync(dirname(file));
|
|
37
|
+
return fs.writeFile(file, JSON.stringify(pkg, null, 2), { encoding: "utf8" });
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function bumpDependencies(pkg, key, version, names) {
|
|
43
|
+
pkg[key] = pkg[key] || {};
|
|
44
|
+
|
|
45
|
+
if (pkg[key]) {
|
|
46
|
+
names.forEach((name) => {
|
|
47
|
+
if (pkg[key][name] && !pkg[key][name].startsWith("workspace:")) {
|
|
48
|
+
pkg[key][name] = version;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|