Skip to content

Commit 6e41f0d

Browse files
committed
build: run prettier before commit
1 parent c584760 commit 6e41f0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+7262
-6537
lines changed

package.json

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88
"url": "https://github.com/leancloud/javascript-sdk"
99
},
1010
"scripts": {
11+
"precommit": "pretty-quick --staged",
1112
"lint": "tsc storage.d.ts",
1213
"test": "npm run lint && npm run test:node",
13-
"test:node": "cross-env NODE_ENV=test nyc --reporter lcov --reporter text mocha --timeout 300000 test/index.js",
14+
"test:node":
15+
"cross-env NODE_ENV=test nyc --reporter lcov --reporter text mocha --timeout 300000 test/index.js",
1416
"docs": "jsdoc src README.md package.json -d docs -c .jsdocrc.json",
1517
"build:node": "gulp babel-node",
16-
"build:browser": "cross-env CLIENT_PLATFORM=Browser webpack --config webpack/browser.js",
17-
"build:rn": "cross-env CLIENT_PLATFORM=ReactNative webpack --config webpack/rn.js",
18-
"build:weapp": "cross-env CLIENT_PLATFORM=Weapp webpack --config webpack/weapp.js",
18+
"build:browser":
19+
"cross-env CLIENT_PLATFORM=Browser webpack --config webpack/browser.js",
20+
"build:rn":
21+
"cross-env CLIENT_PLATFORM=ReactNative webpack --config webpack/rn.js",
22+
"build:weapp":
23+
"cross-env CLIENT_PLATFORM=Weapp webpack --config webpack/weapp.js",
1924
"build": "gulp build && npm run build:live-query",
20-
"build:live-query": "export LIVE_QUERY=1 && npm run build:browser && npm run build:rn && npm run build:weapp",
25+
"build:live-query":
26+
"export LIVE_QUERY=1 && npm run build:browser && npm run build:rn && npm run build:weapp",
2127
"prepublishOnly": "./script/check-version.js"
2228
},
2329
"dependencies": {
@@ -49,9 +55,12 @@
4955
"gulp-babel": "^6.1.1",
5056
"gulp-clean": "^0.3.1",
5157
"gulp-shell": "^0.5.2",
58+
"husky": "^0.14.3",
5259
"jsdoc": "^3.5.5",
5360
"mocha": "^3.0.0",
5461
"nyc": "^8.1.0",
62+
"prettier": "^1.11.1",
63+
"pretty-quick": "^1.4.1",
5564
"qiniu": "^6.1.11",
5665
"should": "^11.1.0",
5766
"typescript": "^2.4.1",
@@ -83,10 +92,12 @@
8392
},
8493
"typings": "./storage.d.ts",
8594
"types": "./storage.d.ts",
95+
"prettier": {
96+
"singleQuote": true,
97+
"trailingComma": "es5"
98+
},
8699
"nyc": {
87-
"require": [
88-
"babel-register"
89-
],
100+
"require": ["babel-register"],
90101
"sourceMap": false,
91102
"instrument": false
92103
}

src/acl.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var _ = require('underscore');
22

