usf-cli 1.1.3 → 1.2.2
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/LICENSE.md +5 -5
- package/README.md +67 -49
- package/ci.sh +60 -0
- package/index.js +186 -186
- package/package.json +30 -30
- package/templates/crud_mongo.js +35 -35
- package/templates/crud_mysql.js +59 -59
- package/templates/crud_postgresql.js +29 -29
- package/templates/crud_redis.js +31 -31
- package/templates/default.js +8 -8
- package/utils/dynamic-runner/index.js +89 -89
- package/utils/function-construct/index.js +120 -120
- package/utils/uploader/index.js +364 -359
- package/.idea/modules.xml +0 -8
- package/.idea/usf-cli.iml +0 -12
- package/.idea/vcs.xml +0 -6
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
usf-cli copyright © 2023 Unity Technologies
|
|
2
|
-
|
|
3
|
-
Your use of the Unity Technologies ("Unity") services known as "usf-cli" are subject to the UOS Terms of Service linked to and copied immediately below.
|
|
4
|
-
[Unity Online Services TOS](https://uos.unity.cn/policy/tos)
|
|
5
|
-
|
|
1
|
+
usf-cli copyright © 2023 Unity Technologies
|
|
2
|
+
|
|
3
|
+
Your use of the Unity Technologies ("Unity") services known as "usf-cli" are subject to the UOS Terms of Service linked to and copied immediately below.
|
|
4
|
+
[Unity Online Services TOS](https://uos.unity.cn/policy/tos)
|
|
5
|
+
|
|
6
6
|
Your use of the usf-cli constitutes your acceptance of such terms. Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.
|
package/README.md
CHANGED
|
@@ -1,50 +1,68 @@
|
|
|
1
|
-
# Develop UOS Func Stateless with usf-cli
|
|
2
|
-
|
|
3
|
-
## Install usf-cli
|
|
4
|
-
```bash
|
|
5
|
-
npm install -g
|
|
6
|
-
```
|
|
7
|
-
|
|
8
|
-
## Create project
|
|
9
|
-
```bash
|
|
10
|
-
mkdir stateless-function
|
|
11
|
-
cd stateless-function
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Init project
|
|
15
|
-
```bash
|
|
16
|
-
usf-cli -i
|
|
17
|
-
# or
|
|
18
|
-
npm init
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Creat function
|
|
22
|
-
```bash
|
|
23
|
-
# create default function
|
|
24
|
-
usf-cli -c --f=helloWorld
|
|
25
|
-
# or create function with crud template
|
|
26
|
-
usf-cli -c --f=helloCrud --t=crud_mysql
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Edit function & event data
|
|
30
|
-
```bash
|
|
31
|
-
vim ./helloWorld/index.js
|
|
32
|
-
# or open it in IDE
|
|
33
|
-
```
|
|
34
|
-
```bash
|
|
35
|
-
vim ./.uos_test/helloWorld_event.json
|
|
36
|
-
# or open it in IDE
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Install Dependency (If necessary)
|
|
40
|
-
```bash
|
|
41
|
-
npm install .
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Run function locally
|
|
45
|
-
```bash
|
|
46
|
-
# with default event data json(./uos_test/helloWorld_event.json)
|
|
47
|
-
usf-cli -r --f=helloWorld
|
|
48
|
-
# or with specified event data json(e.g. you have created a test.json in your project dir)
|
|
49
|
-
usf-cli -r --f=helloWorld --e=./test.json
|
|
1
|
+
# Develop UOS Func Stateless with usf-cli
|
|
2
|
+
|
|
3
|
+
## Install usf-cli
|
|
4
|
+
```bash
|
|
5
|
+
npm install -g usf-cli
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
## Create project
|
|
9
|
+
```bash
|
|
10
|
+
mkdir stateless-function
|
|
11
|
+
cd stateless-function
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Init project
|
|
15
|
+
```bash
|
|
16
|
+
usf-cli -i
|
|
17
|
+
# or
|
|
18
|
+
npm init
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Creat function
|
|
22
|
+
```bash
|
|
23
|
+
# create default function
|
|
24
|
+
usf-cli -c --f=helloWorld
|
|
25
|
+
# or create function with crud template
|
|
26
|
+
usf-cli -c --f=helloCrud --t=crud_mysql
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Edit function & event data
|
|
30
|
+
```bash
|
|
31
|
+
vim ./helloWorld/index.js
|
|
32
|
+
# or open it in IDE
|
|
33
|
+
```
|
|
34
|
+
```bash
|
|
35
|
+
vim ./.uos_test/helloWorld_event.json
|
|
36
|
+
# or open it in IDE
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Install Dependency (If necessary)
|
|
40
|
+
```bash
|
|
41
|
+
npm install .
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Run function locally
|
|
45
|
+
```bash
|
|
46
|
+
# with default event data json(./uos_test/helloWorld_event.json)
|
|
47
|
+
usf-cli -r --f=helloWorld
|
|
48
|
+
# or with specified event data json(e.g. you have created a test.json in your project dir)
|
|
49
|
+
usf-cli -r --f=helloWorld --e=./test.json
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Deploy function
|
|
53
|
+
```bash
|
|
54
|
+
# before delpoying function, you should set app id and service secret for this project (used for generating auth token)
|
|
55
|
+
usf-cli -a --id=<app-id> --secret=<service-secret>
|
|
56
|
+
# and then you can deploy it
|
|
57
|
+
usf-cli -d
|
|
58
|
+
# Func Stateless also support install dependency online, so that if the size of your project is larger than 50MB, you can set 'installDenpendency'
|
|
59
|
+
usf-cli -d --installDependency
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## CI Script
|
|
63
|
+
```bash
|
|
64
|
+
# test usf-cli with ci script (shell)
|
|
65
|
+
vim @usf-cli/ci.sh # set APPID & APPSECRET
|
|
66
|
+
chmod +x @usf-cli/ci.sh
|
|
67
|
+
@usf-cli/ci.sh
|
|
50
68
|
```
|
package/ci.sh
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
APPID=''
|
|
4
|
+
APPSECRET=''
|
|
5
|
+
|
|
6
|
+
START='\033[34m'
|
|
7
|
+
SUCCESS='\033[32m'
|
|
8
|
+
ERROR='\033[31m'
|
|
9
|
+
RESET='\033[0m'
|
|
10
|
+
|
|
11
|
+
# 获取运行脚本时指定的参数a与b
|
|
12
|
+
if [ -z "$APPID" ] || [ -z "$APPSECRET" ]; then
|
|
13
|
+
echo -e "${ERROR}>>> 请通过 'vim $0' 配置 APPID 和 APPSECRET 用于后续部署${RESET}"
|
|
14
|
+
exit 1
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# 检查 npm 是否已安装
|
|
19
|
+
if ! command -v npm &> /dev/null; then
|
|
20
|
+
echo -e "${ERROR}>>> 未检测到 npm,请先安装 npm。${RESET}"
|
|
21
|
+
exit 1
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# 安装usf-cli
|
|
26
|
+
if ! command -v usf-cli &> /dev/null; then
|
|
27
|
+
echo -e "${START}>>> 正在安装 usf-cli...${RESET}"
|
|
28
|
+
npm install -g usf-cli
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
# 检查usf-cli是否安装成功
|
|
32
|
+
if ! command -v usf-cli &> /dev/null; then
|
|
33
|
+
echo -e "${ERROR}>>> usf-cli安装失败,请检查安装过程。${RESET}"
|
|
34
|
+
exit 1
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
echo -e "${SUCCESS}>>> usf-cli已安装。${RESET}"
|
|
38
|
+
|
|
39
|
+
# 安装依赖项
|
|
40
|
+
echo -e "${START}>>> 正在安装依赖项${RESET}"
|
|
41
|
+
npm install .
|
|
42
|
+
|
|
43
|
+
echo -e "${SUCCESS}>>> 成功安装依赖项${RESET}"
|
|
44
|
+
|
|
45
|
+
# 配置变量
|
|
46
|
+
echo -e "${START}>>> 正在配置auth信息${RESET}"
|
|
47
|
+
usf-cli -a --id="$APPID" --secret="$APPSECRET"
|
|
48
|
+
echo -e "${SUCCESS}>>> 成功配置auth信息${RESET}"
|
|
49
|
+
|
|
50
|
+
# 部署项目
|
|
51
|
+
echo -e "${START}>>> 正在部署函数${RESET}"
|
|
52
|
+
output=$(usf-cli -d | tee /dev/tty)
|
|
53
|
+
|
|
54
|
+
# 检查输出是否包含以 "Deployment completed" 开头的内容
|
|
55
|
+
if echo -e "$output" | grep -q 'Deployment completed'; then
|
|
56
|
+
echo -e "${SUCCESS}>>> 部署成功!${RESET}"
|
|
57
|
+
else
|
|
58
|
+
echo -e "${ERROR}>>> 部署失败,请检查配置和运行过程。${RESET}"
|
|
59
|
+
exit 1
|
|
60
|
+
fi
|
package/index.js
CHANGED
|
@@ -1,186 +1,186 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import minimist from "minimist";
|
|
3
|
-
import { dynamicRunner } from "./utils/dynamic-runner/index.js";
|
|
4
|
-
import { create, loader } from "./utils/function-construct/index.js";
|
|
5
|
-
import { createRequire } from "module";
|
|
6
|
-
import { spawn } from "child_process";
|
|
7
|
-
import path from "path";
|
|
8
|
-
import {
|
|
9
|
-
recordAuthInfoToFile,
|
|
10
|
-
getAuthInfoFromFile,
|
|
11
|
-
deployFunctionsToPlatform,
|
|
12
|
-
} from "./utils/uploader/index.js";
|
|
13
|
-
|
|
14
|
-
const parseArguments = () => {
|
|
15
|
-
const args = minimist(process.argv, {
|
|
16
|
-
string: [
|
|
17
|
-
"dir",
|
|
18
|
-
"function",
|
|
19
|
-
"f",
|
|
20
|
-
"event",
|
|
21
|
-
"e",
|
|
22
|
-
"template",
|
|
23
|
-
"t",
|
|
24
|
-
"id",
|
|
25
|
-
"secret",
|
|
26
|
-
],
|
|
27
|
-
boolean: [
|
|
28
|
-
"v",
|
|
29
|
-
"version",
|
|
30
|
-
"h",
|
|
31
|
-
"help",
|
|
32
|
-
"i",
|
|
33
|
-
"init",
|
|
34
|
-
"c",
|
|
35
|
-
"create",
|
|
36
|
-
"run",
|
|
37
|
-
"r",
|
|
38
|
-
"a",
|
|
39
|
-
"auth",
|
|
40
|
-
"d",
|
|
41
|
-
"deploy",
|
|
42
|
-
"installDependency",
|
|
43
|
-
],
|
|
44
|
-
});
|
|
45
|
-
return {
|
|
46
|
-
init: args.i || args.init,
|
|
47
|
-
version: args.v || args.version,
|
|
48
|
-
help: args.h || args.help || process.argv.length === 2,
|
|
49
|
-
create: args.c || args.c,
|
|
50
|
-
run: args.r || args.run,
|
|
51
|
-
dir: args.dir || process.cwd(),
|
|
52
|
-
functionName: args.function || args.f || undefined,
|
|
53
|
-
event: args.e || args.event,
|
|
54
|
-
template: args.t || args.template,
|
|
55
|
-
auth: args.auth || args.a,
|
|
56
|
-
deploy: args.d || args.deploy,
|
|
57
|
-
id: args.id,
|
|
58
|
-
secret: args.secret,
|
|
59
|
-
install: args.installDependency || false,
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const showVersion = function () {
|
|
64
|
-
const require = createRequire(import.meta.url);
|
|
65
|
-
console.log(require("./package.json").version);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const showHelp = function () {
|
|
69
|
-
console.log(`Usage of usf-cli: usf-cli [option]
|
|
70
|
-
|
|
71
|
-
Usage:
|
|
72
|
-
-v get the version of usf-cli
|
|
73
|
-
-h list the instruction of usf-cli
|
|
74
|
-
-i init function project
|
|
75
|
-
-c --f=<function-name> create function <function-name> & its test event data template
|
|
76
|
-
-c --f=<function-name> --t=<template> create function <function-name> with specified template code (see Supported template code) & its test event data template
|
|
77
|
-
-r --f=<function-name> run function <function-name> with default event data(./uos_test/<function-name>_event.json)
|
|
78
|
-
-r --f=<function-name> --e=<event-dir> run function <function-name> with specified event data
|
|
79
|
-
-a --id=<app-id> --secret=<service-secret> set app id and service secret for this project (used for generating auth token)
|
|
80
|
-
-d upload current stateless functions to UOS platform with UOS auth and deploy automatically
|
|
81
|
-
|
|
82
|
-
Supported template code:
|
|
83
|
-
crud_mongo template function code for uos crud(mongo db version)
|
|
84
|
-
crud_mysql template function code for uos crud(mysql db version)
|
|
85
|
-
crud_postgresql template function code for uos crud(postgresql db version)
|
|
86
|
-
crud_redis template function code for uos crud(redis version)
|
|
87
|
-
`);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const initProject = function () {
|
|
91
|
-
spawn("npm", ["init"], {
|
|
92
|
-
shell: true,
|
|
93
|
-
stdio: "inherit",
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const createFunction = function () {
|
|
98
|
-
if (!this.dir) {
|
|
99
|
-
console.error(
|
|
100
|
-
`please specify the directory of stateless project with "--dir"`
|
|
101
|
-
);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (!this.functionName) {
|
|
106
|
-
console.error(`please specify the function name with "--f"`);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
create(this.dir, this.functionName, this.template);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const runFunction = async function () {
|
|
113
|
-
if (!this.dir) {
|
|
114
|
-
console.error(
|
|
115
|
-
`please specify the directory of stateless project with "--dir"`
|
|
116
|
-
);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (!this.functionName) {
|
|
121
|
-
console.error(`please specify the function name with "--f"`);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
let filePath = this.event
|
|
125
|
-
? path.resolve(this.event)
|
|
126
|
-
: path.join(this.dir, `.uos_test/${this.functionName}_event.json`);
|
|
127
|
-
const event = (await loader(filePath)) || {};
|
|
128
|
-
dynamicRunner(`${this.dir}/${this.functionName}`, event);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const setAuthInfo = async function () {
|
|
132
|
-
if (!this.id) {
|
|
133
|
-
console.error(
|
|
134
|
-
`Please specify app id with "--id".\n\nIf not sure about app id, you can go to uos dev portal(https://uos.unity.cn/apps) to find your apps and get app id.`
|
|
135
|
-
);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (!this.secret) {
|
|
139
|
-
console.error(
|
|
140
|
-
`please specify app service secret with "--secret".\n\nIf not sure about app service secret, you can go to uos dev portal(https://uos.unity.cn/apps) to find your apps and get app service secret in setting tab of app detail page.`
|
|
141
|
-
);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
recordAuthInfoToFile(this.id, this.secret);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const deployFunction = async function () {
|
|
148
|
-
if (!this.dir) {
|
|
149
|
-
console.error(
|
|
150
|
-
`please specify the directory of stateless project with "--dir"`
|
|
151
|
-
);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
const auth = (await getAuthInfoFromFile()) || {};
|
|
155
|
-
if (!auth.id || !auth.secret) {
|
|
156
|
-
console.error(
|
|
157
|
-
`Please specify app id and secret with "usf-cli -a --id=<app-id> --secret=<service-secret>".\n\nIf not sure about app id and secret, you can go to uos dev portal(https://uos.unity.cn/apps) to find your apps and get app id and app service secret in setting tab of app detail page..`
|
|
158
|
-
);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
deployFunctionsToPlatform(this.dir, auth, this.install);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const main = async function () {
|
|
165
|
-
const args = parseArguments();
|
|
166
|
-
|
|
167
|
-
const commandMap = {
|
|
168
|
-
version: showVersion,
|
|
169
|
-
help: showHelp,
|
|
170
|
-
init: initProject.bind(args),
|
|
171
|
-
create: createFunction.bind(args),
|
|
172
|
-
run: runFunction.bind(args),
|
|
173
|
-
auth: setAuthInfo.bind(args),
|
|
174
|
-
deploy: deployFunction.bind(args),
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
for (let command in commandMap) {
|
|
178
|
-
if (args[command]) {
|
|
179
|
-
commandMap[command]();
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
showHelp();
|
|
185
|
-
};
|
|
186
|
-
main();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import minimist from "minimist";
|
|
3
|
+
import { dynamicRunner } from "./utils/dynamic-runner/index.js";
|
|
4
|
+
import { create, loader } from "./utils/function-construct/index.js";
|
|
5
|
+
import { createRequire } from "module";
|
|
6
|
+
import { spawn } from "child_process";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import {
|
|
9
|
+
recordAuthInfoToFile,
|
|
10
|
+
getAuthInfoFromFile,
|
|
11
|
+
deployFunctionsToPlatform,
|
|
12
|
+
} from "./utils/uploader/index.js";
|
|
13
|
+
|
|
14
|
+
const parseArguments = () => {
|
|
15
|
+
const args = minimist(process.argv, {
|
|
16
|
+
string: [
|
|
17
|
+
"dir",
|
|
18
|
+
"function",
|
|
19
|
+
"f",
|
|
20
|
+
"event",
|
|
21
|
+
"e",
|
|
22
|
+
"template",
|
|
23
|
+
"t",
|
|
24
|
+
"id",
|
|
25
|
+
"secret",
|
|
26
|
+
],
|
|
27
|
+
boolean: [
|
|
28
|
+
"v",
|
|
29
|
+
"version",
|
|
30
|
+
"h",
|
|
31
|
+
"help",
|
|
32
|
+
"i",
|
|
33
|
+
"init",
|
|
34
|
+
"c",
|
|
35
|
+
"create",
|
|
36
|
+
"run",
|
|
37
|
+
"r",
|
|
38
|
+
"a",
|
|
39
|
+
"auth",
|
|
40
|
+
"d",
|
|
41
|
+
"deploy",
|
|
42
|
+
"installDependency",
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
init: args.i || args.init,
|
|
47
|
+
version: args.v || args.version,
|
|
48
|
+
help: args.h || args.help || process.argv.length === 2,
|
|
49
|
+
create: args.c || args.c,
|
|
50
|
+
run: args.r || args.run,
|
|
51
|
+
dir: args.dir || process.cwd(),
|
|
52
|
+
functionName: args.function || args.f || undefined,
|
|
53
|
+
event: args.e || args.event,
|
|
54
|
+
template: args.t || args.template,
|
|
55
|
+
auth: args.auth || args.a,
|
|
56
|
+
deploy: args.d || args.deploy,
|
|
57
|
+
id: args.id,
|
|
58
|
+
secret: args.secret,
|
|
59
|
+
install: args.installDependency || false,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const showVersion = function () {
|
|
64
|
+
const require = createRequire(import.meta.url);
|
|
65
|
+
console.log(require("./package.json").version);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const showHelp = function () {
|
|
69
|
+
console.log(`Usage of usf-cli: usf-cli [option]
|
|
70
|
+
|
|
71
|
+
Usage:
|
|
72
|
+
-v get the version of usf-cli
|
|
73
|
+
-h list the instruction of usf-cli
|
|
74
|
+
-i init function project
|
|
75
|
+
-c --f=<function-name> create function <function-name> & its test event data template
|
|
76
|
+
-c --f=<function-name> --t=<template> create function <function-name> with specified template code (see Supported template code) & its test event data template
|
|
77
|
+
-r --f=<function-name> run function <function-name> with default event data(./uos_test/<function-name>_event.json)
|
|
78
|
+
-r --f=<function-name> --e=<event-dir> run function <function-name> with specified event data
|
|
79
|
+
-a --id=<app-id> --secret=<service-secret> set app id and service secret for this project (used for generating auth token)
|
|
80
|
+
-d upload current stateless functions to UOS platform with UOS auth and deploy automatically
|
|
81
|
+
|
|
82
|
+
Supported template code:
|
|
83
|
+
crud_mongo template function code for uos crud(mongo db version)
|
|
84
|
+
crud_mysql template function code for uos crud(mysql db version)
|
|
85
|
+
crud_postgresql template function code for uos crud(postgresql db version)
|
|
86
|
+
crud_redis template function code for uos crud(redis version)
|
|
87
|
+
`);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const initProject = function () {
|
|
91
|
+
spawn("npm", ["init"], {
|
|
92
|
+
shell: true,
|
|
93
|
+
stdio: "inherit",
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const createFunction = function () {
|
|
98
|
+
if (!this.dir) {
|
|
99
|
+
console.error(
|
|
100
|
+
`please specify the directory of stateless project with "--dir"`
|
|
101
|
+
);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!this.functionName) {
|
|
106
|
+
console.error(`please specify the function name with "--f"`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
create(this.dir, this.functionName, this.template);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const runFunction = async function () {
|
|
113
|
+
if (!this.dir) {
|
|
114
|
+
console.error(
|
|
115
|
+
`please specify the directory of stateless project with "--dir"`
|
|
116
|
+
);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!this.functionName) {
|
|
121
|
+
console.error(`please specify the function name with "--f"`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
let filePath = this.event
|
|
125
|
+
? path.resolve(this.event)
|
|
126
|
+
: path.join(this.dir, `.uos_test/${this.functionName}_event.json`);
|
|
127
|
+
const event = (await loader(filePath)) || {};
|
|
128
|
+
dynamicRunner(`${this.dir}/${this.functionName}`, event);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const setAuthInfo = async function () {
|
|
132
|
+
if (!this.id) {
|
|
133
|
+
console.error(
|
|
134
|
+
`Please specify app id with "--id".\n\nIf not sure about app id, you can go to uos dev portal(https://uos.unity.cn/apps) to find your apps and get app id.`
|
|
135
|
+
);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (!this.secret) {
|
|
139
|
+
console.error(
|
|
140
|
+
`please specify app service secret with "--secret".\n\nIf not sure about app service secret, you can go to uos dev portal(https://uos.unity.cn/apps) to find your apps and get app service secret in setting tab of app detail page.`
|
|
141
|
+
);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
recordAuthInfoToFile(this.id, this.secret);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const deployFunction = async function () {
|
|
148
|
+
if (!this.dir) {
|
|
149
|
+
console.error(
|
|
150
|
+
`please specify the directory of stateless project with "--dir"`
|
|
151
|
+
);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const auth = (await getAuthInfoFromFile()) || {};
|
|
155
|
+
if (!auth.id || !auth.secret) {
|
|
156
|
+
console.error(
|
|
157
|
+
`Please specify app id and secret with "usf-cli -a --id=<app-id> --secret=<service-secret>".\n\nIf not sure about app id and secret, you can go to uos dev portal(https://uos.unity.cn/apps) to find your apps and get app id and app service secret in setting tab of app detail page..`
|
|
158
|
+
);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
deployFunctionsToPlatform(this.dir, auth, this.install);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const main = async function () {
|
|
165
|
+
const args = parseArguments();
|
|
166
|
+
|
|
167
|
+
const commandMap = {
|
|
168
|
+
version: showVersion,
|
|
169
|
+
help: showHelp,
|
|
170
|
+
init: initProject.bind(args),
|
|
171
|
+
create: createFunction.bind(args),
|
|
172
|
+
run: runFunction.bind(args),
|
|
173
|
+
auth: setAuthInfo.bind(args),
|
|
174
|
+
deploy: deployFunction.bind(args),
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
for (let command in commandMap) {
|
|
178
|
+
if (args[command]) {
|
|
179
|
+
commandMap[command]();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
showHelp();
|
|
185
|
+
};
|
|
186
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "usf-cli",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "usf-cli helps uos stateless function developers with local running, boosting their development efficiency.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"usf-cli": "./index.js"
|
|
8
|
-
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"test": "test"
|
|
11
|
-
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
"cli"
|
|
14
|
-
],
|
|
15
|
-
"type": "module",
|
|
16
|
-
"author": "salanx.shi@uos",
|
|
17
|
-
"license": "ISC",
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"axios": "^1.7.2",
|
|
20
|
-
"child_process": "^1.0.2",
|
|
21
|
-
"cos-nodejs-sdk-v5": "^2.14.4",
|
|
22
|
-
"jszip": "^3.10.1",
|
|
23
|
-
"minimist": "^1.2.8",
|
|
24
|
-
"module": "^1.1.0",
|
|
25
|
-
"path": "^0.12.7",
|
|
26
|
-
"read-pkg-up": "^11.0.0",
|
|
27
|
-
"semver": "^7.6.1",
|
|
28
|
-
"url": "^0.11.3"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "usf-cli",
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"description": "usf-cli helps uos stateless function developers with local running, boosting their development efficiency.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"usf-cli": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "test"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"cli"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"author": "salanx.shi@uos",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"axios": "^1.7.2",
|
|
20
|
+
"child_process": "^1.0.2",
|
|
21
|
+
"cos-nodejs-sdk-v5": "^2.14.4",
|
|
22
|
+
"jszip": "^3.10.1",
|
|
23
|
+
"minimist": "^1.2.8",
|
|
24
|
+
"module": "^1.1.0",
|
|
25
|
+
"path": "^0.12.7",
|
|
26
|
+
"read-pkg-up": "^11.0.0",
|
|
27
|
+
"semver": "^7.6.1",
|
|
28
|
+
"url": "^0.11.3"
|
|
29
|
+
}
|
|
30
|
+
}
|