Manage your svn folders.
Help you to improve the automation process.
The example give you a simple, clear, maintainable project directory structure.
The publish task in example will copy your logs to target folders, from previous commit to now.
You can set a confirm prompt in the task queue.
For whoever have a JavaScript project on a SVN repository, and want to properly maintenance it.
Be sure that SVN version >= 1.6 .
Requires SVN CLI, set language as english.
Create a directory named tools in your project repository path.
Create a local directory of your project named 'projectname'
, then checkout the tools directory to 'projectname/tools'
.
Put your grunt file and package.json in this directory. like this:
This plugin requires Grunt ~0.4.0
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-svn-workflow --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-svn-workflow');
Be sure that you have stored the svn password, for now these tasks can't give you a prompt that need the password .
Reference example file to configure your task file, or just copy the configuration.
Set your svn configs in this task , and put the svnConfig
task in your svn operation task queue.
Type: String
Default: ''
The repository url of project. Set it as 'auto'
to let the task get the repository url with taskDir
option automatically.
Type: String
The local path of the project.
Type: String
The path of the task directory relative to the repository url of project.
var path = require('path');
// Project svn tasks configuration.
grunt.initConfig({
svnConfig : {
// Project svn repository path.
repository : 'auto',
// Project deploy path.
projectDir : path.resolve(__dirname, '../'),
// Project gruntfile directory.
taskDir : 'tools'
}
});
Run this task with the grunt svnInit
command.
Type: String
The repository url of project.
Type: String
The local path of the project.
Type: Object
Describe the SVN directory structure.
var path = require('path');
grunt.initConfig({
svnConfig : {
// Project svn repository path.
repository : 'auto',
// Project deploy path.
projectDir : path.resolve(__dirname, '../'),
// Project gruntfile directory.
taskDir : 'tools'
},
svnInit : {
options : {
repository: '<%=svnConfig.repository%>',
cwd: '<%=svnConfig.projectDir%>'
},
// Build pathes according to the map.
map : {
'dev' : {
'branches' : 'folder',
'tags' : 'folder',
'trunk' : {
'html' : 'folder',
'css' : 'folder',
'js' : 'folder'
}
},
'online' : {
'tags' : 'folder',
'trunk' : 'folder'
}
}
}
});
If you run the task : grunt svnInit
, you will get the directory structure like this:
Set your checkout options, then put the task in where you want.
Type: String
The repository url of project.
Type: String
The local path of the project.
Type: Object
Describe the SVN directory mapping relationship with the local path.
var path = require('path');
grunt.initConfig({
svnConfig : {
// Project svn repository path.
repository : 'auto',
// Project deploy path.
projectDir : path.resolve(__dirname, '../'),
// Project gruntfile directory.
taskDir : 'tools'
},
svnCheckout : {
options : {
repository: '<%=svnConfig.repository%>',
cwd: '<%=svnConfig.projectDir%>'
},
deploy : {
map : {
'trunk' : 'dev/trunk',
'dist' : 'online/trunk'
}
}
}
});
Set your commit options, then put the task in where you want.
Type: String
The repository url of project.
Type: String
The local path of the project.
Type: String
The commit task can copy logs from a svn path.
It's a relative path.
Set it as ''
to close logs copying.
Type: String
SVN relative path to be commited.
Type: String
Local relative path to be commited.
var path = require('path');
grunt.initConfig({
svnConfig : {
// Project svn repository path.
repository : 'auto',
// Project deploy path.
projectDir : path.resolve(__dirname, '../'),
// Project gruntfile directory.
taskDir : 'tools'
},
svnCommit : {
options : {
repository: '<%=svnConfig.repository%>',
cwd: '<%=svnConfig.projectDir%>'
},
online : {
logResource : 'dev/trunk',
svn : 'online/trunk',
src : 'tools/temp/online'
}
}
});
Set your tag options, then put the task in where you want.
Type: String
The repository url of project.
Type: String
The local path of the project.
Type: String
Local relative path for development.
Type: String
Repository relative url for development.
Type: String
Tag repository relative url for development.
Type: String
Local relative path for publishing.
Type: String
Repository relative url for publishing.
Type: String
Tag repository relative url for publishing.
var path = require('path');
grunt.initConfig({
svnConfig : {
// Project svn repository path.
repository : 'auto',
// Project deploy path.
projectDir : path.resolve(__dirname, '../'),
// Project gruntfile directory.
taskDir : 'tools'
},
svnTag : {
options : {
repository: '<%=svnConfig.repository%>',
cwd: '<%=svnConfig.projectDir%>'
},
common : {
dev : 'tools/temp/trunk',
devSvn : 'dev/trunk',
devTag : 'dev/tags',
online : 'tools/temp/online',
onlineSvn : 'online/trunk',
onlineTag : 'online/tags'
}
}
});
Create a simple task and put it in the task queue, to generate a confirm prompt in the running task.
Type: String
The message of prompts.
grunt.initConfig({
confirm : {
distribute : {
msg : 'publish ?'
}
}
});
The full gruntfile example:
var path = require('path');
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
// Clean files for example publish.
clean: {
beforePublish: [
'temp'
]
},
// Copy files for example publish.
copy: {
forPublish: {
expand : true,
cwd : 'temp/trunk/',
src : '**/*',
dest : 'temp/online/'
}
},
confirm : {
distribute : {
msg : 'publish ?'
}
},
svnConfig : {
// Project svn repository path.
repository : 'auto',
// Project deploy path.
projectDir : path.resolve(__dirname, '../'),
// Project gruntfile directory.
taskDir : 'tools'
},
svnInit : {
options : {
repository: '<%=svnConfig.repository%>',
cwd: '<%=svnConfig.projectDir%>'
},
// Build pathes according to the map.
map : {
'dev' : {
'branches' : 'folder',
'tags' : 'folder',
'trunk' : {
'html' : 'folder',
'css' : 'folder',
'js' : 'folder'
}
},
'online' : {
'tags' : 'folder',
'trunk' : 'folder'
}
}
},
svnCheckout : {
options : {
repository: '<%=svnConfig.repository%>',
cwd: '<%=svnConfig.projectDir%>'
},
deploy : {
map : {
'trunk' : 'dev/trunk',
'dist' : 'online/trunk'
}
},
prepare : {
map : {
'tools/temp/online':'online/trunk',
'tools/temp/trunk' : 'dev/trunk'
}
}
},
svnCommit : {
options : {
repository: '<%=svnConfig.repository%>',
cwd: '<%=svnConfig.projectDir%>'
},
online : {
logResource : 'dev/trunk',
svn : 'online/trunk',
src : 'tools/temp/online'
}
},
svnTag : {
options : {
repository: '<%=svnConfig.repository%>',
cwd: '<%=svnConfig.projectDir%>'
},
common : {
dev : 'tools/temp/trunk',
devSvn : 'dev/trunk',
devTag : 'dev/tags',
online : 'tools/temp/online',
onlineSvn : 'online/trunk',
onlineTag : 'online/tags'
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-svn-workflow');
grunt.registerTask(
'deploy',
'Checkout the workingcopy according to the folder map.',
[
'svnConfig',
'svnCheckout:deploy'
]
);
grunt.registerTask(
'publish',
'Pack and compress files, then distribute.',
[
'clean:beforePublish',
'svnConfig',
'svnCheckout:prepare',
//Add your other tasks here, such as copy, uglify, clean and so on.
'copy:forPublish',
'confirm:distribute',
'svnCommit:online',
'svnTag'
]
);
// By default, deploy the workingcopy.
grunt.registerTask('default', [
'deploy'
]);
};
If you have a error like this:
Fatal error: 1801 tag exists ! cancel tag building!
That means there is no change between now and previous commit.
- 2014-12-09 v0.1.1 Fix the bug that tag building will have a error occasionally.
- 2014-12-04 v0.1.0 First official release for Grunt 0.4.0.