models/helper.js
function (is_ignore_errors) {

		var file_paths = [];

		// root of dependence source directory
		file_paths.push('./commands.json');
		// root of denhub-device directory
		file_paths.push(__dirname + '/../commands.json');

		var file = null;
		for (var i = 0, l = file_paths.length; i < l; i++) {
			try {
				file = require('fs').readFileSync(file_paths[i]);
			} catch (e) {
				continue;
			}
			if (file) break;
		}

		if (!file && !is_ignore_errors) {
			console.log(colors.bold.red('Error: Could not read the commands file.'));
			console.log(file_paths.join('\n'));
			console.log(colors.bold('If you never created it, please try the following command:'));
			console.log('$ denhub-device-generator --init\n');
			process.exit(255);
		}

		var commands = {};
		if (file) {
			try {
				commands = JSON.parse(file);
			} catch (e) {
				if (!is_ignore_errors) throw e;
				commands = null;
			}
		}

		return commands;

	}
function (is_ignore_errors) {

		var file_paths = [];

		// root of dependence source directory
		file_paths.push('./commands.json');
		// root of denhub-device directory
		file_paths.push(__dirname + '/../commands.json');

		var file = null;
		for (var i = 0, l = file_paths.length; i < l; i++) {
			try {
				file = require('fs').readFileSync(file_paths[i]);
			} catch (e) {
				continue;
			}
			if (file) break;
		}

		if (!file && !is_ignore_errors) {
			console.log(colors.bold.red('Error: Could not read the commands file.'));
			console.log(file_paths.join('\n'));
			console.log(colors.bold('If you never created it, please try the following command:'));
			console.log('$ denhub-device-generator --init\n');
			process.exit(255);
		}

		var commands = {};
		if (file) {
			try {
				commands = JSON.parse(file);
			} catch (e) {
				if (!is_ignore_errors) throw e;
				commands = null;
			}
		}

		return commands;

	}
function ( is_ignore_errors ) { var file_paths = [ ] ; // root of dependence source directory file_paths . push ( './commands.json' ) ; // root of denhub-device directory file_paths . push ( __dirname + '/../commands.json' ) ; var file = null ; for ( var i = 0 , l = file_paths . length ; i < l ; i ++ ) { try { file = require ( 'fs' ) . readFileSync ( file_paths [ i ] ) ; } catch ( e ) { continue ; } if ( file ) break ; } if ( ! file && ! is_ignore_errors ) { console . log ( colors . bold . red ( 'Error: Could not read the commands file.' ) ) ; console . log ( file_paths . join ( '\n' ) ) ; console . log ( colors . bold ( 'If you never created it, please try the following command:' ) ) ; console . log ( '$ denhub-device-generator --init\n' ) ; process . exit ( 255 ) ; } var commands = { } ; if ( file ) { try { commands = JSON . parse ( file ) ; } catch ( e ) { if ( ! is_ignore_errors ) throw e ; commands = null ; } } return commands ; }
Read the user's commands definition
@return {Object} Commands definition
Read the user s commands definition