diff --git a/Jenkinsfile b/Jenkinsfile index 8ceddbb..d751e00 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -30,8 +30,15 @@ pipeline { } } + stage('Robot') { + when { expression { !GIT_BRANCH.endsWith('master') } } + steps { script { + sh 'echo "Disallow: /" >> public/robots.txt' + } } + } + stage('Publish Prod') { - when { expression { env.GIT_BRANCH ==~ /.*master/ } } + when { expression { GIT_BRANCH.endsWith('master') } } steps { script { sshagent(credentials: ['status-im-auto-ssh']) { sh 'npm run deploy' @@ -40,7 +47,7 @@ pipeline { } stage('Publish Devel') { - when { expression { env.GIT_BRANCH ==~ /.*develop/ } } + when { expression { !GIT_BRANCH.endsWith('master') } } steps { script { sshagent(credentials: ['jenkins-ssh']) { sh ''' diff --git a/_config.dev.yml b/_config.dev.yml index eb2162c..dc32528 100644 --- a/_config.dev.yml +++ b/_config.dev.yml @@ -30,4 +30,4 @@ highlight: disqus_shortname: hexojs twitter: ethstatus -github: staus-im +github: status-im diff --git a/_config.prod.yml b/_config.prod.yml index 91d64c1..de6cb4b 100644 --- a/_config.prod.yml +++ b/_config.prod.yml @@ -30,4 +30,4 @@ highlight: disqus_shortname: hexojs twitter: ethstatus -github: staus-im +github: status-im diff --git a/gulpfile.js b/gulpfile.js index 8cfefd1..153e910 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -14,14 +14,23 @@ var minify = require('gulp-minify'); let cleanCSS = require('gulp-clean-css'); var rename = require("gulp-rename"); +const gitBranch = require('./scripts/git-branch'); + // generate html with 'hexo generate' var hexo = new Hexo(process.cwd(), {}); +const getEnv = function () { + return gitBranch() == 'master' ? 'prod' : 'dev' +} + gulp.task('generate', function(cb) { + var hexo = new Hexo(process.cwd(), { + config: `_config.${getEnv()}.yml`, + watch: false, + }); + hexo.init().then(function() { - return hexo.call('generate', { - watch: false - }); + return hexo.call('generate'); }).then(function() { return hexo.exit(); }).then(function() { @@ -38,10 +47,10 @@ var config = { src: { scss: './themes/navy/source/scss/*.scss', js: [ - './themes/navy/source/js/utils.js', - './themes/navy/source/js/popups.js', - './themes/navy/source/js/main.js', - ] + './themes/navy/source/js/utils.js', + './themes/navy/source/js/popups.js', + './themes/navy/source/js/main.js', + ] }, dist: { css: './public/css', diff --git a/package.json b/package.json index 7ae8921..2362e22 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,9 @@ }, "scripts": { "clean": "rm -rf public/*", - "build": "gulp run && hexo generate", + "build": "gulp run", "eslint": "eslint .", - "deploy": "hexo deploy", - "update-submodules": "git submodule update --recursive --remote" + "deploy": "hexo deploy" }, "dependencies": { "cheerio": "^0.20.0", @@ -51,4 +50,4 @@ "vinyl-source-stream": "^2.0.0", "watchify": "^3.11.0" } -} \ No newline at end of file +} diff --git a/scripts/git-branch.js b/scripts/git-branch.js new file mode 100644 index 0000000..36a8357 --- /dev/null +++ b/scripts/git-branch.js @@ -0,0 +1,23 @@ +'use strict' +const fs = require('fs') +const path = require('path') +const util = require('util') + +function parseBranch(buf) { + const match = /ref: refs\/heads\/([^\n]+)/.exec(buf.toString()) + return match ? match[1] : null +} + +function gitHeadPath(cwd) { + const filepath = path.join(process.cwd(), '.git/HEAD') + if (!fs.existsSync(filepath)) { + throw new Error('.git/HEAD does not exist') + } + return filepath +} + +const gitBranch = function() { + return parseBranch(fs.readFileSync(gitHeadPath())) +} + +module.exports = gitBranch