Skip to content

Commit

Permalink
Merge branch 'new-box'
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Dec 5, 2015
2 parents 7433af3 + f976513 commit 3c595d6
Show file tree
Hide file tree
Showing 45 changed files with 1,048 additions and 1,296 deletions.
45 changes: 2 additions & 43 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,45 +1,4 @@
{
"extends": "eslint:recommended",
"root": true,
"rules": {
"curly": [2, "multi-line"],
"no-console": 0,
"no-path-concat": 2,
"handle-callback-err": 2,
"no-use-before-define": [2, "nofunc"],
"no-shadow-restricted-names": 2,
"block-scoped-var": 2,
"dot-notation": 2,
"eqeqeq": [2, "allow-null"],
"no-else-return": 1,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-implied-eval": 2,
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new-wrappers": 2,
"no-redeclare": 2,
"no-return-assign": 2,
"no-throw-literal": 2,
"no-unused-expressions": [2, {
"allowShortCircuit": true,
"allowTernary": true
}],
"no-useless-call": 2,
"no-useless-concat": 2,
"no-with": 2,
"radix": 2,
"no-self-compare": 2,
"no-unused-vars": [2, {
"vars": "all",
"args": "none"
}],
"strict": [2, "global"]
},
"env": {
"node": true
}
"extends": "hexo",
"root": true
}
83 changes: 1 addition & 82 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -1,85 +1,4 @@
{
"excludeFiles": ["node_modules/**", "coverage/**", "tmp/**"],
"validateIndentation": 2,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"requireSemicolons": true,
"disallowEmptyBlocks": true,
"disallowKeywordsOnNewLine": ["else"],
"disallowKeywords": ["with"],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineBreaks": true,
"disallowMultipleLineStrings": true,
"disallowMultipleVarDecl": "exceptUndefined",
"disallowNewlineBeforeBlockStatements": true,
"disallowOperatorBeforeLineBreak": ["."],
"disallowSpaceBeforeBinaryOperators": [","],
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforeComma": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeSemicolon": true,
"disallowSpacesInCallExpression": true,
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideParentheses": true,
"disallowSpacesInsideParenthesizedExpression": {
"allExcept": [ "{", "}" ]
},
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"disallowYodaConditions": true,
"requireBlocksOnNewline": true,
"requireCapitalizedConstructors": true,
"requireCommaBeforeLineBreak": true,
"requireCurlyBraces": [
"for",
"while",
"do",
"try",
"catch"
],
"requireDotNotation": true,
"requireLineBreakAfterVariableAssignment": true,
"requireLineFeedAtFileEnd": true,
"requirePaddingNewLinesAfterBlocks": true,
"requirePaddingNewLinesAfterUseStrict": true,
"requireParenthesesAroundIIFE": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceAfterKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"catch",
"void",
"while",
"with",
"return",
"typeof"
],
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBetweenArguments": true,
"requireSpacesInFunction": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInConditionalExpression": true,
"requireSpacesInForStatement": true,
"requireSpacesInFunctionDeclaration": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"validateNewlineAfterArrayElements": true,
"validateParameterSeparator": ", ",
"disallowMultipleSpaces": true
"preset": "hexo"
}
10 changes: 0 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@ language: node_js

sudo: false

env:
- CXX=g++-4.8

cache:
apt: true
directories:
- node_modules

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8

node_js:
- "0.12"
- "4"
Expand Down
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ test_script:
- node --version
- npm --version
# Run tests
- npm run eslint
- npm run jscs
- npm test

# Don't actually build.
Expand Down
81 changes: 4 additions & 77 deletions lib/box/file.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,20 @@
'use strict';

var fs = require('hexo-fs');
var Promise = require('bluebird');

var escapeBOM = fs.escapeBOM;
var escapeEOL = fs.escapeEOL;

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

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;
if (!options.hasOwnProperty('escape')) options.escape = true;

return options;
}

function escapeContent(str) {
return escapeBOM(escapeEOL(str));
this.type = data.type;
}

File.prototype.read = function(options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}

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) return resolve(content);

var result = content.toString(encoding);
if (options.escape) return resolve(escapeContent(result));

resolve(result);
}).asCallback(callback);
return fs.readFile(this.source, options).asCallback(callback);
};

File.prototype.readSync = function(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;

var result = content.toString(encoding);
if (options.escape) return escapeContent(result);

return result;
return fs.readFileSync(this.source, options);
};

File.prototype.stat = function(options, callback) {
Expand All @@ -79,27 +23,10 @@ File.prototype.stat = function(options, callback) {
options = {};
}

options = options || {};

var stats = this.stats;
var cache = options.hasOwnProperty('cache') ? options.cache : true;
var self = this;

return new Promise(function(resolve, reject) {
if (stats && cache) return resolve(stats);

fs.stat(self.source).then(resolve, reject);
}).asCallback(callback);
return fs.stat(this.source).asCallback(callback);
};

File.prototype.statSync = function(options) {
options = options || {};

var cache = options.hasOwnProperty('cache') ? options.cache : true;
var stats = this.stats;

if (stats && cache) return stats;

return fs.statSync(this.source);
};

Expand Down

0 comments on commit 3c595d6

Please sign in to comment.