Go get and Fork – script helper workaround

Why

If you write some Golang code, from my point of view, one of biggest pitfall of this language is dependency management.

At the beginning, get library directly from git repository seems a good idea, but between package rules, versions, your pull requests, it becomes a mess quickly.

Some sources on this problem:
Article: Forking Golang repositories on GitHub and managing the import path

StackOverflow : Using forked package import in Go

My workaround

Then, why not automate this procedure ?
In your .bashrc add:

function gofork() {
  if [ $# -ne 2 ] || [ -z "$1" ] || [ -z "$2" ]; then
    echo 'Usage: gofork yourFork originalModule'
    echo 'Example: golang github.com/YourName/go-contrib github.com/heirko/go-contrib'
    return
  fi
   echo "Go get fork $1 and replace $2 in GOPATH: $GOPATH"
   go get $1
   go get $2
   currentDir=$PWD
   cd $GOPATH/src/$1
   remote1=$(git config --get remote.origin.url)
   cd $GOPATH/src/$2
   remote2=$(git config --get remote.origin.url)
   cd $currentDir
   rm -rf $GOPATH/src/$2
   mv $GOPATH/src/$1 $GOPATH/src/$2
   cd $GOPATH/src/$2
   git remote add their $remote2
   echo Now in $GOPATH/src/$2 origin remote is $remote1
   echo And in $GOPATH/src/$2 their remote is $remote2
   cd $currentDir
}

export -f gofork

This command do

  • a ‘go get’ on source and fork repositories
  • extract remote urls
  • replace source code by fork
  • add source remote to your fork repository in case you want pull from source

You can call this script from command line or directly from a script like this:

gofork github.com/heralight/baloo gopkg.in/h2non/baloo.v2

Npm et yarn – quelques fonctions utiles

Lister tout les paquets premier niveau

Npm

npm list -g --depth=0

Yarn

yarn global ls

ajout global

Npm

npm -g install pkg

Yarn

yarn global add pkg

Tutoriel Facebook Buck avec React Native

Nous allons détailler la procédure pour développer avec React Native et compiler efficacement avec Buck sous Linux.

Prérequis

  • Node.js en v5.5 de préférence installer avec NVM
  • android studio ou intellij (sous ubuntu, utilisez umake android)
  • android sdk + platform + API 23 et votre environnement bien paramétré, par exemple dans votre .bashrc:
export ANDROID_HOME="/opt/softs/androidSdk"
export PATH="$PATH:/opt/softs/androidSdk/platform-tools"

Installation

React Native

Documentation

npm install -g react-native-cli

watchman

Documentation

git clone https://github.com/facebook/watchman.git
cd watchman
git checkout v4.7.0  # the latest stable release
./autogen.sh
./configure
make
sudo make install

Buck

git clone https://github.com/facebook/buck.git
cd buck
ant
#./bin/buck --help
ln -s ${PWD}/bin/buck ${HOME}/bin/buck

Création du projet

dans un de vos répertoires, par exemple ~/dev

react-native init AwesomeProject 
cd AwesomeProject 
react-native run-android

Si vous avez correctement configurer votre sdk pour android vous devriez voir votre application déployée et executée sur votre émulateur.

Maintenant SUPPRIMER l’application de votre émulateur afin d’éviter les conflits entre les signatures gradle et buck.

ajout et configuration de BUCK

cd android`
keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"
./gradlew :app:copyDownloadableDepsToLibs

la commande gradle rend les dépendances Gradle disponible pour Buck

Lancement

dans un terminal lancez le packager à la racine du projet:

npm start

compilez, installez et lancez avec buck:

cd android
buck install -r android/app