Skip to content

Commit

Permalink
feature: add new process
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Oct 11, 2016
1 parent ea705bb commit caa2926
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
19 changes: 11 additions & 8 deletions src/cli/process/generate-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ var config = require('../../cli').config
var dateStart
var templatesTexts = {}

function publishNext(published, tt, cb, i = 0) {
var pub = published.shift()
function publishNext(files, tt, cb, i = 0) {
var pub = files.shift()
if(typeof pub !== 'undefined' && pub !== null) {

var jsonObject = fse.readJsonSync(pub.path)
var jsonObject = fse.readJsonSync(pub[processConfig.ABE_STATUS].path)
i++
var p = new Promise((resolve) => {
if(typeof templatesTexts[jsonObject.abe_meta.template] === 'undefined' || templatesTexts[jsonObject.abe_meta.template] === null) {
Expand Down Expand Up @@ -48,20 +48,20 @@ function publishNext(published, tt, cb, i = 0) {

obj = abeExtend.hooks.instance.trigger('afterSave', obj)

trace('('+ getTime() + ') ' + i + ' - ' + pub.path.replace(config.root, '').replace(config.data.url, '') + ' (tpl: ' + jsonObject.abe_meta.template + ')')
trace('('+ getTime() + ') ' + i + ' - ' + pub[processConfig.ABE_STATUS].path.replace(config.root, '').replace(config.data.url, '') + ' (tpl: ' + jsonObject.abe_meta.template + ')')
resolve()
},
() => {
error('publish-all ERROR on ' + pub.path.replace(config.root, '').replace(config.data.url, ''))
error('publish-all ERROR on ' + pub[processConfig.ABE_STATUS].path.replace(config.root, '').replace(config.data.url, ''))
resolve()
})
})

p.then(function () {
publishNext(published, tt, cb, i++)
publishNext(files, tt, cb, i++)
})
.catch(function (e) {
publishNext(published, tt, cb, i++)
publishNext(files, tt, cb, i++)
error('error', e)
})
}else {
Expand All @@ -72,7 +72,9 @@ function publishNext(published, tt, cb, i = 0) {
function startProcess() {
log('start publish all at path ' + processConfig.ABE_PATH);
log('searching for file at ' + config.root);
var files = Manager.instance.getListWithStatusOnFolder('publish', processConfig.ABE_PATH)
log('seach status: ' + processConfig.ABE_STATUS);
log('save to: ' + path.join(config.root, processConfig.ABE_DESTINATION));
var files = Manager.instance.getListWithStatusOnFolder(processConfig.ABE_STATUS, processConfig.ABE_PATH)

log('Found ' + files.length + ' to republish')

Expand All @@ -85,6 +87,7 @@ function startProcess() {

init('generate-posts',
{
ABE_STATUS: 'publish',
ABE_PATH: '',
ABE_DESTINATION: 'site'
})
Expand Down
11 changes: 3 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,19 @@ if(typeof userArgs[0] !== 'undefined' && userArgs[0] !== null){
}
process.env.DEBUG = 'generate-posts:*'
var generateArgs = ['--harmony', __dirname + '/cli/process/generate-posts.js', 'ABE_WEBSITE=' + dir]
var isHelp = false
Array.prototype.forEach.call(userArgs, (arg) => {
if (arg.indexOf('--path=') > -1) {
generateArgs.push('ABE_PATH=' + arg.split('=')[1])
}else if (arg.indexOf('--destination=') > -1) {
generateArgs.push('ABE_DESTINATION=' + arg.split('=')[1])
}else if (arg.indexOf('--status=') > -1) {
generateArgs.push('ABE_STATUS=' + arg.split('=')[1])
}
})

const generate = spawn('node', generateArgs, { shell: true, stdio: 'inherit' })

// generate.stdout.on('data', (data) => {
// console.log(data.toString().replace(/\n/, ''))
// })

// generate.stderr.on('data', (data) => {
// console.log(data.toString().replace(/\n/, ''))
// })

generate.on('close', (code) => {
console.log(clc.cyan('child process exited with code') + ' ' + code)
process.exit(0)
Expand Down

0 comments on commit caa2926

Please sign in to comment.