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
|
|
@ -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