Skip to content

Commit

Permalink
feat: help menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostdevv committed Feb 1, 2022
1 parent a9d6ff8 commit 9474eb2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ We have designed the cli to be able to be run in headless mode, as such the foll
```
npm init routify [directory-name]
-h, --help get the help menu
-v, --version use this to set the version of routify, e.g. 3
-f, --force this option bypasses directory checks, be careful as might overwrite files!
```
17 changes: 16 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const versions = {
3: () => import('./versions/three/index.js'),
};

const helpText = ` npm init routify [directory-name]
-h, --help get the help menu
-v, --version use this to set the version of routify, e.g. 3
-f, --force this option bypasses directory checks, be careful as might overwrite files!`;

async function getVersion(args) {
const argsVersion = args.v || args.version;
if (argsVersion) return argsVersion;
Expand Down Expand Up @@ -40,15 +46,24 @@ export const run = async ({ args }) => {
console.log(` ${k.bold().magenta('Routify')} ${k.magenta().dim('CLI')}`);
console.log();

if (args.h || args.help) {
return console.log(helpText);
}

const version = await getVersion(args);
const force = args.f || args.force;

if (!Object.keys(versions).includes(version.toString()))
return console.log(` ${k.red(`Version ${version} not found`)}`);

const projectName = args._[0] || '.';
const projectDir = resolve(projectName.toString());

if (existsSync(projectDir) && readdirSync(projectDir).length > 0) {
if (
existsSync(projectDir) &&
readdirSync(projectDir).length > 0 &&
!force
) {
const { proceed } = await prompts(
{
type: 'confirm',
Expand Down

0 comments on commit 9474eb2

Please sign in to comment.