diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 3fca025f1..8e70d230a 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -5,6 +5,8 @@ # All rights reserved. # +fs = require 'fs' + EXTERNAL_LIBS = [ 'backbone' 'jquery' @@ -223,6 +225,9 @@ module.exports = (grunt)-> grunt.registerTask 'upload:staging', 'upload the project the staging Amazon S3 environment', ['dist', 'script:s3_upload:staging'] + grunt.registerTask 'useLocalDeps', 'use local dependencies instead of NPM dependencies', + ['script:use_local_deps'] + # Code Tasks ####################################################################################################### grunt.registerTask 'browserify:external', "Bundle 3rd-party libraries used in the app", -> @@ -259,11 +264,6 @@ module.exports = (grunt)-> console.log error if error? done() - grunt.registerTask 'use-local-deps', -> - grunt.file.mkdir './node_modules' - grunt.file.delete './node_modules/crafting-guide-common', force:true - fs.symlinkSync '../../crafting-guide-common/', './node_modules/crafting-guide-common' - # Script Tasks ##################################################################################################### grunt.registerTask 'script:deploy:prod', "deploy code by copying to the production branch", -> @@ -290,6 +290,10 @@ module.exports = (grunt)-> done = this.async() grunt.util.spawn cmd:'./scripts/start', opts:{stdio:'inherit'}, (error)-> done(error) + grunt.registerTask 'script:use_local_deps', "use local dependencies instead of NPM dependencies", -> + done = this.async() + grunt.util.spawn cmd:'./scripts/use_local_deps', opts:{stdio:'inherit'}, (error)-> done(error) + # Command-Line Argument Processing ################################################################################# args = process.argv[..] diff --git a/scripts/use_local_deps b/scripts/use_local_deps new file mode 100755 index 000000000..eb06ad602 --- /dev/null +++ b/scripts/use_local_deps @@ -0,0 +1,8 @@ +#!/bin/bash + +if [[ -d "../crafting-guide-common" ]]; then + rm -rf ./node_modules/crafting-guide-common &>/dev/null + mkdir -p node_modules + cd node_modules + ln -s ../../crafting-guide-common +fi diff --git a/src/client/client.coffee b/src/client/client.coffee index 88c140f9c..8c139f683 100644 --- a/src/client/client.coffee +++ b/src/client/client.coffee @@ -25,8 +25,7 @@ Backbone.$ = $ global.logger = new Logger marked = require 'marked' -marked.setOptions - sanitize: true +marked.setOptions sanitize: true ######################################################################################################################## @@ -53,18 +52,35 @@ switch global.hostName ######################################################################################################################## +Storage = require './storage' +storage = new Storage storage:global.localStorage + +######################################################################################################################## + {CraftingGuideClient} = require 'crafting-guide-common' -client = _.extend new CraftingGuideClient(baseUrl:apiBaseUrl), Backbone.Events -client.onStatusChanged = (c, oldStatus, newStatus)-> - logger.info "Crafting Guide server status changed from #{oldStatus} to #{newStatus}" - client.trigger 'change:status', client, oldStatus, newStatus - client.trigger 'change', client +client = new CraftingGuideClient( + baseUrl: apiBaseUrl + + session: storage.load CraftingGuideClient.SESSION + + onSessionChanged: (client, oldSession, newSession)-> + logger.info "Updated server session data" + storage.store CraftingGuideClient.SESSION, session + client.trigger 'change:session', client, oldSession, newSession + client.trigger 'change', client + + onStatusChanged: (client, oldStatus, newStatus)-> + logger.info "Crafting Guide server status changed from #{oldStatus} to #{newStatus}" + client.trigger 'change:status', client, oldStatus, newStatus + client.trigger 'change', client +) +_(client).extend Backbone.Events client.checkStatus() ######################################################################################################################## SiteController = require './site/site_controller' -global.site = site = new SiteController client: client +global.site = site = new SiteController client:client, storage:storage site.render() site.loadDefaultModPack() site.loadCurrentUser() diff --git a/src/client/site/site_controller.coffee b/src/client/site/site_controller.coffee index 40e5909ca..bd47bfc2a 100644 --- a/src/client/site/site_controller.coffee +++ b/src/client/site/site_controller.coffee @@ -14,13 +14,14 @@ ImageLoader = require './image_loader' Mod = require '../models/game/mod' ModPack = require '../models/game/mod_pack' Router = require './router' -Storage = require './storage' ######################################################################################################################## module.exports = class SiteController extends BaseController constructor: (options={})-> + if not options.client? then throw new Error 'options.client is required' + if not options.storage? then throw new Error 'options.storage is required' options.el = 'html' super options @@ -28,7 +29,7 @@ module.exports = class SiteController extends BaseController @imageLoader = new ImageLoader defaultUrl:'/images/unknown.png' @modPack = new ModPack @router = new Router this - @storage = new Storage storage:global.localStorage + @storage = options.storage @_currentPage = null @_currentPageController = null diff --git a/src/client/site/storage.coffee b/src/client/storage.coffee similarity index 100% rename from src/client/site/storage.coffee rename to src/client/storage.coffee