MEANJS Yo Generator

Overview

One of the most frequently asked features from MEAN users is a way to scaffold their applications. As we looked for a way to help the community build and deploy production level MEAN applications, we decided to go with a Yeoman generator. Yeoman generators provides a powerful, easy to maintain, and open solution for scaffolding applications.

So, we set out to work on the features we thought every developer needs, and we are proud to present the official MEAN.JS Yeoman generator. It includes a set of simple tools you can use to make your MEAN application development easier and way more fun.

Getting Started

Before you begin make sure you have the yo scaffolding tool installed(As it is part of the Yeoman tool set you might have installed it before). To globally install yo you will need to use npm:

$ npm install -g yo

Note: Your user might not have the permissions to install package globally, so use a super user or sudo.

Once you have yo installed, you will need to install the MEAN.JS generator as well:

$ npm install -g generator-meanjs

You are now ready to get started with the MEAN.JS generator. The generator will help you create a MEAN.JS application, a CRUD module, Angular Module, and other AngularJS/Express entities. We’ll begin with the application generator.

Application Generator

The application generator will help you create a fresh copy of a MEAN.JS application in your working folder. To create your MEAN application, navigate to a new project folder, and then use yo to generate your application:

$ yo meanjs

The generator will ask you a few questions about your new application and will generate it for you. When the installation process is over, you will be able to use grunt to run your new MEAN application:

$ grunt

Now, the application generator does a great job scaffolding a whole application, but daily work requires us to repeat a lot of structured code. For this purpose we provided you with some sub-generators to help you speed up your development.

CRUD Module Sub-Generator

The CRUD module sub-generator will help you create a new CRUD module, similar to the article sample provided with the project. To create a new CRUD module you will need to use yo again:

$ yo meanjs:crud-module <module-name>

This will create both AngularJS and Express files supporting full CRUD functionality, and add the Karma and Mocha tests.

Note: Don’t forget to use your module name as an argument when calling the CRUD module sub-generator.

AngularJS Module Sub-Generator

Another redundant task is creating a new AngularJS module structure. For this purpose you can use the Angular module sub-generator. It will create the proper folder structure for you and the module initialization file. Creating a new AngularJS module is simple:

$ yo meanjs:angular-module <module-name>

The sub-generator will ask for more information about your folder structure, and will create the empty new AngularJS module. Now, to fill that new module with your business logic, we provided you with several AngularJS entities sub-generators.

AngularJS Route Sub-Generator

To construct your module you will often need to create a new route. The AngularJS route sub-generator will help you create a view, controller and a proper route in your module routes.js file. If it can’t find the module routes file the sub-generator will create one for you. Creating a new AngularJS route will involve executing this command:

$ yo meanjs:angular-route <route-name>

The sub-generator will ask for more information about your controller, view and routing URL, and will generate the appropriate files for you.

AngularJS Controller Sub-Generator

The AngularJS Controller sub-generator will create a new AngularJS controller in the specified module‘s controllers folder. To create a new AngularJS controller run yo again by using this command:

$ yo meanjs:angular-controller <controller-name>

The sub-generator will ask you for the module name under which you would like to create your new controller, and will create a new AngularJS controller file in that module controllers folder and a controller test in the module tests folder.

Don’t forget! This time you pass the controller name as an argument.

AngularJS View Sub-Generator

Once you have your controller file ready, you may want to add a view that makes use of this controller. The AngularJS view sub-generator will create a new AngularJS view in thr specified module‘s views folder, and will allow you to add a route definition for it. To create a new AngularJS view you will need to execute this command:

$ yo meanjs:angular-view <view-name>

The sub-generator will ask you for the module name under which you would like to create your new view, and some additional routing information. It will then create a new view file in that module‘s views folder and add a routing state to the moduleroutes.js file. If it can’t find the module routes file it will create one for you.

AngularJS Service Sub-Generator

The AngularJS service sub-generator will create a new AngularJS service in the specified module‘s services folder. To create a new AngularJS service you will need to execute this command:

$ yo meanjs:angular-service <service-name>

The sub-generator will ask you for the module name under which you would like to create your new service, and will create a new AngularJS service file in that module‘s services folder.

AngularJS Directive Sub-Generator

The AngularJS directive sub-generator will create a new AngularJS directive in the specified module‘s directives folder. Creating a new AngularJS directive should already look familiar:

$ yo meanjs:angular-directive <directive-name>

The sub-generator will ask you for the module name under which you would like to create your new directive, and will create a new AngularJS directive file in that module‘s directives folder.

AngularJS Filter Sub-Generator

The AngularJS filter sub-generator will create a new AngularJS filter in a specified module‘s filters folder. To create a new AngularJS filter you need to call yo again:

$ yo meanjs:angular-filter <filter-name>

The sub-generator will ask you for the module name under which you would like to create your new filter, and will create a new AngularJS filter file in that module filters folder.

AngularJS Config Sub-Generator

The AngularJS config sub-generator will create a new AngularJS config section in a specified module‘s config folder. To create a new AngularJS config file just call yo:

$ yo meanjs:angular-config <config-name>

The sub-generator will ask you for the module name under which you would like to create your new config, and will create a new AngularJS config file in that module‘s config folder.

AngularJS Test Sub-Generator

Your MEAN application comes pre-bundled with the Karma test runner and Jasmine testing framework. To test your AngularJS controllers you’ll need to create a test file, which Karma will later use to run the tests. For this purpose we provided you with the AngularJS test sub-generator. Creating a new AngularJS test is effortless, just execute this command:

$ yo meanjs:angular-test <controller-name>

