虽然after_build 挂钩是默认答案,但我建议使用任务运行器来完成这项工作。
任务运行器非常棒,可以让这些例程变得更容易。例如,大多数 Middleman 项目需要部署到托管服务器。因此,如果您碰巧使用任务运行器进行部署,您也可以使用它来复制文件。
如果您不使用任务运行器,请考虑使用一个。它会为您省去很多麻烦。
Rake 是 Middleman 的 Ruby 环境的自然选择,但我更喜欢 Grunt。
这是一个 Grunt 复制任务(使用 grunt-contrib-copy 插件):
copy: {
bowercomponents: {
files: [
{
expand: true,
flatten: true,
src: [
'source/Readme.md'
],
dest: 'build/',
filter: 'isFile'
}
]
}
}
这是一个使用 grunt-shell 插件的部署任务:
shell: {
buildAndPublish: {
command: [
'echo "### Building ###"',
'bundle exec middleman build --verbose',
'echo "### Adding built files to git index ###"',
'cd build/',
'git add -A',
'echo "### Commiting changes ###"',
'git commit -m build',
'echo "### Pushing the commit to the gh-pages remote branch ###"',
'git push origin gh-pages',
'cd ..'
].join(' && '),
options: {
stdout: true,
stderr: true
}
}
}