@cmflow/cli 2.0.0-alpha.1 → 2.0.0-alpha.10

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/.yarnrc.yml ADDED
@@ -0,0 +1,3 @@
1
+ nodeLinker: node-modules
2
+
3
+ yarnPath: .yarn/releases/yarn-4.7.0.cjs
package/README.md CHANGED
@@ -50,7 +50,15 @@ export default defineConfig({
50
50
  verifyConditions: ['@cmflow/cli/semantic/verify-conditions'],
51
51
  analyzeCommits: ['@cmflow/cli/semantic/analyze-commits'],
52
52
  verifyRelease: ['@cmflow/cli/semantic/verify-release'],
53
- generateNotes: ['@cmflow/cli/semantic/generate-notes'],
53
+ generateNotes: [
54
+ [
55
+ "@cmflow/cli/semantic/conditional", // add this task to trigger build npm task
56
+ {
57
+ // when: (context) => context.branch.type === "release" // default condition to run the task
58
+ run: ["@semantic-release/release-notes-generator"]
59
+ }
60
+ ]
61
+ ],
54
62
  prepare: [
55
63
  '@cmflow/cli/semantic/prepare/bump-version',
56
64
  [
@@ -65,19 +73,36 @@ export default defineConfig({
65
73
  command: 'test_e2e'
66
74
  }
67
75
  ],
68
- '@cmflow/cli/semantif/prepare/post'
76
+ [
77
+ '@cmflow/cli/semantic/conditional', // add this task to trigger build npm task
78
+ {
79
+ // when: (context) => context.branch.type === "release" // default condition to run the task
80
+ run: [
81
+ '@cmflow/cli/semantic/core/prepare/commit'
82
+ ]
83
+ }
84
+ ]
69
85
  ],
70
86
  publish: [
71
87
  [
72
88
  '@cmflow/cli/semantic/conditional',
73
89
  {
74
90
  // 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
91
+ run: [
92
+ '@cmflow/cli/semantic/publish/sync-repository',
93
+ '@semantic-release/github'
94
+ ] // only run if the conditional rule is true
95
+ }
96
+ ],
97
+ [
98
+ '@cmflow/cli/semantic/conditional', // run process.exit(0) if the branch is not a release branch - legacy: maybe not necessary now all task are conditional
99
+ {
100
+ when: (context) => context.branch.type !== 'release',
101
+ run: '@cmflow/cli/semantic/publish/exit.js'
76
102
  }
77
103
  ]
78
104
  ],
79
105
  success: [
80
- '@cmflow/cli/semantic/success',
81
106
  [
82
107
  '@cmflow/cli/semantic/conditional',
83
108
  {
@@ -87,9 +112,8 @@ export default defineConfig({
87
112
  ]
88
113
  ],
89
114
  fail: [
90
- '@cmflow/cli/semantic/fail',
91
115
  [
92
- '@cmflow/cli/semantic/conditional',
116
+ "@cmflow/cli/semantic/conditional",
93
117
  {
94
118
  // when: (context) => context.branch.type === "release" // default condition to run the task
95
119
  run: '@semantic-release/github' // only run if the conditional rule is true
@@ -149,6 +173,26 @@ Example:
149
173
  }
150
174
  ```
151
175
 
176
+ ### Generate release.info file
177
+
178
+ CmFlow release generate a `release.info` file in the root of your project. This file contains the branch name.
179
+
180
+ ```js
181
+ import { defineConfig } from '@cmflow/cli'
182
+
183
+ export default defineConfig({
184
+ prepare: [
185
+ '@cmflow/cli/semantic/prepare/bump-version',
186
+ [
187
+ '@cmflow/cli/semantic/prepare/release-info',
188
+ {
189
+ path: './resources/release.info'
190
+ }
191
+ ]
192
+ ]
193
+ })
194
+ ```
195
+
152
196
  ### Deploy on Docker Hub
153
197
 
154
198
  Add the following configuration to your `release.config.js`:
package/bin/cm-config.js CHANGED
File without changes
package/bin/cm-fetch.js CHANGED
File without changes
package/bin/cm-finish.js CHANGED
File without changes
package/bin/cm-merge.js CHANGED
File without changes
package/bin/cm-publish.js CHANGED
File without changes
package/bin/cm-push.js CHANGED
File without changes
package/bin/cm-rebase.js CHANGED
File without changes
File without changes
package/bin/cm-start.js CHANGED
File without changes
package/bin/cm.js CHANGED
File without changes
package/bin/cmrelease.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmflow/cli",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.10",
4
4
  "description": "An awesome Git Flow",
5
5
  "author": "camfou",
6
6
  "license": "MIT",
@@ -8,36 +8,31 @@
8
8
  "main": "./src/index.js",
9
9
  "module": "./src/index.js",
10
10
  "type": "module",
11
- "private": false,
12
11
  "bin": {
12
+ "checkfeatures": "./bin/checkfeatures.sh",
13
13
  "cm": "./bin/cm.js",
14
+ "cmconfig": "bin/cm-config.js",
15
+ "cmexpedit": "./bin/cmexpedit.sh",
14
16
  "cmfetch": "bin/cm-fetch.js",
15
- "cmrebase": "bin/cm-rebase.js",
16
17
  "cmfinish": "bin/cm-finish.js",
17
- "cmexpedit": "./bin/cmexpedit.sh",
18
+ "cmmerge": "./bin/cm-merge.js",
18
19
  "cmpublish": "bin/cm-publish.js",
19
- "cmrepublish": "bin/cm-republish.js",
20
- "cmpush": "bin/cm-push.js",
21
20
  "cmpull": "./bin/cmpull.sh",
22
- "cmstart": "bin/cm-start.js",
23
- "checkfeatures": "./bin/checkfeatures.sh",
21
+ "cmpush": "bin/cm-push.js",
22
+ "cmrebase": "bin/cm-rebase.js",
24
23
  "cmrelease": "./bin/cmrelease.js",
25
- "cmmerge": "./bin/cm-merge.js",
26
- "cmchangelog": "bin/cm-changelog.js",
27
- "cmconfig": "bin/cm-config.js"
24
+ "cmrepublish": "bin/cm-republish.js",
25
+ "cmstart": "bin/cm-start.js"
28
26
  },
29
27
  "exports": {
30
- ".": "./index.js",
31
- "./semantic/prepare/*": "./src/semantic-release/core/prepare/*.js",
32
- "./semantic/*": "./src/semantic-release/core/*.js",
33
- "./semantic/docker/*": "./src/semantic-release/docker/*.js"
28
+ ".": "./src/index.js",
29
+ "./semantic/*": "./src/semantic/*.js"
34
30
  },
35
31
  "dependencies": {
32
+ "any-observable": "0.5.1",
36
33
  "axios": "1.8.2",
37
34
  "chalk": "^4.1.0",
38
35
  "commander": "5.1.0",
39
- "conventional-changelog": "3.1.25",
40
- "conventional-changelog-cli": "2.2.2",
41
36
  "execa": "5.1.1",
42
37
  "figures": "3.2.0",
43
38
  "fs-extra": "^10.1.0",
@@ -47,14 +42,16 @@
47
42
  "listr": "0.14.3",
48
43
  "lodash": "4.17.21",
49
44
  "rxjs": "7.8.1",
50
- "semantic-release": "23.1.1",
51
- "semver": "7.3.7",
45
+ "semantic-release": ">=24.2.3",
46
+ "semver": "7.7.1",
52
47
  "split": "1.0.1"
53
48
  },
54
49
  "devDependencies": {
50
+ "@semantic-release/github": "11.0.1",
51
+ "@semantic-release/release-notes-generator": ">=14.0.3",
55
52
  "@stylistic/eslint-plugin": "^4.2.0",
56
- "@typescript-eslint/parser": "8.26.1",
57
53
  "@typescript-eslint/eslint-plugin": "8.26.1",
54
+ "@typescript-eslint/parser": "8.26.1",
58
55
  "eslint": "9.21.0",
59
56
  "eslint-config-prettier": "10.0.2",
60
57
  "eslint-formatter-junit": "^8.40.0",
@@ -62,15 +59,14 @@
62
59
  "eslint-plugin-simple-import-sort": "12.1.1",
63
60
  "eslint-plugin-vitest": "0.5.4",
64
61
  "husky": "4.3.6",
65
- "prettier": "3.5.1",
66
62
  "lint-staged": "10.5.3",
67
- "vitest": "^3.0.8",
68
- "typescript": "5.8.2"
63
+ "prettier": "3.5.1",
64
+ "typescript": "5.8.2",
65
+ "vitest": "^3.0.8"
69
66
  },
70
67
  "peerDependencies": {
71
- "@semantic-release/commit-analyzer": "^11.1.0",
72
- "@semantic-release/github": "^10.1.1",
73
- "@semantic-release/release-notes-generator": "^12.1.0"
68
+ "@semantic-release/commit-analyzer": ">=13.0.1",
69
+ "@semantic-release/release-notes-generator": ">=14.0.3"
74
70
  },
75
71
  "peerDependenciesMeta": {
76
72
  "@semantic-release/commit-analyzer": {
@@ -87,8 +83,7 @@
87
83
  "lint_ci": "eslint --format junit --output-file ./reports/eslint.xml",
88
84
  "lint_fix": "eslint --fix",
89
85
  "release": "node bin/cmrelease.js",
90
- "release_dry_run": "node bin/cmrelease.js --dry-run",
91
- "build_changelog": "node bin/cm-changelog.js"
86
+ "release_dry_run": "node bin/cmrelease.js --dry-run"
92
87
  },
93
88
  "husky": {
94
89
  "hooks": {
@@ -107,5 +102,6 @@
107
102
  "develop": "master",
108
103
  "production": "master"
109
104
  }
110
- }
105
+ },
106
+ "packageManager": "yarn@4.7.0"
111
107
  }
@@ -22,18 +22,17 @@ export default defineConfig({
22
22
  verifyConditions: ["./src/semantic/core/verify-conditions.js"],
23
23
  analyzeCommits: ["@semantic-release/commit-analyzer"],
24
24
  verifyRelease: ["./src/semantic/core/verify-release.js"],
25
- generateNotes: ["./src/semantic/core/generate-notes.js"],
26
- prepare: ["./src/semantic/core/prepare/bump-version.js", "./src/semantic/core/prepare/post.js"],
27
- publish: ["@semantic-release/github"],
28
- success: [
25
+ generateNotes: [
29
26
  [
30
- "./src/semantic/core/success.js",
27
+ "./src/semantic/core/conditional",
31
28
  {
32
- when: () => true
29
+ run: ["@semantic-release/release-notes-generator"]
33
30
  }
34
- ],
35
- "@semantic-release/github"
31
+ ]
36
32
  ],
33
+ prepare: ["./src/semantic/core/prepare/bump-version.js", "./src/semantic/core/prepare/commit.js"],
34
+ publish: ["./src/semantic/core/publish/sync-repository.js", "@semantic-release/github"],
35
+ success: ["@semantic-release/github"],
37
36
  fail: ["@semantic-release/github"],
38
37
  npmPublish: false
39
38
  });
@@ -1,4 +1,3 @@
1
- export * from "./changelog.js";
2
1
  export * from "./clean.js";
3
2
  export * from "./deploy.js";
4
3
  export * from "./fetch.js";
@@ -1,25 +1,42 @@
1
1
  import { getConfig } from "../../common/index.js";
2
+
3
+ export function prepare(pluginConfig, context) {
4
+ return runAll("prepare", pluginConfig, context, context.branch?.type === "release");
5
+ }
6
+
2
7
  export function success(pluginConfig, context) {
3
- return runAll(pluginConfig, context, context.branch?.type === "release");
8
+ return runAll("success", pluginConfig, context, context.branch?.type === "release");
4
9
  }
5
10
 
6
11
  export function publish(pluginConfig, context) {
7
- return runAll(pluginConfig, context, context.branch?.type === "release");
12
+ return runAll("publish", pluginConfig, context, context.branch?.type === "release");
13
+ }
14
+
15
+ export function generateNotes(pluginConfig, context) {
16
+ return runAll("generateNotes", pluginConfig, context, context.branch?.type === "release");
8
17
  }
9
18
 
10
19
  export function fail(pluginConfig, context) {
11
- return runAll(pluginConfig, context, context.branch?.type === "release");
20
+ return runAll("fail", pluginConfig, context, context.branch?.type === "release");
12
21
  }
13
22
 
14
- async function runAll(pluginConfig, context, defaultCondition) {
23
+ async function runAll(step, pluginConfig, context, defaultCondition) {
15
24
  context.config = getConfig();
16
25
 
17
26
  const condition = pluginConfig.when !== undefined ? pluginConfig.if(context) : defaultCondition;
18
27
 
19
28
  if (condition && pluginConfig.run) {
20
29
  const tasks = [].concat(pluginConfig.run);
30
+
21
31
  for (const task of tasks) {
22
- await task(pluginConfig, context);
32
+ if (typeof task === "string") {
33
+ const mod = await import(task);
34
+ const taskFunction = mod[step];
35
+
36
+ if (taskFunction) {
37
+ await taskFunction(pluginConfig, context);
38
+ }
39
+ }
23
40
  }
24
41
  }
25
42
  }
@@ -0,0 +1,29 @@
1
+ import { configureGitWorkspace, getConfig, git } from "../../../common/index.js";
2
+
3
+ export async function prepare(pluginConfig, context) {
4
+ context.config = getConfig();
5
+
6
+ const {
7
+ logger,
8
+ config: { CI_NAME, BUILD_NUMBER }
9
+ } = context;
10
+
11
+ logger.info("Prepare release");
12
+
13
+ configureGitWorkspace(context);
14
+
15
+ logger.info("Adding files to commit");
16
+ git.add("-A").sync();
17
+
18
+ logger.info("Get commit stage status");
19
+ git.status();
20
+
21
+ const revisionMessage = `${CI_NAME} build: ${context.branch.name} ${BUILD_NUMBER} ${context.nextRelease.gitTag} [ci skip]`;
22
+
23
+ logger.info("Commit changes with revision message: ");
24
+ logger.info(revisionMessage);
25
+
26
+ git.commit("-m", revisionMessage).sync();
27
+
28
+ logger.success("Change committed");
29
+ }
@@ -0,0 +1,5 @@
1
+ import { writeFile } from "node:fs/promises";
2
+
3
+ export function prepare(pluginConfig, context) {
4
+ return writeFile(pluginConfig.path, context.branch.name, { encoding: "utf-8" });
5
+ }
@@ -0,0 +1,7 @@
1
+ import { getConfig } from "../../../common/index.js";
2
+
3
+ export async function prepare(pluginConfig, context) {
4
+ context.config = getConfig();
5
+ // avoid next semantic-release steps when is a prerelease or release branch with SKIP_GITHUB_PUBLISH
6
+ process.exit(0);
7
+ }
@@ -0,0 +1,42 @@
1
+ import { getConfig, git } from "../../../common/index.js";
2
+
3
+ export async function publish(pluginConfig, context) {
4
+ context.config = getConfig();
5
+
6
+ const {
7
+ logger,
8
+ config: { PRODUCTION_BRANCH, ORIGIN, DEVELOP_BRANCH }
9
+ } = context;
10
+
11
+ logger.info("Prepare release");
12
+
13
+ async function asyncCatchError(fn) {
14
+ try {
15
+ return await fn();
16
+ } catch (er) {
17
+ context.logger.error(String(er), er.stack);
18
+ }
19
+ }
20
+
21
+ await asyncCatchError(() => git.fetch());
22
+
23
+ if ([PRODUCTION_BRANCH, "alpha", "beta", "rc"].includes(context.branch.name)) {
24
+ logger.info(`Push ${PRODUCTION_BRANCH}`);
25
+
26
+ await asyncCatchError(() => {
27
+ logger.info(`git push --quiet --set-upstream ${ORIGIN} ${context.branch.name}`);
28
+
29
+ return git.push("--quiet", "--set-upstream", ORIGIN, context.branch.name);
30
+ });
31
+ }
32
+
33
+ if (PRODUCTION_BRANCH !== DEVELOP_BRANCH) {
34
+ logger.info(`Sync ${DEVELOP_BRANCH} with ${PRODUCTION_BRANCH}`);
35
+ logger.info(`git push -f ${ORIGIN} ${PRODUCTION_BRANCH}:refs/heads/${DEVELOP_BRANCH}`);
36
+
37
+ await asyncCatchError(async () => {
38
+ await git.push("-f", ORIGIN, `${PRODUCTION_BRANCH}:refs/heads/${DEVELOP_BRANCH}`);
39
+ logger.success(`${ORIGIN}/${DEVELOP_BRANCH} branch correctly updated`);
40
+ });
41
+ }
42
+ }
@@ -16,6 +16,8 @@ const transformCommitType = (commit) => {
16
16
  };
17
17
 
18
18
  export function transformWriter(commit, context) {
19
+ commit = { ...commit };
20
+
19
21
  const issues = [];
20
22
 
21
23
  commit.notes.forEach((note) => {
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import commander from "commander";
4
-
5
- import { commands, runCommand } from "../src/index.js";
6
-
7
- commander
8
- .usage("cmchangelog [options]")
9
- .alias("cm changelog")
10
- .option(
11
- "-p, --preset <preset>",
12
- "Name of the preset you want to use. Must be one of the following:\n" +
13
- "angular, atom, codemirror, ember, eslint, express, jquery, jscs or jshint",
14
- "angular"
15
- )
16
- .option(
17
- "-r, --release-count <count>",
18
- "How many releases to be generated from the latest\n" +
19
- "If 0, the whole changelog will be regenerated and the outfile will be overwritten\n" +
20
- "Default: 0",
21
- 0
22
- )
23
- .option("-t, --tag-prefix <prefix>", "Tag prefix to consider when reading the tags")
24
- .parse(process.argv);
25
-
26
- runCommand(commands.Changelog, commander);
@@ -1,47 +0,0 @@
1
- import conventionalChangelog from "conventional-changelog";
2
- import { createWriteStream } from "fs";
3
- import { Observable } from "rxjs";
4
-
5
- export class Changelog {
6
- mapContext(commander, config) {
7
- return {
8
- preset: commander.preset || "angular",
9
- releaseCount: commander.releaseCount || 0,
10
- outfile: `${process.cwd()}/CHANGELOG.md`,
11
-
12
- tagPrefix: (config.tagFormat || commander.tagPrefix || "").replace("${version}", "")
13
- };
14
- }
15
-
16
- exec({ preset, releaseCount, outfile, tagPrefix }) {
17
- const writableStream = createWriteStream(outfile, { encoding: "utf8" });
18
-
19
- return new Observable((observer) => {
20
- const stream = conventionalChangelog({
21
- preset,
22
- releaseCount,
23
- path: `${process.cwd()}/package.json`,
24
- tagPrefix
25
- });
26
-
27
- stream.pipe(writableStream);
28
-
29
- stream.on("error", (err) => {
30
- observer.error(err);
31
- });
32
-
33
- stream.on("end", () => {
34
- observer.complete();
35
- });
36
- });
37
- }
38
-
39
- getTasks(ctx) {
40
- return [
41
- {
42
- title: "Generate changelog",
43
- task: () => this.exec(ctx)
44
- }
45
- ];
46
- }
47
- }
@@ -1,21 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
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
- }
@@ -1,38 +0,0 @@
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
- }
@@ -1,33 +0,0 @@
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
- }