@gkalpak/aliases 0.13.2 → 0.13.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.
@@ -2,7 +2,7 @@
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  /* eslint-disable max-len */
4
4
  console.log(stripIndentation(`
5
- ### [Generated by: @gkalpak/aliases v0.13.2]
5
+ ### [Generated by: @gkalpak/aliases v0.13.4]
6
6
  ### Copy the following into '~/.bashrc':
7
7
 
8
8
  # Set up prompt.
@@ -2,7 +2,7 @@
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  /* eslint-disable max-len */
4
4
  console.log(stripIndentation(`
5
- ### [Generated by: @gkalpak/aliases v0.13.2]
5
+ ### [Generated by: @gkalpak/aliases v0.13.4]
6
6
  ### Copy the following into '~/.bashrc':
7
7
 
8
8
  # Set up prompt.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  console.log(stripIndentation(`
4
- ### [Generated by: @gkalpak/aliases v0.13.2]
4
+ ### [Generated by: @gkalpak/aliases v0.13.4]
5
5
  ### Run the following commands:
6
6
 
7
7
  git config --global commit.gpgSign true
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  console.log(stripIndentation(`
4
- ### [Generated by: @gkalpak/aliases v0.13.2]
4
+ ### [Generated by: @gkalpak/aliases v0.13.4]
5
5
  ### Run the following commands:
6
6
 
7
7
  git config --global commit.gpgSign true
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  console.log(stripIndentation(`
4
- ### [Generated by: @gkalpak/aliases v0.13.2]
4
+ ### [Generated by: @gkalpak/aliases v0.13.4]
5
5
  ### Run the following commands:
6
6
 
7
7
  git config --global commit.gpgSign true
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  console.log(stripIndentation(`
4
- ### [Generated by: @gkalpak/aliases v0.13.2]
4
+ ### [Generated by: @gkalpak/aliases v0.13.4]
5
5
  ### Copy the following into '~/.gnupg/gpg-agent.conf':
6
6
 
7
7
  default-cache-ttl 86400
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  console.log(stripIndentation(`
4
- ### [Generated by: @gkalpak/aliases v0.13.2]
4
+ ### [Generated by: @gkalpak/aliases v0.13.4]
5
5
  ### Copy the following into '~/.ssh/config':
6
6
 
7
7
  IdentityFile ~/.ssh/id-rsa-gkalpak.ppk
@@ -2,6 +2,6 @@
2
2
  import {readFileSync} from 'node:fs';
3
3
  import {fileURLToPath} from 'node:url';
4
4
  const __dirname = fileURLToPath(new URL('.', import.meta.url));
5
- console.log('""" [Generated by: @gkalpak/aliases v0.13.2]');
5
+ console.log('""" [Generated by: @gkalpak/aliases v0.13.4]');
6
6
  console.log('""" Copy the following into \'~/.vimrc\':\n');
7
7
  console.log(readFileSync(`${__dirname}/../../lib/assets/vimrc.txt`, 'utf8').trim() + '\n');
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  console.log(stripIndentation(`
4
- ### [Generated by: @gkalpak/aliases v0.13.2]
4
+ ### [Generated by: @gkalpak/aliases v0.13.4]
5
5
  ### Copy the following into a root-owned, 600-mode '/etc/resolv.conf' file:
6
6
 
7
7
  # Cloudflare
@@ -14,7 +14,7 @@ console.log(stripIndentation(`
14
14
 
15
15
  -----
16
16
 
17
- ### [Generated by: @gkalpak/aliases v0.13.2]
17
+ ### [Generated by: @gkalpak/aliases v0.13.4]
18
18
  ### Copy the following into a root-owned, 600-mode '/etc/wsl.conf' file:
19
19
 
20
20
  [network]
package/bin/git/gba.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
4
+ // eslint-disable-next-line max-len
5
+ const cmd = 'git branch --all $*';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
+ const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
+ // eslint-disable-next-line quotes
10
+ commandUtils.run(cmd, args, Object.assign({"sapVersion":2}, config)).catch(onError);
11
+ }
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
4
+ // eslint-disable-next-line max-len
5
+ const cmd = 'git branch --delete --force ${1:::__g-pick-branch --gkcu-returnOutput=1} && git push --delete origin ${1:::__g-pick-branch --gkcu-returnOutput=1}';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
+ const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
+ // eslint-disable-next-line quotes
10
+ commandUtils.run(cmd, args, Object.assign({"sapVersion":2}, config)).catch(onError);
11
+ }
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import {commandUtils} from '@gkalpak/cli-utils';
3
+ import {isMain, onError} from '../../lib/utils.js';
4
+ // eslint-disable-next-line max-len
5
+ const cmd = 'git push --delete ${*:::__g-pick-branch --remote --gkcu-returnOutput=1}';
6
+ export default cmd;
7
+ if (isMain(import.meta.url)) {
8
+ const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
9
+ // eslint-disable-next-line quotes
10
+ commandUtils.run(cmd, args, Object.assign({"sapVersion":2}, config)).catch(onError);
11
+ }
package/bin/misc/alv.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- console.log('@gkalpak/aliases v0.13.2');
2
+ console.log('@gkalpak/aliases v0.13.4');
package/bin/node/naga.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {commandUtils} from '@gkalpak/cli-utils';
3
3
  import {isMain, onError} from '../../lib/utils.js';
4
4
  // eslint-disable-next-line max-len
5
- const cmd = 'npm install --global @angular/cli @gkalpak/aliases @gkalpak/cli-utils @gkalpak/ng-maintain eslint firebase-tools http-server light-server shx typescript typescript-run watch yarn $*';
5
+ const cmd = 'npm install --global @angular/cli @gkalpak/aliases @gkalpak/cli-utils @gkalpak/ng-maintain eslint firebase-tools http-server light-server shx typescript verdaccio watch yarn $*';
6
6
  export default cmd;
7
7
  if (isMain(import.meta.url)) {
8
8
  const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
package/bin/node/yaga.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {commandUtils} from '@gkalpak/cli-utils';
3
3
  import {isMain, onError} from '../../lib/utils.js';
4
4
  // eslint-disable-next-line max-len
5
- const cmd = 'yarn global add @angular/cli @gkalpak/aliases @gkalpak/cli-utils @gkalpak/ng-maintain eslint firebase-tools http-server light-server shx typescript typescript-run watch $*';
5
+ const cmd = 'yarn global add @angular/cli @gkalpak/aliases @gkalpak/cli-utils @gkalpak/ng-maintain eslint firebase-tools http-server light-server shx typescript verdaccio watch $*';
6
6
  export default cmd;
7
7
  if (isMain(import.meta.url)) {
8
8
  const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
@@ -5,6 +5,11 @@ import {importWithEnv} from '../utils.js';
5
5
 
6
6
 
7
7
  // Constants
8
+ const branchNameSuffices = {
9
+ '': '',
10
+ '*': ' (current)',
11
+ '+': ' (other worktree)',
12
+ };
8
13
  const internal = {
9
14
  _gPickBranch,
10
15
  };
@@ -15,12 +20,16 @@ export {
15
20
  * @function gPickBranch
16
21
  *
17
22
  * @description
18
- * Prompt the user to pick one of the available git branches via an interactive list.
23
+ * Prompt the user to pick one of the available git branches via an interactive list. By default, local branches are
24
+ * shown, but this can be optionally switched to remote branches only. Supported runtime arguments:
25
+ * - `--remote` [flag]: Only show remote branches when present (otherwise only show local branches).
19
26
  *
27
+ * @param {string[]} [runtimeArgs=[]] - The runtime arguments.
20
28
  * @param {IRunConfig} [config={}] - A configuration object. See {@link commandUtils#IRunConfig} for more details.
21
29
  *
22
30
  * @return {Promise<void|string>} - A promise that resolves to either `undefined` or the selected branch (depending on
23
- * the value of `config.returnOutput`).
31
+ * the value of `config.returnOutput`). When switched to remote branches only the selected branch consists of the
32
+ * remote name, followed by a space, followed by the actual branch name (for example, `origin some-branch`).
24
33
  */
25
34
  gPickBranch,
26
35
 
@@ -31,16 +40,18 @@ export {
31
40
  };
32
41
 
33
42
  // Helpers
34
- async function _gPickBranch(config) {
43
+ async function _gPickBranch(runtimeArgs = [], config = {}) {
35
44
  const gbConfig = Object.assign({}, config, {returnOutput: true});
45
+ const branchType = runtimeArgs.includes('--remote') ? 'remote' : 'local';
36
46
 
37
47
  if (config.dryrun) {
38
- console.log('Pick one from a list of branches.');
48
+ console.log(`Pick one from a list of ${branchType} branches.`);
39
49
  return;
40
50
  }
41
51
 
42
- const branchOutput = await commandUtils.run('git branch', [], gbConfig);
43
- const branch = await pickBranch(branchOutput);
52
+ const branchOutput = await commandUtils.run('git branch --all', [], gbConfig);
53
+ const branches = processBranches(branchOutput).filter(({remote}) => remote === (branchType === 'remote'));
54
+ const branch = await pickBranch(branchType, branches);
44
55
 
45
56
  if (config.returnOutput) {
46
57
  return branch;
@@ -49,49 +60,19 @@ async function _gPickBranch(config) {
49
60
  console.log(branch);
50
61
  }
51
62
 
52
- function gPickBranch(config) {
53
- return internal._gPickBranch(config);
63
+ function gPickBranch(runtimeArgs, config) {
64
+ return internal._gPickBranch(runtimeArgs, config);
54
65
  }
55
66
 
56
- function main(_runtimeArgs, config) {
57
- return gPickBranch(config);
67
+ function main(runtimeArgs, config) {
68
+ return gPickBranch(runtimeArgs, config);
58
69
  }
59
70
 
60
- async function pickBranch(branchesStr) {
71
+ async function pickBranch(branchType, branches) {
61
72
  // Ensure colors are always used (even when running with `returnOutput: <number>`).
62
73
  const {default: inquirer} = await importWithEnv(() => import('inquirer'), {FORCE_COLOR: '1'});
63
74
 
64
- let currentBranchIdx = 0;
65
- const branches = branchesStr.
66
- split('\n').
67
- map(line => line.trim()).
68
- filter(Boolean).
69
- map((branch, i) => {
70
- const [, specialSymbol = '', branchName] = /^(?:([*+])\s*)?(\S.*)$/.exec(branch);
71
- let displayName = branchName.replace(/^(gcoghpr)-(.*)$/, '[$1] $2');
72
-
73
- switch (specialSymbol) {
74
- case '':
75
- break;
76
- case '*':
77
- currentBranchIdx = i;
78
- displayName += ' (current)';
79
- break;
80
- case '+':
81
- displayName += ' (other worktree)';
82
- break;
83
- default:
84
- throw new Error(`Unexpected branch prefix symbol: ${specialSymbol}`);
85
- }
86
-
87
- return {
88
- name: displayName,
89
- value: branchName,
90
- short: branchName,
91
- };
92
- }).
93
- sort((a, b) => (a.name > b.name) ? 1 : -1).
94
- concat(new inquirer.Separator());
75
+ const currentBranchIdx = Math.max(0, branches.findIndex(({name}) => name.endsWith(branchNameSuffices['*'])));
95
76
 
96
77
  const unlisten = processUtils.doOnExit(process, code => {
97
78
  if (code === 0) {
@@ -107,8 +88,8 @@ async function pickBranch(branchesStr) {
107
88
  {
108
89
  type: 'list',
109
90
  name: 'branch',
110
- message: 'Pick a branch:',
111
- choices: branches,
91
+ message: `Pick a ${branchType} branch:`,
92
+ choices: branches.concat(new inquirer.Separator()),
112
93
  default: currentBranchIdx,
113
94
  },
114
95
  ]);
@@ -118,3 +99,30 @@ async function pickBranch(branchesStr) {
118
99
  unlisten();
119
100
  }
120
101
  }
102
+
103
+ function processBranches(branchesStr) {
104
+ return branchesStr.
105
+ split('\n').
106
+ map(line => line.trim()).
107
+ // Filter out empty lines and `HEAD` "aliases".
108
+ filter(line => (line.length > 0) && !line.includes('/HEAD -> ')).
109
+ map(branch => {
110
+ const [, specialSymbol = '', remote = false, branchName] = /^(?:([*+])\s*)?(remotes\/)?(\S.*)$/.exec(branch);
111
+ const branchNameSuffix = branchNameSuffices[specialSymbol];
112
+
113
+ if (branchNameSuffix === undefined) {
114
+ throw new Error(`Unexpected branch prefix symbol: ${specialSymbol}`);
115
+ }
116
+
117
+ const displayName = branchName.replace(/^(gcoghpr)-(.*)$/, '[$1] $2') + branchNameSuffix;
118
+ const isRemote = remote !== false;
119
+
120
+ return {
121
+ name: displayName,
122
+ short: branchName,
123
+ value: isRemote ? branchName.replace('/', ' ') : branchName,
124
+ remote: isRemote,
125
+ };
126
+ }).
127
+ sort((a, b) => (a.name > b.name) ? 1 : -1);
128
+ }
package/lib/constants.js CHANGED
@@ -29,7 +29,7 @@ const GLOBAL_NPM_PACKAGES = [
29
29
  'light-server',
30
30
  'shx',
31
31
  'typescript',
32
- 'typescript-run',
32
+ 'verdaccio',
33
33
  'watch',
34
34
  'yarn',
35
35
  ];
@@ -38,7 +38,8 @@ const DESC_REPLACEMENTS = {
38
38
  [AliasUnknown.DESCRIPTION]: '???',
39
39
  '::gdefb': '<default-branch>',
40
40
  '::__a-builds-dir': '(<.../angular/aio/aio-builds-setup>)',
41
- '::__g-pick-branch --gkcu-returnOutput=1': '(interactively pick a branch)',
41
+ '::__g-pick-branch --gkcu-returnOutput=1': '(interactively pick a local branch)',
42
+ '::__g-pick-branch --remote --gkcu-returnOutput=1': '(interactively pick a remote branch)',
42
43
  '::__g-pick-commit --gkcu-returnOutput=1': '(interactively pick a commit)',
43
44
  '::__g-pick-commit --filter-commits="$1" --gkcu-returnOutput=1': '(interactively pick a filtered commit)',
44
45
  };
@@ -314,10 +315,15 @@ const ALIASES = {
314
315
 
315
316
  // BRANCH
316
317
  gb: new AliasDefault('git branch $*'),
318
+ gba: new AliasDefault('git branch --all $*'),
317
319
  gbc: new AliasDefault(GIT_CREATE_BRANCH_CMD('${2:HEAD}')),
318
320
  gbcd: new AliasDefault(GIT_CREATE_BRANCH_CMD('${0:::gdefb}')),
319
321
  gbco: new AliasDefault(`git fetch origin $1 && ${GIT_CREATE_BRANCH_CMD('origin/$1')}`),
320
322
  gbd: new AliasDefault('git branch --delete --force ${*:::__g-pick-branch --gkcu-returnOutput=1}'),
323
+ gbdr: new AliasDefault('git push --delete ${*:::__g-pick-branch --remote --gkcu-returnOutput=1}'),
324
+ gbdio: new AliasDefault(
325
+ 'git branch --delete --force ${1:::__g-pick-branch --gkcu-returnOutput=1} && ' +
326
+ 'git push --delete origin ${1:::__g-pick-branch --gkcu-returnOutput=1}'),
321
327
 
322
328
  // PULL(-REBASE)
323
329
  gpr: new AliasDefault('git pull --rebase $*'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkalpak/aliases",
3
- "version": "0.13.2",
3
+ "version": "0.13.4",
4
4
  "description": "My global aliases.",
5
5
  "keywords": [
6
6
  "Utility"
@@ -53,10 +53,13 @@
53
53
  "dkrrm": "bin/docker/dkrrm.js",
54
54
  "gaa": "bin/git/gaa.js",
55
55
  "gb": "bin/git/gb.js",
56
+ "gba": "bin/git/gba.js",
56
57
  "gbc": "bin/git/gbc.js",
57
58
  "gbcd": "bin/git/gbcd.js",
58
59
  "gbco": "bin/git/gbco.js",
59
60
  "gbd": "bin/git/gbd.js",
61
+ "gbdio": "bin/git/gbdio.js",
62
+ "gbdr": "bin/git/gbdr.js",
60
63
  "gcl": "bin/git/gcl.js",
61
64
  "gcm": "bin/git/gcm.js",
62
65
  "gcma": "bin/git/gcma.js",
@@ -197,17 +200,27 @@
197
200
  "dependencies": {
198
201
  "@gkalpak/cli-utils": "^0.2.0",
199
202
  "chalk": "^5.3.0",
200
- "inquirer": "^9.3.4",
203
+ "inquirer": "^10.1.8",
201
204
  "is-wsl": "^3.1.0"
202
205
  },
203
206
  "devDependencies": {
204
207
  "eslint": "^8.57.0",
205
208
  "eslint-plugin-import": "^2.29.1",
206
- "eslint-plugin-jasmine": "^4.2.0",
207
- "jasmine": "^5.1.0",
209
+ "eslint-plugin-jasmine": "^4.2.1",
210
+ "jasmine": "^5.2.0",
208
211
  "npm-run-all": "^4.1.5",
209
212
  "shelljs": "^0.8.5",
210
213
  "strip-ansi": "^7.1.0",
211
214
  "watch": "^1.0.2"
215
+ },
216
+ "overrides-comments": {
217
+ "watch": {
218
+ "exec-sh": "Fix vulnerability in transitive dependency `merge` (see https://github.com/gkalpak/aliases/security/dependabot/1)."
219
+ }
220
+ },
221
+ "overrides": {
222
+ "watch": {
223
+ "exec-sh": "0.4.0"
224
+ }
212
225
  }
213
226
  }