1
0
Fork 0

Split app and tests JS files, and simplified dependencies bundle

This commit is contained in:
Michaël Lemaire 2019-05-15 22:14:58 +02:00
parent 29224113c9
commit 436e568a0e
37 changed files with 120 additions and 122 deletions

6
.gitignore vendored
View File

@ -1,10 +1,12 @@
.venv .venv
coverage coverage
/node_modules /node_modules
/out/vendor
/out/assets /out/assets
/out/build.* /out/app.*
/out/tests.*
/out/dependencies.js
/graphics/**/*.blend?* /graphics/**/*.blend?*
/graphics/**/output.png /graphics/**/output.png
/typings/ /typings/
*.log *.log
*.tsbuildinfo

View File

@ -10,7 +10,7 @@
"**/CVS": true, "**/CVS": true,
"**/.DS_Store": true, "**/.DS_Store": true,
"node_modules": true, "node_modules": true,
".env": true, ".venv": true,
"out": true "**/*.tsbuildinfo": true,
} }
} }

13
config/app.json Normal file
View File

@ -0,0 +1,13 @@
{
"extends": "./common.json",
"compilerOptions": {
"outFile": "../out/app.js",
"rootDir": ".."
},
"include": [
"../src/**/*.ts"
],
"exclude": [
"../src/**/*.spec.ts"
]
}

21
config/common.json Normal file
View File

@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "system",
"composite": true,
"declaration": true,
"declarationMap": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"removeComments": false,
"preserveConstEnums": true,
"strict": true,
"sourceMap": true,
"lib": [
"dom",
"es6",
"scripthost"
],
"target": "es6"
}
}

15
config/tests.json Normal file
View File

@ -0,0 +1,15 @@
{
"extends": "./common.json",
"compilerOptions": {
"outFile": "../out/tests.js",
"rootDir": ".."
},
"include": [
"../src/**/*.spec.ts"
],
"references": [
{
"path": "./app.json"
}
]
}

View File

