Skip to content

Commit

Permalink
feat: 新增mogon
Browse files Browse the repository at this point in the history
  • Loading branch information
罗学 committed May 10, 2021
1 parent 0a45955 commit f0c9f5e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
## [1.0.9](https://github.com/luoxue-victor/learn_webpack/compare/v1.5.1...v1.0.9) (2021-05-10)
## [1.0.9](https://github.com/luoxue-victor/learn_webpack/compare/v1.5.2...v1.0.9) (2021-05-10)



## [1.5.2](https://github.com/luoxue-victor/learn_webpack/compare/v1.5.1...v1.5.2) (2021-05-10)


### Features

* 增加 socket ([945861d](https://github.com/luoxue-victor/learn_webpack/commit/945861d51dfd0fbb88b3fa56c08eb289683db743))



Expand Down
3 changes: 2 additions & 1 deletion learn/nice-web.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
- [Redux 入门教程(二):中间件与异步操作](http://www.ruanyifeng.com/blog/2016/09/redux_tutorial_part_two_async_operations.html)
- [Redux 入门教程(三):React-Redux 的用法](http://www.ruanyifeng.com/blog/2016/09/redux_tutorial_part_three_react-redux.html)
- [如何创建一个 Node.js 的命令行应用(英文)](https://blog.logrocket.com/online-radio-server-pure-node-js/)
- [关于socket.io的使用](https://www.cnblogs.com/edwardloveyou/p/10625152.html)
- [关于socket.io的使用](https://www.cnblogs.com/edwardloveyou/p/10625152.html)
- [socket.io](https://socket.io/get-started/chat#Introduction)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
},
"main": "index.js",
"devDependencies": {
"@pkb/cli": "^1.5.1",
"@pkb/cli": "^1.5.2",
"@pkb/plugin-react": "^1.4.50",
"@pkb/plugin-stylelint": "^1.4.50",
"@pkb/rollup-box": "^1.4.54",
"@pkb/node-box": "^1.4.54",
"@pkb/node-box": "^1.5.2",
"@pkb/webpack-box": "^1.4.56"
},
"bugs": {
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/commands/ui.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
const { join } = require('path')
// const { createServer } = require('@pkb/node-box/socket')


exports.registerCommand = (params) => {
const { program } = params
program
.command('ui')
.description('cli ui,界面话')
.action(async (plugin, options = {}) => {
// await socket()
await socket()
await server()
})
}

async function socket () {
const { createServer } = require('@pkb/node-box/socket')

const socket = await createServer(8000)

socket.on('server run', (url) => {
console.log('server run', url)
})
}

const client = () => {
Expand Down
18 changes: 18 additions & 0 deletions packages/node-box/mogon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');

// Connection URL
const url = 'mongodb://localhost:27017';

// Database Name
const dbName = 'myproject';
const client = new MongoClient(url);
// Use connect method to connect to the server
client.connect(function(err) {
assert.equal(null, err);
console.log('Connected successfully to server');

const db = client.db(dbName);

client.close();
});
1 change: 1 addition & 0 deletions packages/node-box/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"koa-router": "^10.0.0",
"koa-views": "^7.0.1",
"koa2-cors": "^2.0.6",
"mongodb": "^3.6.6",
"nodemon": "^2.0.7",
"semver": "^6.3.0",
"socket.io": "^4.0.2",
Expand Down
5 changes: 4 additions & 1 deletion packages/node-box/socket/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const fs = require('fs')
const path = require('path')
const configPath = path.join(__dirname, '__cfg__.json')
const os = require('os')
const chalk = require('chalk')
const configPath = path.join(os.homedir(), '__cfg__.json')

console.log(os.homedir())
exports.createServer = async (port = 7000) => {
const _port = await usePort(port)

Expand Down

0 comments on commit f0c9f5e

Please sign in to comment.