[project] added packers
This commit is contained in:
@@ -30,9 +30,12 @@ class Config {
|
|||||||
this.macros = [];
|
this.macros = [];
|
||||||
this.meta = {
|
this.meta = {
|
||||||
title: null,
|
title: null,
|
||||||
|
filename: null,
|
||||||
|
icon: null,
|
||||||
version: null,
|
version: null,
|
||||||
pack: null,
|
pack: null,
|
||||||
company:null
|
author: null,
|
||||||
|
company: null
|
||||||
};
|
};
|
||||||
if (params) {
|
if (params) {
|
||||||
this.update(params);
|
this.update(params);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const os = require('os');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const fse = require('fs-extra');
|
||||||
//const concat = require('gulp-concat');
|
//const concat = require('gulp-concat');
|
||||||
//const uglify = require('gulp-uglify');
|
//const uglify = require('gulp-uglify');
|
||||||
//const babel = require('gulp-babel');
|
//const babel = require('gulp-babel');
|
||||||
@@ -11,10 +13,12 @@ const Debug = require('./debug');
|
|||||||
const webserver = require('gulp-webserver');
|
const webserver = require('gulp-webserver');
|
||||||
const run = require('../run/index');
|
const run = require('../run/index');
|
||||||
const tail = require('./tail');
|
const tail = require('./tail');
|
||||||
//const deb = require('gulp-debian');
|
const deb = require('gulp-debian');
|
||||||
const {BuildSystem, Platform, Config} = require('./core');
|
const {BuildSystem, Platform, Config} = require('./core');
|
||||||
const vfs = require('vinyl-fs');
|
const vfs = require('vinyl-fs');
|
||||||
const rename = require('gulp-rename');
|
const rename = require('gulp-rename');
|
||||||
|
const template = require('lodash.template');
|
||||||
|
const mkdirp = require('mkdirp');
|
||||||
|
|
||||||
|
|
||||||
const streamToPromise = (stream) => {
|
const streamToPromise = (stream) => {
|
||||||
@@ -61,8 +65,8 @@ class Builder extends Target {
|
|||||||
Builder.factory[buildSystem] = builder;
|
Builder.factory[buildSystem] = builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
static new(buildSystem, config) {
|
static new(buildSystem) {
|
||||||
return new Builder.factory[buildSystem](buildSystem, config);
|
return new Builder.factory[buildSystem](buildSystem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +102,98 @@ class HaxeBuilder extends Builder {
|
|||||||
Builder.register(BuildSystem.HAXE, HaxeBuilder);
|
Builder.register(BuildSystem.HAXE, HaxeBuilder);
|
||||||
Builder.register(BuildSystem.OPENFL, HaxeBuilder);
|
Builder.register(BuildSystem.OPENFL, HaxeBuilder);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Packer extends Target {
|
||||||
|
|
||||||
|
constructor(platform) {
|
||||||
|
super();
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare() {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
call(config) {
|
||||||
|
throw 'Not Implemented';
|
||||||
|
}
|
||||||
|
|
||||||
|
static register(platform, packer) {
|
||||||
|
Packer.factory[platform] = packer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static new(platform) {
|
||||||
|
return new Packer.factory[platform]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Packer.factory = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class FlashPacker extends Packer {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super(Platform.FLASH);
|
||||||
|
}
|
||||||
|
|
||||||
|
call(config) {
|
||||||
|
const target = this.targetPath(config.name, this.platform);
|
||||||
|
const indexTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/flash/index.html')));
|
||||||
|
const index = indexTemplate(config);
|
||||||
|
fs.writeFileSync(path.resolve(target, 'index.html'), index);
|
||||||
|
fs.copyFileSync(path.resolve(__dirname, '..', 'template/flash/swf.js'), path.resolve(target, 'swf.js'));
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Packer.register(Platform.FLASH, FlashPacker);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class LinuxPacker extends Packer {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super(Platform.LINUX);
|
||||||
|
}
|
||||||
|
|
||||||
|
call(config) {
|
||||||
|
const target = this.targetPath(config.name, this.platform);
|
||||||
|
const buildDir = path.join(os.tmpdir(), 'build', config.name, 'debian');
|
||||||
|
const desktopTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/linux/app.desktop')));
|
||||||
|
const desktop = desktopTemplate(config);
|
||||||
|
mkdirp.sync(`${buildDir}/usr/share/applications`);
|
||||||
|
fs.writeFileSync(`${buildDir}/usr/share/applications/${config.meta.filename}.desktop`, desktop);
|
||||||
|
fse.copySync(`${target}`, `${buildDir}/usr/share/${config.meta.filename}/`);
|
||||||
|
return gulp.src(`${buildDir}/*`)
|
||||||
|
.pipe(deb({
|
||||||
|
package: config.meta.filename,
|
||||||
|
version: config.meta.version,
|
||||||
|
section: 'base',
|
||||||
|
priority: 'optional',
|
||||||
|
architecture: 'all',
|
||||||
|
maintainer: config.meta.author,
|
||||||
|
description: config.meta.title,
|
||||||
|
changelog: [],
|
||||||
|
postinst: [
|
||||||
|
'if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ] ; then\n' +
|
||||||
|
' update-menus\n' +
|
||||||
|
'fi'
|
||||||
|
],
|
||||||
|
_target: '/',
|
||||||
|
_out: path.join(target, '..', 'debian'),
|
||||||
|
_clean: true,
|
||||||
|
_verbose: false
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Packer.register(Platform.LINUX, LinuxPacker);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -227,28 +323,43 @@ class Project {
|
|||||||
|
|
||||||
build(platform) {
|
build(platform) {
|
||||||
const builder = Builder.new(this.buildSystem);
|
const builder = Builder.new(this.buildSystem);
|
||||||
|
const config = this.config;
|
||||||
return [
|
return [
|
||||||
() => builder.prepare(),
|
function prepare() { return builder.prepare() },
|
||||||
() => builder.call(platform, this.config)
|
function build() { return builder.call(platform, config) },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
run(platform) {
|
run(platform) {
|
||||||
const builder = Builder.new(this.buildSystem);
|
const builder = Builder.new(this.buildSystem);
|
||||||
const runner = Runner.new(platform, this.config.name);
|
const runner = Runner.new(platform, this.config.name);
|
||||||
|
const config = this.config;
|
||||||
const debug = new Debug();
|
const debug = new Debug();
|
||||||
return [
|
return [
|
||||||
() => builder.prepare(),
|
function prepare() { return builder.prepare() },
|
||||||
() => builder.call(platform, this.config, debug),
|
function build() { return builder.call(platform, config, debug) },
|
||||||
() => runner.prepare(),
|
function prepare() { return runner.prepare() },
|
||||||
() => runner.call(debug)
|
function run() { return runner.call(debug) },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
pack(platform) {
|
||||||
|
const config = this.config;
|
||||||
|
const packer = Packer.new(platform);
|
||||||
|
return [
|
||||||
|
function prepare() { return packer.prepare() },
|
||||||
|
function pack() { return packer.call(config) },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
bind(module, external_gulp /* ToDo: spike */) {
|
bind(module, external_gulp /* ToDo: spike */) {
|
||||||
|
const _gulp = (external_gulp || gulp);
|
||||||
for (const platform of this.platforms) {
|
for (const platform of this.platforms) {
|
||||||
module.exports[`${this.config.name}:${platform}:build`] = (external_gulp || gulp).series(this.build(platform));
|
module.exports[`${this.config.name}:${platform}:build`] = _gulp.series(this.build(platform));
|
||||||
module.exports[`${this.config.name}:${platform}:run`] = (external_gulp || gulp).series(this.run(platform));
|
module.exports[`${this.config.name}:${platform}:run`] = _gulp.series(this.run(platform));
|
||||||
|
if (Packer.factory[platform]) {
|
||||||
|
module.exports[`${this.config.name}:${platform}:pack`] = _gulp.series(this.pack(platform, _gulp));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class Sdk {
|
|||||||
if (this.prepared) {
|
if (this.prepared) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
} else {
|
} else {
|
||||||
mkdirp(this.path);
|
mkdirp.sync(this.path);
|
||||||
const bar = new ProgressBar(`${this.tag} [:bar] :percent :etas`, {width: 40, total: 1000, clear: true});
|
const bar = new ProgressBar(`${this.tag} [:bar] :percent :etas`, {width: 40, total: 1000, clear: true});
|
||||||
let stream = got.stream(this.link);
|
let stream = got.stream(this.link);
|
||||||
stream = stream.on('downloadProgress', (p) => bar.update(p.percent));
|
stream = stream.on('downloadProgress', (p) => bar.update(p.percent));
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gulp-haxetool",
|
"name": "gulp-haxetool",
|
||||||
"version": "0.0.6",
|
"version": "0.0.7",
|
||||||
"description": "Haxe tool for gulp",
|
"description": "Haxe tool for gulp",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
"fs-extra": "^5.0.0",
|
"fs-extra": "^5.0.0",
|
||||||
"got": "^8.3.0",
|
"got": "^8.3.0",
|
||||||
"gulp": "^4.0.0",
|
"gulp": "^4.0.0",
|
||||||
|
"gulp-debian": "^0.1.9",
|
||||||
"gulp-rename": "^1.2.2",
|
"gulp-rename": "^1.2.2",
|
||||||
"gulp-spawn": "^0.4.0",
|
"gulp-spawn": "^0.4.0",
|
||||||
"gulp-webserver": "^0.9.1",
|
"gulp-webserver": "^0.9.1",
|
||||||
|
|||||||
26
template/flash/index.html
Normal file
26
template/flash/index.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title><%=meta.title%></title>
|
||||||
|
<script type="text/javascript" src="swf.js"></script>
|
||||||
|
<style type="text/css">
|
||||||
|
html, body, #container {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="container"></div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
new Swf(
|
||||||
|
document.getElementById('container'),
|
||||||
|
'<%=meta.filename%>.swf',
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
87
template/flash/swf.js
Normal file
87
template/flash/swf.js
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
template/linux/app.desktop
Normal file
9
template/linux/app.desktop
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Encoding=UTF-8
|
||||||
|
Type=Application
|
||||||
|
Comment=<%=meta.title%> <%=meta.version%>
|
||||||
|
Exec=bash -c 'cd "/usr/share/<%=meta.filename%>" && ./<%=meta.filename%>'
|
||||||
|
Icon=/usr/share/<%=meta.filename%>/<%=meta.icon%>
|
||||||
|
Name=<%=meta.title%>
|
||||||
|
Categories=Game
|
||||||
|
Terminal=false
|
||||||
@@ -6,4 +6,4 @@
|
|||||||
--macro "<%=item%>"<% }); %>
|
--macro "<%=item%>"<% }); %>
|
||||||
|
|
||||||
-main <%=main%>
|
-main <%=main%>
|
||||||
-<%=out%> "<%=buildDir%>/<%=platform%>/bin/<%=name%><%=ext%>"
|
-<%=out%> "<%=buildDir%>/<%=platform%>/bin/<%=meta.filename%><%=ext%>"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<project>
|
<project>
|
||||||
<meta title="<%=meta.title%>" package="<%=meta.pack%>" version="<%=meta.version%>" company="<%=meta.company%>"/>
|
<meta title="<%=meta.title%>" package="<%=meta.pack%>" version="<%=meta.version%>" company="<%=meta.company%>"/>
|
||||||
<app main="<%=main%>" path="<%=buildDir%>" file="<%=name%>"/>
|
<app main="<%=main%>" path="<%=buildDir%>" file="<%=meta.filename%>"/>
|
||||||
<% sources.forEach(function(item) { %>
|
<% sources.forEach(function(item) { %>
|
||||||
<source path="<%=item%>"/><% }); %>
|
<source path="<%=item%>"/><% }); %>
|
||||||
<% assets.forEach(function(item) { %>
|
<% assets.forEach(function(item) { %>
|
||||||
|
|||||||
Reference in New Issue
Block a user