Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagit

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagit - npm Package Compare versions

Comparing version 0.1.6 to 1.0.0

146

bin/swagit.js
#!/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"
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc