1
0
Fork 0

Initial bootstrap

This commit is contained in:
Michaël Lemaire 2014-12-28 01:00:00 +01:00
commit 89d793cb33
14 changed files with 7957 additions and 0 deletions

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
.*
/bin
/bootstrap.py
/build
/parts
/venv
/eggs
/node_modules
/src/vendor

162
bootstrap-venv.py Normal file
View File

@ -0,0 +1,162 @@
#!/usr/bin/env python
# Copyright (c) 2014, Jonathan Ballet <jon@multani.info>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Bootstrap a Buildout into its own virtualenv environment.
This script creates a new empty virtualenv, download Buildout's bootstrap script
and execute it in the context of the previously created virtualenv.
python bootstrap-venv.py
Then, you only have to edit your `buildout.cfg` file and run::
./bin/buildout
You can also specify another directory to bootstrap the whole thing in::
python bootstrap-venv.py some-directory
cd some-directory
[ edit buildout.cfg ]
./bin/buildout
"""
# This URL is supposed to be stable
BOOTSTRAP_BUILDOUT_URL = "https://bootstrap.pypa.io/bootstrap-buildout.py"
# TODO: find a place where Virtualenv is FOR EVER AND EVER available.
VIRTUALENV_URL = "https://pypi.python.org/packages/source/v/virtualenv/" + \
"virtualenv-1.11.6.tar.gz"
import io
import gzip
import os
import subprocess
import sys
import tarfile
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
def download_virtualenv(destination):
print("Downloading virtualenv from %s" % VIRTUALENV_URL)
url = urlopen(VIRTUALENV_URL)
string_fp = io.BytesIO(url.read())
gz_fp = gzip.GzipFile(fileobj=string_fp)
tar_fp = tarfile.TarFile(fileobj=gz_fp)
tar_fp.extractall(destination)
path = os.path.join(destination, os.listdir(destination)[0])
sys.path.insert(0, path)
import virtualenv
print("Using virtualenv module at %s" % virtualenv.__file__)
return virtualenv
def create_virtualenv(destination):
venv_dir = os.path.join(destination, "parts", "venv")
try:
import virtualenv
except ImportError:
venv_dist = os.path.join(destination, "parts", "venv-dist")
virtualenv = download_virtualenv(venv_dist)
print("Creating virtual environment in %s..." % venv_dir)
virtualenv.create_environment(venv_dir,
site_packages=False,
clear=True,
unzip_setuptools=False)
print("Virtual environment created in %s." % venv_dir)
return venv_dir
def download_bootstrap(destination):
bootstrap_path = os.path.join(destination, "bootstrap.py")
print("Downloading Buildout bootstrap from %s..." % BOOTSTRAP_BUILDOUT_URL)
url = urlopen(BOOTSTRAP_BUILDOUT_URL)
with open(bootstrap_path, "wb") as fp:
fp.write(url.read())
print("Downloaded Buildout bootstrap into %s." % bootstrap_path)
return bootstrap_path
def make_default_buildout_cfg(buildout_cfg):
content = [
"[buildout]",
"parts = default",
"",
"[default]",
"recipe = zc.recipe.egg",
"eggs = zc.recipe.egg",
"interpreter = python",
]
with open(buildout_cfg, "w") as fp:
fp.writelines(l + "\n" for l in content)
def bootstrap_buildout(venv_dir, bootstrap_path):
python_bin = os.path.join(venv_dir, "bin", "python")
assert os.path.exists(python_bin)
buildout_cfg = os.path.join(os.path.dirname(bootstrap_path), "buildout.cfg")
try:
fp = open(buildout_cfg)
except IOError as err:
if err.errno != 2:
raise
print("Creating a default buildout.cfg file in %s" % buildout_cfg)
make_default_buildout_cfg(buildout_cfg)
else:
fp.close()
print("Bootstrapping Buildout using: %s %s..." % (
python_bin, bootstrap_path))
subprocess.check_call([python_bin, bootstrap_path])
if len(sys.argv) == 2:
real_destination = sys.argv[1]
else:
real_destination = os.getcwd()
print("About to create Buildout environment in %s..." % real_destination)
os.chdir(real_destination)
destination = "."
venv_dir = create_virtualenv(destination)
bootstrap_path = download_bootstrap(destination)
bootstrap_buildout(venv_dir, bootstrap_path)
print("You can know run ./bin/buildout from directory %s" % real_destination)

71
buildout.cfg Normal file
View File

@ -0,0 +1,71 @@
[buildout]
update-versions-file = versions.cfg
extends =
versions.cfg
parts =
init-compile
watch
js-tools
js-libraries
[init-compile]
recipe = collective.recipe.cmd
on_install = true
on_update = true
cmds = ${buildout:bin-directory}/${compile:name}
[compile]
recipe = yt.recipe.shell
name = compile
script = ${js-tools:bin-gulp} build
[watch]
recipe = yt.recipe.shell
name = watch
script = ${js-tools:bin-gulp}
[nodejs]
recipe = gp.recipe.node
executable_node = ${buildout:bin-directory}/node
executable_npm = ${buildout:bin-directory}/npm
[js-tools]
recipe = rodacom.buildout.npm
node_path = ${nodejs:executable_node}
npm_path = ${nodejs:executable_npm}
strip_extension = true
packages =
bower
del
gulp
gulp-concat
gulp-concat-sourcemap
gulp-connect
gulp-gh-pages
gulp-less
gulp-minify-css
gulp-minify-html
gulp-open
gulp-processhtml
gulp-sourcemaps
gulp-typescript
gulp-uglifyjs
gulp-util
gulp-watch
run-sequence
bin-bower = ${buildout:bin-directory}/bower
bin-gulp = ${buildout:bin-directory}/gulp
[js-libraries]
recipe = bowerrecipe
executable = ${js-tools:bin-bower}
base-directory = ${buildout:parts-directory}/bower
downloads = jslibs
packages =
phaser-official
[mkdir-var]
recipe = z3c.recipe.mkdir
paths =
var
var/cache

112
gulpfile.js Normal file
View File

@ -0,0 +1,112 @@
var gulp = require('gulp'),
ts = require('gulp-typescript'),
less = require('gulp-less'),
minifyCSS = require('gulp-minify-css'),
concat = require('gulp-concat-sourcemap'),
sourcemaps = require('gulp-sourcemaps'),
processhtml = require('gulp-processhtml'),
connect = require('gulp-connect'),
open = require('gulp-open'),
del = require('del'),
uglify = require('gulp-uglifyjs'),
deploy = require('gulp-gh-pages'),
runSequence = require('run-sequence');
var paths = {
assets: 'src/assets/**/*',
less: 'src/css/main.less',
index: 'src/index.html',
libs: [
'src/vendor/phaser-official/build/phaser.min.js'
],
ts: 'src/scripts/**/*.ts',
build: './build/',
dist: './dist/'
};
gulp.task('clean', function (cb) {
return del([paths.build, paths.dist], cb);
});
gulp.task('copy', function () {
return gulp.src(paths.assets)
.pipe(gulp.dest(paths.dist + 'assets'));
});
var tsProject = ts.createProject({
declarationFiles: true,
noExternalResolve: true,
sortOutput: true,
sourceRoot: '../scripts'
});
gulp.task('typescript', function () {
var tsResult = gulp.src(paths.ts)
.pipe(sourcemaps.init())
.pipe(ts(tsProject));
return tsResult.js
.pipe(concat('main.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.build));
});
gulp.task('less', function () {
return gulp.src(paths.less)
.pipe(less())
.pipe(gulp.dest(paths.build));
});
gulp.task('processhtml', function () {
return gulp.src(paths.index)
.pipe(processhtml())
.pipe(gulp.dest(paths.dist));
});
gulp.task('reload', ['typescript'], function () {
gulp.src('src/*.html')
.pipe(connect.reload());
});
gulp.task('watch', function () {
gulp.watch(paths.ts, ['typescript', 'reload']);
gulp.watch(paths.less, ['less', 'reload']);
gulp.watch(paths.index, ['reload']);
});
gulp.task('connect', function () {
connect.server({
root: [__dirname + '/src', paths.build],
port: 9000,
livereload: true
});
});
gulp.task("open", function () {
gulp.src(paths.index)
.pipe(open("", {url: "http://localhost:9000"}));
});
gulp.task('minifyJs', ['typescript'], function () {
return gulp.src(paths.libs.concat(paths.build + 'main.js'))
.pipe(uglify('all.min.js', {outSourceMap: false}))
.pipe(gulp.dest(paths.dist));
});
gulp.task('minifyCss', ['less'], function () {
return gulp.src(paths.build + 'main.css')
.pipe(minifyCSS())
.pipe(gulp.dest(paths.dist))
});
gulp.task('deploy', function () {
return gulp.src('./dist/**/*')
.pipe(deploy());
});
gulp.task('default', function() {
runSequence('clean', ['typescript', 'less', 'connect', 'watch'], 'open');
});
gulp.task('build', function() {
return runSequence('clean', ['typescript', 'less', 'copy', 'minifyJs', 'minifyCss', 'processhtml']);
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

15
src/css/main.less Normal file
View File

@ -0,0 +1,15 @@
html, body {
width: 100%;
height: 100%;
overflow: hidden;
background: rgba(166, 167, 247, 0.32);
padding: 0;
margin: 0;
}
.game {
width: 800px;
height: 600px;
margin: 20px auto;
}

29
src/index.html Normal file
View File

@ -0,0 +1,29 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>SpaceTac</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div id="-space-tac" class="game"></div>
<!-- build:remove -->
<script src="http://localhost:35729/livereload.js"></script>
<!-- /build -->
<!-- build:js all.min.js -->
<script src="vendor/phaser-official/build/phaser.js"></script>
<script src="main.js"></script>
<!-- /build -->
<script>
window.onload = function() {
new SpaceTac.Game();
};
</script>
</body>
</html>

15
src/scripts/Game.ts Normal file
View File

@ -0,0 +1,15 @@
/// <reference path="definitions/phaser.d.ts"/>
module SpaceTac {
export class Game extends Phaser.Game {
constructor() {
super(800, 600, Phaser.CANVAS, '-space-tac');
this.state.add('boot', State.Boot);
this.state.add('preload', State.Preload);
this.state.add('main', State.Main);
this.state.start('boot');
}
}
}

5578
src/scripts/definitions/phaser.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

1900
src/scripts/definitions/pixi.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

16
src/scripts/state/Boot.ts Normal file
View File

@ -0,0 +1,16 @@
module SpaceTac.State {
export class Boot extends Phaser.State {
preload() {
this.load.image('preload-bar', 'assets/images/preloader.gif');
}
create() {
this.game.stage.backgroundColor = 0xFFFFFF;
this.input.maxPointers = 1;
this.stage.disableVisibilityChange = true;
this.game.state.start('preload');
}
}
}

View File

@ -0,0 +1,8 @@
module SpaceTac.State {
export class Main extends Phaser.State {
create() {
this.add.text(10, 10, "Let's code !", { font: "65px Arial" });
}
}
}

View File

@ -0,0 +1,13 @@
module SpaceTac.State {
export class Preload extends Phaser.State {
private preloadBar:Phaser.Sprite;
preload() {
this.preloadBar = this.add.sprite(290, 290, 'preload-bar');
}
create() {
this.game.state.start('main');
}
}
}

28
versions.cfg Normal file
View File

@ -0,0 +1,28 @@
[versions]
# Added by buildout at 2014-12-28 20:27:17.084358
bowerrecipe = 0.1.1
collective.recipe.cmd = 0.9
gp.recipe.node = 0.10.28.0
rodacom.buildout.npm = 0.6
yt.recipe.shell = 0.1.7
zc.buildout = 2.3.1
zc.recipe.egg = 2.0.1
# Required by:
# gp.recipe.node==0.10.28.0
hexagonit.recipe.cmmi = 2.0
# Required by:
# hexagonit.recipe.cmmi==2.0
hexagonit.recipe.download = 1.7
# Required by:
# gp.recipe.node==0.10.28.0
python-archive = 0.2
# Required by:
# gp.recipe.node==0.10.28.0
# hexagonit.recipe.cmmi==2.0
# zc.recipe.egg==2.0.1
setuptools = 8.3