nwutils/Web2Executable

Allow blacklisting (or whitelisting) files when exporting

Forecaster opened this issue ยท 14 comments

Currently Web2Exe simply grabs everything in the project dir, including my .git dir, my project data from my IDE and some old data files that are in the project folder for reference.

This is quite unnecessary of course since a lot of this stuff is useless to the app. It'd be great if in say Export Settings there was an input field where I could specify a list of files/dirs separated by commas, along with a checkbox to toggle whitelist/blacklist (Should probably default to blacklist so the app works normally if the field is empty).

Another actual issue that stems from this (other than including unnecessary files) is, I use the path to the exe provided by nw.js to determine where the app is running from, to store data relative to the app, But in my dev environment the path to the exe is not in the project dir, it's to my central nw.js executable, and I don't want the data files to appear there. I could fix this by having a file in my project and check for it, and if it's present assume it's running from the IDE and use a specific path instead of the path relative to the exe. This would work fine if I could tell Web2Exe to not include this file when exporting.

This is a very good description of why blacklisting/whitelisting is useful. How I'm thinking of implementing this is having a tab with a file tree of the current project with check-boxes beside each folder/file that allows you to select/deselect files and folder hierarchies. Does that sound like it would satisfy your needs?

It depends on how this list is going to be updated, will it read the project on load and only then, or will it refresh periodically to see if there are new files? I might personally prefer just a text box where I can write my own list, but some users may prefer a pre-generated list, but I would like to be able to use wildcards which would only really work with text input (I think?).

A whitelist for example:

*.js
*.html
images/*

But regardless of my preferences I'd use the file-list too if that's the option you choose to go with. It would do the job.

I need such feature too. Also app should be able to use these unpacked files. I have in my project sensitive files such as back-end and non-sensitive like fron-end. I would like to compress backend and leave frontend visible to user.

It would decrease startup time. Nw.js itself is opening too long. With compression it's even worse.

Figured out a method to get the working path into my project dir without checking for a file by using an argument (two actually for two different computers with different paths).

Although I just realized too that the file would have had to be next to the exe anyway since that's where the working dir would be, so it wouldn't have been included in the project anyway...

I have found out that require('path') is all I needed.

Path | Node.js documentation

    var path = require('path'); // require path module
    var nwPath = process.execPath; // get path of nw.exe -> C:\...\app\nwjs-sdk-v0.18.4-win-x64\nw.exe
    var nwDir = path.dirname(nwPath); // get path of nw.exe folder -> C:\...\app\nwjs-sdk-v0.18.4-win-x64
    var newPath = path.join(nwDir, '..'); // join "\.." -> C:\...\app
    //C:\ is just example. 

Works after compression. Just remember to remove these files before compression and then add them in desired location after app.exe is created. It would be good to have whitelisting option.

Hey guys, I've been super busy lately and haven't got around to this yet. Thanks for posting workarounds as I'm sure many people will benefit from them. I promise I will get to this eventually but between job/christmas/girlfriend/family/friends it gets a bit hectic sometimes :)

That it does. Take your time!

This is very cool stuff and I thank you both for sharing.

@joey: Just wait until "job/christmas/girlfriend/family/friends" turns into "job/christmas/wife/kids/family/friends". You will think "man I use to have a lot of time":)

Cheers and Happy Holidays to all!

This is my solution for getting the app dir, including overriding it for my two different dev environments:

function get_app_dir()
{
  if (nw.App.argv.indexOf("--dev1") != -1)
    return "E:/Core - Development/nw.js/cmdrs_log_continued/";
  else if (nw.App.argv.indexOf("--dev2") != -1)
    return "C:/Repositories/cmdrs_log_continued/";

  var regex = /(.*(?:\/|\\){1})(?:[a-zA-Z0-9_.]*)$/;
  var result = process.execPath.match(regex);

  if (isset(result[1]))
    return result[1];
  return "";
}

I can then use this function as such:
var def_path = get_app_dir() + "data/" + global.constants.file_names.default_commodities;
This results in def_path containing an absolute path to this specific file.
(The global constant there contains a file name and extension)

Looking forward to trying this feature out. Do not see a windows version for v0.6.0b, is it still uploading or will it come later down the road?

Thanks.

You ah, also seem to have made a couple of mistakes in the release description, it says this for example:
%(system) is windows, %(sys) is %(win)
That seems incorrect

@2braincells2go I have to fix a couple of issues with the Windows version. It has a few bugs that I couldn't fix before I headed off to bed last night. Should be up by the end of today :)

@Forecaster You're correct. That's a typo :) I've corrected it to be %(sys) is win. Thank you for pointing it out :)

Understand Joey. Will check back in few days.

Thanks.

@2braincells2go @Forecaster the Windows version is up. I tried to fix the exporting issue (I think it was something to do with the Python logger) so let me know if it fixes the issue :)