Skip to content

Commit

Permalink
feat: rename to filegen, support template file, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
galenlin committed Jul 20, 2023
1 parent 6674ca4 commit 786d4af
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 212 deletions.
162 changes: 89 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,125 @@
# A simple C++ Class Creator with multiple settings :alien:
# VSCode File Generator

Fork from https://github.com/tzAcee/cpp-class-creator v1.0
Rewrite by Galen Lin, <[email protected]>
Create files in your format.

## Info about v1.0
Supported generators:
* C++ Class & UnitTest file with Google Style.
* TODO: more

In order to increase the flexiblity I implemented a command pattern which can be used to customize own presets for header/source files and it's names. For that I removed all customization options which I added in version <1.0. All of this options can be replaced with the new way of handling the files.
## Configuration

The syntax is {{\*COMMAND\*}} eg. {{\*CLASSNAME\*}}
### filegen.json

#### Available Commands:
Create in your project root.

For file name presets:
- CLASSNAMEUPPER - default classname to upper
- CLASSNAMELOWER - default classname to lower
- CLASSNAMECAPI - default classname with capitalized first letter
- CLASSNAME - default classname
```json
{
"module": "mymodule", // The C++ modalar header
"namespace": "wq", // The C++ class namespace
"organization": "Wequick", // The organization show in copyright
}
```

For file content presets:
### template files

- HEADERFILENAME - default headerfilename as entered in settings
- SOURCEFILENAME - default sourcefilename as entered in settings
- CLASSNAMEUPPER - default classname to upper
- CLASSNAMELOWER - default classname to lower
- CLASSNAMECAPI - default classname with capitalized first letter
- CLASSNAME - default classname
Depending on your platform, the global template path is located here:

* Windows %APPDATA%\Code\User\globalStorage\wequick.filegen.
* macOS $HOME/Library/Application\ Support/Code/User/globalStorage/wequick.filegen.
* Linux $HOME/.config/Code/User/globalStorage/wequick.filegen.

## Features
Or you can create `filegen` folder in your project root to overwrite.

Press **Alt**+**X** to open the Input Field to create a class, <span style="color:red">**while you are focusing the editor!**</span>
Files:
```
filegen
|____${FILENAME}.h // [cpp] header file
|____${FILENAME}.cc // [cpp] source file
|____${FILENAME}_unittest.cc // [cpp] unittest file
```

Type in the name, and there you go. You will directly see, when the file is created.
#### [cpp] header file

Additionaly you can set the path where the file has to be created and customize your own header/source file preset: check Settings at the bottom.
Default as:

![Demo](https://github.com/tzAcee/cpp-class-creator/blob/master/giphy.gif?raw=true)
```cpp
//
// Created by ${USER} on ${DATE}.
// Copyright (c) ${YEAR} ${ORGANIZATION}. All rights reserved.
//

## Settings [settings.json of VS-Code]
#ifndef ${HEADER_GUARD}
#define ${HEADER_GUARD}

```"cpp.creator.headerFileContentPreset": = "string"``` customize your created headerfile content with this setting.
#include <cstring>

Default is:
```
#ifndef {{*CLASSNAMEUPPER*}}_H
#define {{*CLASSNAMEUPPER*}}_H
#pragma once
class {{*CLASSNAME*}}
{
public:
{{*CLASSNAME*}}();
~{{*CLASSNAME*}}();
private:
};
#endif
```
namespace ${NAMESPACE} {

```"cpp.creator.sourceFileContentPreset": = "string"``` customize your created sourcefile content with this setting.
class ${CLASSNAME} {
public:

private:
};

Default is:
```
#include "{{*HEADERFILENAME*}}"
{{*CLASSNAME*}}::{{*CLASSNAME*}}()
{
} // namespace ${NAMESPACE}

}
{{*CLASSNAME*}}::~{{*CLASSNAME*}}()
{
#endif // ${HEADER_GUARD}"

}
```

```"cpp.creator.sourceFileNamePreset": = "string"``` customize your sourcefile name with this setting.
#### [cpp] source file

Default is:
```
{{*CLASSNAME*}}.cpp
```
Default as:

```"cpp.creator.headerFileNamePreset": = "string"``` customize your headerfile name with this setting.
```cpp
//
// Created by ${USER} on ${DATE}.
// Copyright (c) ${YEAR} ${ORGANIZATION}. All rights reserved.
//

#include "${HEADER_PATH}"

namespace ${NAMESPACE} {


} // namespace ${NAMESPACE}

Default is:
```
{{*CLASSNAME*}}.h
```
```"cpp.creator.setPath": = "string" | null | boolean : [NULL by default] ``` set your path where the class should be created as a string. When it's null your class will be created in the current workspace. Set it to true, when you want a input window to appear on every class creation where you can set creation path. On false or on an empty path input box it will also be created in the current workspace.
#### [cpp] unittest file
Default as:
```"cpp.creator.createFolder": = boolean : [FALSE by default] ``` set it to true, so a folder for the class will be created in your workspace -> Only possible when setPath is null.
```cpp
//
// Created by ${USER} on ${DATE}.
// Copyright (c) ${YEAR} ${ORGANIZATION}. All rights reserved.
//
---
#include <gtest/gtest.h>
${MODULE_INCLUDE}
Have fun.
namespace ${NAMESPACE} {
Make Pull Request when you have feature ideas & if you want, support me by sponsoring my github account :)
TEST(${CLASSNAME}Tests, test_any) {
ASSERT_EQ(1, 1);
}
### Changelog
} // namespace ${NAMESPACE}
```

