You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
198 lines
5.7 KiB
198 lines
5.7 KiB
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
function _react() {
|
|
const data = _interopRequireDefault(require("react"));
|
|
|
|
_react = function _react() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function path() {
|
|
const data = _interopRequireWildcard(require("path"));
|
|
|
|
path = function path() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function fs() {
|
|
const data = _interopRequireWildcard(require("fs"));
|
|
|
|
fs = function fs() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function _immer() {
|
|
const data = _interopRequireDefault(require("immer"));
|
|
|
|
_immer = function _immer() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function _assert() {
|
|
const data = _interopRequireDefault(require("assert"));
|
|
|
|
_assert = function _assert() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function _umi() {
|
|
const data = require("umi");
|
|
|
|
_umi = function _umi() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
|
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
|
|
const got = _umi().utils.got,
|
|
mkdirp = _umi().utils.mkdirp;
|
|
|
|
var _default = api => {
|
|
const getDataPath = dbPath => path().join(dbPath, 'dashboard.json');
|
|
|
|
const writeData = (dbPath, data = []) => {
|
|
const dbDataPath = getDataPath(dbPath);
|
|
fs().writeFileSync(dbDataPath, JSON.stringify(data, null, 2), 'utf-8');
|
|
};
|
|
|
|
const getData = /*#__PURE__*/function () {
|
|
var _ref = _asyncToGenerator(function* (dbPath) {
|
|
(0, _assert().default)(dbPath, `dbPath must be supplied, received: ${dbPath}.`);
|
|
|
|
if (!fs().existsSync(dbPath)) {
|
|
mkdirp.sync(dbPath);
|
|
}
|
|
|
|
const dbData = getDataPath(dbPath);
|
|
|
|
if (!fs().existsSync(dbData)) {
|
|
writeData(dbPath);
|
|
} // remove cache
|
|
|
|
|
|
delete require.cache[dbData];
|
|
let list = [];
|
|
|
|
try {
|
|
// eslint-disable-next-line import/no-dynamic-require
|
|
list = require(dbData);
|
|
} catch (e) {
|
|
console.error('dbData requrie error', e);
|
|
}
|
|
|
|
if (!Array.isArray(list)) {
|
|
// reset data into right structure
|
|
writeData(dbPath);
|
|
return []; // throw new Error(`dbData error ${JSON.stringify(list)}`);
|
|
}
|
|
|
|
return list || [];
|
|
});
|
|
|
|
return function getData(_x) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}();
|
|
|
|
api.onUISocket( /*#__PURE__*/function () {
|
|
var _ref2 = _asyncToGenerator(function* ({
|
|
action,
|
|
failure,
|
|
success,
|
|
send
|
|
}) {
|
|
const type = action.type,
|
|
_action$payload = action.payload,
|
|
payload = _action$payload === void 0 ? {} : _action$payload,
|
|
lang = action.lang;
|
|
|
|
switch (type) {
|
|
case 'org.umi.dashboard.card.list':
|
|
{
|
|
try {
|
|
const dbPath = payload.dbPath;
|
|
const list = yield getData(dbPath);
|
|
success(list);
|
|
} catch (e) {
|
|
failure(e);
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
case 'org.umi.dashboard.card.list.change':
|
|
{
|
|
try {
|
|
const dbPath = payload.dbPath,
|
|
key = payload.key,
|
|
enable = payload.enable;
|
|
const list = yield getData(dbPath); // [ { key: '', enable: false } ]
|
|
|
|
const newList = (0, _immer().default)(list, draft => {
|
|
const cardIndex = draft.findIndex(item => item.key === key);
|
|
const newCardData = {
|
|
key,
|
|
enable: !!enable
|
|
};
|
|
|
|
if (cardIndex > -1 && draft[cardIndex]) {
|
|
// delete
|
|
draft.splice(cardIndex, 1);
|
|
}
|
|
|
|
draft.push(newCardData);
|
|
return draft;
|
|
});
|
|
writeData(dbPath, newList);
|
|
success(newList);
|
|
} catch (e) {
|
|
failure(e);
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
default:
|
|
break;
|
|
}
|
|
});
|
|
|
|
return function (_x2) {
|
|
return _ref2.apply(this, arguments);
|
|
};
|
|
}());
|
|
api.addUIPlugin(() => require.resolve('../../../dist/dashboard.umd'));
|
|
};
|
|
|
|
exports.default = _default; |