Skip to content

Commit ec9e07d

Browse files
author
George Taschina
committed
reformat cli to nestjs
1 parent 2d06dd6 commit ec9e07d

37 files changed

+1473
-516
lines changed

apps/cli/jest.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
roots: ['<rootDir>/src'],
5+
testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
6+
transform: {
7+
'^.+\\.ts$': 'ts-jest',
8+
},
9+
collectCoverageFrom: [
10+
'src/**/*.ts',
11+
'!src/**/*.d.ts',
12+
'!src/main.ts',
13+
'!src/cli.ts',
14+
],
15+
moduleNameMapper: {
16+
'^@/(.*)$': '<rootDir>/src/$1',
17+
},
18+
transformIgnorePatterns: [
19+
'node_modules/(?!(inquirer|@inquirer|ora|chalk|ansi-.*)/)',
20+
],
21+
};

apps/cli/package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
"straion": "./dist/cli.js"
88
},
99
"scripts": {
10-
"build": "tsc -b",
10+
"build": "tsc -b && cp confluence-api.json dist/",
1111
"clean": "rm -rf dist | rm tsconfig.tsbuildinfo",
1212
"generate-types": "npx openapicmd typegen ./confluence-api.json > src/types/confluence-api.d.ts",
13-
"prebuild": "pnpm generate-types"
13+
"prebuild": "pnpm generate-types",
14+
"test": "jest",
15+
"test:watch": "jest --watch",
16+
"test:cov": "jest --coverage"
1417
},
1518
"keywords": [
1619
"straion",
@@ -20,19 +23,26 @@
2023
"author": "",
2124
"license": "MIT",
2225
"dependencies": {
26+
"@nestjs/common": "^10.4.20",
27+
"@nestjs/core": "^10.4.20",
2328
"@straion/shared": "workspace:*",
2429
"axios": "^1.6.2",
2530
"chalk": "^4.1.2",
26-
"commander": "^11.1.0",
2731
"inquirer": "^9.2.12",
32+
"nest-commander": "^3.20.1",
2833
"openapi-client-axios": "^7.8.0",
2934
"openapicmd": "^2.7.0",
30-
"ora": "^5.4.1"
35+
"ora": "^5.4.1",
36+
"reflect-metadata": "^0.2.2"
3137
},
3238
"devDependencies": {
39+
"@nestjs/testing": "^10.4.20",
3340
"@types/inquirer": "^9.0.7",
41+
"@types/jest": "^29.5.14",
3442
"@types/node": "^20.10.0",
43+
"jest": "^29.7.0",
3544
"openapi-typescript": "^7.10.1",
45+
"ts-jest": "^29.4.6",
3646
"ts-node": "^10.9.2",
3747
"typescript": "^5.3.3"
3848
}

apps/cli/src/app.module.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Module } from '@nestjs/common';
2+
import { CoreModule } from './core/core.module';
3+
import { AuthModule } from './commands/auth/auth.module';
4+
import { ImportModule } from './commands/import/import.module';
5+
import { StatusModule } from './commands/status/status.module';
6+
import { ListModule } from './commands/list/list.module';
7+
import { SpaceModule } from './commands/space/space.module';
8+
9+
@Module({
10+
imports: [
11+
CoreModule,
12+
AuthModule,
13+
ImportModule,
14+
StatusModule,
15+
ListModule,
16+
SpaceModule,
17+
],
18+
})
19+
export class AppModule {}

apps/cli/src/cli.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,3 @@
11
#!/usr/bin/env node
22

3-
import { Command } from 'commander';
4-
import { importCommand } from './commands/import';
5-
import { authCommand } from './commands/auth';
6-
import { listCommand } from './commands/list';
7-
import { statusCommand } from './commands/status';
8-
import { spaceCommand } from './commands/space';
9-
import { spacesCommand } from './commands/spaces';
10-
11-
const program = new Command();
12-
13-
program
14-
.name('straion')
15-
.description('Document import tool for Straion platform')
16-
.version('1.0.0');
17-
18-
program
19-
.command('import')
20-
.description('Import documents from external platforms')
21-
.option('-s, --source <platform>', 'Source platform (confluence, gdocs)')
22-
.option('--space-key <key>', 'Confluence space key')
23-
.option('--page-id <id>', 'Page ID to import')
24-
.action(importCommand);
25-
26-
program
27-
.command('status <import-id>')
28-
.description('Check the status of an import')
29-
.action(statusCommand);
30-
31-
program
32-
.command('auth')
33-
.description('Configure authentication credentials')
34-
.action(authCommand);
35-
36-
program
37-
.command('list')
38-
.description('List available documents from a source')
39-
.option('-s, --source <platform>', 'Source platform (confluence, gdocs)')
40-
.option('--space-id <spaceId>', 'Confluence space key')
41-
.action(listCommand);
42-
43-
program
44-
.command('space')
45-
.description('Get Confluence space information by key')
46-
.option('--key <spaceId>', 'Confluence space key')
47-
.action(spaceCommand);
48-
49-
program
50-
.command('spaces')
51-
.description('List all available Confluence spaces')
52-
.action(spacesCommand);
53-
54-
program.parse();
3+
import './main';

