Skip to content

Commit

Permalink
feat: 支持登录友互通
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchch6 committed Jun 5, 2020
1 parent be00ae8 commit 1b83f9c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
7 changes: 7 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ const libra = () => {
cli.set('yonui-cli')
})

program
.command('login')
.description('Log in to YonBuilder')
.action(() => {
cli.login()
})

program
.command('publish')
.description('publish')
Expand Down
4 changes: 3 additions & 1 deletion src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ const start = require('./start')
const create = require('./create')
const compress = require('./compress')
const publish = require('./publish')
const login = require('./login')
module.exports = {
init,
build,
start,
create,
set,
publish,
compress
compress,
login
}
66 changes: 66 additions & 0 deletions src/cli/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const fetch = require('node-fetch')
const FormData = require('form-data')
const inquirer = require('inquirer')
const chalk = require('chalk')
const { LOGIN_URL } = require('../utils/globalConfig')

const login = async () => {
// 输入友互通账号密码
const ans = await inquirer.prompt([
{
type: 'input',
name: 'username',
message: 'username:',
validate: function (val) {
if (checkPhone(val) || checkEmail(val)) { // 校验位数
return true
}
return 'Please input the correct mobile number or email'
}
},
{
type: 'password',
name: 'password',
message: 'password:'
}
])
await setUserInfo(ans)
}

function checkPhone (str) {
const reg = /^1[3456789]\d{9}$/
if (reg.test(str)) {
return true
} else {
return false
}
}

function checkEmail (str) {
const reg = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/
if (reg.test(str)) {
return true
} else {
return false
}
}

const setUserInfo = async (ans) => {
const form = new FormData()
form.append('username', ans.username)
form.append('password', ans.password)
fetch(LOGIN_URL, {
method: 'post',
body: form
})
.then(async function (response) {
const res = await response.json()
if (res.status === 200) {
console.log(chalk.green(`${res.data}`))
}
}).catch(function (error) {
console.error(error.message)
})
}

module.exports = login
4 changes: 3 additions & 1 deletion src/utils/globalConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const CONFIG_FILE_NAME = 'yonui-cli'
const YNPM_PUBLISH_URL = 'http://libraui-backend.test.app.yyuap.com/package/cliPublish'
const LOGIN_URL = 'http://libraui-backend.test.app.yyuap.com/package/cliLogin'

module.exports = {
CONFIG_FILE_NAME,
YNPM_PUBLISH_URL
YNPM_PUBLISH_URL,
LOGIN_URL
}
1 change: 0 additions & 1 deletion templates/Project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
},
"author": "",
"license": "ISC",
"syncToMDD": true,
"husky": {
"hooks": {
"pre-commit": "npm run lint:git",
Expand Down

0 comments on commit 1b83f9c

Please sign in to comment.