NOTE: These docs are a bit older, and have not been updated in a while. For example, you no longer need to install Gulp globally, as we run Gulp via Yarn tasks instead.
Ensure the correct version of gulp is installed globally:
npm install -g gulpjs/gulp-cli#4.0
To check your version, run gulp -v
:
[12:39:16] CLI version 0.4.0
[12:39:16] Local version 4.0.0-alpha.2
The main gulpfile.babel.js
defines the task names and groupings.
Tasks are saved in different files in the /gulp
folder.
A task is a function that when complete either:
- calls a callback
- returns a Promise
- returns a stream
Print a list of available tasks by running gulp --tasks
.
To run a task, run gulp <taskname>
.
The clean tasks wipe the output build folders. There are 3 variations:
gulp clean:all
: removes all output filesgulp clean:desktop
: removes only output files related to desktop buildgulp clean:git
: removes git remotes used for desktop git mirrors
gulp css
The css task compiles our SASS files into plain css. Note here, based on our target build environment (staging, production), we replace URLs found in our css with CDN urls.
.pipe(gif(production || staging,
rework(reworkUrl(url => {
if (url.indexOf('resources') >= 0 && config.get('cdn') !== '') {
return config.get('cdn') + '/' + url
}
return url
}))
))
gulp html
The html task compiles the handlebars index.hbs
file into plain html. Note here we inject some configuration variables so they are available in the output html.
data: {
version: version,
development: development,
analyticsEnabled: config.get('analyticsEnabled'),
analyticsId: config.get('analyticsId'),
bugsnagId: config.get('bugsnag.client_key'),
bugsnagDesktopId: config.get('bugsnag.desktop_key'),
gaId: config.get('gaId'),
cdn: config.get('cdn')
}
gulp vendor
The vendor task concats our external javascript files (outside the main bundle) into a single vendor.js file which is included prior to the main bundle. This includes cocos
and other external dependencies which are not Browserified. Note that ordering matters and they are concatenated in order specified.
const vendorFiles = [
'./node_modules/@bower_components/jquery/jquery.js',
'./node_modules/@bower_components/velocity/velocity.js',
'./node_modules/@bower_components/bootstrap-sass-official/assets/javascripts/bootstrap.js',
'./node_modules/@bower_components/underscore/underscore.js',
'./node_modules/@bower_components/backbone/backbone.js',
'./node_modules/@bower_components/backfire/dist/backfire.js',
'./node_modules/@bower_components/backbone.marionette/lib/backbone.marionette.js',
'./app/vendor/jquery_ui/jquery-ui.min.js',
'./app/vendor/ccConfig.js',
'./app/vendor/cocos2d-html5/lib/cocos2d-js-v3.3-beta0.js',
'./app/vendor/aws/aws-sdk.min.js',
'./app/vendor/aws/aws-sdk-mobile-analytics.min.js'
]
gulp js
The bundle task is our main javascript packager using Browserify. Browserify allows us to use node.js require
syntax (aka common.js
) in the browser. Browserify also allows us to define transforms
which are applied to our source code:
bundler.transform(coffeeify) // transforms .coffee to .js
bundler.transform(hbsfy) // transforms client .hbs to .html fragments
bundler.transform(glslify) // transforms shader files into .js
bundler.transform(envify()) // turns specified variables into process.env.*
Browserify also has a built in file watcher called watchify
which is enabled during development to allow for faster incremental builds.
The rsx tasks are used to prepare our resource files for distribution.
gulp rsx:packages
: generates the client resource packages inapp/data
gulp rsx:copy
: moves files fromapp/resources
intodist/resources
gulp rsx:build_urls
: modifies thedist/*.js
files to use CDN urlsgulp rsx:source_urls
: modifies theapp/resources
files to use CDN urlsgulp rsx:imagemin
: minifies images (.jpg, .png) with lossless compression fromapp/original_resources
intoapp/resources
gulp rsx:imagemin:lossy
: minifies images (.jpg, .png) with lossy (pngquant) compression fromapp/original_resources
intoapp/resources
The revision tasks are used to prepare our source files for distribution. The js
and css
files get renamed using content-based hashes. This allows each file to be cached on the CDN with a unique name.
gulp revision:generate
: creates manifest with versioned source files based on their contentgulp revision:replace
: replaces references in source files using manifest
This task uploads the dist
content to S3.
gulp upload:main
: uploads all source files and assets with GZIP (except audio)gulp upload:audio
: uploads audio files (GZIP disabled)gulp upload:main:versioned
: same as main but uploads to/${version}
subfoldergulp upload:audio:versioned
: same as audio but uploads to/${version}
subfolder
This task builds, tags, and pushes our Docker container (used by servers/worker). Docker must be available and ready.
gulp docker:build
: builds the docker containergulp docker:tag
: tags the docker containergulp docker:push
: push the docker container to the registry (quay.io)
This task bumps version numbers in our version.json
and package.json
files. Note that ALL version numbers should be in sync (across are files):
const paths = [
'./version.json',
'./package.json',
'./desktop/package.json'
]
gulp bump:patch
: patch bump, ie, 0.0.xgulp bump:minor
: minor bump, ie 0.x.0gulp bump:major
: major bump, ie x.0.0
The git tasks are helpers for managing git pushes/commit. Note the git tasks will perform a commit -am
so ensure remove unused files or commit before proceeding. To be safe, ensure you are already on latest main
branch and that your changes are safe to commit before proceeding.
There are several subtasks here but the relevant tasks to run are:
-
gulp git:main:{patch,minor,major}
: these tasks will bump the version numbers, commit the changes, create a git tag, and push. The commit msg will be like[2.1.7][patch]
and the tag will be likemain-v2.1.14
. -
gulp git:staging
: this task will merge main => staging, create a tag, and push. The commit msg will be like[2.1.14]=>[staging]
and the tag will be likestaging-v2.1.14
. -
gulp git:production
: this task will merge staging => production, create a tag, and push. The commit msg will be like[2.1.14]=>[production]
and the tag will be likev2.1.14
.
The desktop task operates on the desktop
subfolder. The desktop has its own package.json
and node_modules
used for the Electron client build.
desktop:build
: builds the source code and the Electron exe and app binaries.desktop:package
: zips the binaries, creates a diff against the previous release, and publishes to github
Works from OSX with Wine.
$ brew install wine
$ brew install winetricks
$ winetricks mfc42
Toggle Dev Tools.
OS X: Cmd Alt I Windows: Ctrl Shift I Reload
Force reload the window.
OS X: Cmd R Windows: Ctrl R
The root of the desktop application is the /desktop/app
folder. The main entry is desktop.js
and the source is copied from /dist/src
into /desktop/src
.
Copies source from cleancoco parent /dist/src
folder into /desktop/src
. Run setup:#{environment}
to prepare the desktop app's package.json
with build metadata.
$ npm run clean && npm run copy
$ npm run setup:#{environment}