Skip to content

Commit

Permalink
feat(cli): add customScript option to module command
Browse files Browse the repository at this point in the history
  • Loading branch information
productdevbook committed Mar 3, 2024
1 parent 46c21f7 commit 1d5b7d4
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions packages-core/cli/src/commands/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { execSync } from 'node:child_process'
import { defineCommand } from 'citty'
import { consola } from 'consola'
import { parseNa, run } from '@antfu/ni'
Expand Down Expand Up @@ -27,6 +28,11 @@ export default defineCommand({
description: 'Name of the script',
alias: 's',
},
customScript: {
type: 'boolean',
description: 'Custom script',
alias: 'cs',
},
},
async run({ args }) {
try {
Expand All @@ -51,18 +57,26 @@ export default defineCommand({
if (!selectedScript)
consola.error('No script found')

try {
await run(async (agent, args, ctx) => {
const command = await parseNa(agent, args, ctx)
return command ? command.replace(/"/g, '') : undefined
}, [selectedScript], { programmatic: true }).then(() => {
consola.success('Script executed successfully')
}).catch((error) => {
if (!args.npx) {
try {
await run(async (agent, args, ctx) => {
const command = await parseNa(agent, args, ctx)
return command ? command.replace(/"/g, '') : undefined
}, [selectedScript], { programmatic: true }).then(() => {
consola.success('Script executed successfully')
}).catch((error) => {
consola.error(error)
})
}
catch (error) {
consola.error(error)
})
}
}
catch (error) {
consola.error(error)
else {
execSync(selectedScript, {
stdio: 'inherit',
cwd: file.config.dir.pergel,
})
}
}
catch (error) {
Expand Down

0 comments on commit 1d5b7d4

Please sign in to comment.