apps/cli/src/commands/auth.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { Command, CommandRunner } from 'nest-commander';
2+
import { Injectable } from '@nestjs/common';
3+
import inquirer from 'inquirer';
4+
import { ConfigService } from '../../core/config/config.service';
5+
import { UiService } from '../../core/ui/ui.service';
6+
import { ConfluenceClient } from '../../integrations/confluence';
7+
8+
@Command({
9+
name: 'auth',
10+
description: 'Configure authentication credentials',
11+
})
12+
@Injectable()
13+
export class AuthCommand extends CommandRunner {
14+
constructor(
15+
private readonly configService: ConfigService,
16+
private readonly uiService: UiService,
17+
) {
18+
super();
19+
}
20+
21+
async run(): Promise<void> {
22+
console.log(this.uiService.chalk.bold('\n🔐 Straion Authentication Configuration\n'));
23+
24+
const answers = await inquirer.prompt([
25+
{
26+
type: 'input',
27+
name: 'straionEndpoint',
28+
message: 'Straion API endpoint:',
29+
default: 'http://localhost:3000',
30+
},
31+
{
32+
type: 'password',
33+
name: 'straionApiKey',
34+
message: 'Straion API key:',
35+
default: 'dev-token-12345', // For dev purposes
36+
},
37+
{
38+
type: 'confirm',
39+
name: 'configureConfluence',
40+
message: 'Configure Confluence integration?',
41+
default: true,
42+
},
43+
{
44+
type: 'input',
45+
name: 'confluenceBaseUrl',
46+
message: 'Confluence base URL (e.g., https://your-domain.atlassian.net):',
47+
when: (answers) => answers.configureConfluence,
48+
},
49+
{
50+
type: 'input',
51+
name: 'confluenceEmail',
52+
message: 'Confluence email:',
53+
when: (answers) => answers.configureConfluence,
54+
},
55+
{
56+
type: 'password',
57+
name: 'confluenceApiToken',
58+
message: 'Confluence API token:',
59+
when: (answers) => answers.configureConfluence,
60+
},
61+
]);
62+
63+
const config = this.configService.load();
64+
65+
config.straion = {
66+
endpoint: answers.straionEndpoint,
67+
apiKey: answers.straionApiKey,
68+
};
69+
70+
if (answers.configureConfluence) {
71+
config.confluence = {
72+
baseUrl: answers.confluenceBaseUrl,
73+
email: answers.confluenceEmail,
74+
apiToken: answers.confluenceApiToken,
75+
};
76+
77+
// Test Confluence connection
78+
const spinner = this.uiService.spinner('Testing Confluence connection...').start();
79+
const confluenceClient = await ConfluenceClient.create({
80+
baseUrl: config.confluence.baseUrl,
81+
email: config.confluence.email,
82+
apiToken: config.confluence.apiToken,
83+
});
84+
85+
try {
86+
await confluenceClient.getSpaces();
87+
spinner.succeed(this.uiService.chalk.green('Confluence connection successful!'));
88+
} catch (error) {
89+
spinner.warn(this.uiService.chalk.yellow('Could not verify Confluence connection'));
90+
}
91+
}
92+
93+
this.configService.save(config);
94+
95+
this.uiService.success('\n✓ Configuration saved successfully!');
96+
console.log(this.uiService.chalk.gray(`Config location: ${this.configService.getConfigPath()}\n`));
97+
}
98+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Module } from '@nestjs/common';
2+
import { AuthCommand } from './auth.command';
3+
4+
@Module({
5+
providers: [AuthCommand],
6+
})
7+
export class AuthModule {}

0 commit comments

Comments
 (0)