.
This commit is contained in:
		
							
								
								
									
										89
									
								
								qwen/nodejs/node_modules/nodemon/lib/rules/add.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								qwen/nodejs/node_modules/nodemon/lib/rules/add.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,89 @@
 | 
			
		||||
'use strict';
 | 
			
		||||
 | 
			
		||||
var utils = require('../utils');
 | 
			
		||||
 | 
			
		||||
// internal
 | 
			
		||||
var reEscComments = /\\#/g;
 | 
			
		||||
// note that '^^' is used in place of escaped comments
 | 
			
		||||
var reUnescapeComments = /\^\^/g;
 | 
			
		||||
var reComments = /#.*$/;
 | 
			
		||||
var reEscapeChars = /[.|\-[\]()\\]/g;
 | 
			
		||||
var reAsterisk = /\*/g;
 | 
			
		||||
 | 
			
		||||
module.exports = add;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Converts file patterns or regular expressions to nodemon
 | 
			
		||||
 * compatible RegExp matching rules. Note: the `rules` argument
 | 
			
		||||
 * object is modified to include the new rule and new RegExp
 | 
			
		||||
 *
 | 
			
		||||
 * ### Example:
 | 
			
		||||
 *
 | 
			
		||||
 *     var rules = { watch: [], ignore: [] };
 | 
			
		||||
 *     add(rules, 'watch', '*.js');
 | 
			
		||||
 *     add(rules, 'ignore', '/public/');
 | 
			
		||||
 *     add(rules, 'watch', ':(\d)*\.js'); // note: string based regexp
 | 
			
		||||
 *     add(rules, 'watch', /\d*\.js/);
 | 
			
		||||
 *
 | 
			
		||||
 * @param {Object} rules containing `watch` and `ignore`. Also updated during
 | 
			
		||||
 *                       execution
 | 
			
		||||
 * @param {String} which must be either "watch" or "ignore"
 | 
			
		||||
 * @param {String|RegExp} rule the actual rule.
 | 
			
		||||
 */
 | 
			
		||||
