mirror of
https://github.com/strapi/strapi.git
synced 2025-12-18 02:33:53 +00:00
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
|
|
import { Command } from 'commander';
|
||
|
|
import crypto from 'crypto';
|
||
|
|
import deployProject from './deploy-project';
|
||
|
|
import login from './login';
|
||
|
|
import logout from './logout';
|
||
|
|
import createProject from './create-project';
|
||
|
|
import { CLIContext } from './types';
|
||
|
|
import { getLocalConfig, saveLocalConfig } from './config/local';
|
||
|
|
|
||
|
|
export const cli = {
|
||
|
|
deployProject,
|
||
|
|
login,
|
||
|
|
logout,
|
||
|
|
createProject,
|
||
|
|
};
|
||
|
|
|
||
|
|
const cloudCommands = [deployProject, login, logout];
|
||
|
|
|
||
|
|
async function initCloudCLIConfig() {
|
||
|
|
const localConfig = await getLocalConfig();
|
||
|
|
|
||
|
|
if (!localConfig.deviceId) {
|
||
|
|
localConfig.deviceId = crypto.randomUUID();
|
||
|
|
}
|
||
|
|
|
||
|
|
await saveLocalConfig(localConfig);
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function buildStrapiCloudCommands({
|
||
|
|
command,
|
||
|
|
ctx,
|
||
|
|
argv,
|
||
|
|
}: {
|
||
|
|
command: Command;
|
||
|
|
ctx: CLIContext;
|
||
|
|
argv: string[];
|
||
|
|
}) {
|
||
|
|
await initCloudCLIConfig();
|
||
|
|
// Load all commands
|
||
|
|
for (const cloudCommand of cloudCommands) {
|
||
|
|
try {
|
||
|
|
// Add this command to the Commander command object
|
||
|
|
const subCommand = await cloudCommand.command({ command, ctx, argv });
|
||
|
|
|
||
|
|
if (subCommand) {
|
||
|
|
command.addCommand(subCommand);
|
||
|
|
}
|
||
|
|
} catch (e) {
|
||
|
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export * as services from './services';
|
||
|
|
|
||
|
|
export * from './types';
|