<commit_before>#!/usr/bin/env python

from optparse import OptionParser
import subprocess
import sys, re, os, base64, mimetypes, codecs, shutil

INDEX_TEMPLATE = '''
<!doctype html> 
<html> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
        <script src="{script_name}" type="text/javascript"></script> 
        <title>{project_name}</title> 
        <style type="text/css" media="screen"> 
            body {{
                font-family: Helvetica, Arial, sans-serif;
                font-size: 10pt;
            }}
            #cocos2d-app {{
                border: 1px solid #000;
                width: 480px;
                height: 320px;
                margin: 0 20px;
            }}
        </style> 
    </head> 
    <body> 
        <h1>{project_name}</h1> 
       <div id="cocos2d-app"></div> 
    </body> 
</html> 
'''

MAKE_JS_TEMPLATE = '''
{{
    "output":     "public/{script_name}",
    "extensions": ["js", "gif", "jpeg", "jpg", "png", "tmx", "tsx", "plist"],
    "main_module": "main",

    "paths": {{
        "cocos2d/src" : "/",
        "src" : "/"
    }}
}}
'''

MAIN_JS_TEMPLATE = '''
// Import the cocos2d module
var cocos = require('cocos2d'),
// Import the geometry module
    geo = require('geometry');

// Create a new layer
var {class_name} = cocos.nodes.Layer.extend({{
    init: function() {{
        // You must always call the super class version of init
        @super;

        // Get size of canvas
        var s = cocos.Director.get('sharedDirector').get('winSize');

        // Create label
        var label = cocos.nodes.Label.create({{string: '{project_name}', fontName: 'Arial', fontSize: 76}});

        // Add label to layer
        this.addChild({{child: label, z:1}});

        // Position the label in the centre of the view
        label.set('position', geo.ccp(s.width / 2, s.height / 2));
    }}
}});

// Initialise everything

// Get director
var director = cocos.Director.get('sharedDirector');

// Attach director to our <div> element
director.attachInView(document.getElementById('cocos2d-app'));

// Create a scene
var scene = cocos.nodes.Scene.create();

// Add our layer to the scene
scene.addChild({{child: {class_name}.create()}});

// Run the scene
director.runWithScene(scene);
'''


def main():
    def removeNonAscii(s):
        return "".join(i for i in s if ord(i) < 128)

    parser = OptionParser(usage="Usage: cocos new APP_PATH")
    parser.add_option("-g", "--no-git", action="store_true", dest="nogit")

    (options, args) = parser.parse_args()

    use_git = not options.nogit
    project_path = os.path.abspath(args[0])
    project_name = os.path.basename(project_path)
    script_name = removeNonAscii(project_name.lower().replace(' ', '_')) +'.js'
    class_name = re.sub('(?:^| )(.)', lambda m: m.group(1).upper(), removeNonAscii(project_name.lower()))

    paths = (
        'src',
        'src/resources',
        'public',
    )
    
    # Create initial folders
    print "Creating cocos2d-javascript project in: %s" % project_path
    for p in paths:
        full_path = os.path.join(project_path, p)<commit_msg>Added check for app path when calling ./cocos new<commit_after>#!/usr/bin/env python

from optparse import OptionParser
import subprocess
import sys, re, os, base64, mimetypes, codecs, shutil

INDEX_TEMPLATE = '''
<!doctype html> 
<html> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
        <script src="{script_name}" type="text/javascript"></script> 
        <title>{project_name}</title> 
        <style type="text/css" media="screen"> 
            body {{
                font-family: Helvetica, Arial, sans-serif;
                font-size: 10pt;
            }}
            #cocos2d-app {{
                border: 1px solid #000;
                width: 480px;
                height: 320px;
                margin: 0 20px;
            }}
        </style> 
    </head> 
    <body> 
        <h1>{project_name}</h1> 
       <div id="cocos2d-app"></div> 
    </body> 
</html> 
'''

MAKE_JS_TEMPLATE = '''
{{
    "output":     "public/{script_name}",
    "extensions": ["js", "gif", "jpeg", "jpg", "png", "tmx", "tsx", "plist"],
    "main_module": "main",

    "paths": {{
        "cocos2d/src" : "/",
        "src" : "/"
    }}
}}
'''

MAIN_JS_TEMPLATE = '''
// Import the cocos2d module
var cocos = require('cocos2d'),
// Import the geometry module
    geo = require('geometry');

// Create a new layer
var {class_name} = cocos.nodes.Layer.extend({{
    init: function() {{
        // You must always call the super class version of init
        @super;

        // Get size of canvas
        var s = cocos.Director.get('sharedDirector').get('winSize');

        // Create label
        var label = cocos.nodes.Label.create({{string: '{project_name}', fontName: 'Arial', fontSize: 76}});

        // Add label to layer
        this.addChild({{child: label, z:1}});

        // Position the label in the centre of the view
        label.set('position', geo.ccp(s.width / 2, s.height / 2));
    }}
}});

// Initialise everything

// Get director
var director = cocos.Director.get('sharedDirector');

// Attach director to our <div> element
director.attachInView(document.getElementById('cocos2d-app'));

// Create a scene
var scene = cocos.nodes.Scene.create();

// Add our layer to the scene
scene.addChild({{child: {class_name}.create()}});

// Run the scene
director.runWithScene(scene);
'''


def main():
    def removeNonAscii(s):
        return "".join(i for i in s if ord(i) < 128)

    parser = OptionParser(usage="Usage: cocos new APP_PATH")
    parser.add_option("-g", "--no-git", action="store_true", dest="nogit")

    (options, args) = parser.parse_args()

    if not str(args[0]).strip():
        print "Usage: cocos new APP_PATH"
        return 1


    use_git = not options.nogit
    project_path = os.path.abspath(args[0])
    project_name = os.path.basename(project_path)
    script_name = removeNonAscii(project_name.lower().replace(' ', '_')) +'.js'
    class_name = re.sub('(?:^| )(.)', lambda m: m.group(1).upper(), removeNonAscii(project_name.lower()))

    paths = (
        'src',
        'src/resources',
        'public',
    )
    
    # Create initial folders
    print "Creating cocos2d-javascript project in: %s" % project_path
    for p in paths:
        full_path = os.path.join(project_path, p)
{'fraction_non_alphanumeric': 0.1631857855361596, 'fraction_numerical': 0.011845386533665835, 'mean_word_length': 2.5027292576419216, 'pattern_counts': {'":': 8, '<': 43, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1249809', 'n_tokens_mistral': 2211, 'n_tokens_neox': 2058, 'n_words': 501}