-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cubejs-cli): Improve external commands support
- Loading branch information
Showing
7 changed files
with
66 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,6 @@ | ||
import type { CommanderStatic } from 'commander'; | ||
import { displayError, requireFromPackage, requiredPackageExists } from '../utils'; | ||
|
||
async function devServerCommand() { | ||
await requiredPackageExists('@cubejs-backend/server'); | ||
|
||
const OriginalCommandPackage = await requireFromPackage('@cubejs-backend/server/dist/command/dev-server'); | ||
// eslint-disable-next-line new-cap | ||
const Command = new OriginalCommandPackage.default([]); | ||
return Command.run(); | ||
} | ||
import { proxyCommand } from './proxy-command'; | ||
|
||
export function configureDevServerCommand(program: CommanderStatic) { | ||
program | ||
.command('dev-server') | ||
.description('Run server in Development mode') | ||
.action( | ||
() => devServerCommand() | ||
.catch((e) => displayError(e.stack || e)) | ||
) | ||
.on('--help', () => { | ||
console.log(''); | ||
console.log('Examples:'); | ||
console.log(''); | ||
console.log(' $ cubejs dev-server'); | ||
}); | ||
return proxyCommand(program, 'dev-server'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { CommanderStatic } from 'commander'; | ||
import { displayError, packageExists, requireFromPackage } from '../utils'; | ||
import chalk from 'chalk'; | ||
|
||
export async function proxyCommand(program: CommanderStatic, command: string) { | ||
const serverPackageExists = packageExists('@cubejs-backend/server'); | ||
|
||
const commandInfo = program | ||
.command(command); | ||
|
||
if (serverPackageExists) { | ||
const OriginalCommandPackage = await requireFromPackage(`@cubejs-backend/server/dist/command/${command}`); | ||
// eslint-disable-next-line new-cap | ||
const Command = new OriginalCommandPackage.default([]); | ||
|
||
commandInfo | ||
.description(OriginalCommandPackage.default.description) | ||
.action( | ||
() => Command.run().catch( | ||
(e: any) => displayError(e.stack || e.message) | ||
) | ||
); | ||
} else { | ||
commandInfo | ||
.description( | ||
chalk.red('Unavailable.') + ' Please run this command from project directory.' | ||
) | ||
.action( | ||
() => displayError('Unavailable. Please run this command from project directory.') | ||
); | ||
} | ||
|
||
commandInfo | ||
.on('--help', () => { | ||
console.log(''); | ||
console.log('Examples:'); | ||
console.log(''); | ||
console.log(` $ cubejs ${command}`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,6 @@ | ||
import type { CommanderStatic } from 'commander'; | ||
import { displayError, requiredPackageExists, requireFromPackage } from '../utils'; | ||
import { proxyCommand } from './proxy-command'; | ||
|
||
async function serverCommand() { | ||
await requiredPackageExists('@cubejs-backend/server'); | ||
|
||
const OriginalCommandPackage = await requireFromPackage('@cubejs-backend/server/dist/command/server'); | ||
// eslint-disable-next-line new-cap | ||
const Command = new OriginalCommandPackage.default([]); | ||
return Command.run(); | ||
} | ||
|
||
export function configureServerCommand(program: CommanderStatic) { | ||
program | ||
.command('server') | ||
.description('Run server in Production mode') | ||
.action( | ||
() => serverCommand() | ||
.catch((e) => displayError(e.stack || e)) | ||
) | ||
.on('--help', () => { | ||
console.log(''); | ||
console.log('Examples:'); | ||
console.log(''); | ||
console.log(' $ cubejs server'); | ||
}); | ||
export async function configureServerCommand(program: CommanderStatic) { | ||
return proxyCommand(program, 'server'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters