[build] added webapp task
This commit is contained in:
28
build/webapp.js
Normal file
28
build/webapp.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const gulp = require('gulp');
|
||||||
|
const concat = require('gulp-concat');
|
||||||
|
const uglify = require('gulp-uglify');
|
||||||
|
const babel = require('gulp-babel');
|
||||||
|
const template = require('gulp-template');
|
||||||
|
|
||||||
|
|
||||||
|
const index = () => function index() {
|
||||||
|
return gulp.src('src/webapp/index.html')
|
||||||
|
.pipe(template({
|
||||||
|
scripts: ['app.min.js'],
|
||||||
|
swf: 'tankz.swf'
|
||||||
|
}))
|
||||||
|
.pipe(gulp.dest('target'))
|
||||||
|
};
|
||||||
|
|
||||||
|
const js = () => function js() {
|
||||||
|
const src = [
|
||||||
|
'src/webapp/js/*.js'
|
||||||
|
];
|
||||||
|
return gulp.src(src)
|
||||||
|
.pipe(babel({presets: ['es2015']}))
|
||||||
|
.pipe(uglify())
|
||||||
|
.pipe(concat('app.min.js'))
|
||||||
|
.pipe(gulp.dest('target'))
|
||||||
|
};
|
||||||
|
|
||||||
|
exports['webapp'] = gulp.parallel(index(), js());
|
||||||
@@ -25,7 +25,7 @@ set :npm_env_variables, {}
|
|||||||
|
|
||||||
# gulp
|
# gulp
|
||||||
set :gulp_target_path, -> { release_path }
|
set :gulp_target_path, -> { release_path }
|
||||||
set :gulp_tasks, 'client'
|
set :gulp_tasks, 'default'
|
||||||
set :gulp_flags, '--no-color'
|
set :gulp_flags, '--no-color'
|
||||||
set :gulp_roles, :web
|
set :gulp_roles, :web
|
||||||
before 'deploy:updated', 'gulp'
|
before 'deploy:updated', 'gulp'
|
||||||
|
|||||||
@@ -30,5 +30,6 @@ exports.update = prepare.update;
|
|||||||
merge('./build/prepare');
|
merge('./build/prepare');
|
||||||
merge('./build/client');
|
merge('./build/client');
|
||||||
merge('./build/server');
|
merge('./build/server');
|
||||||
|
merge('./build/webapp');
|
||||||
|
|
||||||
exports.default = gulp.series(exports.clean, exports.client, exports.server);
|
exports.default = gulp.series(exports.clean, exports.client, exports.webapp);
|
||||||
@@ -5,12 +5,18 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ansi-colors": "^1.0.1",
|
"ansi-colors": "^1.0.1",
|
||||||
"async": "^2.6.0",
|
"async": "^2.6.0",
|
||||||
|
"babel-core": "^6.26.0",
|
||||||
|
"babel-preset-es2015": "^6.24.1",
|
||||||
"download": "^6.2.5",
|
"download": "^6.2.5",
|
||||||
"fancy-log": "^1.3.2",
|
"fancy-log": "^1.3.2",
|
||||||
"fs-extra": "^5.0.0",
|
"fs-extra": "^5.0.0",
|
||||||
"got": "^8.0.1",
|
"got": "^8.0.1",
|
||||||
"gulp": "github:gulpjs/gulp#4.0",
|
"gulp": "github:gulpjs/gulp#4.0",
|
||||||
|
"gulp-babel": "^7.0.0",
|
||||||
"gulp-clean": "^0.3.2",
|
"gulp-clean": "^0.3.2",
|
||||||
|
"gulp-concat": "^2.6.1",
|
||||||
|
"gulp-template": "^5.0.0",
|
||||||
|
"gulp-uglify": "^3.0.0",
|
||||||
"plugin-error": "^0.1.2",
|
"plugin-error": "^0.1.2",
|
||||||
"progress": "^2.0.0",
|
"progress": "^2.0.0",
|
||||||
"promise-streams": "^2.1.1",
|
"promise-streams": "^2.1.1",
|
||||||
|
|||||||
27
src/webapp/index.html
Normal file
27
src/webapp/index.html
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Tank'z</title>
|
||||||
|
<% scripts.forEach(function(script) { %>
|
||||||
|
<script type="text/javascript" src="<%-script%>"></script>
|
||||||
|
<% }); %>
|
||||||
|
<style type="text/css">
|
||||||
|
html, body, #container {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="container"></div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
new Swf(
|
||||||
|
document.getElementById('container'),
|
||||||
|
'<%-swf%>',
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
100
src/webapp/js/swf.js
Normal file
100
src/webapp/js/swf.js
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
const typeOf = (item) => {
|
||||||
|
if (item == null) return "null";
|
||||||
|
if (item.nodeName) {
|
||||||
|
if (item.nodeType == 1) return "element";
|
||||||
|
if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? "textnode" : "whitespace";
|
||||||
|
} else if (typeof item.length == "number") {
|
||||||
|
if (item.callee) return "arguments";
|
||||||
|
}
|
||||||
|
return typeof item;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Swf {
|
||||||
|
|
||||||
|
constructor(element, swf, options) {
|
||||||
|
this.id = Math.floor(Math.random() * 10000);
|
||||||
|
this.options = Object.assign({
|
||||||
|
quality: "high",
|
||||||
|
wMode: "opaque",
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
vars: {},
|
||||||
|
}, options);
|
||||||
|
this.element = element;
|
||||||
|
this.swf = swf;
|
||||||
|
this.data = {
|
||||||
|
params: {
|
||||||
|
id: this.id,
|
||||||
|
quality: this.options.quality,
|
||||||
|
allowScriptAccess: "always",
|
||||||
|
allowFullScreen: true,
|
||||||
|
wMode: this.options.wMode,
|
||||||
|
//base: base,
|
||||||
|
swLiveConnect: true
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
name: this.id,
|
||||||
|
width: this.options.width,
|
||||||
|
height: this.options.height
|
||||||
|
},
|
||||||
|
vars: this.options.vars
|
||||||
|
};
|
||||||
|
this.swf = Swf.buildFlashElement(swf, this.data);
|
||||||
|
this.element.appendChild(this.swf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static toFlashVars(object, base) {
|
||||||
|
var queryString = [];
|
||||||
|
for (var key in object) {
|
||||||
|
var value = object[key];
|
||||||
|
if (base) key = base + ":" + key;
|
||||||
|
var result;
|
||||||
|
switch (typeOf(value)) {
|
||||||
|
case "object":
|
||||||
|
result = this.toFlashVars(value, key);
|
||||||
|
break;
|
||||||
|
case "array":
|
||||||
|
var qs = {};
|
||||||
|
value.each(function (val, i) {
|
||||||
|
qs[i] = val;
|
||||||
|
});
|
||||||
|
result = this.toFlashVars(qs, key);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result = key + "=" + encodeURIComponent(value);
|
||||||
|
}
|
||||||
|
if (value != null) queryString.push(result);
|
||||||
|
}
|
||||||
|
return queryString.join("&");
|
||||||
|
}
|
||||||
|
|
||||||
|
static buildFlashElement(path, options) {
|
||||||
|
var params = options.params;
|
||||||
|
var vars = options.vars;
|
||||||
|
var properties = options.properties;
|
||||||
|
|
||||||
|
params.flashVars = this.toFlashVars(vars);
|
||||||
|
var isIE = /*@cc_on!@*/false;
|
||||||
|
if (isIE) {
|
||||||
|
properties.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
|
||||||
|
params.movie = path;
|
||||||
|
} else {
|
||||||
|
properties.type = "application/x-shockwave-flash";
|
||||||
|
}
|
||||||
|
properties.data = path;
|
||||||
|
|
||||||
|
var build = "<object id=\"" + params.id + "\"";
|
||||||
|
for (var property in properties) build += " " + property + "=\"" + properties[property] + "\"";
|
||||||
|
build += ">";
|
||||||
|
for (var param in params) {
|
||||||
|
if (params[param]) build += "<param name=\"" + param + "\" value=\"" + params[param] + "\" />";
|
||||||
|
}
|
||||||
|
build += "</object>";
|
||||||
|
|
||||||
|
var div = document.createElement("div");
|
||||||
|
div.innerHTML = build;
|
||||||
|
return div.firstChild;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Tank'z</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Tank'z</h1>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user