11package com .ossuminc .sbt
22
3- import com .typesafe .sbt .packager .archetypes .JavaAppPackaging
4- import com .typesafe .sbt .packager .graalvmnativeimage .GraalVMNativeImagePlugin
5- import com .typesafe .sbt .packager .universal .UniversalDeployPlugin
63import sbt .*
74import sbt .Keys .*
85import sbt .librarymanagement .Resolver
96
107object OssumIncPlugin extends AutoPlugin {
118
129 object autoImport {
13-
14- object Root {
15-
16- /** Define a Root level project whether it is for a single-project repo or a unirepo with many sub-projects. This
17- * project is configured with a shell prompt, and the standard project information at ThisBuild scope
18- * @param ghRepoName
19- * The name of the github repository we are building
20- * @param ghOrgName
21- * THe name of the github organization/user that contains the `ghRepoName`
22- * @param orgPackage
23- * The organization part of the JVM package this repo uses for its code
24- * @param orgName
25- * The legal name of the organization
26- * @param orgPage
27- * The URL of the website to use for the organization
28- * @param startYr
29- * The year in which this project started, for copyright purposes
30- * @param devs
31- * A list of Developer specifications to include in POM (required by Maven)
32- * @return
33- * The project that was created and configured.
34- */
35- def apply (
36- ghRepoName : String = " " ,
37- ghOrgName : String = " ossuminc" ,
38- orgPackage : String = " com.ossuminc" ,
39- orgName : String = " Ossum, Inc." ,
40- orgPage : URL = url(" https://ossuminc.com/" ),
41- maintainerEmail : String = " reid@ossuminc.com" ,
42- startYr : Int = 2023 ,
43- devs : List [Developer ] = List .empty
44- ): Project = {
45- Project
46- .apply(" root" , file(System .getProperty(" user.dir" )))
47- .enablePlugins(OssumIncPlugin )
48- .configure(
49- helpers.RootProjectInfo .initialize(
50- ghRepoName,
51- ghOrgName,
52- startYr,
53- orgPackage,
54- orgName,
55- orgPage,
56- maintainerEmail,
57- devs
58- ),
59- helpers.Resolvers .configure
60- )
61- }
62- }
63-
64- object Module {
65-
66- /** Define a sub-project or module of the root project. Make sure to use the [[Root ]] function before this Module
67- * is defined. No configuration is applied but you can do that by using the various With.* functions in this
68- * plugin. `With.typical` is typical for Scala3 development
69- * @param dirName
70- * The name of the sub-directory in which the module is located.
71- * @param modName
72- * The name of the artifact to be published. If blank, it will default to the dirName
73- * @return
74- * The project that was created and configured.
75- */
76- def apply (dirName : String , modName : String = " " ): Project = {
77- Project
78- .apply(dirName, file(dirName))
79- .enablePlugins(OssumIncPlugin , JavaAppPackaging )
80- .settings(
81- name := dirName,
82- moduleName := { if (modName.isEmpty) dirName else modName }
83- )
84- }
85- }
86-
87- object Plugin {
88-
89- /** Define a sub-project that produces an sbt plugin. It is necessary to also have used the [[Root ]] function
90- * because what that function sets up is necessary for publishing this module. scoverage doesn't work with sbt
91- * plugins so it is disabled.
92- * @param dirName
93- * The name of the directory in which the plugin code and tests exist
94- * @param modName
95- * The name of the published artifact. If blank, the `dirName` will be used
96- * @return
97- * The configured sbt project that is ready to build an sbt plugin
98- */
99- def apply (dirName : String , modName : String = " " ): Project = {
100- Project
101- .apply(dirName, file(dirName))
102- .enablePlugins(OssumIncPlugin )
103- .configure(helpers.Plugin .configure)
104- .settings(
105- name := dirName,
106- moduleName := { if (modName.isEmpty) dirName else modName }
107- )
108- }
109- }
110-
111- object Program {
112-
113- /** Define a sub-project that produces an executable program. It is necessary to also have used the [[Root ]]
114- * function because what that function sets up is necessary for publishing this module.
115- * @param dirName
116- * The name of the directory in which the plugin code and tests exist
117- * @param appName
118- * The name of the published artifact. If blank, the `dirName` will be used
119- * @return
120- * The configured sbt project that is ready to build an sbt plugin
121- */
122- def apply (dirName : String , appName : String ): Project = {
123- Project
124- .apply(dirName, file(dirName))
125- .enablePlugins(OssumIncPlugin , JavaAppPackaging , UniversalDeployPlugin , GraalVMNativeImagePlugin )
126- .settings(
127- name := dirName,
128- moduleName := { if (appName.isEmpty) dirName else appName }
129- )
130- }
131- }
132-
10+ // The type of function that `Project.configure` takes as its argument
13311 private type ConfigFunc = Project => Project
13412
13+ // Major declarations
14+ val Root : com.ossuminc.sbt.Root .type = com.ossuminc.sbt.Root
15+ val Module : com.ossuminc.sbt.Module .type = com.ossuminc.sbt.Module
16+ val Plugin : com.ossuminc.sbt.Plugin .type = com.ossuminc.sbt.Plugin
17+ val Program : com.ossuminc.sbt.Program .type = com.ossuminc.sbt.Program
18+ val CrossModule : com.ossuminc.sbt.CrossModule .type = com.ossuminc.sbt.CrossModule
19+ val JVM : CrossModule .Target = CrossModule .JVMTarget
20+ val JS : CrossModule .Target = CrossModule .JSTarget
21+ val Native : CrossModule .Target = CrossModule .NativeTarget
22+
23+ // Clauses to customize the major declarations
13524 object With {
13625 val akka : ConfigFunc = helpers.Akka .configure
13726 val aliases : ConfigFunc = helpers.HandyAliases .configure
@@ -140,6 +29,7 @@ object OssumIncPlugin extends AutoPlugin {
14029 val git : ConfigFunc = helpers.Git .configure
14130 val header : ConfigFunc = helpers.Header .configure
14231 val java : ConfigFunc = helpers.Java .configure
32+ val javascript : ConfigFunc = helpers.Javascript .configure
14333 val misc : ConfigFunc = helpers.Miscellaneous .configure
14434 val native : ConfigFunc = helpers.Native .configure
14535 val publishing : ConfigFunc = helpers.SonatypePublishing .configure
@@ -188,6 +78,13 @@ object OssumIncPlugin extends AutoPlugin {
18878 these(java, misc, build_info, release)(project)
18979 }
19080
81+ def js (
82+ hasMain : Boolean = false ,
83+ forProd : Boolean = false
84+ )(project : Project ): Project = {
85+ helpers.Javascript .configure(hasMain, forProd)(project)
86+ }
87+
19188 def native (
19289 buildTarget : String = " static" ,
19390 targetTriple : String = " arm64-apple-macosx11.0.0" ,
0 commit comments