This repository has been archived by the owner on Mar 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use commands instead of just options
- Loading branch information
Brandon Pittman
committed
Oct 18, 2019
1 parent
101c7ce
commit 9cb258f
Showing
7 changed files
with
73 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,62 @@ | ||
#! /usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const meow = require('meow'); | ||
const pascalcase = require('pascalcase'); | ||
|
||
const isGridsomeProject = require('./lib/isGridsomeProject'); | ||
const override = require('./lib/override'); | ||
const createPage = require('./lib/createPage'); | ||
const createComponent = require('./lib/createComponent'); | ||
const createLayout = require('./lib/createLayout'); | ||
const createTemplate = require('./lib/createTemplate'); | ||
const deleteReadme = require('./lib/deleteReadme'); | ||
const cli = meow(` | ||
const copyTemplate = require('./lib/copyTemplate'); | ||
const fresh = require('./lib/fresh'); | ||
|
||
const cli = meow(` | ||
Usage | ||
$ gridsome-helpers -o html|vue | ||
$ gridsome-helpers | ||
override html|vue Override filetype | ||
scaffold -t TYPE -n NAME Scaffold out a new file | ||
fresh Delete Gridsome boilerplate pages and folder-specific README.md files | ||
Options | ||
--override, -o html|vue Override filetype | ||
--component, -c ComponentName Create component skeleton | ||
--page, -p PageName Create page skeleton | ||
--layout, -l LayoutName Create layout skeleton | ||
--template, -t TemplateName Create template skeleton | ||
--delete-readme Delete Gridsome README.md files inside src directories | ||
--help, -h Show help | ||
Options | ||
--type, -t Page|Template|Layout|Component Filetype to be scaffolded | ||
--name, -n SomeFilename Filename to be used (will be pascal cased by CLI) | ||
--help, -h Show help | ||
`, { | ||
flags: { | ||
help: { | ||
alias: 'h', | ||
type: 'boolean' | ||
}, | ||
override: { | ||
type: 'string', | ||
alias: 'o' | ||
}, | ||
component: { | ||
type: 'string', | ||
alias: 'c' | ||
}, | ||
layout: { | ||
type: 'string', | ||
alias: 'l' | ||
}, | ||
page: { | ||
type: { | ||
type: 'string', | ||
alias: 'p' | ||
alias: 't' | ||
}, | ||
template: { | ||
name: { | ||
type: 'string', | ||
alias: 't' | ||
alias: 'n' | ||
} | ||
} | ||
}); | ||
|
||
if (cli.flags.override) { | ||
override(cli); | ||
} | ||
|
||
if (cli.flags.page && cli.flags.page.length > 0) { | ||
createPage(pascalcase(cli.flags.page)); | ||
} | ||
isGridsomeProject(); | ||
|
||
if (cli.flags.template && cli.flags.template.length > 0) { | ||
createTemplate(pascalcase(cli.flags.template)); | ||
} | ||
const command = cli.input[0]; | ||
|
||
if (cli.flags.layout && cli.flags.layout.length > 0) { | ||
createLayout(pascalcase(cli.flags.layout)); | ||
} | ||
switch (command) { | ||
case 'scaffold': | ||
console.log('scaffold'); | ||
copyTemplate(pascalcase(cli.flags.type), pascalcase(cli.flags.name)); | ||
break; | ||
|
||
if (cli.flags.component && cli.flags.component.length > 0) { | ||
createComponent(pascalcase(cli.flags.component)); | ||
} | ||
case 'override': | ||
override(cli.input[1]); | ||
break; | ||
|
||
if (cli.flags.deleteReadme) { | ||
deleteReadme(); | ||
} | ||
case 'fresh': | ||
fresh(); | ||
break; | ||
|
||
if (Object.keys(cli.flags).length === 2) { | ||
cli.showHelp(); | ||
default: | ||
cli.showHelp(); | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const del = require('del'); | ||
const chalk = require('chalk'); | ||
const copyTemplate = require('./copyTemplate'); | ||
|
||
module.exports = async () => { | ||
const deletedPaths = await del([ | ||
'src/{pages,components,layouts,templates}/README.md', | ||
'src/pages/{Index,About}.vue', | ||
'src/layouts/DefaultLayout.vue', | ||
'!./README.md' | ||
]); | ||
|
||
if (deletedPaths.length > 0) { | ||
console.log(chalk.green('Deleted files:\n', deletedPaths.join('\n'))); | ||
} else { | ||
console.log(chalk.yellow('No files to delete.')); | ||
} | ||
|
||
copyTemplate('Layout', 'DefaultLayout'); | ||
copyTemplate('Page', 'Index'); | ||
}; |
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,9 @@ | ||
const fs = require('fs'); | ||
const chalk = require('chalk'); | ||
|
||
module.exports = () => { | ||
if (!fs.existsSync('./gridsome.config.js')) { | ||
console.log(chalk.red('Not in root of a Gridsome project!')); | ||
process.exit(126); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = options => { | ||
console.log(options); | ||
}; |