Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
Update help messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Pittman committed Feb 18, 2020
1 parent ba33f56 commit 8211393
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 56 deletions.
63 changes: 28 additions & 35 deletions src/cli.ts
@@ -1,6 +1,6 @@
#! /usr/bin/env node

import {version, description} from '../package.json';
import {version} from '../package.json';
import {log} from 'console';
import chalk from 'chalk';
import arg from 'arg';
Expand All @@ -12,51 +12,44 @@ const args = arg({
'-v': '--version'
}, {permissive: true});

if (args['--version']) {
const commands = {
init: async () => import('./gridtastic-init').then(i => i.default),
scaffold: async () => import('./gridtastic-scaffold').then(async i => i.default),
override: async () => import('./gridtastic-override').then(async i => i.default),
fresh: async () => import('./gridtastic-fresh').then(async i => i.default)
};

const foundCommand = Boolean(commands[args._[0]]);

if (!foundCommand && args['--version']) {
log(version);
process.exit(0);
}

if (args['--help']) {
const help = chalk`
if (!foundCommand && args['--help']) {
log(chalk`
{bold Usage}
$ gridtastic {bold <command>}
${description}
{bold Available commands}
${Object.keys(commands).join(', ')}
{bold Usage}
{dim $} {bold gridtastic}
{bold Options}
--version, -v Show version
--help, -h Show help
init --repo REPO --dest DEST Download Gridsome starter
override --html --vue Override App.vue and/or index.html
scaffold --TYPE --name NAME Scaffold out a new file
fresh Delete Gridsome boilerplate pages and folder-specific README.md files
{bold Options}
--repo, -r GITHUB_USER/REPO_NAME
--dest, -d Folder to clone Gridsome starter project to
--html Denotes index.html
--vue Denotes App.vue
--template, -t /templates
--page, -p /pages
--component, -c /components
--layout, -l /layouts
--name, -n SomeFilename Filename to be used (will be pascal cased by CLI)
--version, -v Show version
--help, -h Show help
`;
log(help);
For more information run a command with the --help flag
$ gridtastic scaffold --help
`);
process.exit(0);
}

let forwardedArgs = args._.slice(1);

const commands = {
init: async () => import('./gridtastic-init').then(i => i.default),
scaffold: async () => import('./gridtastic-scaffold').then(async i => i.default),
override: async () => import('./gridtastic-override').then(async i => i.default),
fresh: async () => import('./gridtastic-fresh').then(async i => i.default)
};

const command = commands[args._[0]];
const forwardedArgs = args._.slice(1);

if (args['--help']) {
forwardedArgs.push('--help');
}

if (command) {
command().then(exec => exec(forwardedArgs));
Expand Down
19 changes: 18 additions & 1 deletion src/gridtastic-fresh.ts
Expand Up @@ -2,8 +2,25 @@ import del from 'del';
import chalk from 'chalk';
import scaffold from './gridtastic-scaffold';
import isGridsomeProject from './isGridsomeProject';
import arg from 'arg';

export default async (argv: string[]): Promise<void> => {
const args = arg({
'--help': Boolean,
'-h': '--help'
}, {argv});

if (args['--help']) {
console.log(chalk`
{bold Description}
Removes boilerplate files like README.md and About.vue typically included for new developers.
{bold Usage}
$ gridtastic fresh
`);
process.exit(0);
}

export default async (): Promise<void> => {
isGridsomeProject();

const deletedPaths = await del([
Expand Down
29 changes: 24 additions & 5 deletions src/gridtastic-init.ts
Expand Up @@ -2,14 +2,33 @@ import degit from 'degit';
import chalk from 'chalk';
import arg from 'arg';

export default (argv): void => {
export default (argv: string[]): void => {
const args = arg({
'--repo': String,
'--dest': String,
'--help': Boolean,
'-h': '--help'
}, {argv});

if (args['--help']) {
console.log(chalk`
{bold Description}
Creates overrides for App.vue and/or index.html, with boilerplate code.
{bold Usage}
$ gridtastic init [--repo repo] [--dest dest]
[repo] refers to a GitHub repository containing a starter project. [dest]
is the desired directory name for the clone repository. [repo] defaults to
"brandonpittman/gridsome-starter-default" and [dest] defaults to "gridsome-starter-default".
`);
process.exit(0);
}

let {
'--repo': repo = 'brandonpittman/gridsome-starter-default',
'--dest': dest = 'gridsome-starter-default'
} = arg({
'--repo': String,
'--dest': String
}, {argv});
} = args;

let emitter = degit(repo, {
cache: false,
Expand Down
25 changes: 20 additions & 5 deletions src/gridtastic-override.ts
Expand Up @@ -5,16 +5,31 @@ import isGridsomeProject from './isGridsomeProject';
import pkgDir from 'pkg-dir';
import arg from 'arg';

export default async (argv): Promise<void> => {
export default async (argv: string[]): Promise<void> => {
const args = arg({
'--html': Boolean,
'--vue': Boolean,
'--help': Boolean,
'-h': '--help'
}, {argv});

if (args['--help']) {
console.log(chalk`
{bold Description}
Creates overrides for App.vue and/or index.html, with boilerplate code.
{bold Usage}
$ gridtastic override --vue --html
`);
process.exit(0);
}

isGridsomeProject();

let {
'--html': html = false,
'--vue': vue = false
} = arg({
'--html': Boolean,
'--vue': Boolean
}, {argv});
} = args;

if (!fs.existsSync('./src')) {
log(chalk.blue('Creating src directory'));
Expand Down
44 changes: 34 additions & 10 deletions src/gridtastic-scaffold.ts
Expand Up @@ -6,16 +6,15 @@ import pascalcase from 'pascalcase';
import isGridsomeProject from './isGridsomeProject';
import arg from 'arg';

export default async (argv): Promise<void> => {
isGridsomeProject();
// Scaffold --TYPE --name NAME Scaffold out a new file
// --template, -t /templates
// --page, -p /pages
// --component, -c /components
// --layout, -l /layouts
// --name, -n SomeFilename Filename to be used (will be pascal cased by CLI)

let {
'--name': name = null,
'--component': component = false,
'--template': template = false,
'--page': page = false,
'--layout': layout = false
} = arg({
export default async (argv: string[]): Promise<void> => {
const args = arg({
'--template': Boolean,
'--page': Boolean,
'--component': Boolean,
Expand All @@ -25,9 +24,34 @@ export default async (argv): Promise<void> => {
'-c': '--component',
'-p': '--page',
'-t': '--template',
'-n': '--name'
'-n': '--name',
'--help': Boolean,
'-h': '--help'
}, {argv});

if (args['--help']) {
console.log(chalk`
{bold Description}
Creates a new Vue file of page, component, template, or layout types.
{bold Usage}
$ gridtastic scaffold --page --name <name>
<name> will converted to PascalCase automatically.
`);
process.exit(0);
}

isGridsomeProject();

let {
'--name': name = null,
'--component': component = false,
'--template': template = false,
'--page': page = false,
'--layout': layout = false
} = args;

if (!(component || page || template || layout)) {
console.log(chalk.bold.red('Please provide one of the filetype options.'));
process.exit(1);
Expand Down

0 comments on commit 8211393

Please sign in to comment.