angular搭建项目步骤

by Ashish Gaikwad

通过Ashish Gaikwad

建立健康的Angular项目应采取的步骤 (Steps you should take to build a healthy Angular project)

使用Jenkins + SonarQube创建您的“ Angular Fitbit” (Create your “Angular Fitbit” with Jenkins + SonarQube)

Just like the recent introduction of wearables to track our health, the software industry has long followed the practice of monitoring the health of software projects. The most common processes applied are unit tests, integration tests, continuous integration, and code coverage.

就像最近引入可穿戴设备来跟踪我们的健康状况一样,软件行业也长期遵循监视软件项目健康状况的做法。 应用最常见的过程是单元测试,集成测试,连续集成和代码覆盖率。

I recently struggled a bit in trying to setup the above mentioned processes for our project, so I wrote this post to document my experience. Since TypeScript is the default language for Angular 2 projects, existing JS setups do not work.

我最近在尝试为我们的项目设置上述流程时遇到了一些困难,因此我写了这篇文章来记录我的经验。 由于TypeScript是Angular 2项目的默认语言,因此现有的JS设置不起作用。

入门 (Getting started)

Here are the steps to setup a Jenkins CI environment for Angular projects with code coverage using SonarQube on a headless Linux server:

以下是在无头Linux服务器上使用SonarQube为覆盖代码的Angular项目设置Jenkins CI环境的步骤:

  • Download Jenkins and set it up on your build server. Make sure you have Java installed on it, as it is required by Jenkins. Note: Jenkins’ default configuration runs with jenkins user, so you might need to set JAVA_HOME for the jenkins user.

    下载Jenkins并将其设置在您的构建服务器上。 确保您已安装Jenkins要求的Java。 注意 :Jenkins的默认配置与jenkins用户一起运行,因此您可能需要为jenkins用户设置JAVA_HOME

  • Once Jenkins is setup, install or make sure you have the following plugins installed from the manage plugins menu:设置Jenkins后,请从“管理插件”菜单安装或确保已安装以下插件:
  • Make Git, Node, and SonarQube scanner available to Jenkins. This can be done from the Global Tool Configuration menu in the Manage Jenkins menu. You can either chose to install automatically or provide the installation path for these tools. For example:

    使Jenkins可以使用Git,Node和SonarQube扫描仪。 这可以从Manage Jenkins菜单中的Global Tool Configuration菜单中完成。 您可以选择自动安装,也可以提供这些工具的安装路径。 例如:

  • Lastly, make Jenkins aware of the SonarQube server installation from the Configure menu in Manage Jenkins. For example:

    最后,从Manage Jenkins中Configure菜单使Jenkins知道SonarQube服务器的安装。 例如:

Download SonarQube and set it up on your server. It is usually a simple package extraction on all platforms.

下载SonarQube并在您的服务器上进行设置。 通常,它是在所有平台上的简单软件包提取。

To enable Typescript support in SonarQube, we will use the SonarTsPlugin since SonarQube doesn’t yet have a default plugin for Typescript. Simply download the jar from the releases page of the plugin and place it in your SonarQube installations bin folder. Restart Jenkins once. That is all.

为了在SonarQube中启用Typescript支持,我们将使用SonarTsPlugin,因为SonarQube还没有Typescript的默认插件。 只需从插件的发行页面下载jar,然后将其放在SonarQube安装bin文件夹中。 重新启动詹金斯一次。 就这些。

In the Angular projects karma.conf.js file, change/add to the browsers section ChromeHeadless.

在Angular项目的karma.conf.js文件中,更改/添加到browsers部分ChromeHeadless

Example: browsers:['ChromeHeadless'] . From version 60 onwards Google Chrome supports headless mode on Windows as well. So you can continue to use this setting on local machine as well, in case you work on a Windows machine in an enterprise environment (as I do). I personally prefer the headless mode only for the 1–2 seconds that it saves me.

示例: browsers:['ChromeHeadless'] 。 从版本60开始, Google Chrome也支持 Windows的无头模式。 因此,如果您在企业环境中的Windows计算机上工作(就像我一样),那么您也可以继续在本地计算机上使用此设置。 我个人更喜欢无头模式,这种模式只为我节省了1-2秒。

