Run with mocha option in context menu

pull/5370/head
aniket-engg 3 years ago committed by Aniket
parent a6a61c0b55
commit 9670a31108
  1. 1
      apps/remix-ide/src/remixAppManager.js
  2. 11
      libs/remix-ui/workspace/src/lib/actions/index.ts
  3. 6
      libs/remix-ui/workspace/src/lib/components/file-explorer-context-menu.tsx
  4. 9
      libs/remix-ui/workspace/src/lib/components/file-explorer.tsx
  5. 1
      libs/remix-ui/workspace/src/lib/contexts/index.ts
  6. 7
      libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
  7. 2
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
  8. 2
      libs/remix-ui/workspace/src/lib/types/index.ts
  9. 6
      libs/remix-ui/workspace/src/lib/utils/index.ts

@ -114,6 +114,7 @@ export class RemixAppManager extends PluginManager {
const res = await fetch(this.pluginsDirectory)
plugins = await res.json()
plugins = plugins.filter((plugin) => {
if (plugin.name === 'scriptRunner') plugin.url = 'http://127.0.0.1:8081'
if (plugin.targets && Array.isArray(plugin.targets) && plugin.targets.length > 0) {
return (plugin.targets.includes('remix'))
}

@ -256,6 +256,17 @@ export const runScript = async (path: string) => {
})
}
export const runScriptWithMocha = async (path: string) => {
const provider = plugin.fileManager.currentFileProvider()
provider.get(path, (error, content: string) => {
if (error) {
return dispatch(displayPopUp(error))
}
if (content) content = content + '\n' + 'mocha.run()'
plugin.call('scriptRunner', 'execute', content)
})
}
export const emitContextMenuEvent = async (cmd: customAction) => {
await plugin.call(cmd.id, cmd.name, cmd)
}

@ -12,7 +12,7 @@ declare global {
const _paq = window._paq = window._paq || [] //eslint-disable-line
export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) => {
const { actions, createNewFile, createNewFolder, deletePath, renamePath, hideContextMenu, pushChangesToGist, publishFileToGist, publishFolderToGist, copy, paste, runScript, emit, pageX, pageY, path, type, focus, ...otherProps } = props
const { actions, createNewFile, createNewFolder, deletePath, renamePath, hideContextMenu, pushChangesToGist, publishFileToGist, publishFolderToGist, copy, paste, runScript, runScriptWithMocha, emit, pageX, pageY, path, type, focus, ...otherProps } = props
const contextMenuRef = useRef(null)
useEffect(() => {
contextMenuRef.current.focus()
@ -98,6 +98,10 @@ export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) =>
_paq.push(['trackEvent', 'fileExplorer', 'runScript'])
runScript(path)
break
case 'Run with Mocha':
_paq.push(['trackEvent', 'fileExplorer', 'runScriptWithMocha'])
runScriptWithMocha(path)
break
case 'Copy':
copy(path, type)
break

@ -221,6 +221,14 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
const runScriptWithMocha = async (path: string) => {
try {
props.dispatchRunScriptWithMocha(path)
} catch (error) {
props.toast('Run script with Mocha failed')
}
}
const emitContextMenuEvent = (cmd: customAction) => {
try {
props.dispatchEmitContextMenuEvent(cmd)
@ -454,6 +462,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
deletePath={deletePath}
renamePath={editModeOn}
runScript={runScript}
runScriptWithMocha={runScriptWithMocha}
copy={handleCopyClick}
paste={handlePasteClick}
emit={emitContextMenuEvent}

@ -25,6 +25,7 @@ export const FileSystemContext = createContext<{
dispatchCopyFile: (src: string, dest: string) => Promise<void>,
dispatchCopyFolder: (src: string, dest: string) => Promise<void>,
dispatchRunScript: (path: string) => Promise<void>,
dispatchRunScriptWithMocha: (path: string) => Promise<void>,
dispatchEmitContextMenuEvent: (cmd: customAction) => Promise<void>,
dispatchHandleClickFile: (path: string, type: 'file' | 'folder' | 'gist') => Promise<void>
dispatchHandleExpandPath: (paths: string[]) => Promise<void>

@ -5,7 +5,7 @@ import { Toaster } from '@remix-ui/toaster' // eslint-disable-line
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { FileSystemContext } from '../contexts'
import { browserReducer, browserInitialState } from '../reducers/workspace'
import { initWorkspace, fetchDirectory, removeInputField, deleteWorkspace, clearPopUp, publishToGist, createNewFile, setFocusElement, createNewFolder, deletePath, renamePath, copyFile, copyFolder, runScript, emitContextMenuEvent, handleClickFile, handleExpandPath, addInputField, createWorkspace, fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile } from '../actions'
import { initWorkspace, fetchDirectory, removeInputField, deleteWorkspace, clearPopUp, publishToGist, createNewFile, setFocusElement, createNewFolder, deletePath, renamePath, copyFile, copyFolder, runScript, runScriptWithMocha, emitContextMenuEvent, handleClickFile, handleExpandPath, addInputField, createWorkspace, fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile } from '../actions'
import { Modal, WorkspaceProps } from '../types'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { Workspace } from '../remix-ui-workspace'
@ -103,6 +103,10 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await runScript(path)
}
const dispatchRunScriptWithMocha = async (path: string) => {
await runScriptWithMocha(path)
}
const dispatchEmitContextMenuEvent = async (cmd: customAction) => {
await emitContextMenuEvent(cmd)
}
@ -212,6 +216,7 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
dispatchCopyFile,
dispatchCopyFolder,
dispatchRunScript,
dispatchRunScriptWithMocha,
dispatchEmitContextMenuEvent,
dispatchHandleClickFile,
dispatchHandleExpandPath

@ -198,6 +198,7 @@ export function Workspace () {
dispatchCopyFolder={global.dispatchCopyFolder}
dispatchPublishToGist={global.dispatchPublishToGist}
dispatchRunScript={global.dispatchRunScript}
dispatchRunScriptWithMocha={global.dispatchRunScriptWithMocha}
dispatchEmitContextMenuEvent={global.dispatchEmitContextMenuEvent}
dispatchHandleClickFile={global.dispatchHandleClickFile}
dispatchSetFocusElement={global.dispatchSetFocusElement}
@ -233,6 +234,7 @@ export function Workspace () {
dispatchCopyFolder={global.dispatchCopyFolder}
dispatchPublishToGist={global.dispatchPublishToGist}
dispatchRunScript={global.dispatchRunScript}
dispatchRunScriptWithMocha={global.dispatchRunScriptWithMocha}
dispatchEmitContextMenuEvent={global.dispatchEmitContextMenuEvent}
dispatchHandleClickFile={global.dispatchHandleClickFile}
dispatchSetFocusElement={global.dispatchSetFocusElement}

@ -78,6 +78,7 @@ export interface FileExplorerProps {
dispatchCopyFile: (src: string, dest: string) => Promise<void>,
dispatchCopyFolder: (src: string, dest: string) => Promise<void>,
dispatchRunScript: (path: string) => Promise<void>,
dispatchRunScriptWithMocha: (path: string) => Promise<void>,
dispatchPublishToGist: (path?: string, type?: string) => Promise<void>,
dispatchEmitContextMenuEvent: (cmd: customAction) => Promise<void>,
dispatchHandleClickFile: (path: string, type: 'file' | 'folder' | 'gist') => Promise<void>,
@ -108,6 +109,7 @@ export interface FileExplorerContextMenuProps {
publishFolderToGist?: (path?: string, type?: string) => void,
publishFileToGist?: (path?: string, type?: string) => void,
runScript?: (path: string) => void,
runScriptWithMocha?: (path: string) => void,
emit?: (cmd: customAction) => void,
pageX: number,
pageY: number,

@ -30,6 +30,12 @@ export const contextMenuActions: MenuItems = [{
extension: ['.js'],
multiselect: false,
label: ''
}, {
id: 'runWithMocha',
name: 'Run with Mocha',
extension: ['.js'],
multiselect: false,
label: ''
}, {
id: 'pushChangesToGist',
name: 'Push changes to gist',

Loading…
Cancel
Save