Creating empty directories in a Yeoman Generator - yeoman

How does one create an empty directory via a yeoman generator?
I've looked at mem-fs-editor, but as far as I can tell, directories are only created when a child file is created. I've tried creating a file in a sub directory and then deleting the file, but this doesn't work (I assume because mem-fs is prebuilt completely in memory, when it comes to write to disk, empty directories are not written).

mem-fs-editor (the file library used by Yeoman) do not support empty folders. This is very similar to how git work, the internal only keep track of files.
One option is to add .gitkeep or other empty files in those directory. That's my recommended solution as this will fix the issues you'll have anyway using git.
Another option is to use mkdirp:
var mkdirp = require('mkdirp');
// In your generator
mkdirp.sync('/some/path/to/dir/');

Related

Can you create URLs for files in sphinx regardless of where they are saved?

Can you change the location of 'rst' files in sphinx without changing their URIs? I'm working on a documentation where we want to move some files to different folders, without changing the URIs:
For Example: If you create a sphinx project with $ sphinx-quickstart and add some files and folders:
index.rst
/tutorials/howToFoo.rst
/scripts/
With the toctree in in index.rst looking like that:
.. toctree::
:maxdepth: 1
:caption: Processing:
:glob:
scripts/*
tutorials/*
Then after building the project with make html, you have a link in your browser as seen here: tutorials/howToFoo.html
If you want to save the the file in a different folder:
index.rst
/tutorials/
/scripts/howToFoo.rst
Then the URL of your file howToFoo.rst changes depending on where it is saved:
scripts/howToFoo.html.
This is a problem because I don't want links to tutorials or scripts to break.
As the project aims to include many people, it will be very probable that there will be changes in the file structure in the future.
Now my question: Can you create a setup where you can move the files without having to write redirects to their new location, every time you move them?
For Cross Referencing inside of Sphinx this is solved for example with targets, explained here:
https://docs.readthedocs.io/en/stable/guides/cross-referencing-with-sphinx.html#automatically-label-sections
But this doesn't help me because the link in the browser still stays the same.
What I want is a link SomeNeverchangingLinkFor_howToFoo.html regardless of where the file howToFoo.rst is saved.

CN1 - unable to use localization after activating css

Recently I switched over from the legacy css integration to using the current method of css support via the CN1 Preferences dialog. Ever since then, I've had repeated problems accessing strings from the localization resource file.
A few important points:
I have two theme files, but even importing the strings as a csv file into the theme generated by css doesn't work
I've tried all possible combinations of theme initialization with the two theme files, including initializing just one of them, with no consistent success (occasionally it works, but then if I modify the css and the theme file gets regenerated it stops working again)
I created a brand new project and copied my code into it, imported the string files, and it worked - until I turned on css support. Then I was back to square one
When it fails to work, the method UIManager.getL10NResourceNames() returns an empty array
Any help would be greatly appreciated!
CSS controls the file and as a result you can no longer change the theme.res file by other means. You need to keep a separate localization.res file and load that strictly for the localization functionality of your application. You can use Resources.open("/localization.res") to load an arbitrary resource file.
After much poking around, I found the solution. It turns out my situation was the result of a few non-standard things I did. First of all, I had a theme.res file which I renamed using IntelliJ's Refactor >> Rename function, which renamed the hardcoded css theme name in the build.xml file to my new name. I needed to manually revert that string in order to prevent the css compile task from overwriting my theme file. The second thing I noticed is that sometimes (I'm not clear on what caused this) the theme file was not being refreshed in the /out directory when running the app locally. This would manifest itself, for instance, when I would add an image in the theme file, but when running the code it wouldn't be able to find it in the Resources hashtable. Every time this happens, I now know to just delete the contents of /out, thereby forcing the IDE to rebuild/recopy the theme file (I could probably just copy it manually to the /out directory, but I think deleting it is safest).

Extract ZIP and move all files to parent directory

I'm only just getting started with Yeoman, trying to create a Generator that downloads WordPress, unzips it, and then proceeds to download my own WordPress starter theme.
The problem I'm having is that when I extract the latest.zip from wordpress.org (using this.extract()) it contains a wordpress/ directory resulting in my directory structure being my-project/wordpress/ rather than my-project/.
I've tried moving, copying and deleting the wordpress/ directory with various degrees of success; using this.fs.copy() I actually managed to get the files in the correct folder, but when trying to delete the original wordpress/ directory the user has to confirm deletion of every single file (not ideal). When I tried this.fs.move() I had to confirm each and every move instead.
I've found similar gulp/node.js questions on here, but I would prefer to use Yeoman's built in this.fs API.
Please note that I am aware of YEOPress but this is mostly for learnig purposes.
I ended up using the Node Package fs-extra instead as it deletes or moves without confirmation.

File repository in ruby on rails

I would like to create a simple file repository in Ruby on Rails. Users have their accounts, and after one logs in they can upload a file or download files previously uploaded.
The issue here is the security. Files should be safe and not available to anyone but the owners.
Where, in which folder, should I store the files, to make them as safe as possible?
Does it make sense, to rename the uploaded files, store the names in a database and restore them when needed? This might help avoid name conflicts, though I'm not sure if it's a good idea.
Should the files be stored all in one folder, or should they be somewhat divided?
rename the files, for one reason, because you have no way to know if today's file "test" is supposed to replace last week's "test" or not (perhaps the user had them in different directories)
give each user their own directory, this prevents performance problems and makes it easy to migrate, archive, or delete a single user
put metadata in the database and files in the file system
look out for code injection via file name
This is an interesting question. Depending on the level of security you want to apply I would recommend the following:
Choose a folder that is only accessible by your app server (if you chose to store in the FS)
I would always recommend to rename the files to a random generated hash (or incremntally generated name like used in URL shorteners, see the open source implementation of rubyurl). However, I wouldn't store them in a database because filesystems are built for handling files, so let it do the job. You should store the meta data in the database to be able to set the right file name when the user downloads the file.
You should partition the files among multiple folders. This gives you multiple advantages. First, filesystems are not built to handle millions of files in a single folder. If you have operations that try to get all files from a folder this takes significantly more time. If you obfuscate the original file name you could create one directory for each letter in the filename and would get a fairly good distributed number of files per directory.
One last thing to consider is the possible collision of file names. A user should not be able to guess a filename from another user. So you might need some additional checks here.
Depending on the level of security you want to achieve you can apply more and more patterns.
Just don't save the files in the public folder and create a controller that will send the files.
How you want to organise from that point on is your choice. You could make a sub folder per user. There is no need to rename from a security point of view, but do try to cleanup the filename, spaces and non ascii characters make things harder.
For simple cases (where you don't want to distribute the file store):
Store the files in the tmp directory. DON'T store them in public. Then only expose these files via a route and controller where you do the authentication/authorisation checks.
I don't see any reason to rename the files; you can separate them out into sub directories based on the user ID. But if you want to allow the uploading of files with the same name then you may need to generate a unique hash or something for each file's name.
See above. You can partition them any way you see fit. But I would definitely recommend partitioning them and not lumping them in one directory.

why have most of the files in a dreamweaver site been put into a directory called 'upload'?

I cleaned up someone's style sheet for a Dreamweaver site, by editing the css directly, and now the secretary is having trouble using her old template.
Most of the files in her site reside in subdirectories of the 'upload' directory. For example, I would have expected to see the stylesheet in
../assets/css/ etc.
but in fact I'm finding it in
../upload/assets/css/ etc.
In addition to assets, I am also finding Templates and images as subdirectories of 'upload'.
Do you know why this 'upload' directory was used?
I am considering two possible approaches.
(1) Make sure everything needed is in ../upload/ and remove the subdirectories that are directly in the root directory
(2) Edit the template to remove all references to ../upload/
Note that (2) appeals to me because the file structure will be simpler; but I wonder if the client has some sort of extension in her Dreamweaver that causes everything she ftp's to be put into the 'upload' directory.
Note that so far I have copied my cleaned up css file over to ../upload/assets/ as a short-term solution. But they want to be able to make changes to their template, and add new pages, on their own in future.
Thanks.
The likely problem is how she has her FTP remote settings specified. It appears that it now points to the upload folder rather than the web root. Or, it could be that her FTP user account is tied to the upload folder rather than the web root.

Resources