Skip to content

Commit

Permalink
Merge pull request #140 from tanliyuan/feature/package_npm
Browse files Browse the repository at this point in the history
Feature/package npm
  • Loading branch information
tanliyuan authored Mar 1, 2021
2 parents c48d9fe + c165dc2 commit b63493c
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 77 deletions.
4 changes: 1 addition & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
.idea
.DS_Store
node_modules
*
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ArtiPub 目前支持文章编辑、文章发布、数据统计的功能,后期

- MongoDB: 3.6+
- NodeJS: 10+
- NPM: > 5+ , < 7+

## 安装方式

Expand Down Expand Up @@ -128,30 +129,23 @@ docker-compose up

如果您对 npm 熟悉,且已经有 MongoDB 的环境,这是最为快捷的方式。

**安装 npm 包**
从0.1.6版本开始前后端分开打包.

```bash
npm install -g artipub
```
**安装 artipub-front 前端包**

安装 npm 包时,为了加速下载速度,可以加入 `--registry` 参数来设置镜像源(后面源码安装时也可以这样操作)
[artipub-front](frontend/README.md)

```bash
npm install -g artipub --registry=https://registry.npm.taobao.org
```
**安装 artipub-backend 后端包**

**运行 ArtiPub**
[artipub-backend](backend/README.md)

```bash
artipub start
```

该命令默认会使用 `localhost:27017/artipub` 为 MongoDB 数据库链接。输入如下命令可以看更多配置,例如配置数据库等。
安装 npm 包时,为了加速下载速度,可以加入 `--registry` 参数来设置镜像源(后面源码安装时也可以这样操作)

```bash
artipub -h
npm install -g artipub-frontend --registry=https://registry.npm.taobao.org
```


成功运行后,在浏览器中输入 `http://localhost:8000` 可以看到界面。

### 通过源码安装
Expand All @@ -165,20 +159,26 @@ git clone https://github.com/crawlab-team/artipub
**安装 npm 包**

```bash
cd artipub
cd artipub/frontend
npm install
cd artipub/backend
npm install
```

**启动前端**

```bash
npm run start:frontend
//frontend 目录下
npm run build
npm run dev
```

**启动后端**

```bash
npm run start:backend
//backend 目录下
npm run start
```

