Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install & Run StandardJs Static Tool Analysis #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
380 changes: 190 additions & 190 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,201 +1,201 @@
'use strict';
'use strict'

Check failure on line 1 in Gruntfile.js

View workflow job for this annotation

GitHub Actions / test

Missing semicolon

const path = require('path');
const nconf = require('nconf');
const path = require('path')

Check failure on line 3 in Gruntfile.js

View workflow job for this annotation

GitHub Actions / test

Missing semicolon
const nconf = require('nconf')

Check failure on line 4 in Gruntfile.js

View workflow job for this annotation

GitHub Actions / test

Missing semicolon

nconf.argv().env({
separator: '__',
});
const winston = require('winston');
const { fork } = require('child_process');
separator: '__'

Check failure on line 7 in Gruntfile.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 1 tab but found 2 spaces

Check failure on line 7 in Gruntfile.js

View workflow job for this annotation

GitHub Actions / test

Missing trailing comma
})

Check failure on line 8 in Gruntfile.js

View workflow job for this annotation

GitHub Actions / test

Missing semicolon
const winston = require('winston')

Check failure on line 9 in Gruntfile.js

View workflow job for this annotation

GitHub Actions / test

Missing semicolon
const { fork } = require('child_process')

Check failure on line 10 in Gruntfile.js

View workflow job for this annotation

GitHub Actions / test

Missing semicolon

const { env } = process;
let worker;
const { env } = process

Check failure on line 12 in Gruntfile.js

View workflow job for this annotation

GitHub Actions / test

Missing semicolon
let worker

Check failure on line 13 in Gruntfile.js

View workflow job for this annotation

GitHub Actions / test

Missing semicolon

env.NODE_ENV = env.NODE_ENV || 'development';
env.NODE_ENV = env.NODE_ENV || 'development'

const configFile = path.resolve(__dirname, nconf.any(['config', 'CONFIG']) || 'config.json');
const prestart = require('./src/prestart');
const configFile = path.resolve(__dirname, nconf.any(['config', 'CONFIG']) || 'config.json')
const prestart = require('./src/prestart')

prestart.loadConfig(configFile);
prestart.loadConfig(configFile)

const db = require('./src/database');
const plugins = require('./src/plugins');
const db = require('./src/database')
const plugins = require('./src/plugins')

module.exports = function (grunt) {
const args = [];

if (!grunt.option('verbose')) {
args.push('--log-level=info');
nconf.set('log-level', 'info');
}
prestart.setupWinston();

grunt.initConfig({
watch: {},
});

grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('default', ['watch']);

grunt.registerTask('init', async function () {
const done = this.async();
let pluginList = [];
if (!process.argv.includes('--core')) {
await db.init();
pluginList = await plugins.getActive();
addBaseThemes(pluginList);
if (!pluginList.includes('nodebb-plugin-composer-default')) {
pluginList.push('nodebb-plugin-composer-default');
}
if (!pluginList.includes('nodebb-theme-harmony')) {
pluginList.push('nodebb-theme-harmony');
}
}

const styleUpdated_Client = pluginList.map(p => `node_modules/${p}/*.scss`)
.concat(pluginList.map(p => `node_modules/${p}/*.css`))
.concat(pluginList.map(p => `node_modules/${p}/+(public|static|scss)/**/*.scss`))
.concat(pluginList.map(p => `node_modules/${p}/+(public|static)/**/*.css`));

const clientUpdated = pluginList.map(p => `node_modules/${p}/+(public|static)/**/*.js`);
const serverUpdated = pluginList.map(p => `node_modules/${p}/*.js`)
.concat(pluginList.map(p => `node_modules/${p}/+(lib|src)/**/*.js`));

const templatesUpdated = pluginList.map(p => `node_modules/${p}/+(public|static|templates)/**/*.tpl`);
const langUpdated = pluginList.map(p => `node_modules/${p}/+(public|static|languages)/**/*.json`);
const interval = 100;
grunt.config(['watch'], {
styleUpdated: {
files: [
'public/scss/**/*.scss',
...styleUpdated_Client,
],
options: {
interval: interval,
},
},
clientUpdated: {
files: [
'public/src/**/*.js',
'public/vendor/**/*.js',
...clientUpdated,
'node_modules/benchpressjs/build/benchpress.js',
],
options: {
interval: interval,
},
},
serverUpdated: {
files: [
'app.js',
'install/*.js',
'src/**/*.js',
'public/src/modules/translator.common.js',
'public/src/modules/helpers.common.js',
'public/src/utils.common.js',
serverUpdated,
'!src/upgrades/**',
],
options: {
interval: interval,
},
},
templatesUpdated: {
files: [
'src/views/**/*.tpl',
...templatesUpdated,
],
options: {
interval: interval,
},
},
langUpdated: {
files: [
'public/language/en-GB/*.json',
'public/language/en-GB/**/*.json',
...langUpdated,
],
options: {
interval: interval,
},
},
});
const build = require('./src/meta/build');
if (!grunt.option('skip')) {
await build.build(true, { watch: true });
}
run();
done();
});

function run() {
if (worker) {
worker.kill();
}

const execArgv = [];
const inspect = process.argv.find(a => a.startsWith('--inspect'));

if (inspect) {
execArgv.push(inspect);
}

worker = fork('app.js', args, {
env,
execArgv,
});
}

grunt.task.run('init');

grunt.event.removeAllListeners('watch');
grunt.event.on('watch', (action, filepath, target) => {
let compiling;
if (target === 'styleUpdated') {
compiling = ['clientCSS', 'acpCSS'];
} else if (target === 'clientUpdated') {
compiling = ['js'];
} else if (target === 'templatesUpdated') {
compiling = ['tpl'];
} else if (target === 'langUpdated') {
compiling = ['lang'];
} else if (target === 'serverUpdated') {
// empty require cache
const paths = ['./src/meta/build.js', './src/meta/index.js'];
paths.forEach(p => delete require.cache[require.resolve(p)]);
return run();
}

require('./src/meta/build').build(compiling, { webpack: false }, (err) => {
if (err) {
winston.error(err.stack);
}
if (worker) {
worker.send({ compiling: compiling });
}
});
});
};

