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
app/views/external
modules

View file

@ -10,7 +10,7 @@ module.exports = (grunt) ->
grunt.loadNpmTasks 'grunt-execute'
grunt.loadNpmTasks 'grunt-bunyan'
grunt.initConfig
config =
execute:
app:
src: "app.js"
@ -28,10 +28,6 @@ module.exports = (grunt) ->
src: 'app.coffee'
dest: 'app.js'
BackgroundJobsWorker:
src: 'BackgroundJobsWorker.coffee'
dest: 'BackgroundJobsWorker.js'
sharejs:
options:
join: true
@ -163,6 +159,46 @@ module.exports = (grunt) ->
"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', () ->
content = fs.readFileSync "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 '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:css', 'Compile the less files to css', ['less']
grunt.registerTask 'compile:minify', 'Concat and minify the client side js', ['requirejs']
@ -188,6 +226,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: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 'default', 'run'

View file

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

View file

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

View file

@ -10,37 +10,37 @@
"public": "./public"
},
"dependencies": {
"express": "3.3.4",
"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",
"archiver": "0.9.0",
"async": "0.6.2",
"lynx": "0.1.1",
"session.socket.io": "0.1.4",
"socket.io": "0.9.16",
"mimelib": "0.2.14",
"bcrypt": "0.7.5",
"bufferedstream": "1.6.0",
"settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#v1.0.0",
"logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.0.0",
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.0.0",
"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",
"connect-redis": "1.4.5",
"dateformat": "1.0.4-1.2.3",
"express": "3.3.4",
"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",
"nodemailer": "0.6.1",
"bcrypt": "0.7.5",
"archiver": "0.9.0",
"mocha": "1.17.1",
"optimist": "0.6.1",
"redback": "0.4.0",
"redis": "0.10.1",
"request": "2.34.0",
"rimraf": "2.2.6",
"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": {
"chai": "",