From 3133f851648dbfcb821ee831060faa59a6949246 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 17 Feb 2014 14:51:21 +0000 Subject: [PATCH 01/24] Initial open source commit --- libraries/settings/Settings.coffee | 16 ++++++++++++++++ libraries/settings/index.js | 2 ++ libraries/settings/package.json | 8 ++++++++ 3 files changed, 26 insertions(+) create mode 100755 libraries/settings/Settings.coffee create mode 100755 libraries/settings/index.js create mode 100644 libraries/settings/package.json diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.coffee new file mode 100755 index 0000000000..b60d6f8396 --- /dev/null +++ b/libraries/settings/Settings.coffee @@ -0,0 +1,16 @@ +fs = require "fs" +path = require "path" +env = (process.env.NODE_ENV or "development").toLowerCase() + +possibleConfigFiles = [ + process.cwd() + "/config/settings.#{env}.coffee" + path.normalize(__dirname + "/../../config/settings.#{env}.coffee") +] + +for file in possibleConfigFiles + if fs.existsSync(file) + module.exports = require(file) + return + +console.log "No config file could be found at: ", possibleConfigFiles +throw new Error("No config file found") diff --git a/libraries/settings/index.js b/libraries/settings/index.js new file mode 100755 index 0000000000..2d248c73df --- /dev/null +++ b/libraries/settings/index.js @@ -0,0 +1,2 @@ +require("coffee-script") +module.exports = require('./Settings'); diff --git a/libraries/settings/package.json b/libraries/settings/package.json new file mode 100644 index 0000000000..4044c9b3dc --- /dev/null +++ b/libraries/settings/package.json @@ -0,0 +1,8 @@ +{ + "name": "settings-sharelatex", + "homepage": "www.sharelatex.com", + "version": "0.0.1", + "dependencies": { + "coffee-script":"1.6.0" + } +} From 6baf4ebe855af1b6df1fa08c4a6ded6b271911a0 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 19 Feb 2014 13:21:32 +0000 Subject: [PATCH 02/24] Take config from SHARELATEX_CONFIG env variable --- libraries/settings/README.md | 19 +++++++++++++++++++ libraries/settings/Settings.coffee | 11 +++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 libraries/settings/README.md diff --git a/libraries/settings/README.md b/libraries/settings/README.md new file mode 100644 index 0000000000..266092ba9c --- /dev/null +++ b/libraries/settings/README.md @@ -0,0 +1,19 @@ +settings-sharelatex +=================== + +A small module to allow global config settings to be set for all services +within the ShareLaTeX architecture. + +Settings file location +---------------------- + +You can specify a custom location for the settings file by setting the +`SHARELATEX_CONFIG` environment variable. E.g. + + $ export SHARELATEX_CONFIG=/home/james/config/settings.development.coffee + +Otherwise, the settings will be loaded from `config/settings.NODE_ENV.coffee`, +where `NODE_ENV` is another evnironment variable, or defaults to `development`. + +The config directory is first looked for in the current directory, and then relative +to the settings module directory. \ No newline at end of file diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.coffee index b60d6f8396..8f91b46403 100755 --- a/libraries/settings/Settings.coffee +++ b/libraries/settings/Settings.coffee @@ -2,10 +2,13 @@ fs = require "fs" path = require "path" env = (process.env.NODE_ENV or "development").toLowerCase() -possibleConfigFiles = [ - process.cwd() + "/config/settings.#{env}.coffee" - path.normalize(__dirname + "/../../config/settings.#{env}.coffee") -] +if process.env.SHARELATEX_CONFIG? + possibleConfigFiles = [process.env.SHARELATEX_CONFIG] +else + possibleConfigFiles = [ + process.cwd() + "/config/settings.#{env}.coffee" + path.normalize(__dirname + "/../../config/settings.#{env}.coffee") + ] for file in possibleConfigFiles if fs.existsSync(file) From c06e237e312e5e59985c0a2c18388738c9351abc Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 2 Apr 2014 17:25:50 +0100 Subject: [PATCH 03/24] Load and merge defaults if available Load and merge defaults if available --- libraries/settings/Settings.coffee | 31 ++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.coffee index 8f91b46403..dc289e2bfb 100755 --- a/libraries/settings/Settings.coffee +++ b/libraries/settings/Settings.coffee @@ -2,6 +2,24 @@ fs = require "fs" path = require "path" env = (process.env.NODE_ENV or "development").toLowerCase() +merge = (settings, defaults) -> + for key, value of settings + if typeof(value) == "object" + defaults[key] = merge(settings[key], defaults[key] or {}) + else + defaults[key] = value + return defaults + +defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults.coffee") + +console.log "default settings", defaultSettingsPath +if fs.existsSync(defaultSettingsPath) + defaults = require(defaultSettingsPath) + settingsExist = true +else + defaults = {} + settingsExist = false + if process.env.SHARELATEX_CONFIG? possibleConfigFiles = [process.env.SHARELATEX_CONFIG] else @@ -12,8 +30,13 @@ else for file in possibleConfigFiles if fs.existsSync(file) - module.exports = require(file) - return + module.exports = merge(require(file), defaults) + settingsExist = true + break -console.log "No config file could be found at: ", possibleConfigFiles -throw new Error("No config file found") +if !settingsExist + console.warn "No settings or defaults found. I'm flying blind." + +module.exports = defaults + +console.log "Settings", module.exports \ No newline at end of file From 89d09340f572b3f6d7168ea5bd330f4167fb9896 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 2 Apr 2014 17:43:11 +0100 Subject: [PATCH 04/24] Don't log out the settings --- libraries/settings/Settings.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.coffee index dc289e2bfb..e1a750fd3e 100755 --- a/libraries/settings/Settings.coffee +++ b/libraries/settings/Settings.coffee @@ -39,4 +39,3 @@ if !settingsExist module.exports = defaults -console.log "Settings", module.exports \ No newline at end of file From 4f377c5fa214a31237cc542a1cefa2414f58829e Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 2 Apr 2014 21:27:27 +0100 Subject: [PATCH 05/24] Remove unnecessary logging --- libraries/settings/Settings.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.coffee index e1a750fd3e..009958a3e2 100755 --- a/libraries/settings/Settings.coffee +++ b/libraries/settings/Settings.coffee @@ -12,7 +12,6 @@ merge = (settings, defaults) -> defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults.coffee") -console.log "default settings", defaultSettingsPath if fs.existsSync(defaultSettingsPath) defaults = require(defaultSettingsPath) settingsExist = true From 0da921311cd1d72b0bd4d9aaaf2c0f18f64390ff Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 3 Apr 2014 11:14:28 +0100 Subject: [PATCH 06/24] Preserve arrays --- libraries/settings/Settings.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.coffee index 009958a3e2..81fc8977f5 100755 --- a/libraries/settings/Settings.coffee +++ b/libraries/settings/Settings.coffee @@ -4,7 +4,7 @@ env = (process.env.NODE_ENV or "development").toLowerCase() merge = (settings, defaults) -> for key, value of settings - if typeof(value) == "object" + if typeof(value) == "object" and value not instanceof Array defaults[key] = merge(settings[key], defaults[key] or {}) else defaults[key] = value From 1dc82ef6241fd09867eaad8f5a1a4964fe065101 Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 19 Aug 2014 13:35:15 +0100 Subject: [PATCH 07/24] Release version 1.0.0 --- libraries/settings/package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/settings/package.json b/libraries/settings/package.json index 4044c9b3dc..42c0b46c30 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -1,7 +1,12 @@ { "name": "settings-sharelatex", "homepage": "www.sharelatex.com", - "version": "0.0.1", + "description": "A centralised settings system for ShareLaTeX", + "version": "1.0.0", + "repository": { + "type": "git", + "url": "https://github.com/sharelatex/settings-sharelatex.git" + }, "dependencies": { "coffee-script":"1.6.0" } From 5f506723429e333f4b2ac3a967ac92946ca72eec Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 8 Sep 2014 09:17:55 +0100 Subject: [PATCH 08/24] Create LICENSE --- libraries/settings/LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 libraries/settings/LICENSE diff --git a/libraries/settings/LICENSE b/libraries/settings/LICENSE new file mode 100644 index 0000000000..f49ce1ac14 --- /dev/null +++ b/libraries/settings/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 ShareLaTeX + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. From 98eb92a0a999c38b53f97ad69ab255aeedc47127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Fern=C3=A1ndez=20Capel?= Date: Tue, 10 Apr 2018 14:01:32 +0100 Subject: [PATCH 09/24] Allow .js setting files --- libraries/settings/Settings.coffee | 7 ++++--- libraries/settings/package.json | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.coffee index 81fc8977f5..9517e02bcc 100755 --- a/libraries/settings/Settings.coffee +++ b/libraries/settings/Settings.coffee @@ -10,9 +10,9 @@ merge = (settings, defaults) -> defaults[key] = value return defaults -defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults.coffee") +defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults") -if fs.existsSync(defaultSettingsPath) +if fs.existsSync("#{defaultSettingsPath}.coffee") or fs.existsSync("#{defaultSettingsPath}.js") defaults = require(defaultSettingsPath) settingsExist = true else @@ -23,6 +23,8 @@ if process.env.SHARELATEX_CONFIG? possibleConfigFiles = [process.env.SHARELATEX_CONFIG] else possibleConfigFiles = [ + process.cwd() + "/config/settings.#{env}.js" + path.normalize(__dirname + "/../../config/settings.#{env}.js") process.cwd() + "/config/settings.#{env}.coffee" path.normalize(__dirname + "/../../config/settings.#{env}.coffee") ] @@ -37,4 +39,3 @@ if !settingsExist console.warn "No settings or defaults found. I'm flying blind." module.exports = defaults - diff --git a/libraries/settings/package.json b/libraries/settings/package.json index 42c0b46c30..692c0b7b91 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -2,7 +2,7 @@ "name": "settings-sharelatex", "homepage": "www.sharelatex.com", "description": "A centralised settings system for ShareLaTeX", - "version": "1.0.0", + "version": "1.0.1", "repository": { "type": "git", "url": "https://github.com/sharelatex/settings-sharelatex.git" From 006cfb0142d20afecf096e1731d06d35f651c4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Fern=C3=A1ndez=20Capel?= Date: Wed, 11 Apr 2018 14:08:18 +0100 Subject: [PATCH 10/24] Upgrade minor version The last change introduced a new but compatible feature. --- libraries/settings/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/settings/package.json b/libraries/settings/package.json index 692c0b7b91..978a782b03 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -2,7 +2,7 @@ "name": "settings-sharelatex", "homepage": "www.sharelatex.com", "description": "A centralised settings system for ShareLaTeX", - "version": "1.0.1", + "version": "1.1.0", "repository": { "type": "git", "url": "https://github.com/sharelatex/settings-sharelatex.git" From 6d33d383d0e82955803bd4cad03aeb7e66320260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Alby?= Date: Tue, 7 May 2019 16:16:11 +0100 Subject: [PATCH 11/24] Update README.md - change app name --- libraries/settings/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/settings/README.md b/libraries/settings/README.md index 266092ba9c..fd2284a51a 100644 --- a/libraries/settings/README.md +++ b/libraries/settings/README.md @@ -1,8 +1,8 @@ -settings-sharelatex +overleaf/settings-module =================== A small module to allow global config settings to be set for all services -within the ShareLaTeX architecture. +within the Overleaf architecture. Settings file location ---------------------- @@ -16,4 +16,4 @@ Otherwise, the settings will be loaded from `config/settings.NODE_ENV.coffee`, where `NODE_ENV` is another evnironment variable, or defaults to `development`. The config directory is first looked for in the current directory, and then relative -to the settings module directory. \ No newline at end of file +to the settings module directory. From c16fb06ecdfcb4221362fdae3eb4c467aa8c47b4 Mon Sep 17 00:00:00 2001 From: Alf Eaton <75253002+aeaton-overleaf@users.noreply.github.com> Date: Thu, 11 Mar 2021 11:07:32 +0000 Subject: [PATCH 12/24] Log the settings files that are used --- libraries/settings/Settings.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.coffee index 9517e02bcc..4e0c26db57 100755 --- a/libraries/settings/Settings.coffee +++ b/libraries/settings/Settings.coffee @@ -31,6 +31,7 @@ else for file in possibleConfigFiles if fs.existsSync(file) + console.log "Using settings from " + file module.exports = merge(require(file), defaults) settingsExist = true break From c4be8bca60efc32fcce57a2c51f32cc483f41c84 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 16 Mar 2021 09:20:34 +0000 Subject: [PATCH 13/24] 1.2.0 --- libraries/settings/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/settings/package.json b/libraries/settings/package.json index 978a782b03..459f8f7661 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -2,12 +2,12 @@ "name": "settings-sharelatex", "homepage": "www.sharelatex.com", "description": "A centralised settings system for ShareLaTeX", - "version": "1.1.0", + "version": "1.2.0", "repository": { "type": "git", "url": "https://github.com/sharelatex/settings-sharelatex.git" }, "dependencies": { - "coffee-script":"1.6.0" + "coffee-script": "1.6.0" } } From cf1a5bf0f757924cbd7620b771b25d3b8b42022a Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 20 Apr 2021 09:25:26 +0100 Subject: [PATCH 14/24] Add deprecation warning for .coffee settings files --- libraries/settings/Settings.coffee | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.coffee index 4e0c26db57..672b89dc73 100755 --- a/libraries/settings/Settings.coffee +++ b/libraries/settings/Settings.coffee @@ -12,8 +12,14 @@ merge = (settings, defaults) -> defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults") -if fs.existsSync("#{defaultSettingsPath}.coffee") or fs.existsSync("#{defaultSettingsPath}.js") - defaults = require(defaultSettingsPath) +if fs.existsSync("#{defaultSettingsPath}.js") + console.log "Using default settings from #{defaultSettingsPath}.js" + defaults = require("#{defaultSettingsPath}.js") + settingsExist = true +else if fs.existsSync("#{defaultSettingsPath}.coffee") + console.warn "CoffeeScript settings file #{defaultSettingsPath}.coffee is deprecated, please convert to JavaScript" + console.log "Using default settings from #{defaultSettingsPath}.coffee" + defaults = require("#{defaultSettingsPath}.coffee") settingsExist = true else defaults = {} @@ -31,6 +37,8 @@ else for file in possibleConfigFiles if fs.existsSync(file) + if file.endsWith('.coffee') + console.warn "CoffeeScript settings file #{file}.coffee is deprecated, please convert to JavaScript" console.log "Using settings from " + file module.exports = merge(require(file), defaults) settingsExist = true From be098ee993e79124cb358410dc31d4daa34454c1 Mon Sep 17 00:00:00 2001 From: Alf Eaton <75253002+aeaton-overleaf@users.noreply.github.com> Date: Mon, 26 Apr 2021 09:09:00 +0100 Subject: [PATCH 15/24] Update Settings.coffee Co-authored-by: nate stemen --- libraries/settings/Settings.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.coffee index 672b89dc73..7b32d24d27 100755 --- a/libraries/settings/Settings.coffee +++ b/libraries/settings/Settings.coffee @@ -38,7 +38,7 @@ else for file in possibleConfigFiles if fs.existsSync(file) if file.endsWith('.coffee') - console.warn "CoffeeScript settings file #{file}.coffee is deprecated, please convert to JavaScript" + console.warn "CoffeeScript settings file #{file} is deprecated, please convert to JavaScript" console.log "Using settings from " + file module.exports = merge(require(file), defaults) settingsExist = true From c7511970b0a5995c04ed9e64013558f6c2f630b3 Mon Sep 17 00:00:00 2001 From: Alf Eaton <75253002+aeaton-overleaf@users.noreply.github.com> Date: Wed, 28 Apr 2021 09:33:59 +0100 Subject: [PATCH 16/24] v1.3.0 --- libraries/settings/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/settings/package.json b/libraries/settings/package.json index 459f8f7661..3bf1f7ce8e 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -2,7 +2,7 @@ "name": "settings-sharelatex", "homepage": "www.sharelatex.com", "description": "A centralised settings system for ShareLaTeX", - "version": "1.2.0", + "version": "1.3.0", "repository": { "type": "git", "url": "https://github.com/sharelatex/settings-sharelatex.git" From 551eef00fbacac579875e60421b791d7a02e2a4d Mon Sep 17 00:00:00 2001 From: decaffeinate Date: Wed, 26 May 2021 14:24:23 +0100 Subject: [PATCH 17/24] decaffeinate: Rename Settings.coffee from .coffee to .js --- libraries/settings/{Settings.coffee => Settings.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libraries/settings/{Settings.coffee => Settings.js} (100%) diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.js similarity index 100% rename from libraries/settings/Settings.coffee rename to libraries/settings/Settings.js From 2787cd615283884bf62b86726bc5dc4639d329e0 Mon Sep 17 00:00:00 2001 From: decaffeinate Date: Wed, 26 May 2021 14:24:24 +0100 Subject: [PATCH 18/24] decaffeinate: Convert Settings.coffee to JS --- libraries/settings/Settings.js | 101 +++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 42 deletions(-) mode change 100755 => 100644 libraries/settings/Settings.js diff --git a/libraries/settings/Settings.js b/libraries/settings/Settings.js old mode 100755 new mode 100644 index 7b32d24d27..106de03f13 --- a/libraries/settings/Settings.js +++ b/libraries/settings/Settings.js @@ -1,50 +1,67 @@ -fs = require "fs" -path = require "path" -env = (process.env.NODE_ENV or "development").toLowerCase() +/* + * decaffeinate suggestions: + * DS101: Remove unnecessary use of Array.from + * DS207: Consider shorter variations of null checks + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +let defaults, possibleConfigFiles, settingsExist; +const fs = require("fs"); +const path = require("path"); +const env = (process.env.NODE_ENV || "development").toLowerCase(); -merge = (settings, defaults) -> - for key, value of settings - if typeof(value) == "object" and value not instanceof Array - defaults[key] = merge(settings[key], defaults[key] or {}) - else - defaults[key] = value - return defaults +var merge = function(settings, defaults) { + for (let key in settings) { + const value = settings[key]; + if ((typeof(value) === "object") && !(value instanceof Array)) { + defaults[key] = merge(settings[key], defaults[key] || {}); + } else { + defaults[key] = value; + } + } + return defaults; +}; -defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults") +const defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults"); -if fs.existsSync("#{defaultSettingsPath}.js") - console.log "Using default settings from #{defaultSettingsPath}.js" - defaults = require("#{defaultSettingsPath}.js") - settingsExist = true -else if fs.existsSync("#{defaultSettingsPath}.coffee") - console.warn "CoffeeScript settings file #{defaultSettingsPath}.coffee is deprecated, please convert to JavaScript" - console.log "Using default settings from #{defaultSettingsPath}.coffee" - defaults = require("#{defaultSettingsPath}.coffee") - settingsExist = true -else - defaults = {} - settingsExist = false +if (fs.existsSync(`${defaultSettingsPath}.js`)) { + console.log(`Using default settings from ${defaultSettingsPath}.js`); + defaults = require(`${defaultSettingsPath}.js`); + settingsExist = true; +} else if (fs.existsSync(`${defaultSettingsPath}.coffee`)) { + console.warn(`CoffeeScript settings file ${defaultSettingsPath}.coffee is deprecated, please convert to JavaScript`); + console.log(`Using default settings from ${defaultSettingsPath}.coffee`); + defaults = require(`${defaultSettingsPath}.coffee`); + settingsExist = true; +} else { + defaults = {}; + settingsExist = false; +} -if process.env.SHARELATEX_CONFIG? - possibleConfigFiles = [process.env.SHARELATEX_CONFIG] -else +if (process.env.SHARELATEX_CONFIG != null) { + possibleConfigFiles = [process.env.SHARELATEX_CONFIG]; +} else { possibleConfigFiles = [ - process.cwd() + "/config/settings.#{env}.js" - path.normalize(__dirname + "/../../config/settings.#{env}.js") - process.cwd() + "/config/settings.#{env}.coffee" - path.normalize(__dirname + "/../../config/settings.#{env}.coffee") - ] + process.cwd() + `/config/settings.${env}.js`, + path.normalize(__dirname + `/../../config/settings.${env}.js`), + process.cwd() + `/config/settings.${env}.coffee`, + path.normalize(__dirname + `/../../config/settings.${env}.coffee`) + ]; +} -for file in possibleConfigFiles - if fs.existsSync(file) - if file.endsWith('.coffee') - console.warn "CoffeeScript settings file #{file} is deprecated, please convert to JavaScript" - console.log "Using settings from " + file - module.exports = merge(require(file), defaults) - settingsExist = true - break +for (let file of Array.from(possibleConfigFiles)) { + if (fs.existsSync(file)) { + if (file.endsWith('.coffee')) { + console.warn(`CoffeeScript settings file ${file} is deprecated, please convert to JavaScript`); + } + console.log("Using settings from " + file); + module.exports = merge(require(file), defaults); + settingsExist = true; + break; + } +} -if !settingsExist - console.warn "No settings or defaults found. I'm flying blind." +if (!settingsExist) { + console.warn("No settings or defaults found. I'm flying blind."); +} -module.exports = defaults +module.exports = defaults; From 93f618a98055ffa1c7ffad2bcc531dc65fe1dafe Mon Sep 17 00:00:00 2001 From: decaffeinate Date: Wed, 26 May 2021 14:24:24 +0100 Subject: [PATCH 19/24] decaffeinate: Run post-processing cleanups on Settings.coffee --- libraries/settings/Settings.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/settings/Settings.js b/libraries/settings/Settings.js index 106de03f13..f29cf16832 100644 --- a/libraries/settings/Settings.js +++ b/libraries/settings/Settings.js @@ -1,3 +1,5 @@ +// TODO: This file was created by bulk-decaffeinate. +// Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from From 9c0dbbc5c8fa33245ab69692de27a485ebe84345 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Wed, 26 May 2021 15:06:24 +0100 Subject: [PATCH 20/24] Remove CoffeeScript --- libraries/settings/LICENSE | 2 +- libraries/settings/README.md | 8 ++++---- libraries/settings/Settings.js | 29 ++++++++++------------------- libraries/settings/index.js | 1 - libraries/settings/package.json | 15 ++++----------- 5 files changed, 19 insertions(+), 36 deletions(-) diff --git a/libraries/settings/LICENSE b/libraries/settings/LICENSE index f49ce1ac14..54a584e24f 100644 --- a/libraries/settings/LICENSE +++ b/libraries/settings/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 ShareLaTeX +Copyright (c) 2014-2021 Overleaf Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/settings/README.md b/libraries/settings/README.md index fd2284a51a..fee9f78d90 100644 --- a/libraries/settings/README.md +++ b/libraries/settings/README.md @@ -1,4 +1,4 @@ -overleaf/settings-module +@overleaf/settings-module =================== A small module to allow global config settings to be set for all services @@ -10,10 +10,10 @@ Settings file location You can specify a custom location for the settings file by setting the `SHARELATEX_CONFIG` environment variable. E.g. - $ export SHARELATEX_CONFIG=/home/james/config/settings.development.coffee + $ export SHARELATEX_CONFIG=/home/james/config/settings.development.js -Otherwise, the settings will be loaded from `config/settings.NODE_ENV.coffee`, -where `NODE_ENV` is another evnironment variable, or defaults to `development`. +Otherwise, the settings will be loaded from `config/settings.NODE_ENV.js`, +where `NODE_ENV` is another environment variable, or defaults to `development`. The config directory is first looked for in the current directory, and then relative to the settings module directory. diff --git a/libraries/settings/Settings.js b/libraries/settings/Settings.js index f29cf16832..202fc26494 100644 --- a/libraries/settings/Settings.js +++ b/libraries/settings/Settings.js @@ -1,21 +1,12 @@ -// TODO: This file was created by bulk-decaffeinate. -// Sanity-check the conversion and remove this comment. -/* - * decaffeinate suggestions: - * DS101: Remove unnecessary use of Array.from - * DS207: Consider shorter variations of null checks - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ let defaults, possibleConfigFiles, settingsExist; const fs = require("fs"); const path = require("path"); const env = (process.env.NODE_ENV || "development").toLowerCase(); -var merge = function(settings, defaults) { - for (let key in settings) { - const value = settings[key]; +const merge = function(settings, defaults) { + for (const [key, value] of Object.entries(settings)) { if ((typeof(value) === "object") && !(value instanceof Array)) { - defaults[key] = merge(settings[key], defaults[key] || {}); + defaults[key] = merge(value, defaults[key] || {}); } else { defaults[key] = value; } @@ -30,30 +21,30 @@ if (fs.existsSync(`${defaultSettingsPath}.js`)) { defaults = require(`${defaultSettingsPath}.js`); settingsExist = true; } else if (fs.existsSync(`${defaultSettingsPath}.coffee`)) { - console.warn(`CoffeeScript settings file ${defaultSettingsPath}.coffee is deprecated, please convert to JavaScript`); - console.log(`Using default settings from ${defaultSettingsPath}.coffee`); - defaults = require(`${defaultSettingsPath}.coffee`); - settingsExist = true; + // TODO: remove this in the next major version + throw new Error(`CoffeeScript settings file ${defaultSettingsPath}.coffee is no longer supported, please convert to JavaScript`); } else { defaults = {}; settingsExist = false; } -if (process.env.SHARELATEX_CONFIG != null) { +if (process.env.SHARELATEX_CONFIG) { possibleConfigFiles = [process.env.SHARELATEX_CONFIG]; } else { possibleConfigFiles = [ process.cwd() + `/config/settings.${env}.js`, path.normalize(__dirname + `/../../config/settings.${env}.js`), + // TODO: remove these in the next major version process.cwd() + `/config/settings.${env}.coffee`, path.normalize(__dirname + `/../../config/settings.${env}.coffee`) ]; } -for (let file of Array.from(possibleConfigFiles)) { +for (let file of possibleConfigFiles) { if (fs.existsSync(file)) { + // TODO: remove this in the next major version if (file.endsWith('.coffee')) { - console.warn(`CoffeeScript settings file ${file} is deprecated, please convert to JavaScript`); + throw new Error(`CoffeeScript settings file ${file} is no longer supported, please convert to JavaScript`); } console.log("Using settings from " + file); module.exports = merge(require(file), defaults); diff --git a/libraries/settings/index.js b/libraries/settings/index.js index 2d248c73df..1a9043cdaf 100755 --- a/libraries/settings/index.js +++ b/libraries/settings/index.js @@ -1,2 +1 @@ -require("coffee-script") module.exports = require('./Settings'); diff --git a/libraries/settings/package.json b/libraries/settings/package.json index 3bf1f7ce8e..37de0d57fd 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -1,13 +1,6 @@ { - "name": "settings-sharelatex", - "homepage": "www.sharelatex.com", - "description": "A centralised settings system for ShareLaTeX", - "version": "1.3.0", - "repository": { - "type": "git", - "url": "https://github.com/sharelatex/settings-sharelatex.git" - }, - "dependencies": { - "coffee-script": "1.6.0" - } + "name": "@overleaf/settings-module", + "description": "A centralised settings system for Overleaf", + "version": "2.0.0", + "repository": "overleaf/settings-module" } From 955c9162c07e0b064f243ca1596dd3310f72c1e0 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 28 May 2021 09:15:24 +0100 Subject: [PATCH 21/24] Rename to @overleaf/settings --- libraries/settings/README.md | 2 +- libraries/settings/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/settings/README.md b/libraries/settings/README.md index fee9f78d90..ac5adfc14f 100644 --- a/libraries/settings/README.md +++ b/libraries/settings/README.md @@ -1,4 +1,4 @@ -@overleaf/settings-module +@overleaf/settings =================== A small module to allow global config settings to be set for all services diff --git a/libraries/settings/package.json b/libraries/settings/package.json index 37de0d57fd..dd598c373d 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -1,5 +1,5 @@ { - "name": "@overleaf/settings-module", + "name": "@overleaf/settings", "description": "A centralised settings system for Overleaf", "version": "2.0.0", "repository": "overleaf/settings-module" From 03f6e8af642f5554ebc7bd6bffb4763c34397d89 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 6 Jul 2021 13:51:28 +0100 Subject: [PATCH 22/24] [misc] expose merge function in a separate module --- libraries/settings/Settings.js | 12 +----------- libraries/settings/merge.js | 12 ++++++++++++ libraries/settings/package.json | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 libraries/settings/merge.js diff --git a/libraries/settings/Settings.js b/libraries/settings/Settings.js index 202fc26494..60bd447098 100644 --- a/libraries/settings/Settings.js +++ b/libraries/settings/Settings.js @@ -2,17 +2,7 @@ let defaults, possibleConfigFiles, settingsExist; const fs = require("fs"); const path = require("path"); const env = (process.env.NODE_ENV || "development").toLowerCase(); - -const merge = function(settings, defaults) { - for (const [key, value] of Object.entries(settings)) { - if ((typeof(value) === "object") && !(value instanceof Array)) { - defaults[key] = merge(value, defaults[key] || {}); - } else { - defaults[key] = value; - } - } - return defaults; -}; +const { merge } = require('./merge'); const defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults"); diff --git a/libraries/settings/merge.js b/libraries/settings/merge.js new file mode 100644 index 0000000000..c1b24d2bae --- /dev/null +++ b/libraries/settings/merge.js @@ -0,0 +1,12 @@ +function merge(settings, defaults) { + for (const [key, value] of Object.entries(settings)) { + if ((typeof(value) === "object") && !(value instanceof Array)) { + defaults[key] = merge(value, defaults[key] || {}); + } else { + defaults[key] = value; + } + } + return defaults; +} + +module.exports = { merge }; diff --git a/libraries/settings/package.json b/libraries/settings/package.json index dd598c373d..0ea2fde33e 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -1,6 +1,6 @@ { "name": "@overleaf/settings", "description": "A centralised settings system for Overleaf", - "version": "2.0.0", + "version": "2.1.0", "repository": "overleaf/settings-module" } From acc65b2518766ae6e68282a6ec9b3a86f81fb474 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 6 Jul 2021 15:19:13 +0100 Subject: [PATCH 23/24] [misc] fix path to app config/ dir following the renaming of the package The Settings.js file is now located in node_modules/@overleaf/settings, which is one level deeper than node_modules/settings-sharelatex. --- libraries/settings/Settings.js | 6 +++--- libraries/settings/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/settings/Settings.js b/libraries/settings/Settings.js index 60bd447098..6672803955 100644 --- a/libraries/settings/Settings.js +++ b/libraries/settings/Settings.js @@ -4,7 +4,7 @@ const path = require("path"); const env = (process.env.NODE_ENV || "development").toLowerCase(); const { merge } = require('./merge'); -const defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults"); +const defaultSettingsPath = path.normalize(__dirname + "/../../../config/settings.defaults"); if (fs.existsSync(`${defaultSettingsPath}.js`)) { console.log(`Using default settings from ${defaultSettingsPath}.js`); @@ -23,10 +23,10 @@ if (process.env.SHARELATEX_CONFIG) { } else { possibleConfigFiles = [ process.cwd() + `/config/settings.${env}.js`, - path.normalize(__dirname + `/../../config/settings.${env}.js`), + path.normalize(__dirname + `/../../../config/settings.${env}.js`), // TODO: remove these in the next major version process.cwd() + `/config/settings.${env}.coffee`, - path.normalize(__dirname + `/../../config/settings.${env}.coffee`) + path.normalize(__dirname + `/../../../config/settings.${env}.coffee`) ]; } diff --git a/libraries/settings/package.json b/libraries/settings/package.json index 0ea2fde33e..27fae668c3 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -1,6 +1,6 @@ { "name": "@overleaf/settings", "description": "A centralised settings system for Overleaf", - "version": "2.1.0", + "version": "2.1.1", "repository": "overleaf/settings-module" } From cd9877d7d761d46151f61edc9b32afec578fe887 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Thu, 29 Jul 2021 10:51:32 +0100 Subject: [PATCH 24/24] [misc] prepare for monorepo - add git ignore entries - create package-lock.json --- libraries/settings/.gitignore | 2 ++ libraries/settings/package-lock.json | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 libraries/settings/.gitignore create mode 100644 libraries/settings/package-lock.json diff --git a/libraries/settings/.gitignore b/libraries/settings/.gitignore new file mode 100644 index 0000000000..aac65cda7a --- /dev/null +++ b/libraries/settings/.gitignore @@ -0,0 +1,2 @@ +.npmrc +Dockerfile diff --git a/libraries/settings/package-lock.json b/libraries/settings/package-lock.json new file mode 100644 index 0000000000..de48101b3a --- /dev/null +++ b/libraries/settings/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "@overleaf/settings", + "version": "2.1.1", + "lockfileVersion": 1 +}