@ -1,5 +1,7 @@
'use strict' ;
var async = require ( 'async' ) ;
var fork = require ( 'child_process' ) . fork ;
var env = process . env ;
var worker ;
@ -10,6 +12,26 @@ var running = 0;
env . NODE _ENV = env . NODE _ENV || 'development' ;
var nconf = require ( 'nconf' ) ;
nconf . file ( {
file : 'config.json' ,
} ) ;
nconf . defaults ( {
base _dir : _ _dirname ,
views _dir : './build/public/templates' ,
} ) ;
var winston = require ( 'winston' ) ;
winston . configure ( {
transports : [
new winston . transports . Console ( {
handleExceptions : true ,
} ) ,
] ,
} ) ;
var db = require ( './src/database' ) ;
module . exports = function ( grunt ) {
var args = [ ] ;
var initArgs = [ '--build' ] ;
@ -70,80 +92,112 @@ module.exports = function (grunt) {
}
grunt . initConfig ( {
watch : {
lessUpdated _Client : {
files : [
'public/less/*.less' ,
'!public/less/admin/**/*.less' ,
'node_modules/nodebb-*/**/*.less' ,
'!node_modules/nodebb-*/node_modules/**' ,
'!node_modules/nodebb-*/.git/**' ,
] ,
options : {
interval : 1000 ,
} ,
} ,
lessUpdated _Admin : {
files : [
'public/less/admin/**/*.less' ,
'node_modules/nodebb-*/**/*.less' ,
'!node_modules/nodebb-*/node_modules/**' ,
'!node_modules/nodebb-*/.git/**' ,
] ,
options : {
interval : 1000 ,
} ,
} ,
clientUpdated : {
files : [
'public/src/**/*.js' ,
'node_modules/nodebb-*/**/*.js' ,
'!node_modules/nodebb-*/node_modules/**' ,
'node_modules/benchpressjs/build/benchpress.js' ,
'!node_modules/nodebb-*/.git/**' ,
] ,
options : {
interval : 1000 ,
} ,
watch : { } ,
} ) ;
grunt . loadNpmTasks ( 'grunt-contrib-watch' ) ;
grunt . registerTask ( 'default' , [ 'watch' ] ) ;
grunt . registerTask ( 'init' , function ( ) {
var done = this . async ( ) ;
async . waterfall ( [
function ( next ) {
db . init ( next ) ;
} ,
serverUpdated : {
files : [ '*.js' , 'install/*.js' , 'src/**/*.js' ] ,
options : {
interval : 1000 ,
} ,
function ( next ) {
db . getSortedSetRange ( 'plugins:active' , 0 , - 1 , next ) ;
} ,
templatesUpdated : {
files : [
'src/views/**/*.tpl' ,
'node_modules/nodebb-*/**/*.tpl' ,
'!node_modules/nodebb-*/node_modules/**' ,
'!node_modules/nodebb-*/.git/**' ,
] ,
options : {
interval : 1000 ,
} ,
function ( plugins , next ) {
addBaseThemes ( plugins , next ) ;
} ,
langUpdated : {
files : [
'public/language/en-GB/*.json' ,
'public/language/en-GB/**/*.json' ,
'node_modules/nodebb-*/**/*.json' ,
'!node_modules/nodebb-*/node_modules/**' ,
'!node_modules/nodebb-*/.git/**' ,
'!node_modules/nodebb-*/plugin.json' ,
'!node_modules/nodebb-*/package.json' ,
'!node_modules/nodebb-*/theme.json' ,
] ,
options : {
interval : 1000 ,
} ,
function ( plugins , next ) {
if ( ! plugins . includes ( 'nodebb-plugin-composer-default' ) ) {
plugins . push ( 'nodebb-plugin-composer-default' ) ;
}
const lessUpdated _Client = plugins . map ( p => 'node_modules/' + p + '/**/*.less' ) ;
const lessUpdated _Admin = plugins . map ( p => 'node_modules/' + p + '/**/*.less' ) ;
const clientUpdated = plugins . map ( p => 'node_modules/' + p + '/**/*.js' ) ;
const templatesUpdated = plugins . map ( p => 'node_modules/' + p + '/**/*.tpl' ) ;
const langUpdated = plugins . map ( p => 'node_modules/' + p + '/**/*.json' ) ;
grunt . config ( [ 'watch' ] , {
lessUpdated _Client : {
files : [
'public/less/*.less' ,
'!public/less/admin/**/*.less' ,
... lessUpdated _Client ,
'!node_modules/nodebb-*/node_modules/**' ,
'!node_modules/nodebb-*/.git/**' ,
] ,
options : {
interval : 1000 ,
} ,
} ,
lessUpdated _Admin : {
files : [
'public/less/admin/**/*.less' ,
... lessUpdated _Admin ,
'!node_modules/nodebb-*/node_modules/**' ,
'!node_modules/nodebb-*/.git/**' ,
] ,
options : {
interval : 1000 ,
} ,
} ,
clientUpdated : {
files : [
'public/src/**/*.js' ,
... clientUpdated ,
'!node_modules/nodebb-*/node_modules/**' ,
'node_modules/benchpressjs/build/benchpress.js' ,
'!node_modules/nodebb-*/.git/**' ,
] ,
options : {
interval : 1000 ,
} ,
} ,
serverUpdated : {
files : [ '*.js' , 'install/*.js' , 'src/**/*.js' , '!src/upgrades/**' ] ,
options : {
interval : 1000 ,
} ,
} ,
templatesUpdated : {
files : [
'src/views/**/*.tpl' ,
... templatesUpdated ,
'!node_modules/nodebb-*/node_modules/**' ,
'!node_modules/nodebb-*/.git/**' ,
] ,
options : {
interval : 1000 ,
} ,
} ,
langUpdated : {
files : [
'public/language/en-GB/*.json' ,
'public/language/en-GB/**/*.json' ,
... langUpdated ,
'!node_modules/nodebb-*/node_modules/**' ,
'!node_modules/nodebb-*/.git/**' ,
'!node_modules/nodebb-*/plugin.json' ,
'!node_modules/nodebb-*/package.json' ,
'!node_modules/nodebb-*/theme.json' ,
] ,
options : {
interval : 1000 ,
} ,
} ,
} ) ;
next ( ) ;
} ,
} ,
], done ) ;
} ) ;
grunt . loadNpmTasks ( 'grunt-contrib-watch' ) ;
grunt . task. run ( 'init ') ;
grunt . registerTask ( 'default' , [ 'watch' ] ) ;
env . NODE _ENV = 'development' ;
if ( grunt . option ( 'skip' ) ) {
@ -164,3 +218,25 @@ module.exports = function (grunt) {
grunt . event . on ( 'watch' , update ) ;
} ;
function addBaseThemes ( plugins , callback ) {
const themeId = plugins . find ( p => p . startsWith ( 'nodebb-theme-' ) ) ;
if ( ! themeId ) {
return setImmediate ( callback , null , plugins ) ;
}
function getBaseRecursive ( themeId ) {
try {
const baseTheme = require ( themeId + '/theme' ) . baseTheme ;
if ( baseTheme ) {
plugins . push ( baseTheme ) ;
getBaseRecursive ( baseTheme ) ;
}
} catch ( err ) {
console . log ( err ) ;
}
}
getBaseRecursive ( themeId ) ;
callback ( null , plugins ) ;
}