33
module.exports = function(AV) {
4-
var PUBLIC_KEY = "*";
4+
var PUBLIC_KEY = '*';
55

66
/**
77
* Creates a new ACL.
@@ -26,19 +26,25 @@ module.exports = function(AV) {
2626
self.setWriteAccess(arg1, true);
2727
} else {
2828
if (_.isFunction(arg1)) {
29-
throw new Error('AV.ACL() called with a function. Did you forget ()?');
29+
throw new Error(
30+
'AV.ACL() called with a function. Did you forget ()?'
31+
);
3032
}
3133
AV._objectEach(arg1, function(accessList, userId) {
3234
if (!_.isString(userId)) {
3335
throw new Error('Tried to create an ACL with an invalid userId.');
3436
}
3537
self.permissionsById[userId] = {};
3638
AV._objectEach(accessList, function(allowed, permission) {
37-
if (permission !== "read" && permission !== "write") {
38-
throw new Error('Tried to create an ACL with an invalid permission type.');
39+
if (permission !== 'read' && permission !== 'write') {
40+
throw new Error(
41+
'Tried to create an ACL with an invalid permission type.'
42+
);
3943
}
4044
if (!_.isBoolean(allowed)) {
41-
throw new Error('Tried to create an ACL with an invalid permission value.');
45+
throw new Error(
46+
'Tried to create an ACL with an invalid permission value.'
47+
);
4248
}
4349
self.permissionsById[userId][permission] = allowed;
4450
});
@@ -59,7 +65,7 @@ module.exports = function(AV) {
5965
if (userId instanceof AV.User) {
6066
userId = userId.id;
6167
} else if (userId instanceof AV.Role) {
62-
userId = "role:" + userId.getName();
68+
userId = 'role:' + userId.getName();
6369
}
6470
if (!_.isString(userId)) {
6571
throw new Error('userId must be a string.');
@@ -92,7 +98,7 @@ module.exports = function(AV) {
9298
if (userId instanceof AV.User) {
9399
userId = userId.id;
94100
} else if (userId instanceof AV.Role) {
95-
userId = "role:" + userId.getName();
101+
userId = 'role:' + userId.getName();
96102
}
97103
var permissions = this.permissionsById[userId];
98104
if (!permissions) {
@@ -107,7 +113,7 @@ module.exports = function(AV) {
107113
* @param {Boolean} allowed Whether that user should have read access.
108114
*/
109115
AV.ACL.prototype.setReadAccess = function(userId, allowed) {
110-
this._setAccess("read", userId, allowed);
116+
this._setAccess('read', userId, allowed);
111117
};
112118

113119
/**
@@ -119,7 +125,7 @@ module.exports = function(AV) {
119125
* @return {Boolean}
120126
*/
121127
AV.ACL.prototype.getReadAccess = function(userId) {
122-
return this._getAccess("read", userId);
128+
return this._getAccess('read', userId);
123129
};
124130

125131
/**
@@ -128,7 +134,7 @@ module.exports = function(AV) {
128134
* @param {Boolean} allowed Whether that user should have write access.
129135
*/
130136
AV.ACL.prototype.setWriteAccess = function(userId, allowed) {
131-
this._setAccess("write", userId, allowed);
137+
this._setAccess('write', userId, allowed);
132138
};
133139

134140
/**
@@ -140,7 +146,7 @@ module.exports = function(AV) {
140146
* @return {Boolean}
141147
*/
142148
AV.ACL.prototype.getWriteAccess = function(userId) {
143-
return this._getAccess("write", userId);
149+
return this._getAccess('write', userId);
144150
};
145151

146152
/**
@@ -190,7 +196,7 @@ module.exports = function(AV) {
190196
role = role.getName();
191197
}
192198
if (_.isString(role)) {
193-
return this.getReadAccess("role:" + role);
199+
return this.getReadAccess('role:' + role);
194200
}
195201
throw new Error('role must be a AV.Role or a String');
196202
};
@@ -210,7 +216,7 @@ module.exports = function(AV) {
210216
role = role.getName();
211217
}
212218
if (_.isString(role)) {
213-
return this.getWriteAccess("role:" + role);
219+
return this.getWriteAccess('role:' + role);
214220
}
215221
throw new Error('role must be a AV.Role or a String');
216222
};
@@ -229,7 +235,7 @@ module.exports = function(AV) {
229235
role = role.getName();
230236
}
231237
if (_.isString(role)) {
232-
this.setReadAccess("role:" + role, allowed);
238+
this.setReadAccess('role:' + role, allowed);
233239
return;
234240
}
235241
throw new Error('role must be a AV.Role or a String');
@@ -249,10 +255,9 @@ module.exports = function(AV) {
249255
role = role.getName();
250256
}
251257
if (_.isString(role)) {
252-
this.setWriteAccess("role:" + role, allowed);
258+
this.setWriteAccess('role:' + role, allowed);
253259
return;
254260
}
255261
throw new Error('role must be a AV.Role or a String');
256262
};
257-
258263
};

src/app-router.js

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
const {
2-
ajax,
3-
} = require('./utils');
1+
const { ajax } = require('./utils');
42
const Cache = require('./cache');
53

64
function AppRouter(AV) {
75
this.AV = AV;
86
this.lockedUntil = 0;
9-
Cache.getAsync('serverURLs').then(data => {
10-
if (!data) return this.lock(0);
11-
const {
12-
serverURLs,
13-
lockedUntil,
14-
} = data;
15-
this.AV._setServerURLs(serverURLs, false);
16-
this.lockedUntil = lockedUntil;
17-
}).catch(() => this.lock(0));
7+
Cache.getAsync('serverURLs')
8+
.then(data => {
9+
if (!data) return this.lock(0);
10+
const { serverURLs, lockedUntil } = data;
11+
this.AV._setServerURLs(serverURLs, false);
12+
this.lockedUntil = lockedUntil;
13+
})
14+
.catch(() => this.lock(0));
1815
}
1916

2017
AppRouter.prototype.disable = function disable() {
@@ -34,29 +31,35 @@ AppRouter.prototype.refresh = function refresh() {
3431
query: {
3532
appId: this.AV.applicationId,
3633
},
37-
}).then(servers => {
38-
if (this.disabled) return;
39-
let ttl = servers.ttl;
40-
if (!ttl) throw new Error('missing ttl');
41-
ttl = ttl * 1000;
42-
const protocal = 'https://';
43-
const serverURLs = {
44-
push: protocal + servers.push_server,
45-
stats: protocal + servers.stats_server,
46-
engine: protocal + servers.engine_server,
47-
api: protocal + servers.api_server,
48-
};
49-
this.AV._setServerURLs(serverURLs, false);
50-
this.lock(ttl);
51-
return Cache.setAsync('serverURLs', {
52-
serverURLs,
53-
lockedUntil: this.lockedUntil,
54-
}, ttl);
55-
}).catch(error => {
56-
// bypass all errors
57-
console.warn(`refresh server URLs failed: ${error.message}`);
58-
this.lock(600);
59-
});
34+
})
35+
.then(servers => {
36+
if (this.disabled) return;
37+
let ttl = servers.ttl;
38+
if (!ttl) throw new Error('missing ttl');
39+
ttl = ttl * 1000;
40+
const protocal = 'https://';
41+
const serverURLs = {
42+
push: protocal + servers.push_server,
43+
stats: protocal + servers.stats_server,
44+
engine: protocal + servers.engine_server,
45+
api: protocal + servers.api_server,
46+
};
47+
this.AV._setServerURLs(serverURLs, false);
48+
this.lock(ttl);
49+
return Cache.setAsync(
50+
'serverURLs',
51+
{
52+
serverURLs,
53+
lockedUntil: this.lockedUntil,
54+
},
55+
ttl
56+
);
57+
})
58+
.catch(error => {
59+
// bypass all errors
60+
console.warn(`refresh server URLs failed: ${error.message}`);
61+
this.lock(600);
62+
});
6063
};
6164

6265
module.exports = AppRouter;

0 commit comments

Comments
 (0)