Add the following to the scripts section in package.json file.

将以下内容添加到package.json文件中的scripts部分。

The above command makes sure that the build is only triggered if all the tests are successful. The --cc flag is a short code for --code-coverage. This flag will produce the projects coverage report in a new folder named coverage within the project directory. The report file is named lcov.info.

上面的命令确保仅在所有测试成功后才触发构建。 --cc标志是--code-coverage的简短代码。 该标志将在项目目录中名为coverage的新文件夹中生成项目coverage报告。 该报告文件名为lcov.info

The default configuration uses Istanbul reporter to show the code coverage report. To publish this coverage report to SonarQube server, the Jenkins SonarQube scanner plugin requires a configuration which can be added as a sonar-project.properties file to the project or within the Jenkins project configuration. Example properties file:

默认配置使用Istanbul报告程序显示代码覆盖率报告。 要将覆盖报告发布到SonarQube服务器,Jenkins SonarQube扫描器插件需要一个配置,该配置可以作为sonar-project.properties文件添加到项目中或在Jenkins项目配置中。 示例属性文件:

组态 (Configuration)

With the above steps done, the project configuration in Jenkins is fairly simple.

完成上述步骤后,Jenkins中的项目配置非常简单。

First create a new configuration using New Item menu and then a Freestyle project.

首先使用New Item菜单创建一个新配置,然后使用Freestyle项目

Next in the Source Code Management section enable Git and setup the projects repo URL:

接下来,在“ 源代码管理”部分中启用Git并设置项目存储库URL:

In the Build Environment section, enable the checkbox for providing the node and npm environment to the build configuration.

在“ 构建环境”部分中,启用复选框以将节点和npm环境提供给构建配置。

Then in the Build sectionn add two build steps. First Execute Shell and second Execute SonarQube Scanner.

然后在“ 构建”部分中添加两个构建步骤。 第一个执行Shell和第二个执行SonarQube Scanner

The shell step is to run the cibuild npm script and the latter to trigger the coverage report analysis. As mentioned above, the sonar properties can be set in the build configuration as well. Example build configuration:

Shell步骤是运行cibuild npm脚本,然后运行cibuild npm脚本来触发coverage报告分析。 如上所述,声纳属性也可以在构建配置中设置。 示例构建配置:

That is all. Now a build can be triggered using the Build Now menu on the projects home page.

就这些。 现在,可以使用项目主页上的“ 立即构建”菜单来触发构建

The build log will show the test results, the build logs, and the publish log to SonarQube server. It is ideal to setup remote triggers or web hooks to trigger the project build. This will ensure the stability of the project whenever there is a change in the repo.

构建日志将显示测试结果,构建日志以及将日志发布到SonarQube服务器。 设置远程触发器或Web挂钩以触发项目构建的理想选择。 每当回购发生变化时,这将确保项目的稳定性。

Finally, on visiting the SonarQube server, the project details should be visible with all the metrics captured from code coverage report. Example:

最后,在访问SonarQube服务器时,应该使用从代码覆盖率报告中捕获的所有指标显示项目详细信息。 例:

This is only the first step towards creating a healthier code base. The Jenkins build can be further enhanced to create a pipeline build for better control and granular modifications.

这只是创建更健康的代码库的第一步。 可以进一步增强Jenkins构建,以创建管道构建,以实现更好的控制和精细的修改。

Originally published at medium.com on September 16, 2017.

最初于2017年9月16日发布在medium.com上。

翻译自: https://www.freecodecamp.org/news/steps-you-should-take-to-build-a-healthy-angular-project-84eea6608d5f/

angular搭建项目步骤

