tt-minigame-ide-cli 0.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yarnrc +1 -0
- package/LICENSE +21 -0
- package/README.en.md +119 -0
- package/README.md +120 -0
- package/bin/tmg.js +199 -0
- package/lib/auth.js +145 -0
- package/lib/build-npm.js +22 -0
- package/lib/create.js +106 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +79 -0
- package/lib/preview.js +86 -0
- package/lib/upload.js +120 -0
- package/lib/util/check.js +84 -0
- package/lib/util/config.js +41 -0
- package/lib/util/cookie.js +36 -0
- package/lib/util/helper.js +242 -0
- package/lib/util/logger.js +54 -0
- package/lib/util/qrcode.js +19 -0
- package/lib/util/request.js +360 -0
- package/lib/util/version.js +27 -0
- package/package.json +35 -0
- package/template/app.js +5 -0
- package/template/app.json +11 -0
- package/template/app.ttss +0 -0
- package/template/pages/index/index.js +10 -0
- package/template/pages/index/index.ttml +1 -0
- package/template/pages/index/index.ttss +4 -0
package/.yarnrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
registry "https://registry.npmjs.org"
|
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Bytedance Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# tmg-cli
|
2
|
+
|
3
|
+
> `tmg` cli is the official tool for bytedance microapp development.
|
4
|
+
|
5
|
+
[中文](./README.md)
|
6
|
+
|
7
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
8
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
9
|
+
|
10
|
+
- [Installation](#installation)
|
11
|
+
- [Usage](#usage)
|
12
|
+
- [Create Project](#create-project)
|
13
|
+
- [Open existing project](#open-existing-project)
|
14
|
+
- [Login](#login)
|
15
|
+
- [Login by email](#login-by-email)
|
16
|
+
- [Preview project](#preview-project)
|
17
|
+
- [Upload project](#upload-project)
|
18
|
+
|
19
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
It's recommended to install `tmg` globally.
|
24
|
+
|
25
|
+
```
|
26
|
+
npm install -g tt-ide-cli
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Create Project
|
32
|
+
|
33
|
+
Create a new blank miniprogram project with given name in current folder.
|
34
|
+
|
35
|
+
```
|
36
|
+
Usage: tmg create <project-name>
|
37
|
+
|
38
|
+
Create a new project with given name in current folder
|
39
|
+
|
40
|
+
Options:
|
41
|
+
|
42
|
+
-f, --force Overwrite target directory if it exists
|
43
|
+
-h, --help Output usage information
|
44
|
+
```
|
45
|
+
|
46
|
+
### Open existing project
|
47
|
+
|
48
|
+
Open existing project with given path in microapp IDE.
|
49
|
+
|
50
|
+
If the path is not available, start up the IDE only.
|
51
|
+
|
52
|
+
```
|
53
|
+
Usage: tmg open <project-path>
|
54
|
+
|
55
|
+
Open target project by path
|
56
|
+
```
|
57
|
+
|
58
|
+
### Login
|
59
|
+
|
60
|
+
Login to the developer Platform. Proxy is supported.
|
61
|
+
|
62
|
+
```
|
63
|
+
Usage: tmg login [options]
|
64
|
+
|
65
|
+
Login to the developer platform
|
66
|
+
|
67
|
+
Options:
|
68
|
+
-m, --mobile Login by mobile
|
69
|
+
-e, --email Login by email
|
70
|
+
-p, --proxy <proxy> Login with proxy
|
71
|
+
-h, --help output usage information
|
72
|
+
```
|
73
|
+
|
74
|
+
### Login by email
|
75
|
+
|
76
|
+
```
|
77
|
+
Usage: login-e [email] [password]
|
78
|
+
|
79
|
+
Login to the developer platform by E-mail
|
80
|
+
|
81
|
+
Options:
|
82
|
+
-p, --proxy <proxy> Login with proxy
|
83
|
+
-h, --help Output usage information
|
84
|
+
```
|
85
|
+
|
86
|
+
### Preview project
|
87
|
+
|
88
|
+
Upload project to remote and preview the result by scanning the output QR code.
|
89
|
+
|
90
|
+
```
|
91
|
+
Usage: tmg preview [options] [entry]
|
92
|
+
|
93
|
+
preview project by remote
|
94
|
+
|
95
|
+
Options:
|
96
|
+
-f, --force Preview project without local cache(deprecated)
|
97
|
+
--disable-cache Preview project without local cache
|
98
|
+
-s, --small Use small QR Code, but it does not take effect in some environments
|
99
|
+
-c, --copy Copy remote url to clipboard
|
100
|
+
-p, --proxy <proxy> Preview with proxy
|
101
|
+
-h, --help output usage information
|
102
|
+
```
|
103
|
+
|
104
|
+
### Upload project
|
105
|
+
|
106
|
+
Upload project to the developer platform
|
107
|
+
|
108
|
+
```
|
109
|
+
Usage: tmg upload [options] [entry]
|
110
|
+
|
111
|
+
upload project to the developer platform
|
112
|
+
|
113
|
+
Options:
|
114
|
+
-v, --app-version <version> App version (eg: [major].[minor].[patch])
|
115
|
+
-c, --app-changelog <log> Changelog for this version
|
116
|
+
-p, --proxy <proxy> Update request proxy
|
117
|
+
-cp, --copy Copy remote url to clipboard
|
118
|
+
-h, --help output usage information
|
119
|
+
```
|
package/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# tmg-cli
|
2
|
+
|
3
|
+
> `tmg` 是字节跳动小程序官方提供的命令行工具。
|
4
|
+
|
5
|
+
[English](./README.en.md)
|
6
|
+
|
7
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
8
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
9
|
+
|
10
|
+
- [安装](#%E5%AE%89%E8%A3%85)
|
11
|
+
- [使用](#%E4%BD%BF%E7%94%A8)
|
12
|
+
- [创建新项目](#%E5%88%9B%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE)
|
13
|
+
- [打开已有项目](#%E6%89%93%E5%BC%80%E5%B7%B2%E6%9C%89%E9%A1%B9%E7%9B%AE)
|
14
|
+
- [登录](#%E7%99%BB%E5%BD%95)
|
15
|
+
- [通过 email 登录](#%E9%80%9A%E8%BF%87-email-%E7%99%BB%E5%BD%95)
|
16
|
+
- [预览小程序](#%E9%A2%84%E8%A7%88%E5%B0%8F%E7%A8%8B%E5%BA%8F)
|
17
|
+
- [上传项目](#%E4%B8%8A%E4%BC%A0%E9%A1%B9%E7%9B%AE)
|
18
|
+
|
19
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
20
|
+
|
21
|
+
## 安装
|
22
|
+
|
23
|
+
建议在全局安装 `tmg` 。
|
24
|
+
|
25
|
+
```
|
26
|
+
npm install -g tt-ide-cli
|
27
|
+
```
|
28
|
+
|
29
|
+
## 使用
|
30
|
+
|
31
|
+
### 创建新项目
|
32
|
+
|
33
|
+
在当前目录下,以给定的项目名字创建一个空白的小程序项目。
|
34
|
+
|
35
|
+
```
|
36
|
+
Usage: tmg create <project-name>
|
37
|
+
|
38
|
+
Create a new project with given name in current folder
|
39
|
+
|
40
|
+
Options:
|
41
|
+
|
42
|
+
-f, --force Overwrite target directory if it exists
|
43
|
+
-h, --help Output usage information
|
44
|
+
```
|
45
|
+
|
46
|
+
### 打开已有项目
|
47
|
+
|
48
|
+
在小程序开发者工具中打开给定目录的项目。
|
49
|
+
|
50
|
+
如果给定的目录不存在,则仅打开开发者工具。
|
51
|
+
|
52
|
+
```
|
53
|
+
Usage: tmg open <project-path>
|
54
|
+
|
55
|
+
Open target project by path
|
56
|
+
```
|
57
|
+
|
58
|
+
### 登录
|
59
|
+
|
60
|
+
登录到开发者平台。支持代理设置。
|
61
|
+
|
62
|
+
```
|
63
|
+
Usage: tmg login [options]
|
64
|
+
|
65
|
+
Login to the developer platform
|
66
|
+
|
67
|
+
Options:
|
68
|
+
-m, --mobile Login by mobile
|
69
|
+
-e, --email Login by email
|
70
|
+
-p, --proxy <proxy> Login with proxy
|
71
|
+
-h, --help output usage information
|
72
|
+
```
|
73
|
+
|
74
|
+
### 通过 email 登录
|
75
|
+
|
76
|
+
```
|
77
|
+
Usage: login-e [email] [password]
|
78
|
+
|
79
|
+
Login to the developer platform by E-mail
|
80
|
+
|
81
|
+
Options:
|
82
|
+
-p, --proxy <proxy> Login with proxy
|
83
|
+
-h, --help Output usage information
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
### 预览小程序
|
88
|
+
|
89
|
+
将项目上传后,扫码二维码来预览小程序。
|
90
|
+
|
91
|
+
```
|
92
|
+
Usage: tmg preview [options] [entry]
|
93
|
+
|
94
|
+
preview project by remote
|
95
|
+
|
96
|
+
Options:
|
97
|
+
-f, --force Preview project without local cache(deprecated)
|
98
|
+
--disable-cache Preview project without local cache
|
99
|
+
-s, --small Use small QR Code, but it does not take effect in some environments
|
100
|
+
-c, --copy Copy remote url to clipboard
|
101
|
+
-p, --proxy <proxy> Preview with proxy
|
102
|
+
-h, --help output usage information
|
103
|
+
```
|
104
|
+
|
105
|
+
### 上传项目
|
106
|
+
|
107
|
+
把项目上传到开发者平台进行发布。
|
108
|
+
|
109
|
+
```
|
110
|
+
Usage: tmg upload [options] [entry]
|
111
|
+
|
112
|
+
upload project to the developer platform
|
113
|
+
|
114
|
+
Options:
|
115
|
+
-v, --app-version <version> App version (eg: [major].[minor].[patch])
|
116
|
+
-c, --app-changelog <log> Changelog for this version
|
117
|
+
-p, --proxy <proxy> Update request proxy
|
118
|
+
-cp, --copy Copy remote url to clipboard
|
119
|
+
-h, --help output usage information
|
120
|
+
```
|
package/bin/tmg.js
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
const fs = require('fs');
|
3
|
+
const path = require('path');
|
4
|
+
const chalk = require('chalk');
|
5
|
+
const program = require('commander');
|
6
|
+
const cp = require('child_process');
|
7
|
+
const semver = require('semver');
|
8
|
+
const minimist = require('minimist');
|
9
|
+
const { getVersion } = require('../lib/util/version');
|
10
|
+
const requiredVersion = require('../package.json').engines.node;
|
11
|
+
checkNodeVersion(requiredVersion);
|
12
|
+
|
13
|
+
// Get version
|
14
|
+
program.version(getVersion(), '-V, --version', 'Output the current version');
|
15
|
+
|
16
|
+
//#region open project
|
17
|
+
|
18
|
+
program
|
19
|
+
.command('open <project-path>')
|
20
|
+
.description('Open target project by path')
|
21
|
+
.action((projectPath) => {
|
22
|
+
const isMac = process.platform === 'darwin',
|
23
|
+
IDE_SCHEMA = 'bytedanceide:';
|
24
|
+
const openCmd = isMac ? `open ${IDE_SCHEMA}` : `explorer ${IDE_SCHEMA}`;
|
25
|
+
let openPath;
|
26
|
+
if (!path.isAbsolute(projectPath)) {
|
27
|
+
projectPath = path.join(process.cwd(), projectPath);
|
28
|
+
}
|
29
|
+
if (fs.existsSync(projectPath)) {
|
30
|
+
// open project with existing path
|
31
|
+
console.log(chalk.green(`open projectPath: ${projectPath}`));
|
32
|
+
openPath = `${openCmd}?path=${projectPath}`;
|
33
|
+
} else {
|
34
|
+
// project folder not exist,
|
35
|
+
// open IDE
|
36
|
+
console.log(chalk.green(`open IDE`));
|
37
|
+
openPath = openCmd;
|
38
|
+
}
|
39
|
+
|
40
|
+
cp.exec(openPath, (error) => {
|
41
|
+
if (!error) {
|
42
|
+
console.log('打开IDE成功');
|
43
|
+
} else {
|
44
|
+
console.log(chalk.red('打开IDE失败', error));
|
45
|
+
}
|
46
|
+
});
|
47
|
+
});
|
48
|
+
|
49
|
+
//#endregion
|
50
|
+
|
51
|
+
//#region create new project
|
52
|
+
|
53
|
+
program
|
54
|
+
.command('create <project-name>')
|
55
|
+
.description('Create a new project with given name in current folder')
|
56
|
+
.option('-f, --force', 'Overwrite target directory if it exists')
|
57
|
+
.action((name, cmd) => {
|
58
|
+
const options = cleanArgs(cmd);
|
59
|
+
checkArgNum(1);
|
60
|
+
require('../lib/create')(name, options);
|
61
|
+
});
|
62
|
+
|
63
|
+
//#endregion
|
64
|
+
|
65
|
+
//#region Login by mobile or email
|
66
|
+
|
67
|
+
program
|
68
|
+
.command('login')
|
69
|
+
.description('Login to the developer platform')
|
70
|
+
.option('-m, --mobile', 'Login by mobile')
|
71
|
+
.option('-e, --email', 'Login by email')
|
72
|
+
.option('-p, --proxy <proxy>', 'Login with proxy')
|
73
|
+
.action((cmd) => {
|
74
|
+
const options = cleanArgs(cmd);
|
75
|
+
require('../lib/auth')(options);
|
76
|
+
});
|
77
|
+
|
78
|
+
//#endregion
|
79
|
+
|
80
|
+
//#region tmg login by Email
|
81
|
+
|
82
|
+
program
|
83
|
+
.command('login-e [email] [password]')
|
84
|
+
.description('Login to the developer platform by E-mail')
|
85
|
+
.option('-p, --proxy <proxy>', 'Login with proxy')
|
86
|
+
.action((email, password, cmd) => {
|
87
|
+
const options = {
|
88
|
+
type: 'direct',
|
89
|
+
email,
|
90
|
+
password,
|
91
|
+
cmd,
|
92
|
+
};
|
93
|
+
require('../lib/auth')(options);
|
94
|
+
});
|
95
|
+
|
96
|
+
//#endregion
|
97
|
+
|
98
|
+
//#region preview project
|
99
|
+
|
100
|
+
program
|
101
|
+
.command('preview [entry]')
|
102
|
+
.description('Preview project by remote')
|
103
|
+
.option('-f, --force', 'Preview project without local cache(deprecated)')
|
104
|
+
.option('--disable-cache', 'Preview project without local cache')
|
105
|
+
.option('-s, --small', 'Use small QR Code, it may fail in some environments')
|
106
|
+
.option('-c, --copy', 'Copy remote url to clipboard')
|
107
|
+
.option('-p, --proxy <proxy>', 'Preview with proxy')
|
108
|
+
.action((entry, cmd) => {
|
109
|
+
const options = cleanArgs(cmd);
|
110
|
+
checkArgNum(1);
|
111
|
+
require('../lib/preview')(entry, options);
|
112
|
+
});
|
113
|
+
|
114
|
+
//#endregion
|
115
|
+
|
116
|
+
program
|
117
|
+
.command('build-npm [projectPath]')
|
118
|
+
.description('build npm packages in node_modules')
|
119
|
+
// 后面需要支持一下下方的两个选项
|
120
|
+
// .option('--package-json-path');
|
121
|
+
// .options('-i, --ignores', 'npm packages to be ignored')
|
122
|
+
.action((projectPath, cmd) => {
|
123
|
+
const options = cleanArgs(cmd);
|
124
|
+
require('../lib/index').buildNpm({
|
125
|
+
projectPath,
|
126
|
+
...options,
|
127
|
+
});
|
128
|
+
});
|
129
|
+
|
130
|
+
//#region upload project
|
131
|
+
|
132
|
+
program
|
133
|
+
.command('upload [entry]')
|
134
|
+
.description('Upload project to the developer platform')
|
135
|
+
.requiredOption(
|
136
|
+
'-v, --app-version <version>',
|
137
|
+
'App version (eg: [major].[minor].[patch])'
|
138
|
+
)
|
139
|
+
.requiredOption('-c, --app-changelog <log>', 'Changelog for this version')
|
140
|
+
.option('-p, --proxy <proxy>', 'Update request proxy')
|
141
|
+
.option('-cp, --copy', 'Copy remote url to clipboard')
|
142
|
+
.action((entry, cmd) => {
|
143
|
+
const options = cleanArgs(cmd);
|
144
|
+
checkArgNum(1);
|
145
|
+
// console.log(entry, options)
|
146
|
+
require('../lib/upload')(entry, options);
|
147
|
+
});
|
148
|
+
|
149
|
+
//#endregion
|
150
|
+
|
151
|
+
program.parse(process.argv);
|
152
|
+
|
153
|
+
//#region helpers
|
154
|
+
|
155
|
+
function camelize(str) {
|
156
|
+
return str.replace(/-(\w)/g, (_, c) => (c ? c.toUpperCase() : ''));
|
157
|
+
}
|
158
|
+
|
159
|
+
function checkArgNum(num) {
|
160
|
+
if (minimist(process.argv.slice(3))._.length > num) {
|
161
|
+
console.log(
|
162
|
+
chalk.yellow(
|
163
|
+
'\n Info: You provided more than one argument. The first one will be used, the rest are ignored.'
|
164
|
+
)
|
165
|
+
);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
function checkNodeVersion(wanted) {
|
170
|
+
if (!semver.satisfies(process.version, wanted)) {
|
171
|
+
console.log(
|
172
|
+
chalk.red(
|
173
|
+
'You are using Node ' +
|
174
|
+
process.version +
|
175
|
+
', but this version of `tmg`' +
|
176
|
+
' requires Node ' +
|
177
|
+
wanted +
|
178
|
+
'.\nPlease upgrade your Node version.'
|
179
|
+
)
|
180
|
+
);
|
181
|
+
process.exit(1);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
// commander passes the Command object itself as options,
|
186
|
+
// extract only actual options into a fresh object.
|
187
|
+
function cleanArgs(cmd) {
|
188
|
+
return cmd.options.reduce((args, o) => {
|
189
|
+
const key = camelize(o.long.replace(/^--/, ''));
|
190
|
+
// if an option is not present and Command has a method with the same name
|
191
|
+
// it should not be copied
|
192
|
+
if (typeof cmd[key] !== 'function' && typeof cmd[key] !== 'undefined') {
|
193
|
+
args[key] = cmd[key];
|
194
|
+
}
|
195
|
+
return args;
|
196
|
+
}, {});
|
197
|
+
}
|
198
|
+
|
199
|
+
//#endregion
|
package/lib/auth.js
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
// login
|
2
|
+
const inquirer = require('inquirer');
|
3
|
+
const chalk = require('chalk');
|
4
|
+
const { isValidPhoneNumber, isValidVerificationCode, isValidEmail } = require('./util/check');
|
5
|
+
const { clearConsole, outputResult } = require('./util/logger');
|
6
|
+
const { getMobileVerificationCode, userLogin, getUserData } = require('./util/request');
|
7
|
+
const { saveUserCookies } = require('./util/cookie');
|
8
|
+
const { mixEncode } = require('./util/helper');
|
9
|
+
|
10
|
+
async function auth(options) {
|
11
|
+
// Choose login type
|
12
|
+
const loginType = await checkLoginType(options);
|
13
|
+
let requestParams = {};
|
14
|
+
clearConsole(chalk.bold.green(`${loginType === 'mobile' ? '📱': ' 📧'} Sign in with ${loginType}`));
|
15
|
+
const { inputRet } = await inquirer.prompt([
|
16
|
+
{
|
17
|
+
name: 'inputRet',
|
18
|
+
type: 'input',
|
19
|
+
message: `Your ${loginType === 'mobile' ? 'mobile number': 'email'}:`
|
20
|
+
}
|
21
|
+
]);
|
22
|
+
if (loginType === 'mobile') {
|
23
|
+
if (isValidPhoneNumber(inputRet)) {
|
24
|
+
const result = await getMobileVerificationCode(inputRet, options.proxy);
|
25
|
+
result.success ? console.log(chalk.green('Send verification code success')): console.log(chalk.red(result.msg));
|
26
|
+
if (!result.success) return;
|
27
|
+
const { code } = await inquirer.prompt([
|
28
|
+
{
|
29
|
+
name: 'code',
|
30
|
+
type: 'input',
|
31
|
+
message: `Your verification code:`
|
32
|
+
}
|
33
|
+
]);
|
34
|
+
if (isValidVerificationCode(code)) {
|
35
|
+
requestParams = { mobile: inputRet, code };
|
36
|
+
} else {
|
37
|
+
console.log(chalk.red(`[CLI LOGIN ERROR]: Verification code ${chalk.cyan(code)} is not correct`));
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
} else {
|
41
|
+
console.log(chalk.red(`[CLI LOGIN ERROR]: Mobile number ${chalk.cyan(inputRet)} is not correct`));
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
} else {
|
45
|
+
if (isValidEmail(inputRet)) {
|
46
|
+
const { pwd } = await inquirer.prompt([
|
47
|
+
{
|
48
|
+
name: 'pwd',
|
49
|
+
type: 'password',
|
50
|
+
message: `Your password:`
|
51
|
+
}
|
52
|
+
]);
|
53
|
+
requestParams = {
|
54
|
+
mix_mode: 1,
|
55
|
+
email: mixEncode(inputRet),
|
56
|
+
password: mixEncode(pwd)
|
57
|
+
}
|
58
|
+
} else {
|
59
|
+
console.log(chalk.red(`[CLI LOGIN ERROR]: Email ${chalk.cyan(inputRet)} is not correct`));
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
// Start login
|
64
|
+
const { success: loginSuccess, msg: loginMsg, cookies } = await userLogin(loginType, requestParams, options.proxy);
|
65
|
+
if (!loginSuccess) {
|
66
|
+
console.log(chalk.red(`[CLI LOGIN ERROR]: ${loginMsg}`));
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
await saveUserCookies(cookies);
|
70
|
+
const { success: checkSuccess, msg: checkMsg } = await getUserData(options.proxy);
|
71
|
+
if (!checkSuccess) {
|
72
|
+
console.log(chalk.red(`[CLI LOGIN ERROR]: ${checkMsg}`));
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
outputResult('success', loginType, ` 🎉 Login success`);
|
76
|
+
}
|
77
|
+
|
78
|
+
async function loginDirect(options) {
|
79
|
+
const proxy = options.proxy || options.cmd.proxy;
|
80
|
+
if (!isValidEmail(options.email)) {
|
81
|
+
console.log(chalk.red(`[CLI LOGIN ERROR]: Email ${chalk.cyan(options.email)} is not correct`));
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
const loginType = 'email';
|
85
|
+
const requestParams = {
|
86
|
+
mix_mode: 1,
|
87
|
+
email: mixEncode(options.email),
|
88
|
+
password: mixEncode(options.password)
|
89
|
+
};
|
90
|
+
// Start login
|
91
|
+
const { success: loginSuccess, msg: loginMsg, cookies } = await userLogin(loginType, requestParams, proxy);
|
92
|
+
if (!loginSuccess) {
|
93
|
+
console.log(chalk.red(`[CLI LOGIN ERROR]: ${loginMsg}`));
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
await saveUserCookies(cookies, options.cacheDir);
|
97
|
+
const { success: checkSuccess, msg: checkMsg } = await getUserData(proxy);
|
98
|
+
if (!checkSuccess) {
|
99
|
+
console.log(chalk.red(`[CLI LOGIN ERROR]: ${checkMsg}`));
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
outputResult('success', loginType, ` 🎉 Login success`);
|
103
|
+
}
|
104
|
+
|
105
|
+
async function checkLoginType(options) {
|
106
|
+
let loginType = '';
|
107
|
+
if (options.mobile) {
|
108
|
+
loginType = 'mobile';
|
109
|
+
} else if (options.email) {
|
110
|
+
loginType = 'email';
|
111
|
+
} else {
|
112
|
+
const { action } = await inquirer.prompt([
|
113
|
+
{
|
114
|
+
name: 'action',
|
115
|
+
type: 'list',
|
116
|
+
message: `Please choose login type:`,
|
117
|
+
choices: [
|
118
|
+
{ name: 'Mobile', value: 'mobile' },
|
119
|
+
{ name: 'Email', value: 'email' },
|
120
|
+
{ name: 'Cancel', value: false }
|
121
|
+
]
|
122
|
+
}
|
123
|
+
]);
|
124
|
+
if (!action) {
|
125
|
+
return;
|
126
|
+
} else {
|
127
|
+
loginType = action;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
return loginType;
|
131
|
+
}
|
132
|
+
|
133
|
+
module.exports = (...args) => {
|
134
|
+
if (args[0].type === 'direct') {
|
135
|
+
return loginDirect(args[0]).catch(err => {
|
136
|
+
console.log(chalk.red(`[CLI LOGIN ERROR]: ${err}`));
|
137
|
+
process.exit(1);
|
138
|
+
});
|
139
|
+
} else {
|
140
|
+
return auth(...args).catch(err => {
|
141
|
+
console.log(chalk.red(`[CLI LOGIN ERROR]: ${err}`));
|
142
|
+
process.exit(1);
|
143
|
+
});
|
144
|
+
}
|
145
|
+
}
|
package/lib/build-npm.js
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
const { packNpm } = require('@tt-miniprogram/ext-pack');
|
2
|
+
|
3
|
+
const buildNpm = async (options) => {
|
4
|
+
// console.log('buildNpm收到的options是:::', options);
|
5
|
+
let projectPath = options.projectPath || process.cwd();
|
6
|
+
return new Promise((resolve, reject) => {
|
7
|
+
packNpm({
|
8
|
+
rootPath: projectPath,
|
9
|
+
isWatch: false
|
10
|
+
}, function(err, info) {
|
11
|
+
if (err) {
|
12
|
+
console.log({buildSuccess: false, reason: err});
|
13
|
+
reject({buildSuccess: false, reason: err});
|
14
|
+
} else {
|
15
|
+
console.log({buildSuccess: true, reason: info});
|
16
|
+
resolve({buildSuccess: true, reason: info});
|
17
|
+
}
|
18
|
+
});
|
19
|
+
});
|
20
|
+
};
|
21
|
+
|
22
|
+
module.exports = buildNpm;
|