Skip to content

Commit 2afee04

Browse files
committed
feat:first implement
0 parents  commit 2afee04

33 files changed

+567
-0
lines changed

.autod.conf.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
module.exports = {
4+
write: true,
5+
prefix: '^',
6+
test: [
7+
'test',
8+
'benchmark',
9+
],
10+
dep: [
11+
'egg',
12+
'egg-view-nunjucks',
13+
'egg-alinode',
14+
'egg-mysql',
15+
'egg-oss',
16+
],
17+
devdep: [
18+
'egg-bin',
19+
'autod',
20+
'eslint',
21+
'eslint-config-egg',
22+
'supertest',
23+
'ali-oss',
24+
],
25+
exclude: [
26+
'./test/fixtures',
27+
],
28+
};

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test/fixtures
2+
coverage

.eslintrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "eslint-config-egg",
3+
"rules": {
4+
"no-unused-vars": "off"
5+
}
6+
}

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
logs/
2+
npm-debug.log
3+
node_modules/
4+
coverage/
5+
.idea/
6+
run/
7+
.DS_Store
8+
*.swp

.travis.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- '6'
5+
- '7'
6+
install:
7+
- npm i npminstall && npminstall
8+
script:
9+
- npm run ci
10+
after_script:
11+
- npminstall codecov && codecov
12+
env:
13+
global:
14+
- secure: Ws1h7ZU97/2npejMZp3/Jac0ZYkgXBW5gEilR5WrnkdkEbIhhK6HamrcqLrA6qCPV0Ax9nNbZCRJcQwPsTdOxBekJ3+3zflMWevfa9+CRS1Hh0mMcn+D864CjrRiQRgIQa8ZoFVPLaL/7qyQp1i7gLbPcpMjO6CA7LgV1reaf+U=
15+
- secure: Sj56ZeEZ48Sms7+jEI0qvrtEZoGc5ywotxYxvZ3EHg42Xpv6HB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81iRwJNBxwm1cj40cck41Py2eG3AwH0yCj0K3u+o74fOHbTuYLzNskB1gYbA8m6v2vuMnGRblb6+UYEm3yUcYHJ4VXFMmFTMKyNoe/iqEpetgoKffbCAk3Xa7kZbbQR7T03tI=
22+
services:
23+
- mysql

HISTORY.md

Whitespace-only changes.

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
This software is licensed under the MIT License.
2+
3+
Copyright(c) 2016 Alibaba Group Holding Limited and other contributors.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
aliyun-egg
2+
=======
3+
4+
[![NPM version][npm-image]][npm-url]
5+
[![build status][travis-image]][travis-url]
6+
[![Test coverage][codecov-image]][codecov-url]
7+
[![David deps][david-image]][david-url]
8+
[![npm download][download-image]][download-url]
9+
10+
[npm-image]: https://img.shields.io/npm/v/aliyun-egg.svg?style=flat-square
11+
[npm-url]: https://npmjs.org/package/aliyun-egg
12+
[travis-image]: https://img.shields.io/travis/alibaba/aliyun-egg.svg?style=flat-square
13+
[travis-url]: https://travis-ci.org/alibaba/aliyun-egg
14+
[codecov-image]: https://codecov.io/github/alibaba/aliyun-egg/coverage.svg?branch=master
15+
[codecov-url]: https://codecov.io/github/alibaba/aliyun-egg?branch=master
16+
[david-image]: https://img.shields.io/david/alibaba/aliyun-egg.svg?style=flat-square
17+
[david-url]: https://david-dm.org/alibaba/aliyun-egg
18+
[download-image]: https://img.shields.io/npm/dm/aliyun-egg.svg?style=flat-square
19+
[download-url]: https://npmjs.org/package/aliyun-egg
20+
21+
Egg framework for Aliyun.
22+
23+
## Requirement
24+
25+
- node >= 4.0.0
26+
27+
## Installation
28+
29+
```bash
30+
$ npm install aliyun-egg --save
31+
```
32+
33+
## Usage
34+
35+
//
36+
37+
## License
38+
39+
[MIT](LICENSE.txt)

appveyor.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
environment:
2+
matrix:
3+
- nodejs_version: '6'
4+
- nodejs_version: '7'
5+
6+
install:
7+
- ps: Install-Product node $env:nodejs_version
8+
- npm i npminstall && node_modules\.bin\npminstall
9+
10+
test_script:
11+
- node --version
12+
- npm --version
13+
- npm run ci
14+
15+
build: off

config/config.default.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
exports.core = {
4+
name: 'aliyun-egg',
5+
};
6+
exports.alinode = {
7+
enable: false,
8+
server: '',
9+
appid: '',
10+
secret: '',
11+
};

config/plugin.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
module.exports = {
4+
alinode: {
5+
enable: false,
6+
package: 'egg-alinode',
7+
},
8+
oss: {
9+
enable: true,
10+
package: 'egg-oss',
11+
},
12+
mysql: {
13+
enable: true,
14+
package: 'egg-mysql',
15+
},
16+
17+
view: {
18+
enable: true,
19+
package: 'egg-view-nunjucks',
20+
},
21+
};

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./lib/aliyun-egg');

lib/aliyun-egg.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const egg = require('egg');
4+
const path = require('path');
5+
6+
const EGG_PATH = path.dirname(__dirname);
7+
const startCluster = egg.startCluster;
8+
9+
class AliyunEggApplication extends egg.Application {
10+
get [Symbol.for('egg#eggPath')]() {
11+
return EGG_PATH;
12+
}
13+
}
14+
15+
class AliyunAgent extends egg.Agent {
16+
get [Symbol.for('egg#eggPath')]() {
17+
return EGG_PATH;
18+
}
19+
}
20+
21+
exports.Application = AliyunEggApplication;
22+
exports.Agent = AliyunAgent;
23+
exports.startCluster = function(options, callback) {
24+
options = options || {};
25+
options.customEgg = EGG_PATH;
26+
startCluster(options, callback);
27+
};

