File size: 6,787 Bytes
4fea3ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env node
// Smart Roadmap CLI
// Command Line Interface for Smart Roadmap Scanner
// Version: 1.0.0

const SmartRoadmapScanner = require('./src/index');
const path = require('path');
const fs = require('fs');

// Parse command line arguments
function parseArguments(args) {
    const options = {
        command: 'scan',
        projectPath: process.cwd(),
        verbose: false,
        dryRun: false,
        outputDir: 'docs',
        format: 'all',
        help: false,
        version: false
    };

    const validCommands = ['scan', 'analyze', 'help'];
    let commandFound = false;

    for (let i = 0; i < args.length; i++) {
        const arg = args[i];

        if (arg === '-h' || arg === '--help') {
            options.help = true;
        } else if (arg === '--version') {
            options.version = true;
        } else if (arg === '-v' || arg === '--verbose') {
            options.verbose = true;
        } else if (arg === '-d' || arg === '--dry-run') {
            options.dryRun = true;
        } else if (arg === '-o' || arg === '--output') {
            if (i + 1 < args.length) {
                options.outputDir = args[i + 1];
                i++;
            }
        } else if (arg === '--format') {
            if (i + 1 < args.length) {
                options.format = args[i + 1];
                i++;
            }
        } else if (!arg.startsWith('-')) {
            // First non-option arg: command or path
            if (!commandFound && validCommands.includes(arg)) {
                options.command = arg;
                commandFound = true;
            } else {
                // Treat as project path
                options.projectPath = path.resolve(arg);
            }
        }
    }

    return options;
}

// Show help information
function showHelp() {
    console.log(`

Smart Roadmap - AI-Powered Development Roadmap Generator

Version: 1.0.0



USAGE:

  smart-roadmap [command] [path] [options]



COMMANDS:

  scan                 Scan project and generate roadmap (default)

  analyze              Detailed project analysis

  help                 Show this help message



ARGUMENTS:

  path                 Path to project directory (default: current directory)



OPTIONS:

  -v, --verbose        Show detailed output during scan

  -d, --dry-run        Preview without saving files

  -o, --output <dir>   Output directory (default: docs/)

  --format <type>      Output format: json, md, html, all (default: all)

  -h, --help           Show this help message

  --version            Show version number



EXAMPLES:

  smart-roadmap scan                    # Scan current directory

  smart-roadmap scan ./my-project       # Scan specific project

  smart-roadmap analyze --verbose       # Detailed analysis

  smart-roadmap scan -o ./reports       # Custom output directory

  smart-roadmap --help                  # Show help



OUTPUT FILES:

  - project-analysis.json               Machine-readable data

  - DEVELOPMENT_ROADMAP.md              Prioritized development plan

  - PROJECT_ANALYSIS.md                 Detailed analysis report



For more information, visit:

  https://github.com/chahuadev-com/Chahuadev-smart-roadmap

`);
}

// Show version
function showVersion() {
    const packagePath = path.join(__dirname, 'package.json');
    try {
        const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
        console.log(`Smart Roadmap v${pkg.version}`);
        console.log(`Author: ${pkg.author.name || pkg.author}`);
    } catch (error) {
        console.log('Smart Roadmap v1.0.0');
        console.log('Author: Chahua Development Co., Ltd.');
    }
}

// Main CLI function
async function main() {
    const args = process.argv.slice(2);
    const options = parseArguments(args);

    // Show help or version
    if (options.help || args.includes('help')) {
        showHelp();
        return;
    }

    if (options.version) {
        showVersion();
        return;
    }

    // Validate project path
    if (!fs.existsSync(options.projectPath)) {
        console.error(`[ERROR] Project path not found: ${options.projectPath}`);
        process.exit(1);
    }

    console.log('Smart Roadmap v1.0.0');
    console.log('='.repeat(70));
    console.log(`Command: ${options.command}`);
    console.log(`Project: ${path.relative(process.cwd(), options.projectPath) || '.'}`);
    console.log(`Output: ${options.outputDir}`);
    if (options.dryRun) {
        console.log('[DRY RUN] No files will be saved');
    }
    console.log('');

    try {
        // Create scanner instance
        const scanner = new SmartRoadmapScanner({
            projectPath: options.projectPath,
            outputDir: options.outputDir,
            verbose: options.verbose
        });

        // Execute command
        if (options.command === 'scan' || options.command === 'analyze') {
            const analysis = await scanner.scan();

            if (!options.dryRun) {
                // Save analysis results
                const outputPath = path.join(options.projectPath, options.outputDir);
                
                // Create output directory if it doesn't exist
                if (!fs.existsSync(outputPath)) {
                    fs.mkdirSync(outputPath, { recursive: true });
                }

                // Save JSON
                const jsonPath = path.join(options.projectPath, 'project-analysis.json');
                fs.writeFileSync(jsonPath, JSON.stringify(analysis, null, 2), 'utf8');
                console.log(`[SUCCESS] Analysis saved: ${path.relative(process.cwd(), jsonPath)}`);

                // Future: Generate Markdown and HTML reports here
                console.log('[INFO] Roadmap generation will be implemented in next version');
            }

            console.log('\n[SUCCESS] Scan completed!');
            
            if (options.dryRun) {
                console.log('[INFO] Use without --dry-run to save reports');
            }

        } else {
            console.error(`[ERROR] Unknown command: ${options.command}`);
            console.log('Use --help to see available commands');
            process.exit(1);
        }

    } catch (error) {
        console.error(`\n[ERROR] ${error.message}`);
        if (options.verbose) {
            console.error(error.stack);
        }
        process.exit(1);
    }
}

// Run CLI if executed directly
if (require.main === module) {
    main().catch(error => {
        console.error(`[FATAL] ${error.message}`);
        process.exit(1);
    });
}

module.exports = { main, parseArguments, showHelp, showVersion };