Skip to content

Commit 419c773

Browse files
author
bin.cao
committed
init project structure, can not run.
1 parent 2dc1248 commit 419c773

21 files changed

+6045
-0
lines changed

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/dev/
2+
/prd/
3+
/refs/
4+
5+
6+
# kdiff3 ignore
7+
*.orig
8+
9+
# maven ignore
10+
target/
11+
12+
# eclipse ignore
13+
.settings/
14+
.project
15+
.classpath
16+
17+
# idea ignore
18+
.idea/
19+
*.ipr
20+
*.iml
21+
*.iws
22+
23+
# temp ignore
24+
*.log
25+
*.cache
26+
*.diff
27+
*.patch
28+
*.tmp
29+
30+
# system ignore
31+
.DS_Store
32+
Thumbs.db
33+
34+
# package ignore (optional)
35+
# *.jar
36+
# *.war
37+
# *.zip
38+
# *.tar
39+
# *.tar.gz
40+
41+
42+
.sass-cache
43+
/resource/
44+
/log/
45+
/node_modules/

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
###project initialize
2+
npm run init
3+
###run project
4+
one command window run: gulp dev
5+
another command window run: node app.js

app.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var express = require('express');
2+
var cookieParser = require('cookie-parser');
3+
var bodyParser = require('body-parser');
4+
var favicon = require('serve-favicon');
5+
var nodeAnnotation = require('node-annotation');
6+
7+
var fs = require('fs');
8+
var Path = require('path');
9+
10+
nodeAnnotation.setLogger(true);
11+
// nodeAnnotation.configurePath(Path.join(cwd, 'src', 'webApp', 'resource'));
12+
nodeAnnotation.start([
13+
Path.join(__dirname, 'src'),
14+
Path.join(__dirname, 'node_modules', 'node-annotation-extend', 'src')
15+
], function() {
16+
var app = express();
17+
18+
app.set('views', Path.join(__dirname, '/src/views'));
19+
app.set('view engine', 'ejs');
20+
app.use(bodyParser.json());
21+
app.use(bodyParser.urlencoded());
22+
app.use(cookieParser());
23+
app.use(express.static(Path.join(__dirname, 'public')));
24+
app.use('/prd', express.static(Path.join(__dirname, 'prd')));
25+
nodeAnnotation.app(app);
26+
//初始化数据库
27+
var sequelizeDB = require("./src/js/dao/mysql/common/sequelizeDB.js");
28+
var server = app.listen(3939, function() {
29+
console.log('Express server listening on port %d in %s mode', server.address().port, app.settings.env);
30+
});
31+
});

gulpfile.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
var Path = require('path');
2+
var gulp = require('gulp');
3+
var clean = require('gulp-clean');
4+
5+
/**************************
6+
* webpack *
7+
**************************/
8+
gulp.task('webpack', ['clean'], function() {
9+
var webpackConfig = require('./webpack.config');
10+
var gulpWebpack = require('gulp-webpack');
11+
12+
return gulp
13+
.src('prd')
14+
.pipe(clean())
15+
.pipe(gulpWebpack(webpackConfig))
16+
.pipe(gulp.dest('./prd'));
17+
});
18+
/**************************
19+
* clean *
20+
**************************/
21+
gulp.task('clean', function(){
22+
return gulp
23+
.src(Path.join('src', 'node_modules'))
24+
.pipe(clean());
25+
});
26+
/**************************
27+
* libDev *
28+
**************************/
29+
gulp.task('libDev', ['clean'], function() {
30+
//load concat the library
31+
//加快开发模式下模块编译的速度,提前把第三方库生成好
32+
return gulp
33+
.src(Path.join('src', 'development', '**', '*.*'))
34+
.pipe(gulp.dest(Path.join('src', 'node_modules')));
35+
});
36+
/**************************
37+
* webpack-dev-server *
38+
**************************/
39+
gulp.task('webpack-dev-server', ['libDev'], function() {
40+
41+
//start webpack develop server
42+
var webpackConfig = require('./webpack.dev.config');
43+
var WebpackDevServer = require('webpack-dev-server');
44+
var webpack = require('webpack');
45+
46+
new WebpackDevServer(webpack(webpackConfig), {
47+
publicPath: webpackConfig.output.publicPath,
48+
hot: true,
49+
noInfo: false,
50+
historyApiFallback: true,
51+
proxy: [{
52+
path: /^\/f\//,
53+
ignorePath: true,
54+
target: 'http://127.0.0.1:3000/html/index.html'
55+
}]
56+
}).listen(3000, 'localhost', function(err, result) {
57+
if (err) console.log(err);
58+
console.log('Listening at localhost:3000');
59+
});
60+
});
61+
/**************************
62+
* copy profiles *
63+
**************************/
64+
gulp.task('copyProfile', function() {
65+
var allowEnv = ['dev', 'beta', 'prod'];
66+
var env = process.argv[2] || allowEnv[0];
67+
if (allowEnv.indexOf(env) === -1) {
68+
env = allowEnv[0];
69+
}
70+
return gulp.src(Path.join(__dirname, 'src', 'profiles', env, '*'))
71+
.pipe(gulp.dest(Path.join(__dirname, 'resource')));
72+
});
73+
/**************************
74+
* Main *
75+
**************************/
76+
gulp.task('default', function() {
77+
console.info('demo');
78+
});
79+
gulp.task('dev', ['copyProfile', 'webpack-dev-server']);
80+
gulp.task('beta', ['webpack']);
81+
gulp.task('prod', ['webpack']);

makeFekitVerPlugin.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var fs = require('fs'),
2+
path = require('path');
3+
4+
var makeFekitVerPlugin = function(verPath, spliter) {
5+
this.verPath = verPath || __dirname;
6+
this.spliter = spliter || '@';
7+
}
8+
9+
makeFekitVerPlugin.prototype.apply = function(compiler) {
10+
var that = this;
11+
compiler.plugin("done", function(stats) {
12+
var json = stats.toJson();
13+
var hash = json.hash,
14+
files = json.assets//json.assetsByChunkName;
15+
ensureDir([
16+
path.join(that.verPath, 'ver'),
17+
path.join(that.verPath, 'ver/scripts'),
18+
path.join(that.verPath, 'ver/styles')
19+
], fs.W_OK);
20+
var all = "";
21+
files.forEach(function(file){
22+
var fullname = file.name;
23+
var name = fullname.replace(that.spliter + hash, '');
24+
fs.writeFileSync(path.join(that.verPath, 'ver/' + name + '.ver'), hash);
25+
all += fullname + '\n';
26+
});
27+
fs.writeFileSync(path.join(that.verPath, 'ver/versions.mapping'), all );
28+
});
29+
};
30+
31+
function ensureDir(paths, mode){
32+
paths.forEach(function(path){
33+
try {
34+
fs.accessSync(path, mode);
35+
} catch (e) {
36+
fs.mkdirSync(path);
37+
}
38+
});
39+
}
40+
41+
module.exports = makeFekitVerPlugin;

0 commit comments

Comments
 (0)