package.json

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "aliyun-egg",
3+
"version": "0.1.0",
4+
"description": "egg framework for aliyun",
5+
"keywords": [
6+
"egg", "egg-framework", "aliyun"
7+
],
8+
"files": [
9+
"index.js",
10+
"app.js",
11+
"agent.js",
12+
"lib",
13+
"config"
14+
],
15+
"dependencies": {
16+
"egg": "^0.8.0",
17+
"egg-alinode": "^1.1.0",
18+
"egg-mysql": "^1.0.1",
19+
"egg-oss": "^1.0.0",
20+
"egg-view-nunjucks": "^1.0.0"
21+
},
22+
"devDependencies": {
23+
"ali-oss": "^4.8.0",
24+
"autod": "^2.7.1",
25+
"egg-bin": "^2.0.1",
26+
"egg-mock": "^2.1.0",
27+
"eslint": "^3.13.1",
28+
"eslint-config-egg": "^3.2.0",
29+
"rimraf": "^2.5.4",
30+
"supertest": "^2.0.1"
31+
},
32+
"engines": {
33+
"node": ">=6.0.0"
34+
},
35+
"scripts": {
36+
"test": "npm run lint -- --fix && npm run test-local",
37+
"test-local": "egg-bin test ",
38+
"cov": "egg-bin cov",
39+
"lint": "eslint .",
40+
"ci": "npm run lint && npm run cov",
41+
"autod": "autod"
42+
},
43+
"ci": {
44+
"version": "6, 7"
45+
},
46+
"repository": {
47+
"type": "git",
48+
"url": "https://github.com/eggjs/aliyun-egg"
49+
},
50+
"author": "jtyjty99999 <[email protected]> (https://github.com/jtyjty99999)",
51+
"license": "MIT"
52+
}

test/.setup.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
const execSync = require('child_process').execSync;
4+
5+
execSync('mysql -uroot -e "create database IF NOT EXISTS test;"');
6+
execSync('mysql -uroot test < test/npm.sql');
7+
console.log('create table success');

test/aliyun-egg.test.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
'use strict';
2+
3+
const request = require('supertest');
4+
const mm = require('egg-mock');
5+
const oss = require('ali-oss');
6+
const config = require('./fixtures/apps/oss/config/config.default').oss.client;
7+
const assert = require('assert');
8+
const env = process.env;
9+
const region = env.ALI_SDK_OSS_REGION || 'oss-cn-hangzhou';
10+
const utils = require('./utils');
11+
12+
describe('test/aliyun-egg.test.js', () => {
13+
describe('render', () => {
14+
let app;
15+
before(() => {
16+
app = utils.createApp('apps/web');
17+
return app.ready();
18+
});
19+
20+
it('should render', () => {
21+
return request(app.callback())
22+
.get('/')
23+
.expect('world')
24+
.expect(200);
25+
});
26+
});
27+
28+
describe.skip('oss plugin test', () => {
29+
let app;
30+
let lastUploadFileName;
31+
before(function* () {
32+
const ossConfig = {
33+
accessKeyId: config.accessKeyId,
34+
accessKeySecret: config.accessKeySecret,
35+
endpoint: config.endpoint,
36+
region,
37+
callbackServer: 'http://d.rockuw.com:4567',
38+
};
39+
const store = oss(ossConfig);
40+
const bucket = 'ali-oss-test-bucket-test99';
41+
const result = yield store.putBucket(bucket, region);
42+
assert(result.bucket === bucket);
43+
assert(result.res.status === 200);
44+
app = utils.createApp('apps/oss');
45+
return app.ready();
46+
});
47+
48+
after(function* () {
49+
if (lastUploadFileName) {
50+
yield app.oss.delete(lastUploadFileName);
51+
}
52+
app.close();
53+
});
54+
55+
it('should upload file stream to oss', function* () {
56+
const result = yield request(app.callback()).get('/uploadtest').expect(200);
57+
lastUploadFileName = result.body.name;
58+
assert(typeof result.body.name === 'string');
59+
assert(/^http:\/\/ali\-oss\-test\-bucket\-test99.oss\-test.aliyun\-inc.com/.test(result.body.url));
60+
assert(result.body.res.status === 200);
61+
});
62+
});
63+
64+
describe('mysql plugin test', () => {
65+
let app;
66+
before(() => {
67+
app = utils.createApp('apps/mysqlapp-new');
68+
return app.ready();
69+
});
70+
71+
it('should query', () => {
72+
return request(app.callback())
73+
.get('/')
74+
.expect(200);
75+
});
76+
});
77+
});
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const co = require('co');
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
module.exports = function(agent) {
8+
const done = agent.readyCallback('agent-mysql');
9+
const p = path.join(__dirname, 'run/agent_result.json');
10+
fs.existsSync(p) && fs.unlinkSync(p);
11+
12+
co(function* () {
13+
const result = yield agent.mysql.query('select now() as currentTime;');
14+
fs.writeFileSync(p, JSON.stringify(result));
15+
}).then(done, done);
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
module.exports = function* () {
4+
const users = yield this.service.user.list(this);
5+
this.body = {
6+
status: 'success',
7+
users,
8+
};
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = function(app) {
4+
app.get('/', app.controller.home);
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
exports.list = function* (ctx) {
4+
return yield ctx.app.mysql.query('select * from npm_auth');
5+
};

0 commit comments

Comments
 (0)