Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
281 changes: 272 additions & 9 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"nock": "13.5.1",
"prettier": "npm:[email protected]",
"rimraf": "5.0.5",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
"dependencies": {
Expand All @@ -148,6 +149,7 @@
"check-disk-space": "3.4.0",
"cli-columns": "^4.0.0",
"cli-table3": "^0.6.3",
"commander": "^11.1.0",
"configstore": "5.0.1",
"copy-dir": "0.4.0",
"debug": "4.3.4",
Expand Down
83 changes: 83 additions & 0 deletions src/commands/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import chalk from 'chalk';

import app from '../lib/api/app';
import { BaseVIPCommand } from '../lib/base-command';
import { getEnvIdentifier } from '../lib/cli/command';
import { trackEvent } from '../lib/tracker';

import type { CommandUsage } from '../lib/types/commands';

export class AppCommand extends BaseVIPCommand {
protected readonly name: string = 'app';

protected readonly usage: CommandUsage = {
description: 'List and modify your VIP applications',
examples: [
{
description: 'Example 1',
usage: 'vip app app',
},
{
description: 'Example 2',
usage: 'vip example ',
},
],
};

// protected readonly commandOptions: CommandOption[] = [];

protected childCommands: BaseVIPCommand[] = [];

protected async execute( ...arg: unknown[] ): void {
let res;
try {
res = await app(
arg[ 0 ],
'id,repo,name,environments{id,appId,name,type,branch,currentCommit,primaryDomain{name},launched}'
);
} catch ( err ) {
await trackEvent( 'app_command_fetch_error', {
error: `App ${ arg[ 0 ] } does not exist`,
} );

console.log( `App ${ chalk.blueBright( arg[ 0 ] ) } does not exist` );
return;
}

if ( ! res || ! res.environments ) {
await trackEvent( 'app_command_fetch_error', {
error: `App ${ arg[ 0 ] } does not exist`,
} );

console.log( `App ${ chalk.blueBright( arg[ 0 ] ) } does not exist` );
return;
}

await trackEvent( 'app_command_success' );

// Clone the read-only response object so we can modify it
const clonedResponse = Object.assign( {}, res );

const header = [
{ key: 'id', value: res.id },
{ key: 'name', value: res.name },
{ key: 'repo', value: res.repo },
];

clonedResponse.environments = clonedResponse.environments.map( env => {
const clonedEnv = Object.assign( {}, env );

clonedEnv.name = getEnvIdentifier( env );

// Use the short version of git commit hash
clonedEnv.currentCommit = clonedEnv.currentCommit.substring( 0, 7 );

// Flatten object
clonedEnv.primaryDomain = clonedEnv.primaryDomain.name;
delete clonedEnv.__typename;
return clonedEnv;
} );

return { header, data: clonedResponse.environments };
}
}
80 changes: 80 additions & 0 deletions src/commands/example-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { BaseVIPCommand } from '../lib/base-command';

import type { CommandOption, CommandUsage } from '../lib/types/commands';

export class ExampleCommand extends BaseVIPCommand {
protected readonly name: string = 'example';

protected readonly usage: CommandUsage = {
description: 'Example command',
examples: [
{
description: 'Example 1',
usage: 'vip example arg1 arg2',
},
{
description: 'Example 2',
usage: 'vip example --named=arg1 --also=arg2',
},
],
};

protected readonly commandOptions: CommandOption[] = [
{
name: '--slug <slug>, -s <slug>',
description: 'An env slug',
type: 'string',
required: true,
},
];

protected childCommands: BaseVIPCommand[] = [ new ExampleChildCommand() ];

protected execute( opts: unknown[] ): void {
console.log( 'parent', this.getName() );
}
}

export class ExampleChildCommand extends BaseVIPCommand {
protected readonly name: string = 'child';
protected readonly usage: CommandUsage = {
description: 'Example child command',
examples: [
{
description: 'Example 1',
usage: 'vip example child arg1 arg2',
},
{
description: 'Example 2',
usage: 'vip example child --named=arg1 --also=arg2',
},
],
};

protected childCommands: BaseVIPCommand[] = [ new ExampleGrandChildCommand() ];

protected execute( opts: unknown[], ...args: unknown[] ): void {
console.log( this.getName() );
}
}

export class ExampleGrandChildCommand extends BaseVIPCommand {
protected readonly name: string = 'grandchild';
protected readonly usage: CommandUsage = {
description: 'Example grandchild command',
examples: [
{
description: 'Example 1',
usage: 'vip example child arg1 arg2',
},
{
description: 'Example 2',
usage: 'vip example child --named=arg1 --also=arg2',
},
],
};

protected execute( opts: unknown[], ...args: unknown[] ): void {
console.log( this.getName() );
}
}
Loading