Beispiel #1
0
        private void InnerMinify(IAsset asset, DependencyCollection commonExternsDependencies,
                                 ClosureLocalJsCompiler closureCompiler)
        {
            string newContent;
            string assetUrl = asset.Url;
            DependencyCollection assetExternsDependencies = GetAssetExternsDependencies(asset);

            try
            {
                newContent = closureCompiler.Compile(asset.Content, assetUrl, assetExternsDependencies);
            }
            catch (ClosureCompilationException e)
            {
                throw new AssetMinificationException(
                          string.Format(CoreStrings.Minifiers_MinificationSyntaxError,
                                        CODE_TYPE, assetUrl, MINIFIER_NAME, e.Message));
            }
            catch (Exception e)
            {
                throw new AssetMinificationException(
                          string.Format(CoreStrings.Minifiers_MinificationFailed,
                                        CODE_TYPE, assetUrl, MINIFIER_NAME, e.Message));
            }

            asset.Content  = newContent;
            asset.Minified = true;
            FillAssetVirtualPathDependencies(asset, commonExternsDependencies, assetExternsDependencies);
        }
Beispiel #2
0
        /// <summary>
        /// Produces a code minifiction of JS asset by using Google Closure Compiler Application
        /// </summary>
        /// <param name="asset">JS asset</param>
        /// <returns>JS asset with minified text content</returns>
        public override IAsset Minify(IAsset asset)
        {
            if (asset == null)
            {
                throw new ArgumentNullException(
                          nameof(asset),
                          string.Format(CoreStrings.Common_ArgumentIsNull, nameof(asset))
                          );
            }

            if (asset.Minified)
            {
                return(asset);
            }

            DependencyCollection commonExternsDependencies = GetCommonExternsDependencies();

            using (var closureCompiler = new ClosureLocalJsCompiler(JavaVirtualMachinePath,
                                                                    ClosureCompilerApplicationPath, _tempFilesDirectoryPath,
                                                                    commonExternsDependencies, CreateCompilationOptions()))
            {
                InnerMinify(asset, commonExternsDependencies, closureCompiler);
            }

            return(asset);
        }
Beispiel #3
0
        /// <summary>
        /// Produces a code minifiction of JS assets by using Google Closure Compiler Application
        /// </summary>
        /// <param name="assets">Set of JS assets</param>
        /// <returns>Set of JS assets with minified text content</returns>
        public override IList <IAsset> Minify(IList <IAsset> assets)
        {
            if (assets == null)
            {
                throw new ArgumentException(CoreStrings.Common_ValueIsEmpty, "assets");
            }

            if (assets.Count == 0)
            {
                return(assets);
            }

            var assetsToProcessing = assets.Where(a => a.IsScript && !a.Minified).ToList();

            if (assetsToProcessing.Count == 0)
            {
                return(assets);
            }

            DependencyCollection commonExternsDependencies = GetCommonExternsDependencies();

            using (var closureCompiler = new ClosureLocalJsCompiler(JavaVirtualMachinePath,
                                                                    ClosureCompilerApplicationPath, _tempFilesDirectoryPath,
                                                                    commonExternsDependencies, CreateCompilationOptions()))
            {
                foreach (var asset in assetsToProcessing)
                {
                    InnerMinify(asset, commonExternsDependencies, closureCompiler);
                }
            }

            return(assets);
        }
		private void InnerMinify(IAsset asset, DependencyCollection commonExternsDependencies,
			ClosureLocalJsCompiler closureCompiler)
		{
			string newContent;
			string assetUrl = asset.Url;
			DependencyCollection assetExternsDependencies = GetAssetExternsDependencies(asset);

			try
			{
				newContent = closureCompiler.Compile(asset.Content, assetUrl, assetExternsDependencies);
			}
			catch (ClosureCompilingException e)
			{
				throw new AssetMinificationException(
					string.Format(CoreStrings.Minifiers_MinificationSyntaxError,
						CODE_TYPE, assetUrl, MINIFIER_NAME, e.Message));
			}
			catch (Exception e)
			{
				throw new AssetMinificationException(
					string.Format(CoreStrings.Minifiers_MinificationFailed,
						CODE_TYPE, assetUrl, MINIFIER_NAME, e.Message));
			}

			asset.Content = newContent;
			asset.Minified = true;
			FillAssetVirtualPathDependencies(asset, commonExternsDependencies, assetExternsDependencies);
		}
		/// <summary>
		/// Produces a code minifiction of JS-assets by using Google Closure Compiler Application
		/// </summary>
		/// <param name="assets">Set of JS-assets</param>
		/// <returns>Set of JS-assets with minified text content</returns>
		public override IList<IAsset> Minify(IList<IAsset> assets)
		{
			if (assets == null)
			{
				throw new ArgumentException(CoreStrings.Common_ValueIsEmpty, "assets");
			}

			if (assets.Count == 0)
			{
				return assets;
			}

			var assetsToProcessing = assets.Where(a => a.IsScript && !a.Minified).ToList();
			if (assetsToProcessing.Count == 0)
			{
				return assets;
			}

			DependencyCollection commonExternsDependencies = GetCommonExternsDependencies();

			using (var closureCompiler = new ClosureLocalJsCompiler(JavaVirtualMachinePath,
				ClosureCompilerApplicationPath, _tempFilesDirectoryPath,
				commonExternsDependencies, CreateCompilationOptions()))
			{
				foreach (var asset in assetsToProcessing)
				{
					InnerMinify(asset, commonExternsDependencies, closureCompiler);
				}
			}

			return assets;
		}
		/// <summary>
		/// Produces a code minifiction of JS-asset by using Google Closure Compiler Application
		/// </summary>
		/// <param name="asset">JS-asset</param>
		/// <returns>JS-asset with minified text content</returns>
		public override IAsset Minify(IAsset asset)
		{
			if (asset == null)
			{
				throw new ArgumentException(CoreStrings.Common_ValueIsEmpty, "asset");
			}

			if (asset.Minified)
			{
				return asset;
			}

			DependencyCollection commonExternsDependencies = GetCommonExternsDependencies();

			using (var closureCompiler = new ClosureLocalJsCompiler(JavaVirtualMachinePath,
				ClosureCompilerApplicationPath, _tempFilesDirectoryPath,
				commonExternsDependencies, CreateCompilationOptions()))
			{
				InnerMinify(asset, commonExternsDependencies, closureCompiler);
			}

			return asset;
		}