Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions lib/hooks/usePantry.getScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,7 @@ export const getScript = async (pkg: Package, key: 'build' | 'test', deps: Insta
`
}

let fixture_key = key == 'build' ? 'prop' : 'fixture'
let fixture = obj[fixture_key]
if (fixture) {
fixture_key = fixture_key.toUpperCase()
fixture = mm.apply(validate.str(fixture), tokens)
run = undent`
OLD_${fixture_key}=$${fixture_key}
${fixture_key}=$(mktemp)

cat <<DEV_PKGX_EOF > $${fixture_key}
${fixture}
DEV_PKGX_EOF

${run}

rm -f $${fixture_key}

if test -n "$${fixture_key}"; then
${fixture_key}=$OLD_${fixture_key}
else
unset ${fixture_key}
fi
`
}
run = add_fixture(run, key, obj, tokens)

return run.trim()
} else {
Expand Down Expand Up @@ -155,6 +132,38 @@ function expand_env(env: PlainObject, pkg: Package, tokens: { from: string, to:
}).join("\n")
}

function add_fixture(run: string, key: string, obj: any, tokens: { from: string, to: string }[]) {
let fixture_key = key == 'build' ? 'prop' : 'fixture'
let fixture = obj[fixture_key]
if (!fixture) return run

let extname = `${fixture['extname'] || ''}`
while (extname.startsWith('.')) extname = extname.slice(1)

const contents = isPlainObject(fixture) ? fixture['content'] : fixture

fixture_key = fixture_key.toUpperCase()
fixture = useMoustaches().apply(validate.str(contents), tokens)
return undent`
OLD_${fixture_key}=$${fixture_key}
${fixture_key}=$(mktemp)${extname ? `.${extname}` : ''}

cat <<DEV_PKGX_EOF > $${fixture_key}
${fixture}
DEV_PKGX_EOF

${run}

rm -f $${fixture_key}*

if test -n "$${fixture_key}"; then
${fixture_key}=$OLD_${fixture_key}
else
unset ${fixture_key}
fi
`
}

//FIXME these are copy pasta from usePantry because we build to a different prefix so need control over the moustaches
export function expand_env_obj(env_: PlainObject, pkg: Package, tokens: { from: string, to: string }[]): Record<string, string> {
const env = {...env_}
Expand Down
9 changes: 8 additions & 1 deletion projects/pyapp.com/1/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ provides:
- bin/myapp

test:
myapp
- myapp

- run: |
test $(basename $FIXTURE .rb).rb = $(basename $FIXTURE)
test $(cat $FIXTURE) = foo
fixture:
content: foo
extname: .rb