function Babel(inputTree, _options) {
  if (!(this instanceof Babel)) {
    return new Babel(inputTree, _options);
  }

  var options = _options || {};
  options.persist = !options.exportModuleMetadata; // TODO: make this also work in cache
  Filter.call(this, inputTree, options);

  delete options.persist;
  this.options = options;
  this.moduleMetadata = {};
  this.extensions = this.options.filterExtensions || ['js'];
  this.extensionsRegex = getExtensionsRegex(this.extensions);
  this.name = 'broccoli-babel-transpiler';

  if (this.options.exportModuleMetadata) {
    this.exportModuleMetadata = this.options.exportModuleMetadata;
  }
  // Note, Babel does not support this option so we must save it then
  // delete it from the options hash
  delete this.options.exportModuleMetadata;

  if (this.options.browserPolyfill) {
    var babelCorePath = require.resolve('babel-core');
    babelCorePath = babelCorePath.replace(/\/babel-core\/.*$/, '/babel-core');

    var polyfill = funnel(babelCorePath, { files: ['browser-polyfill.js'] });
    this.inputTree = mergeTrees([polyfill, inputTree]);
  } else {
    this.inputTree = inputTree;
  }
  delete this.options.browserPolyfill;
}
function PodStyles(inputTree, options) {
  options = options || {};
  Filter.call(this, inputTree, {
    annotation: options.annotation
  });
  this.extensions = options.extensions;
}
Пример #3
0
function TSLint(inputNode, options) {
  if (!(this instanceof TSLint)) {
    return new TSLint(inputNode, options);
  }
  options = options || {};

  this.options = {
    outputFile: options.outputFile,
    failBuild: options.failBuild || false,
    disableTestGenerator: options.disableTestGenerator || false,
    testGenerator: options.testGenerator || null,
    logError: options.logError
  };

  this.tslintConfigPath = 'tslint.json';
  if (options.configuration) {
    this.tslintConfigPath = options.configuration;
  } else {
    console.log(this.createLogMessage('Using tslint.json as the default file for linting rules', 'blue'));
  }

  if (!existsSync(this.tslintConfigPath)) {
    throw new Error('Cannot find tslint configuration file: ' + tslintConfigPath);
  }

  if (!options.formatter) {
    // default formatter
    this.options.formatter = 'prose';
  }

  Filter.call(this, inputNode, {
    annotation: options.annotation
  });
}
function TemplateLinter(inputNode, _options) {
  if (!(this instanceof TemplateLinter)) { return new TemplateLinter(inputNode, _options); }

  let options = _options || {};
  if (!options.hasOwnProperty('persist')) {
    options.persist = true;
  }

  Filter.call(this, inputNode, {
    annotation: options.annotation,
    persist: options.persist
  });


  this.options = options;
  this._console = this.options.console || console;
  this._templatercConfig = undefined;

  if (this.options.testGenerator) {
    let testGenerator = testGenerators[this.options.testGenerator];
    if (!testGenerator) {
      throw new Error(`No test generator found for "testGenerator: ${this.options.testGenerator}"`);
    }

    this._testGenerator = testGenerator;
  }

  this.linter = new Linter(options);

  debug('Linter config: %s', JSON.stringify(this.linter.config));

  this.issueLocalizationWarningIfNeeded();
}
function CompileFeaturesJSON(inputNode, options) {
  Filter.call(this, inputNode, {
    annotation: options.annotation,
    persist: true
  });
  this.isDevelopment = options.environment !== 'production';
}
Пример #6
0
function Babel(inputTree, _options) {
  if (!(this instanceof Babel)) {
    return new Babel(inputTree, _options);
  }

  let options = _options || {};
  options.persist = 'persist' in options ? options.persist : true;
  options.async = true;

  if (options.browserPolyfill) {
    let polyfillPath = require.resolve('@babel/polyfill/package.json');
    polyfillPath = path.join(path.dirname(polyfillPath), "dist");

    let browserPolyfillPath = options.browserPolyfillPath || "browser-polyfill.js"
    let polyfill = funnel(polyfillPath, {
      files: ['polyfill.js'],
      getDestinationPath: () => browserPolyfillPath
    });
    inputTree = mergeTrees([polyfill, inputTree]);
  }
  delete options.browserPolyfill;
  delete options.browserPolyfillPath;

  Filter.call(this, inputTree, options);

  delete options.persist;
  delete options.async;
  delete options.annotation;
  delete options.description;

  this.console = options.console || console;
  this.throwUnlessParallelizable = options.throwUnlessParallelizable;

  delete options.console;
  delete options.throwUnlessParallelizable;

  this.options = options;
  this.extensions = this.options.filterExtensions || ['js'];
  this.extensionsRegex = getExtensionsRegex(this.extensions);
  this.name = 'broccoli-babel-transpiler';

  if (this.options.helperWhiteList) {
    this.helperWhiteList = this.options.helperWhiteList;
  }

  // Note, Babel does not support this option so we must save it then
  // delete it from the options hash
  delete this.options.helperWhiteList;

  let result = transformIsParallelizable(options);
  let isParallelizable = result.isParallelizable;
  let errors = result.errors;

  if ((this.throwUnlessParallelizable || process.env.THROW_UNLESS_PARALLELIZABLE) && isParallelizable === false) {
    throw new Error(this.toString() +
      ' was configured to `throwUnlessParallelizable` and was unable to parallelize a plugin. \nplugins:\n' + joinCount(errors) + '\nPlease see: https://github.com/babel/broccoli-babel-transpiler#parallel-transpilation for more details');
  }
}
Пример #7
0
function PodStyles(inputTree, options) {
  options = options || {};
  Filter.call(this, inputTree, {
    annotation: options.annotation
  });
  this.extensions = options.extensions;
  this.classicStyleDir = options.classicStyleDir;
  this.terseClassNames = options.terseClassNames;
}
Пример #8
0
function UseStrictRemover (inputTree, _options) {
  if (!(this instanceof UseStrictRemover)) {
    return new UseStrictRemover(inputTree, _options);
  }

  var options = _options || {};
  if (!options.hasOwnProperty('persist')) {
    options.persist = true;
  }
  Filter.call(this, inputTree, options);

  var matcher = options.matcher || /REMOVE_USE_STRICT: true/g;

  delete options.matcher;
  Filter.call(this, inputTree, options);

  this.matcher = matcher;
}
function GlimmerTemplatePrecompiler (inputTree) {
  if (!(this instanceof GlimmerTemplatePrecompiler)) {
    return new GlimmerTemplatePrecompiler(inputTree);
  }

  Filter.call(this, inputTree, {});

  this.inputTree = inputTree;
}
Пример #10
0
function ReplaceFilter (inputTree, options) {
  if (!(this instanceof ReplaceFilter)) {
    return new ReplaceFilter(inputTree, options);
  }
  Filter.call(this, inputTree, options);
  this.inputTree = inputTree;
  this.options = options || {};
  this.files = this.options.files;
  this.applause = Applause.create(options);
}
function UseStrictRemover (inputTree, _options) {
  if (!(this instanceof UseStrictRemover)) {
    return new UseStrictRemover(inputTree, _options);
  }

  var options = _options || {};
  if (!options.hasOwnProperty('persist')) {
    options.persist = true;
  }
  Filter.call(this, inputTree, options);
}
function EmberTemplatePrecompiler (inputTree, options) {
  if (!(this instanceof EmberTemplatePrecompiler)) {
    return new EmberTemplatePrecompiler(inputTree, options);
  }

  options = options || {};
  Filter.call(this, inputTree, options);

  this.inputTree = inputTree;
  this.htmlbarsCompiler = options.htmlbars.compileSpec;
}
Пример #13
0
function JSTFilter(inputTree, options) {
  if (!(this instanceof JSTFilter)) return new JSTFilter(inputTree, options);
  Filter.call(this, inputTree, options);
  this.inputTree = inputTree;
  this.options = options || {};
  this.extensions = options.extensions || DEFAULTS.extensions;
  this.namespace = options.namespace || DEFAULTS.namespace;
  this.templatesRoot = options.templatesRoot || DEFAULTS.templatesRoot;
  this.templateSettings = options.templateSettings || DEFAULTS.templateSettings;
  this.amd = options.amd || DEFAULTS.amd;
  // this.compileFunction = options.compileFunction || '';
}
function GlimmerTemplatePrecompiler (inputTree, options) {
  if (!(this instanceof GlimmerTemplatePrecompiler)) {
    return new GlimmerTemplatePrecompiler(inputTree, options);
  }

  Filter.call(this, inputTree, {});

  this.inputTree = inputTree;
  if (!options.glimmer) {
    throw new Error('No glimmer option provided!');
  }
  this.precompile = options.glimmer.precompile;
}
Пример #15
0
function DustLint(inputTree, _options) {
  if (!(this instanceof DustLint)) {
    return new DustLint(inputTree, _options);
  }
  this.throwOnError = !!_options.throwOnError;
  this.formatter = typeof _options.formatter === 'function' ? _options.formatter : this._formatter;
  this.rules = _options.rules || [];

  var options = _options || {
  };

  Filter.call(this, inputTree, options);
  this.name = 'broccoli-swiffer';
}
Пример #16
0
/**
 * maps files, allow for simple content mutation
 *
 * @example
 *
 * var map = require('broccoli-stew').map;
 *
 * dist = map('lib', function(content, relativePath) {
 *   return 'new content';
 * });
 *
 * dist = map('lib', function(content, relativePath) {
 *   return 'prepend' + content;
 * });
 *
 * dist = map('lib', function(content, relativePath) {
 *   return mutateSomehow(content);
 * });
 *
 * dist = map('lib', '*.js', function(content, relativePath) {
 *   // mutate only files that match *.js
 *   // leave the rest alone
 *   return mutateSomehow(content);
 * });
 *
 */
