From ac82fd2aa65b9d64eaa6363fecd4b38a6654a2b5 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sun, 20 Jun 2021 17:46:03 +0300 Subject: [PATCH] docs(user-menu) module.exports -> export default --- User-Menu-Cookbook.md | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/User-Menu-Cookbook.md b/User-Menu-Cookbook.md index 30a6b94..ed6120f 100644 --- a/User-Menu-Cookbook.md +++ b/User-Menu-Cookbook.md @@ -11,7 +11,7 @@ You can combine them in any way, and also add yours 😉. The simplest way to show rename file dialog. ```js -module.exports = { +export default { 'F2 - Rename file': async ({DOM}) => { await DOM.renameCurrent(); }, @@ -37,11 +37,13 @@ export default { Simple example of running bash scripts with help of `TerminalRun`. ```js +'use strict'; + const isMp3 = (a) => /\.mp3$/.test(a); -module.exports = { +export default { 'F - Convert flac to mp3': async ({DOM, CloudCmd}) => { - const {IO, CurrentInfo} = DOM; + const {IO, CurrentInfo} = DOM; const root = CloudCmd.config('root'); const {dirPath, files} = CurrentInfo; @@ -62,12 +64,30 @@ module.exports = { const names = DOM.getFilenames(files); const mp3Names = names.filter(isMp3); - + await IO.createDirectory(mp3Dir); await IO.move(dirPath, mp3Dir, mp3Names); - + await CloudCmd.refresh(); }, +}; + +async function createDefaultMenu({path, data, DOM, CloudCmd}) { + const {IO} = DOM; + + await IO.write(path, data); + await CloudCmd.refresh(); + + DOM.setCurrentByName('.cloudcmd.menu.js'); + + await CloudCmd.EditFile.show(); +} + +async function readDefaultMenu({prefix}) { + const res = await fetch(`${prefix}/api/v1/user-menu/default`); + const data = await res.text(); + + return data; } ``` @@ -76,7 +96,7 @@ module.exports = { This is how you can create `.cloudcmd.menu.js` file. ```js -module.exports = { +export default { 'C - Create User Menu File': async ({DOM, CloudCmd}) => { const {CurrentInfo} = DOM; @@ -116,7 +136,7 @@ async function readDefaultMenu({prefix}) { ## Compare Directories ```js -module.exports = +export default { 'D - Compare directories': async ({DOM}) => { const { CurrentInfo, @@ -174,7 +194,7 @@ function compare(a, b) { ## Execute Npm Script ```js -module.exports = { +export default { 'D - Build Dev': async ({CloudCmd}) => { await CloudCmd.TerminalRun.show({ command: 'npm run build:client:dev',