Comparing version 0.1.6 to 1.0.0
#!/usr/bin/env node | ||
const args = require('args'); | ||
const fuzzy = require('fuzzy'); | ||
const inquirer = require('inquirer'); | ||
const { yellow, magenta } = require('chalk'); | ||
const { platform, arch } = process; | ||
inquirer.registerPrompt( | ||
'autocomplete', | ||
require('inquirer-autocomplete-prompt') | ||
); | ||
function getBinaryPath() { | ||
const platform_arch = `${platform}-${arch}`; | ||
const binary_path = { | ||
'darwin-x64': '@swagit/darwin-x64', | ||
'darwin-arm64': '@swagit/darwin-arm64', | ||
'linux-x64': '@swagit/linux-x64', | ||
'linux-arm64': '@swagit/linux-arm64', | ||
'win32-x64': '@swagit/win32-x64', | ||
}[platform_arch]; | ||
const checkUpdate = require('../lib/check-update'); | ||
const checkNodeVersion = require('../lib/check-node-version'); | ||
const handleEsc = require('../lib/handle-esc'); | ||
const { info, success, error } = require('../lib/message-prefix'); | ||
const { | ||
checkGit, | ||
getBranches, | ||
deleteBranches, | ||
checkout, | ||
} = require('../lib/git'); | ||
checkNodeVersion(); | ||
handleEsc(); | ||
args.option('d', 'Select branches which you want to delete'); | ||
const flags = args.parse(process.argv); | ||
const search = | ||
(branches) => | ||
(ans, input = '') => | ||
new Promise((resolve) => { | ||
const fuzzyResult = fuzzy.filter( | ||
input, | ||
branches.map(({ value }) => value) | ||
); | ||
resolve(fuzzyResult.map((el) => el.original)); | ||
}); | ||
const startCheckout = async (branches) => { | ||
const { branch } = await inquirer.prompt([ | ||
{ | ||
type: 'autocomplete', | ||
name: 'branch', | ||
message: 'Which branch do you want to checkout?', | ||
source: search(branches), | ||
}, | ||
]); | ||
checkout(branch); | ||
console.log(`${success} Checkout current branch to ${magenta(branch)}`); | ||
}; | ||
const startDeleteBranches = async (branches) => { | ||
const { branches: selectedBranches } = await inquirer.prompt([ | ||
{ | ||
type: 'checkbox', | ||
name: 'branches', | ||
message: 'Which branches do you want to delete?', | ||
choices: branches, | ||
}, | ||
]); | ||
if (selectedBranches.length === 0) { | ||
console.log('No branch selected, exit.'); | ||
process.exit(1); | ||
if (!binary_path) { | ||
throw new Error(`Unsupported platform: ${platform_arch}`); | ||
} | ||
const messageSuffix = | ||
selectedBranches.length === 1 | ||
? 'this branch?' | ||
: `those ${yellow.bold(selectedBranches.length)} branches?`; | ||
const sub_path = platform === 'win32' ? 'swagit.exe' : 'swagit'; | ||
const { confirm } = await inquirer.prompt([ | ||
{ | ||
type: 'confirm', | ||
name: 'confirm', | ||
message: `Are you want to ${yellow.bold('DELETE')} ${messageSuffix} | ||
${selectedBranches.join(', ')}`, | ||
}, | ||
]); | ||
return require.resolve(`${binary_path}/bin/${sub_path}`); | ||
} | ||
if (confirm) { | ||
deleteBranches(selectedBranches); | ||
console.log( | ||
`${success} ${magenta( | ||
selectedBranches.length | ||
)} branches has been deleted.` | ||
); | ||
} | ||
}; | ||
const checkGitRepository = async () => { | ||
const currentBranch = await checkGit(); | ||
if (!currentBranch) { | ||
console.error( | ||
`${error} Not a git repository (or any of the parent directories)` | ||
); | ||
process.exit(1); | ||
} | ||
console.log(`${info} Current branch is ${magenta(currentBranch)}`); | ||
}; | ||
const getGitBranches = async () => { | ||
const branches = await getBranches(); | ||
if (branches.length === 0) { | ||
console.error(`${error} No other branches in the repository`); | ||
process.exit(1); | ||
} | ||
return branches; | ||
}; | ||
const main = async () => { | ||
checkUpdate().catch(() => {}); | ||
await checkGitRepository(); | ||
const branches = await getGitBranches(); | ||
if (flags.d) { | ||
await startDeleteBranches(branches); | ||
} else { | ||
await startCheckout(branches); | ||
} | ||
}; | ||
main(); | ||
require('child_process') | ||
.spawn(getBinaryPath(), process.argv.slice(2), { stdio: 'inherit' }) | ||
.on('exit', process.exit); |
{ | ||
"name": "swagit", | ||
"version": "0.1.6", | ||
"version": "1.0.0", | ||
"description": "A swag tool to use git with interactive cli", | ||
"author": "Evan Ye <jigsaw.ye@gmail.com>", | ||
"license": "MIT", | ||
"author": "Evan Ye <https://jigsawye.com> (jigsaw.ye@gmail.com)", | ||
"repository": { | ||
"url": "https://github.com/jigsawye/swagit.git" | ||
"bin": { | ||
"sg": "bin/swagit.js", | ||
"swagit": "bin/swagit.js" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jigsawye/swagit/issues" | ||
"optionalDependencies": { | ||
"@swagit/linux-x64": "1.0.0", | ||
"@swagit/linux-arm64": "1.0.0", | ||
"@swagit/win32-x64": "1.0.0", | ||
"@swagit/darwin-x64": "1.0.0", | ||
"@swagit/darwin-arm64": "1.0.0" | ||
}, | ||
"bin": { | ||
"sg": "./bin/swagit.js", | ||
"swagit": "./bin/swagit.js" | ||
}, | ||
"files": [ | ||
"bin", | ||
"lib" | ||
], | ||
"scripts": { | ||
"lint": "eslint bin lib", | ||
"prepare": "husky install", | ||
"test": "yarn lint" | ||
}, | ||
"dependencies": { | ||
"args": "^5.0.1", | ||
"chalk": "^4.1.2", | ||
"fuzzy": "^0.1.3", | ||
"inquirer": "^8.1.2", | ||
"inquirer-autocomplete-prompt": "^1.4.0", | ||
"node-version": "^2.0.0", | ||
"simple-git": "^2.45.1", | ||
"update-check": "^1.5.4" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^7.32.0", | ||
"eslint-config-yoctol-base": "^0.24.1", | ||
"eslint-plugin-import": "^2.24.2", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0", | ||
"husky": "^7.0.2", | ||
"lint-staged": "^11.1.2", | ||
"prettier": "^2.3.2", | ||
"prettier-package-json": "^2.6.0" | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"eslint --fix", | ||
"git add" | ||
], | ||
"*.{json,md}": [ | ||
"prettier --write", | ||
"git add" | ||
], | ||
"package.json": [ | ||
"prettier-package-json --write", | ||
"prettier --write", | ||
"git add" | ||
], | ||
".babelrc": [ | ||
"prettier --parser json --write", | ||
"git add" | ||
] | ||
} | ||
} | ||
"bin" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5
0
1
1207
2
20
1
2
0
2
2
+ Added@swagit/darwin-arm64@1.0.0(transitive)
+ Added@swagit/darwin-x64@1.0.0(transitive)
+ Added@swagit/linux-arm64@1.0.0(transitive)
+ Added@swagit/linux-x64@1.0.0(transitive)
+ Added@swagit/win32-x64@1.0.0(transitive)
- Removedargs@^5.0.1
- Removedchalk@^4.1.2
- Removedfuzzy@^0.1.3
- Removedinquirer@^8.1.2
- Removedinquirer-autocomplete-prompt@^1.4.0
- Removednode-version@^2.0.0
- Removedsimple-git@^2.45.1
- Removedupdate-check@^1.5.4
- Removed@kwsites/file-exists@1.1.1(transitive)
- Removed@kwsites/promise-deferred@1.1.1(transitive)
- Removedansi-escapes@4.3.2(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@3.2.14.3.0(transitive)
- Removedargs@5.0.3(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbl@4.1.0(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedcamelcase@5.0.0(transitive)
- Removedchalk@2.4.24.1.2(transitive)
- Removedchardet@0.7.0(transitive)
- Removedcli-cursor@3.1.0(transitive)
- Removedcli-spinners@2.9.2(transitive)
- Removedcli-width@3.0.0(transitive)
- Removedclone@1.0.4(transitive)
- Removedcolor-convert@1.9.32.0.1(transitive)
- Removedcolor-name@1.1.31.1.4(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddeep-extend@0.6.0(transitive)
- Removeddefaults@1.0.4(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedexternal-editor@3.1.0(transitive)
- Removedfigures@3.2.0(transitive)
- Removedfuzzy@0.1.3(transitive)
- Removedhas-flag@3.0.04.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedieee754@1.2.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedini@1.3.8(transitive)
- Removedinquirer@8.2.6(transitive)
- Removedinquirer-autocomplete-prompt@1.4.0(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-interactive@1.0.0(transitive)
- Removedis-unicode-supported@0.1.0(transitive)
- Removedleven@2.1.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlog-symbols@4.1.0(transitive)
- Removedmimic-fn@2.1.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmri@1.1.4(transitive)
- Removedms@2.1.3(transitive)
- Removedmute-stream@0.0.8(transitive)
- Removednode-version@2.0.0(transitive)
- Removedonetime@5.1.2(transitive)
- Removedora@5.4.1(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedrc@1.2.8(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedregistry-auth-token@3.3.2(transitive)
- Removedregistry-url@3.1.0(transitive)
- Removedrestore-cursor@3.1.0(transitive)
- Removedrun-async@2.4.1(transitive)
- Removedrxjs@6.6.77.8.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedsimple-git@2.48.0(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedsupports-color@5.5.07.2.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedtmp@0.0.33(transitive)
- Removedtslib@1.14.12.8.1(transitive)
- Removedtype-fest@0.21.3(transitive)
- Removedupdate-check@1.5.4(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwcwidth@1.0.1(transitive)
- Removedwrap-ansi@6.2.0(transitive)