mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 09:14:48 -04:00
@@ -71,6 +71,10 @@ public:
|
||||
{
|
||||
return newModule_;
|
||||
}
|
||||
inline bool isSupportTsHeader() const
|
||||
{
|
||||
return tsHeader_;
|
||||
}
|
||||
static void SetUseModule()
|
||||
{
|
||||
useModule_ = true;
|
||||
@@ -108,6 +112,7 @@ private:
|
||||
static bool useModule_;
|
||||
cJSON *root_;
|
||||
bool newModule_ = false;
|
||||
bool tsHeader_ = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ static std::set<std::string> g_resourceSet;
|
||||
static std::set<std::string> g_hapResourceSet;
|
||||
const static int8_t INVALID_ID = -1;
|
||||
const static int MIN_SUPPORT_NEW_MODULE_API_VERSION = 60000020;
|
||||
const static int MIN_SUPPORT_TS_HEADER_API_VERSION = 22;
|
||||
const static int API_VERSION_DIVISOR = 1000;
|
||||
|
||||
enum class IgnoreType {
|
||||
IGNORE_FILE,
|
||||
|
||||
@@ -86,9 +86,13 @@ uint32_t ConfigParser::Init()
|
||||
cJSON *appNode = cJSON_GetObjectItem(root_, "app");
|
||||
if (appNode && cJSON_IsObject(appNode)) {
|
||||
cJSON *minAPIVersionNode = cJSON_GetObjectItem(appNode, "minAPIVersion");
|
||||
if (minAPIVersionNode && minAPIVersionNode->valueint >= MIN_SUPPORT_NEW_MODULE_API_VERSION) {
|
||||
int version = minAPIVersionNode ? minAPIVersionNode->valueint : 0;
|
||||
if (version >= MIN_SUPPORT_NEW_MODULE_API_VERSION) {
|
||||
newModule_ = true;
|
||||
}
|
||||
if (version % API_VERSION_DIVISOR >= MIN_SUPPORT_TS_HEADER_API_VERSION) {
|
||||
tsHeader_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
cJSON *moduleNode = cJSON_GetObjectItem(root_, "module");
|
||||
|
||||
+10
-4
@@ -58,11 +58,17 @@ uint32_t Header::Create(HandleHeaderTail headerHandler, HandleBody bodyHandler,
|
||||
}
|
||||
|
||||
stringstream buffer;
|
||||
headerHandler(buffer);
|
||||
for (const auto &resourceId : resourceIds) {
|
||||
bodyHandler(buffer, resourceId);
|
||||
if (headerHandler) {
|
||||
headerHandler(buffer);
|
||||
}
|
||||
if (bodyHandler) {
|
||||
for (const auto &resourceId : resourceIds) {
|
||||
bodyHandler(buffer, resourceId);
|
||||
}
|
||||
}
|
||||
if (tailHandler) {
|
||||
tailHandler(buffer);
|
||||
}
|
||||
tailHandler(buffer);
|
||||
out << buffer.rdbuf();
|
||||
out.close();
|
||||
return RESTOOL_SUCCESS;
|
||||
|
||||
+13
-9
@@ -280,22 +280,26 @@ uint32_t ResourcePack::GenerateJsHeader(const std::string &headerPath) const
|
||||
uint32_t ResourcePack::GenerateTsHeader(const std::string &headerPath) const
|
||||
{
|
||||
Header tsHeader(headerPath);
|
||||
std::string moduleName = configJson_.GetModuleName();
|
||||
std::map<std::string, std::vector<std::pair<std::string, int64_t>>> typeNameIds;
|
||||
uint32_t result = tsHeader.Create([](stringstream &buffer) {
|
||||
Header::HandleHeaderTail handleHeader = [](stringstream &buffer) {
|
||||
buffer << Header::LICENSE_HEADER << "\n";
|
||||
buffer << "//@ts-noCheck" << "\n";
|
||||
}, [&typeNameIds](stringstream &buffer, const ResourceId& resourceId) {
|
||||
if (!ResourceUtil::IsHarResource(resourceId.id)) {
|
||||
};
|
||||
if (!configJson_.isSupportTsHeader()) {
|
||||
return tsHeader.Create(handleHeader, nullptr, nullptr);
|
||||
}
|
||||
std::string moduleName = configJson_.GetModuleName();
|
||||
std::map<std::string, std::vector<std::pair<std::string, int64_t>>> typeNameIds;
|
||||
uint32_t result = tsHeader.Create(handleHeader, [&typeNameIds](stringstream &buffer, const ResourceId& resource) {
|
||||
if (!ResourceUtil::IsHarResource(resource.id)) {
|
||||
return;
|
||||
}
|
||||
auto it = typeNameIds.find(resourceId.type);
|
||||
auto it = typeNameIds.find(resource.type);
|
||||
if (it != typeNameIds.end()) {
|
||||
it->second.emplace_back(make_pair(resourceId.name, resourceId.id));
|
||||
it->second.emplace_back(make_pair(resource.name, resource.id));
|
||||
} else {
|
||||
std::vector<std::pair<std::string, int64_t>> ids;
|
||||
ids.emplace_back(make_pair(resourceId.name, resourceId.id));
|
||||
typeNameIds.emplace(make_pair(resourceId.type, ids));
|
||||
ids.emplace_back(make_pair(resource.name, resource.id));
|
||||
typeNameIds.emplace(make_pair(resource.type, ids));
|
||||
}
|
||||
}, [&moduleName, &typeNameIds](stringstream &buffer) {
|
||||
std::string typesDeclare;
|
||||
|
||||
Reference in New Issue
Block a user