function Mapper(inputTree, _filter, _fn) {
  if (!(this instanceof Mapper)) {
    return new Mapper(inputTree, _filter, _fn);
  }
  Filter.call(this, inputTree);

  if (typeof _filter === 'function') {
    this.fn = _filter;
    this.filter = false;
  } else {
    this.filter = _filter;
    this.fn = _fn;
  }

  this._matches = Object.create(null);

}
Пример #17
0
function Babel(inputTree, _options) {
  if (!(this instanceof Babel)) {
    return new Babel(inputTree, _options);
  }

  let options = _options || {};
  options.persist = 'persist' in options ? options.persist : true;
  options.async = true;
  Filter.call(this, inputTree, options);

  delete options.persist;
  delete options.async;
  delete options.annotation;
  delete options.description;

  this.console = options.console || console;
  this.throwUnlessParallelizable = options.throwUnlessParallelizable;

  delete options.console;
  delete options.throwUnlessParallelizable;

  this.options = options;
  this.extensions = this.options.filterExtensions || ['js'];
  this.extensionsRegex = getExtensionsRegex(this.extensions);
  this.name = 'broccoli-babel-transpiler';

  if (this.options.helperWhiteList) {
    this.helperWhiteList = this.options.helperWhiteList;
  }

  // Note, Babel does not support this option so we must save it then
  // delete it from the options hash
  delete this.options.helperWhiteList;

  if (this.options.browserPolyfill) {
    let babelCorePath = require.resolve('babel-core');
    babelCorePath = babelCorePath.replace(/\/babel-core\/.*$/, '/babel-core');

    let polyfill = funnel(babelCorePath, { files: ['browser-polyfill.js'] });
    this.inputTree = mergeTrees([polyfill, inputTree]);
  } else {
    this.inputTree = inputTree;
  }
  delete this.options.browserPolyfill;
}
Пример #18
0
function TemplateCompiler (inputTree, _options) {
  if (!(this instanceof TemplateCompiler)) {
    return new TemplateCompiler(inputTree, _options);
  }

  var options = _options || {};
  if (!options.hasOwnProperty('persist')) {
    options.persist = true;
  }

  Filter.call(this, inputTree, options); // this._super()

  this.options = options || {};
  this.inputTree = inputTree;

  this.precompile = this.options.templateCompiler.precompile;
  this.registerPlugin = this.options.templateCompiler.registerPlugin;

  this.registerPlugins();
  this.initializeFeatures();
}
Пример #19
0
function JSHinter (inputNode, options) {
  if (!(this instanceof JSHinter)) return new JSHinter(inputNode, options);

  options = options || {};
  if (!options.hasOwnProperty('persist')) {
    options.persist = true;
  }

  Filter.call(this, inputNode, {
    annotation: options.annotation,
    persist: options.persist
  });
  this.log     = true;
  this.options = options;
  this.console = console;

  for (var key in options) {
    if (options.hasOwnProperty(key)) {
      this[key] = options[key]
    }
  }
};
function TemplateLinter(inputNode, _options) {
  if (!(this instanceof TemplateLinter)) { return new TemplateLinter(inputNode, _options); }

  var options = _options || {};
  if (!options.hasOwnProperty('persist')) {
    options.persist = true;
  }

  Filter.call(this, inputNode, {
    annotation: options.annotation,
    persist: options.persist
  });


  this.options = options;
  this._console = this.options.console || console;
  this._templatercConfig = undefined;
  this._astPlugins = undefined;
  this._generateTestFile = this.options.generateTestFile || function() {
    return '';
  };
}
Пример #21
0
function SassLinter(inputTree, options) {
  if (!(this instanceof SassLinter)) {
    return new SassLinter(inputTree, options);
  }

  options = options || {};

  Filter.call(this, inputTree, options);

  this.inputTree = inputTree;

  /* Set passed options */

  for (var key in options) {
    if (options.hasOwnProperty(key)) {
      this[key] = options[key]
    }
  }

  if (!this.disableTestGenerator) {
    // If we are generating tests, the extension of the test files
    this.targetExtension = 'sass-lint-test.js';
  }
};
function CoffeeScriptLinter (inputTree, options) {
  if (!(this instanceof CoffeeScriptLinter)) return new CoffeeScriptLinter(inputTree, options);
  options = options || {};
  // options.persist = true;
  Filter.call(this, inputTree, options);
  this.options = options;
  this.coffeelintJSON = null;
  this.coffeelintignore = null;
  this.formatter = function(filePath, lintResults){
    if(lintResults.length){
      console.log("\n\n==========================================");
      console.log(chalk.yellow("File: "+filePath));
      console.log("==========================================");
      lintResults.forEach(function(error, index){
        if(index != 0){
          console.log("");
        }
        errorColor = chalk.black;
        if(error.level == "error") {
          errorColor = chalk.bgRed.white
        } else if(error.level == "warn") {
          errorColor = chalk.bgYellow.black
        }
        console.log(errorColor(" " + error.message + " (" + error.level + ") "));
        console.log("Line:  "+error.lineNumber);
      });
    }
  };

  this.statsFormatter = function(stats){
    var color = chalk.black.bgGreen;
    if(stats.errorCount > 0){
      color = chalk.white.bgRed;
    }
    console.log("\n\n=======================================================");
    console.log("Linting completed on " + stats.fileCount + " files with " + color(" "+stats.errorCount+" ") + " errors.");
    console.log("=======================================================\n");
  };

  if(options.formatter){
    this.formatter = options.formatter;
  }
  if(options.statsFormatter){
    this.statsFormatter = options.statsFormatter;
  }

  var rawCoffeeLintConfiguration = null;
  if (options.configPath) {
    rawCoffeeLintConfiguration = fs.readFileSync(options.configPath, "utf-8");
  } else if (fs.existsSync("./coffeelint.json")) {
    rawCoffeeLintConfiguration = fs.readFileSync('./coffeelint.json', "utf-8");
  }
  if (rawCoffeeLintConfiguration) {
    try {
      this.coffeelintJSON = JSON.parse(rawCoffeeLintConfiguration);
    } catch(e) {
      throw 'Unable to parse json file: ' + path.resolve(options.coffeelintJSON)
    }
  }

  if(fs.existsSync("./.coffeelintignore")) {
    this.coffeelintignore = ignore()
      .add(fs.readFileSync('./.coffeelintignore').toString())
      .createFilter();
  }
}
Пример #23
0
/*
 * ScssLinter constructor. From here we
 * call the base filter class.
 *
 * @mathod ScssLinter
 *
 * @param {BroccoliNode} inputNode
 *   Broccoli input tree.
 *
 * @param {Object} options
 *   Options to be passed to the linter.
 */
