Skip to content

Commit

Permalink
Merge pull request #39 from laoshu133/master
Browse files Browse the repository at this point in the history
Add extend_dirs support
  • Loading branch information
Xuanwo committed Sep 10, 2016
2 parents 498f637 + 0aab724 commit b4ec757
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,31 @@ deploy:
message: [message]
name: [git user]
email: [git email]

extend_dirs: [extend directory]

# or this:
deploy:
type: git
message: [message]
repo:
repo:
github: <repository url>,[branch]
gitcafe: <repository url>,[branch]
extend_dirs:
- [extend directory]
- [another extend directory]
```

- **repo**: Repository URL
- **branch**: Git branch to deploy the static site to
- **message**: Commit message. The default commit message is `Site updated: {{ now('YYYY-MM-DD HH:mm:ss') }}`.
- **name** and **email**: User info for committing the change, overrides global config. This info is independent of git login.
- **extend_dirs**: Add some extensions directory to publish. e.g `demo`, `examples`

## How it works

`hexo-deployer-git` works by generating the site in `.deploy_git` and *force pushing* to the repo(es) in config.
If `.deploy_git` does not exist, a repo will initialized (`git init`).
Otherwise the curent repo (with its commit history) will be used.
`hexo-deployer-git` works by generating the site in `.deploy_git` and *force pushing* to the repo(es) in config.
If `.deploy_git` does not exist, a repo will initialized (`git init`).
Otherwise the curent repo (with its commit history) will be used.

Users can to clone the deployed repo to `.deploy_git` to keep the commit history.
```
Expand Down
24 changes: 24 additions & 0 deletions lib/deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var fs = require('hexo-fs');
var chalk = require('chalk');
var swig = require('swig');
var moment = require('moment');
var Promise = require('bluebird');
var spawn = require('hexo-util/lib/spawn');
var parseConfig = require('./parse_config');

Expand All @@ -18,6 +19,7 @@ module.exports = function(args) {
var baseDir = this.base_dir;
var deployDir = pathFn.join(baseDir, '.deploy_git');
var publicDir = this.public_dir;
var extendDirs = args.extend_dirs;
var log = this.log;
var message = commitMessage(args);
var verbose = !args.silent;
Expand All @@ -32,6 +34,7 @@ module.exports = function(args) {
help += ' repo: <repository url>\n';
help += ' branch: [branch]\n';
help += ' message: [message]\n\n';
help += ' extend_dirs: [extend directory]\n\n';
help += 'For more help, you can check the docs: ' + chalk.underline('http://hexo.io/docs/deployment.html');

console.log(help);
Expand Down Expand Up @@ -91,6 +94,27 @@ module.exports = function(args) {
}).then(function() {
log.info('Copying files from public folder...');
return fs.copyDir(publicDir, deployDir);
}).then(function() {
log.info('Copying files from extend dirs...');

if (!extendDirs) {
return;
}

if (typeof extendDirs === 'string') {
extendDirs = [extendDirs];
}

var mapFn = function(dir) {
var extendPath = pathFn.join(baseDir, dir);
var extendDist = pathFn.join(deployDir, dir);

return fs.copyDir(extendPath, extendDist);
};

return Promise.map(extendDirs, mapFn, {
concurrency: 2
});
}).then(function() {
return parseConfig(args);
}).each(function(repo) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
"mocha": "^2.5.3"
},
"dependencies": {
"bluebird": "^3.4.1",
"chalk": "^1.1.3",
"hexo-fs": "^0.1.5",
"hexo-fs": "^0.1.6",
"hexo-util": "^0.6.0",
"moment": "^2.13.0",
"swig": "^1.4.2"
}
}
}
22 changes: 22 additions & 0 deletions test/deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('deployer', function() {
var publicDir = pathFn.join(baseDir, 'public');
var fakeRemote = pathFn.join(baseDir, 'remote');
var validateDir = pathFn.join(baseDir, 'validate');
var extendDir = pathFn.join(baseDir, 'extend');

var ctx = {
base_dir: baseDir,
Expand Down Expand Up @@ -93,6 +94,27 @@ describe('deployer', function() {
});
});

it('extend dirs', function() {
var extendDirName = pathFn.basename(extendDir);

return fs.writeFile(pathFn.join(extendDir, 'ext.txt'), 'ext')
.then(function() {
return deployer({
repo: fakeRemote,
extend_dirs: extendDirName,
silent: true
});
}).then(function() {
return validate();
}).then(function() {
var extTxtFile = pathFn.join(validateDir, extendDirName, 'ext.txt');

return fs.readFile(extTxtFile);
}).then(function(content) {
content.should.eql('ext');
});
});

it('multi deployment', function() {
return deployer({
repo: {
Expand Down

0 comments on commit b4ec757

Please sign in to comment.