npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

moria-cli

v2.1.13

Published

moria-cli 通过脚本生成spring cloud 项目脚手架

Downloads

22

Readme

moria-cli 2.0

moria-cli 2.0 创建基于spring cloud的脚手架

moria-cli的目标

  • 快速创建moria微服务
  • 构建微服务的docker镜像
  • 将微服务镜像推送到harbor

准备条件

  • npm >= v7.7.0
  • docker >= v1.13, 已经启动
  • maven , 如果已经安装docker,则可以不安装maven
  • 联网

安装moria-cli

npm i -g moria-cli

目前支持的命令为

  • config
  • create
  • package
  • build
  • deploy
  • update

使用方法

使用帮助

moria-cli help

查看某个命令的帮助

moria-cli <command> -h

创建moria微服务

moria-cli create -g <my.groupid> -a <my-artifactId>

这会在当前文件夹下生成一个 的moria微服务工程。 用户可以在此基础上进行业务开发。

如果 -g 或 -a 没有提供,会进入交互模式,输入groupId 和 artifactId。 artifactId 会做为项目名称,贯穿整个moria操作。

项目打包(在微服务工程根目录调用)

moria-cli package

如果打包成功,会在项目根目录生成 target目录。

该命令可选执行,通常用于验证代码的正确性。失败表示代码存在问题

项目配置(在微服务工程根目录调用)

moria-cli config

交互式输入配置,包含docker仓库,登录设置,通知url。

如果不进行配置,会使用默认选项 config后会生成文件保存与 $HOME/.moria.json

构建微服务镜像(在微服务工程根目录调用)

moria-cli build

构建当前工程,并生成一个docker镜像。

  1. 使用 <user/groupId:version> 做为 imageTag。
  2. 项目本身必须能够通过mvn构建成功,否则会导致构建失败。
  3. 建议执行此步之前执行 moria-cli package

部署微服务

moria-cli deploy

将当前工程推送到docker仓库,并通知云端。通知的接口数据包含。现在上送后台的接口为

environment:  '${docker_ns}',
name:         '${项目名}',
imageRepo:    '${镜像名}',
tag:          ['微服务'],
jarFile:      '${jar在镜像中的路径}',
description:  'user=${docker登录用户}, app=${项目名}',
  • 镜像repo
  • 镜像tag
  • jar包所在的位置

get started

  • 首先 moria-cli create -g com.myapp -a helloworld,创建微服务 hellowrold。
  • 使用ide(如eclipse / idea等)打开项目进行开发。
  • 开发完毕 moria-cli package,打包验证项目是否OK。
  • 使用 moria-deploy push这个镜像,并通知后台

平台支持

platform | 支持情况 ------------|------------- centos7.2 | 通过 ubuntu16.04 | 通过 macos | 通过 (无法自动配置docker, 需手动配置) win10 Pro | 未测试 build / deploy

扩展

项目结构

/
.
├── bin
│   └── moria-cli
├── index.js
├── lib
│   ├── build.js
│   ├── common
│   │   ├── MoriaCore.js
│   │   ├── moriaError.js
│   │   └── specification.js
│   ├── config
│   │   ├── configUtil.js
│   │   └── defaultConf.js
│   ├── config.js
│   ├── create.js
│   ├── deploy.js
│   ├── help.js
│   ├── package.js
│   └── utils
│       ├── checkRequisite.js
│       ├── executor.js
│       ├── getUserInput.js
│       ├── logger.js
│       ├── parsePom.js
│       └── trimCmdSpace.js
├── package.json
├── README.md
└── src
    └── moria-cli.png
  • 程序的入口在 bin/moria-cli
const ALL_COMMAND = [
  'help',
  'config',
  'create',
  'package',
  'build',
  'deploy',
  'update'
];
  • 命令的实现在 lib/ 中 注意每个在 moria-cli中的命令,都需要一个 lib/ 下的单独文件匹配。 如lib/create.js 对应了 命令 create 的实现。但是实际上核心实现在 lib/common/MoriaCore.js

  • lib/common 文件夹下放置了核心实现和规范,以及错误定义

MoriaCore.js     ---- moria-cli 生命周期中的 元操作
moriaError.js    ---- 自定义错误
specification.js ---- 规范配置文件位置,镜像名称,镜像信息的地方
  • utils 放置了一些工具类 工具类的特点就是 不会require utils包外自己写的代码,无状态

#moria-spring-cloud moria-spring-cloud是moria平台构架脚手架的骨架工程(archetpye)

  • 创建镜像 docker build -t foreveross/maven .

  • 提交到harbor

  • 生成脚手架(moria-cli create命令可创建,解释)

docker run -i                                                 \
    -w /home                                                  \
    -v /Users/Aaron:/home                                     \
    -v /Users/Aaron/.m2:/root/.m2                             \
    --rm                                                      \
    foreveross/maven                                          \
    mvn archetype:generate                                    \
    -DarchetypeVersion=1.0.0-RELEASE                          \
    -DarchetypeGroupId=moria.io                               \
    -DarchetypeArtifactId=moria-spring-cloud-archetype        \
    -DarchetypeCatalog=local                                  \
    -DgroupId=foreveross.com                                  \
    -Dversion=0.01                                            \
    -DartifactId=my-app                                       \
    -DinteractiveMode=false   

命令说明: -DarchetypeGroupId=com.xxx 脚手架的groupId -DarchetypeArtifactId=archetype-spring-boot 脚手架的artifactId -DarchetypeVersion=1.0.0 脚手架版本 -DgroupId=com.xxx 需要生成的项目groupId -DartifactId=demo-archetype-generate 需要生成的项目artifactId -Dversion=1.0.0 需要生成的版本号 -DarchetypeCatalog=internal 使用私有仓库脚手架jar包, 前提:已经把脚手架发布到私有仓库中 -DarchetypeCatalog=local 使用本地脚手架jar包, 如果不配置, 它会到中央仓库去下载, 会导致失败 -X debug模式 -DinteractiveMode=false 是否在生成的时候再次确认

使用方式: 使用本地仓库需要 install一次, 再到需要生成项目的目录下去执行命令。 使用私有仓库脚手架,不需要clone项目,只需要配置好maven,settting.xml,并执行以上命令即可