Example #1
0
  exports.mince = function(src, dest, include, configurator, writeAsset, fn) {
    var environment = new Mincer.Environment(process.cwd()),
      asset;

    include.forEach(function(include) {
      environment.appendPath(include);
    });

    if (configurator) { configurator(Mincer); }

    asset = environment.findAsset(src);
    if (!asset) {
      return fn('Cannot find logical path: ' + src.cyan);
    }

    asset.compile(function (err) {
      if (err) {
        fn(err);
      } else {
        if (writeAsset) {
          grunt.log.write('Generating file ' + dest.cyan + '...');
          grunt.file.write(dest, asset.toString());
        }
        fn(null, asset);
      }
    });
  };
Example #2
0
 environment.registerHelper('asset_path', function(name, opts) {
   var asset = environment.findAsset(name, opts);
   if (!asset) throw new Error("File [" + name + "] not found");
   if (self.production) {
     return self._toAssetUrl(asset.digestPath);
   } else {
     return self._toAssetUrl(asset.logicalPath);
   }
 });
Example #3
0
  environment.ContextClass.defineAssetPath(function (pathname, options) {
    // this throws exception with details, if asset not exists
    var resolvedPath = this.resolve(pathname);

    sandbox.assets.used.push(resolvedPath);
    //  console.log(pathname)

    var asset = environment.findAsset(resolvedPath, options);
    return !asset ? null : ("/assets/" + asset.digestPath);
  });
Example #4
0
 .forEach(entry => {
     console.log('Building: %s', entry);
     
     var target = Path.join(buildDir, 'css', entry.replace('.less', `-${Package.version}.css`));
     var asset = env.findAsset(entry, { bundle: true });
     
     Fs.ensureDirSync(Path.dirname(target));
     Fs.writeFileSync(target, asset.buffer);
     
     console.log('Built %s with size: %d', target, asset.buffer.length);
 });
Example #5
0
	var assetPath = function(name) {
		var isProduction = config.env.isProduction();
		var asset = (isProduction) ? manifest.assets[name] : environment.findAsset(name);
		if (!asset) {
			return '';
		}

		return (
			isProduction ?
			path.join(config.web.publicResources, asset) :
			path.join(config.web.resources, asset.digestPath)
		);
	};
Example #6
0
function listAssetsIn(asset_name) {
  var a, asset;
  asset = environment.findAsset(asset_name);
  return ((function() {
    var _i, _len, _ref, _results;
    _ref = asset.toArray();
    _results = [];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      a = _ref[_i];
      _results.push("." + a.relativePath);
    }
    return _results;
  })()).slice(0, -1);
}
Example #7
0
Fabricate.prototype.minceAssets = function(callback) {
  var asset, environment;

  environment = new Mincer.Environment(process.cwd());

  this.include.forEach(function(include) {
    environment.appendPath(include);
  });

  asset = environment.findAsset(this.src, { bundle: false });

  if (!asset) {
    return callback('Cannot find logical path: ' + this.src);
  }

  this.uglifyAssets(_.uniq(
    buildForAsset(asset, path.dirname(asset.pathname), this.tmpDir)
  ), callback);
};
Example #8
0
 env.ContextClass.defineAssetPath(function (pathname, options) {
     var asset = env.findAsset(pathname, options);
     return !asset ? null : ('/assets/' + asset.digestPath);
 });
Example #9
0
 environment.ContextClass.defineAssetPath(function (pathname, options) {
   var asset = environment.findAsset(pathname, options);
   return !asset ? null : ("/assets/" + asset.digestPath);
 });
Example #10
0
'use strict';

var Mincer = require('mincer'),
    RubySassEngine = require('../index');

// use a Sass engine that compiles with official Sass release
Mincer.registerEngine('.sass', RubySassEngine);
Mincer.registerEngine('.scss', RubySassEngine);

var env = new Mincer.Environment(__dirname);
env.appendPath(__dirname + '/fixtures');

var compiledAsset = env.findAsset('test').toString();

if (compiledAsset.indexOf('body h1') !== -1) {
  console.log('OK');
} else {
  console.error('Failed to compile Sass');
  process.exit(1);
}
Example #11
0
  var mince = function (src, options) {
    var environment, asset, err;

    function configureEngine(name) {
      var engine = Mincer[name + 'Engine'] || Mincer[name],
        opts = options.engines[name];
      if (!engine || typeof engine.configure !== 'function') {
        grunt.fail.warn('Invalid Mincer engine ' + name.cyan);
      }
      engine.configure(opts);
    }

    options.configure(Mincer);

    environment = new Mincer.Environment(process.cwd());

    if (options.enable) {
      [].concat(options.enable).forEach(function (configuration) {
        environment.enable(configuration);
      });
    }

    [].concat(options.include).forEach(function (include) {
      environment.appendPath(include);
    });
    environment.appendPath(path.dirname(src));
    environment.appendPath(process.cwd());

    Object.keys(options.helpers).forEach(function (key) {
      // Create a bound function which has access to the current Mincer.Environment
      var helper = options.helpers[key].bind({
        environment: environment
      });
      environment.registerHelper(key, helper);
    });

    if (Object.keys(options.engines).some(configureEngine)) {
      return;
    }

    if (options.jsCompressor) {
      environment.jsCompressor = options.jsCompressor;
    }

    if (options.cssCompressor) {
      environment.cssCompressor = options.cssCompressor;
    }

    if (options.manifestPath && options.manifestPath.length > 0) {
      var resolvedAssets = src.map(function(filepath) {
        return logicalAssetName(environment, filepath);
      });

      if ((options.manifestOptions.sourceMaps !== null) && options.manifestOptions.sourceMaps) {
        environment.enable('source_maps');
      }

      var manifest = new Mincer.Manifest(environment, options.manifestPath);
      return manifest.compile(resolvedAssets, options.manifestOptions);
    }

    asset = environment.findAsset(src);
    if (!asset) {
      grunt.fail.warn('Cannot find logical path ' + src.cyan);
    }
    return asset;
  };