template-library 4.0.3
Install from the command line:
Learn more about npm packages
$ npm install @simatic-ax/template-library@4.0.3
Install via package.json:
"@simatic-ax/template-library": "4.0.3"
About this version
See the documentation on custom templates.
-
If not done, login to the GitHub registry
More information you'll find here
-
Create a new library project from template from CLI
apax create @simatic-ax/library --registry https://npm.pkg.github.com
and follow the dialog
alternatively you can add the project name:
apax create @simatic-ax/library --registry https://npm.pkg.github.com <name of the project>
If this template is not suitable for you, you can create your own user specific templates. This describes, how a template for GitHub is created. For other Git provider it might be similar, but each Git provider has its own specific properties.
-
Select your target path. In this example, it is shown with the Windows Explorer
-
Open a console by entering
cmd + Enter
in the address text boxResult: A command line window will be opened
-
Create a new, empty template workspace by entering:
apax create template template-userspecific
Important: It's very important, that the name of the template package starts with
template-
followed by the name of the template (e.g.template-userspecific
) -
Open the template workspace with:
axcode template-userspecific
Result: AX Code is opened and you an see the following workspace structure which consists of:
-
The apax.yml
(1)
which is the description for the template package -
The apax.yml in the template folder
(2)
which belongs to the workspace, which will be created, when you create a workspace from this template.
The template-folder
(2)
is the folder, which contains all files and folders for the workspace to be created from this template. For example, it can contain:- your individual apax.yml with scrips, variables or common used dependencies
- src- and test-folder with example files
- a README.md
- a docs folder for further documentation
-
The default apax.yml is not suitable to publish your package on a GitHub registry.
Default apax.yml
name: "template-userspecific"
version: 0.0.0
type: generic
-
Scope of the template on GitHub
For GitHub it's important, that the scope is part of the name section. On GitHub, the name of your GitHub organization is also the scope.
If your organization is
simatic-ax
, then the name section in the apax yml must look like:name: "@simatic-ax/template-userspecific"
-
Define URL for the scope
@simatic-ax
Add the registries section to the apax.yml
registries: '@simatic-ax': 'https://npm.pkg.github.com/'
-
Define the content for the template
In the file section, in the apax.yml, you can define, what generally will be shipped in a package. For templates, at minimum, the template folder must be shipped. This can be done, by adding the following lines to tha apax.yml
files: - 'template'
-
Final apax.yml
name: '@simatic-ax/template-library' version: 0.0.0 type: lib author: Siemens AG registries: '@simatic-ax': 'https://npm.pkg.github.com/' files: - 'template'
In this example, you a template for a library (type: lib) will be crated. A list of valid types, you can find here: valid types
The author field is optionally
-
Learn More abut the apax.yml
-
Go to your organization on GitHub
-
Create a new repository
-
Enter exactly the name of your template in the field
Repository name
. In this example it istemplate-library
and click onCreate repository
-
Add the remote repository on GitHub to your local repository (optionally)
git add * git commit -m "first commit" git branch -M main git remote add origin [email protected]:simatic-ax/template-library.git git push -u origin main
Result: now your template is also available on GitHub
Since the repository template-library
is available on GitHub, you can continue publishing your package on the GitHub registry.
-
Create the package version
apax version 0.0.1
Result in apax.yml
version: 0.0.1
-
Create the template package
apax pack
Result: The package file
simatic-ax-template-library-0.0.1.apax.tgz
has been created -
Publish the package on your GitHub registry
Important: If not logged in on GitHub, you've to do it before you can publish a package. More information you'll find here
apax publish --registry https://npm.pkg.github.com --package simatic-ax-template-library-0.0.1.apax.tgz
alternatively you can add a script
publishlib
to the apax.ymlname: '@simatic-ax/template-library' version: 0.0.1 type: lib author: Siemens AG registries: '@simatic-ax': 'https://npm.pkg.github.com/' files: - 'template' scripts: publishlib: apax publish --registry https://npm.pkg.github.com --package *.apax.tgz
and call the script with
apax publishlib
The template is published and ready to use
When your template has been changed for any reasons, it is necessary to update the template-package and publish it again. Since it is not possible to overwrite an existing package with the same version on the GitHub package registry, you need to create a new version with:
apax version <new version>
-
Go to the folder, where your workspace should be created and open a command line interface (or navigate via command line interface to your destination folder)
-
Enter the command
apax create @simatic-ax/library --registry https://npm.pkg.github.com
Note: the when you create a workspace from a template, the prefix
template-
must not be used.
After this you need to pack and publish the package again (see Create the template package
point 2 and 3)
An existing version on the GitHub registry can't be overwritten. If you try it, then apax publish will create an error message.
See the documentation on custom templates.