Skip to content

Commit

Permalink
change publish all (wait each publish not the end to publish all)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Sep 15, 2016
1 parent c5b9d30 commit 3a8a022
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 109 deletions.
109 changes: 62 additions & 47 deletions dist/cli/process/publish-all.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
'use strict';

var _cliColor = require('cli-color');

var _cliColor2 = _interopRequireDefault(_cliColor);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// ./node_modules/.bin/babel-node src/cli/process/publish-all.js ABE_WEBSITE=/path/to/website
// ./node_modules/.bin/babel-node src/cli/process/publish-all.js FILEPATH=/path/to/website/path/to/file.html ABE_WEBSITE=/path/to/website
var pConfig = {};
Expand All @@ -16,6 +22,50 @@ if (typeof pConfig.ABE_PATH === 'undefined' || pConfig.ABE_PATH === null) {
pConfig.ABE_PATH = '';
}

console.log(_cliColor2.default.green('start publish all') + ' path ' + pConfig.ABE_PATH);

function publishNext(published, cb) {
var i = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];

var currentDateStart = new Date();
var pub = published.shift();
if (typeof pub !== 'undefined' && pub !== null) {

var jsonPath = FileParser.changePathEnv(pub.path, config.data.url).replace(new RegExp("\\." + config.files.templates.extension), '.json');
var json = FileParser.getJson(jsonPath);
if (typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
i++;
ar_url.push(pub.path);

var p = new Promise(function (resolve, reject) {
save(pub.path, json.abe_meta.template, null, '', pConfig.TYPE, null, pConfig.TYPE, true).then(function () {
var d = (new Date().getTime() - currentDateStart.getTime()) / 1000;
var total = Math.round((new Date().getTime() - dateStart.getTime()) / 1000 / 60 * 100) / 100;
// logsPub += i + ' [' + d + 'sec] > start publishing ' + pub.path .replace(config.root, '') + ' < ' + jsonPath
console.log(i + ' - (' + _cliColor2.default.green(d + 's') + ' / ' + total + 'm)');
console.log(_cliColor2.default.bgWhite(_cliColor2.default.black(pub.path.replace(config.root, ''))) + ' < ' + _cliColor2.default.bgWhite(_cliColor2.default.black(jsonPath.replace(config.root, ''))) + ' (' + _cliColor2.default.cyan(json.abe_meta.template) + ')');
resolve();
}).catch(function (e) {
// log.write('publish-all', e)
console.log('publish-all', e);
// log.write('publish-all', 'ERROR on ' + pub.path .replace(config.root, ''))
console.log('publish-all', 'ERROR on ' + pub.path.replace(config.root, ''));
resolve();
});
});
}

p.then(function () {
publishNext(published, cb, i++);
}).catch(function () {
console.log('error', _cliColor2.default.red(e));
});
} else {
cb(i);
}
}

