static public Tuple <string[], string[]> GetProjectFiles(string script) { var globalConfig = GetGlobalConfigItems(); string[] defaultSearchDirs = globalConfig.Item1; string[] defaultRefAsms = globalConfig.Item2; string[] defaultNamespaces = globalConfig.Item3; var searchDirs = new List <string>(); searchDirs.Add(Path.GetDirectoryName(script)); searchDirs.AddRange(defaultSearchDirs); var parser = new ScriptParser(script, searchDirs.ToArray(), false); searchDirs.AddRange(parser.SearchDirs); //search dirs could be also defined n the script searchDirs.Add(ScriptsDir); searchDirs.RemoveEmptyAndDulicated(); IList <string> sourceFiles = parser.SaveImportedScripts().ToList(); //this will also generate auto-scripts and save them sourceFiles.Add(script); sourceFiles = sourceFiles.Distinct().ToList(); //some assemblies are referenced from code and some will need to be resolved from the namespaces var refAsms = parser.AgregateReferences(searchDirs, defaultRefAsms, defaultNamespaces); if (NppScriptsAsm != null) { refAsms.Add(NppScriptsAsm); } return(new Tuple <string[], string[]>(sourceFiles.ToArray(), refAsms.ToArray())); }
static public Project GenerateProjectFor(string script) { // Debug.Assert(false); // ******************************************************************************************** // * Extremely important to keep the project building algorithm in sync with CSExecutor.Compile // ******************************************************************************************** var project = new Project { Script = script }; var searchDirs = new List <string>(); searchDirs.Add(Path.GetDirectoryName(script)); var globalConfig = GetGlobalConfigItems(); var defaultSearchDirs = globalConfig.dirs; var defaultRefAsms = globalConfig.asms; var defaultNamespaces = globalConfig.namespaces; searchDirs.AddRange(defaultSearchDirs); ScriptParser parser = null; string currDir = Environment.CurrentDirectory; try { Environment.CurrentDirectory = Path.GetDirectoryName(script); parser = new ScriptParser(script, searchDirs.ToArray(), false); } finally { Environment.CurrentDirectory = currDir; } //search dirs could be also defined in the script var probingDirs = searchDirs.Concat(parser.SearchDirs) .Where(x => !string.IsNullOrEmpty(x)) .Distinct() .ToArray(); var sources = parser.SaveImportedScripts().ToList(); //this will also generate auto-scripts and save them sources.Insert(0, script); //if (parser.Packages.Any() && NotifyClient != null) //{ // NotifyClient("Processing NuGet packages..."); //} project.Files = sources.Distinct().Select <string, string>(Utils.PathNormaliseSeparators).ToArray(); project.Refs = parser.AgregateReferences(probingDirs, defaultRefAsms, defaultNamespaces) .Map(Utils.PathNormaliseSeparators, Utils.EnsureAsmExtension) .ToArray(); project.SearchDirs = probingDirs.Select <string, string>(Utils.PathNormaliseSeparators).ToArray(); return(project); }
static public Project GenerateProjectFor(string script) { // System.Diagnostics.Debug.Assert(false); // ******************************************************************************************** // * Extremely important to keep the project building algorithm in sync with CSExecutor.Compile // ******************************************************************************************** var project = new Project { Script = script }; var searchDirs = new List <string>(); searchDirs.Add(Path.GetDirectoryName(script)); var globalConfig = GetGlobalConfigItems(); var defaultSearchDirs = globalConfig.dirs; var defaultRefAsms = globalConfig.asms; var defaultNamespaces = globalConfig.namespaces; searchDirs.AddRange(defaultSearchDirs); ScriptParser parser; using (new CurrentDirGuard()) { Environment.CurrentDirectory = Path.GetDirectoryName(script); parser = new ScriptParser(script, searchDirs.ToArray(), false); } #if !class_lib CSExecutor.options.preCompilers = parser.Precompilers .Select(x => FileParser.ResolveFile(x, CSExecutor.options.searchDirs)) .AddItem(CSExecutor.options.preCompilers) .JoinBy(","); PrecompilationContext precompiling = CSSUtils.Precompile(script, parser.FilesToCompile.Distinct(), CSExecutor.options); #endif // search dirs could be also defined in the script var probingDirs = searchDirs.Concat(parser.SearchDirs) .Where(x => !string.IsNullOrEmpty(x)) .Distinct() .ToArray(); var sources = parser.SaveImportedScripts().ToList(); //this will also generate auto-scripts and save them sources.Insert(0, script); //if (parser.Packages.Any() && NotifyClient != null) //{ // NotifyClient("Processing NuGet packages..."); //} project.Files = sources.Distinct().Select <string, string>(PathExtensions.PathNormaliseSeparators).ToArray(); project.Refs = parser.AgregateReferences(probingDirs, defaultRefAsms, defaultNamespaces) .Select(PathExtensions.PathNormaliseSeparators) .ToArray(); #if !class_lib project.Refs = project.Refs.ConcatWith(precompiling.NewReferences); project.Files = project.Files.ConcatWith(precompiling.NewIncludes); #endif project.SearchDirs = probingDirs.Select <string, string>(PathExtensions.PathNormaliseSeparators).ToArray(); return(project); }