@cmflow/cli 0.65.1 → 0.65.4

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.
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ const commander = require('commander')
3
+ const { commands, runCommand } = require('../src')
4
+
5
+ commander
6
+ .usage('cmmerge')
7
+ .alias('cm merge')
8
+ .option('-v, --verbose', 'Enable verbose log', (v, t) => t + 1, 0)
9
+ .parse(process.argv)
10
+
11
+ runCommand(commands.Merge, commander)
package/bin/cm.js CHANGED
@@ -14,6 +14,7 @@ commander
14
14
  .command('publish-pages', 'Publish github pages')
15
15
  .command('deploy', 'Deploy app on docker hub/Heroku')
16
16
  .command('rebase', 'Rebase the current branch from production')
17
+ .command('merge', 'Merge current branch into PRODUCTION_BRANCH')
17
18
  .command('fetch', 'Download objects and refs from repository (--all and --prune)')
18
19
  .command('clean', 'Clean deployed docker image on Docker hub')
19
20
  .command('config', 'Configure git workspace with expected information')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmflow/cli",
3
- "version": "0.65.1",
3
+ "version": "0.65.4",
4
4
  "description": "An awesome Git Flow",
5
5
  "author": "camfou",
6
6
  "license": "MIT",
@@ -21,6 +21,7 @@
21
21
  "cmstart": "bin/cm-start.js",
22
22
  "checkfeatures": "./bin/checkfeatures.sh",
23
23
  "cmrelease": "./bin/cmrelease.js",
24
+ "cmmerge": "./bin/cm-merge.js",
24
25
  "cmchangelog": "bin/cm-changelog.js",
25
26
  "cmconfig": "bin/cm-config.js"
26
27
  },
@@ -8,3 +8,4 @@ export * from './rebase'
8
8
  export * from './publish-pages'
9
9
  export * from './clean'
10
10
  export * from './deploy'
