This python script helps you generate a component for your angulardart project (instead of using the traditional ngdart generate component command). This will create the html, css and the dart file with some general boilerplate for the dart and the html file. This also creates a folder in the lib/src folder of your project for the component with all the files, instead of just generally creating the html and dart file in the lib/src folder as done by the ngdart generate component command.
Although you can change the folder name by using -p in the ngdart command it does not create the css file and you also have to manually create the subfolder inside the main folder where you wish to create the component. This file is more in line with what the ng generate component command for Angular with typescript feels like. If in future there are any changes in the ngdart generate component command please refer to that. This code will howerver work in any case.
If you wish to use the command directly just copy the compiled folder to your C drive and add the path to the folder in your environment variables
- Clone or download the repository on your local machine.
- Once the you have downloaded the project go into the project folder and open your bash terminal(for MAC/UNIX/LINUX users) or open git bash (for Windows users).
- Once you open the terminal run the following command:
cp create-component ~/bin
Note: If you get an error in the above command run the below command first:
mkdir -p ~/bin
- Once you have copied the script to your bin folder run the following command to bin to your path:
export PATH=$PATH":$HOME/bin"
- Once all the above steps have been executed successfully you can run the following command in your AngularDart project folder tp create a component:
create-component <component_name> [<subfolder_name>]
You will see that it creates a component folder under /lib/src or under /lib/src/subfolder_name with all your html, dart and css files.
- Using it with just the component_name:
create-component home
- Creating inside a subfolder
create-component home main
- Creating the component within multiple subfolders
create-component home main/page
In case the other steps do not work for you follow the following steps (Make sure to run these steps you have the .py extension of your file added):
- Install pyinstaller using pip by running the following command:
pip install pyinstaller
NOTE: Make sure you have python version below 3.9 installed on your system as 3.9 gives issues in pip install (This is during the time of the writing of this document).
- Run the following command inside the folder with the python file:
pyinstaller --onefile create-component
- Once you run the command it will create the following file structure:
│ ngdartgc.py
│ ngdartgc.spec
│
├───build
│ └───ngdartgc
├───dist
│ ngdartgc.exe
└───__pycache__
ngdartgc.cpython-37.pyc
- Copy over all the files mentioned above in a folder inside the C drive or if you wish to keep the file where it is then move forward to the next step
- Add the path to your dist folder to your environment variables.
- Now you can run the following command:
create-component.exe <component_name> [<subfolder_name>]
- Using it with just the component_name:
create-component.exe home
- Creating inside a subfolder
create-component.exe home main
- Creating the component within multiple subfolders
create-component.exe home main/page
If you wish to create your own name for the command instead of create-component command then once you clone/download the repository you can change the python(create-component) file name and give it whatever name you like and you can call that command(file name) when creating the components
-
Making command line python script
https://dbader.org/blog/how-to-make-command-line-commands-with-python -
Download git bash for windows
https://git-scm.com/downloads -
Create Python Executable file
https://datatofish.com/executable-pyinstaller/