From 8b6425317f132700ead0ec6c020aa64afd28e70d Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 22 Sep 2016 11:02:20 +0100 Subject: [PATCH 1/3] introduce PackageVersions module put all package versions in one central place --- services/web/Gruntfile.coffee | 6 ++++-- .../Features/Project/ProjectController.coffee | 3 ++- .../app/coffee/infrastructure/ExpressLocals.coffee | 14 ++++++++------ .../coffee/infrastructure/PackageVersions.coffee | 13 +++++++++++++ services/web/app/views/project/editor.jade | 13 +++++++------ 5 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 services/web/app/coffee/infrastructure/PackageVersions.coffee diff --git a/services/web/Gruntfile.coffee b/services/web/Gruntfile.coffee index 147ab3a66f..e7389e2356 100644 --- a/services/web/Gruntfile.coffee +++ b/services/web/Gruntfile.coffee @@ -1,4 +1,6 @@ fs = require "fs" +PackageVersions = require "./app/coffee/infrastructure/PackageVersions" +pdfjs = PackageVersions.lib('pdfjs') module.exports = (grunt) -> grunt.loadNpmTasks 'grunt-contrib-coffee' @@ -159,10 +161,10 @@ module.exports = (grunt) -> paths: "moment": "libs/moment-2.9.0" "mathjax": "/js/libs/mathjax/MathJax.js?config=TeX-AMS_HTML" - "libs/pdf": "libs/pdfjs-1.3.91p1/pdf" + "libs/pdf": "libs/#{pdfjs}/pdf" shim: "libs/pdf": - deps: ["libs/pdfjs-1.3.91p1/compatibility"] + deps: ["libs/#{pdfjs}/compatibility"] skipDirOptimize: true modules: [ diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index c1fb698b9d..8120e3e5c9 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -19,6 +19,7 @@ ProjectUpdateHandler = require("./ProjectUpdateHandler") ProjectGetter = require("./ProjectGetter") PrivilegeLevels = require("../Authorization/PrivilegeLevels") AuthenticationController = require("../Authentication/AuthenticationController") +PackageVersions = require("../../infrastructure/PackageVersions") module.exports = ProjectController = @@ -331,7 +332,7 @@ defaultSettingsForAnonymousUser = (user_id)-> THEME_LIST = [] do generateThemeList = () -> - files = fs.readdirSync __dirname + '/../../../../public/js/ace' + files = fs.readdirSync __dirname + '/../../../../public/js/' + PackageVersions.lib('ace') for file in files if file.slice(-2) == "js" and file.match(/^theme-/) cleanName = file.slice(0,-3).slice(6) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 1b316f37ab..8763624516 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -10,17 +10,18 @@ _ = require("underscore") async = require("async") Modules = require "./Modules" Url = require "url" - +PackageVersions = require "./PackageVersions" fingerprints = {} Path = require 'path' - jsPath = if Settings.useMinifiedJs "/minjs/" else "/js/" +ace = PackageVersions.lib('ace') +pdfjs = PackageVersions.lib('pdfjs') getFileContent = (filePath)-> filePath = Path.join __dirname, "../../../", "public#{filePath}" @@ -38,10 +39,10 @@ pathList = [ ["#{jsPath}ide.js"] ["#{jsPath}main.js"] ["#{jsPath}libs.js"] - ["#{jsPath}ace/ace.js","#{jsPath}ace/mode-latex.js", "#{jsPath}ace/snippets/latex.js"] - ["#{jsPath}libs/pdfjs-1.3.91p1/pdf.js"] - ["#{jsPath}libs/pdfjs-1.3.91p1/pdf.worker.js"] - ["#{jsPath}libs/pdfjs-1.3.91p1/compatibility.js"] + ["#{jsPath}#{ace}/ace.js","#{jsPath}#{ace}/mode-latex.js", "#{jsPath}#{ace}/snippets/latex.js"] + ["#{jsPath}libs/#{pdfjs}/pdf.js"] + ["#{jsPath}libs/#{pdfjs}/pdf.worker.js"] + ["#{jsPath}libs/#{pdfjs}/compatibility.js"] ["/stylesheets/style.css"] ] @@ -92,6 +93,7 @@ module.exports = (app, webRouter, apiRouter)-> res.locals.jsPath = jsPath res.locals.fullJsPath = Url.resolve(staticFilesBase, jsPath) + res.locals.lib = PackageVersions.lib res.locals.buildJsPath = (jsFile, opts = {})-> path = Path.join(jsPath, jsFile) diff --git a/services/web/app/coffee/infrastructure/PackageVersions.coffee b/services/web/app/coffee/infrastructure/PackageVersions.coffee new file mode 100644 index 0000000000..c2a73fb2cf --- /dev/null +++ b/services/web/app/coffee/infrastructure/PackageVersions.coffee @@ -0,0 +1,13 @@ +version = { + "pdfjs": "1.3.91p1" +} + +module.exports = { + version: version + + lib: (name) -> + if version[name]? + return "#{name}-#{version[name]}" + else + return "#{name}" +} diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index b5463c647d..e595d21f72 100644 --- a/services/web/app/views/project/editor.jade +++ b/services/web/app/views/project/editor.jade @@ -102,13 +102,14 @@ block content "paths" : { "mathjax": "#{buildJsPath('/libs/mathjax/MathJax.js', {cdn:false, fingerprint:false, qs:{config:'TeX-AMS_HTML'}})}", "moment": "libs/moment-2.7.0", - "libs/pdf": "libs/pdfjs-1.3.91p1/pdf", + "libs/pdf": "libs/#{lib('pdfjs')}/pdf", + "ace": "#{lib('ace')}" }, "urlArgs" : "fingerprint=#{fingerprint(jsPath + 'ide.js')}-#{fingerprint(jsPath + 'libs.js')}", "waitSeconds": 0, "shim": { "libs/pdf": { - deps: ["libs/pdfjs-1.3.91p1/compatibility"] + deps: ["libs/#{lib('pdfjs')}/compatibility"] }, "ace/ext-searchbox": { deps: ["ace/ace"] @@ -123,14 +124,14 @@ block content } } }; - window.aceFingerprint = "#{fingerprint(jsPath + 'ace/ace.js')}" + window.aceFingerprint = "#{fingerprint(jsPath + lib('ace') + '/ace.js')}" - locals.suppressDefaultJs = true - - var pdfPath = 'libs/pdfjs-1.3.91p1/pdf.worker.js' + - var pdfPath = "libs/" + lib('pdfjs') + "/pdf.worker.js" - var fingerprintedPath = fingerprint(jsPath+pdfPath) - var pdfJsWorkerPath = buildJsPath(pdfPath, {cdn:false,qs:{fingerprint:fingerprintedPath}}) // don't use worker for cdn - - var aceWorkerPath = user.betaProgram ? buildJsPath("ace", {cdn:false,fingerprint:false}) : "" // don't use worker for cdn + - var aceWorkerPath = user.betaProgram ? buildJsPath(lib('ace'), {cdn:false,fingerprint:false}) : "" // don't use worker for cdn script(type='text/javascript'). window.pdfJsWorkerPath = "#{pdfJsWorkerPath}"; @@ -139,7 +140,7 @@ block content script( data-main=buildJsPath("ide.js", {fingerprint:false}), baseurl=fullJsPath, - data-ace-base=buildJsPath('ace', {fingerprint:false}), + data-ace-base=buildJsPath(lib('ace'), {fingerprint:false}), src=buildJsPath('libs/require.js') ) From 837151a3958a74a62e3b0911952b20fbdbab3d09 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 22 Sep 2016 11:36:53 +0100 Subject: [PATCH 2/3] include moment in package versions --- services/web/Gruntfile.coffee | 7 +++---- .../web/app/coffee/infrastructure/PackageVersions.coffee | 1 + services/web/app/views/layout.jade | 7 ++++++- services/web/app/views/project/editor.jade | 2 +- services/web/public/coffee/filters/formatDate.coffee | 4 ++-- .../coffee/ide/track-changes/TrackChangesManager.coffee | 3 ++- services/web/public/coffee/libs.coffee | 2 +- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/services/web/Gruntfile.coffee b/services/web/Gruntfile.coffee index e7389e2356..3e7c187d8d 100644 --- a/services/web/Gruntfile.coffee +++ b/services/web/Gruntfile.coffee @@ -1,6 +1,5 @@ fs = require "fs" PackageVersions = require "./app/coffee/infrastructure/PackageVersions" -pdfjs = PackageVersions.lib('pdfjs') module.exports = (grunt) -> grunt.loadNpmTasks 'grunt-contrib-coffee' @@ -159,12 +158,12 @@ module.exports = (grunt) -> inlineText: false preserveLicenseComments: false paths: - "moment": "libs/moment-2.9.0" + "moment": "libs/#{PackageVersions.lib('moment')}" "mathjax": "/js/libs/mathjax/MathJax.js?config=TeX-AMS_HTML" - "libs/pdf": "libs/#{pdfjs}/pdf" + "libs/pdf": "libs/#{PackageVersions.lib('pdfjs')}/pdf" shim: "libs/pdf": - deps: ["libs/#{pdfjs}/compatibility"] + deps: ["libs/#{PackageVersions.lib('pdfjs')}/compatibility"] skipDirOptimize: true modules: [ diff --git a/services/web/app/coffee/infrastructure/PackageVersions.coffee b/services/web/app/coffee/infrastructure/PackageVersions.coffee index c2a73fb2cf..dd7b7d51a4 100644 --- a/services/web/app/coffee/infrastructure/PackageVersions.coffee +++ b/services/web/app/coffee/infrastructure/PackageVersions.coffee @@ -1,5 +1,6 @@ version = { "pdfjs": "1.3.91p1" + "moment": "2.9.0" } module.exports = { diff --git a/services/web/app/views/layout.jade b/services/web/app/views/layout.jade index 30b6b2294b..07fe638b29 100644 --- a/services/web/app/views/layout.jade +++ b/services/web/app/views/layout.jade @@ -126,7 +126,12 @@ html(itemscope, itemtype='http://schema.org/Product') window.requirejs = { "urlArgs" : "fingerprint=#{fingerprint(jsPath + 'main.js')}-#{fingerprint(jsPath + 'libs.js')}", "paths" : { - "moment": "libs/moment-2.7.0" + "moment": "libs/#{lib('moment')}" + }, + "config":{ + "moment":{ + "noGlobal": true + } } }; script( diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index e595d21f72..d6acb94f34 100644 --- a/services/web/app/views/project/editor.jade +++ b/services/web/app/views/project/editor.jade @@ -101,7 +101,7 @@ block content window.requirejs = { "paths" : { "mathjax": "#{buildJsPath('/libs/mathjax/MathJax.js', {cdn:false, fingerprint:false, qs:{config:'TeX-AMS_HTML'}})}", - "moment": "libs/moment-2.7.0", + "moment": "libs/#{lib('moment')}", "libs/pdf": "libs/#{lib('pdfjs')}/pdf", "ace": "#{lib('ace')}" }, diff --git a/services/web/public/coffee/filters/formatDate.coffee b/services/web/public/coffee/filters/formatDate.coffee index 395194456e..5b8c9e10c6 100644 --- a/services/web/public/coffee/filters/formatDate.coffee +++ b/services/web/public/coffee/filters/formatDate.coffee @@ -1,6 +1,6 @@ define [ "base" - "libs/moment-2.9.0" + "moment" ], (App, moment) -> moment.locale "en", calendar: lastDay : '[Yesterday]' @@ -16,4 +16,4 @@ define [ App.filter "relativeDate", () -> (date) -> - moment(date).calendar() \ No newline at end of file + moment(date).calendar() diff --git a/services/web/public/coffee/ide/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/ide/track-changes/TrackChangesManager.coffee index ecd3b5a7f8..10b6bb9765 100644 --- a/services/web/public/coffee/ide/track-changes/TrackChangesManager.coffee +++ b/services/web/public/coffee/ide/track-changes/TrackChangesManager.coffee @@ -1,8 +1,9 @@ define [ + "moment" "ide/track-changes/controllers/TrackChangesListController" "ide/track-changes/controllers/TrackChangesDiffController" "ide/track-changes/directives/infiniteScroll" -], () -> +], (moment) -> class TrackChangesManager constructor: (@ide, @$scope) -> @reset() diff --git a/services/web/public/coffee/libs.coffee b/services/web/public/coffee/libs.coffee index d41170391c..307d0307b6 100644 --- a/services/web/public/coffee/libs.coffee +++ b/services/web/public/coffee/libs.coffee @@ -1,5 +1,5 @@ define [ - "libs/moment-2.9.0" + "moment" "libs/angular-autocomplete/angular-autocomplete" "libs/ui-bootstrap" "libs/ng-context-menu-0.1.4" From 0946729ae64f333931a4ed70a67c71f2f3a0f7ea Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 23 Sep 2016 13:51:21 +0100 Subject: [PATCH 3/3] clean up config object --- services/web/app/views/project/editor.jade | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index d6acb94f34..bc8016dd86 100644 --- a/services/web/app/views/project/editor.jade +++ b/services/web/app/views/project/editor.jade @@ -109,18 +109,18 @@ block content "waitSeconds": 0, "shim": { "libs/pdf": { - deps: ["libs/#{lib('pdfjs')}/compatibility"] + "deps": ["libs/#{lib('pdfjs')}/compatibility"] }, "ace/ext-searchbox": { - deps: ["ace/ace"] + "deps": ["ace/ace"] }, "ace/ext-language_tools": { - deps: ["ace/ace"] + "deps": ["ace/ace"] } }, - config:{ - moment:{ - noGlobal: true + "config":{ + "moment":{ + "noGlobal": true } } };