spacecraft-cli v0.1.0
Spacecraft CLI tool
This project, and the main Spacecraft project, is under heavy production. Do not use in production environments.
This is a command line tool for the Spacecraft PHP package. This tool enables you to easily create new projects, generate new classes and routes, and spin up a web server quickly.
Spacecraft
Spacecraft is a wrapper around the Slim Framework, Twig and Illuminate Database packages. For more information, please visit Spacecraft’s GitHub-repositry.
Installation
The CLI tool is installed requires Node.js and is installed via npm. If you don’t have Node.js, visit https://nodejs.org/ for instructions on how to download it. When you have Node installed, just run:
$ npm install -g spacecraft-cli
After the installation is finished, you will be able to use the tool with the spacecraft
command.
spacecraft.json
The spacecraft.json
file is created automatically when you run the spacecraft new
command. It contains data that is needed to use the other commands, and looks like this:
{
"name": "webapp",
"namespace": "MyApp",
"public": "public",
"port": 8089,
"mode": "development"
}
Usage
Creating a new project
$ spacecraft new webapp
Creating new project 'webapp'...
This command creates a new project, in this case called webapp. Of course, replace webapp with the name you want to give your project, e.g. spacecraft new <project name>
.
The new
command will also ask you for a namespace which will be used for your classes. It will then generate a project structure for you, as well as create some basic files you will need. The command will also run composer install
, which may take some time.
Generating classes
$ spacecraft controller Auth
Creating controller 'AuthController'...
$ spacecraft model User
Creating model 'User'...
These commands generates classes for you in appropriate locations. The controller
command will create a controller class in the app/lib/Controllers
directory and generate some basic code.
Likewise, the model
command will generate a model in the app/lib/Models
directory and generate some basic code as well.
Generating routes
$ spacecraft route get /users/{id} UserController:find
Routing GET '/users/{id}' to UserController:find...
This command generates a route inside the app/routes/routes.php
file. You use the command as spacecraft route <method> <route> (optional: <callback>)
, that is, you may ommit the callback
parameter and a closure will be generated for you instead.
Run built in PHP server
$ spacecraft run
Spacecraft server running on localhost:8089
This command spins up the built in PHP server and sets the document root and port as specified in the spacecraft.json
file.
Contributions
Everyone is welcome to contribute to both this project and the main Spacecraft project. Just create an issue and/or pull request.
If you just have an opinion, idea or want to report a bug, please submit an issue.
License
MIT.