How to covert rm command for Windows environment? - linux

Cypress manual for configuring Reporters contains rm command which doesn't work in Windows, namely
rm cypress/results/* || true
I believe that this is the manual bug regarding using Linux command in Windows environment, so the question is how it can be done in Windows? Moreover, I suppose to use the config file containing this command in Docker container which uses Linux core I believe. So the another problem is if I convert the command for Windows will I be able to use this file in my Docker container? Could somebody point me out the right way of using this command for the both OS? here is the link to Cypress manual containing this command https://docs.cypress.io/guides/tooling/reporters#Examples

rmdir can be used in windows
"delete:reports": "rmdir /S /Q cypress\\results && mkdir cypress\\results",
I do not think this will work for docker.
Cross platform,
yarn add -D rimraf mkdirp
"delete:reports": "rimraf cypress/results && mkdirp cypress/results",

Related

electron build for linux with root access

I am trying to run some shell commands on Linux under electron js that required Root Permissions.
If I run "Sudo electron ." then it works
If I create a build for Linux deb file like
"linux:build": "rm -rf dist && electron-packager . App --platform linux --arch x64 --out dist/ --no-sandbox"
"linux:deb": "electron-installer-debian --src ./dist/App-linux-x64/ --arch amd64 --no-sandbox --config linux.json"
Then Deb file is created, when I installed it then how I can run this app as a root user?
If I try to open this app with sudo App then it throws an error of
Running as root without --no-sandbox is not supported. See https://crbug.com/638180
In case of it's run like this, I don't think it's good practice that user will open app like this. How we can create Linux package that uses root permissions?
I also tried with package sudo-prompt and electron-sudo But it asks for admin password again and again as per commands will run. It should be asking for once.
Can anybody help me with this?
Looking forward to hearing from you guys!

Gitlab pipeline fails since the package.json has windows commands

I am working on a cypress project. The package.json has commands to delete old report folder and create new folder with same name.
I achieve this by using windows commands in package.json:
“Clean-reports”: “rmdir /s /q cypress\reports && mkdircypress\reports”
“Test”:”npm run Clean-reports && cypress run”
But when running this project on gitlab pipeline It gets stuck on rmdir command.
How do we achieve directory deletion and creation when running tests over gitlab pipeline ??
If you have Git for Windows, you have 200+ Linux command accessible in <Path\to\GIt>\usr\bin
That includes command rm.exe
Your Clean-reports steps can then become:
rm -Rf cypress\reports && ...
That command would be interpreted in a Linux environment.

Installing nodejs and npm on MSYS2

My OS is win7, and I using MSYS2(version:MSYS_NT-6.1), Please give advice how to install nodejs and npm on this terminal, Thanks!
I found a solution for resolving the problem,
64bit env.
pacman -S mingw-w64-x86_64-nodejs
32bit env.
pacman -S mingw-w64-i686-nodejs
after installed, Open terminal
$ node -v
v6.11.0
As of 2020, the package mingw-w64-x86_64-nodejs is not available any more. The simplest way to have Node.js, npm and git installed on a Windows machine is using the official Windows installers:
Git: https://git-scm.com/download/win
Node.js (npm is shipped with it): https://nodejs.org/en/download/
After installation, open a command prompt (click on start, and then type cmd and [ENTER]) and verify that all three tools are there:
git --version
node --version
npm --version
Later on, to update Node.js, simply reinstall it from the same source.
I wasted a lot of time on this. My solution is:
Download the Windows Binary (.zip) from nodejs site (https://nodejs.org/en/download/current/)
Extract it to some folder
Add that folder to the PATH env variable
It does work to use the Windows installer, and Node.js helpfully provides bash-script versions of npm and npx in C:\Program Files\nodejs\ to help streamline the process.
However, contrary to Cerclanism's comment # jmgonet's answer, you should not use --full-path with MinGW, no matter what terminal you're using, since that will by default bring the entire Windows path into your MinGW environment.
(Assuming you're a typical Windows developer with things like MSVC, Windows Python, and etc. install dirs on your path, containing plenty of names that clash with MinGW path members, you can see how that might bite you at some point down the road. My full Windows CMD.exe %PATH% is 1236 characters! I don't want all that sucked into MinGW.)
Instead, you should add the nodejs install dir to your MinGW shell $PATH, say by using everyone's favorite ~/.profile/~/.zprofile $PATH-munging trick:
# Append node.js to path
case ${PATH} in
*"/c/program files/nodejs"*)
;;
*)
export PATH="$PATH:/c/program files/nodejs:"
;;
esac
You'll probably also want to set some configuration, since by default Windows npm will use ${APPDATA}/npm for prefix, ${LOCALAPPDATA}/npm-cache for cache, C:\Windows\system32\cmd.exe for shell, etc.
# To view the full config including all defaults and overrides
npm config ls -l
# To view the active config for the specified environment
npm config list -L {global,user,project}
Maybe I was just confused, but to me it seemed, from what the configs show/say, that setting prefix= in my user config would override even local installs. (The project-specific ones where you npm install without --global, directly into a node_modules subdir of the current dir.) But after testing, happily I can report that's not the case, so it's safe to override the builtin prefix= from your $HOME/.npmrc.
Whether or not you move the cache= or let it stay at C:\Users\<you>\AppData\Local\npm-cache\ is your call. I'm sure it'll work that way. (Well, maybe not from an MSYS shell, but from MinGW it should be fine.)
There are minor differences I haven't overcome, but the only one that comes to mind right now is:
npm help <command> opens a browser window to HTML documentation, instead of displaying man page content directly in the terminal like it does on Linux. (Makes sense, as I don't think the manpages are even installed on Windows. Still disconcerting, though.)
You can simply install nvm, then install nodejs through there. In your MSYS2 shell just run the following to download and install nvm. Its better to go directly here and copy the download commands as the version numbers will change in the url.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
then run the following to setup nvm on your bash path:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
After running those commands you can use nvm install 16 or whatever node major version number you want. Type just nvm to get a list of available commands.

How to run rm command on windows 10?

"build": "rm -rf ./build && mkdir ./build && ./node_modules/.bin/babel -d ./build ./src"
This is the command in package.json and it gives me an error saying:
rm is not recognized as internal or external command.
Invalid switch /build
That script was written for the UNIX shell, which does not work on windows. The correct way to do this in a cross-platform way is to use rimraf & mkdirp.
Also, the ./node_modules/.bin/babel portion could be shortened to simply babel (./node_modules/.bin/babel doesn't work on windows IIRC).
Properly written, the script should be:
"build": "rimraf ./build && mkdirp ./build && babel -d ./build ./src"
For this script to work, you will have to install rimraf and mkdirp. You can do this by running:
npm install --save-dev rimraf mkdirp
The --save-dev flag will add rimraf and mkdirp to your package.json's devDependencies section so that they will automatically be installed with future npm installs.
Use rd /s /q "folder name" instead of rm -rf "folder name"
In order to run bash commands on Windows you need to install Bash complied for Windows. Install Cygwin and add bin directory to you PATH variable.
Windows 10 does not provide a UNIX shell by default. You'll need the appropriate UNIX utilities (such as rm) and a shell that supports the syntax you specified.
You have a few options:
Use the Windows 10 Bash Shell - Recent versions of Windows 10 now provide beta support for running Ubuntu within Windows without requiring a virtual machine.
Use Cygwin for development - Cygwin provides a shell of your choice and plenty of UNIX / Linux utilities.
Run a Virtual Machine with a Linux Guest - There are many options for running a VM on Windows. You can use Hyper-V, VirtualBox, or VMware Player. For a guest operating system, Ubuntu is a popular choice, but Fedora and Debian are also common alternatives.
Not to Bash, but in Windows you can use the built-in remove directory (rd) command:
RD /S /Q "folder-name"
Follow this link:
https://learn.microsoft.com/en-us/windows/nodejs/setup-on-wsl2
You will install a linux client for windows, and then instal node.js for that client and you can run rm commands easily

Ubuntu Sublime Text 2 Java Script compiling but not running

I'm setting up Sublime text 2 and running:
console.log("Hello!");
But all I'm getting in the console is "finished in [0.0]
My build system is:
{
"cmd": ["node", "$file"],
"selector": "source.js"
}
Any help would be greatly appreciated. This again is being done in Ubuntu.
The nodejs package for Ubuntu provides /usr/bin/nodejs, not /usr/bin/node. The node package, for amateur packet radio nodes, provides /usr/sbin/node, which is what your build system is running. It has nothing to do with Javascript, hence no output. There are two options (assuming you've already installed nodejs), and you can do one or both:
From the command line, run
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
This will create a symlink to node that (I think, I'm not in Ubuntu at the moment) should be before /usr/sbin in your $PATH. Run echo $PATH to verify the order of your path.
Change your build system to run /usr/bin/nodejs instead of node. This will fix your immediate problem, but if you don't run the other command above you may have issues with Sublime's NodeJS plugin.
Good luck!

Resources