Custom build template for FB instant games per project

Custom build template for FB instant games per project
0.0 0

#1

I would like to have a custom build template for my FB instant games projects, preferably different for each of the projects I have.

According to the documentation about custom templates it seems easy (see here. However, after searching in CocosCreator/resources/static/build-templates there is no fb target.

I tried creating my custom build template folder for instant games anyway, however files are not being swapped.

After some more digging I found this documentation, where under Custom Instant Games paragraph you can find that you can change index.html file for a custom one under resources/static/fb-instant-games/.

Is it really the only existing solution, changing it globally? No possibility to have custom build template per each of my instant games projects?


#2

We have a build script that takes care of that. CC supports only one template pr. build target so you have to overwrite it before compiling.

With the example below you can build and upload to facebook with
sh my_compile_and_upload_script.sh "some comment"

#!/bin/bash -i
COMMENT=$1
if [ -z "$COMMENT" ]; then COMMENT="Staging"; fi

STARTDIR=`pwd`
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
APPID=11111111111111111
ACCESSTOKEN='ABCDEF1234567890'

echo $STARTDIR
echo $BASEDIR

echo '***************************'
echo '**                       **'
echo '**     COPY TEMPLATE     **'
echo '**                       **'
echo '***************************'
cd $BASEDIR
cd ..
rm -rf build-templates
mkdir build-templates
cp -r build-scripts/templates/build-templates-facebook/web-mobile build-templates/web-mobile

echo '***************************'
echo '**                       **'
echo '**        STAGING        **'
echo '**                       **'
echo '***************************'

echo 'APP ID: ' $APPID
echo 'ACCESS TOKEN: ' $ACCESSTOKEN

echo '***************************'
echo '**                       **'
echo '**     BUILD PROJECT     **'
echo '**                       **'
echo '***************************'

cd $BASEDIR
mkdir -p ../build
/Applications/CocosCreator.app/Contents/MacOS/CocosCreator --path ../ --build "platform=web-mobile;buildPath=./build"
cd ../build/web-mobile/
rm -f ../build/buildwebmobile.zip && zip -r ../buildwebmobile.zip  ./
echo '***************************'
echo '**                       **'
echo '** UPLOADING TO FACEBOOK **'
echo '**                       **'
echo '***************************'
curl -O -# -X POST https://graph-video.facebook.com/$APPID/assets -F 'access_token='"$ACCESSTOKEN"'' -F 'type=BUNDLE' -F 'asset=@../buildwebmobile.zip' -F "comment=$COMMENT"

cd $STARTDIR
echo 'DONE!'


#3

That is really nice workaround :wink:

However, now cocos supports custom build templates per build target per project, which doesn’t need overriding cocos templates, but use files located in PROJECT_PATH/build-templates/build-target, that is why I asked why there is no similar solution for Facebook Instant Games.

If cocos devs won’t add it we probably end up with such building and copying script as well.

Thanks for sharing.


#4

Ooh. I didn’t know. Since when does it support that?


#5

I’m not sure since when, because we started development with 1.8 version. Here is link to documentation.


#6

As far as I can see this is just pr. target. In our case we would need two different web-mobile templates.


#7

I found that it actually works, but the “fb-instant-games” template folder is in the wrong place in the Cocos Creator app package (on Mac). I moved that folder into the “Cocos Creator/Contents/Resources/static/build-templates” folder, and it worked as described in the documentation.

So, you can have a config per project, but the default Cocos distribution has it in the wrong place. Maybe they will fix that in the next patch. It’s a simple matter of moving one folder. :slight_smile:

UPDATE: Ah, poop. Looks like there’s still some issue in the engine because the main.js file has some syntax error (renderMode: <%=renderMode%>) preventing the app from starting. So close.

UPDATE2: In main.js, I changed the rendermode to 0 (which is supposed to let the engine decide), and my app started correctly. Not sure what the consequences of letting the engine choose are.

UPDATE3: I noticed some other “template” variables that are not being populated correctly in index.html, but they don’t seem to have a noticeable effect (not yet, anyway). The devs need to verify this feature and make sure it’s working 100%. I’m using Cocos Creator 1.9.0.