2019-11-19 06:04:42 -05:00
|
|
|
const logger = require('logger-sharelatex')
|
|
|
|
const pug = require('pug')
|
2019-11-26 05:02:06 -05:00
|
|
|
const globby = require('globby')
|
2020-06-26 05:48:18 -04:00
|
|
|
const Settings = require('settings-sharelatex')
|
2019-11-19 06:04:42 -05:00
|
|
|
|
2019-11-26 05:02:06 -05:00
|
|
|
// Generate list of view names from app/views
|
|
|
|
|
|
|
|
const viewList = globby
|
2020-05-22 07:15:45 -04:00
|
|
|
.sync('app/views/**/*.pug', {
|
2019-11-26 05:02:06 -05:00
|
|
|
onlyFiles: true,
|
|
|
|
concurrency: 1,
|
2020-05-22 07:15:45 -04:00
|
|
|
ignore: '**/_*.pug'
|
2019-11-26 05:02:06 -05:00
|
|
|
})
|
2020-05-22 07:15:45 -04:00
|
|
|
.concat(
|
|
|
|
globby.sync('modules/*/app/views/**/*.pug', {
|
|
|
|
onlyFiles: true,
|
|
|
|
concurrency: 1,
|
|
|
|
ignore: '**/_*.pug'
|
|
|
|
})
|
|
|
|
)
|
2019-11-26 05:02:06 -05:00
|
|
|
.map(x => {
|
|
|
|
return x.replace(/\.pug$/, '') // strip trailing .pug extension
|
|
|
|
})
|
|
|
|
.filter(x => {
|
|
|
|
return !/^_/.test(x)
|
|
|
|
})
|
2019-11-19 06:04:42 -05:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
precompileViews(app) {
|
|
|
|
let startTime = Date.now()
|
|
|
|
let success = 0
|
|
|
|
let failures = 0
|
|
|
|
viewList.forEach(view => {
|
|
|
|
try {
|
2020-05-22 07:15:45 -04:00
|
|
|
let filename = view + '.pug'
|
2020-06-26 05:48:18 -04:00
|
|
|
pug.compileFile(filename, {
|
|
|
|
cache: true,
|
|
|
|
compileDebug: Settings.debugPugTemplates
|
|
|
|
})
|
2019-11-19 06:59:59 -05:00
|
|
|
logger.log({ view }, 'compiled')
|
2019-11-19 06:04:42 -05:00
|
|
|
success++
|
|
|
|
} catch (err) {
|
2019-11-26 05:02:06 -05:00
|
|
|
logger.error({ view, err: err.message }, 'error compiling')
|
2019-11-19 06:04:42 -05:00
|
|
|
failures++
|
|
|
|
}
|
|
|
|
})
|
|
|
|
logger.log(
|
|
|
|
{ timeTaken: Date.now() - startTime, failures, success },
|
|
|
|
'compiled templates'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|