Permalink
Browse files

Add script to build standalone version

  • Loading branch information...
1 parent 3ee8b47 commit 113f9e11ad0f32b964e0cac10679dc237f1dd626 @ryanwilliams committed Jun 9, 2012
Showing with 110 additions and 0 deletions.
  1. +54 −0 support/distribution/standalone.js
  2. +56 −0 support/distribution/standalone.template
@@ -0,0 +1,54 @@
+#!/usr/bin/env node
+
+/**
+ * @fileOverview Generates a standalone build
+ */
+
+var path = require('path')
+ , sys = require('util')
+ , fs = require('fs')
+ , opts = require('../../lib/cocos2d/opts')
+ , spawn = require('child_process').spawn
+ , Template = require('../../lib/cocos2d/template').Template
+ , Compiler = require('../../lib/cocos2d/compiler').Compiler
+
+;(function main() {
+ 'use strict'
+
+ sys.puts("Generating cocos2d.js")
+
+ var compiler = new Compiler
+ compiler.parseConfig({ libs: ["cocos2d"]
+ , externalize: { cocos2d: "cocos2d.js"
+ , jah: "cocos2d.js"
+ }
+ })
+
+ var pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf8'))
+ , version = 'v' + pkg.version
+ , src = compiler.buildPackages()['cocos2d.js']
+ , wrapper = new Template(fs.readFileSync(path.join(__dirname, 'standalone.template'), 'utf8'))
+ , filename = 'cocos2d-' + version
+
+ // Pad version so copyright frame lines up
+ while (version.length < 20) version += ' '
+
+ var code = wrapper.substitute({"cocos2d.js": src, "version": version})
+
+ if (!path.existsSync('build')) {
+ fs.mkdirSync('build', 511);
+ }
+ fs.writeFileSync('build/' + filename + '.js', code, 'utf8')
+ sys.puts('Wrote to build/' + filename + '.js')
+
+ var uglify = spawn('uglifyjs', ['-o', path.join('build', filename + '.min.js'), path.join('build', filename + '.js')], {cwd: __dirname});
+ uglify.on('exit', function (data) {
+ // Fix the missing newline after copyright
+ var minified = fs.readFileSync(path.join(__dirname, 'build/' + filename + '.min.js'), 'utf8')
+ minified = minified.replace('*/', '*/\n\n')
+ fs.writeFileSync('build/' + filename + '.min.js', minified, 'utf8')
+
+ sys.puts('Wrote to build/' + filename + '.min.js')
+ })
+})();
+
@@ -0,0 +1,56 @@
+/************************************************************************\
+| Cocos2D.js $version$ |
+| |
+| Copyright (c) 2010-2012 Ryan Williams |
+| |
+| Permission is hereby granted, free of charge, to any person obtaining |
+| a copy of this software and associated documentation files (the |
+| "Software"), to deal in the Software without restriction, including |
+| without limitation the rights to use, copy, modify, merge, publish, |
+| distribute, sublicense, and/or sell copies of the Software, and to |
+| permit persons to whom the Software is furnished to do so, subject to |
+| the following conditions: |
+| |
+| The above copyright notice and this permission notice shall be |
+| included in all copies or substantial portions of the Software. |
+| |
+| 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. |
+\************************************************************************/
+
+(function(cc) {
+ var __jah__ = {resources:{}, assetURL: ""};
+
+ $cocos2d.js$
+
+ ;(function(){
+ __jah__.resources["/main.js"] = {data: function (exports, require, resource, module, __filename, __dirname) {
+ var modules = { cocos: require('cocos2d')
+ , events: require('events')
+ , geo: require('geometry')
+ }
+
+ var skip = 'nodes actions'.w
+
+ var modName, mod, key
+ for (modName in modules) {
+ mod = modules[modName]
+ for (key in mod) {
+ if (mod.hasOwnProperty(key) && skip.indexOf(key) == -1) {
+ cc[key] = mod[key]
+ }
+ }
+ }
+
+ window.cc = cc
+
+ }, mimetype: "application/javascript", remote: false}; // END: /main.js
+
+
+ })();
+})({STANDALONE: true})

0 comments on commit 113f9e1

Please sign in to comment.