@takeshape/cli 8.268.2 → 8.271.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.
@@ -0,0 +1,2 @@
1
+ export declare const mergeBranch: import("../../../types").Handler;
2
+ //# sourceMappingURL=merge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../../../src/commands/branch/commands/merge.ts"],"names":[],"mappings":"AA2FA,eAAO,MAAM,WAAW,kCAsEtB,CAAC"}
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.mergeBranch = void 0;
7
+
8
+ var _linkedCommand = require("../../../util/linked-command");
9
+
10
+ var _graphql = require("../../../graphql");
11
+
12
+ var _log = _interopRequireDefault(require("../../../log"));
13
+
14
+ var _chalk = _interopRequireDefault(require("chalk"));
15
+
16
+ var _branches = require("../../../util/branches");
17
+
18
+ var _fatalError = require("../../../util/fatal-error");
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ const getBranchQuery = (0, _graphql.graphQLQuery)(
23
+ /* GraphQL */
24
+ `
25
+ query CliGetBranchQuery($projectId: String!, $environment: TSSchemaBranchEnvironment!, $branchName: String) {
26
+ result: tsGetSchemaBranch(projectId: $projectId, environment: $environment, branchName: $branchName) {
27
+ latestVersion {
28
+ branchName
29
+ environment
30
+ version
31
+ }
32
+ }
33
+ }
34
+ `);
35
+ const getBranchParentQuery = (0, _graphql.graphQLQuery)(
36
+ /* GraphQL */
37
+ `
38
+ query CliGetBranchParentQuery($projectId: String!, $environment: TSSchemaBranchEnvironment!, $branchName: String) {
39
+ result: tsGetSchemaBranch(projectId: $projectId, environment: $environment, branchName: $branchName) {
40
+ parentVersion {
41
+ branchName
42
+ environment
43
+ }
44
+ }
45
+ }
46
+ `);
47
+ const mergeBranchMutation = (0, _graphql.graphQLQuery)(
48
+ /* GraphQL */
49
+ `
50
+ mutation CliMergeBranchMutation($input: TSMergeSchemaBranchInput!) {
51
+ result: tsMergeSchemaBranch(input: $input) {
52
+ dryRun
53
+ deletedBranch {
54
+ environment
55
+ branchName
56
+ }
57
+ mergedBranch {
58
+ environment
59
+ branchName
60
+ }
61
+ }
62
+ }
63
+ `);
64
+
65
+ function ensureHeadArgs(cli) {
66
+ if (!cli.flags.head) {
67
+ throw new Error('You must provide a --head to merge.');
68
+ }
69
+
70
+ return (0, _branches.getBranchArgs)(cli.flags.head);
71
+ }
72
+
73
+ const mergeBranch = (0, _linkedCommand.loggedInAndLinkedCommand)(async (cli, params) => {
74
+ try {
75
+ const {
76
+ dryRun,
77
+ deleteMergedBranch
78
+ } = cli.flags;
79
+ const {
80
+ projectId
81
+ } = params;
82
+ const head = ensureHeadArgs(cli);
83
+ const baseInput = cli.flags.base && (0, _branches.getBranchArgs)(cli.flags.base);
84
+ const targetInput = cli.flags.target && (0, _branches.getBranchArgs)(cli.flags.target);
85
+ const client = (0, _graphql.createAdminConnector)(params, params.authToken, projectId);
86
+ let base;
87
+
88
+ if (baseInput) {
89
+ const baseQueryResult = await getBranchQuery(client, {
90
+ projectId,
91
+ ...baseInput
92
+ });
93
+
94
+ if (!(baseQueryResult !== null && baseQueryResult !== void 0 && baseQueryResult.latestVersion)) {
95
+ return (0, _fatalError.fatalError)('Base branch does not exist');
96
+ }
97
+
98
+ const {
99
+ environment,
100
+ branchName
101
+ } = baseQueryResult.latestVersion;
102
+ base = {
103
+ environment,
104
+ branchName
105
+ };
106
+ } else {
107
+ const parentQueryResult = await getBranchParentQuery(client, {
108
+ projectId,
109
+ ...head
110
+ });
111
+
112
+ if (!(parentQueryResult !== null && parentQueryResult !== void 0 && parentQueryResult.parentVersion)) {
113
+ return (0, _fatalError.fatalError)('Head branch does not exist');
114
+ }
115
+
116
+ base = parentQueryResult.parentVersion;
117
+ }
118
+
119
+ const targetParams = targetInput ? {
120
+ projectId,
121
+ ...targetInput
122
+ } : {
123
+ projectId,
124
+ ...base
125
+ };
126
+ const branchQueryResult = await getBranchQuery(client, targetParams);
127
+
128
+ if (!(branchQueryResult !== null && branchQueryResult !== void 0 && branchQueryResult.latestVersion)) {
129
+ return (0, _fatalError.fatalError)('Target branch does not exist');
130
+ }
131
+
132
+ const target = branchQueryResult.latestVersion;
133
+ const res = await mergeBranchMutation(client, {
134
+ input: {
135
+ deleteMergedHead: deleteMergedBranch ?? false,
136
+ dryRun: dryRun ?? false,
137
+ projectId,
138
+ head,
139
+ base,
140
+ target
141
+ }
142
+ });
143
+ const headBranchName = head.branchName ?? head.environment.toLowerCase();
144
+ const baseBranchName = base.branchName ?? base.environment.toLocaleLowerCase();
145
+ const targetBranchName = target.branchName ?? target.environment.toLocaleLowerCase();
146
+ const deletedBranchName = res.deletedBranch ? res.deletedBranch.branchName ?? res.deletedBranch.environment : undefined;
147
+ const dryRunText = res.dryRun ? _chalk.default.blue('[DRY RUN]') : '';
148
+ (0, _log.default)(_chalk.default.green(`${dryRunText} Head branch "${headBranchName}" was merged into base branch "${baseBranchName}"`.trim()));
149
+ (0, _log.default)(_chalk.default.green(`${dryRunText} Target branch "${targetBranchName}" was updated`.trim()));
150
+
151
+ if (deletedBranchName) {
152
+ (0, _log.default)(_chalk.default.green(`${dryRunText} Head branch "${headBranchName}" was deleted`.trim()));
153
+ }
154
+ } catch (e) {
155
+ (0, _fatalError.fatalError)(e.message);
156
+ }
157
+ });
158
+ exports.mergeBranch = mergeBranch;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/commands/branch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AAmBpC,QAAA,MAAM,cAAc,EAAE,OAQrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/commands/branch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AAqBpC,QAAA,MAAM,cAAc,EAAE,OAQrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -19,6 +19,8 @@ var _list = require("./commands/list");
19
19
 