11
+ export * from './merge'
@@ -0,0 +1,35 @@
1
+ import chalk from 'chalk'
2
+ import figures from 'figures'
3
+ import { mergeBranch } from './tasks/merge-branch'
4
+ import { getConfig, git } from '../common'
5
+
6
+ export class Merge {
7
+ mapContext (commander, context) {
8
+ return {
9
+ ...context,
10
+ config: getConfig()
11
+ }
12
+ }
13
+
14
+ getTasks (context) {
15
+ const { RELEASE_CANDIDATE_TAG } = context
16
+ this.lastCommitMessage = git.getLastCommitMsg()
17
+ if (this.lastCommitMessage.includes(RELEASE_CANDIDATE_TAG)) {
18
+ return [mergeBranch(context)]
19
+ }
20
+ return []
21
+ }
22
+
23
+ success (context) {
24
+ const { RELEASE_CANDIDATE_TAG } = context
25
+ if (this.lastCommitMessage.includes(RELEASE_CANDIDATE_TAG)) {
26
+ // eslint-disable-next-line no-console
27
+ console.log(chalk.green(figures.tick), 'Branch', chalk.green(context.BRANCH_NAME), `merged into ${context.PRODUCTION_BRANCH}`)
28
+ } else {
29
+ // eslint-disable-next-line no-console
30
+ console.log(chalk.green(figures.tick), 'Merge branch', chalk.green(context.BRANCH_NAME), `into ${context.PRODUCTION_BRANCH} not required`)
31
+ // eslint-disable-next-line no-console
32
+ console.log(chalk.green(figures.tick), 'Last commit message : ', chalk.green(this.lastCommitMessage), `does not contains ${RELEASE_CANDIDATE_TAG}`)
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,61 @@
1
+ import { git } from '../../common'
2
+
3
+ function setGHToken (context) {
4
+ const {
5
+ logger,
6
+ config: { GH_TOKEN, REPOSITORY_URL, ORIGIN }
7
+ } = context
8
+
9
+ if (GH_TOKEN) {
10
+ const repository = REPOSITORY_URL.replace('https://', '')
11
+
12
+ logger.info(`Configure remote repository ${repository}`)
13
+ git.remote('remove', ORIGIN).sync()
14
+ git.remote('add', ORIGIN, `https://${GH_TOKEN}@${repository}`).sync()
15
+ }
16
+ }
17
+
18
+ async function gitMep (context) {
19
+ const { logger, branch, config: { PRODUCTION_BRANCH, ORIGIN } } = context
20
+
21
+ logger.info(`Branch ${branch.name} is candidate to MEP`)
22
+
23
+ git.reset('--hard')
24
+ git.clean('-f', '-d').sync()
25
+
26
+ logger.start('Checkout production branch')
27
+
28
+ git.config('--replace-all', 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*')
29
+ git.fetch().sync()
30
+ git.fetch('--tags').sync()
31
+ git.checkout('-qf', PRODUCTION_BRANCH).sync()
32
+
33
+ logger.success(`Current branch: ${PRODUCTION_BRANCH}`)
34
+
35
+ const building = git.getLastCommitMsg()
36
+ logger.info('Last commit message on production', building)
37
+
38
+ logger.start(`Merge ${branch.name} into ${PRODUCTION_BRANCH} branch`)
39
+ git.merge('--no-ff', '-m', `${branch.name}`, branch.name)
40
+ logger.success(`${branch.name} merged into ${PRODUCTION_BRANCH} branch`)
41
+
42
+ setGHToken(context)
43
+
44
+ logger.start(`Push ${PRODUCTION_BRANCH} branch`)
45
+ await git.push(ORIGIN, PRODUCTION_BRANCH)
46
+ logger.success(`${PRODUCTION_BRANCH} branch pushed`)
47
+
48
+ logger.start(`Remove ${ORIGIN}/${branch.name} branch`)
49
+ await git.push(ORIGIN, ':' + branch.name)
50
+ logger.success(`${ORIGIN}/${branch.name} branch correctly removed`)
51
+ }
52
+
53
+ export function mergeBranch (context) {
54
+ const { BRANCH_NAME, PRODUCTION_BRANCH } = context
55
+ return ({
56
+ title: `Merge ${BRANCH_NAME} into ${PRODUCTION_BRANCH}`,
57
+ task: async () => {
58
+ await gitMep(context)
59
+ }
60
+ })
61
+ }
@@ -1,41 +1,6 @@
1
1
  import { dockerPublish } from '../utils/docker-publish'
2
2
  import { git, lerna, npm, yarn, configureGitWorkspace } from '../../common'
3
3
 
4
- async function gitMep (context) {
5
- const { logger, branch, config: { PRODUCTION_BRANCH, ORIGIN } } = context
6
-
7
- logger.info(`Branch ${branch.name} is candidate to MEP`)
8
-
9
- git.reset('--hard')
10
- git.clean('-f', '-d').sync()
11
-
12
- logger.start('Checkout production branch')
13
-
14
- git.config('--replace-all', 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*')
15
- git.fetch().sync()
16
- git.fetch('--tags').sync()
17
- git.checkout('-qf', PRODUCTION_BRANCH).sync()
18
-
19
- logger.success(`Current branch: ${PRODUCTION_BRANCH}`)
20
-
21
- const building = git.getLastCommitMsg()
22
- logger.info('Last commit message on production', building)
23
-
24
- logger.start(`Merge ${branch.name} into ${PRODUCTION_BRANCH} branch`)
25
- git.merge('--no-ff', '-m', `${branch.name}`, branch.name)
26
- logger.success(`${branch.name} merged into ${PRODUCTION_BRANCH} branch`)
27
-
28
- configureGitWorkspace(context)
29
-
30
- logger.start(`Push ${PRODUCTION_BRANCH} branch`)
31
- await git.push(ORIGIN, PRODUCTION_BRANCH)
32
- logger.success(`${PRODUCTION_BRANCH} branch pushed`)
33
-
34
- logger.start(`Remove ${ORIGIN}/${branch.name} branch`)
35
- await git.push(ORIGIN, ':' + branch.name)
36
- logger.success(`${ORIGIN}/${branch.name} branch correctly removed`)
37
- }
38
-
39
4
  async function gitPrepareRelease (pluginConfig, context) {
40
5
  const { logger, config: { CI_NAME, BUILD_NUMBER } } = context
41
6
 
@@ -85,10 +50,8 @@ export async function prepare (pluginConfig, context) {
85
50
  }
86
51
 
87
52
  const lastCommitMessage = git.getLastCommitMsg()
88
-
89
53
  logger.info('Last commit message:', lastCommitMessage)
90
54
  if (lastCommitMessage.includes(RELEASE_CANDIDATE_TAG)) {
91
- await gitMep(context)
92
55
  process.exit(0)
93
56
  }
94
57
  }