Skip to content

Commit

Permalink
Merge branch 'dev-0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed Jul 4, 2023
2 parents f0ee712 + 937a0dd commit 300f4fb
Show file tree
Hide file tree
Showing 62 changed files with 12,503 additions and 11,764 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- run: git submodule update --init --recursive
- restore_cache:
key: node-modules-{{ checksum "package-lock.json" }}-{{ checksum "example/package-lock.json" }}
- run: npm install --force
- run: npm install
- run: npm run bootstrap
- save_cache:
key: node-modules-{{ checksum "package-lock.json" }}-{{ checksum "example/package-lock.json" }}
Expand Down
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]

indent_style = space
indent_size = 2

end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.pbxproj -text
# specific for windows script files
*.bat text eol=crlf
65 changes: 32 additions & 33 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#
.DS_Store

# node.js
#
node_modules/
npm-debug.log
yarn-error.log
# XDE
.expo/

# VSCode
.vscode/
jsconfig.json

# Xcode
#
Expand All @@ -28,48 +28,47 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace
/example/ios/Pods/


# Android/IntelliJ
# Android/IJ
#
build/
.classpath
.cxx
.idea
.gradle
.idea
.project
.settings
local.properties
*.iml
android.iml
android/**/jniLibs/*/*.so

# Cocoapods
#
example/ios/Pods

# Ruby
example/vendor/

# node.js
#
node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore

# Test generated files
/ReactAndroid/src/androidTest/assets/AndroidTestBundle.js
*.js.meta
android/app/libs
android/keystores/debug.keystore

my-release-key.keystore
StaticServerExample/my-release-key.keystore
# Expo
.expo/

# Android
.classpath
.project
.settings/
android/.project
/android/**/jniLibs/*/*.so
# Turborepo
.turbo/

# generated by bob
lib/

# Java compiler outputs
*.class

# MSBuild Binary and Structured Log
*.binlog
*.tlog

# Other
/dr.pogodin-react-native-static-server-*.tgz
/.vscode
/.vs
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.16.0
18.16.1
1 change: 1 addition & 0 deletions .watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPCRE2_CODE_UNIT_WIDTH=8 -I${CMAKE_BINARY_DIR}/sysroot/include -L${CMAKE_BINARY_DIR}/sysroot/lib")

# To find PCRE2 Lighttpd first of all tries to use pkg_check_modules().
# It seems that on Linux it ends up relying on pkg-config utility of the host
# system, which find the host's version of PCRE2. With CMake 3.18.1 it was fine,
# as it used to output the linker flag for PCRE2 just as "-lpcre2-8",
# and just above we set the correct -L flag with the path of PCRE2
# cross-compiled for Android. However, with CMake 3.22.1 the CMake's default
# output is "-L/usr/lib/x86_64-linux-gnu;-lpcre2-8", which ends up forcing
# Lighttpd to try linking against the host's PCRE2, which fails. The flag set
# below instructs pkg-config to not include -L flag into outputs,
# thus restoring the correct linking. However, it is not the best fix,
# I guess.
# TODO: Find a better fix.
set(PKG_CONFIG_ARGN --libs-only-l)

add_subdirectory(lighttpd1.4)

file(WRITE ${CMAKE_BINARY_DIR}/lighttpd1.4/build/plugin-static.h
Expand Down
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Embed HTTP server for [React Native] applications for Android, iOS, Mac (Catalys
and Windows platforms. Powered by [Lighttpd] server, supports both [new][New Architecture]
and [old][Old Architecture] RN architectures.

**BEWARE:** _The Windows support is broken in the version v0.8.0, rely on
the library version v0.7.13 instead, for now._

[![Sponsor](https://raw.githubusercontent.com/birdofpreyru/react-native-static-server/master/.README/sponsor.svg)](https://github.com/sponsors/birdofpreyru)

### Sponsored By:
Expand Down Expand Up @@ -345,6 +348,7 @@ outside platform-specific sub-folders.
(Android-specific).
- [getActiveServer()] — Gets currently active, starting, or stopping
server instance, if any.
- [resolveAssetsPath()] — Resolves relative paths for bundled assets.
- [ERROR_LOG_FILE] — Location of the error log file.
- [STATES] — Enumerates possible states of [Server] instance.
- [UPLOADS_DIR] — Location for uploads.
Expand Down Expand Up @@ -376,9 +380,11 @@ within `options` argument:
- `fileDir` — **string** — The root path on target device from where
static assets should be served. Relative paths (those not starting with `/`,
neither `file:///`) will be automatically prepended by the _document directory_
path; however, empty `fileDir` value is forbidden: if you really want to serve
entire documents directory of the app, provide its absolute path explicitly.
neither `file:///`) are automatically prepended by the platform-dependent
base path (document directory on Android, or main bundle directory on other
platforms); however, empty `fileDir` value
is forbidden — if you really want to serve all content from the base
directory, provide it its absolute path explicitly.
- `errorLog` — **boolean** | [ErrorLogOptions] — Optional.
If set **true** (treated equivalent to `{}`) the server instance will
Expand Down Expand Up @@ -659,6 +665,26 @@ been stopped automatically because of `stopInBackground` option, when the app
entered background, and might be automatically started in future if the app
enters foreground again prior to an explicit [.stop()] call for that instance.
### resolveAssetsPath()
[resolveAssetsPath()]: #resolveassetspath
```ts
import {resolveAssetsPath} from '@dr.pogodin/react-native-static-server';
resolveAssetsPath(path: string): string;
```
If given `path` is relative, it returns the corresponding absolute path,
resolved relative to the platform-specific base location (document folder
on Android; or main bundle folder on other platforms) for bundled assets;
otherwise, it just returns given absolute `path` as is.
In other words, it exposes the same path resolution logic used by [Server]'s
[constructor()] for its `fileDir` argument.
**Arguments**
- `path` — **string** — Absolute or relative path.
Returns **string** — The corresponding absolute path.
### ERROR_LOG_FILE
[ERROR_LOG_FILE]: #error_log_file
```ts
Expand Down
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def isNewArchitectureEnabled() {

apply plugin: "com.android.library"


def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }

if (isNewArchitectureEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public Map<String,Object> getTypedExportedConstants() {
final Map<String,Object> constants = new HashMap<>();

constants.put("CRASHED", Server.CRASHED);
constants.put("IS_MAC_CATALYST", false);
constants.put("LAUNCHED", Server.LAUNCHED);
constants.put("TERMINATED", Server.TERMINATED);

Expand Down
21 changes: 11 additions & 10 deletions dr-pogodin-react-native-static-server.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Pod::Spec.new do |s|
s.preserve_paths = 'README.md', 'package.json', 'index.js'
s.source_files = "ios/**/*.{h,m,mm}"

