Skip to content

Commit

Permalink
feat(release): generate the website
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierBoubert committed Oct 20, 2014
1 parent 874dd98 commit c379ee8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 48 deletions.
116 changes: 69 additions & 47 deletions features/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = function release(config, callback) {
MEMORYOVERFLOW_PATH: '',
WEBSITE_REPO: '',
WEBSITE_PATH: '',
THEMACHINE_PATH: '',
COMMIT_LABEL: '',
commitID: '',
commitUrl: ''
Expand All @@ -54,6 +55,7 @@ module.exports = function release(config, callback) {

config.MEMORYOVERFLOW_PATH = WORK_PATH + '/' + config.MEMORYOVERFLOW_PATH;
config.WEBSITE_PATH = WORK_PATH + '/' + config.WEBSITE_PATH;
config.THEMACHINE_PATH = config.MEMORYOVERFLOW_PATH + '/' + config.THEMACHINE_PATH;

console.log('\ngit clone ' + config.MEMORYOVERFLOW_REPO + ' ' + config.MEMORYOVERFLOW_PATH + '...');

Expand All @@ -62,98 +64,118 @@ module.exports = function release(config, callback) {
return _error(error, callback);
}

console.log('\ngit clone ' + config.WEBSITE_REPO + ' ' + config.WEBSITE_PATH + '...');
console.log('\ninstall The Machine...');

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

console.log('\ncopy ' + config.MEMORYOVERFLOW_PATH + '/website' + ' ' + config.WEBSITE_PATH + '...');
console.log('\nexecute The Machine...');

fs.copySync(config.WEBSITE_PATH + '/README.md', config.WEBSITE_PATH + '/README.tmp');

fs.copySync(config.MEMORYOVERFLOW_PATH + '/website', config.WEBSITE_PATH);

fs.move(config.WEBSITE_PATH + '/README.tmp', config.WEBSITE_PATH + '/README.md', {
clobber: true
cmd.exec('npm run-script generate', {
cwd: config.THEMACHINE_PATH
}, function(error) {
if(error) {
return _error(error, callback);
}

console.log('\ngit config user.name "' + config.USER_AGENT + '"');
console.log('\ngit clone ' + config.WEBSITE_REPO + ' ' + config.WEBSITE_PATH + '...');

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

console.log('\ngit config user.email "' + config.USER_AGENT_EMAIL + '"');
console.log('\ncopy ' + config.MEMORYOVERFLOW_PATH + '/website' + ' ' + config.WEBSITE_PATH + '...');

fs.copySync(config.WEBSITE_PATH + '/README.md', config.WEBSITE_PATH + '/README.tmp');

cmd.exec('git config user.email "' + config.USER_AGENT_EMAIL + '"', {
cwd: config.WEBSITE_PATH
fs.copySync(config.MEMORYOVERFLOW_PATH + '/website', config.WEBSITE_PATH);

fs.move(config.WEBSITE_PATH + '/README.tmp', config.WEBSITE_PATH + '/README.md', {
clobber: true
}, function(error) {
if(error) {
return _error(error, callback);
}

console.log('\ngit add -A');
console.log('\ngit config user.name "' + config.USER_AGENT + '"');

cmd.exec('git add -A', {
cmd.exec('git config user.name "' + config.USER_AGENT + '"', {
cwd: config.WEBSITE_PATH
}, function(error, stdout) {
}, function(error) {
if(error) {
return _error(error, callback);
}

cmd.exec('git status', {
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, stdout) {
}, function(error) {
if(error) {
return _error(error, callback);
}

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

var commitAuthor = ' --author="' + config.USER_AGENT + ' <' + config.USER_AGENT_EMAIL + '>"',
commitLabel = config.COMMIT_LABEL
.replace('{commitID}', config.commitID)
.replace('{commitUrl}', config.commitUrl)
.split('\n')
.map(function(line) {
return ' -m "' + line + '"';
})
.join('');
console.log('\ngit add -A');

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

cmd.exec('git commit' + commitAuthor + commitLabel, {
cmd.exec('git add -A', {
cwd: config.WEBSITE_PATH
}, function(error) {
}, function(error, stdout) {
if(error) {
return _error(error, callback);
}

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

console.log('\ngit push ' + pushRepo + ' gh-pages');

cmd.exec('git push ' + pushRepo + ' gh-pages', {
cmd.exec('git status', {
cwd: config.WEBSITE_PATH
}, function(error) {
}, function(error, stdout) {
if(error) {
return _error(error, callback);
}

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

var commitAuthor = ' --author="' + config.USER_AGENT + ' <' + config.USER_AGENT_EMAIL + '>"',
commitLabel = config.COMMIT_LABEL
.replace('{commitID}', config.commitID)
.replace('{commitUrl}', config.commitUrl)
.split('\n')
.map(function(line) {
return ' -m "' + line + '"';
})
.join('');

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

cmd.exec('git commit' + commitAuthor + commitLabel, {
cwd: config.WEBSITE_PATH
}, function(error) {
if(error) {
return _error(error, callback);
}

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

console.log('\ngit push ' + pushRepo + ' gh-pages');

cmd.exec('git push ' + pushRepo + ' gh-pages', {
cwd: config.WEBSITE_PATH
}, function(error) {
if(error) {
return _error(error, callback);
}

return _success(callback);

});
});
});
});
});
Expand Down
4 changes: 3 additions & 1 deletion publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
MEMORYOVERFLOW_PATH = 'memoryoverflow',
WEBSITE_REPO = 'https://github.com/CodeCorico/MemoryOverflow-website.git',
WEBSITE_PATH = 'website',
THEMACHINE_PATH = 'the-machine',
COMMIT_LABEL = 'release: master-{commitID}\n\nMemoryOverflow commit origin: {commitUrl}';

new Server(SERVER_PORT, function(request, response, body) {
Expand Down Expand Up @@ -49,6 +50,7 @@
SECRET: SECRET,
MEMORYOVERFLOW_REPO: MEMORYOVERFLOW_REPO,
MEMORYOVERFLOW_PATH: MEMORYOVERFLOW_PATH,
THEMACHINE_PATH: THEMACHINE_PATH,
WEBSITE_REPO: WEBSITE_REPO,
WEBSITE_PATH: WEBSITE_PATH,
COMMIT_LABEL: COMMIT_LABEL,
Expand All @@ -63,4 +65,4 @@
response.ok();
});

})();
})();

0 comments on commit c379ee8

Please sign in to comment.