hexo-git-backup
Advanced tools
Comparing version 0.0.92 to 0.1.0
var async = require('async'), | ||
var hexo = require('hexo'); | ||
fs = require('graceful-fs'), | ||
@@ -8,6 +7,6 @@ _ = require('lodash'); | ||
module.exports = function(args, callback){ | ||
var config = hexo.config.backup, | ||
log = hexo.log, | ||
extend = hexo.extend, | ||
backupers = extend.deployer.list(); | ||
var config = this.config.backup, | ||
log = this.log, | ||
backupers = this.extend.deployer.list(), | ||
self = this; | ||
@@ -36,3 +35,3 @@ if (!config){ | ||
*/ | ||
hexo.emit('backupBefore'); | ||
self.emit('backupBefore'); | ||
}; | ||
@@ -48,13 +47,14 @@ | ||
*/ | ||
hexo.emit('backupAfter', err); | ||
self.emit('backupAfter', err); | ||
callback(err); | ||
}; | ||
onBackupStarted(); | ||
// console.log(item); | ||
// console.log(args); | ||
async.eachSeries(config, function(item, next){ | ||
var type = item.type; | ||
if (!backupers.hasOwnProperty(type)){ | ||
if (type != "git"){ | ||
log.e('backuper not found: ' + type); | ||
return next(); | ||
// return next(); | ||
} else { | ||
@@ -64,3 +64,3 @@ log.i('Start backup: ' + type); | ||
git(_.extend({}, item, args), function(err){ | ||
git(_.extend({}, item, args), self,function(err){ | ||
if (err) return next(err); | ||
@@ -67,0 +67,0 @@ |
80
git.js
@@ -8,4 +8,5 @@ var async = require('async'), | ||
module.exports = function(args, callback){ | ||
var baseDir = args.deploy_dir || hexo.base_dir, | ||
module.exports = function(args, selfData, callback){ | ||
var self = selfData, | ||
baseDir = self.base_dir, | ||
//deployDir = path.join(baseDir, '.deploy'), | ||
@@ -15,4 +16,3 @@ deployDir = baseDir, | ||
themesDir = path.join(baseDir, 'themes'), | ||
publicDir = hexo.public_dir; | ||
publicDir = self.public_dir; | ||
if (!args.repo && !args.repository){ | ||
@@ -42,3 +42,38 @@ var help = ''; | ||
} | ||
if(args.themes){ | ||
var themes = args.themes.split(','); | ||
}else if(self.config.theme){ | ||
var themes = [self.config.theme]; | ||
} | ||
var addThemes = function(commands){ | ||
if(themes){ | ||
for (var t in themes){ | ||
var themeName = themes[t]; | ||
var themeGitDir = path.join(baseDir,'themes/' + themeName+ '/.git'); | ||
var themeDir = path.join(baseDir,'themes/' + themeName); | ||
// fs.existsSync(themeGitDir,function(exist){ | ||
if(fs.existsSync(themeGitDir)){ | ||
var child = spawn('rm', ['-rf', '.git'],{cwd: themeDir}); | ||
if(commands){ | ||
var themeFiles = path.join(themeDir,"*"); | ||
commands.push(['add', themeFiles]); | ||
console.log(commands); | ||
} | ||
self.log.i(themeGitDir); | ||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', function(data) { | ||
self.log.i(data); | ||
}); | ||
child.stderr.on('data', function (data) { | ||
self.log.i('stderr: ' + data); | ||
}); | ||
child.on('close', function (code) { | ||
self.log.i('child process exited with code ' + code); | ||
}); | ||
} | ||
// }) | ||
} | ||
} | ||
} | ||
var run = function(command, args, callback){ | ||
@@ -63,29 +98,8 @@ var cp = spawn(command, args, {cwd: deployDir}); | ||
if (exist && !args.setup) return next(); | ||
hexo.log.i('Setting up Git-Backup deployment...'); | ||
self.log.i('Setting up Git-Backup deployment...'); | ||
var commands = [['init']]; | ||
if(args.theme){ | ||
var themeGitDir = path.join(baseDir,'themes/' + args.theme + '/.git'); | ||
var themeDir = path.join(baseDir,'themes/' + args.theme); | ||
fs.exists(themeGitDir,function(exist){ | ||
if(exist){ | ||
var child = spawn('rm', ['-rf', '.git'],{cwd: themeDir}); | ||
hexo.log.i(themeGitDir); | ||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', function(data) { | ||
hexo.log.i(data); | ||
}); | ||
child.stderr.on('data', function (data) { | ||
hexo.log.i('stderr: ' + data); | ||
}); | ||
child.on('close', function (code) { | ||
hexo.log.i('child process exited with code ' + code); | ||
}); | ||
} | ||
}) | ||
} | ||
addThemes(); | ||
if (args.master && repo[args.master]){ | ||
var master = repo[args.master]; | ||
hexo.log.i('fetch from ['+ args.master.green + ']:', master.url.cyan); | ||
self.log.i('fetch from ['+ args.master.green + ']:', master.url.cyan); | ||
commands.push(['remote', 'add', 'origin', '-t', master.branch, master.url]); | ||
@@ -96,3 +110,3 @@ commands.push(['pull']); | ||
commands.push(['commit', '-m', 'First commit']); | ||
hexo.log.i('First'); | ||
self.log.i('First'); | ||
} | ||
@@ -121,7 +135,5 @@ | ||
function(next){ | ||
var commands = [ | ||
['add', '-A'], | ||
['commit', '-m', commitMessage(args)], | ||
]; | ||
var commands = [['add', '-A']]; | ||
addThemes(commands); | ||
commands.push(['commit', '-m', commitMessage(args)]); | ||
for (var t in repo){ | ||
@@ -128,0 +140,0 @@ commands.push(['push', '-u', t, 'master:' + repo[t].branch, '--force']); |
@@ -1,2 +0,2 @@ | ||
var console = hexo.extend.deployer; | ||
var console = hexo.extend.console; | ||
@@ -10,2 +10,2 @@ var backupOptions = { | ||
console.register('backup', require('./backup')); | ||
console.register('backup', 'backup your website', backupOptions, require('./backup')); |
{ | ||
"name": "hexo-git-backup", | ||
"version": "0.0.92", | ||
"version": "0.1.0", | ||
"description": "hexo backup plugin for Hexo,backup to github", | ||
@@ -8,3 +8,3 @@ "main": "index", | ||
"type": "git", | ||
"url": "https://github.com/coneycode/hexo-git-backup.git" | ||
"url": "git+https://github.com/coneycode/hexo-git-backup.git" | ||
}, | ||
@@ -19,5 +19,9 @@ "bugs": { | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Coney Geng <coneylife@gmail.com> (http://gengbiao.me)", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": { | ||
"name": "Coney Geng", | ||
"email": "coneylife@gmail.com", | ||
"url": "http://gengbiao.me" | ||
}, | ||
"license": { | ||
@@ -34,3 +38,10 @@ "type": "MIT", | ||
"swig": "1.4.1" | ||
} | ||
}, | ||
"readme": "# git-backup\n\ngit-backup.\n\n## Install\n\n``` bash\n$ npm install hexo-git-backup --save\n```\n\n## Update\n\nif you install with --save, you must remove firstly when you update it.\n``` bash\n$ npm remove hexo-git-backup\n$ npm install hexo-git-backup --save\n```\n\n## Configure\n\nYou should configure this plugin in `_config.yml`.\n\n``` yaml\nbackup:\n type: git\n repository:\n github: git@github.com:xxx/xxx.git,branchName\n gitcafe: git@github.com:xxx/xxx.git,branchName\n```\n\n## Using\n```\nhexo backup \n```\nor \n```\nhexo b\n```\n## Options\n\nif you want to back up with your theme,just add `theme: your theme name` in `_config.yml`.\n\n``` yaml\nbackup:\n type: git\n theme: coney\n repository:\n github: git@github.com:xxx/xxx.git,branchName\n gitcafe: git@github.com:xxx/xxx.git,branchName\n```\n**Attention: if you do as above, the dir `themes/coney/.git`will be removed**\n\nNow you can backup all the blog!\n## Problems\n\nYou may get some troubles by your computer' permission。\n\n###Error: EISDIR, open\nit is caused by permission.\njust do 'sudo hexo b' \n```\nsudo hexo b\n```\n", | ||
"readmeFilename": "README.md", | ||
"gitHead": "0ed2d20bd42016af2911fd654d10f4544ed42f4a", | ||
"homepage": "https://github.com/coneycode/hexo-git-backup#readme", | ||
"_id": "hexo-git-backup@0.0.92", | ||
"_shasum": "db2011100f62f2f8920f8996152384da07161fb4", | ||
"_from": "hexo-git-backup@*" | ||
} |
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
23877
681
2