angular搭建项目步骤_建立健康的Angular项目应采取的步骤相关推荐

  1. Identity Server 4 原理和实战(完结)_建立Identity Server 4项目,Client Credentials 授权实例...

    创建项目 dotnet new -i IdentityServer4.Templates 多出来的这些模板 adminUI用来测试,想要用再生产环境,需要交钱 结合core的 Identity来使用 ...

  2. 如何从0开始开源项目参与_如何开始一个开源项目

    如何从0开始开源项目参与 by Dmitriy Strukov 德米特里·斯特鲁科夫(Dmitriy Strukov) 如何开始一个开源项目 (How to start an Open Source ...

  3. java后端简历项目经历_从面试官甄别项目经验的角度,说说如何在简历中写项目经验(Java后端方向)...

    在大多的JD(职位介绍)里,会写明该职位需要xx时间的相关经验,换句话说就是需要在简历中看到一定年限的相关商业项目经验,否则估计连面试的机会都没. 在本文里,不讨论这种门槛是否合理,而会以Java相关 ...

  4. react项目开发步骤_成为专业React开发人员的31个步骤

    react项目开发步骤 我为达到可雇用水平而进行的每个项目和课程. (Every single project and course I took to reach a hireable level. ...

  5. 时间序列预测步骤_建立时间序列预测模型的5个简单步骤

    时间序列预测步骤 I am a strong believer in "learning by doing" philosophy. 我坚信"做中学"的哲学. ...

  6. python电商项目介绍_电商大数据项目-推荐系统实战(一)

    本项目是基于Spark MLLib的大数据电商推荐系统项目,使用了scala语言和java语言.基于python语言的推荐系统项目会另外写一篇博客.在阅读本博客以前,需要有以下基础: 1.linux的 ...

  7. 创建微服务架构的步骤_成功备战微服务的5个准备步骤

    本文为大家介绍了5个迁移到微服务架构所需做的准备步骤,包括如何划分微服务,微服务和组织结构间的误解,如何划分组织架构,以及在实现微服务架构中需要尽早考虑的一些问题,值得大家参考. 时至今日,微服务相关 ...

  8. python枪战项目计划书_人肉(共享)代购项目计划书(示例代码)

    人肉(共享)代购项目计划书 寻志同道合人士,共谋发展, 微信号: hummels_whu 项目背景: 1.国人出国旅游.出差的几率大大增加,有较大潜在人数可以作为代购货运服务的提供方.类似于私家车车主 ...

  9. 子项目依赖和父项目冲突_实战 | maven 轻松重构项目

    现在是微服务盛行时代,说不准哪一天领导就会让你对一个大项目进行重构.大项目的痛点:编译慢.发布繁琐等.就像下面这张图: 真的不敢动呀,一不小心就坍塌了. 比如说我们用户系统,我们可以这么重构(这里只是 ...

最新文章

  1. 搞懂Transformer结构,看这篇PyTorch实现就够了
  2. 【原创】parseInt大改造
  3. UOJ #277 BZOJ 4739 [清华集训2016]定向越野 (计算几何、最短路)
  4. 瑞数(裁判文书)js的加密分析
  5. java 线程 内存分配内存_漫谈JAVA语言的内存分配
  6. mysql8.0版本的服务器名称_Linux服务器配置-VSFTP服务配置(六)
  7. 【Java】Java对象引用四个级别(强、软、弱、虚)
  8. 那年学过的Java笔记三核心类库二
  9. 请详细描述listview与gridview的异同点_一建考试中,实在不会的怎么办?教你从题目中获取得分点!...
  10. kafka事务操作案例演示
  11. 记事本如何运行python代码_记事本写代码怎么运行
  12. 解决 appcompat 1.1.0 导致 webview crash 的问题
  13. java 替换html代码_Java中替换HTML标签的方法代码
  14. 一阶惯性环节的性能分析——自动控制原理基础补充(二)
  15. 计量经济学实验报告计算机,计量经济学实验报告记录.doc
  16. 多线程m3u8下载器 v1.0
  17. MATLAB读取图像相关的一些操作
  18. linux 多核 双系统,Linux GRUB实现双系统引导教程
  19. docker使用阿里云的镜像加速器的地址
  20. 购买计算机设备计入什么科目,企业购买设备计入什么会计科目?附会计分录

热门文章

  1. 18-flutter的Future和FutureBuilder
  2. 20、C#里面方法的创建和显示
  3. es5 编写类风格的代码
  4. 10分钟学会php面相对象基础(Ⅰ)
  5. 导入导出Android手机文件
  6. SDT(software-defined Things)?软件定义的物件
  7. 基于Bootstrap里面的Button dropdown打造自定义select
  8. 关于2012年度土建工程专业中级专业技术资格考试有关问题的通知
  9. oracle 求A中不存在于B的记录
  10. 让电脑通过gns3里的路由器上网