[gulp] added project
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
const gulp = require('gulp');
|
||||
const {Haxe, FlashPlayer} = require('gulp-haxetool');
|
||||
const version = require('./version');
|
||||
const prepare = require('./prepare');
|
||||
const Debug = require('./debug');
|
||||
const dateformat = require('dateformat');
|
||||
|
||||
|
||||
const build = (platform, values, debug) => function build() {
|
||||
const build = dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss');
|
||||
let macro = [`CompilationOption.set('build','${build}')`];
|
||||
if (debug) macro = macro.concat(debug.macro());
|
||||
return gulp.src('.')
|
||||
.pipe(new Haxe().openfl({
|
||||
command: 'build',
|
||||
platform: platform,
|
||||
version: version,
|
||||
values: {...values, build_editor:true},
|
||||
debug: debug,
|
||||
macro: macro,
|
||||
}))
|
||||
.pipe(gulp.dest(`target/${platform}`));
|
||||
};
|
||||
|
||||
|
||||
const testFlash = function() {
|
||||
const debug = new Debug();
|
||||
return build('flash', {}, debug)()
|
||||
.pipe(new FlashPlayer().run(true))
|
||||
.pipe(debug.run());
|
||||
};
|
||||
|
||||
|
||||
exports['editor:flash'] = gulp.series(prepare(Haxe.ID), build('flash'));
|
||||
exports['editor:flash:test'] = gulp.series(prepare(Haxe.ID, FlashPlayer.ID), testFlash);
|
||||
269
build/project.js
Normal file
269
build/project.js
Normal file
@@ -0,0 +1,269 @@
|
||||
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 {Haxe, FlashPlayer, Neko} = require('gulp-haxetool');
|
||||
const Debug = require('./debug');
|
||||
const webserver = require('gulp-webserver');
|
||||
const run = require('gulp-run');
|
||||
const tail = require('./tail');
|
||||
const deb = require('gulp-debian');
|
||||
const dateformat = require('dateformat');
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const Platform = {
|
||||
FLASH: 'flash',
|
||||
HTML5: 'html5',
|
||||
LINUX: 'linux',
|
||||
NEKO: 'neko',
|
||||
};
|
||||
|
||||
|
||||
class Config {
|
||||
|
||||
constructor({name, version, lib=[], cp=[], main=null, values={}, macro=[]}) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.lib = lib;
|
||||
this.cp = cp;
|
||||
this.main = main;
|
||||
this.values = values;
|
||||
this.macro = macro;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Builder {
|
||||
|
||||
constructor(platform, config) {
|
||||
this.platform = platform;
|
||||
this.config = config;
|
||||
this.haxe = new Haxe();
|
||||
this.target = 'target';
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return this.haxe.prepare();
|
||||
}
|
||||
|
||||
macro(debug) {
|
||||
const build = dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss');
|
||||
let macro = [`CompilationOption.set('build','${build}')`];
|
||||
if (debug) {
|
||||
macro = macro.concat(debug.macro());
|
||||
}
|
||||
return macro.concat(this.config.macro);
|
||||
}
|
||||
|
||||
call(debug) {
|
||||
throw 'Not Implemented';
|
||||
}
|
||||
|
||||
static register(platform, builder) {
|
||||
Builder.factory[platform] = builder;
|
||||
}
|
||||
|
||||
static new(platform, config) {
|
||||
return new Builder.factory[platform](platform, config);
|
||||
}
|
||||
}
|
||||
|
||||
Builder.factory = {};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class OpenFLBuilder extends Builder {
|
||||
|
||||
call(debug) {
|
||||
return gulp.src('.')
|
||||
.pipe(this.haxe.openfl({
|
||||
command: 'build',
|
||||
platform: this.platform,
|
||||
version: this.config.version,
|
||||
debug: debug,
|
||||
values: this.config.values,
|
||||
macro: this.macro(debug),
|
||||
outputFile: this.config.name,
|
||||
}))
|
||||
.pipe(gulp.dest(`${this.target}/${this.platform}`));
|
||||
}
|
||||
}
|
||||
|
||||
Builder.register(Platform.FLASH, OpenFLBuilder);
|
||||
Builder.register(Platform.HTML5, OpenFLBuilder);
|
||||
Builder.register(Platform.LINUX, OpenFLBuilder);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class HaxeBuilder extends Builder {
|
||||
|
||||
call(debug) {
|
||||
return gulp.src('.')
|
||||
.pipe(new Haxe().build({
|
||||
platform: this.platform,
|
||||
version: this.config.version,
|
||||
lib: this.config.lib,
|
||||
cp: this.config.cp,
|
||||
main: this.config.main,
|
||||
outputFile: this.config.name + '.n', // ToDo: for neko only
|
||||
debug: debug,
|
||||
macro: this.macro(debug),
|
||||
values: this.config.values
|
||||
}))
|
||||
.pipe(gulp.dest(`${this.target}/${this.platform}`));
|
||||
}
|
||||
}
|
||||
|
||||
Builder.register(Platform.NEKO, HaxeBuilder);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Runner {
|
||||
|
||||
constructor(platform, name) {
|
||||
this.platform = platform;
|
||||
this.name = name;
|
||||
this.target = 'target';
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
call(debug) {
|
||||
throw 'Not Implemented';
|
||||
}
|
||||
|
||||
static register(platform, builder) {
|
||||
Runner.factory[platform] = builder;
|
||||
}
|
||||
|
||||
static new(platform, name) {
|
||||
return new Runner.factory[platform](platform, name);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.factory = {};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class FlashRunner extends Runner {
|
||||
|
||||
constructor(platform, name) {
|
||||
super(platform, name);
|
||||
this.player = new FlashPlayer();
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return this.player.prepare();
|
||||
}
|
||||
|
||||
call(debug) {
|
||||
return gulp.src(`${this.target}/${this.platform}/${this.name}.swf`)
|
||||
.pipe(this.player.run(true))
|
||||
.pipe(debug.run());
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.FLASH, FlashRunner);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Html5Runner extends Runner {
|
||||
|
||||
call(debug) {
|
||||
return gulp.src(`${this.target}/${this.platform}`)
|
||||
.pipe(webserver({
|
||||
host: 'localhost', port: 3000,
|
||||
open: true,
|
||||
fallback: 'index.html'
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.HTML5, Html5Runner);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class LinuxRunner extends Runner {
|
||||
|
||||
call(debug) {
|
||||
return gulp.src(`${this.target}/${this.platform}/${this.name}`)
|
||||
.pipe(run(`./${this.name}`, {cwd: `target/${this.platform}`, verbosity: 1}))
|
||||
.pipe(tail(Debug.log));
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.LINUX, LinuxRunner);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class NekoRunner extends Runner {
|
||||
|
||||
call(debug) {
|
||||
return gulp.src(`${this.target}/${this.platform}/${this.name}.n`)
|
||||
.pipe(new Neko().run())
|
||||
.pipe(debug.run());
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.NEKO, NekoRunner);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Project {
|
||||
|
||||
constructor(config, platforms=[]) {
|
||||
this.config = config;
|
||||
this.platforms = platforms;
|
||||
}
|
||||
|
||||
build(platform) {
|
||||
const builder = Builder.new(platform, this.config);
|
||||
return gulp.series(
|
||||
() => builder.prepare(),
|
||||
() => builder.call()
|
||||
);
|
||||
}
|
||||
|
||||
run(platform) {
|
||||
const builder = Builder.new(platform, this.config);
|
||||
const runner = Runner.new(platform, this.config.name);
|
||||
const debug = new Debug();
|
||||
return gulp.series(
|
||||
() => builder.prepare(),
|
||||
() => builder.call(debug),
|
||||
() => runner.prepare(),
|
||||
() => runner.call(debug)
|
||||
);
|
||||
}
|
||||
|
||||
bind(module) {
|
||||
for (const platform of this.platforms) {
|
||||
module.exports[`${this.config.name}:${platform}:build`] = this.build(platform);
|
||||
module.exports[`${this.config.name}:${platform}:run`] = this.run(platform);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Project.Platform = Platform;
|
||||
Project.Config = Config;
|
||||
Project.Builder = Builder;
|
||||
Project.Runner = Runner;
|
||||
|
||||
|
||||
module.exports = Project;
|
||||
@@ -16,11 +16,10 @@ const build = () => function build(debug) {
|
||||
platform: 'neko',
|
||||
version: version,
|
||||
lib: [
|
||||
'protohx',
|
||||
'orm',
|
||||
'protohx:0.4.6',
|
||||
'haxework:git',
|
||||
'haxe-crypto',
|
||||
'yield',
|
||||
'haxe-crypto:0.0.7',
|
||||
'yield:1.1.2',
|
||||
],
|
||||
cp: [
|
||||
'src/common/haxe',
|
||||
@@ -28,7 +27,7 @@ const build = () => function build(debug) {
|
||||
'src-gen/haxe',
|
||||
],
|
||||
main: 'ru.m.tankz.server.Server',
|
||||
outputFile: 'tankz.n',
|
||||
outputFile: 'server.n',
|
||||
debug: debug,
|
||||
macro: macro,
|
||||
values: {proto_debug: debug}
|
||||
|
||||
70
gulpfile.js
70
gulpfile.js
@@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
const os = require('os');
|
||||
const gulp = require('gulp');
|
||||
const clean = require('gulp-clean');
|
||||
const Config = require('./config.json');
|
||||
const prepare = require('./build/prepare');
|
||||
const Project = require('./build/project');
|
||||
const version = require('./build/version');
|
||||
|
||||
const {Sdk} = require('gulp-haxetool');
|
||||
|
||||
@@ -15,20 +15,58 @@ exports.clean = () => {
|
||||
return gulp.src('target/*', {read: false}).pipe(clean());
|
||||
};
|
||||
|
||||
const merge = (value) => {
|
||||
if (typeof value === 'string') {
|
||||
value = require(value);
|
||||
}
|
||||
for (let key in value) if (value.hasOwnProperty(key)) {
|
||||
exports[key] = value[key];
|
||||
}
|
||||
};
|
||||
/**
|
||||
* ToDo:
|
||||
* libs versions from package.json
|
||||
* lib in openfl build
|
||||
* cp in openfl build
|
||||
* main in openfl build
|
||||
* install libs in builder prepare
|
||||
*
|
||||
* run generate proto from prepare.js
|
||||
*/
|
||||
|
||||
exports.update = prepare.update;
|
||||
merge('./build/prepare');
|
||||
merge('./build/client');
|
||||
merge('./build/editor');
|
||||
merge('./build/server');
|
||||
/**
|
||||
* client
|
||||
*/
|
||||
const client = new Project(new Project.Config({
|
||||
name: 'client',
|
||||
version: version
|
||||
}), [
|
||||
Project.Platform.FLASH,
|
||||
Project.Platform.HTML5,
|
||||
Project.Platform.LINUX,
|
||||
]).bind(module);
|
||||
|
||||
/**
|
||||
* editor
|
||||
*/
|
||||
const editor = new Project(new Project.Config({
|
||||
name: 'editor',
|
||||
version: version,
|
||||
values: {build_editor: true}
|
||||
}), [
|
||||
Project.Platform.FLASH,
|
||||
]).bind(module);
|
||||
|
||||
exports.default = gulp.series(exports.clean, exports.client, exports.server);
|
||||
/**
|
||||
* server
|
||||
*/
|
||||
const server = new Project(new Project.Config({
|
||||
name: 'server',
|
||||
version: version,
|
||||
lib: [
|
||||
'protohx:0.4.6',
|
||||
'haxework:git',
|
||||
'haxe-crypto:0.0.7',
|
||||
'yield:1.1.2',
|
||||
],
|
||||
cp: [
|
||||
'src/common/haxe',
|
||||
'src/server/haxe',
|
||||
'src-gen/haxe',
|
||||
],
|
||||
main: 'ru.m.tankz.server.Server',
|
||||
}), [
|
||||
Project.Platform.NEKO,
|
||||
]).bind(module);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"dateformat": "^3.0.3",
|
||||
"gulp": "github:gulpjs/gulp#4.0",
|
||||
"gulp-babel": "^7.0.1",
|
||||
"gulp-clean": "^0.4.0",
|
||||
@@ -14,8 +15,7 @@
|
||||
"gulp-run": "^1.7.1",
|
||||
"gulp-template": "^5.0.0",
|
||||
"gulp-uglify": "^3.0.0",
|
||||
"gulp-webserver": "^0.9.1",
|
||||
"dateformat": "^3.0.3"
|
||||
"gulp-webserver": "^0.9.1"
|
||||
},
|
||||
"haxeDependencies": {
|
||||
"lime": "6.0.1",
|
||||
|
||||
10
project.xml
10
project.xml
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<meta title="Tank'z" package="ru.m.tankz" version="0.0.0" company="MegaLoMania"/>
|
||||
<app main="ru.m.tankz.Client" path="target" file="tankz"/>
|
||||
<meta title="Tank'z" package="ru.m.tankz" company="MegaLoMania"/>
|
||||
<app main="ru.m.tankz.Client"/>
|
||||
<source path="src/common/haxe"/>
|
||||
<source path="src/client/haxe"/>
|
||||
<source path="src-gen/haxe"/>
|
||||
@@ -17,14 +17,10 @@
|
||||
<window width="1024" height="768" unless="html5"/>
|
||||
<haxeflag name="-D" value="swf-gpu"/>
|
||||
<haxeflag name="-D" value="native-trace"/>
|
||||
<!--<haxeflag name="-D" value="proto_debug"/>-->
|
||||
<haxeflag name="-dce" value="no"/>
|
||||
<!--<haxeflag name="-D" value="dom"/>-->
|
||||
<haxeflag name="--macro" value="yield.parser.Parser.auto()"/>
|
||||
<!--<template path="src/client/webapp/index_template.html" rename="index.html"/>-->
|
||||
|
||||
<section if="build_editor">
|
||||
<app main="ru.m.tankz.editor.Editor" path="target" file="editor"/>
|
||||
<app main="ru.m.tankz.editor.Editor"/>
|
||||
<source path="src/editor/haxe"/>
|
||||
</section>
|
||||
</project>
|
||||
Reference in New Issue
Block a user