function add(rules, which, rule) {
 | 
			
		||||
  if (!{ ignore: 1, watch: 1}[which]) {
 | 
			
		||||
    throw new Error('rules/index.js#add requires "ignore" or "watch" as the ' +
 | 
			
		||||
      'first argument');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (Array.isArray(rule)) {
 | 
			
		||||
    rule.forEach(function (rule) {
 | 
			
		||||
      add(rules, which, rule);
 | 
			
		||||
    });
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // support the rule being a RegExp, but reformat it to
 | 
			
		||||
  // the custom :<regexp> format that we're working with.
 | 
			
		||||
  if (rule instanceof RegExp) {
 | 
			
		||||
    // rule = ':' + rule.toString().replace(/^\/(.*?)\/$/g, '$1');
 | 
			
		||||
    utils.log.error('RegExp format no longer supported, but globs are.');
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // remove comments and trim lines
 | 
			
		||||
  // this mess of replace methods is escaping "\#" to allow for emacs temp files
 | 
			
		||||
 | 
			
		||||
  // first up strip comments and remove blank head or tails
 | 
			
		||||
  rule = (rule || '').replace(reEscComments, '^^')
 | 
			
		||||
             .replace(reComments, '')
 | 
			
		||||
             .replace(reUnescapeComments, '#').trim();
 | 
			
		||||
 | 
			
		||||
  var regexp = false;
 | 
			
		||||
 | 
			
		||||
  if (typeof rule === 'string' && rule.substring(0, 1) === ':') {
 | 
			
		||||
    rule = rule.substring(1);
 | 
			
		||||
    utils.log.error('RegExp no longer supported: ' + rule);
 | 
			
		||||
    regexp = true;
 | 
			
		||||
  } else if (rule.length === 0) {
 | 
			
		||||
    // blank line (or it was a comment)
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (regexp) {
 | 
			
		||||
    // rules[which].push(rule);
 | 
			
		||||
  } else {
 | 
			
		||||
    // rule = rule.replace(reEscapeChars, '\\$&')
 | 
			
		||||
    // .replace(reAsterisk, '.*');
 | 
			
		||||
 | 
			
		||||
    rules[which].push(rule);
 | 
			
		||||
    // compile a regexp of all the rules for this ignore or watch
 | 
			
		||||
    var re = rules[which].map(function (rule) {
 | 
			
		||||
      return rule.replace(reEscapeChars, '\\$&')
 | 
			
		||||
                 .replace(reAsterisk, '.*');
 | 
			
		||||
    }).join('|');
 | 
			
		||||
 | 
			
		||||
    // used for the directory matching
 | 
			
		||||
    rules[which].re = new RegExp(re);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										53
									
								
								qwen/nodejs/node_modules/nodemon/lib/rules/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								qwen/nodejs/node_modules/nodemon/lib/rules/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
			
		||||
'use strict';
 | 
			
		||||
var utils = require('../utils');
 | 
			
		||||
var add = require('./add');
 | 
			
		||||
var parse = require('./parse');
 | 
			
		||||
 | 
			
		||||
// exported
 | 
			
		||||
var rules = { ignore: [], watch: [] };
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Loads a nodemon config file and populates the ignore
 | 
			
		||||
 * and watch rules with it's contents, and calls callback
 | 
			
		||||
 * with the new rules
 | 
			
		||||
 *
 | 
			
		||||
 * @param  {String} filename
 | 
			
		||||
 * @param  {Function} callback
 | 
			
		||||
 */
 | 
			
		||||
function load(filename, callback) {
 | 
			
		||||
  parse(filename, function (err, result) {
 | 
			
		||||
    if (err) {
 | 
			
		||||
      // we should have bombed already, but
 | 
			
		||||
      utils.log.error(err);
 | 
			
		||||
      callback(err);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (result.raw) {
 | 
			
		||||
      result.raw.forEach(add.bind(null, rules, 'ignore'));
 | 
			
		||||
    } else {
 | 
			
		||||
      result.ignore.forEach(add.bind(null, rules, 'ignore'));
 | 
			
		||||
      result.watch.forEach(add.bind(null, rules, 'watch'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    callback(null, rules);
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
  reset: function () { // just used for testing
 | 
			
		||||
    rules.ignore.length = rules.watch.length = 0;
 | 
			
		||||
    delete rules.ignore.re;
 | 
			
		||||
    delete rules.watch.re;
 | 
			
		||||
  },
 | 
			
		||||
  load: load,
 | 
			
		||||
  ignore: {
 | 
			
		||||
    test: add.bind(null, rules, 'ignore'),
 | 
			
		||||
    add: add.bind(null, rules, 'ignore'),
 | 
			
		||||
  },
 | 
			
		||||
  watch: {
 | 
			
		||||
    test: add.bind(null, rules, 'watch'),
 | 
			
		||||
    add: add.bind(null, rules, 'watch'),
 | 
			
		||||
  },
 | 
			
		||||
  add: add.bind(null, rules),
 | 
			
		||||
  rules: rules,
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										43
									
								
								qwen/nodejs/node_modules/nodemon/lib/rules/parse.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								qwen/nodejs/node_modules/nodemon/lib/rules/parse.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
'use strict';
 | 
			
		||||
var fs = require('fs');
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Parse the nodemon config file, supporting both old style
 | 
			
		||||
 * plain text config file, and JSON version of the config
 | 
			
		||||
 *
 | 
			
		||||
 * @param  {String}   filename
 | 
			
		||||
 * @param  {Function} callback
 | 
			
		||||
 */
 | 
			
		||||
function parse(filename, callback) {
 | 
			
		||||
  var rules = {
 | 
			
		||||
    ignore: [],
 | 
			
		||||
    watch: [],
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  fs.readFile(filename, 'utf8', function (err, content) {
 | 
			
		||||
 | 
			
		||||
    if (err) {
 | 
			
		||||
      return callback(err);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var json = null;
 | 
			
		||||
    try {
 | 
			
		||||
      json = JSON.parse(content);
 | 
			
		||||
    } catch (e) {}
 | 
			
		||||
 | 
			
		||||
    if (json !== null) {
 | 
			
		||||
      rules = {
 | 
			
		||||
        ignore: json.ignore || [],
 | 
			
		||||
        watch: json.watch || [],
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      return callback(null, rules);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // otherwise return the raw file
 | 
			
		||||
    return callback(null, { raw: content.split(/\n/) });
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = parse;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user