From 00c9fdd362edccafba2936a65c054576dc9b1a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 21 Jan 2015 16:53:25 +0100 Subject: [PATCH] Improve plugin and config loading --- app-loader/app-loader.coffee | 27 +++++++++++++++++++++ app/coffee/modules/base/conf.coffee | 13 ++-------- app/index.jade | 5 ++-- bower.json | 3 ++- conf/{conf.example.js => conf.example.json} | 7 +++--- gulpfile.coffee | 15 +++++++++--- package.json | 3 ++- 7 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 app-loader/app-loader.coffee rename conf/{conf.example.js => conf.example.json} (75%) diff --git a/app-loader/app-loader.coffee b/app-loader/app-loader.coffee new file mode 100644 index 00000000..d17794e9 --- /dev/null +++ b/app-loader/app-loader.coffee @@ -0,0 +1,27 @@ +version = ___VERSION___ +window.taigaConfig = { + "api": "http://localhost:8000/api/v1/", + "eventsUrl": null, + "debug": true, + "publicRegisterEnabled": true, + "feedbackEnabled": true, + "privacyPolicyUrl": null, + "termsOfServiceUrl": null, + "maxUploadFileSize": null, + "gitHubClientId": null, + "contribPlugins": [] +} + +promise = $.getJSON "/js/conf.json" +promise.done (data) -> + window.taigaConfig = _.extend({}, window.taigaConfig, data) + +promise.always -> + if window.taigaConfig.contribPlugins.length > 0 + plugins = _.map(window.taigaConfig.contribPlugins, (plugin) -> "#{plugin}?v=#{version}") + ljs.load plugins, -> + ljs.load "/js/app.js?v=#{version}", -> + angular.bootstrap(document, ['taiga']) + else + ljs.load "/js/app.js?v=#{version}", -> + angular.bootstrap(document, ['taiga']) diff --git a/app/coffee/modules/base/conf.coffee b/app/coffee/modules/base/conf.coffee index e2bb3908..ad3ad0d7 100644 --- a/app/coffee/modules/base/conf.coffee +++ b/app/coffee/modules/base/conf.coffee @@ -19,17 +19,9 @@ # File: modules/base/conf.coffee ### -defaults = { - api: "http://localhost:8000/api/v1/" - debug: true - lang: "en" -} - class ConfigurationService - @.$inject = ["localconf"] - - constructor: (localconf) -> - @.config = _.merge(_.clone(defaults, true), localconf) + constructor: () -> + @.config = window.taigaConfig get: (key, defaultValue=null) -> if _.has(@.config, key) @@ -39,4 +31,3 @@ class ConfigurationService module = angular.module("taigaBase") module.service("$tgConfig", ConfigurationService) -module.value("localconf", null) diff --git a/app/index.jade b/app/index.jade index 27746d57..8bfaee6c 100644 --- a/app/index.jade +++ b/app/index.jade @@ -1,5 +1,5 @@ doctype html -html(lang="en", ng-app="taiga") +html(lang="en") head meta(charset="utf-8") title Taiga @@ -37,5 +37,4 @@ html(lang="en", ng-app="taiga") include partials/views/modules/loader script(src="/js/libs.js?v=#{v}") - script(src="/js/app.js?v=#{v}") - script(src="/js/conf.js?v=#{v}") + script(src="/js/app-loader.js?v=#{v}") diff --git a/bower.json b/bower.json index 0c197528..42c4cf44 100644 --- a/bower.json +++ b/bower.json @@ -73,7 +73,8 @@ "Sortable": "~0.1.8", "pikaday": "~1.2.0", "malihu-custom-scrollbar-plugin": "~3.0.4", - "raven-js": "~1.1.16" + "raven-js": "~1.1.16", + "l.js": "~0.1.0" }, "resolutions": { "lodash": "~2.4.1", diff --git a/conf/conf.example.js b/conf/conf.example.json similarity index 75% rename from conf/conf.example.js rename to conf/conf.example.json index 76425ed2..bd6340a9 100644 --- a/conf/conf.example.js +++ b/conf/conf.example.json @@ -1,4 +1,4 @@ -angular.module('taigaBase').value('localconf', { +{ "api": "http://localhost:8000/api/v1/", "eventsUrl": null, "debug": true, @@ -7,5 +7,6 @@ angular.module('taigaBase').value('localconf', { "privacyPolicyUrl": null, "termsOfServiceUrl": null, "maxUploadFileSize": null, - "gitHubClientId": null -}); + "gitHubClientId": null, + "contribPlugins": [] +} diff --git a/gulpfile.coffee b/gulpfile.coffee index ea058609..570b2bde 100644 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -9,6 +9,7 @@ wrap = require("gulp-wrap") rename = require("gulp-rename") flatten = require('gulp-flatten') gulpif = require('gulp-if') +replace = require("gulp-replace") minifyHTML = require("gulp-minify-html") sass = require("gulp-ruby-sass") @@ -102,6 +103,7 @@ paths.js = [ paths.app + "vendor/markitup-1x/markitup/jquery.markitup.js", paths.app + "vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min.js", paths.app + "vendor/raven-js/dist/raven.js", + paths.app + "vendor/l.js/l.js", paths.app + "js/jquery.ui.git-custom.js", paths.app + "js/jquery-ui.drag-multiple-custom.js", paths.app + "js/sha1-custom.js", @@ -204,8 +206,13 @@ gulp.task "styles", ["delete-tmp-styles"], -> ############################################################################## gulp.task "conf", -> - gulp.src("conf/conf.example.js") - .pipe(rename("conf.js")) + gulp.src(["conf/conf.example.json"]) + .pipe(gulp.dest(paths.dist + "js/")) + +gulp.task "app-loader", -> + gulp.src("app-loader/app-loader.coffee") + .pipe(replace("___VERSION___", (new Date()).getTime())) + .pipe(coffee()) .pipe(gulp.dest(paths.dist + "js/")) gulp.task "locales", -> @@ -236,7 +243,7 @@ gulp.task "jslibs-deploy", -> .pipe(sourcemaps.write('./')) .pipe(gulp.dest(paths.dist + "js/")) -gulp.task "app-watch", ["coffee", "conf", "locales"], -> +gulp.task "app-watch", ["coffee", "conf", "locales", "app-loader"], -> _paths = [ paths.tmp + "app.js", paths.tmp + "locales.en.js" @@ -246,7 +253,7 @@ gulp.task "app-watch", ["coffee", "conf", "locales"], -> .pipe(concat("app.js")) .pipe(gulp.dest(paths.dist + "js/")) -gulp.task "app-deploy", ["coffee", "conf", "locales"], -> +gulp.task "app-deploy", ["coffee", "conf", "locales", "app-loader"], -> _paths = [ paths.tmp + "app.js", paths.tmp + "locales.en.js" diff --git a/package.json b/package.json index 2082e368..581ce792 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "readable-stream": "~1.0.31", "rimraf": "^2.2.8", "run-sequence": "^1.0.1", - "through2": "~0.6.1" + "through2": "~0.6.1", + "gulp-replace": "^0.5.2" } }