Skip to content

Commit

Permalink
refactoring: moving cms data function into cms/data
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Oct 2, 2016
1 parent 3b3ae10 commit 61dd3fd
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
getAttr
} from '../../cli'
} from '../../'

function recurseDeleteKey(currentLevel, arrayKeyAttr) {
var currentArray = arrayKeyAttr.slice(0)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/helpers/abe-sql.js → src/cli/cms/data/abe-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Manager,
FileParser,
getAttr
} from '../'
} from '../../'

export default class Sql {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
,dateUnslug
,config
,Manager
} from '../'
} from '../../'

var fullAttr = '-abe-(.+?)(?=\.'
var captureAttr = '-abe-(.+?)(?=\.'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {cli} from '../'

export function getAttr (str, attr) {
var rex = new RegExp(attr + '=["|\']([\\S\\s]*?)["|\']( +[a-zA-Z0-9-]*?=|}})')
Expand Down
38 changes: 38 additions & 0 deletions src/cli/cms/data/update-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import path from 'path'
import {
config
,FileParser
,fileUtils
,folderUtils
,save
,Hooks
} from '../../'

var pConfig = {}
Array.prototype.forEach.call(process.argv, (item) => {
if (item.indexOf('=') > -1) {
var ar = item.split('=')
pConfig[ar[0]] = ar[1]
}
})

if(typeof pConfig.ABE_WEBSITE !== 'undefined' && pConfig.ABE_WEBSITE !== null) {
if(pConfig.ABE_WEBSITE) config.set({root: pConfig.ABE_WEBSITE.replace(/\/$/, '') + '/'})

var allJson

pConfig.FILEPATH = path.join(config.root, config.data.url, pConfig.FILEPATH ? pConfig.FILEPATH.replace(config.root) : '')

if(pConfig.FILETYPE) {
allJson = FileParser.getFilesByType(pConfig.FILEPATH, pConfig.FILETYPE)
}
else {
allJson = FileParser.getFiles(pConfig.FILEPATH, true, 20, /\.json/)
}

var allJson = Hooks.instance.trigger('beforeUpdateJson', allJson)

}else {
console.log('ABE_WEBSITE is not defined use node process.js ABE_WEBSITE=/pat/to/website')
process.exit(0)
}
10 changes: 6 additions & 4 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import moment from 'moment'
import fse from 'fs-extra'
import clc from 'cli-color'

import fileAttr from './helpers/file-attr'
import fileAttr from './cms/data/file-attr'
import Util from './core/utils/abe-utils'
import handlebarsHelperSlugify from 'handlebars-helper-slugify'

Expand Down Expand Up @@ -31,7 +31,6 @@ import {
import Manager from './core/manager/Manager'
import Page from './models/Page'
import Handlebars from 'handlebars'
import {getAttr, getEnclosingTags, escapeTextToRegex} from './helpers/regex-helper'

import {dateSlug, dateUnslug} from './core/utils/abe-date'
import Locales from './core/utils/abe-locales'
Expand All @@ -45,10 +44,13 @@ import {getTemplate} from './helpers/abe-template'
import Create from './Create'

import config from './core/config/config'
import removeDuplicateAttr from './helpers/abe-remove-duplicate-attr'

import {getAttr, getEnclosingTags, escapeTextToRegex} from './cms/data/regex-helper'
import removeDuplicateAttr from './cms/data/abe-remove-duplicate-attr'

import abeCreate from './helpers/abe-create'
import abeDuplicate from './helpers/abe-duplicate'
import Sql from './helpers/abe-sql'
import Sql from './cms/data/abe-sql'

import {save, checkRequired, saveJson} from './controllers/Save'
import abeProcess from './extend/abe-process'
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ if(typeof userArgs[0] !== 'undefined' && userArgs[0] !== null){
dir = process.env.ROOT.replace(/\/$/, '')
}

const updateJson = spawn('node', ['--harmony', __dirname + '/cli/process/update-json.js', 'ABE_WEBSITE=' + dir])
const updateJson = spawn('node', ['--harmony', __dirname + '/cli/cms/data/update-json.js', 'ABE_WEBSITE=' + dir])

updateJson.stdout.on('data', (data) => {
console.log(clc.cyan('stdout'), data.toString())
Expand Down
2 changes: 1 addition & 1 deletion test/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ config.set({root: __dirname + '/fixtures'})

var Manager = require('../src/cli').Manager;
var Plugins = require('../src/cli').Plugins;
var abeProcess = require('../src/cli').default
var abeProcess = require('../src/cli').abeProcess;

describe('Process', function() {
before( function(done) {
Expand Down

0 comments on commit 61dd3fd

Please sign in to comment.