20
20
  var _tagVersion = require("./commands/tag-version");
21
21
 
22
+ var _merge = require("./commands/merge");
23
+
22
24
  const subcommands = {
23
25
  delete: _delete.deleteBranch,
24
26
  create: _create.createBranch,
@@ -26,7 +28,8 @@ const subcommands = {
26
28
  url: _url.getUrl,
27
29
  versionUrl: _url.getVersionUrl,
28
30
  list: _list.listBranches,
29
- tagVersion: _tagVersion.tagBranchVersion
31
+ tagVersion: _tagVersion.tagBranchVersion,
32
+ merge: _merge.mergeBranch
30
33
  };
31
34
 
32
35
  const commandHandler = async (cli, params) => {
package/dist/index.js CHANGED
@@ -44,6 +44,12 @@ const help = `
44
44
  it multiple time with the same tag and no hash specified it
45
45
  will return the versioned API URL for the existing tag and
46
46
  will not create a new one
47
+ merge merge two branches and place the output in a target branch —
48
+ 'branch merge --head my_branch' will use my_branch as a merge
49
+ head, the branch's parent as a base, and the parent as a target.
50
+ This typically means your merge will be compared to production
51
+ and merged into production.
52
+
47
53
 
48
54
  Examples
49
55
  $ takeshape build --file path/to/tsg.yml
@@ -53,6 +59,7 @@ const help = `
53
59
  $ takeshape branch promote --name my-feature
54
60
  $ takeshape branch url --production
55
61
  $ takeshape branch tagVersion --name my-feature --tag my-tag
62
+ $ takeshape brance merge --head my-feature
56
63
 
57
64
  Options
58
65
  --token, -t TakeShape API auth token
@@ -75,6 +82,12 @@ const help = `
75
82
  --tag tag to apply to a branch version
76
83
  --hash (optional) which version to hash — if not specified will tag the latest
77
84
 
85
+ Only for the merge command — base and target are optional
86
+ --head a development branch name to use as the head. Use this
87
+ flag alone for a smart merge with the branch parent.
88
+ --base the development branch name or 'production' to use for the base
89
+ --target the development branch name to 'production' to use for the target
90
+
78
91
  --branch use with non-branch commands to specify the branch name, required when using --development
79
92
  --name use with branch commands to specify the branch name, required when using --development
80
93
 
package/dist/options.d.ts CHANGED
@@ -78,6 +78,21 @@ export declare const options: {
78
78
  readonly hash: {
79
79
  readonly type: "string";
80
80
  };
81
+ readonly dryRun: {
82
+ readonly type: "boolean";
83
+ };
84
+ readonly deleteMergedBranch: {
85
+ readonly type: "boolean";
86
+ };
87
+ readonly head: {
88
+ readonly type: "string";
89
+ };
90
+ readonly base: {
91
+ readonly type: "string";
92
+ };
93
+ readonly target: {
94
+ readonly type: "string";
95
+ };
81
96
  };
82
97
  };
83
98
  export declare type Flags = typeof options.flags;
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,MAAM,CAAC;AAE5B,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgFV,CAAC;AAEX,oBAAY,KAAK,GAAG,OAAO,OAAO,CAAC,KAAK,CAAC;AACzC,oBAAY,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAAG;IAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;CAAC,CAAC"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,MAAM,CAAC;AAE5B,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+FV,CAAC;AAEX,oBAAY,KAAK,GAAG,OAAO,OAAO,CAAC,KAAK,CAAC;AACzC,oBAAY,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAAG;IAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;CAAC,CAAC"}
package/dist/options.js CHANGED
@@ -82,6 +82,21 @@ const options = {
82
82
  },
83
83
  hash: {
84
84
  type: 'string'
85
+ },
86
+ dryRun: {
87
+ type: 'boolean'
88
+ },
89
+ deleteMergedBranch: {
90
+ type: 'boolean'
91
+ },
92
+ head: {
93
+ type: 'string'
94
+ },
95
+ base: {
96
+ type: 'string'
97
+ },
98
+ target: {
99
+ type: 'string'
85
100
  }
86
101
  }
87
102
  };
@@ -1,10 +1,18 @@
1
1
  import { Cli } from '../options';
2
- export declare type Environment = 'PRODUCTION' | 'DEVELOPMENT' | 'SCRATCH';
3
- export declare function getEnvironment(cli: Cli, flag?: 'branch' | 'name'): Environment;
2
+ import { BRANCH_ENVIRONMENT_PRODUCTION_ENUM, BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM, BRANCH_ENVIRONMENT_SCRATCH_ENUM } from '@takeshape/branches';
3
+ export declare type BranchFlag = 'branch' | 'name';
4
+ export declare type Environment = typeof BRANCH_ENVIRONMENT_PRODUCTION_ENUM | typeof BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM | typeof BRANCH_ENVIRONMENT_SCRATCH_ENUM;
5
+ export declare function getEnvironment(cli: Cli, flag?: BranchFlag): Environment;
6
+ export declare function isEnvironment(environment: string): environment is Environment;
7
+ export declare type BranchArgs = {
8
+ environment: Environment;
9
+ branchName?: string;
10
+ };
11
+ export declare function getBranchArgs(name: string): BranchArgs;
4
12
  export interface BranchParams {
5
13
  environment: Environment;
6
14
  branch?: string;
7
15
  }
8
- export declare function getBranchParams(cli: Cli, flag?: 'branch' | 'name'): BranchParams;
16
+ export declare function getBranchParams(cli: Cli, flag?: BranchFlag): BranchParams;
9
17
  export declare function getBranchBasePath({ environment, branch }: BranchParams, projectId: string): string;
10
18
  //# sourceMappingURL=branches.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"branches.d.ts","sourceRoot":"","sources":["../../../src/util/branches.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAI/B,oBAAY,WAAW,GAAG,YAAY,GAAG,aAAa,GAAG,SAAS,CAAC;AAEnE,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAE,QAAQ,GAAG,MAAiB,GAAG,WAAW,CAcxF;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAE,QAAQ,GAAG,MAAiB,GAAG,YAAY,CAa1F;AAED,wBAAgB,iBAAiB,CAAC,EAAC,WAAW,EAAE,MAAM,EAAC,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAGhG"}
1
+ {"version":3,"file":"branches.d.ts","sourceRoot":"","sources":["../../../src/util/branches.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAG/B,OAAO,EAEL,kCAAkC,EAClC,mCAAmC,EACnC,+BAA+B,EAChC,MAAM,qBAAqB,CAAC;AAE7B,oBAAY,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE3C,oBAAY,WAAW,GACnB,OAAO,kCAAkC,GACzC,OAAO,mCAAmC,GAC1C,OAAO,+BAA+B,CAAC;AAE3C,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAE,UAAqB,GAAG,WAAW,CAcjF;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,IAAI,WAAW,CAM7E;AAED,oBAAY,UAAU,GAAG;IACvB,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAWtD;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAE,UAAqB,GAAG,YAAY,CAanF;AAED,wBAAgB,iBAAiB,CAAC,EAAC,WAAW,EAAE,MAAM,EAAC,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAGhG"}
@@ -3,41 +3,62 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getBranchArgs = getBranchArgs;
6
7
  exports.getBranchBasePath = getBranchBasePath;
7
8
  exports.getBranchParams = getBranchParams;
8
9
  exports.getEnvironment = getEnvironment;
10
+ exports.isEnvironment = isEnvironment;
9
11
 
10
12
  var _fatalError = require("./fatal-error");
11
13
 
12
14
  var _compact = _interopRequireDefault(require("lodash/compact"));
13
15
 
16
+ var _branches = require("@takeshape/branches");
17
+
14
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
19
 
16
20
  function getEnvironment(cli, flag = 'branch') {
17
21
  if (cli.flags.production) {
18
- return 'PRODUCTION';
22
+ return _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM;
19
23
  }
20
24
 
21
25
  if (cli.flags.development) {
22
- return 'DEVELOPMENT';
26
+ return _branches.BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM;
23
27
  }
24
28
 
25
29
  if (cli.flags.scratch) {
26
- return 'SCRATCH';
30
+ return _branches.BRANCH_ENVIRONMENT_SCRATCH_ENUM;
27
31
  }
28
32
 
29
- return cli.flags[flag] ? 'DEVELOPMENT' : 'PRODUCTION';
33
+ return cli.flags[flag] ? _branches.BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM : _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM;
34
+ }
35
+
36
+ function isEnvironment(environment) {
37
+ return [_branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM, _branches.BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM, _branches.BRANCH_ENVIRONMENT_SCRATCH_ENUM].includes(environment);
38
+ }
39
+
40
+ function getBranchArgs(name) {
41
+ if (name === _branches.BRANCH_ENVIRONMENT_PRODUCTION) {
42
+ return {
43
+ environment: _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM
44
+ };
45
+ }
46
+
47
+ return {
48
+ environment: _branches.BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM,
49
+ branchName: name
50
+ };
30
51
  }
31
52
 
32
53
  function getBranchParams(cli, flag = 'branch') {
33
54
  const branch = cli.flags[flag];
34
55
  const environment = getEnvironment(cli, flag);
35
56
 
36
- if (environment === 'PRODUCTION' && branch) {
57
+ if (environment === _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM && branch) {
37
58
  return (0, _fatalError.fatalError)('There is only one production branch --name is invalid');
38
59
  }
39
60
 
40
- if (environment === 'DEVELOPMENT' && !branch) {
61
+ if (environment === _branches.BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM && !branch) {
41
62
  return (0, _fatalError.fatalError)('Development branches require a name, please specify one with --name');
42
63
  }
43
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/cli",
3
- "version": "8.268.2",
3
+ "version": "8.271.0",
4
4
  "description": "TakeShape CLI",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -57,11 +57,11 @@
57
57
  "semver": "^6.3.0",
58
58
  "stream-to-promise": "^2.2.0",
59
59
  "tmp": "^0.0.33",
60
- "@takeshape/branches": "8.268.2",
61
- "@takeshape/ssg": "8.268.2",
62
- "@takeshape/schema": "8.268.2",
63
- "@takeshape/util": "8.268.2",
64
- "@takeshape/streams": "8.268.2"
60
+ "@takeshape/ssg": "8.271.0",
61
+ "@takeshape/branches": "8.271.0",
62
+ "@takeshape/schema": "8.271.0",
63
+ "@takeshape/streams": "8.271.0",
64
+ "@takeshape/util": "8.271.0"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/archiver": "^3.1.0",