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.
102 lines
2.3 KiB
102 lines
2.3 KiB
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.appendBlockToContainer = void 0;
|
|
|
|
function _react() {
|
|
const data = _interopRequireDefault(require("react"));
|
|
|
|
_react = function _react() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function _fs() {
|
|
const data = require("fs");
|
|
|
|
_fs = function _fs() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function _path() {
|
|
const data = require("path");
|
|
|
|
_path = function _path() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function _utils() {
|
|
const data = require("@umijs/utils");
|
|
|
|
_utils = function _utils() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
var _insertComponent = _interopRequireDefault(require("./sdk/insertComponent"));
|
|
|
|
var _util = require("./util");
|
|
|
|
var _constants = require("./sdk/constants");
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
const debug = (0, _utils().createDebug)('umiui:block-sdk:appendBlockToContainer');
|
|
|
|
const appendBlockToContainer = ({
|
|
entryPath,
|
|
blockFolderName,
|
|
dryRun,
|
|
index
|
|
}) => {
|
|
debug('start to update the entry file for block(s) under the path...');
|
|
/**
|
|
* 获取地址
|
|
*/
|
|
|
|
const oldEntry = (0, _fs().readFileSync)(entryPath, 'utf-8');
|
|
debug(`insert component ${blockFolderName} with index ${index}`);
|
|
debug('entryPath', entryPath);
|
|
debug('blockFolderName', blockFolderName);
|
|
const blockPath = (0, _path().join)((0, _path().dirname)(entryPath), blockFolderName);
|
|
debug('blockPath', blockPath);
|
|
const absolutePath = (0, _util.findJS)({
|
|
base: blockPath,
|
|
fileNameWithoutExt: ''
|
|
}) || (0, _util.findJS)({
|
|
base: blockPath,
|
|
fileNameWithoutExt: 'index'
|
|
});
|
|
debug('absolutePath', absolutePath);
|
|
const blockContent = (0, _fs().readFileSync)(absolutePath, 'utf-8');
|
|
|
|
try {
|
|
const newEntry = (0, _insertComponent.default)(oldEntry, {
|
|
identifier: blockFolderName,
|
|
relativePath: `./${blockFolderName}`,
|
|
absolutePath,
|
|
isExtractBlock: blockContent.includes(_constants.INSERT_BLOCK_PLACEHOLDER) || blockContent.includes(_constants.UMI_UI_FLAG_PLACEHOLDER),
|
|
index
|
|
});
|
|
|
|
if (!dryRun) {
|
|
(0, _fs().writeFileSync)(entryPath, newEntry);
|
|
}
|
|
} catch (e) {
|
|
console.error(`Failed write block component: ${e}\n`);
|
|
}
|
|
};
|
|
|
|
exports.appendBlockToContainer = appendBlockToContainer; |