- See Info about v1.0
## Variables

**Enjoy!**
The variable format is `${KEY}`, the `KEY` supports following:

GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
* **FILENAME** - The file name your input. e.g. `file_generator`
* **CLASSNAME** - The class name. From the file name in camel style, e.g. `FileGenerator`
* **USER** - The user. Configured by `git config user.name [USER]`. e.g. `Galen Lin`
* **ORGANIZATION** - The organization. Configured by `organization` filed in `filegen.json` file. e.g. `Wequick`
* **YEAR** - The year of now. e.g. `2023`
* **DATE** - The date of now. Format as 'YYYY-MM-DD', e.g. `2023-07-17`
* **HEAD_GUARD** - The google-style header guard. From the relative-path-to-project-root in upper case, e.g. `WEQUICK_FILE_GENERATOR_H_`
* **HEADER_PATH** - The current header path. From the relative-path-to-project-root join with the file name. e.g. `wequick/file_generator.h`
* **MODULE_INCLUDE** - The modular header includement. If `module` is specified in `filegen.json` then returns '#include <`module`/`module`.h>\n', e.g. `#include <mymodule/mymodule.h>\n`
* **NAMESPACE** - The class namespace. Returns the `namespace` field specified in `filegen.json` or fallback to the project root directory name. e.g. `myproject`
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 19 additions & 42 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "cpp-creator",
"displayName": "C++ Class Creator",
"description": "A simple class creation extension support Google Style and UnitTest",
"name": "filegen",
"displayName": "Code File Generator",
"description": "Create files in your format. Supported generator: C++ Class & UnitTest file with Google Style. More coming soon.",
"publisher": "Wequick",
"icon": "icon/logo.png",
"repository": {
"url": "https://github.com/wequick/vsext-cpp-class-creator.git"
"url": "https://github.com/wequick/vscode-filegen.git"
},
"version": "1.0.0",
"engines": {
Expand All @@ -14,11 +14,17 @@
"categories": [
"Other"
],
"activationEvents": [
"onCommand:extension.createClassAndUnitTest",
"onCommand:extension.createClass",
"onCommand:extension.createUnitTest"
"keywords": [
"generator",
"c++",
"class",
"unittest",
"file",
"template",
"google",
"style"
],
"activationEvents": ["onStartupFinished"],
"main": "./out/extension.js",
"contributes": {
"commands": [
Expand Down Expand Up @@ -69,43 +75,14 @@
],
"configuration": [
{
"title": "C++ Class Creator",
"title": "File Generator",
"properties": {
"cpp.creator.setPath": {
"filegen.templatePath": {
"type": [
"string",
"null",
"boolean"
"string"
],
"default": null,
"description": "Specifies the path, where the class is created or set it to true when you want the path to be dynamically inputted. [setting: cpp.creator.setPath = \"path\" or true]"
},
"cpp.creator.headerFileContentPreset": {
"type": "string",
"editPresentation": "multilineText",
"default": "#ifndef {{*CLASSNAMEUPPER*}}_H\n#define {{*CLASSNAMEUPPER*}}_H\n\n#pragma once\n\nclass {{*CLASSNAME*}}\n{\npublic:\n {{*CLASSNAME*}}();\n ~{{*CLASSNAME*}}();\n\nprivate:\n\n};\n\n#endif",
"description": "Content of your created header file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMECAPI*}} - default classname with capitalized first letter.\n{{*HEADERFILENAME*}} - default headerfilename as entered in the settings. \n{{*SOURCEFILENAME*}} - default sourcefilename as entered in the settings."
},
"cpp.creator.sourceFileContentPreset": {
"type": "string",
"editPresentation": "multilineText",
"default": "#include \"{{*HEADERFILENAME*}}\"\n\n{{*CLASSNAME*}}::{{*CLASSNAME*}}()\n{\n\n}\n\n{{*CLASSNAME*}}::~{{*CLASSNAME*}}()\n{\n\n}",
"description": "Content of your created source file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMECAPI*}} - default classname with capitalized first letter.\n{{*HEADERFILENAME*}} - default headerfilename as entered in the settings. \n{{*SOURCEFILENAME*}} - default sourcefilename as entered in the settings."
},
"cpp.creator.sourceFileNamePreset": {
"type": "string",
"default": "{{*CLASSNAME*}}.cpp",
"description": "Name of your source file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters."
},
"cpp.creator.headerFileNamePreset": {
"type": "string",
"default": "{{*CLASSNAME*}}.h",
"description": "Name of your header file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters."
},
"cpp.creator.createFolder": {
"type": "boolean",
"default": false,
"description": "Create an extra folder for the class."
"default": "filegen",
"description": "Specifies the path, where the template files located in."
}
}
}
Expand Down
Loading

0 comments on commit 786d4af

Please sign in to comment.