diff --git a/.gitignore b/.gitignore index e6ed734..5b9e087 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,12 @@ .venv coverage /node_modules -/out/vendor /out/assets -/out/build.* +/out/app.* +/out/tests.* +/out/dependencies.js /graphics/**/*.blend?* /graphics/**/output.png /typings/ *.log +*.tsbuildinfo diff --git a/.vscode/settings.json b/.vscode/settings.json index 7ffc6fe..54d9b44 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,7 +10,7 @@ "**/CVS": true, "**/.DS_Store": true, "node_modules": true, - ".env": true, - "out": true + ".venv": true, + "**/*.tsbuildinfo": true, } } \ No newline at end of file diff --git a/config/app.json b/config/app.json new file mode 100644 index 0000000..3e10b58 --- /dev/null +++ b/config/app.json @@ -0,0 +1,13 @@ +{ + "extends": "./common.json", + "compilerOptions": { + "outFile": "../out/app.js", + "rootDir": ".." + }, + "include": [ + "../src/**/*.ts" + ], + "exclude": [ + "../src/**/*.spec.ts" + ] +} \ No newline at end of file diff --git a/config/common.json b/config/common.json new file mode 100644 index 0000000..cca877e --- /dev/null +++ b/config/common.json @@ -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" + } +} \ No newline at end of file diff --git a/config/tests.json b/config/tests.json new file mode 100644 index 0000000..29ec127 --- /dev/null +++ b/config/tests.json @@ -0,0 +1,15 @@ +{ + "extends": "./common.json", + "compilerOptions": { + "outFile": "../out/tests.js", + "rootDir": ".." + }, + "include": [ + "../src/**/*.spec.ts" + ], + "references": [ + { + "path": "./app.json" + } + ] +} \ No newline at end of file diff --git a/out/aiworker.js b/out/aiworker.js index 386d119..9e96720 100644 --- a/out/aiworker.js +++ b/out/aiworker.js @@ -8,7 +8,7 @@ var Phaser = new Proxy(function () { }, handler); //var debug = console.log; var debug = function () { }; -importScripts("build.js"); +importScripts("app.js"); onmessage = function (e) { debug("[AI Worker] Received", e.data.length); diff --git a/out/index.html b/out/index.html index 4249445..3993e1f 100644 --- a/out/index.html +++ b/out/index.html @@ -41,9 +41,8 @@
.
- - - + + - - - - - + + + + + + + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 328f5b4..afcf855 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2499,7 +2499,8 @@ "jasmine-core": { "version": "3.4.0", "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": { "version": "3.13.1", @@ -3418,6 +3419,13 @@ "jsdoc": "^3.6.1", "path": "^0.12.7", "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": { @@ -4473,9 +4481,10 @@ } }, "typescript": { - "version": "3.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", - "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==" + "version": "3.5.0-dev.20190516", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.0-dev.20190516.tgz", + "integrity": "sha512-J+1tISjR4yCmZ3F2wWZDEMoocF4wdXsHf68ln6cb0gjm8VmSDUYSPOVbCJUJoLqjWaCEPs05O7eNrbTulo/4ew==", + "dev": true }, "uc.micro": { "version": "1.0.6", diff --git a/package.json b/package.json index 04cec98..1b2f928 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "glob": "^7.1.4", "glob-watcher": "^5.0.3", "jasmine": "^3.4.0", + "jasmine-core": "^3.4.0", "karma": "^4.1.0", "karma-chrome-launcher": "^2.2.0", "karma-coverage": "^1.1.2", @@ -31,12 +32,15 @@ "remap-istanbul": "^0.13.0", "runjs": "^4.4.2", "shelljs": "^0.8.3", - "typescript": "^3.4.5", + "typescript": "^3.5.0-dev.20190516", "uglify-js": "^3.5.12" }, "dependencies": { - "jasmine-core": "^3.4.0", "parse": "^2.4.0", "phaser": "^3.17.0" + }, + "dependenciesMap": { + "parse": "dist/parse.min.js", + "phaser": "dist/phaser.min.js" } -} \ No newline at end of file +} diff --git a/runfile.js b/runfile.js index 2b6473c..68f96f1 100644 --- a/runfile.js +++ b/runfile.js @@ -35,16 +35,16 @@ async function exec(command) { /** * Build app from typescript sources */ -async function ts(dist = false) { +async function ts() { 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 */ 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() { - console.log("Copying vendors..."); - shell.rm('-rf', 'out/vendor'); - shell.mkdir('-p', 'out/vendor'); - shell.cp('-R', 'node_modules/phaser/dist', 'out/vendor/phaser'); - shell.cp('-R', 'node_modules/parse/dist', 'out/vendor/parse'); - shell.cp('-R', 'node_modules/jasmine-core/lib/jasmine-core', 'out/vendor/jasmine'); +async function dependencies() { + console.log("Bundling dependencies..."); + const self = JSON.parse(fs.readFileSync("package.json")); + const deps = Object.keys(self["dependenciesMap"]).map(dependency => `node_modules/${dependency}/${self["dependenciesMap"][dependency]}`); + const bundle = shell.cat(deps); + fs.writeFileSync("out/dependencies.js", bundle); } /** - * Start watching for vendors changes + * Start watching for dependencies changes */ -async function watch_vendors() { - watch(['package.json'], () => vendors()); +async function watch_dependencies() { + watch(['package.json'], () => dependencies()); await forever(); } /** * Trigger a single build */ -async function build(dist = false) { +async function build() { await Promise.all([ - ts(dist), + ts(), data(), - vendors() + dependencies() ]); } @@ -170,14 +169,14 @@ async function build(dist = false) { */ async function optimize() { // 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 */ async function deploy(task, experimental = false) { - await build(true); + await build(); await optimize(); 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 */ async function watch_test(task) { - watch(["out/*.js", "out/*.html"], () => karma()); + watch(["out/*.js", "out/*.html", "spec/support/*"], () => karma()); await forever(); } @@ -216,7 +215,7 @@ async function watch_test(task) { * Run tests in karma, using freshly built app (for continuous integration) */ async function ci(task) { - await Promise.all([ts(), vendors()]); + await Promise.all([ts(), dependencies()]); await karma(); await exec("remap-istanbul -i out/coverage/coverage.json -o out/coverage -t html"); } @@ -230,6 +229,9 @@ async function serve() { port: 8012, root: 'out', ignore: 'out/coverage', + mount: [ + ['/jasmine', './node_modules/jasmine-core/lib/jasmine-core'] + ], wait: 500 }); await new Promise(() => null); @@ -249,7 +251,7 @@ async function continuous() { serve(), watch_ts(), watch_data(), - watch_vendors(), + watch_dependencies(), watch_test(), ]); } @@ -281,8 +283,8 @@ module.exports = { watch_ts: command(watch_ts), data: command(data), watch_data: command(watch_data), - vendors: command(vendors), - watch_vendors: command(watch_vendors), + dependencies: command(dependencies), + watch_dependencies: command(watch_dependencies), build: command(build), test: command(test), watch_test: command(watch_test), diff --git a/spec/support/karma.conf.js b/spec/support/karma.conf.js index 12fe2e3..c36140d 100644 --- a/spec/support/karma.conf.js +++ b/spec/support/karma.conf.js @@ -14,7 +14,7 @@ module.exports = function (config) { }, preprocessors: { - 'build.js': ['coverage'] + 'app.js': ['coverage'] }, coverageReporter: { @@ -31,9 +31,9 @@ module.exports = function (config) { }, files: [ - 'vendor/phaser/phaser.js', - 'vendor/parse/parse.min.js', - 'build.js' + 'dependencies.js', + 'app.js', + 'tests.js', ] }) } diff --git a/src/MainUI.spec.ts b/src/MainUI.spec.ts index f04b929..f566acf 100644 --- a/src/MainUI.spec.ts +++ b/src/MainUI.spec.ts @@ -1,4 +1,4 @@ -/// +/// module TK.SpaceTac.UI.Specs { class FakeStorage { diff --git a/src/common/DiffLog.spec.ts b/src/common/DiffLog.spec.ts index 5e0d38a..630d106 100644 --- a/src/common/DiffLog.spec.ts +++ b/src/common/DiffLog.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.Specs { class TestState { counter = 0 diff --git a/src/common/RObject.spec.ts b/src/common/RObject.spec.ts index 6e03243..199f613 100644 --- a/src/common/RObject.spec.ts +++ b/src/common/RObject.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.Specs { export class TestRObject extends RObject { x: number diff --git a/src/common/Tools.ts b/src/common/Tools.ts index a631d7b..0e1c6e4 100644 --- a/src/common/Tools.ts +++ b/src/common/Tools.ts @@ -477,7 +477,7 @@ module TK { /** * Copy an object (only a shallow copy of immediate properties) */ - export function copy(object: T): T { + export function copy(object: T): T { let objectCopy = Object.create(object.constructor.prototype); copyfields(object, objectCopy); return objectCopy; diff --git a/src/core/Drone.spec.ts b/src/core/Drone.spec.ts index acd183e..b922da3 100644 --- a/src/core/Drone.spec.ts +++ b/src/core/Drone.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac { testing("Drone", test => { test.case("applies area effects when deployed", check => { diff --git a/src/core/PersonalityReactions.spec.ts b/src/core/PersonalityReactions.spec.ts index e7f049b..d282f92 100644 --- a/src/core/PersonalityReactions.spec.ts +++ b/src/core/PersonalityReactions.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.Specs { testing("PersonalityReactions", test => { function apply(pool: ReactionPool): PersonalityReaction | null { diff --git a/src/core/ai/TacticalAI.spec.ts b/src/core/ai/TacticalAI.spec.ts index 817936f..4d880af 100644 --- a/src/core/ai/TacticalAI.spec.ts +++ b/src/core/ai/TacticalAI.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.Specs { testing("TacticalAI", test => { class FixedManeuver extends Maneuver { diff --git a/src/core/diffs/ShipAttributeDiff.spec.ts b/src/core/diffs/ShipAttributeDiff.spec.ts index 6f55fc6..bf8d57c 100644 --- a/src/core/diffs/ShipAttributeDiff.spec.ts +++ b/src/core/diffs/ShipAttributeDiff.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.Specs { testing("ShipAttributeDiff", test => { test.case("applies and reverts", check => { diff --git a/src/core/diffs/ShipDeathDiff.spec.ts b/src/core/diffs/ShipDeathDiff.spec.ts index fbc6284..fb335cd 100644 --- a/src/core/diffs/ShipDeathDiff.spec.ts +++ b/src/core/diffs/ShipDeathDiff.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.Specs { testing("ShipDeathDiff", test => { test.case("applies and reverts", check => { diff --git a/src/core/diffs/ShipValueDiff.spec.ts b/src/core/diffs/ShipValueDiff.spec.ts index 3edd165..0d94a8d 100644 --- a/src/core/diffs/ShipValueDiff.spec.ts +++ b/src/core/diffs/ShipValueDiff.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.Specs { testing("ShipValueDiff", test => { test.case("applies and reverts", check => { diff --git a/src/ui/AssetLoading.spec.ts b/src/ui/AssetLoading.spec.ts index 4b377a4..8d27948 100644 --- a/src/ui/AssetLoading.spec.ts +++ b/src/ui/AssetLoading.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.UI.Specs { testing("AssetLoading", test => { let testgame = setupSingleView(test, () => [new AssetLoading({}), []]); diff --git a/src/ui/BaseView.spec.ts b/src/ui/BaseView.spec.ts index 1ee1718..48aff67 100644 --- a/src/ui/BaseView.spec.ts +++ b/src/ui/BaseView.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.UI.Specs { testing("BaseView", test => { let testgame = setupEmptyView(test); diff --git a/src/ui/Router.spec.ts b/src/ui/Router.spec.ts index ddb8d10..dfdea96 100644 --- a/src/ui/Router.spec.ts +++ b/src/ui/Router.spec.ts @@ -1,6 +1,3 @@ -/// -/// - module TK.SpaceTac.UI.Specs { testing("Router", test => { let testgame = setupSingleView(test, () => [new Router({}), {}]); diff --git a/src/ui/battle/ActionBar.spec.ts b/src/ui/battle/ActionBar.spec.ts index 6e96eb5..43fe0cb 100644 --- a/src/ui/battle/ActionBar.spec.ts +++ b/src/ui/battle/ActionBar.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.UI.Specs { testing("ActionBar", test => { let testgame = setupBattleview(test); diff --git a/src/ui/battle/ActionIcon.spec.ts b/src/ui/battle/ActionIcon.spec.ts index 67414fd..9c9df85 100644 --- a/src/ui/battle/ActionIcon.spec.ts +++ b/src/ui/battle/ActionIcon.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.UI.Specs { testing("ActionIcon", test => { let testgame = setupBattleview(test); diff --git a/src/ui/battle/ActionTooltip.spec.ts b/src/ui/battle/ActionTooltip.spec.ts index f781613..1832546 100644 --- a/src/ui/battle/ActionTooltip.spec.ts +++ b/src/ui/battle/ActionTooltip.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.UI.Specs { testing("ActionTooltip", test => { let testgame = setupEmptyView(test); diff --git a/src/ui/battle/ArenaShip.spec.ts b/src/ui/battle/ArenaShip.spec.ts index 0c91ff1..fb8de62 100644 --- a/src/ui/battle/ArenaShip.spec.ts +++ b/src/ui/battle/ArenaShip.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.UI.Specs { testing("ArenaShip", test => { let testgame = setupBattleview(test); diff --git a/src/ui/battle/BattleView.spec.ts b/src/ui/battle/BattleView.spec.ts index 597d8ac..006d794 100644 --- a/src/ui/battle/BattleView.spec.ts +++ b/src/ui/battle/BattleView.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.UI.Specs { testing("BattleView", test => { let testgame = setupBattleview(test); diff --git a/src/ui/battle/ShipList.spec.ts b/src/ui/battle/ShipList.spec.ts index 9455197..386363e 100644 --- a/src/ui/battle/ShipList.spec.ts +++ b/src/ui/battle/ShipList.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.UI.Specs { testing("ShipList", test => { let testgame = setupEmptyView(test); diff --git a/src/ui/character/CharacterUpgrade.spec.ts b/src/ui/character/CharacterUpgrade.spec.ts index ccc7a9b..0401ce9 100644 --- a/src/ui/character/CharacterUpgrade.spec.ts +++ b/src/ui/character/CharacterUpgrade.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.UI.Specs { testing("CharacterUpgrade", test => { let testgame = setupEmptyView(test); diff --git a/src/ui/character/FleetCreationView.spec.ts b/src/ui/character/FleetCreationView.spec.ts index d4ae328..cc44e51 100644 --- a/src/ui/character/FleetCreationView.spec.ts +++ b/src/ui/character/FleetCreationView.spec.ts @@ -1,5 +1,3 @@ -/// - module TK.SpaceTac.UI.Specs { testing("FleetCreationView", test => { let testgame = setupSingleView(test, () => [new FleetCreationView({}), []]); diff --git a/src/ui/menu/InputInviteCode.spec.ts b/src/ui/menu/InputInviteCode.spec.ts index 18995ca..45f4f67 100644 --- a/src/ui/menu/InputInviteCode.spec.ts +++ b/src/ui/menu/InputInviteCode.spec.ts @@ -1,6 +1,3 @@ -/// -/// - module TK.SpaceTac.UI.Specs { testing("InputInviteCode", test => { let testgame = setupEmptyView(test); diff --git a/tsconfig.dist.json b/tsconfig.dist.json deleted file mode 100644 index 408bc20..0000000 --- a/tsconfig.dist.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "outFile": "out/build.dist.js", - "removeComments": true - }, - "exclude": [ - "src/**/*.spec.ts" - ] -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 7f23acc..3e971f3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,21 +1,5 @@ { - "compilerOptions": { - "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" - }, + "extends": "./config/common.json", "include": [ "src/**/*.ts" ]