Skip to content

Commit da659f2

Browse files
committed
Init realise
1 parent cc3eb6c commit da659f2

File tree

8 files changed

+376
-1
lines changed

8 files changed

+376
-1
lines changed

.gitignore

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Created by https://www.gitignore.io/api/osx,phpstorm,node
2+
3+
### OSX ###
4+
.DS_Store
5+
.AppleDouble
6+
.LSOverride
7+
8+
# Icon must end with two \r
9+
Icon
10+
11+
# Thumbnails
12+
._*
13+
14+
# Files that might appear in the root of a volume
15+
.DocumentRevisions-V100
16+
.fseventsd
17+
.Spotlight-V100
18+
.TemporaryItems
19+
.Trashes
20+
.VolumeIcon.icns
21+
22+
# Directories potentially created on remote AFP share
23+
.AppleDB
24+
.AppleDesktop
25+
Network Trash Folder
26+
Temporary Items
27+
.apdisk
28+
29+
30+
### PhpStorm ###
31+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
32+
33+
*.iml
34+
35+
## Directory-based project format:
36+
.idea/
37+
# if you remove the above rule, at least ignore the following:
38+
39+
# User-specific stuff:
40+
# .idea/workspace.xml
41+
# .idea/tasks.xml
42+
# .idea/dictionaries
43+
44+
# Sensitive or high-churn files:
45+
# .idea/dataSources.ids
46+
# .idea/dataSources.xml
47+
# .idea/sqlDataSources.xml
48+
# .idea/dynamic.xml
49+
# .idea/uiDesigner.xml
50+
51+
# Gradle:
52+
# .idea/gradle.xml
53+
# .idea/libraries
54+
55+
# Mongo Explorer plugin:
56+
# .idea/mongoSettings.xml
57+
58+
## File-based project format:
59+
*.ipr
60+
*.iws
61+
62+
## Plugin-specific files:
63+
64+
# IntelliJ
65+
/out/
66+
67+
# mpeltonen/sbt-idea plugin
68+
.idea_modules/
69+
70+
# JIRA plugin
71+
atlassian-ide-plugin.xml
72+
73+
# Crashlytics plugin (for Android Studio and IntelliJ)
74+
com_crashlytics_export_strings.xml
75+
crashlytics.properties
76+
crashlytics-build.properties
77+
78+
79+
### Node ###
80+
# Logs
81+
logs
82+
*.log
83+
npm-debug.log*
84+
85+
# Runtime data
86+
pids
87+
*.pid
88+
*.seed
89+
90+
# Directory for instrumented libs generated by jscoverage/JSCover
91+
lib-cov
92+
93+
# Coverage directory used by tools like istanbul
94+
coverage
95+
96+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
97+
.grunt
98+
99+
# node-waf configuration
100+
.lock-wscript
101+
102+
# Compiled binary addons (http://nodejs.org/api/addons.html)
103+
build/Release
104+
105+
# Dependency directory
106+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
107+
node_modules
108+

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
## 0.0.1 / 04-10-2015
4+
* Init realise

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Stanislav
3+
Copyright (c) 2015 Stanislav Eremenko (c01nd01r)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# b-add
2+
3+
Небольшая утилита для быстрого добавления БЭМ блоков в файловую систему вашего проекта.
4+
5+
## Возможности
6+
* Автоматическое создание файлов и директорий
7+
* Настройка расширения файлов для каждого типа БЭМ класса (блока, элемента и их модификаторов)
8+
* Настройка разделителей для модификаторов и элементов
9+
10+
## Использование
11+
<pre>
12+
user:~/project$ b_add logo__img_size_big container container__sidebar
13+
</pre>
14+
<pre>
15+
user:~/project$ tree
16+
17+
├── app
18+
│   └── blocks
19+
│   ├── container
20+
│   │   ├── __sidebar
21+
│   │   │   ├── container__sidebar.jade
22+
│   │   │   └── container__sidebar.styl
23+
│   │   ├── container.jade
24+
│   │   ├── container.styl
25+
│   │   └── container.wiki
26+
│   └── logo
27+
│   ├── __img
28+
│   │   ├── logo__img.jade
29+
│   │   ├── logo__img.styl
30+
│   │   └── logo__img_size_big.styl
31+
│   ├── logo.jade
32+
│   ├── logo.styl
33+
│   └── logo.wiki
34+
</pre>
35+
36+
## Установка
37+
<pre>
38+
root:~$ npm install -g b_add
39+
</pre>
40+
41+
## Настройка
42+
Все параметры доступны в файле b_add.json
43+
44+
**blockLocation**
45+
Путь к папке с блоками
46+
47+
**elem**
48+
Разделитель для элемента
49+
50+
**mod**
51+
Разделитель для модификатора
52+
53+
**files**
54+
Настройки расширений для файлов
55+
56+
* **block**
57+
Массив расширений файлов блока
58+
* **blockMod**
59+
Массив расширений файлов модификатора блока
60+
* **elem**
61+
Массив расширений файлов элемента
62+
* **elemMod**
63+
Массив расширений файлов модификатора элемента
64+
65+
<pre>
66+
{
67+
"blockLocation": "./app/blocks/",
68+
"elem": "__",
69+
"mod": "_",
70+
"files": {
71+
"block": [".styl", ".jade", ".wiki"],
72+
"blockMod": [".styl"],
73+
"elem": [".styl", ".jade"],
74+
"elemMod": [".styl"]
75+
}
76+
}
77+
</pre>
78+
79+
## Лицезия
80+
Проект распространяется на условиях лицензии MIT.
81+
Подробнее см. файл LICENSE
82+
83+
## Используемые модули
84+
* [bem-naming](https://github.com/bem/bem-naming)
85+
* [create-file](https://github.com/joakimbeng/create-file)
86+
* [jsonfile](https://github.com/jprichardson/node-jsonfile)
87+
88+
!["Yandex.Metrika counter"](https://mc.yandex.ru/watch/32839275)

b_add.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"blockLocation": "./app/blocks/",
3+
"elem": "__",
4+
"mod": "_",
5+
"files": {
6+
"block": [".styl", ".jade", ".wiki"],
7+
"blockMod": [".styl"],
8+
"elem": [".styl", ".jade"],
9+
"elemMod": [".styl"]
10+
}
11+
}

bin/b_add

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
require('../lib/main.js');

lib/main.js

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
var bemNaming = require('bem-naming');
2+
var wrfile = require('create-file');
3+
var jsonf = require('jsonfile');
4+
5+
var args = process.argv.slice(2);
6+
var config = readConfig();
7+
8+
var naming = bemNaming({
9+
elem: config.elem,
10+
mod: config.mod
11+
});
12+
13+
//Создание файлов по настройкам расширений
14+
function createFiles(path, type) {
15+
config.files[type].forEach( function(item) {
16+
wrfile(path + item, '', function(err){
17+
if(err){
18+
process.stderr.write('Ошибка создания файла: \n' + err.message + '\n');
19+
process.exit(1);
20+
}
21+
})
22+
})
23+
24+
}
25+
26+
//Проверка введеного аргумента на валидность БЭМ нейминга
27+
//Определение типа введеного аргумента
28+
//Вызов соответсвующей функции
29+
function validateArg(arg) {
30+
var input = naming.parse(arg);
31+
32+
switch (true) {
33+
case naming.isBlock(input):
34+
mkBlock(input);
35+
break;
36+
37+
case naming.isElem(input):
38+
mkElem(input);
39+
break;
40+
41+
case naming.isBlockMod(input):
42+
mkBlockMod(input);
43+
break;
44+
45+
case naming.isElemMod(input):
46+
mkElemMod(input);
47+
break;
48+
49+
default:
50+
process.stderr.write('Аргумент "'+ arg + '" не является БЭМ классом \n')
51+
process.exit(1);
52+
}
53+
54+
55+
}
56+
//Создание блока
57+
function mkBlock(input){
58+
var path = config.blockLocation + input.block + '/'
59+
+ input.block;
60+
61+
createFiles(path, 'block');
62+
}
63+
64+
//Создание элемента блока
65+
function mkElem(input){
66+
var path = config.blockLocation + input.block + '/'
67+
+ config.elem + input.elem +'/'
68+
+ input.block + config.elem + input.elem ;
69+
70+
createFiles(path , 'elem');
71+
mkBlock(input);
72+
}
73+
74+
//Создание модификатора блока
75+
function mkBlockMod(input){
76+
var modVal = '_'+ input.modVal;
77+
78+
if (input.modVal === true) var modVal = '';
79+
80+
var path = config.blockLocation + input.block + '/'
81+
+ input.block + config.mod + input.modName + modVal;
82+
83+
createFiles(path, 'blockMod');
84+
mkBlock(input);
85+
}
86+
87+
//Создание модификатора элемента
88+
function mkElemMod(input){
89+
var modVal = '_'+ input.modVal;
90+
91+
if (input.modVal === true ) var modVal = '';
92+
93+
var path = config.blockLocation +input.block + '/'
94+
+ config.elem + input.elem + '/'
95+
+ input.block + config.elem + input.elem + config.mod + input.modName + modVal;
96+
97+
createFiles(path, 'elemMod');
98+
mkElem(input);
99+
}
100+
101+
//Чтение файла настроек b_add.json
102+
function readConfig() {
103+
try {
104+
return jsonf.readFileSync('b_add.json');
105+
} catch (err) {
106+
process.stderr.write('Ошибка чтения конфигурационного файла b_add.json: \n' + err.message + '\n');
107+
process.exit(1);
108+
}
109+
};
110+
111+
//Запуск скрипта
112+
(function main(){
113+
if(!args[0]) {
114+
process.stderr.write('Отсутвуют аргументы. Используйте валидный БЭМ класс \n');
115+
process.exit(1);
116+
}
117+
args.forEach(function(item){
118+
validateArg(item);
119+
});
120+
}).call(this);

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "b_add",
3+
"version": "0.0.1",
4+
"description": "A small utility helps you to easily add BEM blocks in the file system of your project",
5+
"main": "lib/main.js",
6+
"dependencies": {
7+
"bem-naming": "^0.5.1",
8+
"create-file": "^1.0.1",
9+
"jsonfile": "^2.2.2"
10+
},
11+
"devDependencies": {},
12+
"scripts": {
13+
"test": "echo \"May be in future...\" && exit 0"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/c01nd01r/b_add"
18+
},
19+
"keywords": [
20+
"bem",
21+
"block",
22+
"b_add",
23+
"cli"
24+
],
25+
"author": {
26+
"name": "c01nd01r",
27+
"email": "c01nd01r@users.noreply.github.com"
28+
},
29+
"license": "MIT",
30+
"bugs": {
31+
"url": "https://github.com/c01nd01r/b_add/issues"
32+
},
33+
"preferGlobal": "true",
34+
"bin": {
35+
"b_add": "./bin/b_add"
36+
},
37+
"homepage": "https://github.com/c01nd01r/b_add",
38+
"engines": {
39+
"node": ">0.12.0"
40+
}
41+
}

0 commit comments

Comments
 (0)