mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-17 16:38:18 +00:00
feature: cloudcmd: user-menu: root
This commit is contained in:
parent
1c0021dbb6
commit
32f89d3874
5 changed files with 45 additions and 43 deletions
|
|
@ -1,43 +1,31 @@
|
|||
export default {
|
||||
'F2 - Rename file': async ({DOM}) => {
|
||||
await DOM.renameCurrent();
|
||||
},
|
||||
'L - Lint': async ({CloudCmd}) => {
|
||||
const {TerminalRun} = CloudCmd;
|
||||
await run(TerminalRun, 'npm run lint');
|
||||
},
|
||||
'F - Fix Lint': async ({CloudCmd}) => {
|
||||
const {TerminalRun} = CloudCmd;
|
||||
await run(TerminalRun, 'npm run fix:lint');
|
||||
},
|
||||
'T - Test': async ({CloudCmd}) => {
|
||||
const {TerminalRun} = CloudCmd;
|
||||
|
||||
await run(TerminalRun, 'npm run test');
|
||||
},
|
||||
'C - Coverage': async ({CloudCmd}) => {
|
||||
const {TerminalRun} = CloudCmd;
|
||||
|
||||
await run(TerminalRun, 'npm run coverage');
|
||||
},
|
||||
'D - Build Dev': async ({CloudCmd}) => {
|
||||
const {TerminalRun} = CloudCmd;
|
||||
|
||||
await run(TerminalRun, 'npm run build:client:dev');
|
||||
CloudCmd.refresh();
|
||||
},
|
||||
'P - Build Prod': async ({CloudCmd}) => {
|
||||
const {TerminalRun} = CloudCmd;
|
||||
|
||||
await run(TerminalRun, 'npm run build:client');
|
||||
CloudCmd.refresh();
|
||||
},
|
||||
'F2 - Rename File': renameCurrent,
|
||||
'L - Lint': run('npm run lint'),
|
||||
'F - Fix Lint': run('npm run fix:lint'),
|
||||
'T - Test': run('npm run test'),
|
||||
'C - Coverage': run('npm run coverage'),
|
||||
'D - Build Dev': run('npm run build:client:dev'),
|
||||
'P - Build Prod': run('npm run build:client'),
|
||||
};
|
||||
|
||||
async function run(TerminalRun, command) {
|
||||
await TerminalRun.show({
|
||||
command,
|
||||
closeMessage: 'Press any key to close Terminal',
|
||||
autoClose: false,
|
||||
});
|
||||
async function renameCurrent(DOM) {
|
||||
await DOM.renameCurrent();
|
||||
}
|
||||
|
||||
function run(command) {
|
||||
return async ({CloudCmd, DOM}) => {
|
||||
const {TerminalRun, config} = CloudCmd;
|
||||
|
||||
const {CurrentInfo} = DOM;
|
||||
const {dirPath} = CurrentInfo;
|
||||
|
||||
const cwd = config('root') + dirPath;
|
||||
|
||||
return await TerminalRun.show({
|
||||
cwd,
|
||||
command,
|
||||
closeMessage: 'Press any key to close Terminal',
|
||||
autoClose: false,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ export async function init() {
|
|||
}
|
||||
|
||||
export async function show(options = {}) {
|
||||
await runTerminal(options);
|
||||
return await runTerminal(options);
|
||||
}
|
||||
|
||||
const runTerminal = promisify((options, fn) => {
|
||||
|
|
|
|||
|
|
@ -242,6 +242,7 @@ function cloudcmdMiddle({modules, config}) {
|
|||
}),
|
||||
userMenu({
|
||||
menuName: '.cloudcmd.menu.js',
|
||||
config,
|
||||
}),
|
||||
rest({
|
||||
config,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ transpile('');
|
|||
|
||||
const PREFIX = '/api/v1/user-menu';
|
||||
|
||||
export const userMenu = currify(async ({menuName, readFile = _readFile}, req, res, next) => {
|
||||
export const userMenu = currify(async ({menuName, readFile = _readFile, config}, req, res, next) => {
|
||||
if (!req.url.startsWith(PREFIX))
|
||||
return next();
|
||||
|
||||
|
|
@ -24,12 +24,13 @@ export const userMenu = currify(async ({menuName, readFile = _readFile}, req, re
|
|||
res,
|
||||
menuName,
|
||||
readFile,
|
||||
config,
|
||||
});
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
async function onGET({req, res, menuName, readFile}) {
|
||||
async function onGET({req, res, menuName, readFile, config}) {
|
||||
const {dir} = req.query;
|
||||
const url = req.url.replace(PREFIX, '');
|
||||
|
||||
|
|
@ -40,8 +41,9 @@ async function onGET({req, res, menuName, readFile}) {
|
|||
|
||||
const {findUp} = await import('find-up');
|
||||
|
||||
const cwd = join(config('root'), dir);
|
||||
const [errorFind, currentMenuPath] = await tryToCatch(findUp, [menuName], {
|
||||
cwd: dir,
|
||||
cwd,
|
||||
});
|
||||
|
||||
if (errorFind && errorFind.code !== 'ENOENT')
|
||||
|
|
|
|||
|
|
@ -24,8 +24,11 @@ const fixtureCopy = readFileSync(fixtureCopyName, 'utf8');
|
|||
const fixtureCopyFix = readFileSync(fixtureCopyFixName, 'utf8');
|
||||
|
||||
test('cloudcmd: user menu', async (t) => {
|
||||
const config = stub().returns('');
|
||||
const userMenuFile = getUserMenuFile();
|
||||
|
||||
const options = {
|
||||
config,
|
||||
menuName: '.cloudcmd.menu.js',
|
||||
};
|
||||
|
||||
|
|
@ -38,10 +41,13 @@ test('cloudcmd: user menu', async (t) => {
|
|||
});
|
||||
|
||||
test('cloudcmd: user menu: io.mv', async (t) => {
|
||||
const config = stub().returns('');
|
||||
const readFile = stub().returns(fixtureMove);
|
||||
|
||||
const options = {
|
||||
menuName: '.cloudcmd.menu.js',
|
||||
readFile,
|
||||
config,
|
||||
};
|
||||
|
||||
const {request} = serveOnce(userMenu);
|
||||
|
|
@ -55,8 +61,10 @@ test('cloudcmd: user menu: io.mv', async (t) => {
|
|||
});
|
||||
|
||||
test('cloudcmd: user menu: default menu', async (t) => {
|
||||
const config = stub().returns('');
|
||||
const options = {
|
||||
menuName: '111.cloudcmd.menu.js',
|
||||
config,
|
||||
};
|
||||
|
||||
const {request} = serveOnce(userMenu);
|
||||
|
|
@ -70,10 +78,13 @@ test('cloudcmd: user menu: default menu', async (t) => {
|
|||
});
|
||||
|
||||
test('cloudcmd: user menu: io.cp', async (t) => {
|
||||
const config = stub().returns('');
|
||||
const readFile = stub().returns(fixtureCopy);
|
||||
|
||||
const options = {
|
||||
menuName: '.cloudcmd.menu.js',
|
||||
readFile,
|
||||
config,
|
||||
};
|
||||
|
||||
const {request} = serveOnce(userMenu);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue