Skip to content

Commit 2d648c6

Browse files
committed
Updated
1 parent c0f09ca commit 2d648c6

Some content is hidden

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

98 files changed

+2916
-0
lines changed

dev/cgi/jsonp/mta.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
callback({
2+
sid: '500006392'
3+
});

dev/cgi/ping/b.json

Whitespace-only changes.

dev/cgi/ping/img.gif

35 Bytes
Loading

gulp/.eslintrc

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
"parser": "babel-eslint",
3+
4+
"env": {
5+
"browser": true,
6+
"amd": true,
7+
"jasmine": true,
8+
"node": true,
9+
"es6": true
10+
},
11+
12+
"globals": {
13+
"LBF": true,
14+
"$": true,
15+
"jQuery": true,
16+
"setImmediate": true,
17+
"ActiveXObject": true,
18+
"unescape": true,
19+
"escape": true,
20+
"__VERSION__": true,
21+
"__DEV__": true,
22+
"__ENV__": true,
23+
"__DEBUG__": true
24+
},
25+
26+
"parserOptions": {
27+
"ecmaVersion": 6,
28+
"sourceType": "module"
29+
},
30+
31+
"rules": {
32+
"indent": [2, 4, {"SwitchCase": 1}],
33+
"quote-props": 0,
34+
"max-statements": [1, 50],
35+
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
36+
"valid-jsdoc": [2, {
37+
"prefer": {
38+
"arg": "param",
39+
"argument": "param",
40+
"returns": "return",
41+
"fileoverview": "file"
42+
},
43+
"requireReturn": false,
44+
"requireReturnDescription": false,
45+
"requireParamDescription": true
46+
}],
47+
"eol-last": 2,
48+
"space-infix-ops": 2,
49+
"dot-notation": 0,
50+
51+
"no-console": 1,
52+
"no-constant-condition": 1,
53+
"comma-dangle": 2,
54+
"no-debugger": 2,
55+
"no-dupe-keys": 1,
56+
"no-empty-character-class": 2,
57+
"no-ex-assign": 2,
58+
"no-extra-boolean-cast": 1,
59+
"no-extra-semi": 2,
60+
"no-func-assign": 1,
61+
"no-inner-declarations": 1,
62+
"no-invalid-regexp": 2,
63+
"no-negated-in-lhs": 2,
64+
"no-obj-calls": 2,
65+
"no-sparse-arrays": 2,
66+
"no-unreachable": 2,
67+
"use-isnan": 2,
68+
69+
"valid-typeof": 2,
70+
71+
"curly": [2, "all"],
72+
"eqeqeq": [2, "allow-null"],
73+
"guard-for-in": 1,
74+
"no-else-return": 1,
75+
"no-labels": 1,
76+
"no-eval": 2,
77+
"no-extend-native": 2,
78+
"no-extra-bind": 1,
79+
"no-implied-eval": 1,
80+
"no-iterator": 2,
81+
"no-irregular-whitespace": 1,
82+
"no-lone-blocks": 1,
83+
"no-loop-func": 1,
84+
"no-multi-str": 1,
85+
"no-native-reassign": 2,
86+
"no-new-wrappers": 2,
87+
"no-octal": 1,
88+
"no-octal-escape": 1,
89+
"no-proto": 2,
90+
"no-redeclare": 1,
91+
"no-self-compare": 2,
92+
"no-unneeded-ternary": 2,
93+
"no-with": 1,
94+
"radix": 2,
95+
"wrap-iife": [2, "any"],
96+
97+
"no-delete-var": 1,
98+
"no-dupe-args": 2,
99+
"no-duplicate-case": 2,
100+
"no-label-var": 1,
101+
"no-shadow-restricted-names": 2,
102+
"no-undef": 2,
103+
"no-undef-init": 1,
104+
"no-unused-vars": [1, {"vars": "local", "args": "none"}],
105+
"no-use-before-define": [2, "nofunc"],
106+
107+
"brace-style": [1, "stroustrup", {}],
108+
"comma-spacing": [2, {"before": false, "after": true}],
109+
"comma-style": [2, "last"],
110+
"new-cap": [2, {"capIsNewExceptions": ["T", "AddToFavoritesBar"]}],
111+
"new-parens": 1,
112+
"no-array-constructor": 2,
113+
"no-new-object": 2,
114+
"no-spaced-func": 2,
115+
"no-trailing-spaces": 2,
116+
"no-extra-parens": [2, "functions"],
117+
"no-mixed-spaces-and-tabs": 2,
118+
"one-var": [2, "never"],
119+
"operator-linebreak": [2, "before"],
120+
"quotes": [2, "single", {"avoidEscape": true, "allowTemplateLiterals": true}],
121+
"semi": [2, "always"],
122+
"semi-spacing": 2,
123+
"keyword-spacing": 2,
124+
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
125+
"space-before-blocks": [2, "always"],
126+
"array-bracket-spacing": [2, "never"],
127+
"computed-property-spacing": [2, "never"],
128+
"object-curly-spacing": [2, "never"],
129+
"space-in-parens": [2, "never"],
130+
"space-unary-ops": 1,
131+
"spaced-comment": [2, "always", {"exceptions": ["-", "+", ""]}],
132+
"max-nested-callbacks": [1, 3],
133+
134+
"max-depth": [1, 6],
135+
"max-len": [2, 120, 4, {
136+
"ignoreUrls": true,
137+
"ignoreComments": true,
138+
"ignorePattern": "\\+ [\\w\\W]+>'"
139+
}],
140+
"max-params": [1, 6]
141+
}
142+
}

