var gulp = require('gulp'); var concat = require('gulp-concat'); var sort = require('gulp-sort'); var minify = require('gulp-minify'); var replace = require('gulp-string-replace'); gulp.task('build', build); gulp.task('monitor', monitor); //__API_COMPONENT__ var code = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n'; code += '\t\tapiComponent = {};\n'; code += '\t}\n'; code += '\n'; code += '\tR3.API.Component.call(\n'; code += '\t\tthis,\n'; code += '\t\tapiComponent.parent,\n'; code += '\t\tapiComponent.id,\n'; code += '\t\tapiComponent.name,\n'; code += '\t\tapiComponent.register,\n'; code += '\t\tapiComponent.selected,\n'; code += '\t\tapiComponent.isPublic\n'; code += '\t)\n'; code += '\n'; code += '\tif (R3.Utils.UndefinedOrNull(apiComponent.guiInfo)) {\n'; code += '\t\tapiComponent.guiInfo = {};\n'; code += '\t}\n'; code += '\tthis.guiInfo = apiComponent.guiInfo;\n'; //__DEFINE_API_COMPONENT__ var code1 = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n'; code1 += '\t\tapiComponent = {};\n'; code1 += '\t}\n'; code1 += '\n'; code1 += '\tif (R3.Utils.UndefinedOrNull(apiComponent.guiInfo)) {\n'; code1 += '\t\tapiComponent.guiInfo = {};\n'; code1 += '\t}\n'; code1 += '\tthis.guiInfo = apiComponent.guiInfo;\n'; var code2 = 'R3.D3.API.Geometry.Buffer.call(\n'; code2 += '\t\tthis,\n'; code2 += '\t\tapiComponent\n'; code2 += '\t)'; var code3 = 'R3.D3.API.Geometry.Normal.call(\n'; code3 += '\t\tthis,\n'; code3 += '\t\tapiComponent\n'; code3 += '\t)'; var code4 = 'R3.D3.API.Material.call(\n'; code4 += '\t\tthis,\n'; code4 += '\t\tapiComponent\n'; code4 += '\t)'; var code5 = 'if (R3.Utils.UndefinedOrNull(apiTexture)) {\n'; code5 += '\t\tapiTexture = {};\n'; code5 += '\t}\n'; code5 += '\n'; code5 += '\tR3.D3.API.Texture.call(\n'; code5 += '\t\tthis,\n'; code5 += '\t\tapiTexture,\n'; code5 += '\t\tapiTexture.parentMaterials,\n'; code5 += '\t\tapiTexture.mipmaps,\n'; code5 += '\t\tapiTexture.mapping,\n'; code5 += '\t\tapiTexture.wrapS,\n'; code5 += '\t\tapiTexture.wrapT,\n'; code5 += '\t\tapiTexture.magFilter,\n'; code5 += '\t\tapiTexture.minFilter,\n'; code5 += '\t\tapiTexture.anisotropy,\n'; code5 += '\t\tapiTexture.format,\n'; code5 += '\t\tapiTexture.storageType,\n'; code5 += '\t\tapiTexture.offset,\n'; code5 += '\t\tapiTexture.repeat,\n'; code5 += '\t\tapiTexture.rotation,\n'; code5 += '\t\tapiTexture.center,\n'; code5 += '\t\tapiTexture.matrixAutoUpdate,\n'; code5 += '\t\tapiTexture.generateMipMaps,\n'; code5 += '\t\tapiTexture.premultiplyAlpha,\n'; code5 += '\t\tapiTexture.flipY,\n'; code5 += '\t\tapiTexture.unpackAlignment,\n'; code5 += '\t\tapiTexture.encoding,\n'; code5 += '\t\tapiTexture.version,\n'; code5 += '\t\tapiTexture.animated,\n'; code5 += '\t\tapiTexture.reverseAnimation,\n'; code5 += '\t\tapiTexture.forward\n'; code5 += '\t)'; //__RUNTIME_COMPONENT__ var code6 = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n'; code6 += '\t\tapiComponent = {};\n'; code6 += '\t}\n'; code6 += '\n'; code6 += '\tif (R3.Utils.UndefinedOrNull(this.linkedComponents)) {\n'; code6 += '\t\tthis.linkedComponents = {};\n'; code6 += '\t}\n'; code6 += '\n'; code6 += '\tthis.initialize(apiComponent)\n'; code6 += '\n'; code6 += '\tthis.graphics\t= null;\n'; code6 += '\tthis.physics\t= null;\n'; code6 += '\tthis.coder\t\t= null;\n'; code6 += '\tthis.gui\t\t= null;\n'; code6 += '\tthis.stats\t\t= null;\n'; code6 += '\n'; code6 += '\tR3.Event.Emit(\n'; code6 += '\t\tR3.Event.GET_RUNTIME,\n'; code6 += '\t\tthis,\n'; code6 += '\t\tfunction(runtime) {\n'; code6 += '\t\t\tif (R3.Utils.UndefinedOrNull(runtime)) {\n'; code6 += '\t\t\t\treturn;\n'; code6 += '\t\t\t}\n'; code6 += '\t\t\tthis.graphics\t= runtime.graphics;\n'; code6 += '\t\t\tthis.physics\t= runtime.physics;\n'; code6 += '\t\t\tthis.coder\t\t= runtime.coder;\n'; code6 += '\t\t\tthis.gui\t\t= runtime.gui;\n'; code6 += '\t\t\tthis.stats\t\t= runtime.stats;\n'; code6 += '\t\t}.bind(this)\n'; code6 += '\t)'; //__RUNTIME_COMPONENT_INHERITABLE__ var code14 = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n'; code14 += '\t\t\tapiComponent = {};\n'; code14 += '\t\t}\n'; code14 += '\n'; code14 += '\t\tthis.initialize(apiComponent)\n'; code14 += '\n'; code14 += '\t\tthis.graphics\t= null;\n'; code14 += '\t\tthis.physics\t= null;\n'; code14 += '\t\tthis.coder\t\t= null;\n'; code14 += '\t\tthis.gui\t\t= null;\n'; code14 += '\t\tthis.stats\t\t= null;\n'; code14 += '\n'; code14 += '\t\tR3.Event.Emit(\n'; code14 += '\t\t\tR3.Event.GET_RUNTIME,\n'; code14 += '\t\t\tthis,\n'; code14 += '\t\t\tfunction(runtime) {\n'; code14 += '\t\t\t\tif (R3.Utils.UndefinedOrNull(runtime)) {\n'; code14 += '\t\t\t\t\treturn;\n'; code14 += '\t\t\t\t}\n'; code14 += '\t\t\t\tthis.graphics\t= runtime.graphics;\n'; code14 += '\t\t\t\tthis.physics\t= runtime.physics;\n'; code14 += '\t\t\t\tthis.coder\t\t= runtime.coder;\n'; code14 += '\t\t\t\tthis.gui\t\t= runtime.gui;\n'; code14 += '\t\t\t\tthis.stats\t\t= runtime.stats;\n'; code14 += '\t\t\t}.bind(this)\n'; code14 += '\t\t)'; //__DEREGISTER_COMPONENT__ var code7 = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n'; code7 += '\t\tapiComponent = {};\n'; code7 += '\t}\n'; code7 += '\n'; code7 += '\tif (R3.Utils.UndefinedOrNull(apiComponent.register)) {\n'; code7 += '\t\tapiComponent.register = false;\n'; code7 += '\t}\n'; code7 += '\n'; code7 += '\tR3.Event.Emit(\n'; code7 += '\t\tR3.Event.GET_REGISTER_FACES,\n'; code7 += '\t\tnull,\n'; code7 += '\t\tfunction(register) {\n'; code7 += '\t\t\tif (R3.Utils.UndefinedOrNull(register)) {\n'; code7 += '\t\t\t\treturn;\n'; code7 += '\t\t\t}\n'; code7 += '\t\t\tapiComponent.register = register;\n'; code7 += '\t\t}\n'; code7 += '\t)'; //__UPGRADE_TO_RUNTIME__ var code8 = 'R3.Component.call(this)'; var code9 = 'R3.Component.prototype.createInstance.call(this)'; var code10 = 'R3.Component.prototype.updateInstance.call(this, property)'; var code11 = 'R3.D3.Geometry.Buffer.call(\n'; code11 += '\t\tthis,\n'; code11 += '\t\ttrue\n'; code11 += '\t);'; //__INHERIT_ONLY__ var code12 = 'if (R3.Utils.UndefinedOrNull(this.linkedComponents)) {\n'; code12 += '\t\tthis.linkedComponents = {};\n'; code12 += '\t}\n'; code12 += '\t\n'; code12 += '\tif (inherited !== true && inherited !== false) {\n'; code12 += '\t\tthrow new Error(R3.GetComponentName(this) + " should not be instantiated directly");\n'; code12 += '\t}'; //__INHERIT_AND_INSTANTIATE__ var code13 = 'if (R3.Utils.UndefinedOrNull(this.linkedComponents)) {\n'; code13 += '\t\tthis.linkedComponents = {};\n'; code13 += '\t}\n'; code13 += '\t\n'; code13 += '\tif (R3.Utils.UndefinedOrNull(inherited)) {\n\n'; code13 += '\t\t' + code14+ '\n'; code13 += '\t}'; function build() { return gulp.src('./src/r3-*.js') .pipe(sort()) .pipe(concat('r3.js')) .pipe(replace('__DATE__', new Date().toString())) .pipe(replace('__API_COMPONENT__', code)) .pipe(replace('__DEFINE_API_COMPONENT__', code1)) .pipe(replace('__API_GEOMETRY_BUFFER__', code2)) .pipe(replace('__API_GEOMETRY_NORMAL__', code3)) .pipe(replace('__API_MATERIAL__', code4)) .pipe(replace('__API_TEXTURE__', code5)) .pipe(replace('__RUNTIME_COMPONENT__', code6)) .pipe(replace('__DEREGISTER_COMPONENT__', code7)) .pipe(replace('__UPGRADE_TO_RUNTIME__', code8)) .pipe(replace('__CREATE_INSTANCE__', code9)) .pipe(replace('__UPDATE_INSTANCE__', code10)) .pipe(replace('__RUNTIME_BUFFER_COMPONENT__', code11)) .pipe(replace('__INHERIT_ONLY__', code12)) .pipe(replace('__INHERIT_AND_INSTANTIATE__', code13)) // .pipe(minify({ // ext:{ // src:'.js', // min:'-min.js' // } // })) .pipe(gulp.dest('./build/')); } function monitor() { gulp.watch('src/*.js', build); } gulp.task( 'default', gulp.series( build, monitor ) );