## A New Kind of Tutorial ##
Since some time has passed now without getting any answers, I have experimented myself using
$Version
(* 12.3.1 for Microsoft Windows (64-bit) (June 19, 2021) *)
and
Eclipse IDE for Java Developers
Version: Neon.3 Release (4.6.3)
Build id: 20170314-1500
Plugin: Wolfram Workbench COre (10.1.1087)
So bear with me.
## 1 Creating Paclets in Wolfram Workbench 3.0 as of v12.2+ ##
#### 1.1 Create a new project ####
By selecting `File>New>Project` we can enter the process of creating a new project as usual:
<p><img src="https://i.sstatic.net/2F87y.png" width="300"></p>
##### 1.1.1 Select a wizard #####
We may select the `Application Project` wizard that is well suited for Wolfram Language package development:
<p><img src="https://i.sstatic.net/5A5Zi.png" width="300"></p>
##### 1.1.2 Wolfram Language project name and location #####
Next we create a new project called `MyFirstPaclet`. We can use the default workspace or a location of our choice. Since I am also using git for version control, I am collecting my projects in a directory called `\git-local`. Using the `Browse...` button I can create a new subdirectory `\git-local\MyFirstPaclet` and select it as Location:
<p><img src="https://i.sstatic.net/MRVgi.png" width="300"></p>
##### 1.1.3 Project References #####
In the next dialog we are asked for referenced projects—I will skip this for our minimal example by choosing `Next >`.
##### 1.1.4 Application details #####
Finally, we need to give the application name which I also set to `MyFirstPaclet`. I will leave the default choices for the boxes unchanged. Note, that we are _not choosing to create_ `PactletInfo.m` here—we will take care of this manually later on.
<p><img src="https://i.sstatic.net/6X7mP.png" width="300"></p>
Upon selecting `Finish` we should have a project structure that looks like this in the `Package Explorer` window (note, that I deselected any filters to show all files):
<p><img src="https://i.sstatic.net/spqqe.png" width="200"></p>
#### 1.2 Adapt the project structure ####
##### 1.2.1 Modify the project's properties #####
By right clicking on the project directory in the `Package Explorer` we can modify the project's properties. The `Wolfram` entry has ```<<MyFirstPaclet` ``` listed in the window titled `Execution Build Command`—we get rid of this and close the dialog with `Ok`.
<p><img src="https://i.sstatic.net/8XmKl.png" width="200">
<img src="https://i.sstatic.net/fCFHs.png" width="200"></p>
##### 1.2.2 Move and delete files #####
We will not need `init.m` and can thus *delete* it. We then *move* the file `MyFirstPaclet.m` into the directory `\Kernel` and we then *rename* (Refactor>Rename in the context menu) it to `MyFirstPaclet.wl` to be on the modern side of things; also we do not need the additional directory `MyFirstPaclet` so we can move the `\Kernel` directory to the top level and delete the subdirectory `\MyFirstPaclet`. We also delete the hidden file `.WolframResources` (it will always be recreated upon changes to the project properties).
Our project structure should by now look like this:
<p><img src="https://i.sstatic.net/B4oGz.png" width="200"></p>
#### 1.3 Create `PacketInfo.wl` ####
##### 1.3.1 Create custom `PacletInfo` file #####
Select the top level project directory `MyFirstPaclet` and enter the context menu with a right click to create a new `Other...` file and select the wizard for `PacletInfo File`:
<p><img src="https://i.sstatic.net/O7mLK.png" width="300"><img src="https://i.sstatic.net/ETPY9.png" width="300"></p>
In the `PacletInfo file` wizard dialog we change `PacletInfo.m` to `PacletInfo.wl` and enter the paclet name acordingly. We can also deselect the `Function Paclet` option since we will be completely rewriting the file:
<p><img src="https://i.sstatic.net/66m58.png" width="300"></p>
Upon closing the dialog with `Finish` a `PacletInfo.wl` file has be added at the top level of our project directory.
##### 1.3.2 Modify `PacletInfo.wl` #####
If it is not yet shown in the editor, we can double click the newly created `PacletInfo.wl` file to enter the editor:
(* Paclet Info File *)
(* created 2021.11.02*)
Paclet[
Name -> "MyFirstPaclet",
Version -> "0.0.1",
WolframVersion -> "6+",
Extensions -> {
{"Documentation", Language -> "English"}
}]
As we can see, the format is old and thus we can simply rewrite the `Paclet[ ]` section to be a `PacletObject[ ]`:
(* Paclet Info File *)
(* created 2021.11.02*)
PacletObject[
<|
"Name" -> "MyFirstPaclet",
"Version" -> "0.1",
"WolframVersion" -> "12.2+", (* paclet will be invisible to earlier versions *)
"Creator" -> "Bingo S. Little <bsl@domain>",
"Description" -> "My first paclet developed in Workbench.",
"Extensions" -> {
{ "Kernel", "Root" -> "Kernel", "Context"-> { "MyFirstPaclet`" } }
}
|>
]
## 2 Developing the paclet ##
#### 2.1 Writing code ####
We are now al set and can develop our package. In this simple example we will just edit the main package `MyFirstPaclet.wl` in the `/Kernel` directory (to meet the example created in the OP by using `CreatePaclet[ ]`) as follows:
(* Wolfram Language Package *)
(* Created by the Wolfram Workbench 02.11.2021 *)
BeginPackage["MyFirstPaclet`"]
(* Exported symbols added here with SymbolName::usage *)
SayHello
Begin["`Private`"]
(* Implementation of the package *)
SayHello[ name_String ] := Print[ "Hello ", name, "!" ]
End[]
EndPackage[]
When we are done we simply save the modified file `[Ctrl + s]`.
#### 2.2 Running code ####
As is the typical development process, once we have written some code, we can test it by *running the project*, for example by entering the context menu for our project directory:
<p><img src="https://i.sstatic.net/ieRR0.png" width="300"></p>
Even though the `Project Notebook` opens rather quickly, we should patiently wait until the `Console` tab shows `Initialization Complete`:
<p><img src="https://i.sstatic.net/iepsc.png" width="600"></p>
As we can see in the `Project Notebook`, our code works just fine:
<p><img src="https://i.sstatic.net/AIWW1.png" width="600"></p>
While our `Run Session` is still *running*, we can add another function to `MyFirstPaclet.wl`:
(* Wolfram Language Package *)
(* Created by the Wolfram Workbench 02.11.2021 *)
BeginPackage["MyFirstPaclet`"]
(* Exported symbols added here with SymbolName::usage *)
SayHello
SayGoodbye
Begin["`Private`"]
(* Implementation of the package *)
SayHello[ name_String ] := Print[ "Hello ", name, "!" ]
SayGoodbye[ name_String ] := Print[ "Goodbye ", name, "." ]
End[]
EndPackage[]
Upon saving the modified file `[Ctrl + s]` the console will automatically load the package again:
<p><img src="https://i.sstatic.net/WbR9T.png" width="200"></p>
And indeed we can immediately test the new code in the project notebook:
<p><img src="https://i.sstatic.net/uUVfS.png" width="600"></p>
## 3 Deploying the paclet ##
For what follows I assume that you are going to deploy your paclet to some `paclet server`. Again please refer to [Todd's excellent guide for how to set this up](https://www.wolframcloud.com/obj/tgayley/Published/PacletDevelopment.nb). Personally, I am using a local directory in my `\Dropbox` directory, which works out nicely.
#### 2.1 Creating a script for deployment ####
As before, by right clicking on the project directory we add a new `file`, which we call `deployPaclet.wls`:
<p><img src="https://i.sstatic.net/dlKpp.png" width="400"></p>
We then open `deployPaclet.wls` using the `Text Editor`:
<p><img src="https://i.sstatic.net/DQZ99.png" width="400"></p>
We then enter the following script, which of course has to be adapted, and save it `[Ctrl + s]`:
#!/usr/bin/env wolframscript
(* deploy the paclet to the local paclet server and update the paclet site files *)
Needs[ "PacletManager`" ]
$localPacletServer = "D:\\Dropbox\\BSLPacletServer" (* the location of the paclet server as needed for CreatPacletArchive[ ] *)
$thisPaclet = "D:\\git-local\\MyFirstPaclet"
CreatePacletArchive[ $thisPaclet, $localPacletServer ] (* create the .paclet archive *)
PacletManager`BuildPacletSitesFiles[ $localPacletServer ] (* update the paclet site files *)
Now, all we have to do is to tell Workbench that `deployPaclet.wls` is a script (it does not know by itself ;-) by entering the context menu with a right click for that file and selecting `open with other...` and `Wolfram Script`:
<p><img src="https://i.sstatic.net/AVY6L.png" width="400"><img src="https://i.sstatic.net/AIgZh.png" width="200"></p>
CLosing the dialog with `Ok` will already run the script and upon inspection of the paclet server directory we find:
<p><img src="https://i.sstatic.net/TruyB.png" width="400"></p>
From now on we should be able to deploy the paclet simply by selecting the script file `deployPaclet.wls` and pressing `F3`.
> *Note: If newer versions of a paclet are added to the paclet server, it may be necessary to remove the older versions before updating the index files. I will check this and append the script later on.*
#### 2.2 Using the paclet ####
If the `PacletSite` is registered, all one needs to do is to install the paclet once into `$UserBasePacletsDirectory` by
PacletInstall[ "MyFirstPaclet" ]
>Note: There is currently no way to force `PacletInstall` or `PacletInstallSubmit` to install paclets into `$BasePacletsDirectory`, but paclets can be placed there by hand to become visible to all users on the system.
Any notebook that needs the paclet then can use it with `Needs[ ]`:
Needs[ "MyFirstPaclet`" ]