Skip to content

Commit

Permalink
Simplification of cli
Browse files Browse the repository at this point in the history
  • Loading branch information
f0rmat1k committed Mar 22, 2015
1 parent 9f78e60 commit 6124857
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
35 changes: 27 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand All @@ -47,18 +56,27 @@ 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.

####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.

Expand All @@ -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}}
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions bem-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function getBlockName(trgPath, isBlock, isFile, bem, allowedSymbols){

if (isBlock) {
var blockRegExp = new RegExp('(' + allowedSymbols + '+)\/?$', 'i');

return trgPath.match(blockRegExp)[1];
}

Expand Down
11 changes: 6 additions & 5 deletions bemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 = {
Expand Down Expand Up @@ -166,6 +166,7 @@ function isValidNode(child, oldParentPath, newParentPath, originalInfo){
}

function startCreating(fileTypes){
fileTypes = fileTypes || ['css'];
fileTypes.forEach(function(fileType){
createFileFromTemplate(fileType);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6124857

Please sign in to comment.