-
Notifications
You must be signed in to change notification settings - Fork 3
/
refreshResCommand.ts
99 lines (84 loc) · 2.89 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
94
95
96
97
98
99
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_WKWEBVIEW, AppCommand.PLATFORM_IOS, AppCommand.PLATFORM_ANDROID_ECLIPSE, 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.log('错误: 找不到目录 ' + nativePath);
return;
}
if (!fs.existsSync(nativeJSONPath)) {
console.log('错误: 找不到文件 ' + nativeJSONPath + ",无效的native项目路径");
return;
}
let nativeJSON = JSON.parse( fs.readFileSync(nativeJSONPath,'utf8'));
if (!nativeJSON) {
console.log('错误: 文件 ' + nativeJSONPath + ' 无效');
return;
}
if (nativeJSON.h5 === '') {
console.log('错误: 资源目录为空,刷新失败');
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_IOS_WKWEBVIEW);
cmd.excuteRefreshRes(folder, argv.url, appPath);
appPath = AppCommand.AppCommand.getAppPath(nativePath, AppCommand.PLATFORM_ANDROID_ECLIPSE);
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.log('错误:找不到目录' + appPath);
}
}
console.log('请继续......');
}
catch (error) {
console.log();
if (error.code === 'EPERM') {
console.log('错误:文件已经被使用或被其他程序打开');
}
console.log(error.name);
console.log(error.message);
}
}