From 8c65243a5bf1d08cfa7ed46dee30d906a4d1cdb9 Mon Sep 17 00:00:00 2001 From: Daniel Jackson Date: Thu, 18 Aug 2016 13:08:22 +0900 Subject: [PATCH] Updating to latest Phaser version - install script removes our deps - prettier output --- bin/install.js | 124 +++++++++++++++++++++++++++++++++++++++++++------ bower.json | 4 +- package.json | 16 +++---- 3 files changed, 119 insertions(+), 25 deletions(-) diff --git a/bin/install.js b/bin/install.js index 0fb7151..aca0072 100755 --- a/bin/install.js +++ b/bin/install.js @@ -1,19 +1,49 @@ #!/usr/bin/env node -var exec = require('child_process').exec, - fs = require('fs'); +var fs = require('fs'), + util = require('util'), + spawn = require('child_process').spawn, + npmInstall = spawn('npm', ['install']); -console.log('Installing npm dependencies...'); +console.log(styleText('Beginning Installtion Process')); +console.log('============================='); +console.log(styleText('Installing npm dependencies...')); -exec('npm install', function (error) { - if (!error) { - console.log('Installing bower dependencies...'); - exec('bower install', function (error) { - if (!error) { +npmInstall.stdout.on('data', function (data) { + pipeOutput(data); +}); + +npmInstall.stderr.on('data', function (data) { + pipeOutput(data); +}); + +npmInstall.on('exit', function (code) { + if (code === 0) { + console.log(styleText('Installing bower dependencies...')); + + var bowerInstall = spawn('bower', ['install']); + + bowerInstall.stdout.on('data', function (data) { + pipeOutput(data); + }); + + bowerInstall.stderr.on('data', function (data) { + pipeOutput(data); + }); + + bowerInstall.on('exit', function (code) { + if (code === 0) { promptForNamespace(); } + else { + console.error(styleText('Failed to install bower dependencies', 'red')); + } }); } + else { + console.error(styleText('Failed to install npm dependencies', 'red')); + } + }); function promptForNamespace() { @@ -26,7 +56,7 @@ function promptForNamespace() { prompt.get([{ name: 'namespace', - description: 'What will your namespace be?'.green, + description: 'What will your namespace be?', type: 'string', required: true }], function (err, result) { @@ -71,26 +101,90 @@ function promptForCleanup() { prompt.get([{ name: 'cleanup', - description: 'Initialize Git? (Y / N)'.green, + description: 'Initialize Git? (Y / N)', type: 'string', default: 'Y', required: true }], function (err, result) { if (!err && (result.cleanup === 'Y' || result.cleanup === 'y')) { - cleanup(); + cleanupGit(); + } + else { + cleanupNode(); } }); } -function cleanup() { +function cleanupGit() { var rmrf = require('rimraf'); rmrf('.git', function (error) { if (!error) { - exec('git init', function () { - console.log('Git initialized.'); - console.log('Tip: You might want to adjust bower.json + package.json'); + gitInit = spawn('git', ['init']); + + gitInit.stdout.on('data', function (data) { + pipeOutput(data); + }); + + gitInit.stderr.on('data', function (data) { + pipeOutput(data); + }); + + gitInit.on('exit', function () { + cleanupNode(); }); } }); +} + +function cleanupNode() { + var packageJson = require('../package.json'), + npmRm = spawn('npm', ['rm', '-D'].concat(Object.keys(packageJson.devDependencies))); + + console.log(styleText('Removing build dependencies...')); + + npmRm.stdout.on('data', function (data) { + pipeOutput(data); + }); + + npmRm.stderr.on('data', function (data) { + pipeOutput(data); + }); + + npmRm.on('exit', function () { + cleanupBin(); + }); +} + +function cleanupBin() { + var exec = require('child_process').exec; + + exec('rm bin/* && rmdir bin/', function () { + showInstallSuccess(); + }); +} + +function showInstallSuccess() { + console.log('=============================='); + console.log(styleText('Install completed successfully') + '\n'); + console.log('It is recommended to run: `npm init && bower init` to define your own package settings'); + console.log('=============================='); +} + +function pipeOutput(data) { + process.stdout.write(data.toString()); +} + +function styleText(text, colour) { + if (!colour) { + colour = 'green'; + } + + var colours = { + green: 32, + red: 31 + }, + c = colours[colour]; + + return '\u001b[' + c + 'm' + text + '\u001b[39m'; } \ No newline at end of file diff --git a/bower.json b/bower.json index f02a084..6b6110e 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "phaser-typescript-boilerplate", - "version": "1.2.0", + "version": "1.3.0", "homepage": "https://github.com/cloakedninjas/phaser-typescript-boilerplate", "authors": [ "cloakedninjas " @@ -23,6 +23,6 @@ "tests" ], "dependencies": { - "phaser": "~2.4.4" + "phaser": "~2.6.1" } } diff --git a/package.json b/package.json index a3b4258..c2c5990 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "phaser-typescript-boilerplate", - "version": "1.2.0", + "version": "1.3.0", "description": "Boilerplate for Phaser using Typescript", "main": "index.js", "scripts": { @@ -17,14 +17,14 @@ }, "homepage": "https://github.com/cloakedninjas/phaser-typescript-boilerplate#readme", "dependencies": { - "grunt": "^0.4.5", - "grunt-contrib-clean": "^0.7.0", - "grunt-contrib-copy": "^0.8.2", - "grunt-contrib-watch": "^0.6.1", - "grunt-ts": "^5.2.0" + "grunt": "^1.0.1", + "grunt-contrib-clean": "^1.0.0", + "grunt-contrib-copy": "^1.0.0", + "grunt-contrib-watch": "^1.0.0", + "grunt-ts": "^5.5.1" }, "devDependencies": { - "prompt": "^0.2.14", - "rimraf": "^2.5.1" + "prompt": "^1.0.0", + "rimraf": "^2.5.4" } }