Sfoglia il codice sorgente

Decaffeinate: convert individual files to js

Nate Stemen 7 anni fa
parent
commit
ee4d9766fd
3 ha cambiato i file con 127 aggiunte e 74 eliminazioni
  1. 81 49
      services/chat/Gruntfile.js
  2. 23 10
      services/chat/app.js
  3. 23 15
      services/chat/config/settings.defaults.js

+ 81 - 49
services/chat/Gruntfile.js

@@ -1,97 +1,129 @@
-module.exports = (grunt) ->
+/*
+ * decaffeinate suggestions:
+ * DS102: Remove unnecessary code created because of implicit returns
+ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
+ */
+module.exports = function(grunt) {
 
-	# Project configuration.
-	grunt.initConfig
-		forever:
-			app:
-				options:
+	// Project configuration.
+	grunt.initConfig({
+		forever: {
+			app: {
+				options: {
 					index: "app.js"
+				}
+			}
+		},
 
-		execute:
-			app:
+		execute: {
+			app: {
 				src: "app.js"
+			}
+		},
 
-		coffee:
-			server: 
+		coffee: {
+			server: { 
 				expand: true,
 				flatten: false,
 				cwd: 'app/coffee',
 				src: ['**/*.coffee'],
 				dest: 'app/js/',
 				ext: '.js'
+			},
 
-			app_server: 
+			app_server: { 
 				expand: true,
 				flatten: false,
 				src: ['app.coffee'],
 				dest: './',
 				ext: '.js'
+			},
 
-			unit_tests:
+			unit_tests: {
 				expand: true,
 				flatten: false,
 				cwd: 'test/unit/coffee',
 				src: ['**/*.coffee'],
 				dest: 'test/unit/js/',
 				ext: '.js'
+			},
 
-			acceptance_tests:
+			acceptance_tests: {
 				expand: true,
 				flatten: false,
 				cwd: 'test/acceptance/coffee',
 				src: ['**/*.coffee'],
 				dest: 'test/acceptance/js/',
 				ext: '.js'
+			}
+		},
 
-		watch:
-			server_coffee:
-				files: ['app/**/*.coffee', 'test/unit/**/*.coffee']
+		watch: {
+			server_coffee: {
+				files: ['app/**/*.coffee', 'test/unit/**/*.coffee'],
 				tasks: ['compile:server', 'compile:unit_tests', 'mochaTest']
+			}
+		},
 
-		clean: ["app/js", "test/unit/js"]
+		clean: ["app/js", "test/unit/js"],
 
-		nodemon:
-			dev:
-				options:
+		nodemon: {
+			dev: {
+				options: {
 					file: 'app.js'
+				}
+			}
+		},
 
-		concurrent:
-			dev:
-				tasks: ['nodemon', 'watch']
-				options:
+		concurrent: {
+			dev: {
+				tasks: ['nodemon', 'watch'],
+				options: {
 					logConcurrentOutput: true
+				}
+			}
+		},
 
-		mochaTest:
-			unit:
-				options:
-					reporter: process.env.MOCHA_RUNNER || "spec"
+		mochaTest: {
+			unit: {
+				options: {
+					reporter: process.env.MOCHA_RUNNER || "spec",
 					grep: grunt.option("grep")
+				},
 				src: ['test/unit/**/*.js']
-			acceptance:
-				options:
-					reporter: process.env.MOCHA_RUNNER || "spec"
+			},
+			acceptance: {
+				options: {
+					reporter: process.env.MOCHA_RUNNER || "spec",
 					grep: grunt.option("grep")
+				},
 				src: ['test/acceptance/**/*.js']
+			}
+		},
 
-		plato:
-			your_task:
-				files: 'plato': ['app/js/**/*.js'],
+		plato: {
+			your_task: {
+				files: {'plato': ['app/js/**/*.js']}
+			}
+		}
+	});
 
-	grunt.loadNpmTasks 'grunt-contrib-coffee'
-	grunt.loadNpmTasks 'grunt-contrib-watch'
-	grunt.loadNpmTasks 'grunt-nodemon'
-	grunt.loadNpmTasks 'grunt-contrib-clean'
-	grunt.loadNpmTasks 'grunt-concurrent'
-	grunt.loadNpmTasks 'grunt-mocha-test'
-	grunt.loadNpmTasks 'grunt-plato'
-	grunt.loadNpmTasks 'grunt-execute'
-	grunt.loadNpmTasks 'grunt-bunyan'
-	grunt.loadNpmTasks 'grunt-forever'
+	grunt.loadNpmTasks('grunt-contrib-coffee');
+	grunt.loadNpmTasks('grunt-contrib-watch');
+	grunt.loadNpmTasks('grunt-nodemon');
+	grunt.loadNpmTasks('grunt-contrib-clean');
+	grunt.loadNpmTasks('grunt-concurrent');
+	grunt.loadNpmTasks('grunt-mocha-test');
+	grunt.loadNpmTasks('grunt-plato');
+	grunt.loadNpmTasks('grunt-execute');
+	grunt.loadNpmTasks('grunt-bunyan');
+	grunt.loadNpmTasks('grunt-forever');
 	
 
-	grunt.registerTask 'compile', ['clean', 'coffee']
-	grunt.registerTask 'install', ['compile']
-	grunt.registerTask 'default', ['compile', 'bunyan', 'execute']
-	grunt.registerTask 'test:unit', ['compile', 'mochaTest:unit']
-	grunt.registerTask 'test:acceptance', ['compile:acceptance_tests', 'mochaTest:acceptance']
+	grunt.registerTask('compile', ['clean', 'coffee']);
+	grunt.registerTask('install', ['compile']);
+	grunt.registerTask('default', ['compile', 'bunyan', 'execute']);
+	grunt.registerTask('test:unit', ['compile', 'mochaTest:unit']);
+	return grunt.registerTask('test:acceptance', ['compile:acceptance_tests', 'mochaTest:acceptance']);
+};
 

