stdlib: yarn: support cwd, args and packages

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-05-29 01:21:52 -07:00
parent 3605d399c9
commit 39527b761d

View File

@ -15,6 +15,14 @@ import (
// Application source code
source: dagger.#Artifact @dagger(input)
// Extra alpine packages to install
package: {
[string]: true | false | string @dagger(input)
}
// working directory to use
cwd: *"." | string @dagger(input)
// Environment variables
env: {
[string]: string @dagger(input)
@ -31,6 +39,9 @@ import (
// Run this yarn script
script: string | *"build" @dagger(input)
// Optional arguments for the script
args: [...string] | *[] @dagger(input)
build: os.#Dir & {
from: ctr
path: "/build"
@ -38,7 +49,7 @@ import (
ctr: os.#Container & {
image: alpine.#Image & {
package: {
"package": package & {
bash: "=~5.1"
yarn: "=~1.22"
}
@ -46,13 +57,17 @@ import (
shell: path: "/bin/bash"
command: """
[ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME"
yarn install --production false
yarn run "$YARN_BUILD_SCRIPT"
yarn --cwd "$YARN_CWD" install --production false
opts=( $(echo $YARN_ARGS) )
yarn --cwd "$YARN_CWD" run "$YARN_BUILD_SCRIPT" ${opts[@]}
mv "$YARN_BUILD_DIRECTORY" /build
"""
"env": env & {
YARN_BUILD_SCRIPT: script
YARN_ARGS: strings.Join(args, "\n")
YARN_CACHE_FOLDER: "/cache/yarn"
YARN_CWD: cwd
YARN_BUILD_DIRECTORY: buildDir
if writeEnvFile != "" {
ENVFILE_NAME: writeEnvFile