Skip to content

Commit

Permalink
fix(website release): better console logging
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierBoubert committed Nov 1, 2017
1 parent 39698ba commit a0a2d46
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions features/website-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ var extend = require('extend'),

function _cleanWorkspace() {
if(fs.existsSync(WORK_PATH)) {
console.log('remove path ' + WORK_PATH);
console.log(_date() + 'Cleaning workspace...');
fs.removeSync(WORK_PATH);
}
}

function _error(error, callback) {
console.error('\n\nERROR!\n');
console.error(_date() + 'ERROR!');
console.error(error);
console.error('\n\n');

_cleanWorkspace();

Expand All @@ -32,7 +31,7 @@ function _error(error, callback) {
function _success(callback) {
_cleanWorkspace();

console.log('\n\nALL IS DONE!\n\n');
console.log(_date() + 'Website released');

if(callback) {
callback(true);
Expand All @@ -41,6 +40,19 @@ function _success(callback) {
return true;
}

function _date() {
const date = new Date();
let hours = date.getHours();
let minutes = date.getMinutes();
let seconds = date.getSeconds();

hours = hours > 9 ? hours : `0${hours}`;
minutes = minutes > 9 ? minutes : `0${minutes}`;
seconds = seconds > 9 ? seconds : `0${seconds}`;

return `[${hours}:${minutes}:${seconds}] `;
}

module.exports = function websiteRelease(config, callback) {
config = extend(true, {
USER_AGENT: '',
Expand All @@ -63,14 +75,14 @@ module.exports = function websiteRelease(config, callback) {
config.THEMACHINE_PATH = config.MEMORYOVERFLOW_PATH + '/' + config.THEMACHINE_PATH;
config.WEBSITE_ABSOLUTE_PATH = path.join(__dirname, '..', config.WEBSITE_PATH);

console.log('\ngit clone --depth 1 ' + config.MEMORYOVERFLOW_REPO + ' ' + config.MEMORYOVERFLOW_PATH + '...');
console.log(_date() + 'Cloning The Machine...');

cmd.exec('git clone --depth 1 ' + config.MEMORYOVERFLOW_REPO + ' ' + config.MEMORYOVERFLOW_PATH, function(error) {
if(error) {
return _error(error, callback);
}

console.log('\ninstall The Machine...');
console.log(_date() + 'Installing The Machine...');

cmd.exec('npm install', {
cwd: config.THEMACHINE_PATH
Expand All @@ -79,18 +91,16 @@ module.exports = function websiteRelease(config, callback) {
return _error(error, callback);
}

console.log('\nCreate the .env...');

fs.writeFileSync(config.THEMACHINE_PATH + '/.env', 'WEBSITE_TARGET=' + config.WEBSITE_ABSOLUTE_PATH);

console.log('\ngit clone ' + config.WEBSITE_REPO + ' ' + config.WEBSITE_PATH + '...');
console.log(_date() + 'Cloning the website...');

cmd.exec('git clone ' + config.WEBSITE_REPO + ' ' + config.WEBSITE_PATH, function(error) {
if(error) {
return _error(error, callback);
}

console.log('\nexecute The Machine...');
console.log(_date() + 'Starting The Machine...');

cmd.exec('npm run generate', {
cwd: config.THEMACHINE_PATH
Expand All @@ -99,7 +109,7 @@ module.exports = function websiteRelease(config, callback) {
return _error(error, callback);
}

console.log('\ngit config user.name "' + config.USER_AGENT + '"');
console.log(_date() + 'Pushing the new website release...')

cmd.exec('git config user.name "' + config.USER_AGENT + '"', {
cwd: config.WEBSITE_PATH
Expand All @@ -108,17 +118,13 @@ module.exports = function websiteRelease(config, callback) {
return _error(error, callback);
}

console.log('\ngit config user.email "' + config.USER_AGENT_EMAIL + '"');

cmd.exec('git config user.email "' + config.USER_AGENT_EMAIL + '"', {
cwd: config.WEBSITE_PATH
}, function(error) {
if(error) {
return _error(error, callback);
}

console.log('\ngit add -A');

cmd.exec('git add -A', {
cwd: config.WEBSITE_PATH
}, function(error, stdout) {
Expand All @@ -135,7 +141,7 @@ module.exports = function websiteRelease(config, callback) {

var status = stdout.split('\n');
if(status.length && status[1].trim() == 'nothing to commit, working directory clean') {
console.log('NOTHING TO COMMIT');
console.log(_date() + '[NOTHING TO COMMIT]');
return _success(callback);
}

Expand All @@ -149,8 +155,6 @@ module.exports = function websiteRelease(config, callback) {
})
.join('');

console.log('\ngit commit' + commitAuthor + commitLabel);

cmd.exec('git commit' + commitAuthor + commitLabel, {
cwd: config.WEBSITE_PATH
}, function(error) {
Expand All @@ -160,8 +164,6 @@ module.exports = function websiteRelease(config, callback) {

var pushRepo = config.WEBSITE_REPO.replace('https://', 'https://' + config.USER_AGENT + ':' + config.SECRET + '@');

console.log('\ngit push ' + pushRepo.replace(config.SECRET, 'SECRET') + ' gh-pages');

cmd.exec('git push ' + pushRepo + ' gh-pages', {
cwd: config.WEBSITE_PATH
}, function(error) {
Expand Down

0 comments on commit a0a2d46

Please sign in to comment.