-
Notifications
You must be signed in to change notification settings - Fork 5
/
refreshResCommand.ts
93 lines (80 loc) · 2.44 KB
/
refreshResCommand.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import * as AppCommand from './appCommand';
import * as fs from 'fs';
import * as path from 'path';
exports.command = 'refreshres';
exports.describe = '刷新app项目资源'
exports.builder = {
platform:
{
alias: 'p',
default: AppCommand.PLATFORM_ALL,
choices: [AppCommand.PLATFORM_ALL, AppCommand.PLATFORM_IOS, AppCommand.PLATFORM_ANDROID_STUDIO],
required: false,
requiresArg: true,
description: '项目平台'
},
path: {
default: '.',
required: false,
requiresArg: true,
description: 'native项目路径'
},
url:
{
alias: 'u',
required: false,
requiresArg: true,
description: '游戏地址'
}
}
exports.handler = function (argv) {
try {
let cmd = new AppCommand.AppCommand();
let nativeJSONPath = null;
let nativePath = null;
nativePath = AppCommand.AppCommand.getNativePath(argv.path);
nativeJSONPath = AppCommand.AppCommand.getNativeJSONPath(argv.path);
if (!fs.existsSync(nativePath)) {
console.error('错误: 找不到目录 ' + nativePath);
return;
}
if (!fs.existsSync(nativeJSONPath)) {
console.error('错误: 找不到文件 ' + nativeJSONPath + ",无效的native项目路径");
return;
}
let nativeJSON = JSON.parse( fs.readFileSync(nativeJSONPath,'utf8'));
if (!nativeJSON) {
console.error('错误: 文件 ' + nativeJSONPath + ' 无效');
return;
}
if (nativeJSON.h5 === '') {
console.error('错误: 资源目录为空,刷新失败');
return;
}
let folder = nativeJSON.h5;
if (argv.platform === AppCommand.PLATFORM_ALL) {
let appPath = AppCommand.AppCommand.getAppPath(nativePath, AppCommand.PLATFORM_IOS);
cmd.excuteRefreshRes(folder, argv.url, appPath);
appPath = AppCommand.AppCommand.getAppPath(nativePath, AppCommand.PLATFORM_ANDROID_STUDIO);
cmd.excuteRefreshRes(folder, argv.url, appPath);
}
else {
let appPath = AppCommand.AppCommand.getAppPath(nativePath, argv.platform);
if (fs.existsSync(appPath)) {
cmd.excuteRefreshRes(folder, argv.url, appPath);
}
else {
console.error('错误:找不到目录' + appPath);
}
}
console.debug('请继续......');
}
catch (error) {
console.debug();
if (error.code === 'EPERM') {
console.error('错误:文件已经被使用或被其他程序打开');
}
console.error(error.name);
console.error(error.message);
}
}