readme-builder 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +125 -0
- data/bin/readme-builder +3 -0
- data/ext/readme_generator/binding.cpp +61 -0
- data/ext/readme_generator/extconf.rb +60 -0
- data/ext/readme_generator/include/build_detector.hpp +44 -0
- data/ext/readme_generator/include/language_detector.hpp +47 -0
- data/ext/readme_generator/include/license.hpp +61 -0
- data/ext/readme_generator/include/readme_builder.hpp +62 -0
- data/ext/readme_generator/src/build_detector.cpp +210 -0
- data/ext/readme_generator/src/language_detector.cpp +199 -0
- data/ext/readme_generator/src/license.cpp +197 -0
- data/ext/readme_generator/src/main.cpp +40 -0
- data/ext/readme_generator/src/readme_builder.cpp +226 -0
- data/lib/readme_builder/version.rb +4 -0
- data/lib/readme_builder.rb +31 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b59aa8d423852759bfd4f22fcce55150ee3bd486d576212dd4fe00afb7f82102
|
4
|
+
data.tar.gz: bafbb8a2ec5fc9068288e1428f89f2e3694220e6b929065e7b70bb68bc2f58d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85bfde61084e55f3e11cc3f6e4a2309612702c4447394d5db28c28353ffe5fa0519e715729f0a5265d4cc8865dad84e94c4305823183ae37f339432ca599de1d
|
7
|
+
data.tar.gz: 7296779c0b26b03e3be0062060b6b4ec18c80d952ec93ff459a82d4664af84262f931b3bdf5edc0ecdb5c8fead495a02ef7216e654cf605be0cef5a92f0da42a
|
data/README.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# README Builder
|
2
|
+
|
3
|
+
A command-line tool that automatically generates professional README files and licenses for your projects. Simply answer a few questions, and the tool will analyze your project structure, detect programming languages used, and create well-structured documentation.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- Interactive command-line interface
|
8
|
+
- Automatic programming language detection
|
9
|
+
- License generation (MIT, Apache 2.0, GPL-3.0)
|
10
|
+
- Project structure analysis
|
11
|
+
- Build system detection
|
12
|
+
- Language statistics
|
13
|
+
- Cross-platform support
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
```bash
|
18
|
+
gem install readme_builder
|
19
|
+
```
|
20
|
+
|
21
|
+
### Requirements
|
22
|
+
|
23
|
+
- Ruby >= 2.7.0
|
24
|
+
- C++17 compatible compiler
|
25
|
+
- CMake >= 3.14 (for building from source)
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
1. Navigate to your project directory:
|
30
|
+
```bash
|
31
|
+
cd /path/to/your/project
|
32
|
+
```
|
33
|
+
|
34
|
+
2. Run the tool:
|
35
|
+
```bash
|
36
|
+
readme_builder
|
37
|
+
```
|
38
|
+
|
39
|
+
3. Follow the interactive prompts:
|
40
|
+
```
|
41
|
+
Enter project title: My Awesome Project
|
42
|
+
Enter project description: A fantastic tool that does amazing things
|
43
|
+
Select license type:
|
44
|
+
1. MIT
|
45
|
+
2. Apache 2.0
|
46
|
+
3. GPL-3.0
|
47
|
+
Enter number (1-3): 1
|
48
|
+
```
|
49
|
+
|
50
|
+
The tool will then:
|
51
|
+
- Analyze your project directory
|
52
|
+
- Detect programming languages used
|
53
|
+
- Identify build systems
|
54
|
+
- Generate a comprehensive README.md
|
55
|
+
- Create a LICENSE file with your chosen license
|
56
|
+
|
57
|
+
## Generated Files
|
58
|
+
|
59
|
+
### README.md Structure
|
60
|
+
- Project title and description
|
61
|
+
- Installation instructions (based on detected build system)
|
62
|
+
- Usage section
|
63
|
+
- Project structure
|
64
|
+
- Language statistics
|
65
|
+
- License information
|
66
|
+
|
67
|
+
### Supported Licenses
|
68
|
+
- MIT License
|
69
|
+
- Apache License 2.0
|
70
|
+
- GNU GPL v3.0
|
71
|
+
|
72
|
+
## Example
|
73
|
+
|
74
|
+
Here's what happens when you run the tool:
|
75
|
+
|
76
|
+
```bash
|
77
|
+
$ readme_builder
|
78
|
+
Welcome to README Builder!
|
79
|
+
|
80
|
+
Enter project title: Weather App
|
81
|
+
Enter project description: A command-line weather forecast tool
|
82
|
+
Select license type:
|
83
|
+
1. MIT
|
84
|
+
2. Apache 2.0
|
85
|
+
3. GPL-3.0
|
86
|
+
Enter number (1-3): 1
|
87
|
+
|
88
|
+
Analyzing project structure...
|
89
|
+
Detecting languages...
|
90
|
+
Found: Python (80%), JavaScript (15%), CSS (5%)
|
91
|
+
Generating README.md...
|
92
|
+
Generating LICENSE...
|
93
|
+
Done! Created:
|
94
|
+
- README.md
|
95
|
+
- LICENSE
|
96
|
+
```
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
1. Fork the repository
|
101
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
102
|
+
3. Commit your changes (`git commit -am 'Add amazing feature'`)
|
103
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
104
|
+
5. Create a Pull Request
|
105
|
+
|
106
|
+
### Development Setup
|
107
|
+
|
108
|
+
```bash
|
109
|
+
git clone https://github.com/yourusername/readme_builder
|
110
|
+
cd readme_builder
|
111
|
+
bundle install
|
112
|
+
rake compile # Compiles native extensions
|
113
|
+
rake test # Runs tests
|
114
|
+
```
|
115
|
+
|
116
|
+
## License
|
117
|
+
|
118
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
119
|
+
|
120
|
+
## Credits
|
121
|
+
|
122
|
+
Built with:
|
123
|
+
- Ruby for the command-line interface
|
124
|
+
- C++ for the core analysis engine
|
125
|
+
- Native extensions for seamless integration
|
data/bin/readme-builder
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
// ext/readme-builder/binding.cpp
|
2
|
+
#include <ruby.h>
|
3
|
+
#include "readme_builder.hpp"
|
4
|
+
#include "license.hpp"
|
5
|
+
|
6
|
+
// Wrap our C++ ReadmeBuilder class
|
7
|
+
static VALUE rb_readme_builder_init(VALUE self, VALUE rb_name, VALUE rb_desc) {
|
8
|
+
Check_Type(rb_name, T_STRING);
|
9
|
+
Check_Type(rb_desc, T_STRING);
|
10
|
+
|
11
|
+
try {
|
12
|
+
ReadmeBuilder* generator = new ReadmeBuilder(
|
13
|
+
StringValueCStr(rb_name)
|
14
|
+
);
|
15
|
+
generator->setDescription(StringValueCStr(rb_desc));
|
16
|
+
generator->generateWithLanguageDetection();
|
17
|
+
return Qtrue;
|
18
|
+
} catch (const std::exception& e) {
|
19
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
20
|
+
return Qfalse;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
// Wrap our License class
|
25
|
+
static VALUE rb_license_add(VALUE self, VALUE rb_type, VALUE rb_holder) {
|
26
|
+
Check_Type(rb_type, T_STRING);
|
27
|
+
Check_Type(rb_holder, T_STRING);
|
28
|
+
|
29
|
+
try {
|
30
|
+
License license;
|
31
|
+
std::string content = license.getLicenseContent(
|
32
|
+
StringValueCStr(rb_type),
|
33
|
+
StringValueCStr(rb_holder)
|
34
|
+
);
|
35
|
+
|
36
|
+
// Write to LICENSE file
|
37
|
+
FILE* file = fopen("LICENSE", "w");
|
38
|
+
if (!file) {
|
39
|
+
rb_raise(rb_eIOError, "Could not create LICENSE file");
|
40
|
+
return Qfalse;
|
41
|
+
}
|
42
|
+
fprintf(file, "%s", content.c_str());
|
43
|
+
fclose(file);
|
44
|
+
|
45
|
+
return Qtrue;
|
46
|
+
} catch (const std::exception& e) {
|
47
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
48
|
+
return Qfalse;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
// Initialize the extension
|
53
|
+
extern "C" void Init_readme_builder() {
|
54
|
+
VALUE mReadmeGenerator = rb_define_module("ReadmeBuilder");
|
55
|
+
VALUE cGenerator = rb_define_class_under(ReadmeBuilder, "Native", rb_cObject);
|
56
|
+
|
57
|
+
rb_define_singleton_method(cGenerator, "generate",
|
58
|
+
RUBY_METHOD_FUNC(rb_readme_builder_init), 2);
|
59
|
+
rb_define_singleton_method(cGenerator, "add_license",
|
60
|
+
RUBY_METHOD_FUNC(rb_license_add), 2);
|
61
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
##
|
4
|
+
# Configuration script for compiling the ReadmeBuilder native extension.
|
5
|
+
# This script sets up the build environment and creates a Makefile for
|
6
|
+
# compiling the C++ code into a Ruby extension.
|
7
|
+
#
|
8
|
+
# @note Requires C++17 compiler
|
9
|
+
# @note Requires CMake >= 3.14
|
10
|
+
#
|
11
|
+
# @author Your Name
|
12
|
+
# @since 0.1.0
|
13
|
+
|
14
|
+
require 'mkmf'
|
15
|
+
require 'pathname'
|
16
|
+
|
17
|
+
##
|
18
|
+
# Absolute path to the current extension directory
|
19
|
+
CURRENT_DIR = File.expand_path(__dir__)
|
20
|
+
|
21
|
+
##
|
22
|
+
# Absolute path to the project root directory
|
23
|
+
ROOT_DIR = File.expand_path('../..', __dir__)
|
24
|
+
|
25
|
+
##
|
26
|
+
# Add necessary include paths for C++ headers
|
27
|
+
# @note Includes both project root and extension-specific headers
|
28
|
+
$INCFLAGS << " -I#{ROOT_DIR}/include"
|
29
|
+
$INCFLAGS << " -I#{CURRENT_DIR}/include"
|
30
|
+
|
31
|
+
##
|
32
|
+
# Set C++17 as the required standard
|
33
|
+
# @note This is required for filesystem and other modern C++ features
|
34
|
+
$CXXFLAGS << ' -std=c++17'
|
35
|
+
|
36
|
+
##
|
37
|
+
# List of source files to compile
|
38
|
+
# @note Files are listed explicitly to ensure correct build order
|
39
|
+
$srcs = [
|
40
|
+
"#{ROOT_DIR}/src/build_detector.cpp", # Build system detection
|
41
|
+
"#{ROOT_DIR}/src/language_detector.cpp", # Programming language detection
|
42
|
+
"#{ROOT_DIR}/src/license.cpp", # License generation
|
43
|
+
"#{ROOT_DIR}/src/main.cpp", # Main program logic
|
44
|
+
"#{ROOT_DIR}/src/readme_generator.cpp", # README generation
|
45
|
+
"#{CURRENT_DIR}/binding.cpp" # Ruby binding code
|
46
|
+
]
|
47
|
+
|
48
|
+
##
|
49
|
+
# Verify all source files exist before attempting to build
|
50
|
+
# Provides early warning if any files are missing
|
51
|
+
#
|
52
|
+
# @note Warns but doesn't fail if files are missing
|
53
|
+
$srcs.each do |src|
|
54
|
+
unless File.exist?(src)
|
55
|
+
puts "Warning: Source file not found: #{src}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Create the makefile for building the native extension
|
60
|
+
create_makefile('readme_builder/native')
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#ifndef BUILD_SYSTEM_DETECTOR_HPP
|
2
|
+
#define BUILD_SYSTEM_DETECTOR_HPP
|
3
|
+
|
4
|
+
#include <string>
|
5
|
+
#include <filesystem>
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @class BuildSystemDetector
|
9
|
+
* @brief Detects and processes project build systems
|
10
|
+
* @details Scans project directory for common build system files and generates
|
11
|
+
* appropriate installation instructions
|
12
|
+
*/
|
13
|
+
|
14
|
+
class BuildSystemDetector {
|
15
|
+
/**
|
16
|
+
* @brief Constructor initializes detector with project root path
|
17
|
+
* @param root Path to project root directory
|
18
|
+
*/
|
19
|
+
private:
|
20
|
+
/**
|
21
|
+
* @brief Detect presence of various build system files
|
22
|
+
*/
|
23
|
+
|
24
|
+
bool hasCMake;
|
25
|
+
bool hasMakefile;
|
26
|
+
bool hasDockerfile;
|
27
|
+
bool hasPackageJson;
|
28
|
+
bool hasPipfile;
|
29
|
+
bool hasRequirementsTxt;
|
30
|
+
std::string projectRoot;
|
31
|
+
|
32
|
+
void detectBuildSystems();
|
33
|
+
|
34
|
+
public:
|
35
|
+
BuildSystemDetector(const std::string& root);
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @brief Generate markdown-formatted installation instructions
|
39
|
+
* @return std::string Installation instructions in markdown format
|
40
|
+
*/
|
41
|
+
std::string generateInstallationInstructions() const;
|
42
|
+
};
|
43
|
+
|
44
|
+
#endif // BUILD_SYSTEM_DETECTOR_HPP
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#ifndef LANGUAGE_DETECTOR_HPP
|
2
|
+
#define LANGUAGE_DETECTOR_HPP
|
3
|
+
|
4
|
+
#include <string>
|
5
|
+
#include <unordered_map>
|
6
|
+
#include <filesystem>
|
7
|
+
|
8
|
+
class LanguageDetector {
|
9
|
+
/**
|
10
|
+
* @class LanguageDetector
|
11
|
+
* @brief Detects programming languages in project files
|
12
|
+
* @details Analyzes file extensions and content to determine programming
|
13
|
+
* languages used in a project
|
14
|
+
*/
|
15
|
+
private:
|
16
|
+
std::unordered_map<std::string, std::string> extensionMap;
|
17
|
+
std::unordered_map<std::string, int> languageStats;
|
18
|
+
/**
|
19
|
+
* @brief Analyze content of a single file
|
20
|
+
* @param filePath Path to the file to analyze
|
21
|
+
* @return std::string Detected programming language or empty string if unknown
|
22
|
+
*/
|
23
|
+
std::string analyzeFileContent(const std::string& filePath);
|
24
|
+
|
25
|
+
public:
|
26
|
+
/**
|
27
|
+
* @brief Constructor initializes language detection rules
|
28
|
+
*/
|
29
|
+
|
30
|
+
LanguageDetector();
|
31
|
+
/**
|
32
|
+
* @brief Analyze all files in a project directory
|
33
|
+
* @param projectPath Path to the project root
|
34
|
+
*/
|
35
|
+
void analyzeProject(const std::string& projectPath);
|
36
|
+
/**
|
37
|
+
* @brief Get statistics of detected languages
|
38
|
+
* @return std::unordered_map<std::string, int> Map of language names to file counts
|
39
|
+
*/
|
40
|
+
std::unordered_map<std::string, int> getLanguageStatistics() const;
|
41
|
+
void reset();
|
42
|
+
void addCustomExtension(const std::string& extension, const std::string& language);
|
43
|
+
std::string getPrimaryLanguage() const;
|
44
|
+
int getTotalFiles() const;
|
45
|
+
};
|
46
|
+
|
47
|
+
#endif // LANGUAGE_DETECTOR_HPP
|
@@ -0,0 +1,61 @@
|
|
1
|
+
// license.hpp
|
2
|
+
#ifndef LICENSE_HPP
|
3
|
+
#define LICENSE_HPP
|
4
|
+
|
5
|
+
#include <string>
|
6
|
+
#include <unordered_map>
|
7
|
+
#include <vector>
|
8
|
+
|
9
|
+
class License {
|
10
|
+
/**
|
11
|
+
* @brief Constructor initializes license templates and current year
|
12
|
+
*/
|
13
|
+
private:
|
14
|
+
struct LicenseInfo {
|
15
|
+
std::string name;
|
16
|
+
std::string content;
|
17
|
+
std::string description;
|
18
|
+
};
|
19
|
+
|
20
|
+
std::unordered_map<std::string, LicenseInfo> licenses;
|
21
|
+
std::string currentYear;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @brief Initialize the license templates
|
25
|
+
*/
|
26
|
+
void initializeLicenses();
|
27
|
+
/**
|
28
|
+
* @brief Get the current year as string
|
29
|
+
* @return std::string Current year
|
30
|
+
*/
|
31
|
+
std::string getCurrentYear() const;
|
32
|
+
|
33
|
+
public:
|
34
|
+
License();
|
35
|
+
|
36
|
+
/**
|
37
|
+
* @brief Get a list of all available license types
|
38
|
+
* @return std::vector<std::string> List of supported license identifiers
|
39
|
+
*/
|
40
|
+
std::vector<std::string> getAvailableLicenses() const;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* @brief Generate license content with copyright information
|
44
|
+
* @param licenseType The type of license (e.g., "MIT", "Apache-2.0", "GPL-3.0")
|
45
|
+
* @param copyrightHolder Name of the copyright holder
|
46
|
+
* @return std::string Complete license text with copyright information
|
47
|
+
* @throws std::runtime_error if license type is invalid
|
48
|
+
*/
|
49
|
+
std::string getLicenseContent(const std::string& licenseType,
|
50
|
+
const std::string& copyrightHolder) const;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @brief Get description of a specific license
|
54
|
+
* @param licenseType The type of license to get description for
|
55
|
+
* @return std::string Description of the license
|
56
|
+
* @throws std::runtime_error if license type is invalid
|
57
|
+
*/
|
58
|
+
std::string getLicenseDescription(const std::string& licenseType) const;
|
59
|
+
};
|
60
|
+
|
61
|
+
#endif // LICENSE_HPP
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#ifndef README_BUILDER_HPP
|
2
|
+
#define README_BUILDER_HPP
|
3
|
+
|
4
|
+
#include <string>
|
5
|
+
#include <unordered_map>
|
6
|
+
#include <filesystem>
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @class ReadmeBuilder
|
10
|
+
* @brief Builds comprehensive README files for projects
|
11
|
+
* @details Generates README.md files with project information, language statistics,
|
12
|
+
* and installation instructions
|
13
|
+
*/
|
14
|
+
|
15
|
+
class ReadmeBuilder {
|
16
|
+
private:
|
17
|
+
std::string projectName;
|
18
|
+
std::string description;
|
19
|
+
std::unordered_map<std::string, int> languageStats;
|
20
|
+
std::string primaryLanguage;
|
21
|
+
int totalFiles;
|
22
|
+
std::string projectRoot;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @brief Generate the language statistics section
|
26
|
+
* @return std::string Markdown-formatted language statistics
|
27
|
+
*/
|
28
|
+
|
29
|
+
std::string generateLanguageSection() const;
|
30
|
+
std::string generateProjectStructure(const std::string& path, int depth = 0) const;
|
31
|
+
std::string getCurrentDate() const;
|
32
|
+
std::string findProjectRoot(const std::string& startPath) const; // Added helper method
|
33
|
+
void generateFile();
|
34
|
+
|
35
|
+
public:
|
36
|
+
/**
|
37
|
+
* @brief Constructor initializes builder with project information
|
38
|
+
* @param name Project name
|
39
|
+
* @param stats Language statistics
|
40
|
+
* @param primary Primary programming language
|
41
|
+
* @param total Total number of files
|
42
|
+
*/
|
43
|
+
ReadmeBuilder(const std::string& name = "",
|
44
|
+
const std::unordered_map<std::string, int>& stats = {},
|
45
|
+
const std::string& primary = "",
|
46
|
+
int total = 0);
|
47
|
+
|
48
|
+
/**
|
49
|
+
* @brief Interactive README generation process
|
50
|
+
* @throws std::runtime_error if required information is missing
|
51
|
+
*/
|
52
|
+
|
53
|
+
void run();
|
54
|
+
|
55
|
+
/**
|
56
|
+
* @brief Generate README with automatic language detection
|
57
|
+
*/
|
58
|
+
|
59
|
+
void generateWithLanguageDetection();
|
60
|
+
};
|
61
|
+
|
62
|
+
#endif // README_BUILDER_HPP
|
@@ -0,0 +1,210 @@
|
|
1
|
+
/**
|
2
|
+
* @file build_detector.cpp
|
3
|
+
* @brief Build system detection and installation instruction generation
|
4
|
+
* @details This system automatically detects various build systems and package managers
|
5
|
+
* present in a project, including CMake, Make, Docker, npm, and Python package
|
6
|
+
* managers. It then generates appropriate installation and build instructions
|
7
|
+
* tailored to the detected build environment. The system supports multiple
|
8
|
+
* build systems coexisting in the same project, which is common in modern
|
9
|
+
* polyglot applications.
|
10
|
+
*
|
11
|
+
* @author Generated by README Builder
|
12
|
+
* @date 2025-02-17
|
13
|
+
*
|
14
|
+
* @note This implementation prioritizes the most commonly used build steps when
|
15
|
+
* multiple build systems are present, ensuring clear and practical installation
|
16
|
+
* instructions for end users.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "../include/build_detector.hpp"
|
20
|
+
#include <sstream>
|
21
|
+
|
22
|
+
|
23
|
+
file's purpose in one line
|
24
|
+
Detailed information (@details) that explains the full scope and functionality
|
25
|
+
Author and date information for tracking
|
26
|
+
Additional notes (@note) about implementation specifics or important considerations
|
27
|
+
Function Documentation: Each function is documented with:
|
28
|
+
A clear purpose statement (@brief)
|
29
|
+
Detailed explanation of its operation (@details)
|
30
|
+
Parameter descriptions (@param) when present
|
31
|
+
Return value documentation (@return) for functions that return values
|
32
|
+
Exception information (@throws) when exceptions might be thrown
|
33
|
+
Cross-references (@see) to related functions or classes
|
34
|
+
Implementation Context: The documentation provides context about why certain decisions were made, such as:
|
35
|
+
Why certain build systems are detected in a specific order
|
36
|
+
How license templates are structured and why
|
37
|
+
The reasoning behind file analysis approaches
|
38
|
+
User Guidance: The documentation includes helpful information for users:
|
39
|
+
Examples of how to use complex functions
|
40
|
+
Explanations of expected inputs and outputs
|
41
|
+
Clear error conditions and how to handle them
|
42
|
+
References to related functionality
|
43
|
+
Maintainability: The documentation supports future maintenance by:
|
44
|
+
Explaining the relationship between different components
|
45
|
+
Documenting internal data structures and their purpose
|
46
|
+
Providing context for implementation choices
|
47
|
+
Noting any assumptions or dependencies
|
48
|
+
Would you like me to explain any specific aspect of the documentation in more detail? Or would you like to see documentation for any specific functions or components?
|
49
|
+
|
50
|
+
Copy
|
51
|
+
Retry
|
52
|
+
|
53
|
+
|
54
|
+
Claude can make mistakes. Please double-check responses.
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
No file chosen
|
59
|
+
|
60
|
+
3.5 Sonnet
|
61
|
+
|
62
|
+
Explanatory
|
63
|
+
|
64
|
+
Documented build_detector.cpp
|
65
|
+
|
66
|
+
/**
|
67
|
+
* @file build_detector.cpp
|
68
|
+
* @brief Build system detection and installation instruction generation
|
69
|
+
* @details This system automatically detects various build systems and package managers
|
70
|
+
* present in a project, including CMake, Make, Docker, npm, and Python package
|
71
|
+
* managers. It then generates appropriate installation and build instructions
|
72
|
+
* tailored to the detected build environment. The system supports multiple
|
73
|
+
* build systems coexisting in the same project, which is common in modern
|
74
|
+
* polyglot applications.
|
75
|
+
*
|
76
|
+
* @author Generated by README Builder
|
77
|
+
* @date 2025-02-17
|
78
|
+
*
|
79
|
+
* @note This implementation prioritizes the most commonly used build steps when
|
80
|
+
* multiple build systems are present, ensuring clear and practical installation
|
81
|
+
* instructions for end users.
|
82
|
+
*/
|
83
|
+
|
84
|
+
#include "../include/build_detector.hpp"
|
85
|
+
#include <sstream>
|
86
|
+
|
87
|
+
/**
|
88
|
+
* @brief Constructs a BuildSystemDetector for a specific project
|
89
|
+
* @details Initializes the detector with a project root path and performs
|
90
|
+
* initial detection of all supported build systems. The constructor
|
91
|
+
* automatically scans for common build system files like CMakeLists.txt,
|
92
|
+
* Makefile, package.json, etc.
|
93
|
+
*
|
94
|
+
* @param root The root directory path of the project to analyze
|
95
|
+
*
|
96
|
+
* @see detectBuildSystems() For the actual detection logic
|
97
|
+
*/
|
98
|
+
|
99
|
+
|
100
|
+
BuildSystemDetector::BuildSystemDetector(const std::string& root)
|
101
|
+
: projectRoot(root), hasCMake(false), hasMakefile(false),
|
102
|
+
hasDockerfile(false), hasPackageJson(false),
|
103
|
+
hasPipfile(false), hasRequirementsTxt(false) {
|
104
|
+
detectBuildSystems();
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
/**
|
109
|
+
* @brief Detects all build systems present in the project
|
110
|
+
* @details Scans the project root directory for the presence of various build
|
111
|
+
* system configuration files. This method checks for:
|
112
|
+
* - CMake (CMakeLists.txt)
|
113
|
+
* - Make (Makefile)
|
114
|
+
* - Docker (Dockerfile)
|
115
|
+
* - Node.js (package.json)
|
116
|
+
* - Python (Pipfile, requirements.txt)
|
117
|
+
*
|
118
|
+
* The detection results are stored in member variables for later use in
|
119
|
+
* generating installation instructions.
|
120
|
+
*/
|
121
|
+
|
122
|
+
void BuildSystemDetector::detectBuildSystems() {
|
123
|
+
namespace fs = std::filesystem;
|
124
|
+
hasCMake = fs::exists(fs::path(projectRoot) / "CMakeLists.txt");
|
125
|
+
hasMakefile = fs::exists(fs::path(projectRoot) / "Makefile");
|
126
|
+
hasDockerfile = fs::exists(fs::path(projectRoot) / "Dockerfile");
|
127
|
+
hasPackageJson = fs::exists(fs::path(projectRoot) / "package.json");
|
128
|
+
hasPipfile = fs::exists(fs::path(projectRoot) / "Pipfile");
|
129
|
+
hasRequirementsTxt = fs::exists(fs::path(projectRoot) / "requirements.txt");
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* @brief Generates comprehensive installation instructions
|
134
|
+
* @details Creates a markdown-formatted string containing step-by-step
|
135
|
+
* installation instructions based on the detected build systems.
|
136
|
+
* The instructions are organized in a logical order:
|
137
|
+
* 1. Repository cloning
|
138
|
+
* 2. Dependencies installation (Node.js, Python)
|
139
|
+
* 3. Build steps (CMake, Make)
|
140
|
+
* 4. Docker instructions (if applicable)
|
141
|
+
*
|
142
|
+
* The method intelligently handles multiple build systems by providing
|
143
|
+
* appropriate instructions for each detected system while maintaining
|
144
|
+
* a clear and organized structure.
|
145
|
+
*
|
146
|
+
* @return std::string Markdown-formatted installation instructions
|
147
|
+
*
|
148
|
+
* @note The instructions are designed to be beginner-friendly while still
|
149
|
+
* providing all necessary information for successful installation
|
150
|
+
*/
|
151
|
+
|
152
|
+
std::string BuildSystemDetector::generateInstallationInstructions() const {
|
153
|
+
std::stringstream ss;
|
154
|
+
ss << "### Installation\n\n";
|
155
|
+
|
156
|
+
// Clone repository section
|
157
|
+
ss << "1. Clone the repository\n"
|
158
|
+
<< " ```bash\n"
|
159
|
+
<< " git clone [repository-url]\n"
|
160
|
+
<< " cd " << std::filesystem::path(projectRoot).filename().string() << "\n"
|
161
|
+
<< " ```\n\n";
|
162
|
+
|
163
|
+
// Dependencies section
|
164
|
+
if (hasPackageJson) {
|
165
|
+
ss << "2. Install Node.js dependencies\n"
|
166
|
+
<< " ```bash\n"
|
167
|
+
<< " npm install\n"
|
168
|
+
<< " ```\n\n";
|
169
|
+
}
|
170
|
+
|
171
|
+
if (hasPipfile) {
|
172
|
+
ss << "2. Install Python dependencies using Pipenv\n"
|
173
|
+
<< " ```bash\n"
|
174
|
+
<< " pipenv install\n"
|
175
|
+
<< " ```\n\n";
|
176
|
+
} else if (hasRequirementsTxt) {
|
177
|
+
ss << "2. Install Python dependencies\n"
|
178
|
+
<< " ```bash\n"
|
179
|
+
<< " pip install -r requirements.txt\n"
|
180
|
+
<< " ```\n\n";
|
181
|
+
}
|
182
|
+
|
183
|
+
// Build section
|
184
|
+
if (hasCMake) {
|
185
|
+
ss << "3. Build the project using CMake\n"
|
186
|
+
<< " ```bash\n"
|
187
|
+
<< " mkdir build\n"
|
188
|
+
<< " cd build\n"
|
189
|
+
<< " cmake ..\n"
|
190
|
+
<< " cmake --build .\n"
|
191
|
+
<< " ```\n\n";
|
192
|
+
} else if (hasMakefile) {
|
193
|
+
ss << "3. Build the project\n"
|
194
|
+
<< " ```bash\n"
|
195
|
+
<< " make\n"
|
196
|
+
<< " ```\n\n";
|
197
|
+
}
|
198
|
+
|
199
|
+
// Docker section
|
200
|
+
if (hasDockerfile) {
|
201
|
+
ss << "### Docker Installation\n\n"
|
202
|
+
<< "Alternatively, you can build and run using Docker:\n\n"
|
203
|
+
<< "```bash\n"
|
204
|
+
<< "docker build -t " << std::filesystem::path(projectRoot).filename().string() << " .\n"
|
205
|
+
<< "docker run " << std::filesystem::path(projectRoot).filename().string() << "\n"
|
206
|
+
<< "```\n\n";
|
207
|
+
}
|
208
|
+
|
209
|
+
return ss.str();
|
210
|
+
}
|