0.5.5 • Published 4 years ago

tramway v0.5.5

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
4 years ago

Tramway is a development utility to facilitate rapid development by generating common boilerplate and providing the necessary build tools to create an application with Javascript. It includes:

  1. Command for creating routes and controllers
  2. Installation utility for tramway pieces
  3. Build tools so you don't need to configure them yourself

Installation

  1. Generate a new project with npm init
  2. npm install --save-dev tramway and npm install -g tramway

Documentation

  • Usage
  • Install Tramway
  • Build Your Project
  • Create API
  • Create Route
  • Create Controller
  • Create Service
  • Create Entity
  • Create Provider
  • Create Repository
  • Upgrade Babel
  • Configuration

Usage

Replace the COMMAND with the appropriate one from the table below with its corresponding arguments and options.

If installed globally:

tramway COMMAND

Otherwise:

./node_modules/.bin/tramway COMMAND

All commands that create new classes will update the corresponding index.js entries.

Install Tramway

Will install the core modules your application needs with tramway or specific pieces as specified in the arguments. It will also add the necessary files to your project, and entries to gitignore. Note, this command will modify your package.json and package-lock.json files.

ArgumentCommand TypeTypeDefaultRequiredComments
piecesargumentstringnonenoA list of tramway modules to install

Example:

To install the base:

tramway install

To add modules, like a MySQLProvider:

tramway install mysql

Build your project

In most projects you need to set up gulp or grunt or webpack yourself. To get you started quickly, this module includes a build command which will handle the process for you granted you follow the folder convention.

You can also add the command to your package.json scripts to continue using the familiar hooks like npm run build.

Example:

tramway build

Will run gulp tasks on your src folder and create a ready dist folder.

Start your project

In most projects you will likely set up a server to run your project with. To get you started quickly, this module includes a dev server which can watch and auto-build on changes if you specify it.

Example:

tramway start

Create API

Will create all the necessary classes and mappings to have a full API ready. The routes follow REST and are automatically mapped to their controller action with services instantiated and linked in the Dependency Injection configuration.

ArgumentCommand TypeTypeDefaultRequiredComments
resourceargumentstringnoneyesThe name of the Resource to use for all naming
provideroptionstringnoneyesAdds a provider key to the Repository declaration to link them

Example:

tramway create:api Product --provider=mysql

This command will create the following new files and update corresponding index.js files, as well as configuration files:

+ config
++ services
 +- services.js
 +- repositories.js
 +- factories.js
 +- controllers.js
+- routes.js
+ entities
+- Product.js
+ controllers
+- ProductController.js
+ services
+- ProductService.js
+ repositories
+- ProductRepository.js
+ factories
+- ProductFactory.js

Create Route

Will add the necessary routing config to the routes file in the config folder and optionally create the corresponding Controller file with its index.

ArgumentCommand TypeTypeDefaultRequiredComments
controllerargumentstringnoneyesThe name of the Controller class associated to the route
actionargumentstringnoneyesThe name of the method in the Controller class associated to the route
pathargumentstringnonenoThe url path of the route
methodsoptionarraynonenoAn array of http methods the route accepts
argsoptionarraynonenoAn array of arguments the url accepts
create-controlleroptionbooleanfalsenoA flag set to indicate a Controller and corresponding function stub should be generated by the command
diroptionstringconfignoAn option to override the default folder the routing config will be placed in
controller-diroptionstringcontrollersnoAn option to override the default folder where controllers are stored
filenameoptionstringroutesnoAn option to override the default name of the routing config file

Example:

tramway create:route StuffController myAction /hey --methods get post --args id --create-controller --dir conf

Create Controller

Will add a new Controller file with a skeleton for methods and optionally add routes to the config.

ArgumentCommand TypeTypeDefaultRequiredComments
nameargumentstringnoneyesThe name of the Controller class
diroptionstringcontrollersnoAn option to override the default folder the Controller class will be created in
actionsoptionarraynonenoAn array of methods the Controller will have
add-routesoptionbooleanfalsenoA flag to indicate that a route should be created when making the Controller
routes-diroptionstringconfignoAn option to override the default folder where the routing config will be placed
routes-filenameoptionstringroutesnoAn option to override the default filename of the routes config
versionoptionnumberlatestnoAn option to specify which version of the class to use

Example:

tramway create:controller StuffController --add-routes --actions action1 action2 action3 --routes-dir conf

Create Service

Will add a new Service file with a constructor featuring dependency mapping for dependency injection.

ArgumentCommand TypeTypeDefaultRequiredComments
nameargumentstringnoneyesThe name of the Service class
diroptionstringservicesnoAn option to override the default folder the Service class will be created in
dependenciesoptionarraynonenoAn array of dependencies the Service will have
add-dependency-injectionoptionbooleanfalsenoA flag to indicate that a service declaration should be created when making the Service
keyoptionstringnonenoThe name of the key to use in dependency injection configuration
dependency-injection-diroptionstringservicesnoAn option to override the default folder where the service config will be placed
dependency-injection-filenameoptionstringservicesnoAn option to override the default filename of the service config
versionoptionnumberlatestnoAn option to specify which version of the class to use

