Skip to content

Commit

Permalink
allow running scripts inline through annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Oct 4, 2022
1 parent d20e820 commit faf6acf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
6 changes: 3 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Runme Examples
==============

This `README.md` contains some example for testing this extension.
This `README.md` contains some examples for testing this extension.

# Extension Example Markdown Files

Expand All @@ -14,15 +14,15 @@ echo "Hello World"
```
## More Shell

```sh
```sh { inline=true }
echo "Foo 👀"
sleep 2
echo "Bar 🕺"
sleep 2
echo "Loo 🚀"
```

## Complexer Output
## Complex Output

```sh
yarn global add webdriverio
Expand Down
29 changes: 12 additions & 17 deletions src/extension/executors/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from 'vscode'
import { file } from 'tmp-promise'

import type { Metadata } from '../../types'
import { sh as inlineSh } from './shell'

const LABEL_LIMIT = 15
Expand All @@ -24,14 +23,13 @@ export function closeTerminalByScript (script: string) {
async function taskExecutor(
context: ExtensionContext,
exec: NotebookCellExecution,
doc: TextDocument,
metadata: Metadata
doc: TextDocument
): Promise<boolean> {
/**
* run shell inline if set as configuration
*/
const config = workspace.getConfiguration('runme')
if (config.get('shell.runinline')) {
if (config.get('shell.runinline') || exec.cell.metadata.attributes?.inline === 'true') {
return inlineSh(context, exec, doc)
}

Expand All @@ -53,7 +51,7 @@ async function taskExecutor(
cwd: path.dirname(doc.uri.path)
}),
)
const isBackground = metadata?.attributes?.["background"] === "true"
const isBackground = exec.cell.metadata.attributes?.['background'] === 'true'
taskExecution.isBackground = isBackground
taskExecution.presentationOptions = {
focus: true,
Expand Down Expand Up @@ -102,20 +100,17 @@ async function taskExecutor(
})
})

const giveItTime = new Promise<boolean>((resolve) =>
setTimeout(() => {
return resolve(true)
}, 2000)
)
if (isBackground) {
const giveItTime = new Promise<boolean>(
(resolve) => setTimeout(() => resolve(true), 2000))

const background = Promise.race([
p.then((exitCode) => {
return exitCode === 0
}),
giveItTime,
])
return Promise.race([
p.then((exitCode) => exitCode === 0),
giveItTime,
])
}

return (isBackground ? background : !Boolean(await p))
return !Boolean(await p)
}

export const sh = taskExecutor
Expand Down
7 changes: 3 additions & 4 deletions src/extension/executors/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import {
} from 'vscode'

import { OutputType } from '../../constants'
import type { CellOutput, Metadata } from '../../types'
import type { CellOutput } from '../../types'
import { bash } from './task'
import { deploy, login, logout } from './vercel/index'

export async function vercel (
context: ExtensionContext,
exec: NotebookCellExecution,
doc: TextDocument,
metadata: Metadata
doc: TextDocument
): Promise<boolean> {
const command = doc.getText()

Expand Down Expand Up @@ -73,5 +72,5 @@ export async function vercel (
/**
* other commands passed to the CLI
*/
return bash(context, exec, doc, metadata)
return bash(context, exec, doc)
}

0 comments on commit faf6acf

Please sign in to comment.