+ 23 - 10
services/chat/app.js

@@ -1,13 +1,26 @@
-logger = require 'logger-sharelatex'
-settings = require 'settings-sharelatex'
+/*
+ * decaffeinate suggestions:
+ * DS102: Remove unnecessary code created because of implicit returns
+ * DS103: Rewrite code to no longer use __guard__
+ * DS207: Consider shorter variations of null checks
+ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
+ */
+const logger = require('logger-sharelatex');
+const settings = require('settings-sharelatex');
 
-Server = require "./app/js/server"
+const Server = require("./app/js/server");
 
-if !module.parent # Called directly
-	port = settings.internal?.chat?.port or 3010
-	host = settings.internal?.chat?.host or "localhost"
-	Server.server.listen port, host, (error) ->
-		throw error if error?
-		logger.info "Chat starting up, listening on #{host}:#{port}"
+if (!module.parent) { // Called directly
+	const port = __guard__(settings.internal != null ? settings.internal.chat : undefined, x => x.port) || 3010;
+	const host = __guard__(settings.internal != null ? settings.internal.chat : undefined, x1 => x1.host) || "localhost";
+	Server.server.listen(port, host, function(error) {
+		if (error != null) { throw error; }
+		return logger.info(`Chat starting up, listening on ${host}:${port}`);
+	});
+}
 
-module.exports = Server.server
+module.exports = Server.server;
+
+function __guard__(value, transform) {
+  return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
+}

+ 23 - 15
services/chat/config/settings.defaults.js

@@ -1,20 +1,28 @@
-module.exports =
-	internal:
-		chat:
-			host: process.env['LISTEN_ADDRESS'] or "localhost"
+module.exports = {
+	internal: {
+		chat: {
+			host: process.env['LISTEN_ADDRESS'] || "localhost",
 			port: 3010
+		}
+	},
 	
-	apis:
-		web:
-			url: "http://#{process.env['WEB_HOST'] || "localhost"}:#{process.env['WEB_PORT'] or 3000}"
-			user: "sharelatex"
+	apis: {
+		web: {
+			url: `http://${process.env['WEB_HOST'] || "localhost"}:${process.env['WEB_PORT'] || 3000}`,
+			user: "sharelatex",
 			pass: "password"
+		}
+	},
 			
-	mongo:
-		url : "mongodb://#{process.env['MONGO_HOST'] || "localhost"}/sharelatex"
+	mongo: {
+		url : `mongodb://${process.env['MONGO_HOST'] || "localhost"}/sharelatex`
+	},
 
-	redis:
-		web:
-			host: process.env['REDIS_HOST'] || "localhost"
-			port: "6379"
-			password: ""
+	redis: {
+		web: {
+			host: process.env['REDIS_HOST'] || "localhost",
+			port: "6379",
+			password: ""
+		}
+	}
+};