From faf6acf26754f53874525e9dba5203821471c7d5 Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Tue, 4 Oct 2022 11:09:24 -0700 Subject: [PATCH] allow running scripts inline through annotations --- examples/README.md | 6 +++--- src/extension/executors/task.ts | 29 ++++++++++++----------------- src/extension/executors/vercel.ts | 7 +++---- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/examples/README.md b/examples/README.md index 571b824c8..b22ba0695 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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 @@ -14,7 +14,7 @@ echo "Hello World" ``` ## More Shell -```sh +```sh { inline=true } echo "Foo 👀" sleep 2 echo "Bar 🕺" @@ -22,7 +22,7 @@ sleep 2 echo "Loo 🚀" ``` -## Complexer Output +## Complex Output ```sh yarn global add webdriverio diff --git a/src/extension/executors/task.ts b/src/extension/executors/task.ts index 2d4d1b129..7bf70098b 100644 --- a/src/extension/executors/task.ts +++ b/src/extension/executors/task.ts @@ -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 @@ -24,14 +23,13 @@ export function closeTerminalByScript (script: string) { async function taskExecutor( context: ExtensionContext, exec: NotebookCellExecution, - doc: TextDocument, - metadata: Metadata + doc: TextDocument ): Promise { /** * 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) } @@ -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, @@ -102,20 +100,17 @@ async function taskExecutor( }) }) - const giveItTime = new Promise((resolve) => - setTimeout(() => { - return resolve(true) - }, 2000) - ) + if (isBackground) { + const giveItTime = new Promise( + (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 diff --git a/src/extension/executors/vercel.ts b/src/extension/executors/vercel.ts index 769e325a2..5f51f92cc 100644 --- a/src/extension/executors/vercel.ts +++ b/src/extension/executors/vercel.ts @@ -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 { const command = doc.getText() @@ -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) }