private void okButton_Click(object sender, EventArgs e) { string filePath = txtPath.Text.Trim(); DirectoryInfo path = Directory.GetParent(filePath); if (path == null) { MessageBox.Show("The File Name is not valid", "JS Builder Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!path.Exists) { DialogResult dr = MessageBox.Show("Directory '" + path.FullName + "' does not exist. Create it?", "JS Builder", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { Directory.CreateDirectory(path.FullName); } else { return; } } filePath = filePath + (filePath.EndsWith(".jsb") ? "" : ".jsb"); Options.GetInstance().LastProject = filePath; Project.GetInstance().Load(Application.ExecutablePath, Options.GetInstance().LastProject); Project.GetInstance().Name = txtName.Text; this.DialogResult = DialogResult.OK; this.Close(); }
static void Build(string projectPath, string outputPath) { Console.Out.WriteLine("\nBuilding: " + projectPath); Console.Out.WriteLine(); string appExePath = System.Reflection.Assembly.GetExecutingAssembly().Location; System.IO.FileInfo fi = new System.IO.FileInfo(appExePath); appExePath = Util.FixPath(fi.DirectoryName); //NOTE: In order to load an existing settings.xml file for debugging, you must first //create one using the GUI then copy it into the directory from which this assembly //is running (normally jsbuildconsole\bin\debug). Otherwise it will simply use defaults. Options.GetInstance().Load(appExePath); if (cleanOutputDir != null) { //If the clean flag was specified as a param, override the project setting Options.GetInstance().ClearOutputDir = (bool)cleanOutputDir; } ProjectBuilder.MessageAvailable += new MessageDelegate(ProjectBuilder_MessageAvailable); ProjectBuilder.ProgressUpdate += new ProgressDelegate(ProjectBuilder_ProgressUpdate); ProjectBuilder.BuildComplete += new BuildCompleteDelegate(ProjectBuilder_BuildComplete); Project project = Project.GetInstance(); project.Load(appExePath, projectPath); ProjectBuilder.Build(project, outputPath); Wait(); }
private void LoadFiles() { string output = Util.FixPath(Util.ApplyVars(project.Output, "", project)); string[] userVals = Options.GetInstance().Filter.Split(';', ',', '|'); string regex = ""; foreach (string v in userVals) { if (v.Length > 0) { regex += Regex.Escape(Util.ApplyVars(v.Trim(), output, project)) + "|"; } } regex += "^w-t-f$"; // match nothing filter = new Regex(regex, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ECMAScript); files.BeginUpdate(); files.Nodes.Clear(); string outputDir = Util.FixPath(Util.ApplyVars(txtOutput.Text, "", project)); foreach (DirectoryInfo di in project.SelectedDirectories) { LoadDir(null, di, true, di); } files.EndUpdate(); LoadTargets(); }
private void btnBrowse_Click(object sender, EventArgs e) { FileInfo file = new FileInfo(txtPath.Text); if (file.Exists) { saveDialog.FileName = file.FullName; } else { string lastFile = Options.GetInstance().LastProject; if (lastFile != null) { saveDialog.InitialDirectory = new FileInfo(lastFile).Directory.FullName; } else { saveDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal).ToString(); } } if (saveDialog.ShowDialog(this) == DialogResult.OK) { txtPath.Text = saveDialog.FileName; } }
protected override void OnClosing(CancelEventArgs e) { if (SaveProject() == DialogResult.Cancel) { e.Cancel = true; return; } Options.GetInstance().Save(Application.ExecutablePath); // save position and size // Positioning.Save(this, RegistryHive.CurrentUser, REGISTRY_KEY); }
private void tbOptions_Click(object sender, EventArgs e) { string origFileFilter = Options.GetInstance().Files; OptionsForm o = new OptionsForm(); if (o.ShowDialog(this) == DialogResult.OK) { if (origFileFilter != Options.GetInstance().Files) { RefreshTree(); } } }
private void LoadRecentItems() { if (Options.GetInstance().RecentProjects != null && Options.GetInstance().RecentProjects.Count > 0) { this.mnRecentProjects.DropDownItems.Clear(); foreach (string projectName in Options.GetInstance().RecentProjects) { ToolStripMenuItem tsi = new ToolStripMenuItem(); tsi.Text = projectName; tsi.Click += new EventHandler(tsi_Click); this.mnRecentProjects.DropDownItems.Add(tsi); } } }
/// <summary> /// JSDoc does not handle unquoted spaces in paths, so we need to double-quote the path if necessary. /// </summary> private static string GetJsdocPath() { string path = Options.GetInstance().JsdocPath; if (!path.StartsWith("\"")) { path = "\"" + path; } if (!path.EndsWith("\"")) { path += "\""; } path += " "; return(path); }
void tsi_Click(object sender, EventArgs e) { try { if (sender != null) { string projectName = sender.ToString(); Options.GetInstance().LastProject = projectName; project.Load(Application.ExecutablePath, projectName); LoadProject(); } } catch (Exception) { MessageBox.Show("Project File Name has incorrect format.", "JS Builder"); } }
public ProjectForm() { InitializeComponent(); string lastFile = Options.GetInstance().LastProject; if (lastFile != null) { string dir = new FileInfo(lastFile).Directory.FullName; txtPath.Text = dir + (dir.EndsWith("\\") ? "" : "\\") + "NewProject1.jsb"; } else { string dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal).ToString(); txtPath.Text = dir + (dir.EndsWith("\\") ? "" : "\\") + "NewProject1.jsb"; } txtName.Text = "New Project 1"; }
private void tbOpen_Click(object sender, EventArgs e) { if (SaveProject() == DialogResult.Cancel) { return; } string lastFile = Options.GetInstance().LastProject; if (lastFile != null && File.Exists(lastFile)) { openDialog.FileName = lastFile; } if (openDialog.ShowDialog(this) == DialogResult.OK) { Options.GetInstance().LastProject = openDialog.FileName; project.Load(Application.ExecutablePath, openDialog.FileName); LoadProject(); } }
public MainForm(string startupProject) { InitializeComponent(); //Positioning.Load(this, // RegistryHive.CurrentUser, REGISTRY_KEY); Options.GetInstance().Load(Application.ExecutablePath); if (Options.GetInstance().Reopen&& startupProject == null) { startupProject = Options.GetInstance().LastProject; } if (startupProject != null) { FileInfo fi = new FileInfo(startupProject); if (fi.Exists) { project.Load(Application.ExecutablePath, startupProject); LoadProject(); } } LoadRecentItems(); }
protected DialogResult SaveProject() { if (project.FileName != null && project.IsChanged()) { if (Options.GetInstance().AutoSave) { project.Save(); return(DialogResult.OK); } else { DialogResult res = MessageBox.Show("Save Changes to " + project.Name + "?", "Save Project?", MessageBoxButtons.YesNoCancel); if (res == DialogResult.OK) { project.Save(); } return(res); } } return(DialogResult.OK); }
private void AddToRecentItems() { Options.GetInstance().AddRecentProject(project.FileName); Options.GetInstance().Save(Application.ExecutablePath); LoadRecentItems(); }
private TreeDirectoryInfo LoadFiles(DirectoryInfo dir, DirectoryInfo root, TreeNode dirNode) { TreeDirectoryInfo tdInfo = new TreeDirectoryInfo(); string[] filter = Options.GetInstance().Files.Split(';', ',', '|'); FileInfo[] files = { }; foreach (string pattern in filter) { if (pattern.Length > 0) { FileInfo[] matches = GetFiles(dir, pattern); if (matches.Length > 0) { //BPM: changed logic to grab ub first so the insert is at the correct index after resize // to fix crash bug anytime more than one file type was matched separately in the same dir int ub = files.GetUpperBound(0); Array.Resize(ref files, files.Length + matches.Length); matches.CopyTo(files, (files[0] == null ? 0 : ub + 1)); } } } if (Options.GetInstance().Files != project.FileFilter) { //The filter has changed, so we need to remove any items that may still be in the project //that no longer match the new filter criteria. string[] oldFilter = project.FileFilter.Split(';', ',', '|'); foreach (string oldPattern in oldFilter) { bool remove = true; foreach (string pattern in filter) { if (pattern == oldPattern) { remove = false; break; } } if (remove) { //Old pattern is not in the new filter, so remove matching files FileInfo[] oldFiles = GetFiles(dir, oldPattern); foreach (FileInfo fi in oldFiles) { project.RemoveFile(project.GetPath(fi.FullName)); } } } } foreach (FileInfo f in files) { tdInfo.fileCount++; TreeNode fileNode = new FileNode(f.Name, 9, f.FullName, f, root); fileNode.Checked = project.IsSelected(project.GetPath(f.FullName)); dirNode.Nodes.Add(fileNode); if (fileNode.Checked) { tdInfo.selectedFileCount++; } } return(tdInfo); }
static public void Build(Project project, string outputDir) { // NOTE: Make sure that we DO throw any errors that might occur here // and defer handling to the caller. The console app must be allowed // to catch errors so that it can exit unsuccessfully. SetProgress(1, "Initializing..."); string projectDir = Util.FixPath(project.ProjectDir.FullName); outputDir = outputDir != null?Util.FixPath(outputDir) : Util.FixPath(project.Output); //Fix for default '$project\build' getting rendered literally: outputDir = outputDir.Replace("$project", projectDir); RaiseMessage(MessageTypes.Status, "Output path = " + outputDir); //rrs - option of clearing the output dir if (Options.GetInstance().ClearOutputDir) { RaiseMessage(MessageTypes.Status, "Clearing existing output..."); Util.ClearOutputDirectory(outputDir); } //rrs string header = Util.ApplyVars(project.Copyright, outputDir, project); if (header.Length > 0) { header = "/*\r\n * " + header.Replace("\n", "\n * ") + "\r\n */\r\n\r\n"; } string build = Util.FixPath(Util.ApplyVars(project.MinDir, outputDir, project)); string src = Util.FixPath(Util.ApplyVars(project.SourceDir, outputDir, project)); string doc = Util.FixPath(Util.ApplyVars(project.DocDir, outputDir, project)); SetProgress(10, "Loading source files..."); Dictionary <string, SourceFile> files = project.LoadSourceFiles(); float fileValue = 60.0f / (files.Count > 0 ? files.Count : 1); int fileNumber = 0; foreach (SourceFile file in files.Values) { int pct = (int)(fileValue * ++fileNumber); SetProgress(10 + pct, "Building file " + (fileNumber) + " of " + files.Count); RaiseMessage(MessageTypes.Status, "Processing " + file.File.FullName + "..."); file.Header = header; if (project.Source) { //Copy original source files to source output path DirectoryInfo dir = getDirectory(src + file.PathInfo); file.CopyTo(Util.FixPath(dir.FullName) + file.File.Name); } if (project.Minify && file.SupportsSourceParsing) { //Minify files and copy to build output path DirectoryInfo dir = getDirectory(build + file.PathInfo); file.MinifyTo(Util.FixPath(dir.FullName) + file.OutputFilename); } //file.GetCommentBlocks(); } bool jsdocSkipped = false; if (project.Doc) { if (Options.GetInstance().JsdocPath.Length < 1 || !new FileInfo(Options.GetInstance().JsdocPath).Exists) { jsdocSkipped = true; } else { SetProgress(75, "Creating JSDoc output..."); string fileList = ""; foreach (SourceFile f in files.Values) { if (f.SupportsSourceParsing) { fileList += f.File.FullName + " "; } } DirectoryInfo outDir = getDirectory(doc); string args = GetJsdocPath() + Options.GetInstance().JsdocArgs.Replace("$docPath", outDir.FullName); args = args.Replace("$files", fileList); Process p = new Process(); p.EnableRaisingEvents = false; ProcessStartInfo info = new ProcessStartInfo("perl.exe", args); info.CreateNoWindow = true; info.UseShellExecute = false; p.StartInfo = info; try { p.Start(); p.WaitForExit(); } catch (Exception e) { jsdocSkipped = true; } } } SetProgress(85, "Loading build targets..."); List <Target> targets = project.GetTargets(true); bool targetsSkipped = false; if (targets.Count > 0) { float targetValue = 10.0f / (targets.Count > 0 ? targets.Count : 1); int targetNumber = 0; foreach (Target target in targets) { if (target.Includes == null) { targetsSkipped = true; continue; } int pct = (int)(targetValue * ++targetNumber); SetProgress(85 + pct, "Building target " + (targetNumber) + " of " + targets.Count); FileInfo fi = new FileInfo(Util.ApplyVars(target.File, outputDir, project)); fi.Directory.Create(); StreamWriter sw = new StreamWriter(fi.FullName); sw.Write(header); if (!target.Shorthand) { foreach (string f in target.Includes) { sw.Write(files[f].Minified + "\n"); } } else { string[] sh = target.ParseList(); StringBuilder fcn = new StringBuilder(); fcn.Append("(function(){"); int index = 0; foreach (string s in sh) { fcn.AppendFormat("var _{0} = {1};", ++index, s); } sw.Write(fcn.Append("\n")); foreach (string f in target.Includes) { string min = files[f].Minified; index = 0; foreach (string s in sh) { min = min.Replace(s, "_" + index); } sw.Write(min + "\n"); } sw.Write("})();"); } sw.Close(); if (target.Debug) { string filename = fi.FullName; if (fi.Extension == ".js") { //Only rename to -debug for javascript files filename = fi.FullName.Substring(0, fi.FullName.Length - 3) + "-debug.js"; } StreamWriter dsw = new StreamWriter(filename); dsw.Write(header); foreach (string f in target.Includes) { //dsw.Write("\r\n/*\r\n------------------------------------------------------------------\r\n"); //dsw.Write("// File: " + files[f].PathInfo + "\\" + files[f].File.Name + "\r\n"); //dsw.Write("------------------------------------------------------------------\r\n*/\r\n"); dsw.Write(files[f].GetSourceNoComments() + "\n"); } dsw.Close(); } } } if (targetsSkipped) { RaiseMessage(MessageTypes.Info, "One or more build targets referenced files that are no longer included in the build project, so they were skipped."); } if (jsdocSkipped) { RaiseMessage(MessageTypes.Info, "JSDoc was skipped because the path to JSDoc (" + Options.GetInstance().JsdocPath + ") is invalid or perl.exe was not found.\nYou can change the path by selecting Build->Options and entering a new path."); } SetProgress(100, "Done"); if (BuildComplete != null) { BuildComplete(); } }
private void RefreshTree() { LoadFiles(); Project.GetInstance().FileFilter = Options.GetInstance().Files; tbRemoveFolder.Enabled = false; }