Skip to content

Commit

Permalink
add grunt for creating new versions
Browse files Browse the repository at this point in the history
  • Loading branch information
SSilence committed Sep 2, 2014
1 parent e01d185 commit 2a0fe4c
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ user.css
/_docs/website/forum
config.ini
.project
node_modules
2 changes: 1 addition & 1 deletion .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Enable rewrite engine and route requests to framework
RewriteEngine On
RewriteBase /selfoss
#RewriteBase /selfoss

# rule for favicons
RewriteRule !data/favicons/(.*)$ - [C]
Expand Down
98 changes: 98 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
module.exports = function(grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

/* version text replace */
replace: {
version: {
src: [
'package.json',
'README.md',
'common.php',
'_docs/website/index.html'
],
overwrite: true,
replacements: [
// rule for package.json
{
from: /"ver": "\d+\.\d+(\-SNAPSHOT)?"/,
to: ('"ver": "' + grunt.option('newversion') + '"')
},

// rule for README.md
{
from: /'version','\d+\.\d+(\-SNAPSHOT)?'/,
to: ("'version','" + grunt.option('newversion') + "'")
},

// rule for common.php
{
from: /Version \d+\.\d+(\-SNAPSHOT)?/,
to: ("Version " + grunt.option('newversion'))
},

// rule for website/index.html
{
from: /selfoss( |\-)\d+\.\d+(\-SNAPSHOT)?/g,
to: ("selfoss$1" + grunt.option('newversion'))
}]
}
},

/* create zip */
compress: {
main: {
options: {
archive: 'selfoss-<%= pkg.ver %>.zip'
},
files: [
{ expand: true, cwd: 'controllers/', src: ['**'], dest: '/controllers'},
{ expand: true, cwd: 'daos/', src: ['**'], dest: '/daos'},
{ expand: true, cwd: 'helpers/', src: ['**'], dest: '/helpers'},
{ expand: true, cwd: 'libs/', src: ['**'], dest: '/libs'},

// public = don't zip all.js and all.css
{ expand: true, cwd: 'public/', src: ['**'], dest: '/public', filter: function(file) {
return file.indexOf('all.js') === -1 && file.indexOf('all.css') === -1;
}},

// copy data: only directory structure and .htaccess for deny
{ expand: true, cwd: 'data/', src: ['**'], dest: '/data', filter: 'isDirectory'},
{ src: ['data/cache/.htaccess'], dest: '' },
{ src: ['data/logs/.htaccess'], dest: '' },
{ src: ['data/sqlite/.htaccess'], dest: '' },

{ expand: true, cwd: 'spouts/', src: ['**'], dest: '/spouts'},
{ expand: true, cwd: 'templates/', src: ['**'], dest: '/templates'},

{ src: ['.htaccess'], dest: '' },
{ src: ['README.md'], dest: '' },
{ src: ['defaults.ini'], dest: '' },
{ src: ['index.php'], dest: '' },
{ src: ['common.php'], dest: '' },
{ src: ['run.php'], dest: '' },
{ src: ['update.php'], dest: '' }
]
}
}
});

grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-contrib-compress');

/* task checks whether newversion is given and start replacement in files if correct format is given */
grunt.registerTask('versionupdater', 'version update task', function() {
var version = "" + grunt.option('newversion');
if (typeof grunt.option('newversion') != 'undefined') {
grunt.log.writeln('replace version ' + grunt.option('newversion'));
if (version.search(/^\d+\.\d+(\-SNAPSHOT)?$/) == -1)
grunt.fail.warn('newversion must have the format n.m.x or n.m.x-SNAPSHOT (n, m and x are integer numbers)');
grunt.task.run('replace');
}
});

grunt.registerTask('default', ['versionupdater', 'compress']);
grunt.registerTask('version', ['versionupdater']);
grunt.registerTask('zip', ['compress']);
};
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "selfoss",
"description": "selfoss",
"ver": "2.12-SNAPSHOT",
"repository": {
"type": "git",
"url": "https://github.com/SSilence/selfoss.git"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-compress": "^0.10.0",
"grunt-text-replace": "~0.3"
}
}

0 comments on commit 2a0fe4c

Please sign in to comment.