mirror of
https://github.com/msojocs/wx-compiler.git
synced 2025-07-19 00:00:04 +08:00
refactor: 使用napi重写
This commit is contained in:
parent
41370c6371
commit
5841b9c128
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -178,7 +178,7 @@ jobs:
|
||||
sudo apt install -y fuse
|
||||
wget -q https://github.com/TheAssassin/pyuploadtool/releases/download/continuous/pyuploadtool-x86_64.AppImage
|
||||
chmod +x pyuploadtool-x86_64.AppImage
|
||||
./pyuploadtool-x86_64.AppImage **build/wcc **build/wcsc
|
||||
./pyuploadtool-x86_64.AppImage **build/wcc **build/wcsc **build/wcc_module.node **build/wcsc_module.node
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
|
@ -7,6 +7,8 @@ module.exports = {
|
||||
// spec: "./test/spec/**/*.spec.ts",
|
||||
spec: [
|
||||
"./test/spec/**/*.spec.ts",
|
||||
// 'test/spec/wcc/module/module.spec.ts',
|
||||
// 'test/spec/issue/137/issue137.spec.ts',
|
||||
// 'test/spec/issue/129/issue129.spec.ts',
|
||||
// 'test/spec/issue/115/issue115.spec.ts',
|
||||
// 'test/spec/wcc/module/module.spec.ts',
|
||||
|
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -12,7 +12,7 @@
|
||||
"args": [
|
||||
"${workspaceFolder}/test/runner/nwjs/compiler.js",
|
||||
"wcsc",
|
||||
"${workspaceFolder}/test/spec/issue/129/data/example.json"
|
||||
"${workspaceFolder}/test/spec/issue/137/data/example.json"
|
||||
],
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
|
@ -3,10 +3,8 @@ project(wx_complier VERSION 0.1.0 LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
# message("before: ${CMAKE_CXX_FLAGS_DEBUG}")
|
||||
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1")
|
||||
# message("after: ${CMAKE_CXX_FLAGS_DEBUG}")
|
||||
set(TARGET_ARCH x64)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_REENTRANT")
|
||||
|
||||
add_executable(wcc
|
||||
src/wcc.cpp
|
||||
|
@ -1,7 +1,7 @@
|
||||
## 🌈 v0.1.4 / 2025-05-02
|
||||
## 🌈 v0.1.4 / 2025-05-01
|
||||
|
||||
🐞 Bug Fixes
|
||||
- 修正:Arch Linux崩溃
|
||||
- `WXSS::CSSTreeLib::CSSSyntaxTree::RenderCode`: Arch linux会崩溃.(数组访问越界)
|
||||
|
||||
## 🌈 v0.1.3 / 2025-02-17
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
version: "3"
|
||||
services:
|
||||
wx_compiler:
|
||||
image: jiyecafe/wechat-devtools-build:v3
|
||||
|
@ -1,5 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
npm install -g pnpm@8
|
||||
pnpm install
|
||||
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBC
|
||||
echo "----"
|
||||
strings /lib/x86_64-linux-gnu/libc.so.6 | grep GLIBC_
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
gcc --version
|
||||
g++ --version
|
||||
# cmake --verion
|
||||
|
11
package.json
11
package.json
@ -11,6 +11,17 @@
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bindings": "^1.5.0",
|
||||
"cmake-js": "^7.3.0",
|
||||
"node-addon-api": "^7.1.0",
|
||||
"node-api-headers": "^1.5.0"
|
||||
},
|
||||
"binary": {
|
||||
"napi_versions": [
|
||||
7
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.18.10",
|
||||
"@babel/core": "^7.18.13",
|
||||
|
1944
pnpm-lock.yaml
generated
1944
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,47 +3,65 @@ message("current dir: ${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
execute_process(
|
||||
COMMAND mkdir -p ${CMAKE_CURRENT_SOURCE_DIR}/cache;
|
||||
)
|
||||
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cache/nw-headers-v${NW_VERSION}.tar.gz")
|
||||
execute_process(
|
||||
COMMAND wget -c -O nw-headers-v${NW_VERSION}.tar.gz.tmp https://dl.nwjs.io/v${NW_VERSION}/nw-headers-v${NW_VERSION}.tar.gz;
|
||||
COMMAND mv nw-headers-v${NW_VERSION}.tar.gz.tmp nw-headers-v${NW_VERSION}.tar.gz;
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cache
|
||||
OUTPUT_VARIABLE CMAKE_JS_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
endif()
|
||||
execute_process(COMMAND rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/node WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/node")
|
||||
execute_process(COMMAND tar -zxf nw-headers-v${NW_VERSION}.tar.gz -C ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cache)
|
||||
endif()
|
||||
# if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/node-v${NW_VERSION}.lib")
|
||||
# execute_process(
|
||||
# COMMAND wget -c -O node-v${NW_VERSION}.lib.tmp https://dl.nwjs.io/v${NW_VERSION}/node.lib;
|
||||
# COMMAND mv node-v${NW_VERSION}.lib.tmp node-v${NW_VERSION}.lib;
|
||||
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib
|
||||
# OUTPUT_VARIABLE CMAKE_JS_VERSION
|
||||
# OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
# )
|
||||
# endif()
|
||||
# if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/nw-v${NW_VERSION}.lib")
|
||||
# execute_process(
|
||||
# COMMAND wget -c -O nw-v${NW_VERSION}.lib.tmp https://dl.nwjs.io/v${NW_VERSION}/nw.lib;
|
||||
# COMMAND mv nw-v${NW_VERSION}.lib.tmp nw-v${NW_VERSION}.lib;
|
||||
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib
|
||||
# OUTPUT_VARIABLE CMAKE_JS_VERSION
|
||||
# OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
# )
|
||||
# endif()
|
||||
|
||||
include_directories(node/src)
|
||||
include_directories(node/include/node)
|
||||
include_directories(node/deps/v8/include)
|
||||
include_directories(node/deps/uv/include)
|
||||
find_program(PNPM_EXECUTABLE pnpm)
|
||||
if(NOT PNPM_EXECUTABLE)
|
||||
message(FATAL_ERROR "pnpm not found!")
|
||||
endif()
|
||||
if(WIN32)
|
||||
set(PNPM_EXECUTABLE "${PNPM_EXECUTABLE}.CMD")
|
||||
endif()
|
||||
|
||||
message("CMAKE_CXX_FLAGS:${CMAKE_CXX_FLAGS}")
|
||||
message("获取 cmake-js 配置")
|
||||
message(${PROJECT_SOURCE_DIR})
|
||||
execute_process(COMMAND
|
||||
${PNPM_EXECUTABLE} --silent cmake-js --version
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE CMAKE_JS_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
execute_process(COMMAND
|
||||
${PNPM_EXECUTABLE} cmake-js print-cmakejs-src --arch ${TARGET_ARCH} --silent -l error
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE CMAKE_JS_SRC
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
message("获取 CMAKE_JS_SRC 配置: ${CMAKE_JS_SRC}")
|
||||
|
||||
message("PNPM_EXECUTABLE: " ${PNPM_EXECUTABLE})
|
||||
execute_process(COMMAND
|
||||
${PNPM_EXECUTABLE} cmake-js print-cmakejs-include --silent -l error
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE CMAKE_JS_INC
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
message("CMAKE_JS_INC:" ${CMAKE_JS_INC})
|
||||
foreach(item IN LISTS CMAKE_JS_INC)
|
||||
message("include: ${item}")
|
||||
include_directories(${item})
|
||||
endforeach()
|
||||
|
||||
message("获取 node-addon-api 配置")
|
||||
execute_process(COMMAND
|
||||
node -p "require('node-addon-api').include"
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE NODE_ADDON_API_DIR
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
message("node-addon-api 路径:${NODE_ADDON_API_DIR}")
|
||||
|
||||
message("CMAKE_JS_INC: " ${CMAKE_JS_INC})
|
||||
message("CMAKE_JS_SRC: " ${CMAKE_JS_SRC})
|
||||
message("CMAKE_JS_LIB: " ${CMAKE_JS_LIB})
|
||||
|
||||
include_directories(${CMAKE_JS_SRC})
|
||||
include_directories(${NODE_ADDON_API_DIR})
|
||||
|
||||
add_library(wcc_module
|
||||
SHARED
|
||||
./wcc.cpp
|
||||
./include/wcc.hh
|
||||
./config/wcc.hh
|
||||
./config/wcc.cc
|
||||
../include/wxml.h
|
||||
../include/night.h
|
||||
@ -85,11 +103,10 @@ add_library(wcc_module
|
||||
../utils/json.cpp
|
||||
../utils/string_utils.cpp
|
||||
../utils/file.cpp
|
||||
${CMAKE_JS_SRC}
|
||||
)
|
||||
|
||||
target_link_libraries(wcc_module PRIVATE rt pthread)
|
||||
set_target_properties(wcc_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
# DV8_COMPRESS_POINTERS: 缺少会导致IsString崩溃
|
||||
target_compile_options(wcc_module PRIVATE "-DNODE_GYP_MODULE_NAME=binding" "-DUSING_UV_SHARED=1" "-DUSING_V8_SHARED=1" "-DV8_DEPRECATION_WARNINGS=1" "-DV8_DEPRECATION_WARNINGS" "-DV8_REVERSE_JSARGS" "-D_GLIBCXX_USE_CXX11_ABI=1" "-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS" "-D_LARGEFILE_SOURCE" "-D_FILE_OFFSET_BITS=64" "-DV8_COMPRESS_POINTERS" "-DV8_31BIT_SMIS_ON_64BIT_ARCH" "-D__STDC_FORMAT_MACROS" "-DOPENSSL_NO_PINSHARED" "-DOPENSSL_THREADS" "-DOPENSSL_NO_ASM" "-DBUILDING_NODE_EXTENSION")
|
||||
set_target_properties(wcc_module PROPERTIES PREFIX "" SUFFIX ".node")
|
||||
# target_link_libraries(wcc_module ${CMAKE_CURRENT_SOURCE_DIR}/lib/nw-v${NW_VERSION}.lib)
|
||||
# target_link_libraries(wcc_module ${CMAKE_CURRENT_SOURCE_DIR}/lib/node-v${NW_VERSION}.lib)
|
||||
@ -98,6 +115,7 @@ set_target_properties(wcc_module PROPERTIES PREFIX "" SUFFIX ".node")
|
||||
add_library(wcsc_module
|
||||
SHARED
|
||||
./wcsc.cpp
|
||||
./config/wcsc.hh
|
||||
./config/wcsc.cc
|
||||
../wcsc/usage.cpp
|
||||
../wxa/wxa.cpp
|
||||
@ -119,8 +137,8 @@ add_library(wcsc_module
|
||||
../utils/json.cpp
|
||||
../utils/string_utils.cpp
|
||||
../utils/file.cpp
|
||||
${CMAKE_JS_SRC}
|
||||
)
|
||||
target_link_libraries(wcsc_module PRIVATE rt pthread)
|
||||
set_target_properties(wcsc_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
# DV8_COMPRESS_POINTERS: 缺少会导致IsString崩溃
|
||||
target_compile_options(wcsc_module PRIVATE "-DNODE_GYP_MODULE_NAME=binding" "-DUSING_UV_SHARED=1" "-DUSING_V8_SHARED=1" "-DV8_DEPRECATION_WARNINGS=1" "-DV8_DEPRECATION_WARNINGS" "-DV8_REVERSE_JSARGS" "-D_GLIBCXX_USE_CXX11_ABI=1" "-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS" "-D_LARGEFILE_SOURCE" "-D_FILE_OFFSET_BITS=64" "-DV8_COMPRESS_POINTERS" "-DV8_31BIT_SMIS_ON_64BIT_ARCH" "-D__STDC_FORMAT_MACROS" "-DOPENSSL_NO_PINSHARED" "-DOPENSSL_THREADS" "-DOPENSSL_NO_ASM" "-DBUILDING_NODE_EXTENSION")
|
||||
set_target_properties(wcsc_module PROPERTIES PREFIX "" SUFFIX ".node")
|
||||
|
@ -1,172 +1,145 @@
|
||||
#include "../include/wcc.hh"
|
||||
#include "./wcc.hh"
|
||||
#include "napi.h"
|
||||
|
||||
namespace wcc_options
|
||||
{
|
||||
using v8::Local;
|
||||
using v8::String;
|
||||
using v8::Value;
|
||||
|
||||
bool get_boolean_property(v8::Isolate *isolate, v8::Local<v8::Object> &src, const char *property_name, bool &out_value)
|
||||
bool parse_wcc_options(Napi::Env &env, Napi::Object &src, WCCOptions *result)
|
||||
{
|
||||
v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, property_name, v8::NewStringType::kNormal).ToLocalChecked();
|
||||
v8::Local<v8::Value> value;
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (src.Get("verbose").IsBoolean())
|
||||
{
|
||||
result->verbose = src.Get("verbose").As<Napi::Boolean>().Value();
|
||||
}
|
||||
|
||||
if (!src->Get(context, key).ToLocal(&value))
|
||||
if (src.Get("debug").IsBoolean())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
result->debug = src.Get("debug").As<Napi::Boolean>().Value();
|
||||
}
|
||||
if (value->IsUndefined())
|
||||
{
|
||||
out_value = false;
|
||||
return true;
|
||||
}
|
||||
if (!value->IsBoolean())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + "' property must be a boolean").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
out_value = value->BooleanValue(isolate);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get_string_property(v8::Isolate *isolate, v8::Local<v8::Object> &src, const char *property_name, std::string &out_value)
|
||||
{
|
||||
v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, property_name, v8::NewStringType::kNormal).ToLocalChecked();
|
||||
v8::Local<v8::Value> value;
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (src.Get("debugWXS").IsBoolean())
|
||||
{
|
||||
result->debugWXS = src.Get("debugWXS").As<Napi::Boolean>().Value();
|
||||
}
|
||||
|
||||
if (!src->Get(context, key).ToLocal(&value))
|
||||
if (src.Get("showNewTree").IsBoolean())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
result->showNewTree = src.Get("showNewTree").As<Napi::Boolean>().Value();
|
||||
}
|
||||
if (!value->IsString())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + "' property must be a string").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
v8::String::Utf8Value utf8Value(isolate, value);
|
||||
std::string str(*utf8Value, utf8Value.length());
|
||||
out_value = str;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get_vector_string_property(v8::Isolate *isolate, v8::Local<v8::Object> &src, const char *property_name, std::vector<std::string> &out_value)
|
||||
{
|
||||
v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, property_name, v8::NewStringType::kNormal).ToLocalChecked();
|
||||
v8::Local<v8::Value> value;
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (src.Get("isPlugin").IsBoolean())
|
||||
{
|
||||
result->isPlugin = src.Get("isPlugin").As<Napi::Boolean>().Value();
|
||||
}
|
||||
|
||||
if (!src->Get(context, key).ToLocal(&value))
|
||||
if (src.Get("addTestAttre").IsBoolean())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
result->addTestAttre = src.Get("addTestAttre").As<Napi::Boolean>().Value();
|
||||
}
|
||||
if (!value->IsArray())
|
||||
|
||||
if (src.Get("independent").IsBoolean())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + "' property must be a array").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
result->independent = src.Get("independent").As<Napi::Boolean>().Value();
|
||||
}
|
||||
auto arr = value.As<v8::Array>();
|
||||
for (int i=0; i < arr->Length(); i++)
|
||||
|
||||
if (src.Get("isCut").IsBoolean())
|
||||
{
|
||||
v8::Local<v8::Value> v;
|
||||
if (!arr->Get(context, i).ToLocal(&v))
|
||||
result->isCut = src.Get("isCut").As<Napi::Boolean>().Value();
|
||||
}
|
||||
|
||||
if (src.Get("lazyload").IsBoolean())
|
||||
{
|
||||
result->lazyload = src.Get("lazyload").As<Napi::Boolean>().Value();
|
||||
}
|
||||
|
||||
if (src.Get("genfuncname").IsString())
|
||||
{
|
||||
result->genfuncname = src.Get("genfuncname").As<Napi::String>().Utf8Value();
|
||||
}
|
||||
|
||||
if (src.Get("cwd").IsString())
|
||||
{
|
||||
result->cwd = src.Get("cwd").As<Napi::String>().Utf8Value();
|
||||
}
|
||||
|
||||
if (src.Get("wxmlCompileConfig").IsString())
|
||||
{
|
||||
result->wxmlCompileConfig = src.Get("wxmlCompileConfig").As<Napi::String>().Utf8Value();
|
||||
}
|
||||
|
||||
|
||||
if (src.Get("wxmlCompileConfigSplit").IsString())
|
||||
{
|
||||
result->wxmlCompileConfigSplit = src.Get("wxmlCompileConfigSplit").As<Napi::String>().Utf8Value();
|
||||
}
|
||||
|
||||
|
||||
if (src.Get("lazyloadConfig").IsString())
|
||||
{
|
||||
result->lazyloadConfig = src.Get("lazyloadConfig").As<Napi::String>().Utf8Value();
|
||||
}
|
||||
|
||||
|
||||
if (src.Get("files").IsArray())
|
||||
{
|
||||
Napi::Array arr = src.Get("files").As<Napi::Array>();
|
||||
for (size_t i = 0; i < arr.Length(); i++)
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
Napi::Value value = arr[i];
|
||||
if (value.IsString())
|
||||
{
|
||||
result->files.push_back(value.As<Napi::String>().Utf8Value());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Napi::Error::New(env, "files must be an array of strings");
|
||||
}
|
||||
}
|
||||
if (!v->IsString())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + std::string("[") + std::to_string(i) +"]' property must be a string").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
v8::String::Utf8Value utf8Value(isolate, v);
|
||||
std::string str(*utf8Value, utf8Value.length());
|
||||
out_value.emplace_back(str);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get_map_string_property(v8::Isolate *isolate, v8::Local<v8::Object> &src, const char *property_name, std::map<std::string, std::string> &out_value)
|
||||
{
|
||||
v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, property_name, v8::NewStringType::kNormal).ToLocalChecked();
|
||||
v8::Local<v8::Value> value;
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
if (!src->Get(context, key).ToLocal(&value))
|
||||
|
||||
if (src.Get("contents").IsArray())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
Napi::Array arr = src.Get("contents").As<Napi::Array>();
|
||||
for (size_t i = 0; i < arr.Length(); i++)
|
||||
{
|
||||
Napi::Value value = arr[i];
|
||||
if (value.IsString())
|
||||
{
|
||||
result->contents.push_back(value.As<Napi::String>().Utf8Value());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Napi::Error::New(env, "contents must be an array of strings");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!value->IsObject())
|
||||
|
||||
if (src.Get("replaceContent").IsObject())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + "' property must be a object").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
auto obj = value.As<v8::Object>();
|
||||
auto keys = obj->GetPropertyNames(context).ToLocalChecked();
|
||||
|
||||
for (int i = 0; i < keys->Length(); i++)
|
||||
{
|
||||
// key
|
||||
v8::Local<v8::Value> k;
|
||||
if (!keys->Get(context, i).ToLocal(&k))
|
||||
Napi::Object obj = src.Get("replaceContent").As<Napi::Object>();
|
||||
Napi::Array keys = obj.GetPropertyNames();
|
||||
for (size_t i = 0; i < keys.Length(); i++)
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
Napi::Value key = keys[i];
|
||||
if (key.IsString())
|
||||
{
|
||||
std::string keyStr = key.As<Napi::String>().Utf8Value();
|
||||
Napi::Value value = obj.Get(key);
|
||||
if (value.IsString())
|
||||
{
|
||||
result->replaceContent[keyStr] = value.As<Napi::String>().Utf8Value();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Napi::Error::New(env, "replaceContent must be a map of strings");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Napi::Error::New(env, "replaceContent must be a map of strings");
|
||||
}
|
||||
}
|
||||
if (!k->IsString())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + std::string("[") + std::to_string(i) +"]' property must be a string").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
|
||||
// value
|
||||
v8::Local<v8::Value> v;
|
||||
if (!obj->Get(context, k).ToLocal(&v))
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
if (!v->IsString())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + std::string("[") + std::to_string(i) +"]' property must be a string").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
v8::String::Utf8Value utf8Value(isolate, k);
|
||||
std::string kr(*utf8Value, utf8Value.length());
|
||||
v8::String::Utf8Value utf8Value2(isolate, v);
|
||||
std::string vr(*utf8Value2, utf8Value2.length());
|
||||
out_value.emplace(kr, vr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_wcc_options(v8::Isolate *isolate, v8::Local<v8::Object> &src, WCCOptions *result)
|
||||
{
|
||||
Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
bool ret = get_boolean_property(isolate, src, "verbose", result->verbose) &&
|
||||
get_boolean_property(isolate, src, "debug", result->debug) &&
|
||||
get_boolean_property(isolate, src, "debugWXS", result->debugWXS) &&
|
||||
get_boolean_property(isolate, src, "showNewTree", result->showNewTree) &&
|
||||
get_boolean_property(isolate, src, "isPlugin", result->isPlugin) &&
|
||||
get_boolean_property(isolate, src, "addTestAttre", result->addTestAttre) &&
|
||||
get_boolean_property(isolate, src, "independent", result->independent) &&
|
||||
get_boolean_property(isolate, src, "isCut", result->isCut) &&
|
||||
get_boolean_property(isolate, src, "lazyload", result->lazyload) &&
|
||||
get_string_property(isolate, src, "genfuncname", result->genfuncname) &&
|
||||
get_string_property(isolate, src, "cwd", result->cwd) &&
|
||||
get_string_property(isolate, src, "wxmlCompileConfig", result->wxmlCompileConfig) &&
|
||||
get_string_property(isolate, src, "wxmlCompileConfigSplit", result->wxmlCompileConfigSplit) &&
|
||||
get_string_property(isolate, src, "lazyloadConfig", result->lazyloadConfig) &&
|
||||
get_vector_string_property(isolate, src, "files", result->files) &&
|
||||
get_vector_string_property(isolate, src, "contents", result->contents) &&
|
||||
get_map_string_property(isolate, src, "replaceContent", result->replaceContent);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <node.h>
|
||||
#include <napi.h>
|
||||
|
||||
struct WCCOptions
|
||||
{
|
||||
@ -18,7 +18,7 @@ struct WCCOptions
|
||||
bool addTestAttre = false;
|
||||
bool independent = false;
|
||||
std::string genfuncname;
|
||||
bool isCut;
|
||||
bool isCut = false;
|
||||
std::string cwd;
|
||||
bool lazyload = false;
|
||||
std::string wxmlCompileConfig;
|
||||
@ -28,6 +28,6 @@ struct WCCOptions
|
||||
|
||||
namespace wcc_options
|
||||
{
|
||||
bool parse_wcc_options(v8::Isolate *isolate, v8::Local<v8::Object> &src, WCCOptions *result);
|
||||
bool parse_wcc_options(Napi::Env &env, Napi::Object &src, WCCOptions *result);
|
||||
}
|
||||
#endif
|
@ -1,179 +1,108 @@
|
||||
#include "../include/wcsc.hh"
|
||||
#include "v8.h"
|
||||
#include "./wcsc.hh"
|
||||
#include "napi.h"
|
||||
|
||||
namespace wcsc_options
|
||||
{
|
||||
using v8::Local;
|
||||
using v8::String;
|
||||
using v8::Value;
|
||||
|
||||
bool get_boolean_property(v8::Isolate *isolate, v8::Local<v8::Object> &src, const char *property_name, bool &out_value)
|
||||
bool parse_wcsc_options(Napi::Env &env, Napi::Object &src, WCSCOptions *result)
|
||||
{
|
||||
v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, property_name, v8::NewStringType::kNormal).ToLocalChecked();
|
||||
v8::Local<v8::Value> value;
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (src.Get("debug").IsBoolean())
|
||||
{
|
||||
result->debug = src.Get("debug").As<Napi::Boolean>().Value();
|
||||
}
|
||||
else {
|
||||
throw Napi::Error::New(env, "debug must be a boolean");
|
||||
}
|
||||
|
||||
if (!src->Get(context, key).ToLocal(&value))
|
||||
if (src.Get("lazyload").IsBoolean())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
result->lazyload = src.Get("lazyload").As<Napi::Boolean>().Value();
|
||||
}
|
||||
if (!value->IsBoolean())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + "' property must be a boolean").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
else {
|
||||
throw Napi::Error::New(env, "lazyload must be a boolean");
|
||||
}
|
||||
out_value = value->BooleanValue(isolate);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get_string_property(v8::Isolate *isolate, v8::Local<v8::Object> &src, const char *property_name, std::string &out_value)
|
||||
{
|
||||
v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, property_name, v8::NewStringType::kNormal).ToLocalChecked();
|
||||
v8::Local<v8::Value> value;
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (src.Get("cwd").IsString())
|
||||
{
|
||||
result->cwd = src.Get("cwd").As<Napi::String>().Utf8Value();
|
||||
}
|
||||
else {
|
||||
throw Napi::Error::New(env, "cwd must be a string");
|
||||
}
|
||||
|
||||
if (!src->Get(context, key).ToLocal(&value))
|
||||
if (src.Get("classPrefix").IsString())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
result->classPrefix = src.Get("classPrefix").As<Napi::String>().Utf8Value();
|
||||
}
|
||||
if (!value->IsString())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + "' property must be a string").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
else {
|
||||
throw Napi::Error::New(env, "classPrefix must be a string");
|
||||
}
|
||||
v8::String::Utf8Value utf8Value(isolate, value);
|
||||
std::string str(*utf8Value, utf8Value.length());
|
||||
out_value = str;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get_integer_property(v8::Isolate *isolate, v8::Local<v8::Object> &src, const char *property_name, int &out_value)
|
||||
{
|
||||
v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, property_name, v8::NewStringType::kNormal).ToLocalChecked();
|
||||
v8::Local<v8::Value> value;
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
if (!src->Get(context, key).ToLocal(&value))
|
||||
if (src.Get("pageCount").IsNumber())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
result->pageCount = src.Get("pageCount").As<Napi::Number>().Int32Value();
|
||||
}
|
||||
if (!value->IsInt32())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + "' property must be a int32").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
else {
|
||||
throw Napi::Error::New(env, "pageCount must be a number");
|
||||
}
|
||||
out_value = value->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get_vector_string_property(v8::Isolate *isolate, v8::Local<v8::Object> &src, const char *property_name, std::vector<std::string> &out_value)
|
||||
{
|
||||
v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, property_name, v8::NewStringType::kNormal).ToLocalChecked();
|
||||
v8::Local<v8::Value> value;
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
if (!src->Get(context, key).ToLocal(&value))
|
||||
if (src.Get("files").IsArray())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
if (!value->IsArray())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + "' property must be a array").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
auto arr = value.As<v8::Array>();
|
||||
for (int i=0; i < arr->Length(); i++)
|
||||
{
|
||||
v8::Local<v8::Value> v;
|
||||
if (!arr->Get(context, i).ToLocal(&v))
|
||||
Napi::Array arr = src.Get("files").As<Napi::Array>();
|
||||
for (size_t i = 0; i < arr.Length(); i++)
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
Napi::Value value = arr[i];
|
||||
if (value.IsString())
|
||||
{
|
||||
result->files.push_back(value.As<Napi::String>().Utf8Value());
|
||||
}
|
||||
else {
|
||||
throw Napi::Error::New(env, "files must be an array of strings");
|
||||
}
|
||||
}
|
||||
if (!v->IsString())
|
||||
}
|
||||
else {
|
||||
throw Napi::Error::New(env, "files must be an array");
|
||||
}
|
||||
|
||||
if (src.Get("contents").IsArray())
|
||||
{
|
||||
Napi::Array arr = src.Get("contents").As<Napi::Array>();
|
||||
for (size_t i = 0; i < arr.Length(); i++)
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + std::string("[") + std::to_string(i) +"]' property must be a string").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
Napi::Value value = arr[i];
|
||||
if (value.IsString())
|
||||
{
|
||||
result->contents.push_back(value.As<Napi::String>().Utf8Value());
|
||||
}
|
||||
else {
|
||||
throw Napi::Error::New(env, "contents must be an array of strings");
|
||||
}
|
||||
}
|
||||
v8::String::Utf8Value utf8Value(isolate, v);
|
||||
std::string str(*utf8Value, utf8Value.length());
|
||||
out_value.emplace_back(str);
|
||||
}
|
||||
else {
|
||||
throw Napi::Error::New(env, "contents must be an array");
|
||||
}
|
||||
|
||||
if (src.Get("replaceContent").IsObject())
|
||||
{
|
||||
Napi::Object obj = src.Get("replaceContent").As<Napi::Object>();
|
||||
Napi::Array keys = obj.GetPropertyNames();
|
||||
for (size_t i = 0; i < keys.Length(); i++)
|
||||
{
|
||||
Napi::Value k = keys[i];
|
||||
std::string key = k.As<Napi::String>().Utf8Value();
|
||||
if (obj.Get(key).IsString())
|
||||
{
|
||||
result->replaceContent[key] = obj.Get(key).As<Napi::String>().Utf8Value();
|
||||
}
|
||||
else {
|
||||
throw Napi::Error::New(env, "replaceContent must be an object of strings");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw Napi::Error::New(env, "replaceContent must be an object");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get_map_string_property(v8::Isolate *isolate, v8::Local<v8::Object> &src, const char *property_name, std::map<std::string, std::string> &out_value)
|
||||
{
|
||||
v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, property_name, v8::NewStringType::kNormal).ToLocalChecked();
|
||||
v8::Local<v8::Value> value;
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
if (!src->Get(context, key).ToLocal(&value))
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
if (!value->IsObject())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + "' property must be a object").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
auto obj = value.As<v8::Object>();
|
||||
auto keys = obj->GetPropertyNames(context).ToLocalChecked();
|
||||
|
||||
for (int i = 0; i < keys->Length(); i++)
|
||||
{
|
||||
// key
|
||||
v8::Local<v8::Value> k;
|
||||
if (!keys->Get(context, i).ToLocal(&k))
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
if (!k->IsString())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + std::string("[") + std::to_string(i) +"]' property must be a string").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
|
||||
// value
|
||||
v8::Local<v8::Value> v;
|
||||
if (!obj->Get(context, k).ToLocal(&v))
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
if (!v->IsString())
|
||||
{
|
||||
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + std::string("[") + std::to_string(i) +"]' property must be a string").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
|
||||
return false;
|
||||
}
|
||||
v8::String::Utf8Value utf8Value(isolate, k);
|
||||
std::string kr(*utf8Value, utf8Value.length());
|
||||
v8::String::Utf8Value utf8Value2(isolate, v);
|
||||
std::string vr(*utf8Value2, utf8Value2.length());
|
||||
out_value.emplace(kr, vr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_wcsc_options(v8::Isolate *isolate, v8::Local<v8::Object> &src, WCSCOptions *result)
|
||||
{
|
||||
Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
bool ret = get_boolean_property(isolate, src, "debug", result->debug) &&
|
||||
get_boolean_property(isolate, src, "lazyload", result->lazyload) &&
|
||||
get_string_property(isolate, src, "cwd", result->cwd) &&
|
||||
get_string_property(isolate, src, "classPrefix", result->classPrefix) &&
|
||||
get_integer_property(isolate, src, "pageCount", result->pageCount) &&
|
||||
get_vector_string_property(isolate, src, "files", result->files) &&
|
||||
get_vector_string_property(isolate, src, "contents", result->contents) &&
|
||||
get_map_string_property(isolate, src, "replaceContent", result->replaceContent);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <node.h>
|
||||
#include <napi.h>
|
||||
|
||||
struct WCSCOptions
|
||||
{
|
||||
@ -14,11 +14,11 @@ struct WCSCOptions
|
||||
std::string cwd;
|
||||
bool debug = false;
|
||||
std::string classPrefix;
|
||||
bool lazyload;
|
||||
bool lazyload = false;
|
||||
};
|
||||
|
||||
namespace wcsc_options
|
||||
{
|
||||
bool parse_wcsc_options(v8::Isolate *isolate, v8::Local<v8::Object> &src, WCSCOptions *result);
|
||||
bool parse_wcsc_options(Napi::Env &env, Napi::Object &src, WCSCOptions *result);
|
||||
}
|
||||
#endif
|
@ -1,35 +1,22 @@
|
||||
// hello.cc
|
||||
#include "./include/wcc.hh"
|
||||
#include "./config/wcc.hh"
|
||||
#include "../include/file.h"
|
||||
#include "../include/night.h"
|
||||
#include "../include/string_utils.h"
|
||||
#include "../include/wxml.h"
|
||||
#include "v8.h"
|
||||
#include "napi.h"
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <exception>
|
||||
#include <node.h>
|
||||
#include <string>
|
||||
|
||||
namespace wx_compiler {
|
||||
|
||||
using v8::Function;
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::FunctionTemplate;
|
||||
using v8::Isolate;
|
||||
using v8::Local;
|
||||
using v8::NewStringType;
|
||||
using v8::Object;
|
||||
using v8::String;
|
||||
using v8::Value;
|
||||
|
||||
using std::map;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
int compile(Isolate *isolate, WCCOptions &options, Local<Value> &result,
|
||||
std::string &errMsg) {
|
||||
try {
|
||||
Napi::Value compile(Napi::Env &env, WCCOptions &options) {
|
||||
int mark = 0;
|
||||
if (options.debug) {
|
||||
mark |= 2u;
|
||||
@ -41,7 +28,7 @@ int compile(Isolate *isolate, WCCOptions &options, Local<Value> &result,
|
||||
std::map<std::string, std::string> wxsMap;
|
||||
for (int i = 0; i < options.files.size(); i++) {
|
||||
auto file = options.files[i];
|
||||
fileContentMap[file] = options.contents[i];
|
||||
fileContentMap[file] = options.contents[i];
|
||||
if (file.find(".wxs") != std::string::npos) {
|
||||
wxsMap[file] = options.contents[i];
|
||||
}
|
||||
@ -90,8 +77,7 @@ int compile(Isolate *isolate, WCCOptions &options, Local<Value> &result,
|
||||
std::string v146;
|
||||
if ( night::compile_ns_no_wrapper(v152, v156, 1, v146, 0) )
|
||||
{
|
||||
errMsg = "Error: " + v146 + "\n";
|
||||
return -2;
|
||||
throw Napi::Error::New(env, "Error: " + v146 + "\n");
|
||||
}
|
||||
auto v31 = snprintf(0, 0, WXML::GlassEaselWxs::sWrapper.c_str(),
|
||||
v146.c_str()) + 1; char *v32 = (char *)operator new[](v31);
|
||||
@ -121,7 +107,7 @@ int compile(Isolate *isolate, WCCOptions &options, Local<Value> &result,
|
||||
map<string, vector<string>> dependencyListMap;
|
||||
map<string, string> mapData1;
|
||||
const char off_5403C3[] = {'s', '\0', 'e', '\0'};
|
||||
|
||||
std::string errMsg;
|
||||
compilerResult = WXML::Compiler::CompileLazy(
|
||||
fileContentMap, errMsg, outputContentMap,
|
||||
outputFuncMap, // map<string, string>
|
||||
@ -202,61 +188,38 @@ int compile(Isolate *isolate, WCCOptions &options, Local<Value> &result,
|
||||
}
|
||||
std::string v140 = dep.str();
|
||||
outputContentMap["__COMMON__"].append(v140);
|
||||
if (!compilerResult) {
|
||||
|
||||
v8::Local<v8::Object> funcContent = v8::Object::New(isolate);
|
||||
for (auto content : outputContentMap) {
|
||||
funcContent
|
||||
->Set(isolate->GetCurrentContext(),
|
||||
String::NewFromUtf8(isolate, content.first.c_str(),
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
String::NewFromUtf8(isolate, content.second.c_str(),
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked())
|
||||
.Check();
|
||||
}
|
||||
v8::Local<v8::Object> funcName = v8::Object::New(isolate);
|
||||
for (auto func : outputFuncMap) {
|
||||
funcName
|
||||
->Set(isolate->GetCurrentContext(),
|
||||
String::NewFromUtf8(isolate, func.first.c_str(),
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
String::NewFromUtf8(isolate, func.second.c_str(),
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked())
|
||||
.Check();
|
||||
}
|
||||
|
||||
// 你可以在这里设置对象的属性和方法
|
||||
|
||||
// 创建一个实例
|
||||
v8::Local<v8::Object> object_instance = v8::Object::New(isolate);
|
||||
auto _ = object_instance->Set(
|
||||
isolate->GetCurrentContext(),
|
||||
String::NewFromUtf8(isolate, "generateFunctionName",
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
funcName);
|
||||
_ = object_instance->Set(isolate->GetCurrentContext(),
|
||||
String::NewFromUtf8(isolate,
|
||||
"generateFunctionContent",
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
funcContent);
|
||||
|
||||
result = object_instance;
|
||||
if (compilerResult) {
|
||||
throw Napi::Error::New(env, "Error: " + errMsg + "\n");
|
||||
}
|
||||
return compilerResult;
|
||||
|
||||
// Create return objects using proper N-API object creation
|
||||
auto result = Napi::Object::New(env);
|
||||
|
||||
auto funcContent = Napi::Object::New(env);
|
||||
for (auto content : outputContentMap) {
|
||||
funcContent.Set(Napi::String::New(env, content.first),
|
||||
Napi::String::New(env, content.second));
|
||||
}
|
||||
|
||||
auto funcName = Napi::Object::New(env);
|
||||
for (auto func : outputFuncMap) {
|
||||
funcName.Set(Napi::String::New(env, func.first),
|
||||
Napi::String::New(env, func.second));
|
||||
}
|
||||
|
||||
// Set properties on the result object
|
||||
result.Set("generateFunctionName", funcName);
|
||||
result.Set("generateFunctionContent", funcContent);
|
||||
|
||||
return result;
|
||||
} else {
|
||||
// 普通
|
||||
|
||||
int compilerResult = 0;
|
||||
std::map<std::string, std::string> v105;
|
||||
map<string, vector<string>> componentListMap;
|
||||
std::string r;
|
||||
compilerResult =
|
||||
std::string errMsg;
|
||||
int compilerResult =
|
||||
WXML::Compiler::Compile(fileContentMap, // a2
|
||||
errMsg, // a3
|
||||
r, // a4
|
||||
@ -276,98 +239,56 @@ int compile(Isolate *isolate, WCCOptions &options, Local<Value> &result,
|
||||
"boxofchocolate", // "boxofchocolate"
|
||||
"$gdwx", // "$gdwx"
|
||||
"f_"); // "f_"
|
||||
result = String::NewFromUtf8(isolate, r.c_str(), NewStringType::kNormal)
|
||||
.ToLocalChecked();
|
||||
return compilerResult;
|
||||
if (compilerResult) {
|
||||
// error
|
||||
throw Napi::Error::New(env, "Error: " + errMsg + "\n");
|
||||
}
|
||||
return Napi::String::New(env, r);
|
||||
}
|
||||
} catch (std::string& err) {
|
||||
fprintf(stderr, "Error: %s", err.c_str());
|
||||
errMsg = err;
|
||||
return 1;
|
||||
} catch (WXML::DOMLib::ParseException& err) {
|
||||
fprintf(stderr, "Error: %s", err.what());
|
||||
errMsg = err.what();
|
||||
return 1;
|
||||
} catch (std::exception& err) {
|
||||
fprintf(stderr, "Error: %s", err.what());
|
||||
errMsg = err.what();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wcc(const FunctionCallbackInfo<Value> &args) {
|
||||
Isolate *isolate = args.GetIsolate();
|
||||
v8::HandleScope scope(isolate); // Ensure we have a proper handle scope.
|
||||
Napi::Value wcc(const Napi::CallbackInfo &info) {
|
||||
auto env = info.Env();
|
||||
|
||||
// Check if the first argument is an object.
|
||||
if (args.Length() < 1 || !args[0]->IsObject()) {
|
||||
isolate->ThrowException(String::NewFromUtf8(isolate,
|
||||
"Argument must be an object",
|
||||
NewStringType::kNormal)
|
||||
.ToLocalChecked());
|
||||
return;
|
||||
if (info.Length() < 1 || !info[0].IsObject()) {
|
||||
throw Napi::Error::New(env, "Argument must be an object");
|
||||
}
|
||||
|
||||
// Cast the first argument to an Object.
|
||||
Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
Local<Object> obj = args[0]->ToObject(context).ToLocalChecked();
|
||||
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
WCCOptions options;
|
||||
if (!wcc_options::parse_wcc_options(isolate, obj, &options)) {
|
||||
// 选项解析失败
|
||||
return;
|
||||
wcc_options::parse_wcc_options(env, obj, &options);
|
||||
|
||||
try {
|
||||
auto result = Napi::Object::New(env);
|
||||
return compile(env, options);
|
||||
} catch (std::string& err) {
|
||||
fprintf(stderr, "Error: %s", err.c_str());
|
||||
throw Napi::Error::New(env, err);
|
||||
} catch (WXML::DOMLib::ParseException& err) {
|
||||
fprintf(stderr, "Error: %s", err.what());
|
||||
throw Napi::Error::New(env, err.what());
|
||||
} catch (std::exception& err) {
|
||||
fprintf(stderr, "Error: %s", err.what());
|
||||
throw Napi::Error::New(env, err.what());
|
||||
}
|
||||
|
||||
Local<Value> result;
|
||||
std::string errMsg;
|
||||
int code = compile(isolate, options, result, errMsg);
|
||||
|
||||
// Convert the "msg" property to a C++ string and return it.
|
||||
if (code) {
|
||||
// error
|
||||
// args.GetReturnValue().Set(
|
||||
// String::NewFromUtf8(isolate, errMsg.c_str(), NewStringType::kNormal)
|
||||
// .ToLocalChecked());
|
||||
isolate->ThrowException(String::NewFromUtf8(isolate,
|
||||
errMsg.c_str(),
|
||||
NewStringType::kNormal)
|
||||
.ToLocalChecked());
|
||||
} else {
|
||||
// ok
|
||||
args.GetReturnValue().Set(result);
|
||||
catch (...) {
|
||||
fprintf(stderr, "Error: Unknown error");
|
||||
throw Napi::Error::New(env, "Unknown error");
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize(Local<Object> exports, Local<Object> module) {
|
||||
|
||||
Isolate *isolate = exports->GetIsolate();
|
||||
auto context = isolate->GetCurrentContext();
|
||||
static Napi::Object Initialize(Napi::Env env, Napi::Object exports) {
|
||||
|
||||
std::string versionInfo;
|
||||
WXML::Compiler::GetVersionInfo(versionInfo, "global");
|
||||
|
||||
// Set the module.exports to be a function
|
||||
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, wcc);
|
||||
Local<Function> fn = tpl->GetFunction(context).ToLocalChecked();
|
||||
|
||||
auto func = Napi::Function::New(env, wcc);
|
||||
// Set the 'version' property on the function
|
||||
fn->Set(context,
|
||||
String::NewFromUtf8(isolate, "version", NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
String::NewFromUtf8(isolate, versionInfo.c_str(),
|
||||
NewStringType::kNormal)
|
||||
.ToLocalChecked())
|
||||
.Check();
|
||||
exports.Set("version", Napi::String::New(env, versionInfo));
|
||||
|
||||
module
|
||||
->Set(context,
|
||||
String::NewFromUtf8(isolate, "exports", NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
fn)
|
||||
.Check();
|
||||
return func;
|
||||
}
|
||||
|
||||
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
|
||||
NODE_API_MODULE(WCC_MODULE, Initialize)
|
||||
|
||||
} // namespace wx_compiler
|
@ -1,36 +1,25 @@
|
||||
// hello.cc
|
||||
#include "./include/wcsc.hh"
|
||||
#include "./config/wcsc.hh"
|
||||
#include "../include/file.h"
|
||||
#include "../include/string_utils.h"
|
||||
#include "../include/wxss.h"
|
||||
#include "../include/wxml.h"
|
||||
#include "v8.h"
|
||||
#include "napi.h"
|
||||
#include <algorithm>
|
||||
#include <node.h>
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace wx_compiler {
|
||||
|
||||
using v8::Function;
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::FunctionTemplate;
|
||||
using v8::Isolate;
|
||||
using v8::Local;
|
||||
using v8::NewStringType;
|
||||
using v8::Object;
|
||||
using v8::String;
|
||||
using v8::Value;
|
||||
|
||||
using std::map;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
int compile(Isolate *isolate, WCSCOptions &options, Local<Value> &result,
|
||||
std::string &errMsg) {
|
||||
Napi::Value compile(const Napi::Env &env, WCSCOptions &options) {
|
||||
/**
|
||||
* 文件内容map filename -> fileContent
|
||||
*/
|
||||
* 文件内容map filename -> fileContent
|
||||
*/
|
||||
std::map<std::string, std::string> v77;
|
||||
for (int i=0; i<options.files.size(); i++) {
|
||||
v77[options.files[i]] = options.contents[i];
|
||||
@ -41,7 +30,7 @@ int compile(Isolate *isolate, WCSCOptions &options, Local<Value> &result,
|
||||
for (int i=0; i<options.pageCount; i++) {
|
||||
v72.push_back(options.files[i]);
|
||||
}
|
||||
|
||||
std::string errMsg;
|
||||
if (options.lazyload) {
|
||||
// 懒加载
|
||||
|
||||
@ -58,6 +47,7 @@ int compile(Isolate *isolate, WCSCOptions &options, Local<Value> &result,
|
||||
int ret = lt.GetCommHead(v72, v94, true, v76);
|
||||
if (ret) {
|
||||
fprintf(stderr, "ERR: GetCommHead ret %d", ret);
|
||||
throw Napi::Error::New(env, "ERR: GetCommHead ret " + std::to_string(ret));
|
||||
}
|
||||
for (int i = 0; i < v72.size(); i++) {
|
||||
std::string v98;
|
||||
@ -69,131 +59,88 @@ int compile(Isolate *isolate, WCSCOptions &options, Local<Value> &result,
|
||||
}
|
||||
v92.emplace(cur, v98);
|
||||
}
|
||||
v8::Local<v8::Object> pageWxss = v8::Object::New(isolate);
|
||||
for (auto func : v92) {
|
||||
pageWxss
|
||||
->Set(isolate->GetCurrentContext(),
|
||||
String::NewFromUtf8(isolate, func.first.c_str(),
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
String::NewFromUtf8(isolate, func.second.c_str(),
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked())
|
||||
.Check();
|
||||
|
||||
// Create stable N-API objects for return
|
||||
auto result = Napi::Object::New(env);
|
||||
auto pageWxss = Napi::Object::New(env);
|
||||
|
||||
// Add properties to the pageWxss object
|
||||
for (auto const& pair : v92) {
|
||||
pageWxss.Set(
|
||||
Napi::String::New(env, pair.first),
|
||||
Napi::String::New(env, pair.second)
|
||||
);
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> object_instance = v8::Object::New(isolate);
|
||||
auto _ = object_instance->Set(isolate->GetCurrentContext(),
|
||||
String::NewFromUtf8(isolate, "common",
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
String::NewFromUtf8(isolate, v94.c_str(),
|
||||
v8::NewStringType::kNormal).ToLocalChecked());
|
||||
_ = object_instance->Set(isolate->GetCurrentContext(),
|
||||
String::NewFromUtf8(isolate,
|
||||
"pageWxss",
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
pageWxss);
|
||||
result = object_instance;
|
||||
|
||||
// Set the common and pageWxss properties on the result object
|
||||
result.Set("common", Napi::String::New(env, v94));
|
||||
result.Set("pageWxss", pageWxss);
|
||||
|
||||
if (ret) {
|
||||
fprintf(stderr, "ERR: %s\nerror file count: %d\n", "", 0);
|
||||
return 1;
|
||||
throw Napi::Error::New(env, "ERR: \nerror file count: " + std::to_string(0));
|
||||
}
|
||||
// main - 25 - 9
|
||||
return 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
std::string ret = "ERR: wxss GetCompiledResult: " + v96 + ", error file count: " + std::to_string(lt.offset_4) + ", ret " + std::to_string(lt.offset_0);
|
||||
auto r = String::NewFromUtf8(isolate, ret.c_str(),
|
||||
v8::NewStringType::kNormal)
|
||||
.ToLocalChecked();
|
||||
fprintf(stderr,
|
||||
"ERR: wxss GetCompiledResult: %s, error file count: %d, ret %d",
|
||||
v96.data(), lt.offset_4, lt.offset_0);
|
||||
return 1;
|
||||
throw Napi::Error::New(env, ret);
|
||||
} else {
|
||||
// 普通
|
||||
std::string v88;
|
||||
int ret = WXSS::NewLintAndParseCSSList(v77, v72, v88, errMsg, 0, options.debug, v75, v76);
|
||||
if (ret)
|
||||
{
|
||||
return 1;
|
||||
if (ret) {
|
||||
throw Napi::Error::New(env, "ERR: wxss GetCompiledResult: " + errMsg + ", error file count: " + std::to_string(ret));
|
||||
}
|
||||
result = String::NewFromUtf8(isolate, v88.c_str(), NewStringType::kNormal).ToLocalChecked();
|
||||
|
||||
// Create a String object with proper lifetime
|
||||
return Napi::String::New(env, v88);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wcc(const FunctionCallbackInfo<Value> &args) {
|
||||
Isolate *isolate = args.GetIsolate();
|
||||
v8::HandleScope scope(isolate); // Ensure we have a proper handle scope.
|
||||
Napi::Value wcsc(const Napi::CallbackInfo &info) {
|
||||
auto env = info.Env();
|
||||
|
||||
// Check if the first argument is an object.
|
||||
if (args.Length() < 1 || !args[0]->IsObject()) {
|
||||
isolate->ThrowException(String::NewFromUtf8(isolate,
|
||||
"Argument must be an object",
|
||||
NewStringType::kNormal)
|
||||
.ToLocalChecked());
|
||||
return;
|
||||
if (info.Length() < 1 || !info[0].IsObject()) {
|
||||
throw Napi::Error::New(env, Napi::String::New(env, "Argument must be an object"));
|
||||
}
|
||||
|
||||
// Cast the first argument to an Object.
|
||||
Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
Local<Object> obj = args[0]->ToObject(context).ToLocalChecked();
|
||||
auto obj = info[0].As<Napi::Object>();
|
||||
|
||||
WCSCOptions options;
|
||||
if (!wcsc_options::parse_wcsc_options(isolate, obj, &options)) {
|
||||
// 选项解析失败
|
||||
return;
|
||||
try {
|
||||
wcsc_options::parse_wcsc_options(env, obj, &options);
|
||||
Napi::Object result;
|
||||
std::string errMsg;
|
||||
return compile(env, options);
|
||||
}
|
||||
catch (std::string& err) {
|
||||
fprintf(stderr, "Error: %s", err.c_str());
|
||||
throw Napi::Error::New(env, err);
|
||||
}catch (std::runtime_error &err) {
|
||||
fprintf(stderr, "Runtime error: %s",err.what());
|
||||
throw Napi::Error::New(env, err.what());
|
||||
} catch (std::exception& err) {
|
||||
fprintf(stderr, "Exception: %s", err.what());
|
||||
throw Napi::Error::New(env, err.what());
|
||||
}
|
||||
catch (...) {
|
||||
fprintf(stderr, "Error: Unknown error");
|
||||
throw Napi::Error::New(env, "Unknown error");
|
||||
}
|
||||
|
||||
Local<Value> result;
|
||||
std::string errMsg;
|
||||
int code = compile(isolate, options, result, errMsg);
|
||||
|
||||
// Convert the "msg" property to a C++ string and return it.
|
||||
if (code) {
|
||||
// error
|
||||
args.GetReturnValue().Set(
|
||||
String::NewFromUtf8(isolate, errMsg.c_str(), NewStringType::kNormal)
|
||||
.ToLocalChecked());
|
||||
} else {
|
||||
// ok
|
||||
args.GetReturnValue().Set(result);
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize(Local<Object> exports, Local<Object> module) {
|
||||
static Napi::Object Initialize(Napi::Env env, Napi::Object exports) {
|
||||
|
||||
Isolate *isolate = exports->GetIsolate();
|
||||
auto context = isolate->GetCurrentContext();
|
||||
|
||||
std::string versionInfo;
|
||||
// TODO
|
||||
// WXML::Compiler::GetVersionInfo(versionInfo, "global");
|
||||
|
||||
// Set the module.exports to be a function
|
||||
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, wcc);
|
||||
Local<Function> fn = tpl->GetFunction(context).ToLocalChecked();
|
||||
|
||||
// Set the 'version' property on the function
|
||||
fn->Set(context,
|
||||
String::NewFromUtf8(isolate, "version", NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
String::NewFromUtf8(isolate, versionInfo.c_str(),
|
||||
NewStringType::kNormal)
|
||||
.ToLocalChecked())
|
||||
.Check();
|
||||
|
||||
module
|
||||
->Set(context,
|
||||
String::NewFromUtf8(isolate, "exports", NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
fn)
|
||||
.Check();
|
||||
return Napi::Function::New(env, wcsc);
|
||||
}
|
||||
|
||||
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
|
||||
NODE_API_MODULE(WCSC_MODULE, Initialize)
|
||||
|
||||
} // namespace wx_compiler
|
@ -48,8 +48,6 @@ const wcscNative = (optionsPath: string, projectPath: string, outputPath: string
|
||||
}
|
||||
resolve(r);
|
||||
} else {
|
||||
// process.stderr.write(Buffer.concat(errData).toString());
|
||||
// process.stderr.write(Buffer.concat(spwanData).toString());
|
||||
const err = Buffer.concat(errData).toString()
|
||||
process.stderr.write(err);
|
||||
const r: CompilerResult = {
|
||||
|
@ -8,13 +8,17 @@ const optionsData = fs.readFileSync(p).toString();
|
||||
const options = JSON.parse(optionsData);
|
||||
|
||||
(async () => {
|
||||
const result = await compiler[type](options);
|
||||
console.log('---------------result------------------')
|
||||
if (typeof result === "string") {
|
||||
process.stdout.write(result);
|
||||
process.exitCode = 1
|
||||
process.exit(1)
|
||||
} else {
|
||||
process.stdout.write(JSON.stringify(result));
|
||||
try {
|
||||
const result = await compiler[type](options);
|
||||
console.log('---------------result------------------')
|
||||
if (typeof result === "string") {
|
||||
process.stdout.write(result);
|
||||
process.exitCode = 1
|
||||
process.exit(1)
|
||||
} else {
|
||||
process.stdout.write(JSON.stringify(result));
|
||||
}
|
||||
}catch (err) {
|
||||
// console.error('conpile.js error ->' + err)
|
||||
}
|
||||
})();
|
||||
|
29
test/spec/issue/137/data/example.json
Normal file
29
test/spec/issue/137/data/example.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"files": [
|
||||
"./pages/index/index.wxss",
|
||||
"./pages/logs/logs.wxss",
|
||||
"./components/navigation-bar/navigation-bar.wxss",
|
||||
"./app.wxss"
|
||||
],
|
||||
"contents": [
|
||||
"/**index.wxss**/\n:root\npage {\n height: 100vh;\n display: flex;\n flex-direction: column;\n}\n\n.scrollarea {\n flex: 1;\n overflow-y: hidden;\n}\n\n.userinfo {\n display: flex;\n flex-direction: column;\n align-items: center;\n color: #aaa;\n width: 80%;\n}\n\n.userinfo-avatar {\n overflow: hidden;\n width: 128rpx;\n height: 128rpx;\n margin: 20rpx;\n border-radius: 50%;\n}\n\n.usermotto {\n margin-top: 200px;\n}\n\n.avatar-wrapper {\n padding: 0;\n width: 56px !important;\n border-radius: 8px;\n margin-top: 40px;\n margin-bottom: 40px;\n}\n\n.avatar {\n display: block;\n width: 56px;\n height: 56px;\n}\n\n.nickname-wrapper {\n display: flex;\n width: 100%;\n padding: 16px;\n box-sizing: border-box;\n border-top: .5px solid rgba(0, 0, 0, 0.1);\n border-bottom: .5px solid rgba(0, 0, 0, 0.1);\n color: black;\n}\n\n.nickname-label {\n width: 105px;\n}\n\n.nickname-input {\n flex: 1;\n}\n",
|
||||
"page {\n height: 100vh;\n display: flex;\n flex-direction: column;\n}\n.scrollarea {\n flex: 1;\n overflow-y: hidden;\n}\n.log-item {\n margin-top: 20rpx;\n text-align: center;\n}\n.log-item:last-child {\n padding-bottom: env(safe-area-inset-bottom);\n}\n",
|
||||
".weui-navigation-bar {\n --weui-FG-0:rgba(0,0,0,.9);\n --height: 44px;\n --left: 16px;\n}\n.weui-navigation-bar .android {\n --height: 48px;\n}\n\n.weui-navigation-bar {\n overflow: hidden;\n color: var(--weui-FG-0);\n flex: none;\n}\n\n.weui-navigation-bar__inner {\n position: relative;\n top: 0;\n left: 0;\n height: calc(var(--height) + env(safe-area-inset-top));\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n padding-top: env(safe-area-inset-top);\n width: 100%;\n box-sizing: border-box;\n}\n\n.weui-navigation-bar__left {\n position: relative;\n padding-left: var(--left);\n display: flex;\n flex-direction: row;\n align-items: flex-start;\n height: 100%;\n box-sizing: border-box;\n}\n\n.weui-navigation-bar__btn_goback_wrapper {\n padding: 11px 18px 11px 16px;\n margin: -11px -18px -11px -16px;\n}\n\n.weui-navigation-bar__btn_goback_wrapper.weui-active {\n opacity: 0.5;\n}\n\n.weui-navigation-bar__btn_goback {\n font-size: 12px;\n width: 12px;\n height: 24px;\n -webkit-mask: url(\"data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E\") no-repeat 50% 50%;\n mask: url(\"data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E\") no-repeat 50% 50%;\n -webkit-mask-size: cover;\n mask-size: cover;\n background-color: var(--weui-FG-0);\n}\n\n.weui-navigation-bar__center {\n font-size: 17px;\n text-align: center;\n position: relative;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n font-weight: bold;\n flex: 1;\n height: 100%;\n}\n\n.weui-navigation-bar__loading {\n margin-right: 4px;\n align-items: center;\n}\n\n.weui-loading {\n font-size: 16px;\n width: 16px;\n height: 16px;\n display: block;\n background: transparent url(\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' viewBox='0 0 80 80' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3Eloading%3C/title%3E%3Cdefs%3E%3ClinearGradient x1='94.0869141%25' y1='0%25' x2='94.0869141%25' y2='90.559082%25' id='linearGradient-1'%3E%3Cstop stop-color='%23606060' stop-opacity='0' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3ClinearGradient x1='100%25' y1='8.67370605%25' x2='100%25' y2='90.6286621%25' id='linearGradient-2'%3E%3Cstop stop-color='%23606060' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3C/defs%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' opacity='0.9'%3E%3Cg%3E%3Cpath d='M40,0 C62.09139,0 80,17.90861 80,40 C80,62.09139 62.09139,80 40,80 L40,73 C58.2253967,73 73,58.2253967 73,40 C73,21.7746033 58.2253967,7 40,7 L40,0 Z' fill='url(%23linearGradient-1)'%3E%3C/path%3E%3Cpath d='M40,0 L40,7 C21.7746033,7 7,21.7746033 7,40 C7,58.2253967 21.7746033,73 40,73 L40,80 C17.90861,80 0,62.09139 0,40 C0,17.90861 17.90861,0 40,0 Z' fill='url(%23linearGradient-2)'%3E%3C/path%3E%3Ccircle id='Oval' fill='%23606060' cx='40.5' cy='3.5' r='3.5'%3E%3C/circle%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\") no-repeat;\n background-size: 100%;\n margin-left: 0;\n animation: loading linear infinite 1s;\n}\n\n@keyframes loading {\n from {\n transform: rotate(0);\n }\n to {\n transform: rotate(360deg);\n }\n}\n",
|
||||
":root\n.container {\n height: 100%;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: space-between;\n padding: 200rpx 0;\n box-sizing: border-box;\n} \n"
|
||||
],
|
||||
"pageCount": 3,
|
||||
"cwd": "/home/msojocs/WeChatProjects/miniprogram-2",
|
||||
"replaceContent": {
|
||||
"app.wxss": ":root\n.container {\n height: 100%;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: space-between;\n padding: 200rpx 0;\n box-sizing: border-box;\n} \n",
|
||||
"./app.wxss": ":root\n.container {\n height: 100%;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: space-between;\n padding: 200rpx 0;\n box-sizing: border-box;\n} \n",
|
||||
"components/navigation-bar/navigation-bar.wxss": ".weui-navigation-bar {\n --weui-FG-0:rgba(0,0,0,.9);\n --height: 44px;\n --left: 16px;\n}\n.weui-navigation-bar .android {\n --height: 48px;\n}\n\n.weui-navigation-bar {\n overflow: hidden;\n color: var(--weui-FG-0);\n flex: none;\n}\n\n.weui-navigation-bar__inner {\n position: relative;\n top: 0;\n left: 0;\n height: calc(var(--height) + env(safe-area-inset-top));\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n padding-top: env(safe-area-inset-top);\n width: 100%;\n box-sizing: border-box;\n}\n\n.weui-navigation-bar__left {\n position: relative;\n padding-left: var(--left);\n display: flex;\n flex-direction: row;\n align-items: flex-start;\n height: 100%;\n box-sizing: border-box;\n}\n\n.weui-navigation-bar__btn_goback_wrapper {\n padding: 11px 18px 11px 16px;\n margin: -11px -18px -11px -16px;\n}\n\n.weui-navigation-bar__btn_goback_wrapper.weui-active {\n opacity: 0.5;\n}\n\n.weui-navigation-bar__btn_goback {\n font-size: 12px;\n width: 12px;\n height: 24px;\n -webkit-mask: url(\"data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E\") no-repeat 50% 50%;\n mask: url(\"data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E\") no-repeat 50% 50%;\n -webkit-mask-size: cover;\n mask-size: cover;\n background-color: var(--weui-FG-0);\n}\n\n.weui-navigation-bar__center {\n font-size: 17px;\n text-align: center;\n position: relative;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n font-weight: bold;\n flex: 1;\n height: 100%;\n}\n\n.weui-navigation-bar__loading {\n margin-right: 4px;\n align-items: center;\n}\n\n.weui-loading {\n font-size: 16px;\n width: 16px;\n height: 16px;\n display: block;\n background: transparent url(\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' viewBox='0 0 80 80' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3Eloading%3C/title%3E%3Cdefs%3E%3ClinearGradient x1='94.0869141%25' y1='0%25' x2='94.0869141%25' y2='90.559082%25' id='linearGradient-1'%3E%3Cstop stop-color='%23606060' stop-opacity='0' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3ClinearGradient x1='100%25' y1='8.67370605%25' x2='100%25' y2='90.6286621%25' id='linearGradient-2'%3E%3Cstop stop-color='%23606060' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3C/defs%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' opacity='0.9'%3E%3Cg%3E%3Cpath d='M40,0 C62.09139,0 80,17.90861 80,40 C80,62.09139 62.09139,80 40,80 L40,73 C58.2253967,73 73,58.2253967 73,40 C73,21.7746033 58.2253967,7 40,7 L40,0 Z' fill='url(%23linearGradient-1)'%3E%3C/path%3E%3Cpath d='M40,0 L40,7 C21.7746033,7 7,21.7746033 7,40 C7,58.2253967 21.7746033,73 40,73 L40,80 C17.90861,80 0,62.09139 0,40 C0,17.90861 17.90861,0 40,0 Z' fill='url(%23linearGradient-2)'%3E%3C/path%3E%3Ccircle id='Oval' fill='%23606060' cx='40.5' cy='3.5' r='3.5'%3E%3C/circle%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\") no-repeat;\n background-size: 100%;\n margin-left: 0;\n animation: loading linear infinite 1s;\n}\n\n@keyframes loading {\n from {\n transform: rotate(0);\n }\n to {\n transform: rotate(360deg);\n }\n}\n",
|
||||
"./components/navigation-bar/navigation-bar.wxss": ".weui-navigation-bar {\n --weui-FG-0:rgba(0,0,0,.9);\n --height: 44px;\n --left: 16px;\n}\n.weui-navigation-bar .android {\n --height: 48px;\n}\n\n.weui-navigation-bar {\n overflow: hidden;\n color: var(--weui-FG-0);\n flex: none;\n}\n\n.weui-navigation-bar__inner {\n position: relative;\n top: 0;\n left: 0;\n height: calc(var(--height) + env(safe-area-inset-top));\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n padding-top: env(safe-area-inset-top);\n width: 100%;\n box-sizing: border-box;\n}\n\n.weui-navigation-bar__left {\n position: relative;\n padding-left: var(--left);\n display: flex;\n flex-direction: row;\n align-items: flex-start;\n height: 100%;\n box-sizing: border-box;\n}\n\n.weui-navigation-bar__btn_goback_wrapper {\n padding: 11px 18px 11px 16px;\n margin: -11px -18px -11px -16px;\n}\n\n.weui-navigation-bar__btn_goback_wrapper.weui-active {\n opacity: 0.5;\n}\n\n.weui-navigation-bar__btn_goback {\n font-size: 12px;\n width: 12px;\n height: 24px;\n -webkit-mask: url(\"data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E\") no-repeat 50% 50%;\n mask: url(\"data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E\") no-repeat 50% 50%;\n -webkit-mask-size: cover;\n mask-size: cover;\n background-color: var(--weui-FG-0);\n}\n\n.weui-navigation-bar__center {\n font-size: 17px;\n text-align: center;\n position: relative;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n font-weight: bold;\n flex: 1;\n height: 100%;\n}\n\n.weui-navigation-bar__loading {\n margin-right: 4px;\n align-items: center;\n}\n\n.weui-loading {\n font-size: 16px;\n width: 16px;\n height: 16px;\n display: block;\n background: transparent url(\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' viewBox='0 0 80 80' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3Eloading%3C/title%3E%3Cdefs%3E%3ClinearGradient x1='94.0869141%25' y1='0%25' x2='94.0869141%25' y2='90.559082%25' id='linearGradient-1'%3E%3Cstop stop-color='%23606060' stop-opacity='0' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3ClinearGradient x1='100%25' y1='8.67370605%25' x2='100%25' y2='90.6286621%25' id='linearGradient-2'%3E%3Cstop stop-color='%23606060' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3C/defs%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' opacity='0.9'%3E%3Cg%3E%3Cpath d='M40,0 C62.09139,0 80,17.90861 80,40 C80,62.09139 62.09139,80 40,80 L40,73 C58.2253967,73 73,58.2253967 73,40 C73,21.7746033 58.2253967,7 40,7 L40,0 Z' fill='url(%23linearGradient-1)'%3E%3C/path%3E%3Cpath d='M40,0 L40,7 C21.7746033,7 7,21.7746033 7,40 C7,58.2253967 21.7746033,73 40,73 L40,80 C17.90861,80 0,62.09139 0,40 C0,17.90861 17.90861,0 40,0 Z' fill='url(%23linearGradient-2)'%3E%3C/path%3E%3Ccircle id='Oval' fill='%23606060' cx='40.5' cy='3.5' r='3.5'%3E%3C/circle%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\") no-repeat;\n background-size: 100%;\n margin-left: 0;\n animation: loading linear infinite 1s;\n}\n\n@keyframes loading {\n from {\n transform: rotate(0);\n }\n to {\n transform: rotate(360deg);\n }\n}\n",
|
||||
"pages/index/index.wxss": "/**index.wxss**/\n:root\npage {\n height: 100vh;\n display: flex;\n flex-direction: column;\n}\n\n.scrollarea {\n flex: 1;\n overflow-y: hidden;\n}\n\n.userinfo {\n display: flex;\n flex-direction: column;\n align-items: center;\n color: #aaa;\n width: 80%;\n}\n\n.userinfo-avatar {\n overflow: hidden;\n width: 128rpx;\n height: 128rpx;\n margin: 20rpx;\n border-radius: 50%;\n}\n\n.usermotto {\n margin-top: 200px;\n}\n\n.avatar-wrapper {\n padding: 0;\n width: 56px !important;\n border-radius: 8px;\n margin-top: 40px;\n margin-bottom: 40px;\n}\n\n.avatar {\n display: block;\n width: 56px;\n height: 56px;\n}\n\n.nickname-wrapper {\n display: flex;\n width: 100%;\n padding: 16px;\n box-sizing: border-box;\n border-top: .5px solid rgba(0, 0, 0, 0.1);\n border-bottom: .5px solid rgba(0, 0, 0, 0.1);\n color: black;\n}\n\n.nickname-label {\n width: 105px;\n}\n\n.nickname-input {\n flex: 1;\n}\n",
|
||||
"./pages/index/index.wxss": "/**index.wxss**/\n:root\npage {\n height: 100vh;\n display: flex;\n flex-direction: column;\n}\n\n.scrollarea {\n flex: 1;\n overflow-y: hidden;\n}\n\n.userinfo {\n display: flex;\n flex-direction: column;\n align-items: center;\n color: #aaa;\n width: 80%;\n}\n\n.userinfo-avatar {\n overflow: hidden;\n width: 128rpx;\n height: 128rpx;\n margin: 20rpx;\n border-radius: 50%;\n}\n\n.usermotto {\n margin-top: 200px;\n}\n\n.avatar-wrapper {\n padding: 0;\n width: 56px !important;\n border-radius: 8px;\n margin-top: 40px;\n margin-bottom: 40px;\n}\n\n.avatar {\n display: block;\n width: 56px;\n height: 56px;\n}\n\n.nickname-wrapper {\n display: flex;\n width: 100%;\n padding: 16px;\n box-sizing: border-box;\n border-top: .5px solid rgba(0, 0, 0, 0.1);\n border-bottom: .5px solid rgba(0, 0, 0, 0.1);\n color: black;\n}\n\n.nickname-label {\n width: 105px;\n}\n\n.nickname-input {\n flex: 1;\n}\n",
|
||||
"pages/logs/logs.wxss": "page {\n height: 100vh;\n display: flex;\n flex-direction: column;\n}\n.scrollarea {\n flex: 1;\n overflow-y: hidden;\n}\n.log-item {\n margin-top: 20rpx;\n text-align: center;\n}\n.log-item:last-child {\n padding-bottom: env(safe-area-inset-bottom);\n}\n",
|
||||
"./pages/logs/logs.wxss": "page {\n height: 100vh;\n display: flex;\n flex-direction: column;\n}\n.scrollarea {\n flex: 1;\n overflow-y: hidden;\n}\n.log-item {\n margin-top: 20rpx;\n text-align: center;\n}\n.log-item:last-child {\n padding-bottom: env(safe-area-inset-bottom);\n}\n"
|
||||
},
|
||||
"debug": true,
|
||||
"classPrefix": "",
|
||||
"lazyload": true
|
||||
}
|
38
test/spec/issue/137/issue137.spec.ts
Normal file
38
test/spec/issue/137/issue137.spec.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import assert from "assert"
|
||||
import path from "path"
|
||||
import { describe } from "mocha";
|
||||
import linux from '../../../runner/module-linux'
|
||||
import windows from '../../../runner/module-windows'
|
||||
import * as fs from 'fs'
|
||||
|
||||
describe("issue - 137", function () {
|
||||
describe("issue: linux output should equal with wine", function () {
|
||||
it("Arch linux crash", async function () {
|
||||
const p = path.resolve(__dirname, './data/example.json')
|
||||
const storagePath = path.resolve(
|
||||
__dirname,
|
||||
`output/${this.test?.title}`
|
||||
);
|
||||
try {
|
||||
fs.mkdirSync(storagePath, { recursive: true });
|
||||
} catch (error) {}
|
||||
|
||||
const w = await windows.wcsc(p);
|
||||
const n = await linux.wcsc(p, '', storagePath);
|
||||
// console.log('windows:', typeof w)
|
||||
// console.log('linux:', typeof n)
|
||||
|
||||
fs.writeFileSync(
|
||||
`${storagePath}/wine-output.json`,
|
||||
JSON.stringify(w, null, 4)
|
||||
);
|
||||
fs.writeFileSync(
|
||||
`${storagePath}/node-output.json`,
|
||||
JSON.stringify(n, null, 4)
|
||||
);
|
||||
assert.equal(typeof n, typeof w);
|
||||
assert.equal(w.success, true)
|
||||
assert.deepEqual(n, w);
|
||||
});
|
||||
});
|
||||
});
|
28
test/spec/wcc/module/data/options-202505012307.json
Normal file
28
test/spec/wcc/module/data/options-202505012307.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"files": [
|
||||
"./pages/index/index.wxml",
|
||||
"./pages/logs/logs.wxml"
|
||||
],
|
||||
"contents": [
|
||||
"<!--index.wxml-->\n<scroll-view class=\"scrollarea\" scroll-y type=\"list\">\n <view class=\"container\">\n <view class=\"userinfo\">\n <block wx:if=\"{{canIUseNicknameComp && !hasUserInfo}}\">\n <button class=\"avatar-wrapper\" open-type=\"chooseAvatar\" bind:chooseavatar=\"onChooseAvatar\">\n <image class=\"avatar\" src=\"{{userInfo.avatarUrl}}\"></image>\n </button>\n <view class=\"nickname-wrapper\">\n <text class=\"nickname-label\">昵称</text>\n <input type=\"nickname\" class=\"nickname-input\" placeholder=\"请输入昵称\" bind:change=\"onInputChange\" />\n </view>\n </block>\n <block wx:elif=\"{{!hasUserInfo}}\">\n <button wx:if=\"{{canIUseGetUserProfile}}\" bindtap=\"getUserProfile\"> 获取头像昵称 </button>\n <view wx:else> 请使用2.10.4及以上版本基础库 </view>\n </block>\n <block wx:else>\n <image bindtap=\"bindViewTap\" class=\"userinfo-avatar\" src=\"{{userInfo.avatarUrl}}\" mode=\"cover\"></image>\n <text class=\"userinfo-nickname\">{{userInfo.nickName}}</text>\n </block>\n </view>\n <view class=\"usermotto\">\n <text class=\"user-motto\" style=\"color:var(--primary);\">{{motto}}</text>\n </view>\n </view>\n</scroll-view>\n",
|
||||
"<!--logs.wxml-->\n<scroll-view class=\"scrollarea\" scroll-y type=\"list\">\n <block wx:for=\"{{logs}}\" wx:key=\"timeStamp\" wx:for-item=\"log\">\n <view class=\"log-item\">{{index + 1}}. {{log.date}}</view>\n </block>\n</scroll-view>\n"
|
||||
],
|
||||
"replaceContent": {
|
||||
"pages/index/index.wxml": "<!--index.wxml-->\n<scroll-view class=\"scrollarea\" scroll-y type=\"list\">\n <view class=\"container\">\n <view class=\"userinfo\">\n <block wx:if=\"{{canIUseNicknameComp && !hasUserInfo}}\">\n <button class=\"avatar-wrapper\" open-type=\"chooseAvatar\" bind:chooseavatar=\"onChooseAvatar\">\n <image class=\"avatar\" src=\"{{userInfo.avatarUrl}}\"></image>\n </button>\n <view class=\"nickname-wrapper\">\n <text class=\"nickname-label\">昵称</text>\n <input type=\"nickname\" class=\"nickname-input\" placeholder=\"请输入昵称\" bind:change=\"onInputChange\" />\n </view>\n </block>\n <block wx:elif=\"{{!hasUserInfo}}\">\n <button wx:if=\"{{canIUseGetUserProfile}}\" bindtap=\"getUserProfile\"> 获取头像昵称 </button>\n <view wx:else> 请使用2.10.4及以上版本基础库 </view>\n </block>\n <block wx:else>\n <image bindtap=\"bindViewTap\" class=\"userinfo-avatar\" src=\"{{userInfo.avatarUrl}}\" mode=\"cover\"></image>\n <text class=\"userinfo-nickname\">{{userInfo.nickName}}</text>\n </block>\n </view>\n <view class=\"usermotto\">\n <text class=\"user-motto\" style=\"color:var(--primary);\">{{motto}}</text>\n </view>\n </view>\n</scroll-view>\n",
|
||||
"./pages/index/index.wxml": "<!--index.wxml-->\n<scroll-view class=\"scrollarea\" scroll-y type=\"list\">\n <view class=\"container\">\n <view class=\"userinfo\">\n <block wx:if=\"{{canIUseNicknameComp && !hasUserInfo}}\">\n <button class=\"avatar-wrapper\" open-type=\"chooseAvatar\" bind:chooseavatar=\"onChooseAvatar\">\n <image class=\"avatar\" src=\"{{userInfo.avatarUrl}}\"></image>\n </button>\n <view class=\"nickname-wrapper\">\n <text class=\"nickname-label\">昵称</text>\n <input type=\"nickname\" class=\"nickname-input\" placeholder=\"请输入昵称\" bind:change=\"onInputChange\" />\n </view>\n </block>\n <block wx:elif=\"{{!hasUserInfo}}\">\n <button wx:if=\"{{canIUseGetUserProfile}}\" bindtap=\"getUserProfile\"> 获取头像昵称 </button>\n <view wx:else> 请使用2.10.4及以上版本基础库 </view>\n </block>\n <block wx:else>\n <image bindtap=\"bindViewTap\" class=\"userinfo-avatar\" src=\"{{userInfo.avatarUrl}}\" mode=\"cover\"></image>\n <text class=\"userinfo-nickname\">{{userInfo.nickName}}</text>\n </block>\n </view>\n <view class=\"usermotto\">\n <text class=\"user-motto\" style=\"color:var(--primary);\">{{motto}}</text>\n </view>\n </view>\n</scroll-view>\n",
|
||||
"pages/logs/logs.wxml": "<!--logs.wxml-->\n<scroll-view class=\"scrollarea\" scroll-y type=\"list\">\n <block wx:for=\"{{logs}}\" wx:key=\"timeStamp\" wx:for-item=\"log\">\n <view class=\"log-item\">{{index + 1}}. {{log.date}}</view>\n </block>\n</scroll-view>\n",
|
||||
"./pages/logs/logs.wxml": "<!--logs.wxml-->\n<scroll-view class=\"scrollarea\" scroll-y type=\"list\">\n <block wx:for=\"{{logs}}\" wx:key=\"timeStamp\" wx:for-item=\"log\">\n <view class=\"log-item\">{{index + 1}}. {{log.date}}</view>\n </block>\n</scroll-view>\n"
|
||||
},
|
||||
"verbose": false,
|
||||
"debug": true,
|
||||
"debugWXS": false,
|
||||
"showNewTree": false,
|
||||
"addTestAttre": false,
|
||||
"independent": false,
|
||||
"genfuncname": "$gwx",
|
||||
"cwd": "/home/msojocs/WeChatProjects/miniprogram-2",
|
||||
"lazyload": true,
|
||||
"lazyloadConfig": "./pages/index/index>_<2413./pages/logs/logs",
|
||||
"wxmlCompileConfig": "2>_<2413./pages/index/index.wxml>_<24130>_<2413./pages/logs/logs.wxml>_<24130",
|
||||
"wxmlCompileConfigSplit": ">_<2413"
|
||||
}
|
@ -54,6 +54,32 @@ describe("wcc - module", function () {
|
||||
// console.log('windows:', typeof w)
|
||||
// console.log('linux:', typeof n)
|
||||
|
||||
assert.equal(typeof n, typeof w);
|
||||
fs.writeFileSync(
|
||||
`${storagePath}/wine-output.json`,
|
||||
JSON.stringify(w, null, 4)
|
||||
);
|
||||
fs.writeFileSync(
|
||||
`${storagePath}/node-output.json`,
|
||||
JSON.stringify(n, null, 4)
|
||||
);
|
||||
assert.deepEqual(n, w);
|
||||
});
|
||||
it("初次加载3 - 1", async function () {
|
||||
const p = path.resolve(__dirname, './data/options-202505012307.json')
|
||||
const storagePath = path.resolve(
|
||||
__dirname,
|
||||
`miniprogram-demo/${this.test?.title}`
|
||||
);
|
||||
try {
|
||||
fs.mkdirSync(storagePath, { recursive: true });
|
||||
} catch (error) {}
|
||||
|
||||
const w = await windows.wcc(p);
|
||||
const n = await linux.wcc(p, '');
|
||||
// console.log('windows:', typeof w)
|
||||
// console.log('linux:', typeof n)
|
||||
|
||||
assert.equal(typeof n, typeof w);
|
||||
fs.writeFileSync(
|
||||
`${storagePath}/wine-output.json`,
|
||||
|
6
test/wcsc_module.sh
Executable file
6
test/wcsc_module.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
root_dir=$(cd `dirname $0`/.. && pwd -P)
|
||||
|
||||
echo "linux:"
|
||||
$root_dir/cache/nwjs-sdk-v0.55.0-linux-x64/nw $root_dir/test/runner/nwjs/compiler.js wcsc $root_dir/test/spec/issue/137/data/example.json
|
Loading…
x
Reference in New Issue
Block a user