Skip to content

Commit

Permalink
refactoring; refining template.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Oct 29, 2016
1 parent a1f32ae commit 930790a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
29 changes: 7 additions & 22 deletions src/cli/cms/templates/template.js
Expand Up @@ -8,28 +8,13 @@ import {
abeExtend
} from '../../'

export function findTemplateAndPartialsInFolder (currentPath) {
var res = []
var files = fse.readdirSync(currentPath)
for (var i in files) {
var currentFile = currentPath + '/' + files[i]
var stats = fse.statSync(currentFile)
if (stats.isFile()) {
if (currentFile.indexOf('.' + config.files.templates.extension) > -1) {
res.push(currentFile)
}
}
else if (stats.isDirectory()) {
res = res.concat(findTemplateAndPartialsInFolder(currentFile))
}
}
return res
}

export function getTemplateAndPartials(templatesPath) {
export function getTemplatesAndPartials(templatesPath) {
var p = new Promise((resolve) => {
let templatesList = findTemplateAndPartialsInFolder(templatesPath)
resolve(templatesList)
const extension = '.' + config.files.templates.extension
return coreUtils.file.getFilesAsync(templatesPath, true, extension)
.then(function(files){
return resolve(files)
})
})

return p
Expand Down Expand Up @@ -258,7 +243,7 @@ export function findRequestColumns(templatesList) {

export function getSelectTemplateKeys(templatesPath) {
var p = new Promise((resolve, reject) => {
return getTemplateAndPartials(templatesPath)
return getTemplatesAndPartials(templatesPath)
.then((templatesList) => {
return findRequestColumns(templatesList)
.then((whereKeys) => {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/core/utils/file.js
Expand Up @@ -136,7 +136,7 @@ export function getFilesAsync(dirname, recursive = true, filterExt = '') {
return
}
if (recursive) {
return coreUtils.file.getFiles(pathFile, recursive, filterExt).then(function(filesInDir) {
return coreUtils.file.getFilesAsync(pathFile, recursive, filterExt).then(function(filesInDir) {
items = items.concat(filesInDir)
})
}
Expand Down

0 comments on commit 930790a

Please sign in to comment.