Skip to content

Commit

Permalink
feat: Add exec task and remove install task (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jan 5, 2024
1 parent 74f6400 commit 8fa4d4e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 43 deletions.
9 changes: 2 additions & 7 deletions packages/pinion/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { version } = JSON.parse(readFileSync(join(__dirname, '../package.json'),
const BASE_ACTIONS = ['help', '--help', '-h', '--version', '-V']

export const cli = async (cmd: string[]) => {
const [generatorFile, ...argRest] = cmd
const [generatorFile, ...argv] = cmd
const program = new Command()

program.name('pinion').description('The Pinion CLI')
Expand All @@ -37,12 +37,7 @@ export const cli = async (cmd: string[]) => {
}

const { generate } = await loadModule(moduleName)
const generatorContext = getContext(
{
argv: argRest
},
{}
)
const generatorContext = getContext({ argv }, {})

if (typeof generate !== 'function') {
throw new Error('The generator file must export a generate function')
Expand Down
21 changes: 21 additions & 0 deletions packages/pinion/src/tasks/exec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Callable, getCallable, PinionContext } from '../core.js'
import { addTrace } from './helpers.js'

export const exec =
<C extends PinionContext>(cmd: Callable<string, C>, _args: string[] = []) =>
async (ctx: C) => {
const command = await getCallable(cmd, ctx)
const args = await getCallable(_args, ctx)

ctx.pinion.logger.notice(`Running ${command} ${args.join(' ')}`)

const exitCode = await ctx.pinion.exec(command, args, {
cwd: ctx.cwd
})

if (exitCode !== 0) {
throw new Error(`Command "${command}" exited with error code ${exitCode}`)
}

return addTrace(ctx, 'exec', { command, args })
}
2 changes: 1 addition & 1 deletion packages/pinion/src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export * from './render.js'
export * from './inject.js'
export * from './run.js'
export * from './fs.js'
export * from './packager.js'
export * from './exec.js'
export * from './conditionals.js'
export * from './commander.js'
export { Command } from 'commander'
27 changes: 0 additions & 27 deletions packages/pinion/src/tasks/packager.ts

This file was deleted.

10 changes: 2 additions & 8 deletions packages/pinion/test/templates/pinion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
prepend,
append,
before,
install,
exec,
copyFiles
} from '../../lib/index.js'

Expand Down Expand Up @@ -50,13 +50,7 @@ export const generate = (ctx: GeneratorArguments) =>
}
}))
)
.then(
when(
(ctx) => !!ctx.name && !ctx.age,
install(['@feathersjs/feathers'], false, 'echo'),
install(['@feathersjs/feathers'], true, 'echo')
)
)
.then(when((ctx) => !!ctx.name && !ctx.age, exec('echo', ['"This is a test"'])))
.then(copyFiles(fromFile(__dirname), toFile('tmp', 'copy')))
.then(runGenerators(__dirname))
.then((ctx) => ({
Expand Down

0 comments on commit 8fa4d4e

Please sign in to comment.