Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
K
kpp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexandr Veselov
kpp
Commits
17eb35d2
Commit
17eb35d2
authored
Feb 25, 2016
by
Nikolay Gromov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
создание блоков автоматом
parent
bd44bce7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
22 deletions
+47
-22
README.md
README.md
+12
-1
createBlock.js
createBlock.js
+35
-21
No files found.
README.md
View file @
17eb35d2
...
...
@@ -34,6 +34,17 @@ block-name/ # Папка блока
readme.md
# Какое-то пояснение
```
### Удобное создание нового блока
```bash
node createBlock.js [имя блока] [доп. расширения через пробел]
```
По умолчанию будут созданы
`.html`
и
`.less`
файлы, в них будет записан стартовый контент.
Если блок уже существует, файлы не будут затёрты, но создадутся те файлы, которые ещё не существуют.
## Подключение блоков
...
...
createBlock.js
View file @
17eb35d2
'use strict'
;
// Использование: node createBlock.js [имя блока] [доп. расширения через пробел]
const
fs
=
require
(
'fs'
);
const
pjson
=
require
(
'./package.json'
);
const
dirs
=
pjson
.
config
.
directories
;
const
mkdirp
=
require
(
'mkdirp'
);
// Использование: run node createBlock.js [BLOCK_NAME] [additional extensions]
let
blockName
=
process
.
argv
[
2
];
let
defaultExtensions
=
[
'html'
,
'less'
];
let
defaultExtensions
=
[
'html'
,
'less'
];
// расширения по умолчанию
let
extensions
=
uniqueArray
(
defaultExtensions
.
concat
(
process
.
argv
.
slice
(
3
)));
if
(
blockName
)
{
if
(
blockName
)
{
let
dirPath
=
dirs
.
blocks
+
'/'
+
blockName
+
'/'
;
if
(
!
fileExist
(
dirPath
))
{
mkdirp
(
dirPath
,
function
(
err
){
if
(
err
)
{
console
.
error
(
'---------- Отмена операции: '
+
err
);
}
else
{
console
.
log
(
'---------- Отмена операции: блок '
+
dirPath
+
' уже существует'
);
}
// console.log(fileExist(dirPath));
// mkdirp(dirPath, function(err){
// if (err) {
// console.error(err);
// }
// else {
// extensions.forEach(function(extention){
// fs.closeSync(fs.openSync(path.join(dirPath, blockName + '.' + extention), 'w'));
// });
// }
// })
extensions
.
forEach
(
function
(
extention
){
let
filePath
=
dirPath
+
blockName
+
'.'
+
extention
;
let
fileContent
=
''
;
if
(
extention
==
'less'
)
{
fileContent
=
'.'
+
blockName
+
' {
\
n
\
n}
\
n'
;
}
else
if
(
extention
==
'html'
)
{
fileContent
=
'<div class="'
+
blockName
+
'">content</div>
\
n'
;
}
if
(
fileExist
(
filePath
)
===
false
)
{
fs
.
writeFile
(
filePath
,
fileContent
,
function
(
err
)
{
if
(
err
)
{
return
console
.
log
(
'---------- Файл не создан: '
+
err
);
}
console
.
log
(
'---------- Файл создан: '
+
filePath
);
});
}
else
{
console
.
log
(
'---------- Файл не создан: '
+
filePath
+
' уже существует'
);
}
});
}
});
}
else
{
console
.
log
(
'---------- Отмена операции: не указан блок'
);
}
// Оставить в массиве только уникальные значения (убрать повторы)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment