From 02163292802a623aa807f15ed5d87114357764d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=A1=E6=B3=A1=E6=9C=BA=E4=B8=8D=E5=86=92=E6=B3=A1?= =?UTF-8?q?=E4=BA=86?= Date: Mon, 1 Mar 2021 11:53:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?npm=E6=89=93=E5=8C=85=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .npmignore | 4 +--- README.md | 36 +++++++++++++++++----------------- backend/README.md | 29 ++++++++++++++++++++++++++++ backend/cli.js | 32 ++++++++++++++++++++++++++++++ backend/package.json | 22 ++++++++++++++++----- cli.js | 45 ------------------------------------------- frontend/.npmignore | 1 + frontend/README.md | 29 ++++++++++++++++++++++++++++ frontend/cli.js | 26 +++++++++++++++++++++++++ frontend/package.json | 25 ++++++++++++++++++------ 10 files changed, 172 insertions(+), 77 deletions(-) create mode 100644 backend/README.md create mode 100644 backend/cli.js delete mode 100644 cli.js create mode 100644 frontend/.npmignore create mode 100644 frontend/README.md create mode 100644 frontend/cli.js diff --git a/.npmignore b/.npmignore index 0ac92e1..72e8ffc 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1 @@ -.idea -.DS_Store -node_modules +* diff --git a/README.md b/README.md index fc0942f..419c5f4 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ ArtiPub 目前支持文章编辑、文章发布、数据统计的功能,后期 - MongoDB: 3.6+ - NodeJS: 10+ +- NPM: > 5+ , < 7+ ## 安装方式 @@ -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` 可以看到界面。 ### 通过源码安装 @@ -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 ``` **配置数据库** diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 0000000..e7953d3 --- /dev/null +++ b/backend/README.md @@ -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 +``` diff --git a/backend/cli.js b/backend/cli.js new file mode 100644 index 0000000..6e61093 --- /dev/null +++ b/backend/cli.js @@ -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 ', 'mongodb host name', '127.0.0.1') + .option('-p, --port ', 'port number', 27017) + .option('-d, --dbname ', 'database name', 'artipub') + .option('-u, --username ', 'mongodb username', '') + .option('-P, --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) diff --git a/backend/package.json b/backend/package.json index 53c19f7..6f100a0 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,25 +1,37 @@ { - "name": "backend", - "version": "1.0.0", + "name": "artipub-backend", + "version": "0.1.6-alpha.1", "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": "tanliyuan_n@163.com", + "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" diff --git a/cli.js b/cli.js deleted file mode 100644 index b3c0ecf..0000000 --- a/cli.js +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env node -const os = require('os') -const exec = require('child_process').exec -const path = require('path') -const program = require('caporal') - -program - .command('start', 'Start ArtiPub server') - .option('-H, --host', 'MongoDB host name', null) - .option('-P, --port', 'MongoDB port number', null, '27017') - .option('-d, --db', 'MongoDB database name', null, 'artipub') - .option('-u, --username', 'MongoDB username', null, '') - .option('-p, --password', 'MongoDB password', null, '') - .action((...arr) => { - const cmdObj = arr[arr.length - 2] - - const umiCmd = path.join( - __dirname, - 'node_modules', - '.bin', - os.platform() - .match(/^win/) ? 'umi.cmd' : 'umi' - ) + ' dev' - - // 开启前端服务 - console.log(umiCmd) - exec(umiCmd, { shell: true }) - - const host = cmdObj.host || 'localhost' - const port = cmdObj.port || '27017' - const db = cmdObj.db || 'artipub' - const username = cmdObj.username || '' - const password = cmdObj.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('./backend/server') - }) - -program.parse(process.argv) diff --git a/frontend/.npmignore b/frontend/.npmignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/frontend/.npmignore @@ -0,0 +1 @@ +* diff --git a/frontend/README.md b/frontend/README.md new file mode 100644 index 0000000..1bf0286 --- /dev/null +++ b/frontend/README.md @@ -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 +``` diff --git a/frontend/cli.js b/frontend/cli.js new file mode 100644 index 0000000..c35a35a --- /dev/null +++ b/frontend/cli.js @@ -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 name', '127.0.0.1') + .option('-p, --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) diff --git a/frontend/package.json b/frontend/package.json index 0499880..0656fa9 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,16 +1,16 @@ { - "name": "artipub", - "version": "0.1.4", + "name": "artipub-frontend", + "version": "0.1.6-alpha.4", "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", @@ -25,7 +25,18 @@ "post", "puppeteer" ], + "files": [ + "dist/", + "cli.js" + ], "author": "Marvin Zhang", + "contributors": [ + { + "name": "tanliyuan", + "email": "tanliyuan_n@163.com", + "url": "https://juejin.cn/user/3843548383021127/posts" + } + ], "license": "BSD-3-Clause", "bugs": { "url": "https://github.com/crawlab-team/artipub/issues" @@ -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", From c165dc2a09052b385a24abbc2ed3a1a516f63c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=A1=E6=B3=A1=E6=9C=BA=E4=B8=8D=E5=86=92=E6=B3=A1?= =?UTF-8?q?=E4=BA=86?= Date: Mon, 1 Mar 2021 11:56:32 +0800 Subject: [PATCH 2/2] beta --- backend/package.json | 2 +- frontend/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/package.json b/backend/package.json index 6f100a0..4c2f8d8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "artipub-backend", - "version": "0.1.6-alpha.1", + "version": "0.1.6", "description": "", "main": "server.js", "scripts": { diff --git a/frontend/package.json b/frontend/package.json index 0656fa9..35948bd 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "artipub-frontend", - "version": "0.1.6-alpha.4", + "version": "0.1.6", "description": "Article publishing platform that automatically distributes your articles to various media channels", "scripts": { "prod": "http-server ./dist",