Create basic module loading system

This commit is contained in:
James Allen 2014-09-08 14:19:24 +01:00
parent 08cebe369d
commit becb294c5c
5 changed files with 78 additions and 31 deletions

View file

@ -67,3 +67,5 @@ Gemfile.lock
.DS_Store .DS_Store
app/views/external app/views/external
modules

View file

@ -10,7 +10,7 @@ module.exports = (grunt) ->
grunt.loadNpmTasks 'grunt-execute' grunt.loadNpmTasks 'grunt-execute'
grunt.loadNpmTasks 'grunt-bunyan' grunt.loadNpmTasks 'grunt-bunyan'
grunt.initConfig config =
execute: execute:
app: app:
src: "app.js" src: "app.js"
@ -27,10 +27,6 @@ module.exports = (grunt) ->
app: app:
src: 'app.coffee' src: 'app.coffee'
dest: 'app.js' dest: 'app.js'
BackgroundJobsWorker:
src: 'BackgroundJobsWorker.coffee'
dest: 'BackgroundJobsWorker.js'
sharejs: sharejs:
options: options:
@ -163,6 +159,46 @@ module.exports = (grunt) ->
"help" "help"
] ]
moduleCompileServerTasks = []
moduleCompileUnitTestTasks = []
moduleUnitTestTasks = []
for module in fs.readdirSync "./modules"
config.coffee["module_#{module}_server"] = {
expand: true,
flatten: false,
cwd: "modules/#{module}/app/coffee",
src: ['**/*.coffee'],
dest: "modules/#{module}/app/js",
ext: '.js'
}
config.coffee["module_#{module}_index"] = {
src: "modules/#{module}/index.coffee",
dest: "modules/#{module}/index.js"
}
moduleCompileServerTasks.push "coffee:module_#{module}_server"
moduleCompileServerTasks.push "coffee:module_#{module}_index"
config.coffee["module_#{module}_unit_tests"] = {
expand: true,
flatten: false,
cwd: "modules/#{module}/test/unit/coffee",
src: ['**/*.coffee'],
dest: "modules/#{module}/test/unit/js",
ext: '.js'
}
config.mochaTest["module_#{module}_unit"] = {
src: ["modules/#{module}/test/unit/js/*.js"]
options:
reporter: grunt.option('reporter') or 'spec'
grep: grunt.option("grep")
}
moduleCompileUnitTestTasks.push "coffee:module_#{module}_unit_tests"
moduleUnitTestTasks.push "mochaTest:module_#{module}_unit"
grunt.initConfig config
grunt.registerTask 'wrap_sharejs', 'Wrap the compiled ShareJS code for AMD module loading', () -> grunt.registerTask 'wrap_sharejs', 'Wrap the compiled ShareJS code for AMD module loading', () ->
content = fs.readFileSync "public/js/libs/sharejs.js" content = fs.readFileSync "public/js/libs/sharejs.js"
fs.writeFileSync "public/js/libs/sharejs.js", """ fs.writeFileSync "public/js/libs/sharejs.js", """
@ -174,7 +210,9 @@ module.exports = (grunt) ->
grunt.registerTask 'help', 'Display this help list', 'availabletasks' grunt.registerTask 'help', 'Display this help list', 'availabletasks'
grunt.registerTask 'compile:server', 'Compile the server side coffee script', ['clean:app', 'coffee:app', 'coffee:app_dir'] grunt.registerTask 'compile:modules:server', 'Compile all the modules', moduleCompileServerTasks
grunt.registerTask 'compile:modules:unit_tests', 'Compile all the modules unit tests', moduleCompileUnitTestTasks
grunt.registerTask 'compile:server', 'Compile the server side coffee script', ['clean:app', 'coffee:app', 'coffee:app_dir', 'compile:modules:server']
grunt.registerTask 'compile:client', 'Compile the client side coffee script', ['coffee:client', 'coffee:sharejs', 'wrap_sharejs'] grunt.registerTask 'compile:client', 'Compile the client side coffee script', ['coffee:client', 'coffee:sharejs', 'wrap_sharejs']
grunt.registerTask 'compile:css', 'Compile the less files to css', ['less'] grunt.registerTask 'compile:css', 'Compile the less files to css', ['less']
grunt.registerTask 'compile:minify', 'Concat and minify the client side js', ['requirejs'] grunt.registerTask 'compile:minify', 'Concat and minify the client side js', ['requirejs']
@ -187,6 +225,8 @@ module.exports = (grunt) ->
grunt.registerTask 'test:unit', 'Run the unit tests (use --grep=<regex> or --feature=<feature> for individual tests)', ['compile:server', 'compile:unit_tests', 'mochaTest:unit'] grunt.registerTask 'test:unit', 'Run the unit tests (use --grep=<regex> or --feature=<feature> for individual tests)', ['compile:server', 'compile:unit_tests', 'mochaTest:unit']
grunt.registerTask 'test:smoke', 'Run the smoke tests', ['compile:smoke_tests', 'mochaTest:smoke'] grunt.registerTask 'test:smoke', 'Run the smoke tests', ['compile:smoke_tests', 'mochaTest:smoke']
grunt.registerTask 'test:modules:unit', 'Run the unit tests for the modules', ['compile:modules:server', 'compile:modules:unit_tests'].concat(moduleUnitTestTasks)
grunt.registerTask 'run', "Compile and run the web-sharelatex server", ['compile', 'bunyan', 'execute'] grunt.registerTask 'run', "Compile and run the web-sharelatex server", ['compile', 'bunyan', 'execute']
grunt.registerTask 'default', 'run' grunt.registerTask 'default', 'run'

