danthareja / node-google-apps-script

[DEPRECATED - use clasp instead] The easiest way to develop Google Apps Script projects
MIT License
353 stars 70 forks source link

Feature Brainstorm: support duplicate filenames when in separate directories #52

Open techjeffharris opened 7 years ago

techjeffharris commented 7 years ago

gapps allows you to nest files in folders, but the Apps Script platform expects a flat file structure. Because of this, no files can have the same name, even if they are in separate directories. One file will overwrite the other, making debugging difficult.

Here's my brainstorm of a solution to the enable duplicate filenames when in separate local directories:

Say we add a couple keys to gapps.config.json

then create a flag for the upload/push commands to collapse of the directory structure within /src:

-d, --enable-dirs=PLACEHOLDER - enables local diretory support by prefixing each 
        filename with its path once all instances of the value of path.separator() 
        has been converted using to the default placeholder "_" or PLACEHOLDER,  
        if supplied.

Now, let's suppose I have a gapps project:

my-gapps-project
├── src/
│   ├── lib/
│   │   ├── foo.js
│   │   └── utils.js
│   ├── foo.js
│   └── utils.js
└── gapps.config.json

With the new behavior, if I call

$ gapps upload -d

My project will upload as such:

my-gapps-project
├── foo.gs
├── lib_foo.gs
├── lib_utils.gs
└── utils.gs

The same flag could be added to the init/clone commands to request the reciprocal effect--convert the default/specified PLACEHOLDER with path.separator(), then create files/folder accordingly.

Also, if a person wants to do this folder conversion at all, they probably want it done automatically, so --enable-dirs=PLACEHOLDER would update the gapps.config.json key "enable_dirs" to true and update "separator_placeholder" with PLACEHOLDER, if specified.

If we are going to have a sticky flag to enable diretory support, we should also have --disable-dirs to disable directory support which would essentially set "enable_dirs" to false.

I hope to submit a pull request once I spend the time to wrap my head around the code, but I figured I would see if anywone else is interested in this!

Thanks for all the hard work!

oshliaer commented 7 years ago

Is a google apps feature? The script project is simple. It don't need packages. I'm using npm scrips for this.

Just my ¢50

shrugs commented 7 years ago

I initially wanted to pursue something like this but avoided it due to the additional complexity. I think this is a feature worth adding if it's opt-in like you desribed; the primary issue is that the "directory separator" can't be used in the filename at all, so something like _ would probably run into issues if people aren't aware of that restriction.

perhaps something that would never occur in a filename like _-_ might work well? Regardless, I support adding this but don't have the time to work on it myself.

techjeffharris commented 7 years ago

I have no opinions on the separator, other than agreeing that _ is likely not the best default due to its already ubiquitous use in filenames.

Also, I still haven't taken any look at the code, sorry.. hopefully soon? ¯_(ツ)_/¯