Easily generate, save and load project structures on the fly!
Table of contents
- Quick example
- Generating structures
- Initializing files with content
- Saving and re-using templates
YSGen (Yaml Structure Generator) is a package that allows you to easily generate a scaffolding project structure by using a yaml file to represent the project's structure.
Below you will find a yaml file that represents a project's structure. You may notice that this looks similar to a document tree.
index.php: App: Controllers: PagesController.php: TaskController.php: router.php: Models: User.php: Post.php: public: css: js: images: assets: views: layout.html: pages: page.html: sass: app.sass: js: app.js:
After running the
ysgen generate command on this file, you will create the actual project structure that is inside that
│ index.php │ structure.yml │ ├───App │ │ router.php │ │ │ └───Controllers │ PagesController.php │ TaskController.php │ ├───assets │ ├───js │ │ app.js │ │ │ ├───sass │ │ app.sass │ │ │ └───views │ │ layout.html │ │ │ └───pages │ page.html │ ├───Models │ Post.php │ User.php │ └───public ├───css ├───images └───js
- Choose a location to store this application. In this example I will use
C:/Program Filesas the location.
git clone https://github.com/glowdemon1/ysgen
- Add the ysgen installation path to your system's path variables.
C:/Program Files/ysgen/in this example.
To create a new project structure, you must first create a folder and create a file called
structure.yml inside that folder. The
structure.yml file represents the projects structure, this file should not be named differently!
App: Controllers: PagesController.php: TaskController.php: router.php:
- The first line creates an
Appdirectory. (Note that ALL lines must end with a column ':' unless you want to add content to that file).
- The second line creates a
Controllersdirectory inside the
Appdirectory (notice how the indentation relates to that?).
- The third and fourth line both create a
.phpfile inside the
App/Controllersdirectory. (To create a file you end the name with an extension, else it will be seen as a folder).
- And finaly the last line creates a
router.phpfile inside the
After you have made your
structure.yml file you can open the command prompt, change the directory to your project's folder and use
ysgen generate. This will create the project structure for you. You may delete the
structure.yml file after use, or save it.
Initializing files with content
You can also insert content in files when generating your project structure. Take a look at the example below:
index.php: | <html> <head> <title>test</title> </head> <body> <h1>You can also initialize files with content!</h1> </body> </html> App: Controllers: PagesController.php: TaskController.php: router.php:
The above example will generate the following structure:
│ index.php │ structure.yml │ └───App │ router.php │ └───Controllers PagesController.php TaskController.php
If you take a closer look at
index.php file, you'll notice that it's populated with the following:
<html> <head> <title>test</title> </head> <body> <h1>You can also initialize files with content!</h1> </body> </html>
Simply place a pipe symbol after the filename and start your content on the next line followed by a single level of indentation. Please note that the colon and the pipe must have a space between eachother. See this post for more info.
Saving and re-using templates
structure.yml files can be easily saved and re-used later as templates. The files will be stored under the
data folder in your YSGen installation folder. To save a file:
ysgen save <name> where
<name> is the name you want to save this file under. Afterwards you can easily run
ysgen generate <name> to generate a project structure from a saved template.
C:\Users\Me\Desktop\test>ysgen | generate: | Arguments: <optional:name> | Description: Generates a project's structure, uses saved template if name is specified. + | save: | Arguments: <name> | Description: Save a local structure.yml and make it usable globally. + | list: | Arguments: <> | Description: List all globally available templates.