Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create custom package templates #76

Closed
aronovgj opened this issue Feb 7, 2015 · 6 comments
Closed

Create custom package templates #76

aronovgj opened this issue Feb 7, 2015 · 6 comments

Comments

@aronovgj
Copy link

aronovgj commented Feb 7, 2015

I would like to be able to modify templates. My packages all look sort of similar so I find it faster to actually copy an existing package and modify it. If I could create a custom template the new-function would actually be useful to me.

@rismoney
Copy link
Contributor

rismoney commented Feb 7, 2015

Something like warmup?
https://chocolatey.org/packages/warmup

@aronovgj
Copy link
Author

aronovgj commented Feb 7, 2015

i know warmup and it was fine for me to use a 3rd party solution because the old chocolatey did not offer this at all. but if chocolatey wants to offer templates it should also offer a way to modify them. i mean new is supposed to eliminate the need to use warmup, right?

@ferventcoder ferventcoder added this to the 0.9.10 milestone May 11, 2015
@ferventcoder ferventcoder modified the milestones: 0.9.10, 0.9.10.x May 20, 2015
@ferventcoder ferventcoder modified the milestones: 0.9.9.9, 0.9.10.x Sep 18, 2015
@ferventcoder
Copy link
Member

If you drop a template into $env:ChocolateyInstall\templates folder, you can use -t name_of_template to generate a choco template based on that. So for:

image

You would call choco new pkgname -t organization and choco will use the template folder instead of the built-in template.

To replace the built-in template, you should put a folder in the template with the name of "default". Then choco will use that instead of the built-in template with no need to specify a template name.

ferventcoder added a commit that referenced this issue Sep 18, 2015
Allow creation of custom templates. If you drop a template folder into
`$env:ChocolateyInstall\templates` folder, you can use `-t
name_of_template_folder` to generate a choco template based on that.

If you were to drop an organization folder into the templates folder,
you would call `choco new pkgname -t organization` and choco will use
the template folder instead of the built-in template.

You can also replace the built-in template by placing a "default" folder
into the templates folder. choco will use that instead
of the built-in template with no need to specify a template name.
ferventcoder added a commit that referenced this issue Sep 18, 2015
* stable:
  (GH-76) Create custom templates
  (maint) comment about extension including dot
  (maint) resharper settings
@ferventcoder ferventcoder self-assigned this Sep 18, 2015
@ferventcoder
Copy link
Member

A file with the extension .nuspec

<?xml version="1.0" encoding="utf-8"?>
<!-- Do not remove this test for UTF-8: if ԏԠdoesnӴ appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one. -->
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
  <metadata>
    <id>[[PackageNameLower]]</id>
    <title>[[PackageName]] (Install)</title>
    <version>[[PackageVersion]]</version>
    <authors>Original authors</authors>
    <owners>[[MaintainerName]]</owners>
    <description>__REPLACE__MarkDown_Okay [[AutomaticPackageNotesNuspec]]
    </description>
    <tags>[[PackageNameLower]] admin</tags>
    <!--<dependencies>
      <dependency id="" version="__VERSION__" />
      <dependency id="" />
    </dependencies>-->
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
  </files>
</package>

tools\chocolateyInstall.ps1:

$ErrorActionPreference = 'Stop'; # stop on all errors

[[AutomaticPackageNotesInstaller]]
$packageName  = '[[PackageName]]'
$toolsDir     = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$fileLocation = Join-Path $toolsDir 'NAME_OF_EMBEDDED_INSTALLER_FILE'

$packageArgs = @{
  packageName   = $packageName
  file          = $fileLocation
  fileType      = '[[InstallerType]]' #only one of these: exe, msi, msu

  #MSI
  silentArgs    = "/qn /norestart /l*v `"$env:TEMP\chocolatey\$($packageName)\$($packageName).MsiInstall.log`""
  validExitCodes= @(0, 3010, 1641)
  #OTHERS
  #silentArgs   ='[[SilentArgs]]' # /s /S /q /Q /quiet /silent /SILENT /VERYSILENT -s - try any of these to get the silent installer
  #validExitCodes= @(0) #please insert other valid exit codes here
}

Install-ChocolateyInstallPackage @packageArgs

@ferventcoder
Copy link
Member

You can get the names by running choco new -h:

Possible properties to pass:
    packageversion
    maintainername
    maintainerrepo
    installertype
    url
    url64
    silentargs

However PackageName and PackageNameLower also show up as they are based on the name of the package that you pass e.g. "bob" in choco new bob

Then you surround those templated values with [[]] to make them templated for choco to use.

@ferventcoder
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants