@gkalpak/aliases 0.9.4 → 0.10.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.
Files changed (162) hide show
  1. package/README.md +4 -4
  2. package/bin/aio/__a-builds-dir.js +5 -7
  3. package/bin/aio/aioall.js +5 -5
  4. package/bin/aio/aioatt.js +5 -5
  5. package/bin/aio/aiobd.js +5 -5
  6. package/bin/aio/aiord.js +5 -5
  7. package/bin/aio/aiorm.js +5 -5
  8. package/bin/config/cfgbash.js +3 -4
  9. package/bin/config/cfgbash.wsl.js +3 -4
  10. package/bin/config/cfggit.js +3 -4
  11. package/bin/config/cfggit.wsl.js +4 -5
  12. package/bin/config/cfgvim.js +5 -3
  13. package/bin/docker/dkrall.js +5 -5
  14. package/bin/docker/dkratt.js +5 -5
  15. package/bin/docker/dkrbd.js +5 -5
  16. package/bin/docker/dkrrd.js +5 -5
  17. package/bin/docker/dkrrm.js +5 -5
  18. package/bin/git/__g-pick-branch.js +5 -7
  19. package/bin/git/__g-pick-commit.js +5 -7
  20. package/bin/git/gaa.js +5 -5
  21. package/bin/git/gb.js +5 -5
  22. package/bin/git/gbc.js +5 -5
  23. package/bin/git/gbcm.js +5 -5
  24. package/bin/git/gbd.js +5 -5
  25. package/bin/git/gcl.js +5 -5
  26. package/bin/git/gcm.js +5 -5
  27. package/bin/git/gcma.js +5 -5
  28. package/bin/git/gcmane.js +5 -5
  29. package/bin/git/gcmf.js +5 -5
  30. package/bin/git/gcmfc.js +5 -5
  31. package/bin/git/gcmfs.js +5 -5
  32. package/bin/git/gcmi.js +5 -5
  33. package/bin/git/gcmia.js +5 -5
  34. package/bin/git/gcmiane.js +5 -5
  35. package/bin/git/gcmif.js +5 -5
  36. package/bin/git/gcmifc.js +5 -5
  37. package/bin/git/gcmifs.js +5 -5
  38. package/bin/git/gco.js +5 -5
  39. package/bin/git/gcoghpr-cleanup.js +5 -5
  40. package/bin/git/gcoghpr.js +5 -7
  41. package/bin/git/gcom.js +5 -5
  42. package/bin/git/gcopr.js +5 -5
  43. package/bin/git/gcp.js +5 -5
  44. package/bin/git/gcpa.js +5 -5
  45. package/bin/git/gcpc.js +5 -5
  46. package/bin/git/gcpx.js +5 -5
  47. package/bin/git/gcpxl.js +5 -5
  48. package/bin/git/gd.js +5 -5
  49. package/bin/git/gd1.js +5 -5
  50. package/bin/git/gdefb.js +5 -5
  51. package/bin/git/gdh.js +5 -5
  52. package/bin/git/gdn.js +5 -5
  53. package/bin/git/gdn1.js +5 -5
  54. package/bin/git/gdnh.js +5 -5
  55. package/bin/git/gl.js +5 -5
  56. package/bin/git/gl1.js +5 -5
  57. package/bin/git/gl1g.js +5 -5
  58. package/bin/git/gmt.js +5 -5
  59. package/bin/git/gngprh.js +5 -5
  60. package/bin/git/gngprm.js +5 -5
  61. package/bin/git/gp.js +5 -5
  62. package/bin/git/gp1.js +5 -5
  63. package/bin/git/gpf.js +5 -5
  64. package/bin/git/gpr.js +5 -5
  65. package/bin/git/gpro.js +5 -5
  66. package/bin/git/gprom.js +5 -5
  67. package/bin/git/gpru.js +5 -5
  68. package/bin/git/gprum.js +5 -5
  69. package/bin/git/grb.js +5 -5
  70. package/bin/git/grba.js +5 -5
  71. package/bin/git/grbc.js +5 -5
  72. package/bin/git/grbi.js +5 -5
  73. package/bin/git/grbia.js +5 -5
  74. package/bin/git/grbin.js +5 -5
  75. package/bin/git/grbm.js +5 -5
  76. package/bin/git/grs.js +5 -5
  77. package/bin/git/grs1.js +5 -5
  78. package/bin/git/gs.js +5 -5
  79. package/bin/git/gsh.js +5 -5
  80. package/bin/git/gshn.js +5 -5
  81. package/bin/git/gst.js +5 -5
  82. package/bin/git/gstk.js +5 -5
  83. package/bin/git/gstl.js +5 -5
  84. package/bin/git/gstp.js +5 -5
  85. package/bin/git/gsync.js +5 -5
  86. package/bin/misc/alv.js +1 -2
  87. package/bin/misc/halp.js +2 -2
  88. package/bin/misc/ll.darwin.js +5 -5
  89. package/bin/misc/ll.js +5 -5
  90. package/bin/misc/lla.darwin.js +5 -5
  91. package/bin/misc/lla.js +5 -5
  92. package/bin/misc/osv.darwin.js +5 -5
  93. package/bin/misc/osv.js +5 -5
  94. package/bin/misc/osv.win32.js +5 -5
  95. package/bin/misc/salfup.js +5 -5
  96. package/bin/node/nad.js +5 -5
  97. package/bin/node/naga.js +5 -5
  98. package/bin/node/nap.js +5 -5
  99. package/bin/node/niin.js +5 -5
  100. package/bin/node/nls.js +5 -5
  101. package/bin/node/nls1.js +5 -5
  102. package/bin/node/nlsg.js +5 -5
  103. package/bin/node/nlsg1.js +5 -5
  104. package/bin/node/nr.js +5 -5
  105. package/bin/node/nrd.js +5 -5
  106. package/bin/node/nrin.js +5 -5
  107. package/bin/node/nrp.js +5 -5
  108. package/bin/node/nrx.js +5 -5
  109. package/bin/node/ns.js +5 -5
  110. package/bin/node/nsin.js +5 -5
  111. package/bin/node/nsx.js +5 -5
  112. package/bin/node/nt.js +5 -5
  113. package/bin/node/ntin.js +5 -5
  114. package/bin/node/ntx.js +5 -5
  115. package/bin/node/nua.js +5 -5
  116. package/bin/node/nud.js +5 -5
  117. package/bin/node/nup.js +5 -5
  118. package/bin/node/nv.js +5 -5
  119. package/bin/node/nvls.js +5 -5
  120. package/bin/node/nvls.win32.js +5 -5
  121. package/bin/node/nvlsa.js +5 -5
  122. package/bin/node/nvlsa.win32.js +5 -5
  123. package/bin/node/nvmup.js +5 -5
  124. package/bin/node/nvmup.win32.js +5 -5
  125. package/bin/node/nvu.js +5 -7
  126. package/bin/node/srv.js +5 -5
  127. package/bin/node/srvw.js +5 -5
  128. package/bin/node/yad.js +5 -5
  129. package/bin/node/yaga.js +5 -5
  130. package/bin/node/yap.js +5 -5
  131. package/bin/node/yiin.js +5 -5
  132. package/bin/node/yls.js +5 -5
  133. package/bin/node/yls1.js +5 -5
  134. package/bin/node/ylsg.js +5 -5
  135. package/bin/node/ylsg1.js +5 -5
  136. package/bin/node/yr.js +5 -5
  137. package/bin/node/yrd.js +5 -5
  138. package/bin/node/yrin.js +5 -5
  139. package/bin/node/yrp.js +5 -5
  140. package/bin/node/yrx.js +5 -5
  141. package/bin/node/ys.js +5 -5
  142. package/bin/node/ysin.js +5 -5
  143. package/bin/node/ysx.js +5 -5
  144. package/bin/node/yt.js +5 -5
  145. package/bin/node/ytin.js +5 -5
  146. package/bin/node/ytx.js +5 -5
  147. package/bin/node/yua.js +5 -5
  148. package/bin/node/yud.js +5 -5
  149. package/bin/node/yup.js +5 -5
  150. package/lib/alias-scripts/a-builds-dir.js +65 -45
  151. package/lib/alias-scripts/g-pick-branch.js +44 -25
  152. package/lib/alias-scripts/g-pick-commit.js +44 -25
  153. package/lib/alias-scripts/gcoghpr.js +182 -195
  154. package/lib/alias-scripts/nvu.js +57 -49
  155. package/lib/alias.js +4 -5
  156. package/lib/constants.js +68 -47
  157. package/lib/helper.js +96 -88
  158. package/lib/utils.js +113 -58
  159. package/package.json +8 -6
  160. package/scripts/build.js +11 -10
  161. package/scripts/platformize-bin.js +7 -7
  162. package/scripts/test-pkg.js +14 -12
package/bin/node/ysin.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
3
4
  // eslint-disable-next-line max-len
4
- const cmd = module.exports = 'yarn --cwd=$1 start $2*';
5
- if (require.main === module) {
6
- const {commandUtils} = require('@gkalpak/cli-utils');
7
- const {onError} = require('../../lib/utils');
5
+ const cmd = 'yarn --cwd=$1 start $2*';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
8
  const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
9
  // eslint-disable-next-line quotes
10
10
  commandUtils.run(cmd, args, Object.assign({"sapVersion":2}, config)).catch(onError);
package/bin/node/ysx.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
3
4
  // eslint-disable-next-line max-len
4
- const cmd = module.exports = 'yarn start $*';
5
- if (require.main === module) {
6
- const {commandUtils} = require('@gkalpak/cli-utils');
7
- const {onError} = require('../../lib/utils');
5
+ const cmd = 'yarn start $*';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
8
  const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
9
  // eslint-disable-next-line quotes
10
10
  commandUtils.run(cmd, args, Object.assign({"sapVersion":2,"suppressTbj":true}, config)).catch(onError);
package/bin/node/yt.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
3
4
  // eslint-disable-next-line max-len
4
- const cmd = module.exports = 'yarn test $*';
5
- if (require.main === module) {
6
- const {commandUtils} = require('@gkalpak/cli-utils');
7
- const {onError} = require('../../lib/utils');
5
+ const cmd = 'yarn test $*';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
8
  const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
9
  // eslint-disable-next-line quotes
10
10
  commandUtils.run(cmd, args, Object.assign({"sapVersion":2}, config)).catch(onError);
package/bin/node/ytin.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
3
4
  // eslint-disable-next-line max-len
4
- const cmd = module.exports = 'yarn --cwd=$1 test $2*';
5
- if (require.main === module) {
6
- const {commandUtils} = require('@gkalpak/cli-utils');
7
- const {onError} = require('../../lib/utils');
5
+ const cmd = 'yarn --cwd=$1 test $2*';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
8
  const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
9
  // eslint-disable-next-line quotes
10
10
  commandUtils.run(cmd, args, Object.assign({"sapVersion":2}, config)).catch(onError);
package/bin/node/ytx.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
3
4
  // eslint-disable-next-line max-len
4
- const cmd = module.exports = 'yarn test $*';
5
- if (require.main === module) {
6
- const {commandUtils} = require('@gkalpak/cli-utils');
7
- const {onError} = require('../../lib/utils');
5
+ const cmd = 'yarn test $*';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
8
  const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
9
  // eslint-disable-next-line quotes
10
10
  commandUtils.run(cmd, args, Object.assign({"sapVersion":2,"suppressTbj":true}, config)).catch(onError);
package/bin/node/yua.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
3
4
  // eslint-disable-next-line max-len
4
- const cmd = module.exports = 'node --eval "/* Update dependencies. */ const deps = Object.keys(require(\'./package.json\').dependencies || {}).map(x => x + \'@latest\'); console.log(\'\\nUpdating \' + deps.length + \' dependencies...\'); deps.length && child_process.spawnSync(\'yap\', deps, {shell: true, stdio: \'inherit\'});" && node --eval "/* Update devDependencies. */ const deps = Object.keys(require(\'./package.json\').devDependencies || {}).map(x => x + \'@latest\'); console.log(\'\\nUpdating \' + deps.length + \' devDependencies...\'); deps.length && child_process.spawnSync(\'yad\', deps, {shell: true, stdio: \'inherit\'});"';
5
- if (require.main === module) {
6
- const {commandUtils} = require('@gkalpak/cli-utils');
7
- const {onError} = require('../../lib/utils');
5
+ const cmd = 'node --eval "/* Update dependencies. */ const deps = Object.keys(require(\'./package.json\').dependencies || {}).map(x => x + \'@latest\'); console.log(\'\\nUpdating \' + deps.length + \' dependencies...\'); deps.length && child_process.spawnSync(\'yap\', deps, {shell: true, stdio: \'inherit\'});" && node --eval "/* Update devDependencies. */ const deps = Object.keys(require(\'./package.json\').devDependencies || {}).map(x => x + \'@latest\'); console.log(\'\\nUpdating \' + deps.length + \' devDependencies...\'); deps.length && child_process.spawnSync(\'yad\', deps, {shell: true, stdio: \'inherit\'});"';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
8
  const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
9
  // eslint-disable-next-line quotes
10
10
  commandUtils.run(cmd, args, Object.assign({"sapVersion":2}, config)).catch(onError);
package/bin/node/yud.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
3
4
  // eslint-disable-next-line max-len
4
- const cmd = module.exports = 'node --eval "/* Update devDependencies. */ const deps = Object.keys(require(\'./package.json\').devDependencies || {}).map(x => x + \'@latest\'); console.log(\'\\nUpdating \' + deps.length + \' devDependencies...\'); deps.length && child_process.spawnSync(\'yad\', deps, {shell: true, stdio: \'inherit\'});"';
5
- if (require.main === module) {
6
- const {commandUtils} = require('@gkalpak/cli-utils');
7
- const {onError} = require('../../lib/utils');
5
+ const cmd = 'node --eval "/* Update devDependencies. */ const deps = Object.keys(require(\'./package.json\').devDependencies || {}).map(x => x + \'@latest\'); console.log(\'\\nUpdating \' + deps.length + \' devDependencies...\'); deps.length && child_process.spawnSync(\'yad\', deps, {shell: true, stdio: \'inherit\'});"';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
8
  const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
9
  // eslint-disable-next-line quotes
10
10
  commandUtils.run(cmd, args, Object.assign({"sapVersion":2}, config)).catch(onError);
package/bin/node/yup.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
3
4
  // eslint-disable-next-line max-len
4
- const cmd = module.exports = 'node --eval "/* Update dependencies. */ const deps = Object.keys(require(\'./package.json\').dependencies || {}).map(x => x + \'@latest\'); console.log(\'\\nUpdating \' + deps.length + \' dependencies...\'); deps.length && child_process.spawnSync(\'yap\', deps, {shell: true, stdio: \'inherit\'});"';
5
- if (require.main === module) {
6
- const {commandUtils} = require('@gkalpak/cli-utils');
7
- const {onError} = require('../../lib/utils');
5
+ const cmd = 'node --eval "/* Update dependencies. */ const deps = Object.keys(require(\'./package.json\').dependencies || {}).map(x => x + \'@latest\'); console.log(\'\\nUpdating \' + deps.length + \' dependencies...\'); deps.length && child_process.spawnSync(\'yap\', deps, {shell: true, stdio: \'inherit\'});"';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
8
  const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
9
  // eslint-disable-next-line quotes
10
10
  commandUtils.run(cmd, args, Object.assign({"sapVersion":2}, config)).catch(onError);
@@ -1,12 +1,19 @@
1
- 'use strict';
2
-
3
1
  // Imports
4
- const fs = require('fs');
5
- const path = require('path');
6
- const utils = require('../utils');
2
+ import {stat} from 'node:fs/promises';
3
+ import {resolve as pathResolve} from 'node:path';
4
+
5
+ import {stripIndentation} from '../utils.js';
6
+
7
+
8
+ // Constants
9
+ const internal = {
10
+ _aBuildsDir,
11
+ _fsStat,
12
+ _pathResolve,
13
+ };
7
14
 
8
15
  // Exports
9
- const exps = module.exports = {
16
+ export {
10
17
  /**
11
18
  * @function aBuildsDir
12
19
  *
@@ -19,44 +26,49 @@ const exps = module.exports = {
19
26
  * @return {Promise<void|string>} - A promise that resolves to either `undefined` or the absolute directory path
20
27
  * (depending on the value of `config.returnOutput`).
21
28
  */
22
- aBuildsDir: _aBuildsDir,
29
+ aBuildsDir,
23
30
 
24
- main: __main,
25
- };
31
+ main,
26
32
 
27
- // Functions - Definitions
28
- function __main(_runtimeArgs, config) {
29
- return exps.aBuildsDir(config);
30
- }
33
+ // Exposed for testing purposes only.
34
+ internal as _testing,
35
+ };
31
36
 
32
- function _aBuildsDir(config) {
37
+ // Helpers
38
+ async function _aBuildsDir(config) {
33
39
  if (config.dryrun) {
34
40
  console.log('Get the absolute path to \'.../angular/aio/aio-builds-setup/\'.');
35
- return Promise.resolve();
41
+ return;
42
+ }
43
+
44
+ const buildsDirPath = await locateBuildsDir(config.debug);
45
+
46
+ if (config.returnOutput) {
47
+ return buildsDirPath;
36
48
  }
37
49
 
38
- return locateBuildsDir(config.debug).
39
- then(buildsDirPath => config.returnOutput ? buildsDirPath : console.log(buildsDirPath));
50
+ console.log(buildsDirPath);
40
51
  }
41
52
 
42
- function exists(somePath) {
43
- return new Promise(resolve => fs.exists(somePath, resolve));
53
+ function _fsStat(filePath) {
54
+ return stat(filePath);
44
55
  }
45
56
 
46
- function isBuildsDir(candidateAbsPath) {
47
- return Promise.resolve(true).
48
- then(prev => prev && /[\\/]aio[\\/]aio-builds-setup$/.test(candidateAbsPath)).
49
- then(prev => prev && exists(candidateAbsPath)).
50
- then(prev => prev && isDirectory(candidateAbsPath));
57
+ function _pathResolve(...paths) {
58
+ return pathResolve(...paths);
51
59
  }
52
60
 
53
- function isDirectory(somePath) {
54
- return new Promise((resolve, reject) =>
55
- fs.stat(somePath, (err, stats) =>
56
- err ? reject(err) : resolve(stats.isDirectory())));
61
+ function aBuildsDir(config) {
62
+ return internal._aBuildsDir(config);
57
63
  }
58
64
 
59
- function locateBuildsDir(debug = false) {
65
+ async function isBuildsDir(candidateAbsPath) {
66
+ return /[\\/]aio[\\/]aio-builds-setup$/.test(candidateAbsPath) &&
67
+ await pathExists(candidateAbsPath) &&
68
+ await pathIsDirectory(candidateAbsPath);
69
+ }
70
+
71
+ async function locateBuildsDir(debug = false) {
60
72
  const candidateRelPaths = [
61
73
  'aio/aio-builds-setup', // Run from: angular/
62
74
  'aio-builds-setup', // Run from: angular/aio/
@@ -65,29 +77,37 @@ function locateBuildsDir(debug = false) {
65
77
  '../..', // Run from: angular/aio/aio-builds-setup/dockerbuild/scripts-js/
66
78
  ];
67
79
 
68
- return candidateRelPaths.
69
- reduce((prevPromise, p) => prevPromise.then(prevAbsPath => {
70
- if (prevAbsPath) return prevAbsPath;
80
+ for (const p of candidateRelPaths) {
81
+ const absPath = internal._pathResolve(p);
71
82
 
72
- const absPath = path.resolve(p);
83
+ if (debug) {
84
+ console.log(`Checking '${p}' (resolved to '${absPath}')...`);
85
+ }
73
86
 
87
+ if (await isBuildsDir(absPath)) {
74
88
  if (debug) {
75
- console.log(`Checking '${p}' (resolved to '${absPath}')...`);
89
+ console.log(`Target directory found: ${absPath}`);
76
90
  }
77
91
 
78
- return isBuildsDir(absPath).then(itIs => itIs && absPath);
79
- }), Promise.resolve(false)).
80
- then(buildsDirPath => {
81
- if (debug && buildsDirPath) {
82
- console.log(`Target directory found: ${buildsDirPath}`);
83
- }
84
- return buildsDirPath || notFound();
85
- });
86
- }
92
+ return absPath;
93
+ }
94
+ }
87
95
 
88
- function notFound() {
89
- throw new Error(utils.stripIndentation(`
96
+ throw new Error(stripIndentation(`
90
97
  Unable to locate the '.../aio/aio-setup-builds/' directory.
91
98
  Make sure you are in a directory between 'angular/' and 'angular/aio/aio-builds-setup/dockerbuild/scripts-js/'.
92
99
  `));
93
100
  }
101
+
102
+ function main(_runtimeArgs, config) {
103
+ return aBuildsDir(config);
104
+ }
105
+
106
+ function pathExists(somePath) {
107
+ return internal._fsStat(somePath).then(() => true, () => false);
108
+ }
109
+
110
+ async function pathIsDirectory(somePath) {
111
+ const stats = await internal._fsStat(somePath);
112
+ return stats.isDirectory();
113
+ }
@@ -1,14 +1,16 @@
1
- 'use strict';
2
-
3
1
  // Imports
4
- const {commandUtils, processUtils} = require('@gkalpak/cli-utils');
5
- const utils = require('../utils');
2
+ import {commandUtils, processUtils} from '@gkalpak/cli-utils';
3
+
4
+ import {importWithEnv} from '../utils.js';
6
5
 
7
- // Ensure colors are always used (even when running with `returnOutput: <number>`).
8
- const inquirer = utils.requireWithEnv('inquirer', process.env, {FORCE_COLOR: '1'});
6
+
7
+ // Constants
8
+ const internal = {
9
+ _gPickBranch,
10
+ };
9
11
 
10
12
  // Exports
11
- const exps = module.exports = {
13
+ export {
12
14
  /**
13
15
  * @function gPickBranch
14
16
  *
@@ -20,30 +22,45 @@ const exps = module.exports = {
20
22
  * @return {Promise<void|string>} - A promise that resolves to either `undefined` or the selected branch (depending on
21
23
  * the value of `config.returnOutput`).
22
24
  */
23
- gPickBranch: _gPickBranch,
25
+ gPickBranch,
24
26
 
25
- main: __main,
26
- };
27
+ main,
27
28
 
28
- // Functions - Definitions
29
- function __main(_runtimeArgs, config) {
30
- return exps.gPickBranch(config);
31
- }
29
+ // Exposed for testing purposes only.
30
+ internal as _testing,
31
+ };
32
32
 
33
- function _gPickBranch(config) {
33
+ // Helpers
34
+ async function _gPickBranch(config) {
34
35
  const gbConfig = Object.assign({}, config, {returnOutput: true});
35
36
 
36
37
  if (config.dryrun) {
37
38
  console.log('Pick one from a list of branches.');
38
- return Promise.resolve();
39
+ return;
40
+ }
41
+
42
+ const branchOutput = await commandUtils.run('git branch', [], gbConfig);
43
+ const branch = await pickBranch(branchOutput);
44
+
45
+ if (config.returnOutput) {
46
+ return branch;
39
47
  }
40
48
 
41
- return commandUtils.run('git branch', [], gbConfig).
42
- then(output => pickBranch(output)).
43
- then(branch => config.returnOutput ? branch : console.log(branch));
49
+ console.log(branch);
50
+ }
51
+
52
+ function gPickBranch(config) {
53
+ return internal._gPickBranch(config);
44
54
  }
45
55
 
46
- function pickBranch(branchesStr) {
56
+ function main(_runtimeArgs, config) {
57
+ return gPickBranch(config);
58
+ }
59
+
60
+ async function pickBranch(branchesStr) {
61
+ // Ensure colors are always used (even when running with `returnOutput: <number>`).
62
+ const {default: inquirer} = await importWithEnv('inquirer', import.meta.url, {FORCE_COLOR: '1'});
63
+
47
64
  let currentBranchIdx = 0;
48
65
  const branches = branchesStr.
49
66
  split('\n').
@@ -85,8 +102,8 @@ function pickBranch(branchesStr) {
85
102
  }
86
103
  });
87
104
 
88
- const promise = inquirer.
89
- prompt([
105
+ try {
106
+ const {branch} = await inquirer.prompt([
90
107
  {
91
108
  type: 'list',
92
109
  name: 'branch',
@@ -94,8 +111,10 @@ function pickBranch(branchesStr) {
94
111
  choices: branches,
95
112
  default: currentBranchIdx,
96
113
  },
97
- ]).
98
- then(({branch}) => branch);
114
+ ]);
99
115
 
100
- return utils.finallyAsPromised(promise, unlisten);
116
+ return branch;
117
+ } finally {
118
+ unlisten();
119
+ }
101
120
  }
@@ -1,14 +1,16 @@
1
- 'use strict';
2
-
3
1
  // Imports
4
- const {commandUtils, processUtils} = require('@gkalpak/cli-utils');
5
- const utils = require('../utils');
2
+ import {commandUtils, processUtils} from '@gkalpak/cli-utils';
3
+
4
+ import {importWithEnv} from '../utils.js';
6
5
 
7
- // Ensure colors are always used (even when running with `returnOutput: <number>`).
8
- const inquirer = utils.requireWithEnv('inquirer', process.env, {FORCE_COLOR: '1'});
6
+
7
+ // Constants
8
+ const internal = {
9
+ _gPickCommit,
10
+ };
9
11
 
10
12
  // Exports
11
- const exps = module.exports = {
13
+ export {
12
14
  /**
13
15
  * @function gPickCommit
14
16
  *
@@ -20,30 +22,45 @@ const exps = module.exports = {
20
22
  * @return {Promise<void|string>} - A promise that resolves to either `undefined` or the selected commit (depending on
21
23
  * the value of `config.returnOutput`).
22
24
  */
23
- gPickCommit: _gPickCommit,
25
+ gPickCommit,
24
26
 
25
- main: __main,
26
- };
27
+ main,
27
28
 
28
- // Functions - Definitions
29
- function __main(_runtimeArgs, config) {
30
- return exps.gPickCommit(config);
31
- }
29
+ // Exposed for testing purposes only.
30
+ internal as _testing,
31
+ };
32
32
 
33
- function _gPickCommit(config) {
33
+ // Helpers
34
+ async function _gPickCommit(config) {
34
35
  const glConfig = Object.assign({}, config, {returnOutput: true});
35
36
 
36
37
  if (config.dryrun) {
37
38
  console.log('Pick one from a list of commits.');
38
- return Promise.resolve();
39
+ return;
40
+ }
41
+
42
+ const commitOutput = await commandUtils.run('git log --oneline -50', [], glConfig);
43
+ const commit = await pickCommit(commitOutput);
44
+
45
+ if (config.returnOutput) {
46
+ return commit;
39
47
  }
40
48
 
41
- return commandUtils.run('git log --oneline -50', [], glConfig).
42
- then(output => pickCommit(output)).
43
- then(commit => config.returnOutput ? commit : console.log(commit));
49
+ console.log(commit);
50
+ }
51
+
52
+ function gPickCommit(config) {
53
+ return internal._gPickCommit(config);
44
54
  }
45
55
 
46
- function pickCommit(commitsStr) {
56
+ function main(_runtimeArgs, config) {
57
+ return gPickCommit(config);
58
+ }
59
+
60
+ async function pickCommit(commitsStr) {
61
+ // Ensure colors are always used (even when running with `returnOutput: <number>`).
62
+ const {default: inquirer} = await importWithEnv('inquirer', import.meta.url, {FORCE_COLOR: '1'});
63
+
47
64
  const commits = commitsStr.
48
65
  split('\n').
49
66
  map(line => line.trim()).
@@ -59,8 +76,8 @@ function pickCommit(commitsStr) {
59
76
  }
60
77
  });
61
78
 
62
- const promise = inquirer.
63
- prompt([
79
+ try {
80
+ const {commit} = await inquirer.prompt([
64
81
  {
65
82
  type: 'list',
66
83
  name: 'commit',
@@ -68,8 +85,10 @@ function pickCommit(commitsStr) {
68
85
  choices: commits,
69
86
  default: 0,
70
87
  },
71
- ]).
72
- then(({commit}) => commit.replace(/\s+.*$/, ''));
88
+ ]);
73
89
 
74
- return utils.finallyAsPromised(promise, unlisten);
90
+ return commit.replace(/\s+.*$/, '');
91
+ } finally {
92
+ unlisten();
93
+ }
75
94
  }