@cmflow/cli 1.1.1-alpha.1 → 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/README.md CHANGED
@@ -69,25 +69,30 @@ export default defineConfig({
69
69
  ],
70
70
  publish: [
71
71
  [
72
- '@cmflow/cli/semantic/publish',
72
+ '@cmflow/cli/semantic/conditional',
73
73
  {
74
- runAfter: "@semantic-release/github" // only run if the conditional rule is true
74
+ // when: (context) => context.branch.type === "release" // default condition to run the task
75
+ run: '@semantic-release/github' // only run if the conditional rule is true
75
76
  }
76
77
  ]
77
78
  ],
78
79
  success: [
80
+ '@cmflow/cli/semantic/success',
79
81
  [
80
- '@cmflow/cli/semantic/publish',
82
+ '@cmflow/cli/semantic/conditional',
81
83
  {
82
- runAfter: "@semantic-release/github" // only run if the conditional rule is true
84
+ // when: (context) => context.branch.type === "release" // default condition to run the task
85
+ run: '@semantic-release/github' // only run if the conditional rule is true
83
86
  }
84
87
  ]
85
88
  ],
86
89
  fail: [
90
+ '@cmflow/cli/semantic/fail',
87
91
  [
88
- '@cmflow/cli/semantic/fail',
92
+ '@cmflow/cli/semantic/conditional',
89
93
  {
90
- runAfter: "@semantic-release/github" // only run if the conditional rule is true
94
+ // when: (context) => context.branch.type === "release" // default condition to run the task
95
+ run: '@semantic-release/github' // only run if the conditional rule is true
91
96
  }
92
97
  ]
93
98
  ],
@@ -108,6 +113,25 @@ Then edit your `package.json` add the following tasks on script property:
108
113
 
109
114
  Now, CmFlow and semantic release are correctly installed on your project.
110
115
 
116
+ ### Condition step (publish, success, fail)
117
+
118
+ CMFlow provide a `@cmflow/cli/semantic/conditional` task to run one task or many task only if a condition is true. The condition is a
119
+ function that takes the semantic context as parameter and return a boolean.
120
+
121
+ You can customize the condition to run the task by adding a `when` property to the configuration object.
122
+
123
+ ```javascript
124
+ export default defineConfig({
125
+ publish: [
126
+ '@cmflow/cli/semantic/conditional',
127
+ {
128
+ when: (context) => context.branch.type === 'release', // default condition to run the task
129
+ run: ['@semantic-release/github', '@semantic-release/github'] // only run if the conditional rule is true
130
+ }
131
+ ]
132
+ })
133
+ ```
134
+
111
135
  ### Build and E2E Test
112
136
 
113
137
  CmFlow release are able to run `build` and `test_e2e` task during the prepare step. It's useful when you want to
@@ -135,9 +159,9 @@ import { defineConfig } from '@cmflow/cli'
135
159
  export default defineConfig({
136
160
  publish: [
137
161
  [
138
- '@cmflow/cli/semantic/publish',
162
+ '@cmflow/cli/semantic/conditional',
139
163
  {
140
- runAfter: '@semantic-release/github' // only run if the conditional rule is true
164
+ run: '@semantic-release/github'
141
165
  }
142
166
  ],
143
167
  '@cmflow/cli/semantic/docker/publish'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmflow/cli",
3
- "version": "1.1.1-alpha.1",
3
+ "version": "2.0.0-alpha.1",
4
4
  "description": "An awesome Git Flow",
5
5
  "author": "camfou",
6
6
  "license": "MIT",
@@ -20,33 +20,20 @@ export default defineConfig({
20
20
  }
21
21
  ],
22
22
  verifyConditions: ["./src/semantic/core/verify-conditions.js"],
23
- analyzeCommits: ["./src/semantic/core/analyze-commits.js"],
23
+ analyzeCommits: ["@semantic-release/commit-analyzer"],
24
24
  verifyRelease: ["./src/semantic/core/verify-release.js"],
25
25
  generateNotes: ["./src/semantic/core/generate-notes.js"],
26
26
  prepare: ["./src/semantic/core/prepare/bump-version.js", "./src/semantic/core/prepare/post.js"],
27
- publish: [
28
- [
29
- "./src/semantic/core/publish.js",
30
- {
31
- runAfter: "@semantic-release/github"
32
- }
33
- ]
34
- ],
27
+ publish: ["@semantic-release/github"],
35
28
  success: [
36
29
  [
37
30
  "./src/semantic/core/success.js",
38
31
  {
39
- runAfter: "@semantic-release/github"
40
- }
41
- ]
42
- ],
43
- fail: [
44
- [
45
- "./src/semantic/core/fail.js",
46
- {
47
- runAfter: "@semantic-release/github"
32
+ when: () => true
48
33
  }
49
- ]
34
+ ],
35
+ "@semantic-release/github"
50
36
  ],
37
+ fail: ["@semantic-release/github"],
51
38
  npmPublish: false
52
39
  });
@@ -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
+ }
@@ -3,9 +3,7 @@ import { git } from "../../common/index.js";
3
3
  /**
4
4
  * Remove the tag from the git repository if the release is not a prerelease.
5
5
  *
6
- * Add runAfter property with the semantic-release plugin name to run after the fail task.
7
- *
8
- * @param pluginConfig {{runAfter: string}}
6
+ * @param pluginConfig
9
7
  * @param context
10
8
  * @return {Promise<void>}
11
9
  */