@ -8,7 +8,7 @@ var Phaser = new Proxy(function () { }, handler);
//var debug = console.log; //var debug = console.log;
var debug = function () { }; var debug = function () { };
importScripts("build.js"); importScripts("app.js");
onmessage = function (e) { onmessage = function (e) {
debug("[AI Worker] Received", e.data.length); debug("[AI Worker] Received", e.data.length);

View File

@ -41,9 +41,8 @@
<div id="-space-tac" class="game"></div> <div id="-space-tac" class="game"></div>
<div class=".fontLoader">.</div> <div class=".fontLoader">.</div>
<script src="vendor/parse/parse.min.js"></script> <script src="dependencies.js"></script>
<script src="vendor/phaser/phaser.js"></script> <script src="app.js"></script>
<script src="build.js"></script>
<script> <script>
window.onload = function () { window.onload = function () {

View File

@ -2,7 +2,7 @@ const Pool = require('process-pool').default;
const pool = new Pool({ processLimit: 8 }); const pool = new Pool({ processLimit: 8 });
const work = pool.prepare(function () { const work = pool.prepare(function () {
const App = require("./build").TK.SpaceTac; const App = require("./app").TK.SpaceTac;
async function doOneBattle(i) { async function doOneBattle(i) {
let ai1 = new App.TacticalAI(); let ai1 = new App.TacticalAI();

View File

@ -5,7 +5,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>SpaceTac - Unit tests</title> <title>SpaceTac - Unit tests</title>
<link rel="stylesheet" href="vendor/jasmine/jasmine.css"> <link rel="stylesheet" href="/jasmine/jasmine.css">
<style> <style>
canvas { canvas {
display: none; display: none;
@ -22,12 +22,13 @@
<div id="-space-tac" class="game"></div> <div id="-space-tac" class="game"></div>
</div> </div>
<script src="vendor/jasmine/jasmine.js"></script> <script src="/jasmine/jasmine.js"></script>
<script src="vendor/jasmine/jasmine-html.js"></script> <script src="/jasmine/jasmine-html.js"></script>
<script src="vendor/jasmine/boot.js"></script> <script src="/jasmine/boot.js"></script>
<script src="vendor/parse/parse.min.js"></script>
<script src="vendor/phaser/phaser.min.js"></script> <script src="dependencies.js"></script>
<script src="build.js"></script> <script src="app.js"></script>
<script src="tests.js"></script>
</body> </body>
</html> </html>

17
package-lock.json generated
View File

@ -2499,7 +2499,8 @@
"jasmine-core": { "jasmine-core": {
"version": "3.4.0", "version": "3.4.0",
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.4.0.tgz", "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.4.0.tgz",
"integrity": "sha512-HU/YxV4i6GcmiH4duATwAbJQMlE0MsDIR5XmSVxURxKHn3aGAdbY1/ZJFmVRbKtnLwIxxMJD7gYaPsypcbYimg==" "integrity": "sha512-HU/YxV4i6GcmiH4duATwAbJQMlE0MsDIR5XmSVxURxKHn3aGAdbY1/ZJFmVRbKtnLwIxxMJD7gYaPsypcbYimg==",
"dev": true
}, },
"js-yaml": { "js-yaml": {
"version": "3.13.1", "version": "3.13.1",
@ -3418,6 +3419,13 @@
"jsdoc": "^3.6.1", "jsdoc": "^3.6.1",
"path": "^0.12.7", "path": "^0.12.7",
"typescript": "^3.4.5" "typescript": "^3.4.5"
},
"dependencies": {
"typescript": {
"version": "3.4.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz",
"integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw=="
}
} }
}, },
"pify": { "pify": {
@ -4473,9 +4481,10 @@
} }
}, },
"typescript": { "typescript": {
"version": "3.4.5", "version": "3.5.0-dev.20190516",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.0-dev.20190516.tgz",
"integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==" "integrity": "sha512-J+1tISjR4yCmZ3F2wWZDEMoocF4wdXsHf68ln6cb0gjm8VmSDUYSPOVbCJUJoLqjWaCEPs05O7eNrbTulo/4ew==",
"dev": true
}, },
"uc.micro": { "uc.micro": {
"version": "1.0.6", "version": "1.0.6",

View File

@ -21,6 +21,7 @@
"glob": "^7.1.4", "glob": "^7.1.4",
"glob-watcher": "^5.0.3", "glob-watcher": "^5.0.3",
"jasmine": "^3.4.0", "jasmine": "^3.4.0",
"jasmine-core": "^3.4.0",
"karma": "^4.1.0", "karma": "^4.1.0",
"karma-chrome-launcher": "^2.2.0", "karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2", "karma-coverage": "^1.1.2",
@ -31,12 +32,15 @@
"remap-istanbul": "^0.13.0", "remap-istanbul": "^0.13.0",
"runjs": "^4.4.2", "runjs": "^4.4.2",
"shelljs": "^0.8.3", "shelljs": "^0.8.3",
"typescript": "^3.4.5", "typescript": "^3.5.0-dev.20190516",
"uglify-js": "^3.5.12" "uglify-js": "^3.5.12"
}, },
"dependencies": { "dependencies": {
"jasmine-core": "^3.4.0",
"parse": "^2.4.0", "parse": "^2.4.0",
"phaser": "^3.17.0" "phaser": "^3.17.0"
},
"dependenciesMap": {
"parse": "dist/parse.min.js",
"phaser": "dist/phaser.min.js"
} }
} }

View File

@ -35,16 +35,16 @@ async function exec(command) {
/** /**
* Build app from typescript sources * Build app from typescript sources
*/ */
async function ts(dist = false) { async function ts() {
console.log("Building app..."); console.log("Building app...");
await exec(`tsc --project ${dist ? "./tsconfig.dist.json" : "."}`); await exec(`tsc --build config/app.json config/tests.json`);
} }
/** /**
* Start watching for typescript changes * Start watching for typescript changes
*/ */
async function watch_ts() { async function watch_ts() {
await exec(`tsc --project . --watch --preserveWatchOutput`); await exec(`tsc --build config/app.json config/tests.json --watch --preserveWatchOutput`);
} }
/** /**
@ -135,33 +135,32 @@ async function watch_data() {
} }
/** /**
* Copy the vendors from node_modules to dist directory * Copy and concatenate the vendors from node_modules to out/dependencies.js
*/ */
async function vendors() { async function dependencies() {
console.log("Copying vendors..."); console.log("Bundling dependencies...");
shell.rm('-rf', 'out/vendor'); const self = JSON.parse(fs.readFileSync("package.json"));
shell.mkdir('-p', 'out/vendor'); const deps = Object.keys(self["dependenciesMap"]).map(dependency => `node_modules/${dependency}/${self["dependenciesMap"][dependency]}`);
shell.cp('-R', 'node_modules/phaser/dist', 'out/vendor/phaser'); const bundle = shell.cat(deps);
shell.cp('-R', 'node_modules/parse/dist', 'out/vendor/parse'); fs.writeFileSync("out/dependencies.js", bundle);
shell.cp('-R', 'node_modules/jasmine-core/lib/jasmine-core', 'out/vendor/jasmine');
} }
/** /**
* Start watching for vendors changes * Start watching for dependencies changes
*/ */
async function watch_vendors() { async function watch_dependencies() {
watch(['package.json'], () => vendors()); watch(['package.json'], () => dependencies());
await forever(); await forever();
} }
/** /**
* Trigger a single build * Trigger a single build
*/ */
async function build(dist = false) { async function build() {
await Promise.all([ await Promise.all([
ts(dist), ts(),
data(), data(),
vendors() dependencies()
]); ]);
} }
@ -170,14 +169,14 @@ async function build(dist = false) {
*/ */
async function optimize() { async function optimize() {
// TODO do not overwrite dev build // TODO do not overwrite dev build
await exec("uglifyjs out/build.dist.js --source-map --ecma 6 --mangle --keep-classnames --compress --output out/build.js"); await exec("uglifyjs out/app.js --source-map --ecma 6 --mangle --keep-classnames --compress --output out/app.js");
} }
/** /**
* Deploy to production * Deploy to production
*/ */
async function deploy(task, experimental = false) { async function deploy(task, experimental = false) {
await build(true); await build();
await optimize(); await optimize();
await exec(`rsync -avz --delete ./out/ hosting.thunderk.net:/srv/website/spacetac${experimental ? "x" : ""}/`); await exec(`rsync -avz --delete ./out/ hosting.thunderk.net:/srv/website/spacetac${experimental ? "x" : ""}/`);
} }
@ -208,7 +207,7 @@ async function test(task) {
* Run tests in karma when the build changes * Run tests in karma when the build changes
*/ */
async function watch_test(task) { async function watch_test(task) {
watch(["out/*.js", "out/*.html"], () => karma()); watch(["out/*.js", "out/*.html", "spec/support/*"], () => karma());
await forever(); await forever();
} }
@ -216,7 +215,7 @@ async function watch_test(task) {
* Run tests in karma, using freshly built app (for continuous integration) * Run tests in karma, using freshly built app (for continuous integration)
*/ */
async function ci(task) { async function ci(task) {
await Promise.all([ts(), vendors()]); await Promise.all([ts(), dependencies()]);
await karma(); await karma();
await exec("remap-istanbul -i out/coverage/coverage.json -o out/coverage -t html"); await exec("remap-istanbul -i out/coverage/coverage.json -o out/coverage -t html");
} }
@ -230,6 +229,9 @@ async function serve() {
port: 8012, port: 8012,
root: 'out', root: 'out',
ignore: 'out/coverage', ignore: 'out/coverage',
mount: [
['/jasmine', './node_modules/jasmine-core/lib/jasmine-core']
],
wait: 500 wait: 500
}); });
await new Promise(() => null); await new Promise(() => null);
@ -249,7 +251,7 @@ async function continuous() {
serve(), serve(),
watch_ts(), watch_ts(),
watch_data(), watch_data(),
watch_vendors(), watch_dependencies(),
watch_test(), watch_test(),
]); ]);
} }
@ -281,8 +283,8 @@ module.exports = {
watch_ts: command(watch_ts), watch_ts: command(watch_ts),
data: command(data), data: command(data),
watch_data: command(watch_data), watch_data: command(watch_data),
vendors: command(vendors), dependencies: command(dependencies),
watch_vendors: command(watch_vendors), watch_dependencies: command(watch_dependencies),
build: command(build), build: command(build),
test: command(test), test: command(test),
watch_test: command(watch_test), watch_test: command(watch_test),

View File

@ -14,7 +14,7 @@ module.exports = function (config) {
}, },
preprocessors: { preprocessors: {
'build.js': ['coverage'] 'app.js': ['coverage']
}, },
coverageReporter: { coverageReporter: {
@ -31,9 +31,9 @@ module.exports = function (config) {
}, },
files: [ files: [
'vendor/phaser/phaser.js', 'dependencies.js',
'vendor/parse/parse.min.js', 'app.js',
'build.js' 'tests.js',
] ]
}) })
} }

