diff --git a/js/.gitignore b/js/.gitignore new file mode 100644 index 00000000..311f52b0 --- /dev/null +++ b/js/.gitignore @@ -0,0 +1 @@ +react-native-go-ipfs.tgz diff --git a/js/Makefile b/js/Makefile new file mode 100644 index 00000000..32635cab --- /dev/null +++ b/js/Makefile @@ -0,0 +1,50 @@ +ALL_NODE_MODULES=node_modules $(wildcard */node_modules) +POD_NAME=GomobileIPFS +MODULE_NAME=react-native-go-ipfs +LOCAL_REPO=$(MODULE_NAME)/android/local_repo +BRIDGE_VERSION=0.0.1 +GOMOBILE_IPFS_VERSION=0.0.1 +LOCAL_BRIDGE_DIR=$(LOCAL_REPO)/ipfs/gomobile/android/$(BRIDGE_VERSION) +LOCAL_GOMOBILE_IPFS_DIR=$(LOCAL_REPO)/ipfs/gomobile/gomobile-ipfs/$(GOMOBILE_IPFS_VERSION) +ARCHIVE=$(MODULE_NAME).tgz +LOCAL_POD=$(MODULE_NAME)/ios/$(POD_NAME) + +.PHONY: run.% +run.%: + cd app && ./node_modules/.bin/react-native run-$* + +.PHONY: deps.android +deps.android: + $(MAKE) -C .. build.android + cd ../android && ./gradlew bridge:build + + rm -fr $(LOCAL_REPO) + cp -R ../android/local_repo $(LOCAL_REPO) + mkdir -p $(LOCAL_BRIDGE_DIR) + cp ../android/bridge/build/outputs/aar/bridge-debug.aar $(LOCAL_BRIDGE_DIR)/android-$(BRIDGE_VERSION).aar + cp $(LOCAL_GOMOBILE_IPFS_DIR)/gomobile-ipfs-0.0.1.pom $(LOCAL_BRIDGE_DIR)/android-0.0.1.pom + sed -i.bak 's/gomobile-ipfs<\/artifactId>/android<\/artifactId>/' $(LOCAL_BRIDGE_DIR)/android-0.0.1.pom + + cd $(MODULE_NAME) && yarn pack --filename ../$(ARCHIVE) + cd app && yarn remove react-native-go-ipfs || true + yarn cache clean + cd app && yarn add file:../$(ARCHIVE) + + +.PHONY: deps.ios +deps.ios: + $(MAKE) -C .. build.ios + + rm -fr $(LOCAL_POD) + mkdir -p $(LOCAL_POD) + cp -R ../ios/$(POD_NAME) ../ios/Frameworks ../ios/$(POD_NAME).podspec ../ios/LICENSE $(LOCAL_POD) + + cd $(MODULE_NAME) && yarn pack --filename ../$(ARCHIVE) + cd app && yarn remove react-native-go-ipfs || true + yarn cache clean + cd app && yarn add file:../$(ARCHIVE) + cd app/ios && pod install + +.PHONY: clean +clean: + rm -fr $(LOCAL_REPO) $(LOCAL_POD) $(ALL_NODE_MODULES) $(ARCHIVE) diff --git a/js/app/.buckconfig b/js/app/.buckconfig new file mode 100644 index 00000000..934256cb --- /dev/null +++ b/js/app/.buckconfig @@ -0,0 +1,6 @@ + +[android] + target = Google Inc.:Google APIs:23 + +[maven_repositories] + central = https://repo1.maven.org/maven2 diff --git a/js/app/.eslintrc.js b/js/app/.eslintrc.js new file mode 100644 index 00000000..40c6dcd0 --- /dev/null +++ b/js/app/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: '@react-native-community', +}; diff --git a/js/app/.flowconfig b/js/app/.flowconfig new file mode 100644 index 00000000..4afc766a --- /dev/null +++ b/js/app/.flowconfig @@ -0,0 +1,75 @@ +[ignore] +; We fork some components by platform +.*/*[.]android.js + +; Ignore "BUCK" generated dirs +/\.buckd/ + +; Ignore polyfills +node_modules/react-native/Libraries/polyfills/.* + +; These should not be required directly +; require from fbjs/lib instead: require('fbjs/lib/warning') +node_modules/warning/.* + +; Flow doesn't support platforms +.*/Libraries/Utilities/LoadingView.js + +[untyped] +.*/node_modules/@react-native-community/cli/.*/.* + +[include] + +[libs] +node_modules/react-native/Libraries/react-native/react-native-interface.js +node_modules/react-native/flow/ + +[options] +emoji=true + +esproposal.optional_chaining=enable +esproposal.nullish_coalescing=enable + +module.file_ext=.js +module.file_ext=.json +module.file_ext=.ios.js + +munge_underscores=true + +module.name_mapper='^react-native$' -> '/node_modules/react-native/Libraries/react-native/react-native-implementation' +module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' +module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' + +suppress_type=$FlowIssue +suppress_type=$FlowFixMe +suppress_type=$FlowFixMeProps +suppress_type=$FlowFixMeState + +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError + +[lints] +sketchy-null-number=warn +sketchy-null-mixed=warn +sketchy-number=warn +untyped-type-import=warn +nonstrict-import=warn +deprecated-type=warn +unsafe-getters-setters=warn +inexact-spread=warn +unnecessary-invariant=warn +signature-verification-failure=warn +deprecated-utility=error + +[strict] +deprecated-type +nonstrict-import +sketchy-null +unclear-type +unsafe-getters-setters +untyped-import +untyped-type-import + +[version] +^0.105.0 diff --git a/js/app/.gitattributes b/js/app/.gitattributes new file mode 100644 index 00000000..d42ff183 --- /dev/null +++ b/js/app/.gitattributes @@ -0,0 +1 @@ +*.pbxproj -text diff --git a/js/app/.gitignore b/js/app/.gitignore new file mode 100644 index 00000000..ad572e63 --- /dev/null +++ b/js/app/.gitignore @@ -0,0 +1,59 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + +# BUCK +buck-out/ +\.buckd/ +*.keystore +!debug.keystore + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/ + +*/fastlane/report.xml +*/fastlane/Preview.html +*/fastlane/screenshots + +# Bundle artifact +*.jsbundle + +# CocoaPods +/ios/Pods/ diff --git a/js/app/.prettierrc.js b/js/app/.prettierrc.js new file mode 100644 index 00000000..5c4de1a4 --- /dev/null +++ b/js/app/.prettierrc.js @@ -0,0 +1,6 @@ +module.exports = { + bracketSpacing: false, + jsxBracketSameLine: true, + singleQuote: true, + trailingComma: 'all', +}; diff --git a/js/app/.watchmanconfig b/js/app/.watchmanconfig new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/js/app/.watchmanconfig @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/js/app/App.js b/js/app/App.js new file mode 100644 index 00000000..7771cd18 --- /dev/null +++ b/js/app/App.js @@ -0,0 +1,156 @@ +/** + * Sample React Native App + * https://github.com/facebook/react-native + * + * @format + * @flow + */ + +import React from 'react'; +import { + SafeAreaView, + StyleSheet, + ScrollView, + View, + Text, + StatusBar, + Button, + NativeModules, +} from 'react-native'; + +import { + Header, + LearnMoreLinks, + Colors, + DebugInstructions, + ReloadInstructions, +} from 'react-native/Libraries/NewAppScreen'; + +import IPFS from 'react-native-go-ipfs'; + +function uuidv4() { + // https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = (Math.random() * 16) | 0, + v = c == 'x' ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); +} + +const test = async () => { + const testId = uuidv4(); + + console.log('Starting IPFS test:', testId); + + const ipfs = new IPFS(); + console.log('Constructed IPFS object:', ipfs, ` (testId: ${testId})`); + + console.log('Starting ipfs instance:', ipfs, ` (testId: ${testId})`); + await ipfs.start(); + console.log( + 'Started ipfs instance', + ipfs.nativeHandle, + ` (testId: ${testId})`, + ); + + const {ID} = await ipfs.id(); + console.log( + `Executed command /id on instance ${ + ipfs.nativeHandle + }, got ID=${ID} (testId: ${testId})`, + ); + + const handle = ipfs.nativeHandle; + await ipfs.stop(); + console.log('Stopped ipfs instance', handle, ` (testId: ${testId})`); +}; + +const App: () => React$Node = () => { + return ( + <> + + +