-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Feat: use commandDir * Feat: refactor for commandDir and change from option -r to command r * Test: update test for new feat * Docs: update readme * Refactor: remove not used option * Test: update tests * Chore: mv default to release * Test: update tests * Docs: update readme BREAKING CHANGE: option (-r, -v) removed, add commands (r, v)
- Loading branch information
Showing
33 changed files
with
378 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,13 @@ | ||
#!/usr/bin/env node | ||
|
||
import chalk from 'chalk'; | ||
import inquirer from 'inquirer'; | ||
import isAdded from 'is-git-added'; | ||
import isGit from 'is-git-repository'; | ||
import getGitRemotes from 'get-git-remotes'; | ||
import getCommitRange from 'git-commit-range'; | ||
import taggedCommits from 'tagged-git-commits'; | ||
import updateNotifier from 'update-notifier'; | ||
import yargs from 'yargs'; | ||
|
||
import generateVersions from './helpers/generateVersions'; | ||
import getLatestVersion from './helpers/getLatestVersion'; | ||
import updateNotifier from 'update-notifier'; | ||
import pkg from '../package.json'; | ||
import questions from './questions'; | ||
import tasks from './tasks'; | ||
import recoverTasks from './recover-tasks'; | ||
|
||
const argv = yargs | ||
.usage('Usage: $0') | ||
.alias('v', 'version') | ||
.describe('v', 'Version number') | ||
.help('h') | ||
.alias('h', 'help') | ||
.alias('r', 'recover') | ||
.describe('r', 'Recover the complete CHANGELOG.md') | ||
yargs // eslint-disable-line | ||
.commandDir('cmds') | ||
.demandCommand() | ||
.help() | ||
.argv; | ||
|
||
updateNotifier({ pkg }).notify(); | ||
|
||
const cli = () => { | ||
const cwd = process.cwd(); | ||
const latestTaggedCommits = taggedCommits({ path: cwd }); | ||
const latestTaggedCommit = latestTaggedCommits.length === 0 ? '' : latestTaggedCommits[0].commit; | ||
const commits = getCommitRange({ path: cwd, from: latestTaggedCommit }); | ||
const latestVersion = getLatestVersion(); | ||
const newVersions = generateVersions(latestVersion); | ||
const questionsList = questions(newVersions); | ||
|
||
if (!isGit(cwd)) { | ||
return console.warn(chalk.red('Error: this is not a git repository... make sure you are in the right directory')); | ||
} else if (!isAdded(cwd) && commits.length === 0) { | ||
return console.warn(chalk.red('Error: no changes... try to git add <files>')); | ||
} else if (commits.length === 0) { | ||
return console.warn(chalk.red('Error: no commits yet... try to git commit -m <message>')); | ||
} else if (!getGitRemotes(cwd)) { | ||
return console.warn(chalk.red('Error: it seems you do not have a remote repository set... try to git remote add origin <remote-url>')); | ||
} else if (latestVersion === '') { | ||
return console.warn(chalk.red('Error: it seems you do not have a package.json... try npm init')); | ||
} | ||
|
||
return inquirer | ||
.prompt(questionsList) | ||
.then((answers) => { | ||
if (answers.ownVersion) { | ||
return tasks(commits, answers.ownVersion) | ||
.run() | ||
.catch(() => console.warn(chalk.red('Error: whoops, try to solve the problem mentioned above...'))); | ||
} | ||
|
||
return tasks(commits, answers.version) | ||
.run() | ||
.catch(() => console.warn(chalk.red('Error: whoops, try to solve the problem mentioned above...'))); | ||
}) | ||
.catch((err) => console.warn(chalk.red(err))); | ||
}; | ||
|
||
if (argv.v) { | ||
console.info(`v${pkg.version}`); | ||
} else if (argv.recover) { | ||
if (argv.recover === 'b' || argv.recover === 'backup') { | ||
recoverTasks(true).run(); | ||
} else { | ||
recoverTasks(false).run(); | ||
} | ||
} else { | ||
cli(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import recoverTasks from '../tasks/recover-tasks'; | ||
|
||
const command = 'recover [backup]'; | ||
|
||
const builder = { | ||
backup: { | ||
default: false, | ||
}, | ||
}; | ||
|
||
const aliases = ['r']; | ||
|
||
const desc = 'Recover the complete CHANGELOG.md'; | ||
|
||
/* istanbul ignore next */ | ||
const handler = (argv) => { | ||
if (argv.backup || argv.b) { | ||
return recoverTasks(true).run(); | ||
} | ||
|
||
return recoverTasks(false).run(); | ||
}; | ||
|
||
export { | ||
command, | ||
builder, | ||
aliases, | ||
desc, | ||
handler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import release from '../tasks/release-tasks'; | ||
|
||
const command = '*'; | ||
|
||
const desc = 'Release a new version (run tests, write changelog, tag version, push release)'; | ||
|
||
/* istanbul ignore next */ | ||
const handler = () => release(); | ||
|
||
export { | ||
command, | ||
desc, | ||
handler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pkg from '../../package.json'; | ||
|
||
const command = 'version'; | ||
|
||
const aliases = ['v']; | ||
|
||
const desc = 'Show the current version number'; | ||
|
||
/* istanbul ignore next */ | ||
const handler = () => console.info(`sgr version ${pkg.version}`); | ||
|
||
export { | ||
command, | ||
aliases, | ||
desc, | ||
handler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.