Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit 57462e1

Browse files
committed
fix windows login error & add deploy default config
1 parent 1e6e4e9 commit 57462e1

10 files changed

Lines changed: 59 additions & 33 deletions

File tree

bin/cloudbase.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const Sentry = require('@sentry/node')
55
const program = require('commander')
66
const logSymbols = require('log-symbols')
77
const updateNotifier = require('update-notifier')
8+
const address = require('address')
89
const pkg = require('../package.json')
910

1011
const isBeta = pkg.version.indexOf('-') > -1
@@ -45,7 +46,8 @@ Sentry.configureScope(scope => {
4546
try {
4647
const credential = store.authStore.get('credential') || {}
4748
scope.setUser({
48-
uin: credential.uin || ''
49+
uin: credential.uin || '',
50+
ip: address.ip() || ''
4951
})
5052
} catch (e) {
5153
Sentry.captureException(e)

lib/commands/functions/deploy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ function deploy(ctx, commandOptions) {
6666
runtime: 'Nodejs8.9',
6767
installDependency: true
6868
},
69-
handler: 'index.main'
69+
handler: 'index.main',
70+
ignore: ['node_modules', 'node_modules/**/*']
7071
};
7172
}
7273
else {

lib/utils/auth.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const crypto_1 = __importDefault(require("crypto"));
1717
const portfinder_1 = __importDefault(require("portfinder"));
1818
const query_string_1 = __importDefault(require("query-string"));
1919
const open_1 = __importDefault(require("open"));
20+
const address_1 = __importDefault(require("address"));
2021
var cli_table_1 = require("./cli-table");
2122
exports.printCliTable = cli_table_1.printCliTable;
2223
const store_1 = require("./store");
@@ -37,17 +38,15 @@ function getPort() {
3738
});
3839
}
3940
function getMacAddress() {
40-
const networkInterfaces = os_1.default.networkInterfaces();
41-
const options = ['eth0', 'eth1', 'en0', 'en1'];
42-
let netInterface = [];
43-
options.some(key => {
44-
if (networkInterfaces[key]) {
45-
netInterface = networkInterfaces[key];
46-
return true;
47-
}
41+
return new Promise(resolve => {
42+
address_1.default.mac((err, mac) => {
43+
if (err) {
44+
resolve('');
45+
return;
46+
}
47+
resolve(mac);
48+
});
4849
});
49-
const mac = (netInterface.length && netInterface[0].mac) || '';
50-
return mac;
5150
}
5251
function getOSInfo() {
5352
const hostname = os_1.default.hostname();
@@ -63,7 +62,7 @@ function md5(str) {
6362
}
6463
function refreshTmpToken(metaData) {
6564
return __awaiter(this, void 0, void 0, function* () {
66-
const mac = getMacAddress();
65+
const mac = yield getMacAddress();
6766
const hash = md5(mac);
6867
metaData.hash = hash;
6968
const res = yield utils_1.fetch(refreshTokenUrl, {
@@ -148,9 +147,12 @@ function getAuthTokenFromWeb() {
148147
loading.start('正在打开腾讯云获取授权');
149148
try {
150149
const { server, port } = yield createLocalServer();
151-
const mac = getMacAddress();
150+
const mac = yield getMacAddress();
152151
const os = getOSInfo();
153152
const hash = md5(mac);
153+
if (!mac) {
154+
throw new error_1.CloudBaseError('获取 Mac 地址失败,无法登录!');
155+
}
154156
const CliAuthUrl = `${CliAuthBaseUrl}?port=${port}&hash=${hash}&mac=${mac}&os=${os}`;
155157
yield open_1.default(CliAuthUrl);
156158
loading.succeed('已打开云开发 CLI 授权页面,请在云开发 CLI 授权页面同意授权!');

lib/utils/function-packer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class FunctionPacker {
8282
});
8383
}
8484
clean() {
85-
del_1.default.sync([this.funcDistPath, this.tmpPath]);
85+
this.funcDistPath && del_1.default.sync([this.funcDistPath]);
86+
this.tmpPath && del_1.default.sync([this.tmpPath]);
8687
}
8788
}
8889
exports.FunctionPacker = FunctionPacker;

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"license": "ISC",
2222
"dependencies": {
2323
"@sentry/node": "^5.7.1",
24+
"address": "^1.1.2",
2425
"archiver": "^3.1.1",
2526
"arg": "^4.1.1",
2627
"chalk": "^2.4.2",

src/commands/functions/deploy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export async function deploy(ctx: FunctionContext, commandOptions) {
6363
runtime: 'Nodejs8.9',
6464
installDependency: true
6565
},
66-
handler: 'index.main'
66+
handler: 'index.main',
67+
ignore: ['node_modules', 'node_modules/**/*']
6768
}
6869
} else {
6970
throw new CloudBaseError(`函数 ${name} 配置不存在`)

src/function/create.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { CloudService, FunctionPacker, CodeType, loadingFactory } from '../utils'
1+
import {
2+
CloudService,
3+
FunctionPacker,
4+
CodeType,
5+
loadingFactory
6+
} from '../utils'
27
import { CloudBaseError } from '../error'
38
import { ICreateFunctionOptions } from '../types'
49
import { createFunctionTriggers } from './trigger'

src/utils/auth.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import crypto from 'crypto'
44
import portfinder from 'portfinder'
55
import queryString from 'query-string'
66
import open from 'open'
7+
import address from 'address'
78

89
import { Credential, AuthSecret } from '../types'
910
export { printCliTable } from './cli-table'
@@ -33,18 +34,16 @@ async function getPort(): Promise<number> {
3334
}
3435

3536
// 获取本机 Mac 地址
36-
function getMacAddress(): string {
37-
const networkInterfaces = os.networkInterfaces()
38-
const options = ['eth0', 'eth1', 'en0', 'en1']
39-
let netInterface: os.NetworkInterfaceInfo[] = []
40-
options.some(key => {
41-
if (networkInterfaces[key]) {
42-
netInterface = networkInterfaces[key]
43-
return true
44-
}
37+
function getMacAddress(): Promise<string> {
38+
return new Promise(resolve => {
39+
address.mac((err, mac) => {
40+
if (err) {
41+
resolve('')
42+
return
43+
}
44+
resolve(mac)
45+
})
4546
})
46-
const mac: string = (netInterface.length && netInterface[0].mac) || ''
47-
return mac
4847
}
4948

5049
// 获取 hostname 和平台信息
@@ -69,7 +68,7 @@ function md5(str: string): string {
6968
export async function refreshTmpToken(
7069
metaData: Credential & { isLogout?: boolean }
7170
): Promise<Credential> {
72-
const mac = getMacAddress()
71+
const mac = await getMacAddress()
7372
const hash = md5(mac)
7473
metaData.hash = hash
7574

@@ -164,10 +163,14 @@ export async function getAuthTokenFromWeb(): Promise<Credential> {
164163

165164
try {
166165
const { server, port } = await createLocalServer()
167-
const mac = getMacAddress()
166+
const mac = await getMacAddress()
168167
const os = getOSInfo()
169168
const hash = md5(mac)
170169

170+
if (!mac) {
171+
throw new CloudBaseError('获取 Mac 地址失败,无法登录!')
172+
}
173+
171174
const CliAuthUrl = `${CliAuthBaseUrl}?port=${port}&hash=${hash}&mac=${mac}&os=${os}`
172175
await open(CliAuthUrl)
173176

src/utils/function-packer.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ export class FunctionPacker {
8080
return code
8181
} catch (error) {
8282
this.clean()
83-
throw new CloudBaseError(`函数代码打包失败:\n ${error.message}`)
83+
throw new CloudBaseError(
84+
`函数代码打包失败:\n ${error.message}`
85+
)
8486
}
8587
}
8688

@@ -90,12 +92,15 @@ export class FunctionPacker {
9092
return code
9193
} catch (error) {
9294
this.clean()
93-
throw new CloudBaseError(`函数代码打包失败:\n ${error.message}`)
95+
throw new CloudBaseError(
96+
`函数代码打包失败:\n ${error.message}`
97+
)
9498
}
9599
}
96100
}
97101

98102
clean() {
99-
del.sync([this.funcDistPath, this.tmpPath])
103+
this.funcDistPath && del.sync([this.funcDistPath])
104+
this.tmpPath && del.sync([this.tmpPath])
100105
}
101106
}

0 commit comments

Comments
 (0)