2014-02-12 10:23:40 +00:00
fs = require " fs "
2016-09-22 10:02:20 +00:00
PackageVersions = require " ./app/coffee/infrastructure/PackageVersions "
2018-02-06 14:04:28 +00:00
Settings = require " settings-sharelatex "
2017-01-18 15:38:18 +00:00
require ( ' es6-promise ' ) . polyfill ( )
2014-02-12 10:23:40 +00:00
module.exports = (grunt) ->
grunt . loadNpmTasks ' grunt-contrib-coffee '
grunt . loadNpmTasks ' grunt-contrib-less '
grunt . loadNpmTasks ' grunt-contrib-clean '
grunt . loadNpmTasks ' grunt-mocha-test '
grunt . loadNpmTasks ' grunt-available-tasks '
grunt . loadNpmTasks ' grunt-contrib-requirejs '
grunt . loadNpmTasks ' grunt-bunyan '
2015-03-17 16:59:17 +00:00
grunt . loadNpmTasks ' grunt-sed '
grunt . loadNpmTasks ' grunt-git-rev-parse '
2015-10-09 09:11:38 +00:00
grunt . loadNpmTasks ' grunt-file-append '
2015-11-12 12:38:35 +00:00
grunt . loadNpmTasks ' grunt-file-append '
grunt . loadNpmTasks ' grunt-env '
2016-06-15 11:08:11 +00:00
grunt . loadNpmTasks ' grunt-newer '
grunt . loadNpmTasks ' grunt-contrib-watch '
grunt . loadNpmTasks ' grunt-parallel '
grunt . loadNpmTasks ' grunt-exec '
2017-01-18 15:38:18 +00:00
grunt . loadNpmTasks ' grunt-postcss '
2017-09-27 08:37:20 +00:00
grunt . loadNpmTasks ' grunt-forever '
grunt . loadNpmTasks ' grunt-shell '
2016-07-01 14:04:39 +00:00
# grunt.loadNpmTasks 'grunt-contrib-imagemin'
2016-07-04 15:03:29 +00:00
# grunt.loadNpmTasks 'grunt-sprity'
2015-10-09 09:11:38 +00:00
2014-09-08 13:19:24 +00:00
config =
2016-06-15 11:08:11 +00:00
exec:
run:
command : " node app.js | ./node_modules/logger-sharelatex/node_modules/bunyan/bin/bunyan --color "
2017-10-24 15:03:59 +00:00
cssmin_sl:
command : " node_modules/clean-css/bin/cleancss --s0 --source-map -o public/stylesheets/style.css public/stylesheets/style.css "
cssmin_ol:
command : " node_modules/clean-css/bin/cleancss --s0 --source-map -o public/stylesheets/ol-style.css public/stylesheets/ol-style.css "
2016-06-15 11:08:11 +00:00
2017-09-27 08:37:20 +00:00
forever:
app:
options:
index: " app.js "
2017-11-21 09:01:07 +00:00
logFile: " app.log "
2016-06-15 11:08:11 +00:00
watch:
coffee:
2016-06-18 18:16:45 +00:00
files: ' public/**/*.coffee '
2016-06-15 11:08:11 +00:00
tasks: [ ' quickcompile:coffee ' ]
options: { }
less:
files: ' **/*.less '
tasks: [ ' compile:css ' ]
options: { }
parallel:
run:
tasks : [ ' exec ' , ' watch ' ]
options:
grunt : true
stream : true
2014-02-12 10:23:40 +00:00
2016-06-18 15:50:56 +00:00
2016-06-30 13:58:54 +00:00
# imagemin:
# dynamic:
# files: [{
# expand: true
# cwd: 'public/img/'
# src: ['**/*.{png,jpg,gif}']
# dest: 'public/img/'
# }]
# options:
# interlaced:false
# optimizationLevel: 7
2016-06-18 18:16:45 +00:00
2016-07-04 15:03:29 +00:00
# sprity:
# sprite:
# options:
# cssPath:"/img/"
# 'style': '../../public/stylesheets/app/sprites.less'
# margin: 0
# src: ['./public/img/flags/24/*.png']
# dest: './public/img/sprite'
2016-06-18 18:16:45 +00:00
2016-06-18 15:50:56 +00:00
2014-02-12 10:23:40 +00:00
coffee:
app_dir:
expand: true ,
flatten: false ,
cwd: ' app/coffee ' ,
src: [ ' **/*.coffee ' ] ,
dest: ' app/js/ ' ,
ext: ' .js '
app:
src: ' app.coffee '
dest: ' app.js '
2014-03-18 15:06:10 +00:00
2014-02-12 10:23:40 +00:00
sharejs:
options:
join: true
files:
" public/js/libs/sharejs.js " : [
2014-07-08 11:01:32 +00:00
" public/coffee/ide/editor/sharejs/header.coffee "
" public/coffee/ide/editor/sharejs/vendor/types/helpers.coffee "
" public/coffee/ide/editor/sharejs/vendor/types/text.coffee "
" public/coffee/ide/editor/sharejs/vendor/types/text-api.coffee "
" public/coffee/ide/editor/sharejs/vendor/client/microevent.coffee "
" public/coffee/ide/editor/sharejs/vendor/client/doc.coffee "
" public/coffee/ide/editor/sharejs/vendor/client/ace.coffee "
2018-02-02 17:24:27 +00:00
" public/coffee/ide/editor/sharejs/vendor/client/cm.coffee "
2014-02-12 10:23:40 +00:00
]
client:
expand: true ,
flatten: false ,
cwd: ' public/coffee ' ,
src: [ ' **/*.coffee ' ] ,
dest: ' public/js/ ' ,
2017-06-26 15:27:12 +00:00
ext: ' .js ' ,
2017-06-26 15:14:03 +00:00
options:
2017-06-26 15:27:12 +00:00
sourceMap: true
2014-02-12 10:23:40 +00:00
smoke_tests:
expand: true ,
flatten: false ,
cwd: ' test/smoke/coffee ' ,
src: [ ' **/*.coffee ' ] ,
dest: ' test/smoke/js/ ' ,
ext: ' .js '
unit_tests:
expand: true ,
flatten: false ,
2017-11-27 17:10:22 +00:00
cwd: ' test/unit/coffee ' ,
2014-02-12 10:23:40 +00:00
src: [ ' **/*.coffee ' ] ,
2017-11-27 17:10:22 +00:00
dest: ' test/unit/js/ ' ,
2014-02-12 10:23:40 +00:00
ext: ' .js '
2016-03-08 15:59:04 +00:00
acceptance_tests:
expand: true ,
flatten: false ,
cwd: ' test/acceptance/coffee ' ,
src: [ ' **/*.coffee ' ] ,
dest: ' test/acceptance/js/ ' ,
ext: ' .js '
2014-02-12 10:23:40 +00:00
less:
app:
2017-10-23 15:58:02 +00:00
options:
sourceMap: true
2017-10-24 15:03:59 +00:00
sourceMapFilename: " public/stylesheets/style.css.map "
2017-10-23 15:58:02 +00:00
sourceMapBasepath: " public/stylesheets "
2018-02-05 16:20:33 +00:00
globalVars:
' is-overleaf ' : false
2018-02-06 14:04:28 +00:00
' show-rich-text ' : Settings . showRichText
2014-02-12 10:23:40 +00:00
files:
2014-06-04 15:14:35 +00:00
" public/stylesheets/style.css " : " public/stylesheets/style.less "
2017-08-07 15:01:59 +00:00
ol:
2017-10-23 15:58:02 +00:00
options:
sourceMap: true
2017-10-24 15:03:59 +00:00
sourceMapFilename: " public/stylesheets/ol-style.css.map "
2017-10-23 15:58:02 +00:00
sourceMapBasepath: " public/stylesheets "
2018-02-05 16:20:33 +00:00
globalVars:
' is-overleaf ' : true
2018-02-06 14:04:28 +00:00
' show-rich-text ' : Settings . showRichText
2017-08-07 15:01:59 +00:00
files:
" public/stylesheets/ol-style.css " : " public/stylesheets/ol-style.less "
2014-02-12 10:23:40 +00:00
2017-01-18 15:38:18 +00:00
postcss:
options:
2017-10-24 15:03:59 +00:00
map:
prev: " public/stylesheets/ "
inline: false
sourcesContent: true
2017-01-18 15:38:18 +00:00
processors: [
require ( ' autoprefixer ' ) ( { browsers: [ ' last 2 versions ' , ' ie >= 10 ' ] } )
]
dist:
2017-10-24 15:03:59 +00:00
src: [ " public/stylesheets/style.css " , " public/stylesheets/ol-style.css " ]
2016-06-18 20:49:32 +00:00
2015-11-12 12:38:35 +00:00
env:
run:
add:
NODE_TLS_REJECT_UNAUTHORIZED : 0
2016-06-15 11:08:11 +00:00
2014-02-12 10:23:40 +00:00
requirejs:
compile:
options:
2014-06-16 17:29:55 +00:00
optimize : " uglify2 "
uglify2:
mangle: false
2014-02-12 10:23:40 +00:00
appDir: " public/js "
baseUrl: " ./ "
dir: " public/minjs "
inlineText: false
2017-06-26 15:14:03 +00:00
generateSourceMaps: true
2014-02-12 10:23:40 +00:00
preserveLicenseComments: false
paths:
2016-09-22 10:36:53 +00:00
" moment " : " libs/ #{ PackageVersions . lib ( ' moment ' ) } "
2015-01-29 18:11:38 +00:00
" mathjax " : " /js/libs/mathjax/MathJax.js?config=TeX-AMS_HTML "
2016-10-13 13:51:21 +00:00
" pdfjs-dist/build/pdf " : " libs/ #{ PackageVersions . lib ( ' pdfjs ' ) } /pdf "
2016-10-12 08:52:15 +00:00
" ace " : " #{ PackageVersions . lib ( ' ace ' ) } "
2017-12-01 11:22:41 +00:00
" fineuploader " : " libs/ #{ PackageVersions . lib ( ' fineuploader ' ) } "
2014-02-12 10:23:40 +00:00
shim:
2016-10-13 13:51:21 +00:00
" pdfjs-dist/build/pdf " :
2016-09-22 10:36:53 +00:00
deps: [ " libs/ #{ PackageVersions . lib ( ' pdfjs ' ) } /compatibility " ]
2014-02-12 10:23:40 +00:00
skipDirOptimize: true
modules: [
{
name: " main " ,
2017-12-13 17:07:58 +00:00
exclude: [ " libraries " ]
2014-02-12 10:23:40 +00:00
} , {
name: " ide " ,
2017-12-13 17:07:58 +00:00
exclude: [ " pdfjs-dist/build/pdf " , " libraries " ]
2017-12-13 14:19:19 +00:00
} , {
2017-12-13 17:07:58 +00:00
name: " libraries "
2014-11-04 12:01:53 +00:00
} , {
name: " ace/mode-latex "
2016-09-14 14:17:24 +00:00
} , {
name: " ace/worker-latex "
2014-02-12 10:23:40 +00:00
}
2014-11-04 12:01:53 +00:00
2014-02-12 10:23:40 +00:00
]
clean:
app: [ " app/js " ]
2017-11-27 17:10:22 +00:00
unit_tests: [ " test/unit/js " ]
2016-03-08 15:59:04 +00:00
acceptance_tests: [ " test/acceptance/js " ]
2014-02-12 10:23:40 +00:00
mochaTest:
unit:
2017-11-27 17:10:22 +00:00
src: [ " test/unit/js/ #{ grunt . option ( ' feature ' ) or ' ** ' } /*.js " ]
2014-02-12 10:23:40 +00:00
options:
reporter: grunt . option ( ' reporter ' ) or ' spec '
grep: grunt . option ( " grep " )
smoke:
src: [ ' test/smoke/js/**/*.js ' ]
options:
reporter: grunt . option ( ' reporter ' ) or ' spec '
grep: grunt . option ( " grep " )
2016-03-08 15:59:04 +00:00
acceptance:
src: [ " test/acceptance/js/ #{ grunt . option ( ' feature ' ) or ' ** ' } /*.js " ]
options:
2016-07-28 13:50:08 +00:00
timeout: 40000
2016-03-08 15:59:04 +00:00
reporter: grunt . option ( ' reporter ' ) or ' spec '
grep: grunt . option ( " grep " )
2014-02-12 10:23:40 +00:00
2015-03-17 16:59:17 +00:00
" git-rev-parse " :
version:
options:
prop: ' commit '
2015-10-09 09:11:38 +00:00
file_append:
default_options: files: [ {
append: ' \n //ide.js is complete - used for automated testing '
input: ' public/minjs/ide.js '
output: ' public/minjs/ide.js '
} ]
2015-03-17 16:59:17 +00:00
sed:
version:
2017-01-20 12:03:02 +00:00
path: " app/views/sentry.pug "
2015-03-17 16:59:17 +00:00
pattern: ' @@COMMIT@@ ' ,
replacement: ' <%= commit %> ' ,
release:
2017-01-20 12:03:02 +00:00
path: " app/views/sentry.pug "
2015-03-17 16:59:17 +00:00
pattern: " @@RELEASE@@ "
replacement: process . env . BUILD_NUMBER || " (unknown build) "
2014-02-12 10:23:40 +00:00
2017-09-27 08:37:20 +00:00
shell:
fullAcceptanceTests:
command: " bash ./test/acceptance/scripts/full-test.sh "
dockerTests:
command: ' docker run -v " $(pwd):/app " --env SHARELATEX_ALLOW_PUBLIC_ACCESS=true --rm sharelatex/acceptance-test-runner '
2016-06-15 11:08:11 +00:00
2014-02-12 10:23:40 +00:00
availabletasks:
tasks:
options:
2016-06-15 11:08:11 +00:00
filter: ' exclude ' ,
tasks: [
' coffee '
' less '
' clean '
' mochaTest '
' availabletasks '
' wrap_sharejs '
' requirejs '
' execute '
' bunyan '
]
groups:
" Compile tasks " : [
" compile:server "
" compile:client "
" compile:tests "
" compile "
" compile:unit_tests "
" compile:smoke_tests "
" compile:css "
" compile:minify "
" install "
]
" Test tasks " : [
" test:unit "
" test:acceptance "
]
" Run tasks " : [
" run "
" default "
]
" Misc " : [
" help "
]
2014-02-12 10:23:40 +00:00
2014-09-08 13:19:24 +00:00
moduleCompileServerTasks = [ ]
moduleCompileUnitTestTasks = [ ]
moduleUnitTestTasks = [ ]
2014-09-08 16:33:30 +00:00
moduleCompileClientTasks = [ ]
moduleIdeClientSideIncludes = [ ]
2014-10-03 10:32:59 +00:00
moduleMainClientSideIncludes = [ ]
2014-09-08 13:23:47 +00:00
if fs . existsSync " ./modules "
for module in fs . readdirSync " ./modules "
2014-09-08 14:40:46 +00:00
if fs . existsSync " ./modules/ #{ module } /index.coffee "
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 " ] = {
2017-08-21 15:49:08 +00:00
src: [ " modules/ #{ module } /test/unit/js/**/*.js " ]
2014-09-08 14:40:46 +00:00
options:
reporter: grunt . option ( ' reporter ' ) or ' spec '
grep: grunt . option ( " grep " )
}
moduleCompileUnitTestTasks . push " coffee:module_ #{ module } _unit_tests "
moduleUnitTestTasks . push " mochaTest:module_ #{ module } _unit "
2014-09-08 16:33:30 +00:00
2014-10-03 10:32:59 +00:00
if fs . existsSync " ./modules/ #{ module } /public/coffee/ide/index.coffee "
2014-09-08 16:33:30 +00:00
config . coffee [ " module_ #{ module } _client_ide " ] = {
expand: true ,
flatten: false ,
cwd: " modules/ #{ module } /public/coffee/ide " ,
src: [ ' **/*.coffee ' ] ,
dest: " public/js/ide/ #{ module } " ,
ext: ' .js '
}
moduleCompileClientTasks . push " coffee:module_ #{ module } _client_ide "
moduleIdeClientSideIncludes . push " ide/ #{ module } /index "
2014-10-03 10:32:59 +00:00
if fs . existsSync " ./modules/ #{ module } /public/coffee/main/index.coffee "
config . coffee [ " module_ #{ module } _client_main " ] = {
expand: true ,
flatten: false ,
cwd: " modules/ #{ module } /public/coffee/main " ,
src: [ ' **/*.coffee ' ] ,
dest: " public/js/main/ #{ module } " ,
ext: ' .js '
}
moduleCompileClientTasks . push " coffee:module_ #{ module } _client_main "
moduleMainClientSideIncludes . push " main/ #{ module } /index "
2014-09-08 13:19:24 +00:00
grunt . initConfig config
2014-02-12 10:23:40 +00:00
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 " , """
2014-07-09 17:20:57 +00:00
define ( [ " ace/ace " ] , function ( ) {
2014-02-12 10:23:40 +00:00
#{content}
return window . sharejs ;
} ) ;
"""
grunt . registerTask ' help ' , ' Display this help list ' , ' availabletasks '
2014-09-08 13:19:24 +00:00
grunt . registerTask ' compile:modules:server ' , ' Compile all the modules ' , moduleCompileServerTasks
grunt . registerTask ' compile:modules:unit_tests ' , ' Compile all the modules unit tests ' , moduleCompileUnitTestTasks
2014-09-08 16:33:30 +00:00
grunt . registerTask ' compile:modules:client ' , ' Compile all the module client side code ' , moduleCompileClientTasks
grunt . registerTask ' compile:modules:inject_clientside_includes ' , () ->
content = fs . readFileSync ( " public/js/ide.js " ) . toString ( )
2014-10-08 11:22:04 +00:00
content = content . replace ( /, "__IDE_CLIENTSIDE_INCLUDES__"/g , moduleIdeClientSideIncludes . map ( (i) -> " , \" #{ i } \" " ) . join ( " " ) )
2014-09-08 16:33:30 +00:00
fs . writeFileSync " public/js/ide.js " , content
2014-10-03 10:32:59 +00:00
content = fs . readFileSync ( " public/js/main.js " ) . toString ( )
2014-10-08 11:22:04 +00:00
content = content . replace ( /, "__MAIN_CLIENTSIDE_INCLUDES__"/g , moduleMainClientSideIncludes . map ( (i) -> " , \" #{ i } \" " ) . join ( " " ) )
2014-10-03 10:32:59 +00:00
fs . writeFileSync " public/js/main.js " , content
2014-09-08 16:33:30 +00:00
2014-09-08 13:19:24 +00:00
grunt . registerTask ' compile:server ' , ' Compile the server side coffee script ' , [ ' clean:app ' , ' coffee:app ' , ' coffee:app_dir ' , ' compile:modules:server ' ]
2014-09-08 16:33:30 +00:00
grunt . registerTask ' compile:client ' , ' Compile the client side coffee script ' , [ ' coffee:client ' , ' coffee:sharejs ' , ' wrap_sharejs ' , " compile:modules:client " , ' compile:modules:inject_clientside_includes ' ]
2017-01-18 15:38:18 +00:00
grunt . registerTask ' compile:css ' , ' Compile the less files to css ' , [ ' less ' , ' postcss:dist ' ]
2017-10-24 15:03:59 +00:00
grunt . registerTask ' compile:minify ' , ' Concat and minify the client side js and css ' , [ ' requirejs ' , " file_append " , " exec:cssmin_sl " , " exec:cssmin_ol " ]
2014-02-12 10:23:40 +00:00
grunt . registerTask ' compile:unit_tests ' , ' Compile the unit tests ' , [ ' clean:unit_tests ' , ' coffee:unit_tests ' ]
2016-03-08 15:59:04 +00:00
grunt . registerTask ' compile:acceptance_tests ' , ' Compile the acceptance tests ' , [ ' clean:acceptance_tests ' , ' coffee:acceptance_tests ' ]
2014-02-12 10:23:40 +00:00
grunt . registerTask ' compile:smoke_tests ' , ' Compile the smoke tests ' , [ ' coffee:smoke_tests ' ]
2017-11-20 10:36:48 +00:00
grunt . registerTask ' compile:tests ' , ' Compile all the tests ' , [ ' compile:smoke_tests ' , ' compile:unit_tests ' , ' compile:acceptance_tests ' ]
2014-02-12 10:23:40 +00:00
grunt . registerTask ' compile ' , ' Compiles everything need to run web-sharelatex ' , [ ' compile:server ' , ' compile:client ' , ' compile:css ' ]
2016-06-15 11:08:11 +00:00
grunt . registerTask ' quickcompile:coffee ' , ' Compiles only changed coffee files ' , [ ' newer:coffee ' ]
2014-02-12 10:23:40 +00:00
grunt . registerTask ' install ' , " Compile everything when installing as an npm module " , [ ' compile ' ]
2015-06-16 09:53:18 +00:00
grunt . registerTask ' test:unit ' , ' Run the unit tests (use --grep=<regex> or --feature=<feature> for individual tests) ' , [ ' compile:server ' , ' compile:modules:server ' , ' compile:unit_tests ' , ' compile:modules:unit_tests ' , ' mochaTest:unit ' ] . concat ( moduleUnitTestTasks )
2016-03-08 15:59:04 +00:00
grunt . registerTask ' test:acceptance ' , ' Run the acceptance tests (use --grep=<regex> or --feature=<feature> for individual tests) ' , [ ' compile:acceptance_tests ' , ' mochaTest:acceptance ' ]
2014-02-12 10:23:40 +00:00
grunt . registerTask ' test:smoke ' , ' Run the smoke tests ' , [ ' compile:smoke_tests ' , ' mochaTest:smoke ' ]
2014-09-08 13:19:24 +00:00
2017-09-27 08:37:20 +00:00
grunt . registerTask (
' test:acceptance:full ' ,
" Start server and run acceptance tests " ,
[ ' shell:fullAcceptanceTests ' ]
)
grunt . registerTask (
' test:acceptance:docker ' ,
" Run acceptance tests inside docker container " ,
[ ' compile:acceptance_tests ' , ' shell:dockerTests ' ]
)
2014-09-08 13:19:24 +00:00
grunt . registerTask ' test:modules:unit ' , ' Run the unit tests for the modules ' , [ ' compile:modules:server ' , ' compile:modules:unit_tests ' ] . concat ( moduleUnitTestTasks )
2014-02-12 10:23:40 +00:00
2016-09-21 09:48:23 +00:00
grunt . registerTask ' run:watch ' , " Compile and run the web-sharelatex server " , [ ' compile ' , ' env:run ' , ' parallel ' ]
grunt . registerTask ' run ' , " Compile and run the web-sharelatex server " , [ ' compile ' , ' env:run ' , ' exec ' ]
2016-06-15 11:08:11 +00:00
2014-02-12 10:23:40 +00:00
grunt . registerTask ' default ' , ' run '
2017-01-20 12:03:02 +00:00
grunt . registerTask ' version ' , " Write the version number into sentry.pug " , [ ' git-rev-parse ' , ' sed ' ]
2015-11-18 15:21:48 +00:00