juce-framework / JUCE

JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins.
https://juce.com
Other
6.31k stars 1.67k forks source link

New feature: add-file functionality to Projucer #1348

Closed tesseiko closed 4 months ago

tesseiko commented 4 months ago

Added new subcommand to Projucer command line.

Projucer --add-file jucerfile.jucer path/to/file/or/directory/to/add/project

Feature request https://forum.juce.com/t/projucer-add-folder-file-via-command-line/50732

tesseiko commented 4 months ago

Here is the patch, in case anybody wants to patch this feature to a previous version. Tested in 6.1.6.

=================================================================================

diff --git a/extras/Projucer/Source/Application/jucer_CommandLine.cpp b/extras/Projucer/Source/Application/jucer_CommandLine.cpp
index eff87122f..ba462cce9 100644
--- a/extras/Projucer/Source/Application/jucer_CommandLine.cpp
+++ b/extras/Projucer/Source/Application/jucer_CommandLine.cpp
@@ -152,6 +152,19 @@ namespace
                 modules.tryToFixMissingDependencies (m);
         }

+        //==============================================================================
+        /* 
+         tesseiko's patch for adding existing file/directory to project
+        */
+        void addFile (const File& file)
+        {
+            project->getMainGroup().addFileRetainingSortOrder (file, true);
+        }
+        /* 
+         tesseiko's patch for adding existing file/directory to project
+        */
+        //==============================================================================
+
         std::unique_ptr<Project> project;
     };

@@ -171,6 +184,31 @@ namespace
         proj.save (justSaveResources, args.containsOption ("--fix-missing-dependencies"));
     }

+    //==============================================================================
+    /* 
+     tesseiko's patch for adding existing file/directory to project
+    */
+    static void addFile (const ArgumentList& args)
+    {
+        args.checkMinNumArguments (3);
+        LoadedProject proj (args[1]);
+        auto fileToAdd = args[2].resolveAsExistingFile();
+
+        std::cout << "Adding File: "
+                  << fileToAdd.getFileName() << std::endl;
+
+        proj.addFile (fileToAdd.getFullPathName());
+
+        std::cout << "Re-saving file: "
+                  << proj.project->getFile().getFullPathName() << std::endl;
+
+        proj.save (false, args.containsOption ("--fix-missing-dependencies"));
+    }
+    /* 
+     tesseiko's patch for adding existing file/directory to project
+    */
+    //==============================================================================
+
     //==============================================================================
     static void getVersion (const ArgumentList& args)
     {
@@ -824,6 +862,8 @@ namespace
                   << std::endl
                   << "Usage: " << std::endl
                   << std::endl
+                  << " " << appName << " --add-file project_file path_to_file_to_add" << std::endl
+                  << "    Adds an existing file or directory to a project." << std::endl
                   << " " << appName << " --resave project_file" << std::endl
                   << "    Resaves all files and resources in a project. Add the \"--fix-missing-dependencies\" option to automatically fix any missing module dependencies." << std::endl
                   << std::endl
@@ -906,6 +946,7 @@ int performCommandLine (const ArgumentList& args)
         if (matchCommand ("help"))                     { showHelp();                            return 0; }
         if (matchCommand ("h"))                        { showHelp();                            return 0; }
         if (matchCommand ("resave"))                   { resaveProject (args, false);           return 0; }
+        if (matchCommand ("add-file"))                 { addFile (args);                        return 0; } // tesseiko's patch
         if (matchCommand ("resave-resources"))         { resaveProject (args, true);            return 0; }
         if (matchCommand ("get-version"))              { getVersion (args);                     return 0; }
         if (matchCommand ("set-version"))              { setVersion (args);                     return 0; }

copy the patch and save it to a file, e.g., cli_add_file.patch Then navigate to your cheked-out version of juce framework and run git apply /path/to/cli_add_file.patch and rebuild Projucer

tesseiko commented 4 months ago

I apologize for my mistake in creating a pull request for the master branch. I've rectified this by creating a new pull request in the 'develop' branch. You can find it here: https://github.com/juce-framework/JUCE/pull/1349