**配置数据库**
Expand Down
29 changes: 29 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## ArtiPub 后端模块
从 0.1.6 开始前后端分开打包, 对应前端包 [artipub-frontend](https://www.npmjs.com/package/artipub-frontend)

## 启动命令

```bash
//全局安装
npm i -g artipub-backend

//默认启动 http://localhost:3000, 确保本地 mongodb 已经启动在 27017 端口
artipub-be start

//查看其他配置参数
artipub-be --help
```

```bash
//非全局安装
npm i artipub-backend

//安装目录下执行, 确保npm 5+, 有npx命令
npx artipub-be start

//或者
./node_modules/.bin/artipub-be start

//查看其他配置参数
npx artipub-be --help
```
32 changes: 32 additions & 0 deletions backend/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node
const { version }= require('./package.json');
const program = require('commander')

program
.version(version)
.command('start')
.description('Start ArtiPub backend server')
.option('-H, --host <host>', 'mongodb host name', '127.0.0.1')
.option('-p, --port <port>', 'port number', 27017)
.option('-d, --dbname <dbname>', 'database name', 'artipub')
.option('-u, --username <username>', 'mongodb username', '')
.option('-P, --password <password>', 'mongodb password', '')
.action((options) => {

const host = options.host || 'localhost'
const port = options.port || '27017'
const db = options.dbname || 'artipub'
const username = options.username || ''
const password = options.password || ''

process.env.MONGO_HOST = host
process.env.MONGO_PORT = port
process.env.MONGO_DB = db
process.env.MONGO_USERNAME = username
process.env.MONGO_PASSWORD = password

// 开启后段服务
require('./server')
})

program.parse(process.argv)
22 changes: 17 additions & 5 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
{
"name": "backend",
"version": "1.0.0",
"name": "artipub-backend",
"version": "0.1.6",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js"
"start": "node server.js",
"prerelease": "npm version prerelease --preid=alpha"
},
"author": "Marvin Zhang",
"contributors": [
{
"name": "tanliyuan",
"email": "[email protected]",
"url": "https://juejin.cn/user/3843548383021127/posts"
}
],
"bin": {
"artipub-be": "cli.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"async-lock": "^1.2.2",
"axios": "^0.20.0",
"body-parser": "^1.19.0",
"cheerio": "^1.0.0-rc.3",
"clipboardy": "^2.1.0",
"commander": "^7.1.0",
"cron": "^1.7.1",
"express": "^4.17.1",
"log4js": "^5.1.0",
"mongoose": "^5.6.12",
"morgan": "^1.9.1",
"puppeteer-chromium-resolver": "^5.2.0",
"cheerio": "^1.0.0-rc.3",
"request": "^2.88.0",
"request-promise-native": "^1.0.7",
"showdown": "^1.9.0"
Expand Down
45 changes: 0 additions & 45 deletions cli.js

This file was deleted.

1 change: 1 addition & 0 deletions frontend/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
29 changes: 29 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## ArtiPub 前端模块
从 0.1.6 开始前后端分开打包, 对应后端包 [artipub-backend](https://www.npmjs.com/package/artipub-backend)

## 启动命令

```bash
//全局安装
npm i -g artipub-frontend

//默认启动 http://localhost:8000
artipub-fe start

//查看其他配置参数
artipub-fe --help
```

```bash
//非全局安装
npm i artipub-frontend

//安装目录下执行, 确保npm 5+, 有npx命令
npx artipub-fe start

//或者
./node_modules/.bin/artipub-fe start

//查看其他配置参数
npx artipub-fe --help
```
26 changes: 26 additions & 0 deletions frontend/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node
const { version }= require('./package.json');
const path = require('path');
const exec = require('child_process').exec
const program = require('commander')

const distDir = path.join(
__dirname, './dist'
);

program
.version(version)
.command('start')
.description('Start ArtiPub frontend server')
.option('-h, --host <host>', 'host name', '127.0.0.1')
.option('-p, --port <port>', 'port number', 8000)
.action((options) => {
const setUpCmd = `npx http-server ${distDir} -a ${options.host} -p ${options.port}`;

// 开启前端服务
console.log(`启动命令:${setUpCmd}`)
console.log(`访问:http://127.0.0.1:${options.port} `)
exec(setUpCmd, { shell: true })
})

program.parse(process.argv)
25 changes: 19 additions & 6 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "artipub",
"version": "0.1.4",
"name": "artipub-frontend",
"version": "0.1.6",
"description": "Article publishing platform that automatically distributes your articles to various media channels",
"main": "index.js",
"scripts": {
"start": "node cli.js start",
"start:frontend": "umi dev",
"prod": "http-server ./dist",
"dev": "umi dev",
"build": "umi build",
"prerelease": "npm version prerelease --preid=alpha",
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"artipub": "./cli.js"
"artipub-fe": "cli.js"
},
"repository": {
"type": "git",
Expand All @@ -25,7 +25,18 @@
"post",
"puppeteer"
],
"files": [
"dist/",
"cli.js"
],
"author": "Marvin Zhang",
"contributors": [
{
"name": "tanliyuan",
"email": "[email protected]",
"url": "https://juejin.cn/user/3843548383021127/posts"
}
],
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/crawlab-team/artipub/issues"
Expand All @@ -39,7 +50,9 @@
"antd": "^3.20.0",
"classnames": "^2.2.6",
"codemirror": "^5.48.2",
"commander": "^7.1.0",
"dva": "^2.4.1",
"http-server": "^0.12.3",
"lodash": "^4.17.11",
"markdown-it": "^10.0.0",
"moment": "^2.24.0",
Expand Down

0 comments on commit b63493c

Please sign in to comment.