gulp/config/config.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @file configs
3+
*/
4+
const version = require('../../package.json').version;
5+
6+
module.exports = {
7+
version: version,
8+
url: {
9+
app: '/S3',
10+
cgi: '/cgi'
11+
},
12+
path: {
13+
src: './src',
14+
test: './test',
15+
dest: './dist',
16+
cgi: './dev/cgi'
17+
},
18+
port: {
19+
// connect 端口
20+
connect: 8888
21+
},
22+
compress: false
23+
};

gulp/middleware/cgi.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const url = require('url');
2+
const path = require('path');
3+
const fs = require('fs');
4+
const config = require('../config/getConfig')();
5+
6+
module.exports = function (req, res, next) {
7+
let pathname = url.parse(req.url).pathname.replace(config.url.cgi, '');
8+
const parts = pathname.split('/');
9+
parts.shift();
10+
pathname = path.join(...parts);
11+
const filePath = path.normalize(path.join(config.path.cgi, `${pathname}.json`));
12+
13+
function response(file) {
14+
let body = file || '';
15+
const isImg = (parts[0] === 'ping') && (req.method === 'GET');
16+
if (isImg) {
17+
body = fs.readFileSync(path.normalize(path.join(config.path.cgi, '/ping/img.gif')));
18+
}
19+
res.writeHead(200, {
20+
// 'Content-Length': Buffer.byteLength(body),
21+
'Content-Type': parts[0] === 'ping'
22+
? (req.method === 'GET' ? 'image/gif' : 'plain/text')
23+
: 'application/javascript'
24+
});
25+
res.end(body, isImg ? 'binary' : null);
26+
}
27+
28+
fs.readFile(filePath, function (err, file) {
29+
if (err) {
30+
const jsFilePath = path.normalize(path.join(config.path.cgi, `${pathname}.js`));
31+
fs.readFile(jsFilePath, function (err, file) {
32+
if (err) {
33+
next(err);
34+
return;
35+
}
36+
response(file);
37+
});
38+
return;
39+
}
40+
response(file);
41+
});
42+
};

gulp/middleware/favicon.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
module.exports = function (req, res, next) {
4+
res.end();
5+
};

gulp/tasks/build.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const gulp = require('gulp');
2+
3+
gulp.task('build', ['rollup']);

gulp/tasks/default.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const gulp = require('gulp');
2+
3+
gulp.task('default', ['server']);