function addBaseThemes(pluginList) {
let themeId = pluginList.find(p => p.includes('nodebb-theme-'));
if (!themeId) {
return pluginList;
}
let baseTheme;
do {
try {
baseTheme = require(`${themeId}/theme`).baseTheme;
} catch (err) {
console.log(err);
}

if (baseTheme) {
pluginList.push(baseTheme);
themeId = baseTheme;
}
} while (baseTheme);
return pluginList;
const args = []

if (!grunt.option('verbose')) {
args.push('--log-level=info')
nconf.set('log-level', 'info')
}
prestart.setupWinston()

grunt.initConfig({
watch: {}
})

grunt.loadNpmTasks('grunt-contrib-watch')

grunt.registerTask('default', ['watch'])

grunt.registerTask('init', async function () {
const done = this.async()
let pluginList = []
if (!process.argv.includes('--core')) {
await db.init()
pluginList = await plugins.getActive()
addBaseThemes(pluginList)
if (!pluginList.includes('nodebb-plugin-composer-default')) {
pluginList.push('nodebb-plugin-composer-default')
}
if (!pluginList.includes('nodebb-theme-harmony')) {
pluginList.push('nodebb-theme-harmony')
}
}

const styleUpdated_Client = pluginList.map(p => `node_modules/${p}/*.scss`)
.concat(pluginList.map(p => `node_modules/${p}/*.css`))
.concat(pluginList.map(p => `node_modules/${p}/+(public|static|scss)/**/*.scss`))
.concat(pluginList.map(p => `node_modules/${p}/+(public|static)/**/*.css`))

const clientUpdated = pluginList.map(p => `node_modules/${p}/+(public|static)/**/*.js`)
const serverUpdated = pluginList.map(p => `node_modules/${p}/*.js`)
.concat(pluginList.map(p => `node_modules/${p}/+(lib|src)/**/*.js`))

const templatesUpdated = pluginList.map(p => `node_modules/${p}/+(public|static|templates)/**/*.tpl`)
const langUpdated = pluginList.map(p => `node_modules/${p}/+(public|static|languages)/**/*.json`)
const interval = 100
grunt.config(['watch'], {
styleUpdated: {
files: [
'public/scss/**/*.scss',
...styleUpdated_Client
],
options: {
interval
}
},
clientUpdated: {
files: [
'public/src/**/*.js',
'public/vendor/**/*.js',
...clientUpdated,
'node_modules/benchpressjs/build/benchpress.js'
],
options: {
interval
}
},
serverUpdated: {
files: [
'app.js',
'install/*.js',
'src/**/*.js',
'public/src/modules/translator.common.js',
'public/src/modules/helpers.common.js',
'public/src/utils.common.js',
serverUpdated,
'!src/upgrades/**'
],
options: {
interval
}
},
templatesUpdated: {
files: [
'src/views/**/*.tpl',
...templatesUpdated
],
options: {
interval
}
},
langUpdated: {
files: [
'public/language/en-GB/*.json',
'public/language/en-GB/**/*.json',
...langUpdated
],
options: {
interval
}
}
})
const build = require('./src/meta/build')
if (!grunt.option('skip')) {
await build.build(true, { watch: true })
}
run()
done()
})

function run () {
if (worker) {
worker.kill()
}

const execArgv = []
const inspect = process.argv.find(a => a.startsWith('--inspect'))

if (inspect) {
execArgv.push(inspect)
}

worker = fork('app.js', args, {
env,
execArgv
})
}

grunt.task.run('init')

grunt.event.removeAllListeners('watch')
grunt.event.on('watch', (action, filepath, target) => {
let compiling
if (target === 'styleUpdated') {
compiling = ['clientCSS', 'acpCSS']
} else if (target === 'clientUpdated') {
compiling = ['js']
} else if (target === 'templatesUpdated') {
compiling = ['tpl']
} else if (target === 'langUpdated') {
compiling = ['lang']
} else if (target === 'serverUpdated') {
// empty require cache
const paths = ['./src/meta/build.js', './src/meta/index.js']
paths.forEach(p => delete require.cache[require.resolve(p)])
return run()
}

require('./src/meta/build').build(compiling, { webpack: false }, (err) => {
if (err) {
winston.error(err.stack)
}
if (worker) {
worker.send({ compiling })
}
})
})
}

function addBaseThemes (pluginList) {
let themeId = pluginList.find(p => p.includes('nodebb-theme-'))
if (!themeId) {
return pluginList
}
let baseTheme
do {
try {
baseTheme = require(`${themeId}/theme`).baseTheme
} catch (err) {
console.log(err)
}

if (baseTheme) {
pluginList.push(baseTheme)
themeId = baseTheme
}
} while (baseTheme)
return pluginList
}
Loading