Npm multiple file script (lessc) - css

I'm trying to run a lessc PowerShell commandline in my package.json.
So in my scripts section I have something like that:
Get-ChildItem *.less -Recurse | ForEach-Object {lessc $_.FullName > $_.BaseName.css}
but it's giving me the following error:
'Get-ChildItem' is not recognized as an internal or external command
while this is executing normally in PowerShell
Get-ChildItem *.less -Recurse | ForEach-Object {echo $_.Name}
A plain lessc command also works as expected.
Any ideas?
Also check this question that have another solution for this.

The error message suggests that you're not running the statement in PowerShell. lessc is a node.js application, not a PowerShell command, so it's unsurprising that it works when used by itself.
To be able to use PowerShell cmdlets you need to run the statement in PowerShell, e.g. like this:
powershell.exe -ExecutionPolicy Bypass -Command "Get-ChildItem *.less -recurse | Foreach-Object{ lessc $_.FullName > $_.BaseName.css }"

Related

Makefile "No such file or directory" when command is in PATH

I'm trying to write a Makefile in such a way that all of the steps in my recipe can call scripts a list of directories. As an example, I have node commands that are in a node_modules/.bin directory, but there could just as well be Python commands from a Python virtual environment as well, etc.
I have node installed, as well as TypeScript installed via npm in my /node_modules. Given my directory /tmp/test123, I wrote the following Makefile at /tmp/test123/Makefile as an example:
PATH = /tmp/test123/node_modules/.bin:$(PATH)
.PHONY: compile
compile:
env | grep "PATH"
tsc --help
However, if I try to run it, it outputs:
$ make compile
env | grep "PATH"
PATH=/tmp/test123/node_modules/.bin:... # the rest of my PATH
tsc --help
make: tsc: No such file or directory
make: *** [compile] Error 1
But if I change the last line to cd . && tsc --help, then compile runs successfully.
Why is make unable to find the tsc command in the PATH? Why do I need to run cd . && in front of it? Is there any better workaround than writing cd . && in front of all of my recipe steps?

How do I use to the zsh 'command' option to execute a the builtin 'source' command?

I am trying to log each time my shell sources a file. I am using zsh, so I went into zshenv and added this function.
source() {
echo "sourcing $1"
command source $1
}
The idea is everytime "source [file]" appears in one of my dotfiles and is executed, it should print the action to terminal first, before actually sourcing the file.
instead i'm getting some errors like this
sourcing /Users/js/.cargo/env
source:2: command not found: source
sourcing /Users/js/.sources/postgres-env.sh
source:2: command not found: source
sourcing /Users/js/.oh-my-zsh/oh-my-zsh.sh
source:2: command not found: source
sourcing /Users/js/.iterm2_shell_integration.zsh
source:2: command not found: source
What is the correct way to use the shell 'command' option with zsh to call source here?
command is intended to specifically invoke external commands. For example if you have an alias or function for git, command git will bypass those.
You're looking for the builtin command to limit command lookup to only builtin commands.
source() {
echo "sourcing $1"
builtin source "$1"
}
For it to work regardless of shell, you could use this instead:
#!/usr/bin/env sh
source() {
echo "sourcing $1"
. "$1"
}
source "$1"

How to copy qwindows.dll into platforms target subfolder?

I am trying to copy qwindows.dll from qt library folder to target one. At the moment I am using the following code:
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::QWindowsIntegrationPlugin> $<TARGET_FILE_DIR:${PROJECT_NAME}>)
It works, but it copies the file in the target directory. I need to copy the file inside a platforms subfolder, and I don't know what to do. I've tried
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::QWindowsIntegrationPlugin> $<TARGET_FILE_DIR:${PROJECT_NAME}>/platforms/qwindows.dll)
But the problem is that the .dll has another name in debug mode (qwindowsd.dll) so I need to insert the command two times.
Is there a way to use the Qt5::QWindowsIntegrationPlugin to retrieve the file name and use it as destination file in the second command?
add_custom_command(
TARGET demo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:demo>/platforms/
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:Qt5::QWindowsIntegrationPlugin>
$<TARGET_FILE_DIR:demo>/platforms/
)

command line less.watch()

What's the write command line for watching and compiling .less files. I want to watch a folder of lss files for any changes and to compile it to css.
I tried using terminal to cd right into the folder where my .less files are and to just run this command less.watch() but when I made changes nothing got outputted to css file.
What am I missing.
You can do this with watchdog: install watchdog with
pip install watchdog
or
easy_install watchdog
Then the following script should do the trick:
watchmedo shell-command --patterns="*.less" --command=\
'LESS=`echo "${watch_src_path}" | sed s/.less$/.css/`; \
echo compile: "${watch_src_path}";\
lessc "${watch_src_path}" "${LESS}"; \
if [ "$?" -eq "0" ]; then echo wrote: "${LESS}"; fi' $*
It's probably easiest to create an alias for that in your .bash_profile (or whatever the equivalent on your system is.

Powershell script to create folder, website and deploy using MSDeploy.exe

I would like to deploy a web application on Windows 2008 R2. I know the separate PowerShell commands to do various tasks. But I would like to put this into a nice PowerShell script.
I just need the syntax, can you please help me to do the following actions:
Test if C:\Inetpub\MyWebsite folder exists, if not, create it.
Test in IIS7 if MyWebsite exists, if not create it (I know how to Import-Module WebAdministration and call New-WebSite)
Now the complicated part. I deploy a Web site from a package prepared by Visual Studio 2010. VS supplies a .cmd file where I just need to execute it from a DOS prompt. This means I have to leave the PS Console, open a DOS Console to run that cmd file. Is it possible to run a .cmd file from within a PowerShell console ?
To answer your questions:
Import-Module WebAdministration
# Check for physical path
$sitePath = "c:\inetpub\MyWebsite"
if (-not (Test-Path -path $sitePath))
{
New-Item -Path $sitePath -type directory
}
# Check for site
$siteName = "MyWebSite"
$site = Get-WebSite | where { $_.Name -eq $siteName }
if($site -eq $null)
{
Write-Host "Creating site: $siteName"
# Put your New-WebSite code here
}
# Execute your .cmd here
c:\PathToScript\MakeMySite.cmd
You can run .cmd scripts from within PowerShell just fine.
I have also changed a little bit. Using the same Test syntax to test if a website exists or not:
if (-not (Test-Path -path IIS:\Sites\$SiteName))
{
New-WebSite -Name $SiteName ...etc...
}
Also for executing the *.cmd file, I lift some code from the web and saw that people use & to execute external command. Hope that you are OK:
& c:\PathToScript\MakeMySite.cmd arg1 arg2
Thank you very much for your help.
If you need to run the .cmd file as administrator, you can use the following code:
Start-Process -FilePath C:\PathToScript\MakeMySite.cmd -Verb RunAs -ArgumentList "/y"

Resources