Pass "content of file" instead of "location of file" - node.js

I am creating an electron app for windows and using some windows app dependencies.
The other dependencies require a file path as variable. Example
dependency.exe --config /path/to/config/file.conf
i wish to replace /path/to/config/file.conf directly with the content
for example
dependency.exe --config $("configuration content")
Reason? I do not wish to create a config file for user to see and keep it as closed source

I'm assuming dependency.exe is your app. You can have it read from standard input, then use the type command to get the configuration file contents:
type file.conf | dependency.exe

Related

Exporting and Importing content using a JSON config

I am trying to export a space from contentful using the Export/import tool and the option config json file.
What is the file path where the config file should be?
Contentful DevRel here. Welcome to Stack Overflow! 👋
I assume you're referring to the config.json file mentioned in the docs. The config file is optional in case you don't want to pass the command-line options. The CLI options will do the job just fine.
If you want to go with this config file you choose the file path and can run the command with the path to your config as follows:
contentful space export --config example-config.json
Hope that helps. :)

How to configure ESLint auto fix on save in WebStorm/PHPStorm?

I am trying to create a custom file watcher in WebStorm that will auto fix ESLint errors on save. In Settings > Tools > File Watchers I created a new file watcher with the following settings:
File type: Any
Scope: All places
Program: /home/user/Projects/todo-app/eslint-autofix.sh
Arguments: blank
Output paths to refresh: blank
Other options > Working directory: /home/user/Projects/todo-app
eslint-autofix.sh:
#!/usr/bin/env bash
./node_modules/.bin/eslint --fix
Then I made an ESLint error and pressed Ctrl + S to save. The following error pops up:
/home/user/Projects/todo-app/eslint-autofix.sh
/usr/bin/env: ‘node’: No such file or directory
How to fix this error?
According to this article, settings should be as the following:
File type: Any (or JavaScript)
Scope: Project files
Program: $ProjectFileDir$/node_modules/.bin/eslint
Arguments: --fix $FilePath$
Output paths to refresh: $FileDir$
On WebStorm 2020.1.1, there is a checkbox called Run eslint --fix on save.
Also see:
https://www.jetbrains.com/help/webstorm/eslint.html#ws_js_eslint_activate
Just to extend on jstice4all's & gotjosh's solution:
I was able to get the FileWatcher to ESLint for some projects, but it wasn't working with the plugin extends: '#react-native-community'
#react-native-community/eslint-config#overrides[2]:
Environment key "jest/globals" is unknown
Turns out that the #react-native-community plugin needs to be ran from the project folder itself in order to load the environment variables, whereas the file watcher runs from the node_module/eslint path. To get it to work I had to add the following config:
Working Directory: $ProjectFileDir$
Screenshot Config

How to create a JSCS config file on windows

When I try to create a JSCS config file:
C:\Blog\BlogWeb>jscs --auto-configure "C:\Blog\BlogWeb\temp.jscs"
I get the following error:
safeContextKeyword option requires string or array value
What parameter am I supposed to pass? What is a safecontextkeyword?
New to NPM and JSCS, please excuse ignorance.
JSCS was complaining that I didn't have a config file, so I was trying to figure out how to create one.
JSCS looks for a config file in these places, unless you manually specify it with the --config option:
jscs it will consequentially search for jscsConfig option in package.json file then for .jscsrc (which is a just JSON with comments) and .jscs.json files in the current working directory then in nearest ancestor until it hits the system root.
I fixed this by:
Create a new file named .jscsrc. Windows Explorer may not let you do this, so may need to use the command line.
Copy the following into it. It doesn't matter if this is the preset you want to use or not. The command will overwrite it.
{
"preset": "jquery",
"requireCurlyBraces": null // or false
}
Verify that it works by running a command such as:
run the command
jscs --auto-configure .jscsrc

Node.js / Export configuration file

I have the following configuration file in /etc/sysconfig/myconf:
export USER=root
export NODE_DIR=/opt/MyDir
I want to use these setting in my .js file, which located in /opt/myapplication:
var userApp = //USER in /etc/sysconfig/myconf file
var dir = //NODE_DIR in /etc/sysconfig/myconf file
Is there any way to do it without open the file and parse it contents?
As I understand the export should give me the option to read it easily in node.js, but I don't find how (In addition, when I run export -p, I don't see these variables)
EDIT: what I search is equal Node.js's command to source command in Linux (the variables is not environment variables)
If those environment variables are available when you launch the program, you can use process.env. https://nodejs.org/api/process.html#process_process_env

How to remove multiple virtual directories?

I need to remove a big amount of virtual directories, some of them don't have associated physical directories.
Ideas?
As you need to remove a large amount, I'm guessing you'll want to use some form of script.
IIS 6.0, using IISvdir.vbs( article # MSDN):
At the command prompt, use the cd command to change to the directory where the Iisvdir.vbs script is installed. The default location for this file is systemroot/system32/iisvdir.vbs.
At the command prompt, type:
cscript iisvdir.vbs /delete "Sample Web Site" VirtualDirectoryName.
Substitute your Web site name and virtual directory name as appropriate. If there are spaces in the Web site name, use quotation marks around the Web site name, as shown in the preceding example.
IIS 7 using AppCmd.exe (article # TechNet):
To remove a virtual directory, use the following syntax:
appcmd delete vdir /vdir.name: string
The variable vdir.namestring is the virtual path of the virtual directory.
For example, to remove a virtual directory named photos from the root application of a site named contoso, type the following at the command prompt, and then press ENTER:
appcmd delete vdir /vdir.name: contoso / photos
To remove a virtual directory named photos from an application named marketing in a site named contoso, type the following at the command prompt, and then press ENTER:
appcmd delete vdir /vdir.name: contoso / marketing / photos
HTH
You could also write an msbuild script to do this and use the msbuild extension pack which is available here. I have used this successfully to do exactly what you are saying for 100s of vdirs in iis 6 AND in iis 7.5.
Its pretty simple and took me longer to write the .proj file than it did to figure out how to do it.
have fun :)
the resultant msbuild target would look like as follows
<Target Name="IIS7VirtualDirectories:Delete">
<MSBuild.ExtensionPack.Web.Iis7Application
TaskAction="Delete"
Website="%(Application.WebsiteName)"
Applications="#(Application)"
MachineName="$(MachineName)"
ContinueOnError="false"/>
<MSBuild.ExtensionPack.Web.Iis7Website
TaskAction="DeleteVirtualDirectory"
Name="%(VirtualDirectory.WebsiteName)"
VirtualDirectories="#(VirtualDirectory)"
ContinueOnError="false"
MachineName="$(MachineName)"/>
</Target>
Where Application and VirtualDirectory are defined in an external proj file :)

Resources