Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Setup yarn, flow, eslint and prettier + minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Nov 12, 2018
1 parent ff743b2 commit b675174
Show file tree
Hide file tree
Showing 9 changed files with 1,945 additions and 138 deletions.
46 changes: 46 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Facebook.
*
* As with any software that integrates with the Facebook platform, your use of
* this software is subject to the Facebook Developer Principles and Policies
* [http://developers.facebook.com/policy/]. This copyright notice shall be
* included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* @format
*/
'use strict';

module.exports = {
env: {
node: true,
},
extends: 'eslint-config-fb-strict',
plugins: ['babel', 'flowtype', 'import', 'prettier'],
parser: 'babel-eslint',
rules: {
'babel/quotes': ['error', 'single', 'avoid-escape'],
'consistent-return': 'error',
'import/no-extraneous-dependencies': 'error',
'lint/extra-arrow-initializer': 'off',
'max-len': 'off',
'no-alert': 'error',
'no-console': 'error',
'no-unused-vars': 'error',
'no-var': 'off',
'prefer-arrow-callback': 'off',
'prefer-const': ['warn', {destructuring: 'all'}],
'prettier/prettier': ['error', 'fb', '@format'],
'sort-keys': 'off',
},
};
20 changes: 20 additions & 0 deletions .flowconfig
@@ -0,0 +1,20 @@
[libs]
flow/index.js.flow

[options]
emoji=true

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native_fb[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native_fb[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

munge_underscores=true

[version]
^0.86.0
3 changes: 2 additions & 1 deletion .npmignore
@@ -1,2 +1,3 @@
# sample app
sample/
sample/
.github/
36 changes: 19 additions & 17 deletions bin/ios_setup.js
Expand Up @@ -43,7 +43,7 @@ if (process.argv.length <= 3) {
const appId = process.argv[2];
const appName = process.argv[3];

function downloadFbSdk (next) {
function downloadFbSdk(next) {
try {
fs.accessSync(frameworkDir, fs.F_OK);
} catch (e) {
Expand All @@ -69,7 +69,7 @@ function downloadFbSdk (next) {
pump(download, writeToFile, next);
}

function unzipFramework (next) {
function unzipFramework(next) {
console.log('Unzipping the framework');
const zip = new AdmZip(zipFilePath);
zip.extractAllTo(frameworkDir, true);
Expand All @@ -78,12 +78,13 @@ function unzipFramework (next) {
next();
}

function correctSearchPaths (next) {
function correctSearchPaths(next) {
const rctfbsdkProjectPath = './node_modules/react-native-fbsdk/ios/RCTFBSDK.xcodeproj/project.pbxproj';
const rctfbsdkProject = xcode.project(rctfbsdkProjectPath);
rctfbsdkProject.parse(function (err) {
rctfbsdkProject.parse(function(err) {
if (err) {
return next(err);
next(err);
return;
}
rctfbsdkProject.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/../../../ios/Frameworks"');
fs.writeFileSync(rctfbsdkProjectPath, rctfbsdkProject.writeSync());
Expand All @@ -92,25 +93,26 @@ function correctSearchPaths (next) {
});
}

function updateFBSDKFrameworks (next) {
function updateFBSDKFrameworks(next) {
const files = fs.readdirSync('./ios/');
var myProjName = files.filter((f) => { return f.substr(-10) === '.xcodeproj'; })[0];
var myProjName = files.filter(f => { return f.substr(-10) === '.xcodeproj'; })[0];
const myProjPath = path.join('./ios/', myProjName, '/project.pbxproj');
myProjName = myProjName.replace('.xcodeproj', '');
console.log('Updating target:' + myProjName + ' at ' + myProjPath + ' ...');

const myProj = xcode.project(myProjPath);
myProj.parse(function (err) {
myProj.parse(function(err) {
if (err) {
return next(err);
next(err);
return;
}
myProj.pbxCreateGroup('Frameworks', './ios/Frameworks');

// NOTE: Assumes first target is the app.
const target = myProj.getFirstTarget().uuid;
myProj.addFramework('./ios/Frameworks/FBSDKCoreKit.framework', { 'customFramework': true, 'target': target, 'link': true });
myProj.addFramework('./ios/Frameworks/FBSDKShareKit.framework', { 'customFramework': true, 'target': target, 'link': true });
myProj.addFramework('./ios/Frameworks/FBSDKLoginKit.framework', { 'customFramework': true, 'target': target, 'link': true });
myProj.addFramework('./ios/Frameworks/FBSDKCoreKit.framework', {'customFramework': true, target, 'link': true});
myProj.addFramework('./ios/Frameworks/FBSDKShareKit.framework', {'customFramework': true, target, 'link': true});
myProj.addFramework('./ios/Frameworks/FBSDKLoginKit.framework', {'customFramework': true, target, 'link': true});

// WARNING: this will overwrite any existing search paths
myProj.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/Frameworks/"');
Expand All @@ -121,14 +123,14 @@ function updateFBSDKFrameworks (next) {
});
}

function updatePlist (files, next) {
function updatePlist(files, next) {
console.dir(files);
var plistDirPath = '';
files.map(function (file) {
files.map(function(file) {
return path.join('./ios/', file);
}).filter(function (file) {
}).filter(function(file) {
return fs.statSync(file).isDirectory();
}).forEach(function (file) {
}).forEach(function(file) {
if (fs.readdirSync(file).indexOf('Base.lproj') !== -1) {
plistDirPath = file;
}
Expand All @@ -146,7 +148,7 @@ function updatePlist (files, next) {
next();
}

function done (err) {
function done(err) {
if (err) {
console.error(err);
} else {
Expand Down
27 changes: 27 additions & 0 deletions flow/index.js.flow
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Facebook.
*
* As with any software that integrates with the Facebook platform, your use of
* this software is subject to the Facebook Developer Principles and Policies
* [http://developers.facebook.com/policy/]. This copyright notice shall be
* included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* @flow
* @format
*/

// Just mock RN for flow as it's way simplier than making it typecheck
declare module 'react-native' {
declare module.exports: any;
}
32 changes: 30 additions & 2 deletions package.json
Expand Up @@ -32,6 +32,11 @@
"core"
],
"license": "Facebook Platform License",
"scripts": {
"flow": "flow",
"lint": "eslint .",
"prettier": "prettier \"./**/*.js\" --write"
},
"dependencies": {
"adm-zip": "^0.4.7",
"fastfall": "^1.5.1",
Expand All @@ -42,7 +47,30 @@
"xcode": "^1.0.0"
},
"peerDependencies": {
"react-native": ">=0.44.0",
"prop-types": "15.x.x"
"prop-types": "15.x.x",
"react-native": ">=0.44.0"
},
"devDependencies": {
"babel-eslint": "^10.0.1",
"eslint": "5.1.0",
"eslint-config-fb-strict": "22.1.0",
"eslint-plugin-babel": "^5.2.1",
"eslint-plugin-flowtype": "2.43.0",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-jest": "21.8.0",
"eslint-plugin-jsx-a11y": "6.0.3",
"eslint-plugin-prettier": "2.6.0",
"eslint-plugin-react": "7.6.1",
"eslint-plugin-relay": "0.0.23",
"flow-bin": "^0.86.0",
"prettier": "^1.15.2"
},
"prettier": {
"requirePragma": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false,
"jsxBracketSameLine": true,
"parser": "flow"
}
}
98 changes: 0 additions & 98 deletions sample/HelloFacebook/index.ios.js

This file was deleted.

Expand Up @@ -25,6 +25,7 @@ const FBSDK = require('react-native-fbsdk');

import React, {Component} from 'react';
import {
Alert,
AppRegistry,
StyleSheet,
Text,
Expand All @@ -42,30 +43,26 @@ class HelloFacebook extends Component {
};

this.state = {
shareLinkContent: shareLinkContent,
shareLinkContent,
};
}

shareLinkWithShareDialog() {
var tmp = this;
ShareDialog.canShow(this.state.shareLinkContent)
.then(function(canShow) {
if (canShow) {
return ShareDialog.show(tmp.state.shareLinkContent);
async shareLinkWithShareDialog() {
const canShow = await ShareDialog.canShow(this.state.shareLinkContent);
if (canShow) {
try {
const {isCancelled, postId} = await ShareDialog.show(
this.state.shareLinkContent,
);
if (isCancelled) {
Alert.alert('Share cancelled');
} else {
Alert.alert('Share success with postId: ' + postId);
}
})
.then(
function(result) {
if (result.isCancelled) {
alert('Share cancelled');
} else {
alert('Share success');
}
},
function(error) {
alert('Share fail with error: ' + error);
},
);
} catch (error) {
Alert.alert('Share fail with error: ' + error);
}
}
}

render() {
Expand Down

0 comments on commit b675174

Please sign in to comment.