View file

@ -39,6 +39,7 @@ WikiController = require("./Features/Wiki/WikiController")
ConnectedUsersController = require("./Features/ConnectedUsers/ConnectedUsersController") ConnectedUsersController = require("./Features/ConnectedUsers/ConnectedUsersController")
DropboxRouter = require "./Features/Dropbox/DropboxRouter" DropboxRouter = require "./Features/Dropbox/DropboxRouter"
dropboxHandler = require "./Features/Dropbox/DropboxHandler" dropboxHandler = require "./Features/Dropbox/DropboxHandler"
Modules = require "./infrastructure/Modules"
logger = require("logger-sharelatex") logger = require("logger-sharelatex")
_ = require("underscore") _ = require("underscore")
@ -67,6 +68,8 @@ module.exports = class Router
StaticPagesRouter.apply(app) StaticPagesRouter.apply(app)
TemplatesRouter.apply(app) TemplatesRouter.apply(app)
DropboxRouter.apply(app) DropboxRouter.apply(app)
Modules.applyRouter(app)
app.get '/blog', BlogController.getIndexPage app.get '/blog', BlogController.getIndexPage
app.get '/blog/*', BlogController.getPage app.get '/blog/*', BlogController.getPage

View file

@ -88,6 +88,8 @@ module.exports =
url: "http://localhost:3013" url: "http://localhost:3013"
templates: templates:
url: "http://localhost:3007" url: "http://localhost:3007"
githubSync:
url: "http://localhost:3022"
recurly: recurly:
privateKey: "" privateKey: ""
apiKey: "" apiKey: ""

View file

@ -3,44 +3,44 @@
"version": "0.1.0", "version": "0.1.0",
"description": "The HTTP front end for ShareLaTeX", "description": "The HTTP front end for ShareLaTeX",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/sharelatex/web-sharelatex.git" "url": "https://github.com/sharelatex/web-sharelatex.git"
}, },
"directories": { "directories": {
"public": "./public" "public": "./public"
}, },
"dependencies": { "dependencies": {
"express": "3.3.4", "archiver": "0.9.0",
"mongoose": "3.8.8",
"mongojs": "0.10.1",
"underscore": "1.6.0",
"rimraf": "2.2.6",
"connect-redis": "1.4.5",
"redis": "0.10.1",
"request": "2.34.0",
"xml2js": "0.2.0",
"dateformat": "1.0.4-1.2.3",
"optimist": "0.6.1",
"async": "0.6.2", "async": "0.6.2",
"lynx": "0.1.1", "bcrypt": "0.7.5",
"session.socket.io": "0.1.4",
"socket.io": "0.9.16",
"mimelib": "0.2.14",
"bufferedstream": "1.6.0", "bufferedstream": "1.6.0",
"settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#v1.0.0", "connect-redis": "1.4.5",
"logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.0.0", "dateformat": "1.0.4-1.2.3",
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.0.0", "express": "3.3.4",
"translations-sharelatex": "git+https://github.com/sharelatex/translations-sharelatex.git#master",
"soa-req-id": "git+https://github.com/sharelatex/soa-req-id.git#v1.0.0",
"fairy": "0.0.2", "fairy": "0.0.2",
"jade": "~1.3.1",
"logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.0.0",
"lynx": "0.1.1",
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.0.0",
"mimelib": "0.2.14",
"mocha": "1.17.1",
"mongojs": "0.10.1",
"mongoose": "3.8.8",
"node-uuid": "1.4.1", "node-uuid": "1.4.1",
"nodemailer": "0.6.1", "nodemailer": "0.6.1",
"bcrypt": "0.7.5", "optimist": "0.6.1",
"archiver": "0.9.0",
"mocha": "1.17.1",
"redback": "0.4.0", "redback": "0.4.0",
"redis": "0.10.1",
"request": "2.34.0",
"rimraf": "2.2.6",
"sanitizer": "0.1.1", "sanitizer": "0.1.1",
"jade": "~1.3.1" "session.socket.io": "0.1.4",
"settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#v1.0.0",
"soa-req-id": "git+https://github.com/sharelatex/soa-req-id.git#v1.0.0",
"socket.io": "0.9.16",
"translations-sharelatex": "git+https://github.com/sharelatex/translations-sharelatex.git#master",
"underscore": "1.6.0",
"xml2js": "0.2.0"
}, },
"devDependencies": { "devDependencies": {
"chai": "", "chai": "",