mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 10:32:39 +08:00
Merge pull request #822 from VisualSJ/master_modular
模块化GULP任务,以及定义引擎模块入口
This commit is contained in:
@@ -1,173 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
var Path = require('path');
|
||||
var gulp = require('gulp');
|
||||
var concat = require('gulp-concat');
|
||||
var es = require('event-stream');
|
||||
var sourcemaps = require('gulp-sourcemaps');
|
||||
|
||||
var srcs = [
|
||||
|
||||
'./cocos2d/core/base-nodes/BaseNodesPropertyDefine.js',
|
||||
'./cocos2d/core/base-nodes/CCSGNode.js',
|
||||
'./cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/core/base-nodes/CCSGNodeWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/core/scenes/CCSGScene.js',
|
||||
'./cocos2d/core/scenes/CCLoaderScene.js',
|
||||
|
||||
'./cocos2d/core/layers/CCLayer.js',
|
||||
'./cocos2d/core/layers/CCLayerCanvasRenderCmd.js',
|
||||
'./cocos2d/core/layers/CCLayerWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/core/sprites/SpritesPropertyDefine.js',
|
||||
'./cocos2d/core/sprites/CCSGSprite.js',
|
||||
'./cocos2d/core/sprites/CCSGSpriteCanvasRenderCmd.js',
|
||||
'./cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js',
|
||||
'./cocos2d/core/sprites/CCBakeSprite.js',
|
||||
'./cocos2d/core/sprites/CCSpriteBatchNode.js',
|
||||
'./cocos2d/core/sprites/CCSpriteBatchNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/core/sprites/CCScale9Sprite.js',
|
||||
'./cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js',
|
||||
'./cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/core/CCConfiguration.js',
|
||||
|
||||
'./cocos2d/core/CCDrawingPrimitivesCanvas.js',
|
||||
'./cocos2d/core/CCDrawingPrimitivesWebGL.js',
|
||||
|
||||
'./cocos2d/core/label/CCSGLabel.js',
|
||||
'./cocos2d/core/label/CCSGLabelCanvasRenderCmd.js',
|
||||
'./cocos2d/core/label/CCSGLabelWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/core/editbox/CCSGEditBox.js',
|
||||
'./cocos2d/core/editBox/CCdomNode.js',
|
||||
|
||||
'./cocos2d/core/videoplayer/CCSGVideoPlayer.js',
|
||||
|
||||
'./cocos2d/render-texture/CCRenderTexture.js',
|
||||
'./cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js',
|
||||
'./cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/shape-nodes/CCDrawNode.js',
|
||||
'./cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/shape-nodes/CCDrawNodeWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/clipping-nodes/CCClippingNode.js',
|
||||
'./cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/particle/CCSGParticleSystem.js',
|
||||
'./cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js',
|
||||
'./cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js',
|
||||
// './cocos2d/particle/CCSGParticleExamples.js',
|
||||
'./cocos2d/particle/CCParticleBatchNode.js',
|
||||
'./cocos2d/particle/CCParticleBatchNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/tilemap/CCSGTMXTiledMap.js',
|
||||
'./cocos2d/tilemap/CCTMXXMLParser.js',
|
||||
'./cocos2d/tilemap/CCTMXObjectGroup.js',
|
||||
'./cocos2d/tilemap/CCSGTMXLayer.js',
|
||||
'./cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js',
|
||||
'./cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/parallax/CCParallaxNode.js',
|
||||
'./cocos2d/parallax/CCParallaxNodeRenderCmd.js',
|
||||
|
||||
'./cocos2d/physics/CCPhysicsDebugNode.js',
|
||||
'./cocos2d/physics/CCPhysicsDebugNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/physics/CCPhysicsDebugNodeWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/motion-streak/CCSGMotionStreak.js',
|
||||
'./cocos2d/motion-streak/CCSGMotionStreakWebGLRenderCmd.js'
|
||||
|
||||
];
|
||||
|
||||
var header = new Buffer('(function (cc, ccui, ccs, cp) {\n');
|
||||
var footer = new Buffer('\n}).call(window, cc, ccui, ccs, cp);\n');
|
||||
|
||||
//function wrap (header, footer) {
|
||||
// return es.through(function (file) {
|
||||
// file.contents = Buffer.concat([header, file.contents, footer]);
|
||||
// this.emit('data', file);
|
||||
// });
|
||||
//}
|
||||
|
||||
var File = require('vinyl');
|
||||
function wrapFile (header, footer) {
|
||||
var headerFile = new File({
|
||||
cwd: process.cwd(),
|
||||
base: process.cwd(),
|
||||
path: Path.resolve('header.js'),
|
||||
contents: header
|
||||
});
|
||||
var footerFile = new File({
|
||||
cwd: process.cwd(),
|
||||
base: process.cwd(),
|
||||
path: Path.resolve('footer.js'),
|
||||
contents: footer
|
||||
});
|
||||
var isHeaderInserted = false;
|
||||
return es.through(
|
||||
function (file) {
|
||||
if (!isHeaderInserted) {
|
||||
this.emit('data', headerFile);
|
||||
isHeaderInserted = true;
|
||||
}
|
||||
//file.contents = Buffer.concat([header, file.contents, footer]);
|
||||
this.emit('data', file);
|
||||
},
|
||||
function () {
|
||||
this.emit('data', footerFile);
|
||||
this.emit('end');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
gulp.task('build-modular-cocos2d', function () {
|
||||
return gulp.src(srcs)
|
||||
.pipe(wrapFile(header, footer))
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(concat(Path.basename(paths.modularCocos2d)))
|
||||
.pipe(sourcemaps.write('./'))
|
||||
//.pipe(wrap(header, footer))
|
||||
|
||||
.pipe(es.through(
|
||||
function (file) {
|
||||
var content = file.contents.toString();
|
||||
content = content.replace(/\r\n/g , '\n');
|
||||
file.contents = new Buffer(content);
|
||||
this.emit('data', file);
|
||||
}
|
||||
))
|
||||
|
||||
.pipe(gulp.dest(Path.dirname(paths.modularCocos2d)));
|
||||
});
|
||||
@@ -1,269 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Path = require('path');
|
||||
var Fs = require('fire-fs');
|
||||
var Del = require('del');
|
||||
|
||||
var gulp = require('gulp');
|
||||
var mirror = require('gulp-mirror');
|
||||
var pipe = require('multipipe');
|
||||
var uglify = require('gulp-uglify');
|
||||
var rename = require('gulp-rename');
|
||||
var sourcemaps = require('gulp-sourcemaps');
|
||||
var es = require('event-stream');
|
||||
var size = require('gulp-size');
|
||||
var chalk = require('chalk');
|
||||
|
||||
var browserify = require('browserify');
|
||||
var source = require('vinyl-source-stream');
|
||||
var buffer = require('vinyl-buffer');
|
||||
var handleErrors = require('../util/handleErrors');
|
||||
//var babelify = require('babelify');
|
||||
|
||||
require('./build-cocos2d');
|
||||
|
||||
function getUglifyOptions (minify, global_defs) {
|
||||
if (minify) {
|
||||
return {
|
||||
compress: {
|
||||
global_defs: global_defs,
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
var compress = {
|
||||
// http://lisperator.net/uglifyjs/compress
|
||||
global_defs: global_defs,
|
||||
sequences: false, // join consecutive statements with the “comma operator”
|
||||
properties: false, // optimize property access: a["foo"] → a.foo
|
||||
//dead_code: true, // discard unreachable code
|
||||
drop_debugger: false, // discard “debugger” statements
|
||||
unsafe: false, // some unsafe optimizations (see below)
|
||||
conditionals: false, // optimize if-s and conditional expressions
|
||||
comparisons: false, // optimize comparisons
|
||||
//evaluate: true, // evaluate constant expressions
|
||||
booleans: false, // optimize boolean expressions
|
||||
loops: false, // optimize loops
|
||||
unused: false, // drop unused variables/functions
|
||||
hoist_funs: false, // hoist function declarations
|
||||
hoist_vars: false, // hoist variable declarations
|
||||
if_return: false, // optimize if-s followed by return/continue
|
||||
join_vars: false, // join var declarations
|
||||
cascade: false, // try to cascade `right` into `left` in sequences
|
||||
side_effects: false // drop side-effect-free statements
|
||||
//warnings: true // warn about potentially dangerous optimizations/code
|
||||
};
|
||||
return {
|
||||
mangle: false,
|
||||
//preserveComments: 'all',
|
||||
output: {
|
||||
// http://lisperator.net/uglifyjs/codegen
|
||||
beautify: true,
|
||||
bracketize: true
|
||||
},
|
||||
compress: compress
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function printSizes (sizeGetter, minSizeGetter, zippedSizeGetter) {
|
||||
return es.through(null, function () {
|
||||
console.log('Size of web engine: zipped: ' + chalk.cyan(zippedSizeGetter.size.toLocaleString() + 'B') +
|
||||
', minimized: ' + chalk.cyan(minSizeGetter.size.toLocaleString() + 'B') +
|
||||
', raw: ' + chalk.cyan(sizeGetter.size.toLocaleString() + 'B') +
|
||||
', compression ratio: ' + chalk.magenta((zippedSizeGetter.size / sizeGetter.size * 100).toFixed(2) + '%'));
|
||||
this.emit('end');
|
||||
});
|
||||
}
|
||||
|
||||
function rebundle_html_dev_min(bundler) {
|
||||
console.log('Compiling ' + paths.outFileDev + ' and ' + paths.outFile + ' ...');
|
||||
|
||||
function createSizeGetter (gzip) {
|
||||
return size({
|
||||
gzip: gzip,
|
||||
pretty: false,
|
||||
showTotal: false,
|
||||
showFiles: false,
|
||||
});
|
||||
}
|
||||
|
||||
var sizeGetter = createSizeGetter(false);
|
||||
var minSizeGetter = createSizeGetter(false);
|
||||
var zippedSizeGetter = createSizeGetter(true);
|
||||
|
||||
var devPipes = [
|
||||
uglify(getUglifyOptions(false, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: true,
|
||||
CC_TEST: false,
|
||||
CC_JSB: false
|
||||
})),
|
||||
sizeGetter
|
||||
];
|
||||
var minPipes = [
|
||||
rename(paths.outFile),
|
||||
uglify(getUglifyOptions(true, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: false,
|
||||
CC_TEST: false,
|
||||
CC_JSB: false
|
||||
})),
|
||||
minSizeGetter,
|
||||
zippedSizeGetter,
|
||||
];
|
||||
|
||||
return bundler.bundle()
|
||||
.on('error', handleErrors.handler)
|
||||
.pipe(handleErrors())
|
||||
.pipe(source(paths.outFileDev))
|
||||
.pipe(buffer())
|
||||
.pipe(sourcemaps.init({loadMaps: true}))
|
||||
.pipe(mirror(pipe(devPipes), pipe(minPipes)))
|
||||
.pipe(printSizes(sizeGetter, minSizeGetter, zippedSizeGetter))
|
||||
.pipe(sourcemaps.write('./', {
|
||||
sourceRoot: './',
|
||||
includeContent: true,
|
||||
addComment: true
|
||||
}))
|
||||
.pipe(gulp.dest(paths.outDir));
|
||||
}
|
||||
|
||||
function rebundle(bundler, name, options) {
|
||||
var macros = options && options.macros; // default false
|
||||
// only if macros // default false
|
||||
var sourceMaps = !!((options && ('sourceMaps' in options)) ? options.sourceMaps : macros);
|
||||
var minify = !!(options && options.minify); // default false
|
||||
|
||||
var bundle = bundler.bundle()
|
||||
.on('error', handleErrors.handler)
|
||||
.pipe(handleErrors())
|
||||
.pipe(source(name))
|
||||
.pipe(buffer());
|
||||
|
||||
if (macros) {
|
||||
console.log('Compiling ' + name + ' ...');
|
||||
if (sourceMaps) {
|
||||
bundle = bundle.pipe(sourcemaps.init({loadMaps: true}));
|
||||
}
|
||||
bundle = bundle.pipe(uglify(getUglifyOptions(minify, macros)));
|
||||
if (sourceMaps) {
|
||||
bundle = bundle.pipe(sourcemaps.write('./', {
|
||||
sourceRoot: '../',
|
||||
includeContent: false,
|
||||
addComment: true
|
||||
}));
|
||||
}
|
||||
}
|
||||
bundle = bundle.pipe(gulp.dest(paths.outDir));
|
||||
|
||||
return bundle;
|
||||
}
|
||||
|
||||
function createBundler(entryFiles) {
|
||||
// https://github.com/substack/node-browserify#methods
|
||||
var options = {
|
||||
debug: true, //temporarily disable due to an asar packing bug
|
||||
detectGlobals: false, // dont insert `process`, `global`, `__filename`, and `__dirname`
|
||||
bundleExternal: false // dont bundle external modules
|
||||
//standalone: 'engine-framework',
|
||||
//basedir: tempScriptDir
|
||||
};
|
||||
return new browserify(entryFiles, options)
|
||||
.exclude('package.json');
|
||||
}
|
||||
|
||||
gulp.task('build-html5', ['build-modular-cocos2d'], function () {
|
||||
return rebundle_html_dev_min(createBundler(paths.jsEntry));
|
||||
});
|
||||
|
||||
gulp.task('clean-test', function (done) {
|
||||
Del([paths.test.destEditorExtends, paths.test.dest],
|
||||
// sometimes it may need to delay 100ms to ensure build-test will be execute...
|
||||
setTimeout(function () {
|
||||
done();
|
||||
}, 100));
|
||||
});
|
||||
|
||||
gulp.task('build-test', ['build-modular-cocos2d', 'clean-test'], function () {
|
||||
var engine = rebundle(createBundler(paths.jsEntry), Path.basename(paths.test.dest));
|
||||
if (Fs.existsSync(paths.test.jsEntryEditorExtends)) {
|
||||
var bundler = createBundler(paths.test.jsEntryEditorExtends);
|
||||
//bundler = bundler.transform(babelify.configure({
|
||||
// presets: ["es2015"]
|
||||
//}));
|
||||
var editorExtends = rebundle(bundler, Path.basename(paths.test.destEditorExtends));
|
||||
return es.merge(engine, editorExtends);
|
||||
}
|
||||
else {
|
||||
// not in editor, skip editor extend
|
||||
return engine;
|
||||
}
|
||||
});
|
||||
|
||||
gulp.task('build-preview', ['build-modular-cocos2d'], function () {
|
||||
return rebundle(createBundler(paths.jsEntry), Path.basename(paths.preview.dest), {
|
||||
macros: {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: true,
|
||||
CC_TEST: false,
|
||||
CC_JSB: false
|
||||
},
|
||||
sourceMaps: true
|
||||
});
|
||||
});
|
||||
|
||||
function rebundle_jsb(bundler, name, minify) {
|
||||
var skips = paths.jsb.skipModules;
|
||||
for (var i = 0; i < skips.length; ++i) {
|
||||
bundler.ignore(require.resolve(skips[i]));
|
||||
}
|
||||
rebundle(bundler, name, {
|
||||
minify: minify,
|
||||
macros: {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: false,
|
||||
CC_TEST: false,
|
||||
CC_JSB: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
gulp.task('build-jsb-extends-min', function () {
|
||||
var jsbPolyfill = rebundle_jsb(createBundler(paths.jsb.entries), paths.jsb.outFile, true);
|
||||
return jsbPolyfill;
|
||||
});
|
||||
gulp.task('build-jsb-extends-dev', function () {
|
||||
var jsbPolyfill = rebundle_jsb(createBundler(paths.jsb.entries), paths.jsb.outFileDev, false);
|
||||
return jsbPolyfill;
|
||||
});
|
||||
|
||||
gulp.task('build', ['build-html5', 'build-preview', 'build-jsb-extends-min', 'build-jsb-extends-dev']);
|
||||
gulp.task('build-min', ['build-html5', 'build-jsb-extends-min']);
|
||||
gulp.task('build-dev', ['build-preview', 'build-jsb-extends-dev'], function (done) {
|
||||
// make dist version dirty
|
||||
Del(['./bin/cocos2d-js.js', './bin/cocos2d-js-min.js', './bin/jsb_polyfill.js'], done);
|
||||
});
|
||||
@@ -1,32 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Path = require('path');
|
||||
var gulp = require('gulp');
|
||||
var del = require('del');
|
||||
|
||||
gulp.task('clean', function (done) {
|
||||
del(Path.join(paths.outDir, '**/*'));
|
||||
});
|
||||
@@ -0,0 +1,185 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
const Utils = require('./utils');
|
||||
const Path = require('fire-path');
|
||||
|
||||
const Source = require('vinyl-source-stream');
|
||||
const Gulp = require('gulp');
|
||||
const Buffer = require('vinyl-buffer');
|
||||
const Uglify = require('gulp-uglify');
|
||||
const Sourcemaps = require('gulp-sourcemaps');
|
||||
const Size = require('gulp-size');
|
||||
const EventStream = require('event-stream');
|
||||
const Chalk = require('chalk');
|
||||
const HandleErrors = require('../util/handleErrors');
|
||||
|
||||
exports.buildCocosJs = function (sourceFile, outputFile, excludes, callback) {
|
||||
var outDir = Path.dirname(outputFile);
|
||||
var outFile = Path.basename(outputFile);
|
||||
var bundler = Utils.createBundler(sourceFile);
|
||||
|
||||
excludes && excludes.forEach(function (file) {
|
||||
bundler.exclude(file);
|
||||
});
|
||||
|
||||
var uglifyOption = Utils.uglifyOptions(false, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: true,
|
||||
CC_TEST: false,
|
||||
CC_JSB: false
|
||||
});
|
||||
|
||||
bundler.bundle()
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(Sourcemaps.init({loadMaps: true}))
|
||||
.pipe(Uglify(uglifyOption))
|
||||
.pipe(Sourcemaps.write('./', {
|
||||
sourceRoot: './',
|
||||
includeContent: true,
|
||||
addComment: true
|
||||
}))
|
||||
.pipe(Gulp.dest(outDir))
|
||||
.on('end', callback);
|
||||
};
|
||||
|
||||
exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, callback) {
|
||||
var outDir = Path.dirname(outputFile);
|
||||
var outFile = Path.basename(outputFile);
|
||||
var bundler = Utils.createBundler(sourceFile);
|
||||
|
||||
excludes && excludes.forEach(function (file) {
|
||||
bundler.exclude(file);
|
||||
});
|
||||
|
||||
var uglifyOption = Utils.uglifyOptions(true, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: false,
|
||||
CC_TEST: false,
|
||||
CC_JSB: false
|
||||
});
|
||||
|
||||
var rawSize = Size({ gzip: false, pretty: false, showTotal: false, showFiles: false });
|
||||
var zippedSize = Size({ gzip: true, pretty: false, showTotal: false, showFiles: false });
|
||||
|
||||
bundler.bundle()
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(Sourcemaps.init({loadMaps: true}))
|
||||
.pipe(Uglify(uglifyOption))
|
||||
.pipe(rawSize)
|
||||
.pipe(zippedSize)
|
||||
.pipe(EventStream.through(null, function () {
|
||||
var raw = rawSize.size;
|
||||
var zipped = zippedSize.size;
|
||||
var percent = ((zipped / raw) * 100).toFixed(2);
|
||||
console.log(`Size of ${outputFile}: minimized: ${Chalk.cyan(raw + 'B')} zipped: ${Chalk.cyan(zipped + 'B')}, compression ratio: ${percent}%`);
|
||||
this.emit('end');
|
||||
}))
|
||||
.pipe(Sourcemaps.write('./', {
|
||||
sourceRoot: './',
|
||||
includeContent: true,
|
||||
addComment: true
|
||||
}))
|
||||
.pipe(Gulp.dest(outDir))
|
||||
.on('end', callback);
|
||||
};
|
||||
|
||||
exports.buildPreview = function (sourceFile, outputFile, callback) {
|
||||
|
||||
var outFile = Path.basename(outputFile);
|
||||
var outDir = Path.dirname(outputFile);
|
||||
|
||||
var bundler = Utils.createBundler(sourceFile);
|
||||
bundler.exclude('./bin/modular-cocos2d-cut.js')
|
||||
.bundle()
|
||||
.on('error', HandleErrors.handler)
|
||||
.pipe(HandleErrors())
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(Sourcemaps.init({loadMaps: true}))
|
||||
.pipe(Uglify(Utils.uglifyOptions(false, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: true,
|
||||
CC_TEST: false,
|
||||
CC_JSB: false
|
||||
})))
|
||||
.pipe(Sourcemaps.write('./', {
|
||||
sourceRoot: '../',
|
||||
includeContent: false,
|
||||
addComment: true
|
||||
}))
|
||||
.pipe(Gulp.dest(outDir))
|
||||
.on('end', callback);
|
||||
};
|
||||
|
||||
exports.buildJsb = function (sourceFile, outputFile, jsbSkipModules, callback) {
|
||||
var outFile = Path.basename(outputFile);
|
||||
var outDir = Path.dirname(outputFile);
|
||||
|
||||
var bundler = Utils.createBundler(sourceFile);
|
||||
jsbSkipModules.forEach(function (module) {
|
||||
bundler.ignore(require.resolve(module));
|
||||
});
|
||||
bundler.bundle()
|
||||
.on('error', HandleErrors.handler)
|
||||
.pipe(HandleErrors())
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(Uglify(Utils.uglifyOptions(false, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: false,
|
||||
CC_TEST: false,
|
||||
CC_JSB: true
|
||||
})))
|
||||
.pipe(Gulp.dest(outDir))
|
||||
.on('end', callback);
|
||||
};
|
||||
|
||||
exports.buildJsbMin = function (sourceFile, outputFile, jsbSkipModules, callback) {
|
||||
var outFile = Path.basename(outputFile);
|
||||
var outDir = Path.dirname(outputFile);
|
||||
|
||||
var bundler = Utils.createBundler(sourceFile);
|
||||
jsbSkipModules.forEach(function (module) {
|
||||
bundler.ignore(require.resolve(module));
|
||||
});
|
||||
bundler.bundle()
|
||||
.on('error', HandleErrors.handler)
|
||||
.pipe(HandleErrors())
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(Uglify(Utils.uglifyOptions(true, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: false,
|
||||
CC_TEST: false,
|
||||
CC_JSB: true
|
||||
})))
|
||||
.pipe(Gulp.dest(outDir))
|
||||
.on('end', callback);
|
||||
};
|
||||
@@ -0,0 +1,205 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
const Path = require('path');
|
||||
const Async = require('async');
|
||||
const gulp = require('gulp');
|
||||
const File = require('vinyl');
|
||||
const concat = require('gulp-concat');
|
||||
const es = require('event-stream');
|
||||
const sourcemaps = require('gulp-sourcemaps');
|
||||
|
||||
//'./cocos2d/parallax/CCParallaxNode.js',
|
||||
//'./cocos2d/parallax/CCParallaxNodeRenderCmd.js',
|
||||
//'./cocos2d/physics/CCPhysicsDebugNode.js',
|
||||
//'./cocos2d/physics/CCPhysicsDebugNodeCanvasRenderCmd.js',
|
||||
//'./cocos2d/physics/CCPhysicsDebugNodeWebGLRenderCmd.js',
|
||||
|
||||
var modules = {
|
||||
'Core': [
|
||||
'./cocos2d/core/base-nodes/BaseNodesPropertyDefine.js',
|
||||
'./cocos2d/core/base-nodes/CCSGNode.js',
|
||||
'./cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/core/base-nodes/CCSGNodeWebGLRenderCmd.js',
|
||||
'./cocos2d/core/scenes/CCSGScene.js',
|
||||
'./cocos2d/core/scenes/CCLoaderScene.js',
|
||||
'./cocos2d/core/layers/CCLayer.js',
|
||||
'./cocos2d/core/layers/CCLayerCanvasRenderCmd.js',
|
||||
'./cocos2d/core/layers/CCLayerWebGLRenderCmd.js',
|
||||
'./cocos2d/core/CCConfiguration.js',
|
||||
'./cocos2d/core/CCDrawingPrimitivesCanvas.js',
|
||||
'./cocos2d/core/CCDrawingPrimitivesWebGL.js'
|
||||
],
|
||||
|
||||
'Sprite': [
|
||||
'./cocos2d/core/sprites/SpritesPropertyDefine.js',
|
||||
'./cocos2d/core/sprites/CCSGSprite.js',
|
||||
'./cocos2d/core/sprites/CCSGSpriteCanvasRenderCmd.js',
|
||||
'./cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js',
|
||||
'./cocos2d/core/sprites/CCBakeSprite.js',
|
||||
'./cocos2d/core/sprites/CCSpriteBatchNode.js',
|
||||
'./cocos2d/core/sprites/CCSpriteBatchNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js',
|
||||
'./cocos2d/core/sprites/CCScale9Sprite.js',
|
||||
'./cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js',
|
||||
'./cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js'
|
||||
],
|
||||
|
||||
'Label': [
|
||||
'./cocos2d/core/label/CCSGLabel.js',
|
||||
'./cocos2d/core/label/CCSGLabelCanvasRenderCmd.js',
|
||||
'./cocos2d/core/label/CCSGLabelWebGLRenderCmd.js'
|
||||
],
|
||||
|
||||
'Mask': [
|
||||
'./cocos2d/shape-nodes/CCDrawNode.js',
|
||||
'./cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/shape-nodes/CCDrawNodeWebGLRenderCmd.js',
|
||||
'./cocos2d/clipping-nodes/CCClippingNode.js',
|
||||
'./cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js'
|
||||
],
|
||||
|
||||
'ParticleSystem': [
|
||||
'./cocos2d/particle/CCSGParticleSystem.js',
|
||||
'./cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js',
|
||||
'./cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js',
|
||||
'./cocos2d/particle/CCParticleBatchNode.js',
|
||||
'./cocos2d/particle/CCParticleBatchNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js'
|
||||
],
|
||||
|
||||
'TiledMap': [
|
||||
'./cocos2d/tilemap/CCSGTMXTiledMap.js',
|
||||
'./cocos2d/tilemap/CCTMXXMLParser.js',
|
||||
'./cocos2d/tilemap/CCTMXObjectGroup.js',
|
||||
'./cocos2d/tilemap/CCSGTMXLayer.js',
|
||||
'./cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js',
|
||||
'./cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js'
|
||||
],
|
||||
|
||||
'EditorBox': [
|
||||
'./cocos2d/core/editbox/CCSGEditBox.js',
|
||||
'./cocos2d/core/editBox/CCdomNode.js'
|
||||
],
|
||||
|
||||
'VideoPlayer': [
|
||||
'./cocos2d/core/videoplayer/CCSGVideoPlayer.js'
|
||||
],
|
||||
|
||||
'MotionStreak': [
|
||||
'./cocos2d/motion-streak/CCSGMotionStreak.js',
|
||||
'./cocos2d/motion-streak/CCSGMotionStreakWebGLRenderCmd.js',
|
||||
'./cocos2d/render-texture/CCRenderTexture.js',
|
||||
'./cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js',
|
||||
'./cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js'
|
||||
]
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 在生成合并文件的时候插入模块头尾
|
||||
* @returns {*}
|
||||
*/
|
||||
function wrapFile() {
|
||||
var cwd = process.cwd();
|
||||
var headerFile = new File({
|
||||
cwd: cwd, base: cwd, path: Path.resolve('header.js'),
|
||||
contents: new Buffer('(function (cc, ccui, ccs, cp) {\n')
|
||||
});
|
||||
var footerFile = new File({
|
||||
cwd: cwd, base: cwd, path: Path.resolve('footer.js'),
|
||||
contents: new Buffer('\n}).call(window, cc, ccui, ccs, cp);\n')
|
||||
});
|
||||
var isHeaderInserted = false;
|
||||
return es.through(function (file) {
|
||||
if (!isHeaderInserted) {
|
||||
this.emit('data', headerFile);
|
||||
isHeaderInserted = true;
|
||||
}
|
||||
//file.contents = Buffer.concat([header, file.contents, footer]);
|
||||
this.emit('data', file);
|
||||
}, function () {
|
||||
this.emit('data', footerFile);
|
||||
this.emit('end');
|
||||
});
|
||||
}
|
||||
|
||||
exports.buildModular = function ( outFile, outDir, exModule, callback ) {
|
||||
|
||||
var list = [];
|
||||
for (let name in modules) {
|
||||
if (exModule.indexOf(name) !== -1) continue;
|
||||
let files = modules[name];
|
||||
files.forEach((file) => {
|
||||
list.push(file);
|
||||
});
|
||||
}
|
||||
|
||||
list = list.map(function (file) {
|
||||
return Path.join(__dirname, '../../', file);
|
||||
});
|
||||
|
||||
return gulp.src(list)
|
||||
.pipe(wrapFile())
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(concat(outFile))
|
||||
.pipe(sourcemaps.write('./'))
|
||||
.pipe(es.through(function (file) {
|
||||
var content = file.contents.toString();
|
||||
content = content.replace(/\r\n/g, '\n');
|
||||
file.contents = new Buffer(content);
|
||||
this.emit('data', file);
|
||||
}))
|
||||
.pipe(gulp.dest(outDir))
|
||||
.on('end', callback);
|
||||
};
|
||||
|
||||
exports.buildFileWithoutModular = function ( outDir, done ) {
|
||||
var list = [];
|
||||
|
||||
for (let name in modules) {
|
||||
let files = modules[name];
|
||||
list.push({
|
||||
name: name,
|
||||
files: files
|
||||
});
|
||||
}
|
||||
|
||||
outDir = Path.join(__dirname, '../../', outDir, 'modules');
|
||||
Async.eachSeries(list, function ( item, next ) {
|
||||
return gulp.src(item.files.map(function ( path ) {
|
||||
console.log(Path.join(__dirname, '../../', path));
|
||||
return Path.join(__dirname, '../../', path)
|
||||
}))
|
||||
.pipe(concat(item.name + '.js'))
|
||||
.pipe(gulp.dest(outDir))
|
||||
.on('end', next);
|
||||
}, function () {
|
||||
done();
|
||||
});
|
||||
};
|
||||
+61
-32
@@ -5,11 +5,11 @@
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
@@ -23,43 +23,72 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Fs = require('fire-fs');
|
||||
var gulp = require('gulp');
|
||||
var fb = require('gulp-fb');
|
||||
var shell = require('gulp-shell');
|
||||
'use strict';
|
||||
|
||||
var TimeOutInSeconds = 5;
|
||||
const Path = require('fire-path');
|
||||
const Fs = require('fire-fs');
|
||||
const Del = require('del');
|
||||
const Source = require('vinyl-source-stream');
|
||||
const Gulp = require('gulp');
|
||||
const Fb = require('gulp-fb');
|
||||
const Buffer = require('vinyl-buffer');
|
||||
const HandleErrors = require('../util/handleErrors');
|
||||
const EventStream = require('event-stream');
|
||||
|
||||
gulp.task('unit-runner', function() {
|
||||
var js = paths.test.src;
|
||||
var dest = paths.outDir;
|
||||
var libs = [paths.test.dest];
|
||||
const Utils = require('./utils');
|
||||
|
||||
exports.build = function (sourceFile, outputFile, callback) {
|
||||
var jsEntryEditorExtends = '../editor/test-utils/engine-extends-entry.js';
|
||||
|
||||
var bundler = Utils.createBundler(sourceFile);
|
||||
var engine = bundler.bundle()
|
||||
.on('error', HandleErrors.handler)
|
||||
.pipe(HandleErrors())
|
||||
.pipe(Source(Path.basename(outputFile)))
|
||||
.pipe(Buffer())
|
||||
.pipe(Gulp.dest(Path.dirname(outputFile)));
|
||||
|
||||
if (Fs.existsSync(jsEntryEditorExtends)) {
|
||||
var editorExtends = Utils.createBundler(jsEntryEditorExtends)
|
||||
.bundle()
|
||||
.on('error', HandleErrors.handler)
|
||||
.pipe(HandleErrors())
|
||||
.pipe(Source(Path.basename(jsEntryEditorExtends)))
|
||||
.pipe(Buffer())
|
||||
.pipe(Gulp.dest(Path.dirname(outputFile)));
|
||||
EventStream.merge(engine, editorExtends)
|
||||
.on('end', callback);
|
||||
} else {
|
||||
engine.on('end', callback);
|
||||
}
|
||||
};
|
||||
|
||||
exports.clean = function (list, callback) {
|
||||
Del(list, callback)
|
||||
};
|
||||
|
||||
exports.unit = function (outDir, libs, callback) {
|
||||
var title = 'Cocos2d-JS Test Suite';
|
||||
if (Fs.existsSync(paths.test.destEditorExtends)) {
|
||||
libs.push(paths.test.destEditorExtends);
|
||||
if (Fs.existsSync('./bin/cocos2d-js-extends-for-test.js')) {
|
||||
libs.push('./bin/cocos2d-js-extends-for-test.js');
|
||||
title += ' (Editor Extends Included)'
|
||||
}
|
||||
return gulp.src(js, { read: false, base: './' })
|
||||
.pipe(fb.toFileList())
|
||||
.pipe(fb.generateRunner(paths.test.runner, dest, title, libs))
|
||||
.pipe(gulp.dest(dest));
|
||||
});
|
||||
return Gulp.src('test/qunit/unit/**/*.js', { read: false, base: './' })
|
||||
.pipe(Fb.toFileList())
|
||||
.pipe(Fb.generateRunner('test/qunit/lib/qunit-runner.html', outDir, title, libs))
|
||||
.pipe(Gulp.dest(outDir))
|
||||
.on('end', callback);
|
||||
};
|
||||
|
||||
function test () {
|
||||
exports.test = function (callback) {
|
||||
var qunit;
|
||||
try {
|
||||
qunit = require('gulp-qunit');
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
console.error('Please run "npm install gulp-qunit" before running "gulp test".');
|
||||
throw e;
|
||||
}
|
||||
return gulp.src('bin/qunit-runner.html', { read: false })
|
||||
.pipe(qunit({ timeout: TimeOutInSeconds }));
|
||||
}
|
||||
|
||||
gulp.task('test', ['build-test', 'unit-runner'], test);
|
||||
gulp.task('visual-test', ['build-test'], shell.task([
|
||||
'sh ./test/visual-tests/run.sh'
|
||||
]));
|
||||
gulp.task('test-no-build', test);
|
||||
return Gulp.src('bin/qunit-runner.html', { read: false })
|
||||
.pipe(qunit({ timeout: 5 }))
|
||||
.on('end', callback);
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
const Path = require('path');
|
||||
const Browserify = require('browserify');
|
||||
|
||||
exports.uglifyOptions = function (minify, global_defs) {
|
||||
if (minify) {
|
||||
return {
|
||||
compress: {global_defs: global_defs}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
mangle: false,
|
||||
//preserveComments: 'all',
|
||||
output: {
|
||||
// http://lisperator.net/uglifyjs/codegen
|
||||
beautify: true,
|
||||
bracketize: true
|
||||
},
|
||||
compress: {
|
||||
// http://lisperator.net/uglifyjs/compress
|
||||
global_defs: global_defs,
|
||||
sequences: false, // join consecutive statements with the “comma operator”
|
||||
properties: false, // optimize property access: a["foo"] → a.foo
|
||||
//dead_code: true, // discard unreachable code
|
||||
drop_debugger: false, // discard “debugger” statements
|
||||
unsafe: false, // some unsafe optimizations (see below)
|
||||
conditionals: false, // optimize if-s and conditional expressions
|
||||
comparisons: false, // optimize comparisons
|
||||
//evaluate: true, // evaluate constant expressions
|
||||
booleans: false, // optimize boolean expressions
|
||||
loops: false, // optimize loops
|
||||
unused: false, // drop unused variables/functions
|
||||
hoist_funs: false, // hoist function declarations
|
||||
hoist_vars: false, // hoist variable declarations
|
||||
if_return: false, // optimize if-s followed by return/continue
|
||||
join_vars: false, // join var declarations
|
||||
cascade: false, // try to cascade `right` into `left` in sequences
|
||||
side_effects: false // drop side-effect-free statements
|
||||
//warnings: true // warn about potentially dangerous optimizations/code
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.createBundler = function createBundler(entryFiles) {
|
||||
// https://github.com/substack/node-browserify#methods
|
||||
var options = {
|
||||
debug: true, //temporarily disable due to an asar packing bug
|
||||
detectGlobals: false, // dont insert `process`, `global`, `__filename`, and `__dirname`
|
||||
bundleExternal: false // dont bundle external modules
|
||||
//standalone: 'engine-framework',
|
||||
//basedir: tempScriptDir
|
||||
};
|
||||
return new Browserify(entryFiles, options)
|
||||
.exclude(Path.join(__dirname, '../../package.json'));
|
||||
};
|
||||
+15
-18
@@ -1,17 +1,16 @@
|
||||
var gulp = require('gulp');
|
||||
var watchify = require('watchify');
|
||||
var browserify = require('browserify');
|
||||
var Fs = require('fs');
|
||||
var Path = require('path');
|
||||
var Watchify = require('watchify');
|
||||
var Browserify = require('browserify');
|
||||
var Fs = require('fire-fs');
|
||||
|
||||
function watchFile(opts) {
|
||||
var bundler = new browserify(opts.entries, {
|
||||
var bundler = new Browserify(opts.entries, {
|
||||
cache: {},
|
||||
packageCache: {},
|
||||
debug: true,
|
||||
detectGlobals: false, // dont insert `process`, `global`, `__filename`, and `__dirname`
|
||||
bundleExternal: false, // dont bundle external modules
|
||||
plugin: [watchify]
|
||||
plugin: [Watchify]
|
||||
});
|
||||
|
||||
bundler.on('update', bundle);
|
||||
@@ -46,26 +45,24 @@ function watchFile(opts) {
|
||||
return bundle();
|
||||
}
|
||||
|
||||
gulp.task('watch-preview', function () {
|
||||
exports.preview = function (sourceFile, outputFile) {
|
||||
return watchFile({
|
||||
entries: paths.jsEntry,
|
||||
dest: paths.preview.dest,
|
||||
entries: sourceFile,
|
||||
dest: outputFile,
|
||||
prefix: 'CC_DEV = true;\n'
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
gulp.task('watch-jsb-polyfill', function () {
|
||||
exports.jsbPolyfill = function (sourceFile, outputFile, skipModules) {
|
||||
return watchFile({
|
||||
entries: paths.jsb.entries,
|
||||
dest: Path.join(paths.outDir, paths.jsb.outFileDev),
|
||||
entries: sourceFile,
|
||||
dest: outputFile,
|
||||
prefix: function () {
|
||||
var prefix = 'CC_DEV = true;\n';
|
||||
prefix += 'CC_JSB = true;\n';
|
||||
|
||||
|
||||
return prefix;
|
||||
},
|
||||
skips: paths.jsb.skipModules
|
||||
skips: skipModules
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('watch-dev-files', ['watch-preview', 'watch-jsb-polyfill']);
|
||||
};
|
||||
+137
-46
@@ -23,59 +23,150 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var gulp = require('gulp');
|
||||
var requireDir = require('require-dir');
|
||||
var Path = require('path');
|
||||
'use strict';
|
||||
|
||||
MinifyOriginCocos2d = false; // true - compile by closure, false - just concat
|
||||
const Path = require('fire-path');
|
||||
const gulp = require('gulp');
|
||||
const Del = require('del');
|
||||
const Shell = require('gulp-shell');
|
||||
|
||||
// specify game project paths for tasks.
|
||||
paths = {
|
||||
src: './src',
|
||||
jsEntry: './index.js',
|
||||
outDir: './bin',
|
||||
outFileDev: 'cocos2d-js.js',
|
||||
outFile: 'cocos2d-js-min.js',
|
||||
const Modular = require('./gulp/tasks/modular');
|
||||
const Engine = require('./gulp/tasks/engine');
|
||||
const Test = require('./gulp/tasks/test');
|
||||
const Watch = require('./gulp/tasks/watch');
|
||||
|
||||
jsb: {
|
||||
entries: [
|
||||
'./jsb/index.js',
|
||||
'./extends.js'
|
||||
],
|
||||
outFile: 'jsb_polyfill.js',
|
||||
outFileDev: 'jsb_polyfill.dev.js',
|
||||
skipModules: [
|
||||
'../../cocos2d/core/CCGame',
|
||||
'../../cocos2d/core/textures/CCTexture2D',
|
||||
'../../cocos2d/core/sprites/CCSpriteFrame',
|
||||
'../../cocos2d/core/event/event',
|
||||
'../../cocos2d/core/load-pipeline/audio-downloader',
|
||||
'../../cocos2d/audio/CCAudio',
|
||||
'../../extensions/spine/SGSkeleton',
|
||||
'../../extensions/spine/SGSkeletonAnimation',
|
||||
'../../extensions/spine/SGSkeletonCanvasRenderCmd',
|
||||
'../../extensions/spine/SGSkeletonWebGLRenderCmd',
|
||||
'../../extensions/spine/lib/spine',
|
||||
],
|
||||
},
|
||||
///////////////
|
||||
// modular //
|
||||
///////////////
|
||||
|
||||
test: {
|
||||
src: 'test/qunit/unit/**/*.js',
|
||||
runner: 'test/qunit/lib/qunit-runner.html',
|
||||
jsEntryEditorExtends: '../editor/test-utils/engine-extends-entry.js', // only available in editor
|
||||
dest: 'bin/cocos2d-js-for-test.js',
|
||||
destEditorExtends: 'bin/cocos2d-js-extends-for-test.js'
|
||||
},
|
||||
//gulp.task('build-file-without-module', function (done) {
|
||||
// Modular.buildFileWithoutModular(paths.outDir, done);
|
||||
//});
|
||||
gulp.task('build-all-modular', function (done) {
|
||||
Modular.buildModular('modular-cocos2d.js', './bin', [], done);
|
||||
});
|
||||
gulp.task('build-cut-modular', function (done) {
|
||||
Modular.buildModular('modular-cocos2d-cut.js', './bin', [], done);
|
||||
});
|
||||
|
||||
preview: {
|
||||
dest: 'bin/cocos2d-js-for-preview.js',
|
||||
},
|
||||
gulp.task('build-modular-cocos2d', ['build-all-modular', 'build-cut-modular']);
|
||||
|
||||
modularCocos2d: './bin/modular-cocos2d.js',
|
||||
};
|
||||
|
||||
// require all tasks in gulp/tasks, including sub-folders
|
||||
requireDir('./gulp/tasks', { recurse: true });
|
||||
/////////////
|
||||
// engine //
|
||||
/////////////
|
||||
|
||||
gulp.task('build-cocos2d-dev', ['build-modular-cocos2d'], function (done) {
|
||||
Engine.buildCocosJs('./index.js', './bin/cocos2d-js.js', ['./bin/modular-cocos2d-cut.js'], done);
|
||||
});
|
||||
|
||||
gulp.task('build-cocos2d-min', ['build-modular-cocos2d'], function (done) {
|
||||
Engine.buildCocosJsMin('./index.js', './bin/cocos2d-js-min.js', ['./bin/modular-cocos2d-cut.js'], done);
|
||||
});
|
||||
|
||||
gulp.task('build-html5', ['build-cocos2d-dev', 'build-cocos2d-min']);
|
||||
|
||||
gulp.task('build-preview', ['build-modular-cocos2d'], function (done) {
|
||||
Engine.buildPreview('./index.js', './bin/cocos2d-js-for-preview.js', done);
|
||||
});
|
||||
|
||||
var jsbSkipModules = [
|
||||
'../../cocos2d/core/CCGame',
|
||||
'../../cocos2d/core/textures/CCTexture2D',
|
||||
'../../cocos2d/core/sprites/CCSpriteFrame',
|
||||
'../../cocos2d/core/event/event',
|
||||
'../../cocos2d/core/load-pipeline/audio-downloader',
|
||||
'../../cocos2d/audio/CCAudio',
|
||||
'../../extensions/spine/SGSkeleton',
|
||||
'../../extensions/spine/SGSkeletonAnimation',
|
||||
'../../extensions/spine/SGSkeletonCanvasRenderCmd',
|
||||
'../../extensions/spine/SGSkeletonWebGLRenderCmd',
|
||||
'../../extensions/spine/lib/spine'
|
||||
];
|
||||
|
||||
gulp.task('build-jsb-extends-dev', function (done) {
|
||||
Engine.buildJsb([
|
||||
'./jsb/index.js',
|
||||
'./extends.js'
|
||||
], './bin/jsb_polyfill.dev.js', jsbSkipModules, done);
|
||||
});
|
||||
|
||||
gulp.task('build-jsb-extends-min', function (done) {
|
||||
Engine.buildJsbMin([
|
||||
'./jsb/index.js',
|
||||
'./extends.js'
|
||||
], './bin/jsb_polyfill.js', jsbSkipModules, done);
|
||||
});
|
||||
|
||||
gulp.task('build-jsb', ['build-jsb-extends-dev', 'build-jsb-extends-min']);
|
||||
|
||||
gulp.task('build-min', ['build-html5', 'build-jsb']);
|
||||
|
||||
|
||||
/////////
|
||||
// test //
|
||||
/////////
|
||||
|
||||
gulp.task('clean-test', function (done) {
|
||||
Test.clean([
|
||||
'./bin/cocos2d-js-extends-for-test.js',
|
||||
'./bin/cocos2d-js-for-test.js'
|
||||
], done);
|
||||
});
|
||||
|
||||
gulp.task('build-test', ['build-modular-cocos2d', 'clean-test'], function (done) {
|
||||
Test.build('./index.js', './bin/cocos2d-js-for-test.js', done);
|
||||
});
|
||||
|
||||
gulp.task('unit-runner', [], function (done) {
|
||||
Test.unit('./bin', [
|
||||
'./bin/cocos2d-js-for-test.js'
|
||||
], done);
|
||||
});
|
||||
|
||||
gulp.task('test', ['build-test', 'unit-runner'], function (done) {
|
||||
Test.test(done);
|
||||
});
|
||||
|
||||
gulp.task('visual-test', ['build-test'], Shell.task([
|
||||
'sh ./test/visual-tests/run.sh'
|
||||
]));
|
||||
|
||||
gulp.task('test-no-build', function (done) {
|
||||
Test.test(done);
|
||||
});
|
||||
|
||||
////////////
|
||||
// global //
|
||||
////////////
|
||||
|
||||
gulp.task('build-dev', ['build-preview', 'build-jsb-extends-dev'], function (done) {
|
||||
// make dist version dirty
|
||||
Del(['./bin/cocos2d-js.js', './bin/cocos2d-js-min.js', './bin/jsb_polyfill.js'], done);
|
||||
});
|
||||
|
||||
gulp.task('build', ['build-html5', 'build-preview', 'build-jsb-extends-min', 'build-jsb-extends-dev']);
|
||||
|
||||
// default task
|
||||
gulp.task('default', ['build']);
|
||||
|
||||
gulp.task('clean', function (done) {
|
||||
Del(Path.join('./bin', '**/*'), done);
|
||||
});
|
||||
|
||||
////////////
|
||||
// watch //
|
||||
////////////
|
||||
|
||||
gulp.task('watch-preview', function () {
|
||||
Watch.preview('./index.js', './bin/cocos2d-js-for-preview.js');
|
||||
});
|
||||
|
||||
gulp.task('watch-jsb-polyfill', function () {
|
||||
Watch.jsbPolyfill([
|
||||
'./jsb/index.js',
|
||||
'./extends.js'
|
||||
], './bin/jsb_polyfill.dev.js', jsbSkipModules);
|
||||
});
|
||||
|
||||
gulp.task('watch-dev-files', ['watch-preview', 'watch-jsb-polyfill']);
|
||||
|
||||
@@ -48,7 +48,15 @@ require('./predefine');
|
||||
var isMainProcess = CC_EDITOR && Editor.isMainProcess;
|
||||
if (!isMainProcess) {
|
||||
// LOAD ORIGIN COCOS2D COMPILED BY CLOSURE
|
||||
require('./bin/modular-cocos2d');
|
||||
try {
|
||||
require('./bin/modular-cocos2d');
|
||||
} catch (error) {
|
||||
if (error.code === 'MODULE_NOT_FOUND') {
|
||||
require('./bin/modular-cocos2d-cut');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// load modules for editor's core-level which included in modular-cocos2d.js
|
||||
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
[
|
||||
{
|
||||
"name": "Core",
|
||||
"locked": true,
|
||||
"entries": []
|
||||
},
|
||||
{
|
||||
"name": "Canvas",
|
||||
"locked": true,
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCCanvas.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Sprite",
|
||||
"locked": true,
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCSprite.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Label",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCLabel.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Mask",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCMask.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CCSpriteDistortion",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCSpriteDistortion.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "LabelOutline",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCLabelOutline.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ParticleSystem",
|
||||
"entries": [
|
||||
"./cocos2d/particle.CCParticleSystem.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "TiledMap",
|
||||
"entries": [
|
||||
"./cocos2d/tilemap/CCTiledMap.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Spine Skeleton",
|
||||
"entries": [
|
||||
"./extensions/spine/index.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Widget",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCWidget.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Button",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCButton.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ProgressBar",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCProgressBar.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ScrollBar",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCScrollBar.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ScrollView",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCScrollView.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Layout",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCLayout.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "EditorBox",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCEditBox.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "VideoPlayer",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCVideoPlayer.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "AudioSource",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCAudioSource.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Animation",
|
||||
"entries": [
|
||||
"./cocos2d/core/components/CCAnimation.js",
|
||||
"./cocos2d/animation/index.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "MotionStreak",
|
||||
"entries": [
|
||||
"./cocos2d/motion-streak/CCMotionStreak.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Collider",
|
||||
"entries": [
|
||||
"./cocos2d/core/collider/index.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user