public void Precompile(IAssetPipeline pipeline, IAssetRegistration registration)
        {
            var allFiles = pipeline.AllFiles().Where(x => x.Extension() == ".js");
            allFiles.Each(x =>
            {
                var name = x.LibraryName();
                var content = _fileSystem.ReadStringFromFile(x.FullPath);
                var match = _regex.Match(content);
                if (!match.Success) { return; }

                var tag = match.Groups[1].Value;
                var dependencies = match.Groups[3].Value;
                dependencies = _replacements
                    .Aggregate(dependencies, (current, value) => current.Replace(value, ""));
                var assets = dependencies.Split(',');
                //register all requirejs depedencies into asset graph
                foreach (var asset in assets)
                {
                    registration.Dependency(name, "{0}.js".ToFormat(asset));
                }

                if (tag == "require")
                {
                    _registry.Register(x);
                }
            });
        }
Пример #2
0
        public void Dependency(string dependent, string dependency)
        {
            _logs.FindByName(dependent)
            .Add(_provenance, "requires {0}".ToFormat(dependency));

            _logs.FindByName(dependency)
            .Add(_provenance, "supports {0}".ToFormat(dependent));

            _inner.Dependency(dependent, dependency);
        }
Пример #3
0
 /// <summary>
 /// Specify asset requirements (comma delimited names)
 /// </summary>
 /// <param name="commaDelimitedAssetNames"></param>
 /// <returns></returns>
 public AssetsExpression Requires(string commaDelimitedAssetNames)
 {
     commaDelimitedAssetNames.ToDelimitedArray().Each(x => _registration.Dependency(_assetName, x));
     return(_parent);
 }
Пример #4
0
        public void ReadLine(string text)
        {
            if (text.Trim().IsEmpty())
            {
                return;
            }
            if (text.Trim().StartsWith("#"))
            {
                return;
            }

            var tokens = new Queue <string>(StringTokenizer.Tokenize(text.Replace(',', ' ')));

            if (tokens.Count == 1)
            {
                if (_readerAction == null)
                {
                    throw new InvalidSyntaxException("Not enough tokens in the command line");
                }

                _readerAction(tokens.First());
                return;
            }

            _lastName     = null;
            _readerAction = null;

            if (tokens.Count() < 3)
            {
                throw new InvalidSyntaxException("Not enough tokens in the command line");
            }

            var key  = tokens.Dequeue();
            var verb = tokens.Dequeue();

            if (key == "ordered")
            {
                handleOrderedSet(tokens, verb);
                return;
            }

            // TODO -- time for something more sophisticated here
            if (key == "apply")
            {
                readPolicy(tokens, verb);
                return;
            }

            if (key == "combine")
            {
                readCombination(tokens, verb);
                return;
            }

            switch (verb)
            {
            case "is":
                if (tokens.Count > 1)
                {
                    throw new InvalidSyntaxException("Only one name can appear on the right side of the 'is' verb");
                }
                _registration.Alias(tokens.Dequeue(), key);
                break;

            case "requires":
                tokens.Each(name => _registration.Dependency(key, name));
                break;

            case "extends":
                if (tokens.Count > 1)
                {
                    throw new InvalidSyntaxException("Only one name can appear on the right side of the 'extends' verb");
                }

                _registration.Extension(key, tokens.Single());
                break;

            case "includes":
                tokens.Each(name => _registration.AddToSet(key, name));
                break;

            case "preceeds":
                tokens.Each(name => _registration.Preceeding(key, name));
                break;

            default:
                string message = "'{0}' is an invalid verb".ToFormat(verb);
                throw new InvalidSyntaxException(message);
            }
        }