private bool Compile()
        {
            CompilerOptions options = new CompilerOptions();

            options.DebugFlavor = DebugFlavor;
            if (DebugFlavor)
            {
                options.IncludeTests = IncludeTests;
            }
            else
            {
                options.Minimize = Minimize;
            }
            options.Defines    = GetDefines();
            options.References = GetReferences();
            options.Sources    = GetSources(_sources);
            options.Resources  = GetResources(_resources);
            if (_template != null)
            {
                options.TemplateFile = new TaskItemInputStreamSource(_template, "Template");
            }
            if (_docCommentFile != null)
            {
                options.DocCommentFile = new TaskItemInputStreamSource(_docCommentFile, "DocComment");
            }

            ITaskItem scriptTaskItem = new TaskItem(OutputPath);

            options.ScriptFile = new TaskItemOutputStreamSource(scriptTaskItem);

            string errorMessage = String.Empty;

            if (options.Validate(out errorMessage) == false)
            {
                Log.LogError(errorMessage);
                return(false);
            }

            ScriptCompiler compiler = new ScriptCompiler(this);

            compiler.Compile(options);
            if (_hasErrors == false)
            {
                _script = scriptTaskItem;

                string projectName    = (_projectPath != null) ? Path.GetFileNameWithoutExtension(_projectPath) : String.Empty;
                string scriptFileName = Path.GetFileName(scriptTaskItem.ItemSpec);
                string scriptPath     = Path.GetFullPath(scriptTaskItem.ItemSpec);

                Log.LogMessage(MessageImportance.High, "{0} -> {1} ({2})", projectName, scriptFileName, scriptPath);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool Compile()
        {
            CompilerOptions options = new CompilerOptions();

            options.Minimize        = Minimize;
            options.Defines         = GetDefines();
            options.References      = GetReferences();
            options.Sources         = GetSources(Sources);
            options.Resources       = GetResources(Resources);
            options.IncludeResolver = this;
            options.AssemblyName    = AssemblyName;

            ITaskItem scriptTaskItem = new TaskItem(OutputPath);

            options.ScriptFile = new TaskItemOutputStreamSource(scriptTaskItem);

            if (GenerateScriptMetadata)
            {
                var metadataPath = Path.ChangeExtension(OutputPath, "meta.js");
                options.MetadataFile = new TaskItemOutputStreamSource(new TaskItem(metadataPath));
            }

            string errorMessage = string.Empty;

            if (options.Validate(out errorMessage) == false)
            {
                Log.LogError(errorMessage);
                return(false);
            }

            ScriptCompiler compiler = new ScriptCompiler(this);

            if (compiler.Compile(options) && hasErrors == false)
            {
                Script = scriptTaskItem;

                string projectName    = (ProjectPath != null) ? Path.GetFileNameWithoutExtension(ProjectPath) : string.Empty;
                string scriptFileName = Path.GetFileName(scriptTaskItem.ItemSpec);
                string scriptPath     = Path.GetFullPath(scriptTaskItem.ItemSpec);

                Log.LogMessage(MessageImportance.High, "{0} -> {1} ({2})", projectName, scriptFileName, scriptPath);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        private bool Compile(string name, IEnumerable <ITaskItem> sourceItems, IEnumerable <ITaskItem> resourceItems, string locale)
        {
            ITaskItem scriptTaskItem;

            CompilerOptions debugOptions =
                CreateOptions(name, sourceItems, resourceItems, locale,
                              /* debug */ true, /* includeTests */ false, /* minimize */ false,
                              out scriptTaskItem);

            string errorMessage = String.Empty;

            if (debugOptions.Validate(out errorMessage) == false)
            {
                Log.LogError(errorMessage);
                return(false);
            }

            ScriptCompiler debugCompiler = new ScriptCompiler(this);

            debugCompiler.Compile(debugOptions);
            if (_hasErrors == false)
            {
                // Only copy references once (when building language neutral scripts)
                bool copyReferences = String.IsNullOrEmpty(locale) && CopyReferences;

                OnScriptFileGenerated(scriptTaskItem, debugOptions, copyReferences);
                if (_hasErrors)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            if (debugOptions.HasTestTypes)
            {
                CompilerOptions testOptions =
                    CreateOptions(name, sourceItems, resourceItems, locale,
                                  /* debug */ true, /* includeTests */ true, /* minimize */ false,
                                  out scriptTaskItem);
                ScriptCompiler testCompiler = new ScriptCompiler(this);
                testCompiler.Compile(testOptions);
                if (_hasErrors == false)
                {
                    OnScriptFileGenerated(scriptTaskItem, testOptions, /* copyReferences */ false);
                }
                else
                {
                    return(false);
                }
            }

            CompilerOptions releaseOptions =
                CreateOptions(name, sourceItems, resourceItems, locale,
                              /* debug */ false, /* includeTests */ false, /* minimize */ true,
                              out scriptTaskItem);
            ScriptCompiler releaseCompiler = new ScriptCompiler(this);

            releaseCompiler.Compile(releaseOptions);
            if (_hasErrors == false)
            {
                OnScriptFileGenerated(scriptTaskItem, releaseOptions, /* copyReferences */ false);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        private bool Compile() {
            CompilerOptions options = new CompilerOptions();
            options.DebugFlavor = DebugFlavor;
            if (DebugFlavor) {
                options.IncludeTests = IncludeTests;
            }
            else {
                options.Minimize = Minimize;
            }
            options.Defines = GetDefines();
            options.References = GetReferences();
            options.Sources = GetSources(_sources);
            options.Resources = GetResources(_resources);
            if (_template != null) {
                options.TemplateFile = new TaskItemInputStreamSource(_template, "Template");
            }
            if (_docCommentFile != null) {
                options.DocCommentFile = new TaskItemInputStreamSource(_docCommentFile, "DocComment");
            }

            ITaskItem scriptTaskItem = new TaskItem(OutputPath);
            options.ScriptFile = new TaskItemOutputStreamSource(scriptTaskItem);

            string errorMessage = String.Empty;
            if (options.Validate(out errorMessage) == false) {
                Log.LogError(errorMessage);
                return false;
            }

            ScriptCompiler compiler = new ScriptCompiler(this);
            compiler.Compile(options);
            if (_hasErrors == false) {
                _script = scriptTaskItem;

                string projectName = (_projectPath != null) ? Path.GetFileNameWithoutExtension(_projectPath) : String.Empty;
                string scriptFileName = Path.GetFileName(scriptTaskItem.ItemSpec);
                string scriptPath = Path.GetFullPath(scriptTaskItem.ItemSpec);

                Log.LogMessage(MessageImportance.High, "{0} -> {1} ({2})", projectName, scriptFileName, scriptPath);
            }
            else {
                return false;
            }

            return true;
        }
Ejemplo n.º 5
0
        private bool Compile(IEnumerable <ITaskItem> sourceItems, IEnumerable <ITaskItem> resourceItems, string locale)
        {
            ITaskItem scriptTaskItem;

            CompilerOptions options =
                CreateOptions(sourceItems, resourceItems, locale,
                              /* includeTests */ false, /* minimize */ false,
                              out scriptTaskItem);

            string errorMessage = String.Empty;

            if (options.Validate(out errorMessage) == false)
            {
                Log.LogError(errorMessage);
                return(false);
            }

            ScriptCompiler compiler = new ScriptCompiler(this);

            compiler.Compile(options);
            if (_hasErrors == false)
            {
                // Only copy references once (when building language neutral scripts)
                bool copyReferences = String.IsNullOrEmpty(locale) && CopyReferences;

                OnScriptFileGenerated(scriptTaskItem, options, copyReferences);
                if (_hasErrors)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            if (options.HasTestTypes)
            {
                CompilerOptions testOptions =
                    CreateOptions(sourceItems, resourceItems, locale,
                                  /* includeTests */ true, /* minimize */ false,
                                  out scriptTaskItem);
                ScriptCompiler testCompiler = new ScriptCompiler(this);
                testCompiler.Compile(testOptions);
                if (_hasErrors == false)
                {
                    OnScriptFileGenerated(scriptTaskItem, testOptions, /* copyReferences */ false);
                }
                else
                {
                    return(false);
                }
            }

            if (_minimize)
            {
                CompilerOptions minimizeOptions =
                    CreateOptions(sourceItems, resourceItems, locale,
                                  /* includeTests */ false, /* minimize */ true,
                                  out scriptTaskItem);
                ScriptCompiler minimizingCompiler = new ScriptCompiler(this);
                minimizingCompiler.Compile(minimizeOptions);
                if (_hasErrors == false)
                {
                    ExecuteCruncher(scriptTaskItem);
                    OnScriptFileGenerated(scriptTaskItem, minimizeOptions, /* copyReferences */ false);
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }