-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-hpp.js
More file actions
52 lines (41 loc) · 2.33 KB
/
generate-hpp.js
File metadata and controls
52 lines (41 loc) · 2.33 KB
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
const fs = require('fs');
const path = require('path');
const outputFile = path.join(__dirname, 'cclip.hpp');
const includesDirectory = path.join(__dirname, 'includes');
const sourceDirectory = path.join(__dirname, 'src');
const includes = fs.readdirSync(includesDirectory).filter(file => file.endsWith('.h'))
const sources = fs.readdirSync(sourceDirectory).filter(file => file.endsWith('.cpp'));
const legalHeader = `/**
This file is part of the CClip project, a simple and convenient library for handling command line arguments in C++ applications.
The primary purpose of CClip is to make the parsing of command-line options easier, providing a structured and consistent way to manage command-line inputs.
It enables developers to define specific command-line options and arguments that their applications can accept. Once these options are defined, CClip allows them to be easily parsed and retrieved when the application is run, reducing the complexity associated with command-line input handling.
The parsing functionality provided by CClip is intuitive and efficient, making it an ideal choice for any C++ application that requires command-line input functionality.
For more information please visit our github page at https://github.com/Drew-Chase/cclip
*/`
const version= '0.1.0';
let content = '';
// Include the content of all header files
for (const include of includes) {
const includeFileContent = fs.readFileSync(path.join(includesDirectory, include), 'utf8');
content += removeLocalIncludes(includeFileContent);
}
// Include the content of all source files
for (const source of sources) {
let sourceFileContent = fs.readFileSync(path.join(sourceDirectory, source), 'utf8');
content += removeLocalIncludes(sourceFileContent);
}
function removeLocalIncludes(content) {
const includesFound = content.match(/#include\s*".*"/g);
if (includesFound) {
for (const include of includesFound) {
const includeFile = include.replace('#include "', '').replace('"', '');
if (includes.includes(includeFile)) {
content = content.replace(include, '');
}
}
}
return content;
}
content = content.replace(/#pragma once/g, '');
content = `${legalHeader}\n\n#pragma once\n#define CCLIP_VERSION "${version}"\n${content}`
fs.writeFileSync(outputFile, content);