12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- const fs = require('fire-fs');
- const path = require('fire-path');
- module.exports = (function (){
- var _instance;
- function init (params) {
- return {
- _config: {},
- _versionConfig: {},
- getConfig () {
- return this._config;
- },
- setConfig (config) {
- this._config = config;
- },
- getConfigFilePath () {
- return path.join(Editor.Project.path, 'settings', 'buildhelper.json');
- },
- loadJsonFile (filePath) {
- let obj = null;
- try {
- obj = JSON.parse(fs.readFileSync(filePath, 'utf8'));
- } catch (err) {
- Editor.log(err);
- obj = {};
- }
- return obj;
- },
- saveJsonFile (filePath, data) {
- const dirPath = path.dirname(filePath);
- fs.ensureDir(dirPath, function () {
- fs.writeFileSync(filePath, data);
- });
- },
- load () {
- let filePath = this.getConfigFilePath();
- this._config = this.loadJsonFile(filePath);
- },
- save () {
- let filePath = this.getConfigFilePath();
- this.saveJsonFile(filePath, JSON.stringify(this._config, '', '\t'));
- },
- getItem (key) {
- return this._config[key];
- },
- setItem (key, value) {
- this._config[key] = value;
- },
- loadVersionConfig () {
- Editor.Scene.callSceneScript('build-helper', 'getVersionConfig', (err, ns) => {
- if (err) {
- Editor.error('编译助手(build-helper)获取版本信息失败!');
- Editor.log('编译助手(build-helper)将重新获取版本信息!');
- setTimeout(()=> {
- this.loadVersionConfig();
- }, 1000);
- return;
- }
- this.setVersionConfig(ns);
- Editor.log('编译助手(build-helper)获取版本信息成功!', ns);
- });
- },
- setVersionConfig (cfg) {
- this._versionConfig = cfg;
- },
- getVersionConfig () {
- return this._versionConfig;
- }
- };
- }
- return {
- getInstance (params) {
- if (!_instance){
- _instance = init(params);
- }
- return _instance;
- }
- };
- })();
|