From 612485769ae54a617c2575cd670cd44b1f3a4f11 Mon Sep 17 00:00:00 2001 From: Anton Grischenko Date: Sun, 22 Mar 2015 16:12:27 +0500 Subject: [PATCH] Simplification of cli --- README.md | 35 +++++++++++++++++++++++++++-------- bem-info.js | 1 + bemy.js | 11 ++++++----- package.json | 2 +- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 44cd7d1..f6b8fa0 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ bemy -t [task] -f [path] [options] When you call bemy on files it is like you call bemy on the folder contains this file. So this two variants are equal: `-f ~/testBlock/__elem` and `-f ~/testBlock/__elem/testBlock__elem.bh.js`. + +Starting with version 2.1 `-t` and `-p` and `-f` is no more required. Task seleced depend on call bemy. See details on tasks description below. + ###Shared CLI options `-t [task name]` — name of the called task. default: 'auto'; `-f [path]` — path to BEM node (folder or file); @@ -29,15 +32,21 @@ Example: Command: `bemy -t create -f ~/testBlock/__elem -p "css js"` Result: In the folder `~/testBlock/__elem` was added two files: `testBlock__elem.js` and `testBlock__elem.css`. +```bash +cd some-block +bemy c j +``` +Result: called 'create' task and appear `some-block/some-block.css` and `some-block/some-block.js`. + ####Options `-o` — to open the file after creation. This command configured in config.json in section `editor-open-command`. Default value is `wstorm {{file-path}}:{{line-number}}`. See more details at below in section `Configuring`.; -`-p [file list]` — file types list. Available following file types: `-p "css js deps priv bh"`. Also you can use short notation `p c j b d`. You can add you own file types and shortcuts at config.json. +`-p [file list]` — file types list. Available following file types: `-p "css js deps priv bh"`. Also you can use short notation `p c j b d`. You can add you own file types and shortcuts at config.json. Also you can set file types with just enumeration before single options keys, e.g. `bemy c j -o -g`. -An example of using bemy with `external tools` of webstorm for the task of creation: +Webstorm requiered `-f [path]`. An example of using bemy with `external tools` of webstorm for the task of creation: ![](https://cloud.githubusercontent.com/assets/769992/6725632/0232f4ee-ce2e-11e4-942e-7845381663ed.png) Don't forget to configure hotkey for task running (e.g. `ctrl + c`) at `keymap` section. -###Task of renaming +###The task of renaming Recursively renames current node and its children. `-d` turn on deep mode and the contents of the files will also be renamed. Deep rename used `rename` param from config file so you should to configure it for you own file types. `rename` renames only described files and valid directories (e.g. mod folder in mod folder isn't valid). ####CLI for task of renaming: @@ -47,10 +56,10 @@ Recursively renames current node and its children. `-d` turn on deep mode and th `-d` — turn on deep mode with renaming of files content; `-p` — new BEM node name; -An example of using bemy with `external tools` of webstorm for the task of renaming: +Webstorm requiered `-f [path]`. An example of using bemy with `external tools` of webstorm for the task of renaming: ![](https://cloud.githubusercontent.com/assets/769992/6766361/e3006d96-d025-11e4-948e-1f11a663f2ea.png) -###Autotask +###The autotask Call default action depend on BEM node. Currently work following variants: 1. If target is deps-file, creates described elems\mods\elemMods folder structure. And depend on options of config.json also creates elems\mods\elemMods files. By default it's css files. Se `Configuring` section for more details. 2. Otherwise call create task with default options (equal `-t create -f [path] -p "css"`). Default file types for autotask configurable at config.json. @@ -58,7 +67,16 @@ Call default action depend on BEM node. Currently work following variants: ####CLI for autotask `bemy -f [path]` -An example of using bemy with `external tools` of webstorm for the autotask: +or you can call just bemy: +Run autotask: +```bash +cd some-block +bemy +``` +Called autotask and created the only css file `some-block.css`. +You should set `-f` when you want set not current directory or call bemy on `deps.js` file. + +Webstorm requiered `-f [path]`. An example of using bemy with `external tools` of webstorm for the autotask: ![](https://cloud.githubusercontent.com/assets/769992/6725778/23a5188a-ce30-11e4-828d-0d590fb26e08.png) Don't forget to configure hotkey for task running (e.g. `ctrl + a`) at `keymap` section. @@ -72,7 +90,8 @@ Description of the used file types. `shortcuts` — list of short that you can use after `-p` key in Task of creation; `rename` – mask for deep renaming. {{bemNode}} will be replaced to new node name. You can also use an array of masks; `template` — path to template of file type. Teamplate used when any files are created. -There are following placeholders: `{{blockName}}`, `{{elemName}}`, `{{modName}}`, `{{modVal}}` and `{{cursor}}`. When files are created this entries will be replaced with relevant part of BEM node name. And `{{cursor}}` will be deleted and used for setting cursor line number (see more at Configuring section). +There are following placeholders: `{{blockName}}`, `{{elemName}}`, `{{modName}}`, `{{modVal}}` and `{{cursor}}`. When files are created this entries will be replaced with relevant part of BEM node name. And `{{cursor}}` will be deleted and used for setting cursor line number (see more at `Configuring` section). + For example, default css template contain: ``` .{{blockName}}{{elemName}}{{modName}}{{modVal}} @@ -83,7 +102,7 @@ For example, default css template contain: , so resulted file will contain: ```css .testBlock__elem { -/* curor will be here, if you use right configured -o key */ +/* curor will be here, when you use right configured -o key */ } ``` `deps_task` – options for autotask when it called on deps file. `files` – list of file types to be created in addition to folders. diff --git a/bem-info.js b/bem-info.js index 1ea5aa8..b9fa78d 100644 --- a/bem-info.js +++ b/bem-info.js @@ -96,6 +96,7 @@ function getBlockName(trgPath, isBlock, isFile, bem, allowedSymbols){ if (isBlock) { var blockRegExp = new RegExp('(' + allowedSymbols + '+)\/?$', 'i'); + return trgPath.match(blockRegExp)[1]; } diff --git a/bemy.js b/bemy.js index 5b179b8..2880d9c 100644 --- a/bemy.js +++ b/bemy.js @@ -9,9 +9,9 @@ var exec = require('child_process').exec; var depsNormalize = require('deps-normalize'); var options = minimist(process.argv.slice(2)), - trgPath = options.f, + trgPath = options.f ? path.resolve(options.f) : process.env.PWD, configPath = options.c ? path.resolve(options.c) : path.join(__dirname, 'config.json'), - prompt = options.p ? options.p.toString().split(/\s/) : '', + prompt = options.p ? options.p.toString().split(/\s/) : options._, config = JSON.parse(fs.readFileSync(configPath, 'utf-8')), isOwnConfig = options.c, bemInfo = require('./bem-info.js')(config); @@ -35,10 +35,10 @@ var bem = config.bem, return shortcuts; }(), DEFAULT_ACTIONS = { - blockDir: startCreating.bind(this, ['css']), + blockDir: startCreating.bind(this, prompt), deps: createStructureByDeps, - elemDir: startCreating.bind(this, ['css']), - modDir: startCreating.bind(this, ['css']) + elemDir: startCreating.bind(this, prompt), + modDir: startCreating.bind(this, prompt) }, BEM_INFO = bemInfo(trgPath), tasks = { @@ -166,6 +166,7 @@ function isValidNode(child, oldParentPath, newParentPath, originalInfo){ } function startCreating(fileTypes){ + fileTypes = fileTypes || ['css']; fileTypes.forEach(function(fileType){ createFileFromTemplate(fileType); }); diff --git a/package.json b/package.json index d9ce7a4..9bf45b2 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "type": "git", "url": "https://github.com/f0rmat1k/bemy.git" }, - "version": "2.0.0", + "version": "2.1.0", "keywords": [ "bem", "BEM Tools"