function ScssLinter(inputNode) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  if (typeof inputNode === 'undefined' || (typeof inputNode === 'undefined' ? 'undefined' : _typeof(inputNode)) !== 'object') {
    throw new Error('Invalid input node.');
  }

  // If this was called on the object then create
  // a new ScssLinter instance.
  if (!(this instanceof ScssLinter)) {
    return new ScssLinter(inputNode, options);
  }

  // Persist options to be passed to sass-lint.
  this.options = options;

  // Call the parent prototype function.
  Filter.call(this, inputNode, {
    annotation: 'SCSS Linter',
    persist: true
  });

  // Configuration options.
  var _iteratorNormalCompletion = true;
  var _didIteratorError = false;
  var _iteratorError = undefined;

  try {
    for (var _iterator = Object.keys(this.options)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
      var key = _step.value;

      this[key] = this.options[key];
    }

    // Test generators.
  } catch (err) {
    _didIteratorError = true;
    _iteratorError = err;
  } finally {
    try {
      if (!_iteratorNormalCompletion && _iterator.return) {
        _iterator.return();
      }
    } finally {
      if (_didIteratorError) {
        throw _iteratorError;
      }
    }
  }

  if (typeof this.testGenerator === 'string') {
    this.testGenerator = require('./test-generators')[this.testGenerator];
    if (!this.testGenerator) {
      throw new Error('Could not find \'' + this.testGenerator + '\' test generator.');
    }
  }

  if (this.testGenerator) {
    this.targetExtension = 'sass-lint-test.js';
  }
}