-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from iuricmp/lint
Adding Prettier
- Loading branch information
Showing
29 changed files
with
2,388 additions
and
1,439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.pb.* | ||
*.gen.* | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module.exports = { | ||
root: true, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'@react-native', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint', 'import'], | ||
rules: { | ||
'prettier/prettier': 0, | ||
semi: ['error', 'never'], | ||
'@typescript-eslint/quotes': ['error', 'single'], | ||
quotes: ['error', 'single'], | ||
'react-native/no-inline-styles': 0, | ||
'jsx-quotes': ['error', 'prefer-single'], | ||
'no-shadow': 0, | ||
'no-catch-shadow': 0, | ||
indent: ['error', 2], | ||
'no-mixed-spaces-and-tabs': ['error', 'smart-tabs'], | ||
'react/react-in-jsx-scope': 2, | ||
'@typescript-eslint/no-explicit-any': 'warn', | ||
'@typescript-eslint/ban-ts-comment': 'warn', | ||
'import/order': [ | ||
'error', | ||
{ | ||
groups: [ | ||
['builtin', 'external'], | ||
'internal', | ||
['sibling', 'parent', 'index'], | ||
'object', | ||
'type', | ||
], | ||
pathGroups: [ | ||
{ | ||
pattern: '@berty/**', | ||
group: 'internal', | ||
position: 'before', | ||
}, | ||
], | ||
pathGroupsExcludedImportTypes: [], | ||
'newlines-between': 'always', | ||
alphabetize: { | ||
order: 'asc', | ||
caseInsensitive: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
globals: { | ||
JSX: 'readonly', | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
# Cache | ||
.cache | ||
.eslintcache | ||
|
||
# VSCode | ||
.vscode/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
module.exports = { | ||
branch: 'main', | ||
plugins: [ | ||
'@semantic-release/commit-analyzer', | ||
'@semantic-release/release-notes-generator', | ||
'@semantic-release/github', | ||
], | ||
branch: 'main', | ||
plugins: [ | ||
'@semantic-release/commit-analyzer', | ||
'@semantic-release/release-notes-generator', | ||
'@semantic-release/github', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
import { useState, useEffect } from 'react'; | ||
import * as WeshnetExpo from '@weshnet/expo'; | ||
import * as WeshnetExpo from '@weshnet/expo' | ||
import React, { useState, useEffect } from 'react' | ||
import { StyleSheet, Text, View } from 'react-native' | ||
|
||
export default function App() { | ||
const [peerID, setPeerID] = useState<string>() | ||
const [peerID, setPeerID] = useState<string>() | ||
|
||
useEffect(() => { | ||
WeshnetExpo.init().then(client => { | ||
client.serviceGetConfiguration({}).then((res) => { | ||
setPeerID(res.peerId) | ||
console.log(res) | ||
}) | ||
}) | ||
}, []) | ||
useEffect(() => { | ||
WeshnetExpo.init().then((client) => { | ||
client.serviceGetConfiguration({}).then((res) => { | ||
setPeerID(res.peerId) | ||
console.log(res) | ||
}) | ||
}) | ||
}, []) | ||
|
||
const loadingView = (<Text> Loading Weshnet... </Text>) | ||
const weshView = (<Text>hello my peerid is: {peerID}</Text>) | ||
return ( | ||
<View style={styles.container}> | ||
{!peerID ? loadingView : weshView} | ||
</View> | ||
); | ||
const loadingView = <Text> Loading Weshnet... </Text> | ||
const weshView = <Text>hello my peerid is: {peerID}</Text> | ||
return ( | ||
<View style={styles.container}>{!peerID ? loadingView : weshView}</View> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: '#fff', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}); | ||
container: { | ||
flex: 1, | ||
backgroundColor: '#fff', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { registerRootComponent } from 'expo'; | ||
import { registerRootComponent } from 'expo' | ||
|
||
import App from './App'; | ||
import App from './App' | ||
|
||
// registerRootComponent calls AppRegistry.registerComponent('main', () => App); | ||
// It also ensures that whether you load the app in Expo Go or in a native build, | ||
// the environment is set up appropriately | ||
registerRootComponent(App); | ||
registerRootComponent(App) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
// Learn more https://docs.expo.io/guides/customizing-metro | ||
const { getDefaultConfig } = require('expo/metro-config'); | ||
const path = require('path'); | ||
const { getDefaultConfig } = require('expo/metro-config') /* eslint-disable-line @typescript-eslint/no-var-requires */ | ||
const path = require('path') /* eslint-disable-line @typescript-eslint/no-var-requires */ | ||
|
||
const config = getDefaultConfig(__dirname); | ||
const config = getDefaultConfig(__dirname) | ||
|
||
// npm v7+ will install ../node_modules/react-native because of peerDependencies. | ||
// To prevent the incompatible react-native bewtween ./node_modules/react-native and ../node_modules/react-native, | ||
// excludes the one from the parent folder when bundling. | ||
config.resolver.blockList = [ | ||
...Array.from(config.resolver.blockList ?? []), | ||
new RegExp(path.resolve('..', 'node_modules', 'react-native')), | ||
]; | ||
] | ||
|
||
config.resolver.nodeModulesPaths = [ | ||
path.resolve(__dirname, './node_modules'), | ||
path.resolve(__dirname, '../node_modules'), | ||
]; | ||
] | ||
|
||
config.watchFolders = [path.resolve(__dirname, '..')]; | ||
config.watchFolders = [path.resolve(__dirname, '..')] | ||
|
||
config.transformer.getTransformOptions = async () => ({ | ||
transform: { | ||
experimentalImportSupport: false, | ||
inlineRequires: true, | ||
}, | ||
}); | ||
}) | ||
|
||
module.exports = config | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,82 @@ | ||
import pbjs from 'protobufjs'; | ||
import Handlebars from 'handlebars'; | ||
import Handlebars from 'handlebars' | ||
import pbjs from 'protobufjs' | ||
|
||
// Load Protocol Buffer from specified .proto file | ||
const pb = pbjs.loadSync('api/protocoltypes.proto'); | ||
const pb = pbjs.loadSync('api/protocoltypes.proto') | ||
|
||
// Function to decapitalize the first letter of a string | ||
const uncap = (str) => str.charAt(0).toLowerCase() + str.slice(1); | ||
const uncap = (str) => str.charAt(0).toLowerCase() + str.slice(1) | ||
|
||
const getInterface = (typ) => { | ||
const parts = typ.split('.'); | ||
const ilast = `I${parts.pop()}`; | ||
parts.push(ilast); | ||
return parts.join('.'); | ||
const parts = typ.split('.') | ||
const ilast = `I${parts.pop()}` | ||
parts.push(ilast) | ||
return parts.join('.') | ||
} | ||
|
||
// Define an array of services | ||
const services = [ | ||
'weshnet.protocol.v1.ProtocolService', | ||
]; | ||
const services = ['weshnet.protocol.v1.ProtocolService'] | ||
|
||
// Prepare Handlebars templates | ||
const serviceClientTemplate = Handlebars.compile(` | ||
import api from './api/index.d' | ||
import { Unary, ResponseStream, RequestStream } from './types' | ||
export type ServiceClientType<S> = {{#each services}} {{this}} {{/each}}never; | ||
`); | ||
`) | ||
|
||
const ClientTemplate = Handlebars.compile(` | ||
export interface {{name}}Client { | ||
{{#each methods}} | ||
{{this.name}}: {{this.type}}<api.{{this.svcName}}.{{this.request}}, api.{{this.svcName}}.{{this.reply}}>, | ||
{{/each}} | ||
} | ||
`); | ||
`) | ||
|
||
// Gather data for ServiceClientType | ||
let serviceData = { | ||
services: services.map(svcType => { | ||
const svc = pb.lookup(svcType); | ||
return `S extends typeof api.${svc.parent.parent.name}.${svc.name} ? ${svc.name}Client :`; | ||
}) | ||
}; | ||
services: services.map((svcType) => { | ||
const svc = pb.lookup(svcType) | ||
return `S extends typeof api.${svc.parent.parent.name}.${svc.name} ? ${svc.name}Client :` | ||
}), | ||
} | ||
|
||
// Generate and output ServiceClientType | ||
console.log(serviceClientTemplate(serviceData)); | ||
console.log(serviceClientTemplate(serviceData)) | ||
|
||
// Gather data for each Client and output | ||
for (const svcType of services) { | ||
const svc = pb.lookup(svcType); | ||
const svc = pb.lookup(svcType) | ||
const methodsData = Object.entries(svc.methods).map(([key, method]) => { | ||
let rpcType = ''; | ||
let rpcType = '' | ||
if (!method.requestStream && !method.responseStream) { | ||
// Unary | ||
rpcType = 'Unary'; | ||
rpcType = 'Unary' | ||
} else if (method.requestStream && !method.responseStream) { | ||
// Request Stream | ||
rpcType = 'RequestStream'; | ||
rpcType = 'RequestStream' | ||
} else if (!method.requestStream && method.responseStream) { | ||
// Response Stream | ||
rpcType = 'ResponseStream'; | ||
rpcType = 'ResponseStream' | ||
} else { | ||
// Dubplex | ||
rpcType = 'never'; | ||
rpcType = 'never' | ||
} | ||
|
||
const name = uncap(key); | ||
const name = uncap(key) | ||
return { | ||
name: name, | ||
request: getInterface(method.requestType), | ||
reply: method.responseType, | ||
type: rpcType, | ||
svcName: `${svc.parent.parent.name}`, | ||
}; | ||
}); | ||
} | ||
}) | ||
|
||
let ClientData = { | ||
name: svc.name, | ||
methods: methodsData, | ||
}; | ||
} | ||
|
||
console.log(ClientTemplate(ClientData)); | ||
console.log(ClientTemplate(ClientData)) | ||
} |
Oops, something went wrong.