Skip to content

Instantly share code, notes, and snippets.

@jmrnilsson
Last active January 29, 2017 21:43
Show Gist options
  • Save jmrnilsson/a74a6eb37d478cb9f14b3232cec14198 to your computer and use it in GitHub Desktop.
Save jmrnilsson/a74a6eb37d478cb9f14b3232cec14198 to your computer and use it in GitHub Desktop.
PowerShell: Lightweight replacement function when Makefile not available
{
"name": "powershell-makefile",
"description": "",
"main": "build.ps1",
"license": "",
"homepage": "",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"grunt": "^1"
}
}
# https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md#macos-1011
# https://msdn.microsoft.com/powershell
# https://github.com/PowerShell/PowerShell/releases/tag/v6.0.0-alpha.15
[CmdletBinding()]
Param([Parameter(Mandatory=$False,Position=1)] [string]$Command)
$Command = If ($Command) { $Command } Else { "default" }
Write-Output "Make targets ($Command)"
Function New-Target
{
Param([string]$Source, [string]$Target)
$Modified = If (Test-Path $Target)
{
((Get-Item $Target).LastWriteTime).Ticks
}
Else
{
0
}
Return ((Get-Item $Source).LastWriteTime).Ticks -gt $Modified
}
If ($Command -imatch "clean")
{
If (Test-Path ./node_modules)
{
Remove-Item -Recurse -Force ./node_modules
}
If (Test-Path ./bower_components)
{
Remove-Item -Recurse -Force ./bower_components
}
Exit 0;
}
If (New-Target ./package.json ./node_modules/package.json)
{
$(npm install)
Copy-Item package.json ./node_modules/package.json
}
Else
{
Write-Output "Skipping package.json..."
}
If (New-Target ./bower.json ./bower_components/bower.json)
{
$(node_modules/.bin/bower install)
Copy-Item bower.json ./bower_components/bower.json
}
Else
{
Write-Output "Skipping bower.json..."
}
{
"name": "powershell-makefile",
"version": "1.0.0",
"description": "",
"main": "build.ps1",
"scripts": {
"test": "test.ps1"
},
"author": "",
"license": "",
"devDependencies": {
"bower": "^1.8.0",
"eslint": "^3.14.1",
"gulp": "1.*",
"jest": "^18.1.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment