From 2ff3438e9ea9bb8672518b846424fed103fb825b Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 20 Jun 2018 15:30:59 +0200 Subject: [PATCH 1/3] Remove useless script, rename some other --- scripts/{hey.js => live-cli.js} | 4 ++ scripts/parse-accounts.js | 6 +-- scripts/trans.js | 71 --------------------------------- 3 files changed, 7 insertions(+), 74 deletions(-) rename scripts/{hey.js => live-cli.js} (95%) delete mode 100755 scripts/trans.js diff --git a/scripts/hey.js b/scripts/live-cli.js similarity index 95% rename from scripts/hey.js rename to scripts/live-cli.js index 4c361809..b08b40c4 100644 --- a/scripts/hey.js +++ b/scripts/live-cli.js @@ -1,3 +1,7 @@ +// This is a work in progress +// The goal is to provide a cli which allow interact +// with device & libcore for faster iterations + require('babel-polyfill') require('babel-register') diff --git a/scripts/parse-accounts.js b/scripts/parse-accounts.js index 4a9d2d77..f5b0b8c2 100644 --- a/scripts/parse-accounts.js +++ b/scripts/parse-accounts.js @@ -1,6 +1,6 @@ -// Utility to human-read the accounts.json file -// You have to pass it in parameter, because the location -// differ depending on the OS. +// Utility to human-read the accounts.json file +// You have to pass it in parameter, because the location +// differ depending on the OS. const { formatCurrencyUnit, diff --git a/scripts/trans.js b/scripts/trans.js deleted file mode 100755 index d519a6ba..00000000 --- a/scripts/trans.js +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env node - -/* eslint-disable no-console */ -/* eslint-disable no-use-before-define */ - -require('dotenv').config() - -const path = require('path') -const fs = require('fs') -const axios = require('axios') -const querystring = require('querystring') -const forEach = require('lodash/forEach') -const objectPath = require('object-path') -const yaml = require('js-yaml') -const chalk = require('chalk') - -const { LOKALISE_TOKEN, LOKALISE_PROJECT } = process.env -const BASE = 'https://api.lokalise.co/api' - -const stats = { - nb: 0, -} - -main() - -async function main() { - try { - console.log(`${chalk.blue('[>]')} ${chalk.dim('Fetching translations...')}`) - const url = `${BASE}/string/list` - const { data } = await axios.post( - url, - querystring.stringify({ - api_token: LOKALISE_TOKEN, - id: LOKALISE_PROJECT, - }), - ) - if (data.response.status === 'error') { - throw new Error(JSON.stringify(data.response)) - } - const { strings } = data - forEach(strings, syncLanguage) - console.log( - `${chalk.blue('[>]')} ${chalk.dim('Successfully imported')} ${stats.nb} ${chalk.dim( - 'translations', - )}`, - ) - } catch (err) { - console.log(err) - console.log(`${chalk.red('[x] Error in the process')}`) - process.exit(1) - } -} - -function syncLanguage(translations, language) { - const folderPath = getLanguageFolderPath(language) - const filePath = path.resolve(folderPath, 'translation.yml') - if (!fs.existsSync(folderPath)) { - fs.mkdirSync(folderPath) - } - const obj = translations.reduce((acc, cur) => { - objectPath.set(acc, cur.key, cur.translation) - console.log(`${chalk.green('[✓]')} ${language} ${chalk.dim(cur.key)}`) - ++stats.nb - return acc - }, {}) - fs.writeFileSync(filePath, yaml.dump(obj)) -} - -function getLanguageFolderPath(language) { - return path.resolve(__dirname, `../static/i18n/${language}`) -} From aad226e46040489128abe2c4f76e1f504587a127 Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 20 Jun 2018 16:46:28 +0200 Subject: [PATCH 2/3] Optimize postinstall script --- scripts/postinstall.sh | 67 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh index bb75d776..471afd51 100755 --- a/scripts/postinstall.sh +++ b/scripts/postinstall.sh @@ -1,8 +1,65 @@ #/bin/bash -flow-typed install -s --overwrite -rm flow-typed/npm/{react-i18next_v7.x.x.js,styled-components_v3.x.x.js,redux_*} +function MAIN { + REBUILD_ELECTRON_NATIVE_DEPS + INSTALL_FLOW_TYPED +} -if [ "$SKIP_REBUILD" != "1" ]; then - electron-builder install-app-deps -fi +function GET_HASH_PATH { + HASH_NAME=$1 + echo "./node_modules/.cache/LEDGER_HASH_$HASH_NAME" +} + +function GET_HASH { + HASH_NAME=$1 + HASH_PATH=`GET_HASH_PATH $HASH_NAME` + if [ ! -e "$HASH_PATH" ]; then + echo '' + else + HASH_CONTENT=`cat "$HASH_PATH"` + echo $HASH_CONTENT + fi +} + +function SET_HASH { + HASH_NAME=$1 + HASH_CONTENT=$2 + echo "setting hash $HASH_NAME to $HASH_CONTENT" + HASH_PATH=`GET_HASH_PATH $HASH_NAME` + mkdir -p ./node_modules/.cache + echo $HASH_CONTENT > $HASH_PATH +} + +function INSTALL_FLOW_TYPED { + LATEST_FLOW_TYPED_COMMIT_HASH=`curl --silent --header "Accept: application/vnd.github.VERSION.sha" https://api.github.com/repos/flowtype/flow-typed/commits/master` + CURRENT_FLOW_TYPED_HASH=`GET_HASH 'flow-typed'` + if [ "$LATEST_FLOW_TYPED_COMMIT_HASH" == "$CURRENT_FLOW_TYPED_HASH" ]; then + echo "> Flow-typed definitions are up to date. Skipping" + else + echo "> Installing flow-typed defs" + flow-typed install -s --overwrite + echo "> Removing broken flow definitions" + rm flow-typed/npm/{react-i18next_v7.x.x.js,styled-components_v3.x.x.js,redux_*} + SET_HASH 'flow-typed' $LATEST_FLOW_TYPED_COMMIT_HASH + fi +} + +function REBUILD_ELECTRON_NATIVE_DEPS { + # for strange/fancy os-es + if [[ `uname` == 'Darwin' ]]; then + PACKAGE_JSON_HASH=`md5 package.json | cut -d ' ' -f 1` + else + # for normal os-es + PACKAGE_JSON_HASH=`md5sum package.json | cut -d ' ' -f 1` + fi + CACHED_PACKAGE_JSON_HASH=`GET_HASH 'package.json'` + if [ "$CACHED_PACKAGE_JSON_HASH" == "$PACKAGE_JSON_HASH" ]; then + echo "> Electron native deps are up to date. Skipping" + else + echo "> Installing electron native deps" + electron-builder install-app-deps + SET_HASH 'package.json' $PACKAGE_JSON_HASH + fi +} + +MAIN From a5661230fc47926b40295ce4ae8cfdcc5c73350d Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 20 Jun 2018 17:09:35 +0200 Subject: [PATCH 3/3] Prevent flow from trying to parse hash as json --- scripts/postinstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh index 471afd51..2eaa9447 100755 --- a/scripts/postinstall.sh +++ b/scripts/postinstall.sh @@ -7,7 +7,7 @@ function MAIN { function GET_HASH_PATH { HASH_NAME=$1 - echo "./node_modules/.cache/LEDGER_HASH_$HASH_NAME" + echo "./node_modules/.cache/LEDGER_HASH_$HASH_NAME.hash" } function GET_HASH {