s.dependency "React-Core"

# This requires CMake on the build host, which can be installed via Homebrew (https://brew.sh)
s.script_phase = {
:name => 'Build native dependencies',
Expand Down Expand Up @@ -72,27 +70,30 @@ Pod::Spec.new do |s|
CMD
}

$otherLibToolFlags = "-llighttpd -lpcre2-8 -lmod_dirlisting -lmod_h2"
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
if respond_to?(:install_modules_dependencies, true)
install_modules_dependencies(s)
else
s.dependency "React-Core"

# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"OTHER_LIBTOOLFLAGS" => $otherLibToolFlags,
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
else
# TODO: Can we put these flags into a variable, and then qoute it here,
# and above where the same flags should be set?
s.pod_target_xcconfig = {
"OTHER_LIBTOOLFLAGS" => $otherLibToolFlags
}
end
end

s.pod_target_xcconfig = {
"OTHER_LIBTOOLFLAGS" => "-llighttpd -lpcre2-8 -lmod_dirlisting -lmod_h2"
}
end
1 change: 0 additions & 1 deletion example/.node-version

This file was deleted.

2 changes: 1 addition & 1 deletion example/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
4 changes: 2 additions & 2 deletions example/Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby '>= 2.6.10'
ruby ">= 2.6.10"

gem 'cocoapods', '>= 1.11.3'
gem 'cocoapods', '~> 1.12'
51 changes: 2 additions & 49 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"

import com.android.build.OutputFile

/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
Expand All @@ -13,8 +11,8 @@ react {
// root = file("../")
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
// reactNativeDir = file("../node_modules/react-native")
// The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
// codegenDir = file("../node_modules/react-native-codegen")
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
// codegenDir = file("../node_modules/@react-native/codegen")
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
// cliFile = file("../node_modules/react-native/cli.js")

Expand Down Expand Up @@ -52,14 +50,6 @@ react {
// hermesFlags = ["-O", "-output-source-map"]
}

/**
* Set this to true to create four separate APKs instead of one,
* one for each native architecture. This is useful if you don't
* use App Bundles (https://developer.android.com/guide/app-bundle/)
* and want to have separate APKs to upload to the Play Store.
*/
def enableSeparateBuildPerCPUArchitecture = false

/**
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
*/
Expand All @@ -78,16 +68,6 @@ def enableProguardInReleaseBuilds = true
*/
def jscFlavor = 'org.webkit:android-jsc:+'

/**
* Private function to get the list of Native Architectures you want to build.
* This reads the value from reactNativeArchitectures in your gradle.properties
* file and works together with the --active-arch-only flag of react-native run-android.
*/
def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

android {
ndkVersion rootProject.ext.ndkVersion

Expand All @@ -107,15 +87,6 @@ android {
assets.srcDirs = ['../../assets']
}
}

splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include (*reactNativeArchitectures())
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
Expand All @@ -136,30 +107,12 @@ android {
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}

// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}

}
}
}

dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")

implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.squareup.okhttp3', module:'okhttp'
Expand Down
Loading

0 comments on commit 300f4fb

Please sign in to comment.