var dateStart = new Date();
// var logsPub = ""
if (typeof pConfig.ABE_WEBSITE !== 'undefined' && pConfig.ABE_WEBSITE !== null) {
var config = require('../../cli').config;
Expand All @@ -33,12 +83,6 @@ if (typeof pConfig.ABE_WEBSITE !== 'undefined' && pConfig.ABE_WEBSITE !== null)

Manager.instance;

// log.write('publish-all', '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
console.log('publish-all', '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *');
// log.write('publish-all', 'start process publish')
console.log('publish-all', 'start process publish');
var dateStart = new Date();

var type = null;
var folder = null;
if (typeof pConfig.FILEPATH !== 'undefined' && pConfig.FILEPATH !== null) {
Expand Down Expand Up @@ -66,52 +110,23 @@ if (typeof pConfig.ABE_WEBSITE !== 'undefined' && pConfig.ABE_WEBSITE !== null)
var promises = [];
var i = 0;

published.forEach(function (pub) {
var jsonPath = FileParser.changePathEnv(pub.path, config.data.url).replace(new RegExp("\\." + config.files.templates.extension), '.json');
var json = FileParser.getJson(jsonPath);
if (typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
i++;
ar_url.push(pub.path);

// save(url, tplPath, json = null, text = '', type = '', previousSave = null, realType = 'draft', publishAll = false)

var p = new Promise(function (resolve, reject) {
var d = (new Date().getTime() - dateStart.getTime()) / 1000;
// logsPub += i + ' [' + d + 'sec] > start publishing ' + pub.path .replace(config.root, '') + ' < ' + jsonPath
console.log(i + ' [' + d + 'sec] > start publishing ' + pub.path.replace(config.root, '') + ' < ' + jsonPath + ' (template: ' + json.abe_meta.template + ')');
// resolve()
// return
console.log(pConfig);
save(pub.path, json.abe_meta.template, null, '', pConfig.TYPE, null, pConfig.TYPE, true).then(function () {
// logsPub += 'successfully update > ' + pub.path .replace(config.root, '')
// console.log('successfully update > ' + pub.path .replace(config.root, ''))
resolve();
}).catch(function (e) {
// log.write('publish-all', e)
console.log('publish-all', e);
// log.write('publish-all', 'ERROR on ' + pub.path .replace(config.root, ''))
console.log('publish-all', 'ERROR on ' + pub.path.replace(config.root, ''));
resolve();
});
});
promises.push(p);
}
});

// logsPub += 'total ' + promises.length + ' files'
console.log('total ' + promises.length + ' files');
dateStart = new Date();
publishNext(published, function (i) {
console.log('total ' + _cliColor2.default.green(i) + ' files');

Promise.all(promises).then(function () {
dateStart = (new Date().getTime() - dateStart.getTime()) / 1000;
// Promise.all(promises)
// .then(() => {
dateStart = Math.round((new Date().getTime() - dateStart.getTime()) / 1000 / 60 * 100) / 100;
// logsPub += 'publish process finished in ' + dateStart + 'sec'
console.log('publish process finished in ' + dateStart + 'sec');
console.log('publish process finished in ' + _cliColor2.default.green(dateStart) + 'm');
// log.write('publish-all', logsPub)
// console.log('publish-all', logsPub)
process.exit(0);
}).catch(function (e) {
// log.write('publish-all', e)
console.log('publish-all', e);
console.log(e);
// }).catch(function(e) {
// // log.write('publish-all', e)
// console.log('publish-all', e)
// console.log(e)
// })
});
} catch (e) {
// statements
Expand Down
135 changes: 73 additions & 62 deletions src/cli/process/publish-all.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import clc from 'cli-color'

// ./node_modules/.bin/babel-node src/cli/process/publish-all.js ABE_WEBSITE=/path/to/website
// ./node_modules/.bin/babel-node src/cli/process/publish-all.js FILEPATH=/path/to/website/path/to/file.html ABE_WEBSITE=/path/to/website
var pConfig = {}
Expand All @@ -14,6 +16,60 @@ if(typeof pConfig.ABE_PATH === 'undefined' || pConfig.ABE_PATH === null) {
pConfig.ABE_PATH = ''
}

console.log(clc.green('start publish all') + ' path ' + pConfig.ABE_PATH)

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

var jsonPath = FileParser.changePathEnv(pub.path, config.data.url).replace(new RegExp("\\." + config.files.templates.extension), '.json')
var json = FileParser.getJson(jsonPath)
if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
i++
ar_url.push(pub.path)

var p = new Promise((resolve, reject) => {
save(
pub.path,
json.abe_meta.template,
null,
'',
pConfig.TYPE,
null,
pConfig.TYPE,
true)
.then(() => {
var d = (new Date().getTime() - currentDateStart.getTime()) / 1000
var total = (Math.round((new Date().getTime() - dateStart.getTime()) / 1000 / 60 * 100)) / 100
// logsPub += i + ' [' + d + 'sec] > start publishing ' + pub.path .replace(config.root, '') + ' < ' + jsonPath
console.log(i + ' - (' + clc.green(d + 's') + ' / ' + total + 'm)')
console.log(clc.bgWhite(clc.black(pub.path.replace(config.root, '')))
+ ' < ' + clc.bgWhite(clc.black(jsonPath.replace(config.root, '')))
+ ' (' + clc.cyan(json.abe_meta.template) + ')')
resolve()
}).catch(function(e) {
// log.write('publish-all', e)
console.log('publish-all', e)
// log.write('publish-all', 'ERROR on ' + pub.path .replace(config.root, ''))
console.log('publish-all', 'ERROR on ' + pub.path .replace(config.root, ''))
resolve()
})
})
}

p.then(function () {
publishNext(published, cb, i++)
})
.catch(function () {
console.log('error', clc.red(e))
})
}else {
cb(i)
}
}

var dateStart = new Date()
// var logsPub = ""
if(typeof pConfig.ABE_WEBSITE !== 'undefined' && pConfig.ABE_WEBSITE !== null) {
var config = require('../../cli').config
Expand All @@ -31,12 +87,6 @@ if(typeof pConfig.ABE_WEBSITE !== 'undefined' && pConfig.ABE_WEBSITE !== null) {

Manager.instance;

// log.write('publish-all', '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
console.log('publish-all', '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
// log.write('publish-all', 'start process publish')
console.log('publish-all', 'start process publish')
var dateStart = new Date()

var type = null
var folder = null
if(typeof pConfig.FILEPATH !== 'undefined' && pConfig.FILEPATH !== null) {
Expand Down Expand Up @@ -66,63 +116,24 @@ if(typeof pConfig.ABE_WEBSITE !== 'undefined' && pConfig.ABE_WEBSITE !== null) {
var promises = []
var i = 0

published.forEach(function (pub) {
var jsonPath = FileParser.changePathEnv(pub.path, config.data.url).replace(new RegExp("\\." + config.files.templates.extension), '.json')
var json = FileParser.getJson(jsonPath)
if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
i++
ar_url.push(pub.path)

// save(url, tplPath, json = null, text = '', type = '', previousSave = null, realType = 'draft', publishAll = false)

var p = new Promise((resolve, reject) => {
var d = (new Date().getTime() - dateStart.getTime()) / 1000
// logsPub += i + ' [' + d + 'sec] > start publishing ' + pub.path .replace(config.root, '') + ' < ' + jsonPath
console.log(i + ' [' + d + 'sec] > start publishing ' + pub.path .replace(config.root, '') + ' < ' + jsonPath + ' (template: ' + json.abe_meta.template + ')')
// resolve()
// return
console.log(pConfig)
save(
pub.path,
json.abe_meta.template,
null,
'',
pConfig.TYPE,
null,
pConfig.TYPE,
true)
.then(() => {
// logsPub += 'successfully update > ' + pub.path .replace(config.root, '')
// console.log('successfully update > ' + pub.path .replace(config.root, ''))
resolve()
}).catch(function(e) {
// log.write('publish-all', e)
console.log('publish-all', e)
// log.write('publish-all', 'ERROR on ' + pub.path .replace(config.root, ''))
console.log('publish-all', 'ERROR on ' + pub.path .replace(config.root, ''))
resolve()
})
})
promises.push(p)
}
dateStart = new Date()
publishNext(published, function (i) {
console.log('total ' + clc.green(i) + ' files')

// Promise.all(promises)
// .then(() => {
dateStart = (Math.round((new Date().getTime() - dateStart.getTime()) / 1000 / 60 * 100)) / 100
// logsPub += 'publish process finished in ' + dateStart + 'sec'
console.log('publish process finished in ' + clc.green(dateStart) + 'm')
// log.write('publish-all', logsPub)
// console.log('publish-all', logsPub)
process.exit(0)
// }).catch(function(e) {
// // log.write('publish-all', e)
// console.log('publish-all', e)
// console.log(e)
// })
})

// logsPub += 'total ' + promises.length + ' files'
console.log('total ' + promises.length + ' files')

Promise.all(promises)
.then(() => {
dateStart = (new Date().getTime() - dateStart.getTime()) / 1000
// logsPub += 'publish process finished in ' + dateStart + 'sec'
console.log('publish process finished in ' + dateStart + 'sec')
// log.write('publish-all', logsPub)
// console.log('publish-all', logsPub)
process.exit(0)
}).catch(function(e) {
// log.write('publish-all', e)
console.log('publish-all', e)
console.log(e)
})
} catch(e) {
// statements
console.log(e);
Expand Down

0 comments on commit 3a8a022

Please sign in to comment.