@@ -19,11 +17,5 @@ export async function fail(pluginConfig, context) {
19
17
  try {
20
18
  await git.push("--delete", ORIGIN, tagFormat.replace("${version}", context.nextRelease.version));
21
19
  } catch {}
22
-
23
- if (pluginConfig.runAfter) {
24
- const { fail } = await import(pluginConfig.runAfter);
25
-
26
- await fail(pluginConfig, context);
27
- }
28
20
  }
29
21
  }
@@ -5,7 +5,7 @@ import { git } from "../../common/index.js";
5
5
  * Add runAfter property with the semantic-release plugin name to run after the success task
6
6
  * depending on the branch type.
7
7
  *
8
- * @param pluginConfig {{runAfter: string}}
8
+ * @param pluginConfig {{}}
9
9
  * @param context
10
10
  * @return {Promise<void>}
11
11
  */
@@ -17,7 +17,9 @@ export async function success(pluginConfig, context) {
17
17
  config: { PRODUCTION_BRANCH, ORIGIN, DEVELOP_BRANCH }
18
18
  } = context;
19
19
 
20
- if (branch.type !== "prerelease") {
20
+ const condition = pluginConfig.when !== undefined ? pluginConfig.when(context) : branch.type !== "prerelease";
21
+
22
+ if (condition) {
21
23
  await git.push("--quiet", "--set-upstream", ORIGIN, PRODUCTION_BRANCH);
22
24
 
23
25
  if (PRODUCTION_BRANCH !== DEVELOP_BRANCH) {
@@ -27,11 +29,5 @@ export async function success(pluginConfig, context) {
27
29
 
28
30
  logger.success(`${ORIGIN}/${DEVELOP_BRANCH} branch correctly updated`);
29
31
  }
30
-
31
- if (pluginConfig.runAfter) {
32
- const { success } = await import(pluginConfig.runAfter);
33
-
34
- await success(pluginConfig, context);
35
- }
36
32
  }
37
33
  }
@@ -2,4 +2,14 @@ import omit from "lodash/omit.js";
2
2
 
3
3
  import { WORKFLOW_CONFIGURATION } from "../../workflow/index.js";
4
4
 
5
- export const releaseRules = WORKFLOW_CONFIGURATION.map((props) => omit(props, ["label"]));
5
+ export const releaseRules = [
6
+ {
7
+ breaking: true,
8
+ release: "major"
9
+ },
10
+ {
11
+ revert: true,
12
+ release: "patch"
13
+ },
14
+ ...WORKFLOW_CONFIGURATION.map((props) => omit(props, ["label"]))
15
+ ];
@@ -1,9 +0,0 @@
1
- export async function publish(pluginConfig, context) {
2
- const { branch } = context;
3
-
4
- if (branch.type === "release" && pluginConfig.runAfter) {
5
- const { publish } = await import(pluginConfig.runAfter);
6
-
7
- await publish(pluginConfig, context);
8
- }
9
- }