-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): Implement custom bundle task (#894)
* Add link settings * fix * Rename to api-dist-js * Correct import * Update CI * Implement bundleJS * Add comments * Add TODO * Fix import * Fix workflow --------- Co-authored-by: Artsiom Shamsutdzinau <[email protected]>
- Loading branch information
1 parent
3f916c7
commit 67d8151
Showing
9 changed files
with
68 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ jobs: | |
apps: sbt | ||
|
||
- name: scala-js build | ||
run: sbt ";language-server-apiJS/fullOptJS;aqua-apiJS/fullLinkJS" | ||
run: sbt ";language-server-apiJS/fullBundleJS;aqua-apiJS/fullBundleJS" | ||
|
||
- name: Import secrets | ||
uses: hashicorp/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ jobs: | |
- name: scala-js build | ||
env: | ||
SNAPSHOT: ${{ steps.version.outputs.id }} | ||
run: sbt ";language-server-apiJS/fastOptJS;aqua-apiJS/fastLinkJS" | ||
run: sbt ";language-server-apiJS/fastBundleJS;aqua-apiJS/fastBundleJS" | ||
|
||
- name: Import secrets | ||
uses: hashicorp/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ jobs: | |
apps: sbt | ||
|
||
- name: aqua-api build | ||
run: sbt "aqua-apiJS/fastLinkJS" | ||
run: sbt "aqua-apiJS/fastBundleJS" | ||
|
||
- name: Setup pnpm | ||
uses: pnpm/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import sbt.* | ||
import sbt.Keys.* | ||
|
||
import org.scalajs.linker.interface.Report | ||
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.* | ||
|
||
/** | ||
* Utility to add bundling js functionality to a project. | ||
*/ | ||
object BundleJS { | ||
// Bundle full js (result of fullLinkJS) | ||
val fullBundleJS = taskKey[Unit]("Full bundle JS") | ||
// Bundle fast js (result of fastLinkJS) | ||
val fastBundleJS = taskKey[Unit]("Fast bundle JS") | ||
|
||
/** | ||
* Add full/fast bundle JS tasks to a project. | ||
* | ||
* @param outputFilePath **relative to baseDirectory** path to output file | ||
* @return Seq of settings with tasks | ||
*/ | ||
def addBundleJS( | ||
outputFilePath: String // TODO: Accept `File` | ||
) = Seq( | ||
fullBundleJS := Def.taskDyn { | ||
bundleJS(fullLinkJS, outputFilePath) | ||
}.value, | ||
fastBundleJS := Def.taskDyn { | ||
bundleJS(fastLinkJS, outputFilePath) | ||
}.value | ||
) | ||
|
||
private def bundleJS( | ||
linkJSTask: TaskKey[Attributed[Report]], | ||
outputFilePath: String | ||
) = Def.taskDyn { | ||
val logger = streams.value.log | ||
|
||
val jsDir = (Compile / linkJSTask / scalaJSLinkerOutputDirectory).value | ||
val linkResult = (Compile / linkJSTask).value | ||
val outputFile = baseDirectory.value / outputFilePath | ||
|
||
linkResult.data.publicModules.toList match { | ||
case Nil => | ||
throw new RuntimeException("No public modules generated") | ||
case _ :: _ :: _ => | ||
throw new RuntimeException("More than one public module generated") | ||
case module :: Nil => | ||
val jsFile = jsDir / module.jsFileName | ||
Def.task { | ||
logger.info(s"Copying $jsFile to $outputFile") | ||
IO.copyFile(jsFile, outputFile) | ||
} | ||
} | ||
} | ||
} |