This will create a test file for your controller, and if the sub-generator doesn’t find the specified controller file, it will create one for you.

Don’t forget! You‘re suppose to pass the controller name as an argument.

Express Model Sub-Generator

Often you will find the need to just create a single Express model. The Express model sub-generator will help you with creating an Express model in the app/models folder. To create a new model just use yo:

$ yo meanjs:express-model <model-name>

This will create a new empty model in the app/models folder and a new model test in the app/tests folder.

Note: It is recommended you avoid naming your model in plural form and use a singular form instead. i.e article and not articles

Express Controller Sub-Generator

Another recurring task is creating an empty Express controller. The Express controller sub-generator will help you with creating an Express controller in the app/controllers folder. To create a new controller just use yo:

$ yo meanjs:express-controller <controller-name>

This will create a new empty controller in the app/controllers folder.

Express Routes Sub-Generator

To make HTTP requests to your controller methods you will need to use a routing file in the app/routes folder. The Express routes sub-generator will help you to add a new empty routes file. To create a new routes file execute this yo command:

$ yo meanjs:express-route <route-name>

This will create a new empty route file in the app/routes folder.

Express Test Sub-Generator

Your MEAN application comes pre-bundled with the Mocha testing framework. To test your Express models you’ll need to create a new test file, which Mocha will use while running tests. For this purpose we provided you with the Express test sub-generator. Creating a new Express test is easy, just execute this command:

$ yo meanjs:express-test <model-name>

This will create a test file for your Express model, and if the sub-generator doesn’t find the specified model, it will create one for you.

Don’t forget! You‘re suppose to pass the model name as an argument.

时间: 2024-11-06 22:19:28

MEANJS Yo Generator的相关文章

使用MeanJS Yeoman Generator

1.首先全局安装该生成器 sudo npm install -g generator-meanjs 2.为项目创建一个路径 mkdir xmen && cd xmen 3.创建app yo meanjs 根据提示,输入应用名,描述,关键词,是否创建crud例子.. 4.运行app sudo NODE_ENV=development grunt 以开发环境运行app 如果使用production环境运行,需要在运行前,先生成下 grunt build 5.添加crud模块 yo meanjs

MEANJS DOC

Overview Thank you for downloading the MEAN.JS boilerplate! This simple documentation will cover the basics of developing your MEAN application. Before you begin we recommend you read about the basic building blocks that assemble a MEAN.JS applicatio

用MeanJS和Yeoman生成器生成【翻译】

One of my favorite things with Yii is the Gii (Generator). 关于Yii(php框架)我喜爱的事情之一是Gii(生成器)Global Information Infrastructure. With a few clicks I could simply add a few Models/Controllers/Views (or all of the above), then build/customize those. 我只需要点击几次

编写自己的yeoman generator

在构建前端项目时,使用yeoman generator可以帮助我们完成新建文件.安装模块.类库等重复性操作,然而已有的generator有时并不能满足需求,所以可以利用yeoman 的API来构建自己的生成器. 这里介绍自定义generator的大致步骤. 1. $ npm install -g generator-generator 2. $ yo generator 输入你的github用户名.生成器的名字(注意命名,yoeman会为你输入的名字添加前缀generator) 看一下生成的文件

Yeoman自动构建js项目(转)

从零开始nodejs系列文章,将介绍如何利Javascript做为服务端脚本,通过Nodejs框架web开发.Nodejs框架是基于V8的引擎,是目前速度最快的Javascript引擎.chrome浏览器就基于V8,同时打开20-30个网页都很流畅.Nodejs标准的web开发框架Express,可以帮助我们迅速建立web站点,比起PHP的开发效率更高,而且学习曲线更低.非常适合小型网站,个性化网站,我们自己的Geek网站!! 前言有一种技术可以提高我们的工作效率,可以让我们专心做我们擅长的事,

yeoman(转)

前言有一种技术可以提高我们的工作效率,可以让我们专心做我们擅长的事,可以屏蔽复杂性,可以规范我们的架构和我们的代码,可以让我们的享受编程的乐趣.Yeoman可以做到. 很多年以前,rails刚刚出世,伴随着一个新的名词“脚手架(scaffolding)”出现了.脚手架是一种提高开发效率的工具的代名词.随后,各种编程语言都开始实现自己的“脚手架”工具.Maven重新构造了Java的世界,改变了几千万的开发者对于Java项目构建的认识.Yeoman在Javascript领域正做着同样的事情. 看着各

grunt插件制作

插件内容:在文件的顶部加入字符画. 一个从无到有的项目,所以我们需要用yeoman来初始化项目.上yeoman官网的generator收纳页搜索gruntplugin. 安装这个generator: npm install -g generator-gruntplugin //generator的命名规则:genetator-generator的名字 生成项目代码 yo gruntplugin grunt-buddha //yo generator的名字 项目的名字 然后cmd会出现项目的配置信

编写自定义Yeoman生成器

转载自JSCON-简时空:<自定义Yeoman生成器> 1.Getting Started 1.1.设置Node模块 Yeoman提供了generator-generator方便快速编写自己的生成器. 安装: npm install -g generator-generator运行: yo generator 创建一个名为generator-name的文件夹(name为你的生成器名);[important] 创建package.json文件,这是NodeJS模块的“信息图”,可以手动或者使用命

NetCore开源项目集合

具体见:https://github.com/thangchung/awesome-dotnet-core 半年前看到的,今天又看到了,记录下. General ASP.NET Core Documentation - The official ASP.NET Core documentation site. .NET Core Documentation - Home of the technical documentation for .NET Core, C#, F# and Visual