@gkalpak/aliases 0.10.0 → 0.10.2

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.10.0]
5
+ ### [Generated by: @gkalpak/aliases v0.10.2]
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.10.0]
5
+ ### [Generated by: @gkalpak/aliases v0.10.2]
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.10.0]
4
+ ### [Generated by: @gkalpak/aliases v0.10.2]
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.10.0]
4
+ ### [Generated by: @gkalpak/aliases v0.10.2]
5
5
  ### Run the following commands:
6
6
 
7
7
  git config --global commit.gpgSign true
@@ -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.10.0]');
5
+ console.log('""" [Generated by: @gkalpak/aliases v0.10.2]');
6
6
  console.log('""" Copy the following into \'~/.vimrc\':\n');
7
7
  console.log(readFileSync(`${__dirname}/../../lib/assets/vimrc.txt`, 'utf8').trim() + '\n');
@@ -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 fetch origin $1 && git checkout origin/$1 -b $1 && git config branch.$1.remote origin && git config branch.$1.merge refs/heads/$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.10.0');
2
+ console.log('@gkalpak/aliases v0.10.2');
package/lib/constants.js CHANGED
@@ -115,6 +115,10 @@ const CFGGIT_SPEC_WITH_CRED_HELPER = credHelper => new AliasSpec(
115
115
  `),
116
116
  'Show configuration instructions for `git`.');
117
117
 
118
+ const GIT_CREATE_BRANCH_CMD = srcBranchArg =>
119
+ `git checkout ${srcBranchArg} -b $1 && git config branch.$1.remote origin && ` +
120
+ 'git config branch.$1.merge refs/heads/$1';
121
+
118
122
  const SCRIPT_BACKED_CODE = (scriptName, desc) => stripIndentation(`
119
123
  #!/usr/bin/env node
120
124
  import {commandUtils} from '@gkalpak/cli-utils';
@@ -262,12 +266,9 @@ const ALIASES = {
262
266
 
263
267
  // BRANCH
264
268
  gb: new AliasDefault('git branch $*'),
265
- gbc: new AliasDefault(
266
- 'git checkout ${2:HEAD} -b $1 && git config branch.$1.remote origin && ' +
267
- 'git config branch.$1.merge refs/heads/$1'),
268
- gbcm: new AliasDefault(
269
- `git checkout \${0:::${GIT_GET_DEFAULT_BRANCH_CMD}} -b $1 && git config branch.$1.remote origin && ` +
270
- 'git config branch.$1.merge refs/heads/$1'),
269
+ gbc: new AliasDefault(GIT_CREATE_BRANCH_CMD('${2:HEAD}')),
270
+ gbcm: new AliasDefault(GIT_CREATE_BRANCH_CMD(`\${0:::${GIT_GET_DEFAULT_BRANCH_CMD}}`)),
271
+ gbco: new AliasDefault(`git fetch origin $1 && ${GIT_CREATE_BRANCH_CMD('origin/$1')}`),
271
272
  gbd: new AliasDefault('git branch --delete --force ${*:::__g-pick-branch --gkcu-returnOutput=1}'),
272
273
 
273
274
  // PULL(-REBASE)
package/lib/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Imports
2
- import {readFileSync} from 'node:fs';
2
+ import {existsSync, readFileSync, realpathSync} from 'node:fs';
3
3
  import {createRequire} from 'node:module';
4
4
  import {fileURLToPath, pathToFileURL} from 'node:url';
5
5
 
@@ -11,6 +11,8 @@ const LINE_LIMIT = 75;
11
11
  const INDENT_PER_LEVEL = 2;
12
12
  const PLATFORM = isWsl ? 'wsl' : process.platform;
13
13
  const internal = {
14
+ _fsExistsSync,
15
+ _fsRealpathSync,
14
16
  _getPlatform,
15
17
  _import,
16
18
  _onError,
@@ -35,6 +37,14 @@ export {
35
37
  };
36
38
 
37
39
  // Helpers
40
+ function _fsExistsSync(path) {
41
+ return existsSync(path);
42
+ }
43
+
44
+ function _fsRealpathSync(path) {
45
+ return realpathSync(path);
46
+ }
47
+
38
48
  function _getPlatform() {
39
49
  return PLATFORM;
40
50
  }
@@ -113,17 +123,11 @@ async function importWithEnv(targetImportPath, sourceImportMetaUrl, tempEnvVars)
113
123
  }
114
124
 
115
125
  function isMain(fileUrl) {
116
- const extRe = /\.[cm]?js$/;
117
-
126
+ const mainExt = ['', '.js'].find(ext => internal._fsExistsSync(`${process.argv[1]}${ext}`)) ?? '';
127
+ const mainPath = internal._fsRealpathSync(`${process.argv[1]}${mainExt}`);
118
128
  const filePath = fileURLToPath(fileUrl);
119
- const mainPath = process.argv[1];
120
-
121
- const filePathExt = extRe.exec(filePath)?.[0];
122
- const mainPathExt = extRe.exec(mainPath)?.[0];
123
129
 
124
- return (filePath === mainPath) ||
125
- ((filePathExt !== null) && (filePath === `${mainPath}${filePathExt}`)) ||
126
- ((mainPathExt !== null) && (`${filePath}${mainPathExt}` === mainPath));
130
+ return filePath === mainPath;
127
131
  }
128
132
 
129
133
  function loadJson(filePath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkalpak/aliases",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "My global aliases.",
5
5
  "keywords": [
6
6
  "Utility"
@@ -52,6 +52,7 @@
52
52
  "gb": "./bin/git/gb.js",
53
53
  "gbc": "./bin/git/gbc.js",
54
54
  "gbcm": "./bin/git/gbcm.js",
55
+ "gbco": "./bin/git/gbco.js",
55
56
  "gbd": "./bin/git/gbd.js",
56
57
  "gcl": "./bin/git/gcl.js",
57
58
  "gcm": "./bin/git/gcm.js",