Example:

tramway create:service StuffService  --dependencies dep1 dep2 dep3 --dir testservices

Create Entity

Will add a new Entity file with getters and setters for specified properties.

ArgumentCommand TypeTypeDefaultRequiredComments
nameargumentstringnoneyesThe name of the Entity class
diroptionstringentitiesnoAn option to override the default folder the Entity class will be created in
propertiesoptionarraynonenoAn array of properties the Entity will have
versionoptionnumberlatestnoAn option to specify which version of the class to use

Example:

tramway create:entity Product --properties width height price

Create Factory

Will add a new Factory file with a placeholder for building the entity.

ArgumentCommand TypeTypeDefaultRequiredComments
nameargumentstringnoneyesThe name of the Factory class
diroptionstringentitiesnoAn option to override the default folder the Factory class will be created in
versionoptionnumberlatestnoAn option to specify which version of the class to use

Example:

tramway create:factory ProductFactory --add-dependency-injection --key factory.product

Create Provider

Requires tramway-core-connection v 2.0.0^ Will add a new Provider file with supported stubs and the option of adding to dependency injection.

ArgumentCommand TypeTypeDefaultRequiredComments
nameargumentstringnoneyesThe name of the Provider class
diroptionstringconnectionsnoAn option to override the default folder the Provider class will be created in
add-dependency-injectionoptionbooleanfalsenoA flag to indicate that a service declaration should be created when making the Provider
keyoptionstringnonenoThe name of the key to use in dependency injection configuration
dependency-injection-diroptionstringservicesnoAn option to override the default folder where the service config will be placed
dependency-injection-filenameoptionstringservicesnoAn option to override the default filename of the service config
versionoptionnumberlatestnoAn option to specify which version of the class to use

Example:

tramway create:provider MySQLProvider --add-dependency-injection --key provider:mysql

Create Repository

Will add a new Repository file with supported stubs and the option of adding to dependency injection with linked connection.

ArgumentCommand TypeTypeDefaultRequiredComments
nameargumentstringnoneyesThe name of the Repository class
diroptionstringrepositoriesnoAn option to override the default folder the Repository class will be created in
add-dependency-injectionoptionbooleanfalsenoA flag to indicate that a service declaration should be created when making the Repository
keyoptionstringnonenoThe name of the key to use in dependency injection configuration
connectionoptionstringnonenoThe key of the connection in the service declaration
dependency-injection-diroptionstringservicesnoAn option to override the default folder where the service config will be placed
dependency-injection-filenameoptionstringservicesnoAn option to override the default filename of the service config
versionoptionnumberlatestnoAn option to specify which version of the class to use

Example:

tramway create:repository ProductsRepository --add-dependency-injection --connection connection:things --key repositories:products

Upgrade Babel

The upgrade babel command will replace the old setup - as per the way the Tramway (<0.5.0) initially installed it - with the new set up, upgrading babel presets to their 7.0 versions.

Example:

tramway upgrade:babel

Configuration

The commands create their files in the default scalpel that TramwayJS follows

+ src
+- config
+- controllers
+- services
+- entities
+- repositories
+- providers
+- commands

In some projects, however, the structure can vary and the framework is able to adapt to adjustments using environment variables.

VariablePurposeDefault
TRAMWAY_PROJECT_PATHThe root path of the project./src
TRAMWAY_PROJECT_CONTROLLERS_PATHPath to controllers appended to TRAMWAY_PROJECT_PATHcontrollers
TRAMWAY_PROJECT_ENTITIES_PATHPath to entities appended to TRAMWAY_PROJECT_PATHentities
TRAMWAY_PROJECT_SERVICES_PATHPath to services appended to TRAMWAY_PROJECT_PATHservices
TRAMWAY_PROJECT_CONNECTIONS_PATHPath to connections appended to TRAMWAY_PROJECT_PATHconnections
TRAMWAY_PROJECT_REPOSITORIES_PATHPath to repositories appended to TRAMWAY_PROJECT_PATHrepositories
TRAMWAY_PROJECT_PROVIDERS_PATHPath to providers appended to TRAMWAY_PROJECT_PATHproviders
TRAMWAY_PROJECT_CONFIG_PATHPath to config appended to TRAMWAY_PROJECT_PATHconfig
TRAMWAY_PROJECT_ROUTES_FILEName of the routes file storied in the config directoryroutes
TRAMWAY_PROJECT_SERVICES_FILEName of the services file storied in the config directoryservices

Example:

TRAMWAY_PROJECT_PATH=./dev tramway create:service Service

This command will create a new Service.js file in ./dev/services. It has the same behavior as overriding the dir using the dir option but is meant for a global application.

0.5.4

4 years ago

0.5.5

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.3

5 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago