Skip to content

Commit

Permalink
expose createSession utility
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Mar 28, 2024
1 parent 3544e99 commit a73bbcc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/cli/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { cmdArgs as runCmdArgs } from './run.js'
import { CLI_EPILOGUE } from '../constants.js'
import { initBrowserSession } from '../utils.js'
import { deleteSession, deleteAllSessions, listSessions, saveSession } from '../session.js'
import { RunnerArgs } from 'types.js'

export const command = 'session [options]'
export const desc = 'Manage `bx` sessions.'
Expand Down Expand Up @@ -79,10 +80,14 @@ export const handler = async () => {
sessionName = `${browserName}-${browserNameSessions.length}`
}

await createSession(sessionName, { ...params, browserName })
console.log(`Session "${sessionName}" started, you can now run scripts faster e.g. \`npx bx ./script.js --sessionName ${sessionName}\``)
process.exit(0)
}

export async function createSession (sessionName: string, params: RunnerArgs) {
const headless = Boolean(params.headless)
const rootDir = params.rootDir || process.cwd()
const browser = await initBrowserSession({ ...params, rootDir, headless, browserName })
const browser = await initBrowserSession({ ...params, rootDir, headless })
await saveSession(browser, sessionName)
console.log(`Session "${sessionName}" started, you can now run scripts faster e.g. \`npx bx ./script.js --sessionName ${sessionName}\``)
process.exit(0)
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './session.js'
export { run } from './cli/run.js'
export { run } from './cli/run.js'
export { createSession } from './cli/session.js'

0 comments on commit a73bbcc

Please sign in to comment.