bootstrap-component
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -6,4 +6,5 @@ #!/usr/bin/env node | ||
const inquirer = require('inquirer'); | ||
const minimist = require('minimist'); | ||
const mkdirp = require('mkdirp'); | ||
const path = require('path'); | ||
const mkdirp = require('mkdirp'); | ||
@@ -13,3 +14,2 @@ const EXIT_CODES = { | ||
NOT_IN_ROOT_FOLDER: 1, | ||
INCORRECT_FOLDER_STRUCTURE: 2, | ||
COMPONENT_NAME_MISSING: 3, | ||
@@ -27,3 +27,2 @@ ALREADY_EXISTS: 4, | ||
const isInRootFolder = fs.existsSync(path.resolve(CURRENT_DIR, 'package.json')); | ||
const hasCorrectFolderStructure = fs.existsSync(path.resolve(CURRENT_DIR, 'src', 'components')); | ||
@@ -37,12 +36,5 @@ if (!isInRootFolder) { | ||
} | ||
if (!hasCorrectFolderStructure) { | ||
console.error( | ||
'💩 Looks like you don\'t have a src/components folder. This tool is set up to follow this ' + | ||
'structure. If you came across this script and need it to work for you, please submit ' + | ||
'an issue or a pull request at https://www.github.com/selbekk/bootstrap-component.' | ||
); | ||
process.exit(EXIT_CODES.INCORRECT_FOLDER_STRUCTURE); | ||
} | ||
const args = minimist(process.argv.slice(2)); | ||
let componentName = process.argv[2]; | ||
let componentName = args._[0]; | ||
if (!componentName) { | ||
@@ -63,3 +55,13 @@ const result = await inquirer.prompt([{ | ||
const componentFolder = path.resolve(CURRENT_DIR, 'src', 'components', toCase.kebab(componentName)); | ||
let componentPath = args.path; | ||
if (!componentPath) { | ||
const result = await inquirer.prompt([{ | ||
message: 'Where do you want to place your new component?', | ||
name: 'path', | ||
default: 'src/components', | ||
}]) | ||
componentPath = result.path; | ||
} | ||
const componentFolder = path.resolve(CURRENT_DIR, componentPath, toCase.kebab(componentName)); | ||
if (fs.existsSync(componentFolder)) { | ||
@@ -66,0 +68,0 @@ console.error( |
{ | ||
"name": "bootstrap-component", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -8,3 +8,7 @@ "bin": { | ||
}, | ||
"keywords": ["react", "bootstrap", "component"], | ||
"keywords": [ | ||
"react", | ||
"bootstrap", | ||
"component" | ||
], | ||
"repository": "selbekk/bootstrap-component", | ||
@@ -16,4 +20,5 @@ "author": "selbekk <kristofer@selbekk.io>", | ||
"inquirer": "^4.0.1", | ||
"minimist": "^1.2.0", | ||
"mkdirp": "^0.5.1" | ||
} | ||
} |
@@ -39,2 +39,8 @@ # Bootstrap a new React component! | ||
You can specify the path too with the `--path=some/path/to/components`, if you need to create a similar | ||
structure somewhere else in your code base. The default is `src/components`. | ||
``` | ||
$ comp my-component --path=src/components | ||
This will bootstrap a new component, complete with index.js file and ready to be coded. | ||
@@ -41,0 +47,0 @@ |
4494
4
71
51
4
+ Addedminimist@^1.2.0