get-output-directory.js 825 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var path = require('path'),
  3. fs = require('fs');
  4. var getContextDirectory = require('./get-context-directory');
  5. /**
  6. * Infer the compilation output directory from options.
  7. * Relative paths are resolved against the compilation context (or process.cwd() where not specified).
  8. * @this {{options: object}} A loader or compilation
  9. * @returns {undefined|string} The output path string, where defined
  10. */
  11. function getOutputDirectory() {
  12. /* jshint validthis:true */
  13. var base = this.options && this.options.output ? this.options.output.directory : null,
  14. absBase = !!base && path.resolve(getContextDirectory.call(this), base),
  15. isValid = !!absBase && fs.existsSync(absBase) && fs.statSync(absBase).isDirectory();
  16. return isValid ? absBase : undefined;
  17. }
  18. module.exports = getOutputDirectory;