View File

@ -1,4 +1,4 @@
/// <reference path="ui/TestGame.ts" /> /// <reference path="../node_modules/phaser/types/phaser.d.ts"/>
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
class FakeStorage { class FakeStorage {

View File

@ -1,5 +1,3 @@
/// <reference path="DiffLog.ts" />
module TK.Specs { module TK.Specs {
class TestState { class TestState {
counter = 0 counter = 0

View File

@ -1,5 +1,3 @@
/// <reference path="RObject.ts" />
module TK.Specs { module TK.Specs {
export class TestRObject extends RObject { export class TestRObject extends RObject {
x: number x: number

View File

@ -477,7 +477,7 @@ module TK {
/** /**
* Copy an object (only a shallow copy of immediate properties) * Copy an object (only a shallow copy of immediate properties)
*/ */
export function copy<T>(object: T): T { export function copy<T extends Object>(object: T): T {
let objectCopy = <T>Object.create(object.constructor.prototype); let objectCopy = <T>Object.create(object.constructor.prototype);
copyfields(object, objectCopy); copyfields(object, objectCopy);
return objectCopy; return objectCopy;

View File

@ -1,5 +1,3 @@
/// <reference path="effects/BaseEffect.ts" />
module TK.SpaceTac { module TK.SpaceTac {
testing("Drone", test => { testing("Drone", test => {
test.case("applies area effects when deployed", check => { test.case("applies area effects when deployed", check => {

View File

@ -1,5 +1,3 @@
/// <reference path="PersonalityReactions.ts" />
module TK.SpaceTac.Specs { module TK.SpaceTac.Specs {
testing("PersonalityReactions", test => { testing("PersonalityReactions", test => {
function apply(pool: ReactionPool): PersonalityReaction | null { function apply(pool: ReactionPool): PersonalityReaction | null {

View File

@ -1,5 +1,3 @@
/// <reference path="Maneuver.ts" />
module TK.SpaceTac.Specs { module TK.SpaceTac.Specs {
testing("TacticalAI", test => { testing("TacticalAI", test => {
class FixedManeuver extends Maneuver { class FixedManeuver extends Maneuver {

View File

@ -1,5 +1,3 @@
/// <reference path="../../common/Testing.ts" />
module TK.SpaceTac.Specs { module TK.SpaceTac.Specs {
testing("ShipAttributeDiff", test => { testing("ShipAttributeDiff", test => {
test.case("applies and reverts", check => { test.case("applies and reverts", check => {

View File

@ -1,5 +1,3 @@
/// <reference path="../../common/Testing.ts" />
module TK.SpaceTac.Specs { module TK.SpaceTac.Specs {
testing("ShipDeathDiff", test => { testing("ShipDeathDiff", test => {
test.case("applies and reverts", check => { test.case("applies and reverts", check => {

View File

@ -1,5 +1,3 @@
/// <reference path="../../common/Testing.ts" />
module TK.SpaceTac.Specs { module TK.SpaceTac.Specs {
testing("ShipValueDiff", test => { testing("ShipValueDiff", test => {
test.case("applies and reverts", check => { test.case("applies and reverts", check => {

View File

@ -1,5 +1,3 @@
/// <reference path="TestGame.ts" />
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("AssetLoading", test => { testing("AssetLoading", test => {
let testgame = setupSingleView(test, () => [new AssetLoading({}), []]); let testgame = setupSingleView(test, () => [new AssetLoading({}), []]);

View File

@ -1,5 +1,3 @@
/// <reference path="TestGame.ts" />
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("BaseView", test => { testing("BaseView", test => {
let testgame = setupEmptyView(test); let testgame = setupEmptyView(test);

View File

@ -1,6 +1,3 @@
/// <reference path="TestGame.ts" />
/// <reference path="Router.ts" />
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("Router", test => { testing("Router", test => {
let testgame = setupSingleView(test, () => [new Router({}), {}]); let testgame = setupSingleView(test, () => [new Router({}), {}]);

View File

@ -1,5 +1,3 @@
/// <reference path="../TestGame.ts"/>
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("ActionBar", test => { testing("ActionBar", test => {
let testgame = setupBattleview(test); let testgame = setupBattleview(test);

View File

@ -1,5 +1,3 @@
/// <reference path="../TestGame.ts"/>
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("ActionIcon", test => { testing("ActionIcon", test => {
let testgame = setupBattleview(test); let testgame = setupBattleview(test);

View File

@ -1,5 +1,3 @@
/// <reference path="../TestGame.ts"/>
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("ActionTooltip", test => { testing("ActionTooltip", test => {
let testgame = setupEmptyView(test); let testgame = setupEmptyView(test);

View File

@ -1,5 +1,3 @@
/// <reference path="../TestGame.ts"/>
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("ArenaShip", test => { testing("ArenaShip", test => {
let testgame = setupBattleview(test); let testgame = setupBattleview(test);

View File

@ -1,5 +1,3 @@
/// <reference path="../TestGame.ts"/>
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("BattleView", test => { testing("BattleView", test => {
let testgame = setupBattleview(test); let testgame = setupBattleview(test);

View File

@ -1,5 +1,3 @@
/// <reference path="../TestGame.ts"/>
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("ShipList", test => { testing("ShipList", test => {
let testgame = setupEmptyView(test); let testgame = setupEmptyView(test);

View File

@ -1,5 +1,3 @@
/// <reference path="../TestGame.ts"/>
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("CharacterUpgrade", test => { testing("CharacterUpgrade", test => {
let testgame = setupEmptyView(test); let testgame = setupEmptyView(test);

View File

@ -1,5 +1,3 @@
/// <reference path="../TestGame.ts"/>
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("FleetCreationView", test => { testing("FleetCreationView", test => {
let testgame = setupSingleView(test, () => [new FleetCreationView({}), []]); let testgame = setupSingleView(test, () => [new FleetCreationView({}), []]);

View File

@ -1,6 +1,3 @@
/// <reference path="../TestGame.ts" />
/// <reference path="MainMenu.ts" />
module TK.SpaceTac.UI.Specs { module TK.SpaceTac.UI.Specs {
testing("InputInviteCode", test => { testing("InputInviteCode", test => {
let testgame = setupEmptyView(test); let testgame = setupEmptyView(test);

View File

@ -1,10 +0,0 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"outFile": "out/build.dist.js",
"removeComments": true
},
"exclude": [
"src/**/*.spec.ts"
]
}

View File

@ -1,21 +1,5 @@
{ {
"compilerOptions": { "extends": "./config/common.json",
"module": "system",
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"removeComments": false,
"preserveConstEnums": true,
"outFile": "out/build.js",
"strict": true,
"sourceMap": true,
"lib": [
"dom",
"es6",
"scripthost"
],
"target": "es6"
},
"include": [ "include": [
"src/**/*.ts" "src/**/*.ts"
] ]