Authored by ccbikai

增加代码检查

{
"extends": "yoho"
}
... ...
{
"extends": "stylelint-config-yoho"
}
... ...
/**
* yohobuy app
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars'),
bodyParser = require('body-parser'),
favicon = require('serve-favicon'),
cookieParser = require('cookie-parser');
var app = express();
app.set('view engine', '.hbs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// dispatcher
require('./dispatch')(app);
// listener
app.listen(3000, function() {
console.log('yohobuy start');
});
\ No newline at end of file
/**
* yohobuy app
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars'),
bodyParser = require('body-parser'),
favicon = require('serve-favicon'),
cookieParser = require('cookie-parser');
var app = express();
app.set('view engine', '.hbs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// dispatcher
require('./dispatch')(app);
// listener
app.listen(3000, function() {
console.log('yohobuy start');
});
... ...
/**
* 路由分发
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/27
*/
module.exports = app => {
//公共服务
//业务模块
app.use('/guang', require('./apps/guang'));
};
/**
* 路由分发
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/27
*/
module.exports = app => {
// 公共服务
// 业务模块
app.use('/guang', require('./apps/guang'));
};
... ...
/**
* 登录判断
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
module.exports = (req, res, next) => {
next();
};
\ No newline at end of file
/**
* 登录判断
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
module.exports = (req, res, next) => {
next();
};
... ...
... ... @@ -10,4 +10,4 @@ const router = require('express').Router();
const cRoot = './controllers';
module.exports = router;
\ No newline at end of file
module.exports = router;
... ...
/**
* 接口公共方法
* @author: xuqiMqi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
const rp = require('request-promise');
const _ = require('lodash');
class API {
/**
* get
* @param url String
* @param data Obejct
*/
get(url, data) {
return rp({
url: `${this.server}${url}`,
qs: data
});
}
/**
* multi get
* @params: urls => Array[Object[url[string], data[object]]]
*/
multiGet(urls) {
var rps = [],
self = this;
_.forEach(urls, function(el) {
rps.push(rp({
url: `${self.server}${el.url}`,
qs: el.data
}));
});
return Promise.all(rps).then((d) => {
return d;
});
}
/**
* post
* @param url String
* @param data Obejct
*/
post(url, data) {
return rp({
url: `${this.server}${url}`,
method: 'post',
form: data
});
}
}
module.exports = API;
\ No newline at end of file
/**
* 接口公共方法
* @author: xuqiMqi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
const rp = require('request-promise');
const _ = require('lodash');
class API {
/**
* get
* @param url String
* @param data Obejct
*/
get(url, data) {
return rp({
url: `${this.server}${url}`,
qs: data
});
}
/**
* multi get
* @params: urls => Array[Object[url[string], data[object]]]
*/
multiGet(urls) {
var rps = [],
self = this;
_.forEach(urls, function(el) {
rps.push(rp({
url: `${self.server}${el.url}`,
qs: el.data
}));
});
return Promise.all(rps).then((d) => {
return d;
});
}
/**
* post
* @param url String
* @param data Obejct
*/
post(url, data) {
return rp({
url: `${this.server}${url}`,
method: 'post',
form: data
});
}
}
module.exports = API;
... ...
{
"name": "m-yohobuy-node",
"version": "0.0.1",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
"type": "git",
"url": "http://git.dev.yoho.cn/web/yohobuy-node.git"
},
"scripts": {
"start": "node app.js",
"dev": "node_modules/.bin/nodemon -e js,hbs -i public/ app.js",
"online": "NODE_ENV=\"production\" node app.js",
"debug": "DEBUG=\"express:*\" node app.js",
"lint-js": "node_modules/.bin/eslint -c .eslintrc --cache --fix `git diff --cached --name-only --diff-filter=ACM | grep .js$` app.js",
"lint-css": "node_modules/.bin/stylelint --config .stylelintrc `git diff --cached --name-only --diff-filter=ACM | grep .css$`",
"precommit": "npm run lint-js && npm run lint-css"
},
"license": "MIT",
"dependencies": {
"body-parser": "^1.15.0",
... ... @@ -15,17 +25,19 @@
"lodash": "^4.8.2",
"morgan": "^1.7.0",
"request-promise": "^2.0.1",
"serve-favicon": "^2.3.0",
"shelljs": "^0.7.0"
"serve-favicon": "^2.3.0"
},
"devDependencies": {
"autoprefixer": "^6.3.6",
"eslint": "^2.9.0",
"eslint-config-yoho": "^1.0.1",
"gulp": "^3.9.1",
"gulp-cssnano": "^2.1.2",
"gulp-ftp": "^1.1.0",
"gulp-postcss": "^6.1.0",
"gulp-sourcemaps": "^2.0.0-alpha",
"gulp-util": "^3.0.7",
"husky": "^0.11.4",
"postcss-assets": "^4.0.1",
"postcss-cachebuster": "^0.1.2",
"postcss-calc": "^5.2.1",
... ... @@ -38,8 +50,11 @@
"postcss-sprites": "^3.1.2",
"postcss-use": "^2.0.2",
"precss": "^1.4.0",
"stylelint": "^6.2.2",
"stylelint-config-yoho": "^1.2.0",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.14.1",
"webpack-stream": "^3.1.0"
"webpack-stream": "^3.1.0",
"shelljs": "^0.7.0"
}
}
... ...
/**
* Yohobuy 构建脚本
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
const gulp = require('gulp');
const gutil = require('gulp-util');
const ftp = require('gulp-ftp');
const postcss = require('gulp-postcss');
const sourcemaps = require('gulp-sourcemaps');
const cssnano = require('gulp-cssnano');
const webpack = require('webpack');
const webpackDevServer = require('webpack-dev-server');
const webpackConfig = require('./webpack.config.js');
const env = {
dev: Symbol('development'),
pro: Symbol('production')
};
const config = require('../package.json');
const ftpConfig = {
host: '218.94.75.50',
user: 'php',
pass: 'yoho9646'
};
const distRoot = `dist/${config.name}`;
const dist = {
js: `${distRoot}/${config.version}`,
css: `${distRoot}/${config.version}`,
assets: `${distRoot}/assets`,
img: `${distRoot}/assets/img`,
font: `${distRoot}/assets/font`
};
/**
* postcss plugins for both dev and pro
* @parem et Symbol
*/
const postcssPlugin = (et) => {
var sprites = {
spritesmith: {
padding: 2
},
groupBy(file) {
var group = file.url.split('/')[1];
group = group === '' ? 'yo' : group;
return group ? Promise.resolve(group) : Promise.reject(group);
}
},
assets,
plugins;
// assets & sprites config in both dev and pro
if (et === env.pro) {
assets = {
loadPaths: [dist.img, dist.font],
};
Object.assign(sprites, {
basePath: dist.img,
stylesheetPath: dist.css,
spritePath: dist.img
});
} else if (et === env.dev) {
assets = {
loadPaths: ['img/', 'font/'],
relativeTo: 'css/'
};
Object.assign(sprites, {
basePath: 'img/',
stylesheetPath: 'css/',
spritePath: 'img/'
});
};
plugins = [
require('autoprefixer')({
browsers: ['> 1%']
}),
require('precss'),
require('postcss-sprites').default(sprites),
require('postcss-assets')(assets),
require('postcss-calc'),
require('postcss-opacity'),
//可选
require('postcss-use')({
modules: ['postcss-clearfix', 'postcss-crip', 'postcss-short', 'postcss-center', 'postcss-position']
})
];
if (et === env.pro) {
plugins.push(require('postcss-cachebuster')({
imagesPath: `/${dist.img}`,
cssPath: `/${dist.css}`
}));
}
return plugins;
};
// default
gulp.task('default', ['postcss-dev', 'postcss-watch', 'webpack-dev-server']);
// ge
gulp.task('ge', ['postcss', 'webpack']);
// dist
gulp.task('dist', ['ge'], () => {
var ftpstream = ftp(ftpConfig);
return gulp.src('dist/**/')
.pipe(ftpstream)
.pipe(gutil.noop());
});
// postcss compile in dev
gulp.task('postcss-dev', () => {
return gulp.src('scss/index.css')
.pipe(sourcemaps.init())
.pipe(postcss(postcssPlugin(env.dev)))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('css/'));
});
// postcss file watch
gulp.task('postcss-watch', () => {
gulp.watch('scss/**/*.css', ['postcss-dev']);
});
// copy assets
gulp.task('assets', ['img', 'font']);
// copy img
gulp.task('img', () => {
return gulp.src('img/**/*')
.pipe(gulp.dest(dist.img));
});
//copy font
gulp.task('font', () => {
return gulp.src('font/*')
.pipe(gulp.dest(dist.font));
});
// postcss compile in pro
gulp.task('postcss', ['assets'], () => {
return gulp.src('scss/index.css')
.pipe(postcss(postcssPlugin(env.pro)))
.pipe(cssnano())
.pipe(gulp.dest(dist.css));
});
// webpack dev server
gulp.task('webpack-dev-server', () => {
var devConfig = Object.assign({}, webpackConfig, {
debug: true
});
new webpackDevServer(webpack(devConfig), {
contentBase: '.',
publicPath: '//localhost:8000/',
hot: true,
stats: {
colors: true
}
}).listen(8000, 'localhost', (err) => {
if (err) {
throw new gutil.PluginError('webpack-dev-server', err);
}
gutil.log('[webpack-serve]', 'http://localhost:8000/');
});
});
// webpack compile in pro
gulp.task('webpack', () => {
var proConfig = Object.assign({}, webpackConfig);
proConfig.output.path = dist.js;
webpack(proConfig, (err, stats) => {
if (err) {
throw new gutil.PluginError('webpack', err);
}
});
});
\ No newline at end of file
/**
* Yohobuy 构建脚本
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
const gulp = require('gulp');
const gutil = require('gulp-util');
const ftp = require('gulp-ftp');
const postcss = require('gulp-postcss');
const sourcemaps = require('gulp-sourcemaps');
const cssnano = require('gulp-cssnano');
const webpack = require('webpack');
const webpackDevServer = require('webpack-dev-server');
const webpackConfig = require('./webpack.config.js');
const env = {
dev: Symbol('development'),
pro: Symbol('production')
};
const config = require('../package.json');
const ftpConfig = {
host: '218.94.75.50',
user: 'php',
pass: 'yoho9646'
};
const distRoot = `dist/${config.name}`;
const dist = {
js: `${distRoot}/${config.version}`,
css: `${distRoot}/${config.version}`,
assets: `${distRoot}/assets`,
img: `${distRoot}/assets/img`,
font: `${distRoot}/assets/font`
};
/**
* postcss plugins for both dev and pro
* @parem et Symbol
*/
const postcssPlugin = (et) => {
var sprites = {
spritesmith: {
padding: 2
},
groupBy(file) {
var group = file.url.split('/')[1];
group = group === '' ? 'yo' : group;
return group ? Promise.resolve(group) : Promise.reject(group);
}
},
assets,
plugins;
// assets & sprites config in both dev and pro
if (et === env.pro) {
assets = {
loadPaths: [dist.img, dist.font]
};
Object.assign(sprites, {
basePath: dist.img,
stylesheetPath: dist.css,
spritePath: dist.img
});
} else if (et === env.dev) {
assets = {
loadPaths: ['img/', 'font/'],
relativeTo: 'css/'
};
Object.assign(sprites, {
basePath: 'img/',
stylesheetPath: 'css/',
spritePath: 'img/'
});
}
plugins = [
require('autoprefixer')({
browsers: ['> 1%']
}),
require('precss'),
require('postcss-sprites').default(sprites),
require('postcss-assets')(assets),
require('postcss-calc'),
require('postcss-opacity'),
// 可选
require('postcss-use')({
modules: ['postcss-clearfix', 'postcss-crip', 'postcss-short', 'postcss-center', 'postcss-position']
})
];
if (et === env.pro) {
plugins.push(require('postcss-cachebuster')({
imagesPath: `/${dist.img}`,
cssPath: `/${dist.css}`
}));
}
return plugins;
};
// default
gulp.task('default', ['postcss-dev', 'postcss-watch', 'webpack-dev-server']);
// ge
gulp.task('ge', ['postcss', 'webpack']);
// dist
gulp.task('dist', ['ge'], () => {
var ftpstream = ftp(ftpConfig);
return gulp.src('dist/**/')
.pipe(ftpstream)
.pipe(gutil.noop());
});
// postcss compile in dev
gulp.task('postcss-dev', () => {
return gulp.src('scss/index.css')
.pipe(sourcemaps.init())
.pipe(postcss(postcssPlugin(env.dev)))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('css/'));
});
// postcss file watch
gulp.task('postcss-watch', () => {
gulp.watch('scss/**/*.css', ['postcss-dev']);
});
// copy assets
gulp.task('assets', ['img', 'font']);
// copy img
gulp.task('img', () => {
return gulp.src('img/**/*')
.pipe(gulp.dest(dist.img));
});
// copy font
gulp.task('font', () => {
return gulp.src('font/*')
.pipe(gulp.dest(dist.font));
});
// postcss compile in pro
gulp.task('postcss', ['assets'], () => {
return gulp.src('scss/index.css')
.pipe(postcss(postcssPlugin(env.pro)))
.pipe(cssnano())
.pipe(gulp.dest(dist.css));
});
// webpack dev server
gulp.task('webpack-dev-server', () => {
var devConfig = Object.assign({}, webpackConfig, {
debug: true
});
new webpackDevServer(webpack(devConfig), {
contentBase: '.',
publicPath: '//localhost:8000/',
hot: true,
stats: {
colors: true
}
}).listen(8000, 'localhost', (err) => {
if (err) {
throw new gutil.PluginError('webpack-dev-server', err);
}
gutil.log('[webpack-serve]', 'http://localhost:8000/');
});
});
// webpack compile in pro
gulp.task('webpack', () => {
var proConfig = Object.assign({}, webpackConfig);
proConfig.output.path = dist.js;
webpack(proConfig, (err, stats) => {
if (err) {
throw new gutil.PluginError('webpack', err);
}
});
});
... ...
/**
* webpack config
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
const webpack = require('webpack');
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
require('shelljs/global');
var entries = {};
//构建各模块子页面JS。生成规则module.page.js
ls(__dirname + '/js/**/*.page.js').forEach((f) => {
var dir = _.slice(f.split('/'), -2); //[modulename, xx.page.js]
// Important
// 生成规则:module.page: './js/module/xx.page.js'
entries[`${dir[0]}.${dir[1].match(/(.*).page.js/)[1]}`] = `./js/${dir.join('/')}`;
});
module.exports = {
entry: entries,
output: {
path: path.join(__dirname, 'bundle'), //absolute path
filename: '[name].js'
}
};
\ No newline at end of file
/**
* webpack config
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
const webpack = require('webpack');
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
require('shelljs/global');
var entries = {};
// 构建各模块子页面JS。生成规则module.page.js
ls(__dirname + '/js/**/*.page.js').forEach((f) => {
var dir = _.slice(f.split('/'), -2); // [modulename, xx.page.js]
// Important
// 生成规则:module.page: './js/module/xx.page.js'
entries[`${dir[0]}.${dir[1].match(/(.*).page.js/)[1]}`] = `./js/${dir.join('/')}`;
});
module.exports = {
entry: entries,
output: {
path: path.join(__dirname, 'bundle'), // absolute path
filename: '[name].js'
}
};
... ...