diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..ea26699 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,201 @@ +{ + "parser": "babel-eslint", + + "parserOptions": { + "ecmaFeatures": { + "jsx": true, + "modules": true, + "experimentalObjectRestSpread": true + } + }, + + "env": { + "es6": true, + "jasmine": true, + "node": 1 + }, + + "plugins": [ + "react" + ], + + "globals": { + "__DEV__": true, + "__dirname": false, + "__fbBatchedBridgeConfig": false, + "cancelAnimationFrame": false, + "clearImmediate": true, + "clearInterval": false, + "clearTimeout": false, + "console": false, + "document": false, + "escape": false, + "exports": false, + "fetch": false, + "global": false, + "jest": false, + "Map": true, + "module": false, + "navigator": false, + "process": false, + "Promise": true, + "requestAnimationFrame": true, + "require": false, + "Set": true, + "setImmediate": true, + "setInterval": false, + "setTimeout": false, + "window": false, + "XMLHttpRequest": false, + "pit": false, + "FormData": true + }, + + "rules": { + "comma-dangle": 0, + "no-cond-assign": 1, + "no-console": 0, + "no-constant-condition": 0, + "no-control-regex": 1, + "no-debugger": 1, + "no-dupe-keys": 1, + "no-empty": 0, + "no-empty-character-class": 1, + "no-ex-assign": 1, + "no-extra-boolean-cast": 1, + "no-extra-parens": 0, + "no-extra-semi": 1, + "no-func-assign": 1, + "no-inner-declarations": 0, + "no-invalid-regexp": 1, + "no-negated-in-lhs": 1, + "no-obj-calls": 1, + "no-regex-spaces": 1, + "no-reserved-keys": 0, + "no-sparse-arrays": 1, + "no-unreachable": 1, + "use-isnan": 1, + "valid-jsdoc": 0, + "valid-typeof": 1, + "block-scoped-var": 0, + "complexity": 0, + "consistent-return": 0, + "curly": 1, + "default-case": 0, + "dot-notation": 1, + "eqeqeq": 1, + "guard-for-in": 0, + "no-alert": 1, + "no-caller": 1, + "no-div-regex": 1, + "no-else-return": 0, + "no-labels": 1, + "no-eq-null": 0, + "no-eval": 1, + "no-extend-native": 1, + "no-extra-bind": 1, + "no-fallthrough": 1, + "no-floating-decimal": 1, + "no-implied-eval": 1, + "no-iterator": 1, + "no-lone-blocks": 1, + "no-loop-func": 0, + "no-multi-str": 0, + "no-native-reassign": 0, + "no-new": 1, + "no-new-func": 1, + "no-new-wrappers": 1, + "no-octal": 1, + "no-octal-escape": 1, + "no-proto": 1, + "no-redeclare": 0, + "no-return-assign": 1, + "no-script-url": 1, + "no-self-compare": 1, + "no-sequences": 1, + "no-unused-expressions": 0, + "no-void": 1, + "no-warning-comments": 0, + "no-with": 1, + "radix": 1, + "vars-on-top": 0, + "wrap-iife": 0, + "yoda": 1, + + "strict": 0, + + "no-catch-shadow": 1, + "no-delete-var": 1, + "no-label-var": 1, + "no-shadow": 1, + "no-shadow-restricted-names": 1, + "no-undef": 2, + "no-undefined": 0, + "no-undef-init": 1, + "no-unused-vars": [1, {"vars": "all", "args": "none"}], + "no-use-before-define": 0, + "handle-callback-err": 1, + "no-mixed-requires": 1, + "no-new-require": 1, + "no-path-concat": 1, + "no-process-exit": 0, + "no-restricted-modules": 1, + "no-sync": 0, + + "key-spacing": 0, + "comma-spacing": 0, + "no-multi-spaces": 0, + "brace-style": 0, + "camelcase": 0, + "consistent-this": [1, "self"], + "eol-last": 1, + "func-names": 0, + "func-style": 0, + "new-cap": 0, + "new-parens": 1, + "no-nested-ternary": 0, + "no-array-constructor": 1, + "no-lonely-if": 0, + "no-new-object": 1, + "no-spaced-func": 1, + "semi-spacing": 1, + "no-ternary": 0, + "no-trailing-spaces": 1, + "no-underscore-dangle": 0, + "no-mixed-spaces-and-tabs": 1, + "quotes": [1, "single", "avoid-escape"], + "quote-props": 0, + "semi": 0, + "sort-vars": 0, + "keyword-spacing": [0, { "before": true }], + "space-in-brackets": 0, + "space-in-parens": 0, + "space-infix-ops": 1, + "space-unary-ops": [1, { "words": true, "nonwords": false }], + "max-nested-callbacks": 0, + "one-var": 0, + "wrap-regex": 0, + + "max-depth": 0, + "max-len": 0, + "max-params": 0, + "max-statements": 0, + "no-bitwise": 1, + "no-plusplus": 0, + + "react/display-name": 0, + "react/jsx-boolean-value": 0, + "react/jsx-no-undef": 1, + "react/jsx-sort-props": 0, + "react/jsx-uses-react": 0, + "react/jsx-uses-vars": 1, + "react/no-did-mount-set-state": 1, + "react/no-did-update-set-state": 1, + "react/no-multi-comp": 0, + "react/no-unknown-property": 0, + "react/prop-types": 0, + "react/react-in-jsx-scope": 0, + "react/self-closing-comp": 1, + "react/wrap-multilines": 0 + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a35f1b --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +# Xcode +!**/*.xcodeproj +!**/*.pbxproj +!**/*.xcworkspacedata +!**/*.xcsettings +!**/*.xcscheme +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + +# Gradle +/build/ +/Examples/**/android/app/build/ +/Examples/**/android/app/gradle/ +/Examples/**/android/app/gradlew +/Examples/**/android/app/gradlew.bat +/ReactAndroid/build/ + +# Buck +.buckd +buck-out +/ReactAndroid/src/main/jni/prebuilt/lib/armeabi-v7a/ +/ReactAndroid/src/main/jni/prebuilt/lib/x86/ + +# Android +.idea +.gradle +local.properties +*.iml +/android/ + +# Node +node_modules +*.log +.nvm + +# OS X +.DS_Store + +# Test generated files +/ReactAndroid/src/androidTest/assets/AndroidTestBundle.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d52a45e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - 6.4.0 diff --git a/README.md b/README.md new file mode 100644 index 0000000..f69a700 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ + +# react-native-version-number + + +Returns the `CFBundleShortVersionString` and the `CFBundleVersion`. Android version is under development. + +## Getting started + +`$ npm install react-native-version-number --save` + +### Mostly automatic installation + +`$ react-native link react-native-version-number` + +### Manual installation + +#### iOS + +1. In Xcode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` +2. Go to `node_modules` ➜ `react-native-version-number` and add `RNVersionNumber.xcodeproj` +3. In Xcode, in the project navigator, select your project. Add `libRNVersionNumber.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` +4. Run your project (`Cmd+R`)< + + +## Usage +```javascript +import VersionNumber from 'react-native-version-number'; + +console.log(VersionNumber.appVersion); +console.log(VersionNumber.buildVersion); +``` + +## License +MIT. diff --git a/index.js b/index.js new file mode 100644 index 0000000..18911ad --- /dev/null +++ b/index.js @@ -0,0 +1,17 @@ +/* @flow */ + +import { NativeModules } from 'react-native'; + +const { RNVersionNumber } = NativeModules; + +type VersionObject = { + appVersion: string, + buildVersion: string +} + +const VersionNumber: VersionObject = { + appVersion: RNVersionNumber.appVersion, + buildVersion: RNVersionNumber.buildVersion, +} + +export default VersionNumber; diff --git a/ios/RNVersionNumber.h b/ios/RNVersionNumber.h new file mode 100644 index 0000000..8a64f1c --- /dev/null +++ b/ios/RNVersionNumber.h @@ -0,0 +1,7 @@ + +#import "RCTBridgeModule.h" + +@interface RNVersionNumber : NSObject + +@end + \ No newline at end of file diff --git a/ios/RNVersionNumber.m b/ios/RNVersionNumber.m new file mode 100644 index 0000000..cabb1b6 --- /dev/null +++ b/ios/RNVersionNumber.m @@ -0,0 +1,18 @@ + +#import "RNVersionNumber.h" + +@implementation RNVersionNumber + +- (dispatch_queue_t)methodQueue +{ + return dispatch_get_main_queue(); +} +RCT_EXPORT_MODULE() + +- (NSDictionary *)constantsToExport +{ + return @{@"appVersion" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], + @"buildVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]}; +} + +@end diff --git a/ios/RNVersionNumber.xcodeproj/project.pbxproj b/ios/RNVersionNumber.xcodeproj/project.pbxproj new file mode 100644 index 0000000..7c020de --- /dev/null +++ b/ios/RNVersionNumber.xcodeproj/project.pbxproj @@ -0,0 +1,252 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + B3E7B58A1CC2AC0600A0062D /* RNVersionNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNVersionNumber.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 58B511D91A9E6C8500147676 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 134814201AA4EA6300B7C361 /* libRNVersionNumber.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNVersionNumber.a; sourceTree = BUILT_PRODUCTS_DIR; }; + B3E7B5881CC2AC0600A0062D /* RNVersionNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNVersionNumber.h; sourceTree = ""; }; + B3E7B5891CC2AC0600A0062D /* RNVersionNumber.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNVersionNumber.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 58B511D81A9E6C8500147676 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 134814211AA4EA7D00B7C361 /* Products */ = { + isa = PBXGroup; + children = ( + 134814201AA4EA6300B7C361 /* libRNVersionNumber.a */, + ); + name = Products; + sourceTree = ""; + }; + 58B511D21A9E6C8500147676 = { + isa = PBXGroup; + children = ( + B3E7B5881CC2AC0600A0062D /* RNVersionNumber.h */, + B3E7B5891CC2AC0600A0062D /* RNVersionNumber.m */, + 134814211AA4EA7D00B7C361 /* Products */, + ); + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 58B511DA1A9E6C8500147676 /* RNVersionNumber */ = { + isa = PBXNativeTarget; + buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNVersionNumber" */; + buildPhases = ( + 58B511D71A9E6C8500147676 /* Sources */, + 58B511D81A9E6C8500147676 /* Frameworks */, + 58B511D91A9E6C8500147676 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = RNVersionNumber; + productName = RCTDataManager; + productReference = 134814201AA4EA6300B7C361 /* libRNVersionNumber.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 58B511D31A9E6C8500147676 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0610; + ORGANIZATIONNAME = Facebook; + TargetAttributes = { + 58B511DA1A9E6C8500147676 = { + CreatedOnToolsVersion = 6.1.1; + }; + }; + }; + buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNVersionNumber" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 58B511D21A9E6C8500147676; + productRefGroup = 58B511D21A9E6C8500147676; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 58B511DA1A9E6C8500147676 /* RNVersionNumber */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 58B511D71A9E6C8500147676 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + B3E7B58A1CC2AC0600A0062D /* RNVersionNumber.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 58B511ED1A9E6C8500147676 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 58B511EE1A9E6C8500147676 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 58B511F01A9E6C8500147676 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(SRCROOT)/../../../React/**", + "$(SRCROOT)/../../react-native/React/**", + ); + LIBRARY_SEARCH_PATHS = "$(inherited)"; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = RNVersionNumber; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 58B511F11A9E6C8500147676 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(SRCROOT)/../../../React/**", + "$(SRCROOT)/../../react-native/React/**", + ); + LIBRARY_SEARCH_PATHS = "$(inherited)"; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = RNVersionNumber; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNVersionNumber" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 58B511ED1A9E6C8500147676 /* Debug */, + 58B511EE1A9E6C8500147676 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNVersionNumber" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 58B511F01A9E6C8500147676 /* Debug */, + 58B511F11A9E6C8500147676 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 58B511D31A9E6C8500147676 /* Project object */; +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..390d794 --- /dev/null +++ b/package.json @@ -0,0 +1,37 @@ +{ + "name": "react-native-version-number", + "version": "0.1.0", + "description": "", + "main": "index.js", + "scripts": { + "lint": "eslint index.js", + "test": "npm run lint" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/APSL/react-native-version-number.git" + }, + "tags": [ + "react", + "react-native", + "react-component", + "ios" + ], + "keywords": [ + "react", + "react-native", + "ios", + "react-component" + ], + "author": "Alvaro Medina Ballester ", + "license": "MIT", + "bugs": { + "url": "https://github.com/APSL/react-native-version-number/issues" + }, + "homepage": "https://github.com/APSL/react-native-version-number#readme", + "devDependencies": { + "babel-eslint": "^6.1.2", + "eslint": "^3.3.1", + "eslint-plugin-react": "^6.1.2" + } +}