gulp/tasks/rollup.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const path = require('path');
2+
const gulp = require('gulp');
3+
const rollup = require('rollup').rollup;
4+
const alias = require('rollup-plugin-alias');
5+
const minify = require('uglify-js').minify;
6+
const config = require('../config/config');
7+
8+
function uglify(options = {}, minifier = minify) {
9+
return {
10+
name: 'uglify',
11+
12+
transformBundle(code) {
13+
options.fromString = true;
14+
delete options.inSourceMap;
15+
delete options.outSourceMap;
16+
17+
// trigger sourcemap generation
18+
if (options.sourceMap !== false) {
19+
options.outSourceMap = 'x';
20+
}
21+
22+
const result = minifier(code, options);
23+
24+
// Strip sourcemaps comment and extra \n
25+
if (result.map) {
26+
const commentPos = result.code.lastIndexOf('//#');
27+
result.code = result.code.slice(0, commentPos).trim();
28+
}
29+
30+
return result;
31+
}
32+
};
33+
}
34+
35+
gulp.task('rollup', function () {
36+
var rollups = [];
37+
var varConfig = config;
38+
var plugins = [];
39+
40+
if (varConfig.path.alias) {
41+
plugins.push(alias(varConfig.path.alias));
42+
}
43+
44+
if (varConfig.compress) {
45+
plugins.push(uglify());
46+
}
47+
48+
for (var entry in varConfig.path.entrys) {
49+
if (!varConfig.path.entrys.hasOwnProperty(entry)) {
50+
continue;
51+
}
52+
53+
var fileName = entry + '.js';
54+
var destFile = path.resolve(varConfig.path.dest, fileName);
55+
var r = rollup({
56+
entry: path.resolve(varConfig.path.src, varConfig.path.entrys[entry]),
57+
plugins: plugins
58+
})
59+
.then((function (e, dest) {
60+
return function (bundle) {
61+
return bundle.write({
62+
format: 'iife',
63+
dest: dest,
64+
useStrict: false
65+
});
66+
};
67+
})(entry, destFile));
68+
rollups.push(r);
69+
}
70+
return Promise.all(rollups);
71+
});

gulp/tasks/server.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
const gulp = require('gulp');
3+
const connect = require('connect');
4+
const http = require('http');
5+
const serveStatic = require('serve-static');
6+
const favicon = require('../middleware/favicon');
7+
const cgi = require('../middleware/cgi');
8+
const config = require('../config/config');
9+
10+
const startConnect = () => {
11+
const app = connect();
12+
// 提供favicon
13+
app.use('/favicon.ico', favicon);
14+
// 模拟假数据
15+
app.use(config.url.cgi, cgi);
16+
app.use(config.url.app, serveStatic(config.path.dest));
17+
18+
http.createServer(app).listen(config.port.connect);
19+
};
20+
21+
22+
gulp.task('server', ['rollup', 'watch'], function (callback) {
23+
startConnect();
24+
});

gulp/tasks/watch.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const gulp = require('gulp');
2+
const config = require('../config/config');
3+
4+
gulp.task('watch', function () {
5+
gulp.watch(`${config.path.src}/**/*.js`, ['rollup']);
6+
gulp.watch(`${config.path.test}/**/*.js`, ['rollup']);
7+
});

gulpfile.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
gulpfile.js
3+
===========
4+
Rather than manage one giant configuration file responsible
5+
for creating multiple tasks, each task has been broken out into
6+
its own file in gulp/tasks. Any files in that directory get
7+
automatically required below.
8+
9+
To add a new task, simply add a new task file that directory.
10+
gulp/tasks/default.js specifies the default set of tasks to run
11+
when you run `gulp`.
12+
*/
13+
14+
require('babel-core/register');
15+
var requireDir = require('require-dir');
16+
17+
// Require all tasks in gulp/tasks, including subfolders
18+
requireDir('./gulp/tasks', {recurse: true});

package.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "qidian_da",
3+
"version": "0.6.3",
4+
"description": "",
5+
"main": "src/index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "zmmbreeze / @zhoumm",
10+
"license": "MIT",
11+
"keywords": [
12+
"es6",
13+
"third",
14+
"script",
15+
"javascript",
16+
"tools"
17+
],
18+
"devDependencies": {
19+
"babel-core": "5.8.35",
20+
"babel-eslint": "5.0.0-beta6",
21+
"babel-loader": "5.4.0",
22+
"babel-runtime": "5.8.35",
23+
"connect": "3.4.0",
24+
"eslint": "2.13.1",
25+
"eslint-plugin-react": "3.15.0",
26+
"expect.js": "^0.3.1",
27+
"glob": "6.0.4",
28+
"gulp": "3.9.0",
29+
"gulp-contrib-copy": "0.1.2",
30+
"gulp-rename": "1.2.2",
31+
"gulp-util": "3.0.7",
32+
"inline-source": "4.2.4",
33+
"merge": "1.2.0",
34+
"merge-stream": "1.0.0",
35+
"mocha": "^3.2.0",
36+
"require-dir": "0.1.0",
37+
"rollup": "0.34.10",
38+
"rollup-plugin-alias": "1.2.0",
39+
"rollup-plugin-multi-entry": "2.0.1",
40+
"rollup-plugin-replace": "1.1.1",
41+
"serve-static": "1.11.1",
42+
"uglify-js": "2.7.3",
43+
"vinyl-buffer": "1.0.0",
44+
"vinyl-source-stream": "0.1.1"
45+
}
46+
}

0 commit comments

Comments
 (0)