Skip to content

Commit

Permalink
Merge 6db7562 into e247041
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Dec 16, 2014
2 parents e247041 + 6db7562 commit 7758b3f
Show file tree
Hide file tree
Showing 294 changed files with 10,599 additions and 10,805 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
node_modules
tmp
debug.log
.idea
node_modules/
tmp/
*.log
.idea/
coverage/
8 changes: 6 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"proto": true,
"eqnull": true,
"expr": true,
"indent": 2,
"node": true,
"trailing": true,
"quotmark": "single"
"quotmark": "single",
"undef": true,
"unused": "vars",
"globals": {
"Promise": true
}
}
10 changes: 8 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
test/
tmp
debug.log
tmp/
coverage/
*.log
.jshintrc
.travis.yml
gulpfile.js
.idea/
appveyor.yml
14 changes: 12 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
language: node_js

node_js:
- "0.10"
- "0.11"
before_script:
- npm install -g gulp

script:
- npm test

after_script:
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
- cat ./coverage/lcov.info | ./node_modules/codeclimate-test-reporter/bin/codeclimate.js

addons:
code_climate:
repo_token: 161a304c89a989fd09844b22ad0b3af84a930cea8915350b82ecd8fa12c92985
8 changes: 0 additions & 8 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Hexo

[![Build Status](https://travis-ci.org/hexojs/hexo.svg?branch=master)](https://travis-ci.org/hexojs/hexo) [![NPM version](https://badge.fury.io/js/hexo.svg)](http://badge.fury.io/js/hexo)
[![Build Status](https://travis-ci.org/hexojs/hexo.svg?branch=master)](https://travis-ci.org/hexojs/hexo) [![NPM version](https://badge.fury.io/js/hexo.svg)](http://badge.fury.io/js/hexo) [![Coverage Status](https://img.shields.io/coveralls/hexojs/hexo.svg)](https://coveralls.io/r/hexojs/hexo?branch=master) [![Code Climate](https://codeclimate.com/github/hexojs/hexo/badges/gpa.svg)](https://codeclimate.com/github/hexojs/hexo) [![Build status](https://ci.appveyor.com/api/projects/status/hpx3lduqjj2t6uqq/branch/master?svg=true)](https://ci.appveyor.com/project/tommy351/hexo/branch/master)

A fast, simple & powerful blog framework, powered by [Node.js](http://nodejs.org).

Expand Down
35 changes: 35 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Based on https://github.com/gruntjs/grunt/blob/master/appveyor.yml
# http://www.appveyor.com/docs/appveyor-yml

# Fix line endings in Windows. (runs before repo cloning)
init:
- git config --global core.autocrlf input

# Test against these versions of Node.js.
environment:
matrix:
- nodejs_version: "0.10"
- nodejs_version: "0.11"

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node 0.STABLE.latest
- ps: Install-Product node $env:nodejs_version
# Typical npm stuff.
- npm install

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# We test multiple Windows shells because of prior stdout buffering issues
# filed against Grunt. https://github.com/joyent/node/issues/3584
- ps: "npm test # PowerShell" # Pass comment to PS for easier debugging
- cmd: npm test

# Don't actually build.
build: off

# Set build version format here instead of in the admin panel.
version: "{build}"
2 changes: 1 addition & 1 deletion assets/gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DS_Store
Thumbs.db
db.json
debug.log
*.log
node_modules/
public/
.deploy/
31 changes: 2 additions & 29 deletions bin/hexo
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
#!/usr/bin/env node

var args = require('minimist')(process.argv.slice(2)),
fs = require('graceful-fs'),
path = require('path'),
async = require('async'),
init = require('../lib/init'),
cwd = process.cwd(),
lastCwd = cwd;
var args = require('minimist')(process.argv.slice(2));

// Find Hexo folder recursively
async.doUntil(
function(next){
var configFile = path.join(cwd, '_config.yml');

fs.exists(configFile, function(exist){
if (exist){
init(cwd, args);
} else {
lastCwd = cwd;
cwd = path.dirname(cwd);
next();
}
});
},
function(){
return cwd === lastCwd;
},
function(){
init(process.cwd(), args);
}
);
require('../lib/cli/init')(args);
28 changes: 19 additions & 9 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
path = require('path');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var del = require('del');

var lib = 'lib/**/*.js',
test = 'test/scripts/**/*.js';
var lib = 'lib/**/*.js';
var test = 'test/scripts/**/*.js';

gulp.task('mocha', function(){
gulp.task('coverage', function(){
return gulp.src(lib)
.pipe($.istanbul())
.pipe($.istanbul.hookRequire());
});

gulp.task('coverage:clean', function(callback){
del(['coverage/**/*'], callback);
});

gulp.task('mocha', ['coverage'], function(){
return gulp.src('test/index.js')
.pipe($.mocha({
reporter: 'spec',
ignoreLeaks: true
}));
reporter: 'spec'
}))
.pipe($.istanbul.writeReports());
});

gulp.task('jshint', function(){
Expand Down
151 changes: 57 additions & 94 deletions lib/box/file.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,73 @@
var fs = require('graceful-fs'),
_ = require('lodash'),
util = require('../util'),
file = util.file2;

/**
* The file object of the Box class.
*
* @class File
* @param {Box} box
* @param {String} source The full path of the file.
* @param {String} path The relative path of the file.
* @param {String} type
* @param {Object} params
* @constructor
* @namespace Box
* @module hexo
*/
var File = module.exports = function File(box, source, path, type, params){
this.box = box;
this.source = source;
this.path = path;
this.type = type;
this.params = params;
};
var fs = require('hexo-fs');
var Promise = require('bluebird');

function File(data){
this.source = data.source;
this.path = data.path;
this.type = data.type;
this.params = data.params;
this.content = data.content;
}

function wrapReadOptions(options){
options = options || {};
if (typeof options === 'string') options = {encoding: options};
if (!options.hasOwnProperty('encoding')) options.encoding = 'utf8';
if (!options.hasOwnProperty('cache')) options.cache = true;

return options;
}

/**
* Reads the file.
*
* @method read
* @param {Object} [options]
* @param {Function} [callback]
* @async
*/
File.prototype.read = function(options, callback){
if (!callback){
if (typeof options === 'function'){
callback = options;
options = {};
} else {
callback = function(){};
}
if (!callback && typeof options === 'function'){
callback = options;
options = {};
}

file.readFile(this.source, options, callback);
var self = this;
var content = this.content;

options = wrapReadOptions(options);

return new Promise(function(resolve, reject){
if (!options.cache || !content){
return fs.readFile(self.source, options).then(resolve, reject);
}

var encoding = options.encoding;

if (encoding){
resolve(content.toString(encoding));
} else {
resolve(content);
}
}).nodeify(callback);
};

/**
* Reads the file synchronizedly.
*
* @method read
* @param {Object} [options]
* @return {String}
*/
File.prototype.readSync = function(options){
return file.readFileSync(this.source, options);
var content = this.content;

options = wrapReadOptions(options);

if (!options.cache || !content){
return fs.readFileSync(this.source, options);
}

var encoding = options.encoding;

if (encoding){
return content.toString(encoding);
} else {
return content;
}
};

/**
* Gets the file status.
*
* @method stat
* @param {Function} callback
* @async
*/
File.prototype.stat = function(callback){
fs.stat(this.source, callback);
return fs.stat(this.source).nodeify(callback);
};

/**
* Gets the file status synchronizedly.
*
* @method statSync
* @return {fs.Stats}
*/
File.prototype.statSync = function(){
return fs.statSync(this.source);
};

/**
* Renders the file with renderers.
*
* @method render
* @param {Object} [options]
* @param {Function} [callback]
* @async
*/
File.prototype.render = function(options, callback){
if (!callback){
if (typeof options === 'function'){
callback = options;
options = {};
} else {
callback = function(){};
}
}

hexo.render.render({path: this.source}, options, callback);
};

/**
* Renders the file with renderers synchronizedly.
*
* @method renderSync
* @param {Object} [options]
* @return {String}
*/
File.prototype.renderSync = function(options){
return hexo.render.renderSync({path: this.source}, options);
};
module.exports = File;
Loading

0 comments on commit 7758b3f

Please sign in to comment.