mirror of
https://github.com/zhitaocai/CocosCreator-Build-Encrypt.git
synced 2026-05-31 16:39:22 +08:00
修复 .cocos-project.json 不存在时可能崩溃的问题
This commit is contained in:
@@ -51,7 +51,7 @@
|
||||
|
||||
### Cocos Creator 2.4.+
|
||||
|
||||
不支持(后续可能会有计划支持)
|
||||
目前不支持(后续可能会有计划支持)
|
||||
|
||||
### Cocos Creator 2.3.3
|
||||
|
||||
|
||||
@@ -14,8 +14,18 @@ export class CocosProjectConfig {
|
||||
projectName: string | undefined;
|
||||
|
||||
fromJson(json: any): CocosProjectConfig {
|
||||
this.engineVersion = json["engine_version"];
|
||||
this.projectName = json["projectName"];
|
||||
this.engineVersion = this._getJson(json, "engineVersion");
|
||||
this.projectName = this._getJson(json, "projectName");
|
||||
return this;
|
||||
}
|
||||
|
||||
private _getJson(json: any, key: string) {
|
||||
if (json) {
|
||||
let value = json[key];
|
||||
if (value != null && value != undefined) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ export class TaskConfig {
|
||||
/**
|
||||
* Cocos 项目配置
|
||||
*/
|
||||
cocosProject: CocosProjectConfig;
|
||||
cocosProject: CocosProjectConfig | undefined;
|
||||
|
||||
constructor(buildOutputDirPath: string) {
|
||||
// console.log("当前执行文件所在目录路径", __dirname);
|
||||
@@ -76,7 +76,10 @@ export class TaskConfig {
|
||||
this.buildOutputMainJsFilePath = path.join(this.buildOutputDirPath, "main.js");
|
||||
this.buildOutputLoaderPluginJsFilePath = path.join(this.buildOutputDirPath, "src/assets/loaderplugin.js");
|
||||
this.inputLoaderPluginJsFilePath = path.join(path.dirname(process.argv[1]), "loaderplugin.js");
|
||||
this.cocosProject = new CocosProjectConfig().fromJson(JSON.parse(fs.readFileSync(this.buildOutputCocosProjectJsonFilePath).toString()));
|
||||
|
||||
if (fs.existsSync(this.buildOutputCocosProjectJsonFilePath)) {
|
||||
this.cocosProject = new CocosProjectConfig().fromJson(JSON.parse(fs.readFileSync(this.buildOutputCocosProjectJsonFilePath).toString()));
|
||||
}
|
||||
|
||||
console.log("初始化项目配置");
|
||||
console.log(this);
|
||||
|
||||
Reference in New Issue
Block a user