Skip to content

Commit

Permalink
converted bash scripts from live-common
Browse files Browse the repository at this point in the history
  • Loading branch information
valpinkman committed Aug 16, 2022
1 parent 348a52b commit 6304914
Show file tree
Hide file tree
Showing 29 changed files with 1,603 additions and 1,155 deletions.
7 changes: 5 additions & 2 deletions apps/ledger-live-desktop/scripts/sync-families-dispatch.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env zx
import "zx/globals";
import rimraf from "rimraf";

const basePath = path.join(__dirname, "..");
const rendererPath = path.join(basePath, "src", "renderer");
const generatedPath = path.join(rendererPath, "generated");

await fs.promises.rm(generatedPath, { recursive: true, force: true });
await fs.promises.mkdir(generatedPath);
await rimraf(generatedPath, async e => {
if (!!e) return echo(chalk.red(e));
await fs.promises.mkdir(generatedPath);
});

const families = await fs.readdir(path.join(rendererPath, "families"));
const targets = [
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"android:ci:playstore": "bundle exec fastlane android ci_playstore --env production",
"preandroid:ci:nightly": "bundle install",
"android:ci:nightly": "bundle exec fastlane android ci_nightly --env nightly",
"android:hermes:staging": "export HERMES_ENABLED_ANDROID=true && yarn android:staging",
"android:hermes:staging": "export HERMES_ENABLED_ANDROID=true && pnpm android:staging",
"android:staging": "cd android && ./gradlew assembleStagingRelease",
"android:install": "./scripts/install-and-run-apk.sh",
"android:clean": "$ANDROID_HOME/platform-tools/adb shell pm clear com.ledger.live",
Expand Down
11 changes: 7 additions & 4 deletions apps/ledger-live-mobile/scripts/post.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
#!/usr/bin/env zx
import "zx/globals";
import rimraf from "rimraf";

cd(path.join(__dirname, ".."));

const syncFamilies = async () =>
await $`zx ./scripts/sync-families-dispatch.mjs`;

const patchers = async () => {
await $`patch -N -i scripts/patches/RNFastCrypto.h.patch node_modules/react-native-fast-crypto/ios/RNFastCrypto.h &2>/dev/null`;
await $`patch -N -i scripts/patches/RNFastCrypto.h.patch node_modules/react-native-fast-crypto/ios/RNFastCrypto.h 2>/dev/null`;

// patching transitive gradle dependency
await $`patch -N -i ./scripts/patches/react-native-video.2575.patch node_modules/react-native-video/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java &2>/dev/null`;
await $`patch -N -i ./scripts/patches/react-native-video+5.2.0.patch node_modules/react-native-video/android-exoplayer/build.gradle &2>/dev/null`;
await $`patch -N -i ./scripts/patches/react-native-video.2575.patch node_modules/react-native-video/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java 2>/dev/null`;
await $`patch -N -i ./scripts/patches/react-native-video+5.2.0.patch node_modules/react-native-video/android-exoplayer/build.gradle 2>/dev/null`;

// See: https://github.com/expo/expo/issues/15622#issuecomment-997225774
// patch -N -i scripts/patches/RNAnalytics.h.patch node_modules/@segment/analytics-react-native/ios/RNAnalytics/RNAnalytics.h
};

const final = async () => {
await fs.promises.rm("third-party/glog-0.3.5/test-driver", { force: true });
rimraf("third-party/glog-0.3.5/test-driver", e => {
if (!!e) echo(chalk.red(e));
});

// Had to remove the following because we already have the AsyncSocket lib as a dependency from Flipper 🐬
// Why would anyone bundle an external lib available on CocoaPods anyway?
Expand Down
7 changes: 5 additions & 2 deletions apps/ledger-live-mobile/scripts/sync-families-dispatch.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env zx
import "zx/globals";
import rimraf from "rimraf";

const basePath = path.join(__dirname, "..", "src");
const generatedPath = path.join(basePath, "generated");

await fs.promises.rm(generatedPath, { recursive: true, force: true });
await fs.promises.mkdir(generatedPath);
await rimraf(generatedPath, async e => {
if (!!e) return echo(chalk.red(e));
await fs.promises.mkdir(generatedPath);
});

const dirContent = await fs.promises.readdir(path.join(basePath, "families"), {
withFileTypes: true,
Expand Down
4 changes: 2 additions & 2 deletions libs/ledger-live-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
},
"license": "Apache-2.0",
"scripts": {
"build": "bash ./scripts/build-ts.sh",
"watch": "bash ./scripts/watch-ts.sh",
"build": "zx ./scripts/build-ts.mjs",
"watch": "zx ./scripts/watch-ts.mjs",
"updateAppSupportsQuitApp": "node scripts/updateAppSupportsQuitApp.js",
"prettier": "prettier --write 'src/**/*.?s' 'cli/src/**/*.?s'",
"lint": "eslint src",
Expand Down
33 changes: 33 additions & 0 deletions libs/ledger-live-common/scripts/build-ts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env zx
import "zx/globals";
import rimraf from "rimraf";

cd(path.join(__dirname, ".."));

const remover = async () => {
await rimraf("lib", (e) => {
if (e) echo(chalk.red(e));
});
await rimraf("src/data/icons/react*", (e) => {
if (e) echo(chalk.red(e));
});
};

await remover();

await $`zx ./scripts/sync-families-dispatch.mjs`;

await $`node ./scripts/buildReactIcons.js`;
await $`node ./scripts/buildReactFlags.js`;

const prefix = $.prefix;

within(async () => {
$.prefix = prefix;
await $`NODE_ENV=production pnpm tsc --project src/tsconfig.json`;
});

within(async () => {
$.prefix = prefix;
await $`NODE_ENV=production pnpm tsc --project src/tsconfig.json -m ES6 --outDir lib-es`;
});
19 changes: 0 additions & 19 deletions libs/ledger-live-common/scripts/build-ts.sh

This file was deleted.

15 changes: 0 additions & 15 deletions libs/ledger-live-common/scripts/build.sh

This file was deleted.

143 changes: 143 additions & 0 deletions libs/ledger-live-common/scripts/sync-families-dispatch.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/usr/bin/env zx
import "zx/globals";
import rimraf from "rimraf";

const targets = [
"customAddressValidation.ts",
"hw-getAddress.ts",
"hw-signMessage.ts",
"transaction.ts",
"bridge/js.ts",
"bridge/mock.ts",
"cli-transaction.ts",
"specs.ts",
"speculos-deviceActions.ts",
"deviceTransactionConfig.ts",
"mock.ts",
"account.ts",
"exchange.ts",
"presync.ts",
"platformAdapter.ts",
];

cd(path.join(__dirname, "..", "src"));
rimraf.sync("generated");
await fs.promises.mkdir("generated");
await fs.promises.mkdir("generated/bridge");

const families = (
await fs.promises.readdir("families", { withFileTypes: true })
)
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);

async function genTarget(targets, families) {
targets.forEach(async (target) => {
const imprtTarget = target.replace(".ts", "");
const outpath = path.join("generated", target);
let imports = ``;
let exprts = `export default {`;

for (const family of families) {
if (fs.existsSync(path.join("families", family, target))) {
const subPath = target.split("/");
let rewind = "../";
if (subPath.length >= 2) {
let subs = subPath.length / 2;
while (subs > 0) {
rewind += "../";
subs--;
}
}
imports += `import ${family} from "${rewind}families/${family}/${imprtTarget}";
`;
exprts += `
${family},`;
}
}

exprts += `
};
`;

const str = `${imports}
${exprts}`;

await fs.promises.writeFile(outpath, str, "utf8");
});
}

async function getDeviceTransactionConfig(families) {
const outpath = path.join("generated", "deviceTransactionConfig.ts");
let imports = ``;
let exprts = `export type ExtraDeviceTransactionField =`;
for (const family of families) {
const p = path.join("families", family, "deviceTransactionConfig.ts");
if (fs.existsSync(p)) {
const file = await fs.promises.readFile(p, "utf8");
const hasExports = file.includes(
"export type ExtraDeviceTransactionField"
);
if (hasExports) {
imports += `import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_${family} } from "../families/${family}/deviceTransactionConfig";
`;
exprts += `
| ExtraDeviceTransactionField_${family}`;
}
}
}

const str = `${imports}
${exprts};
`;

await fs.promises.appendFile(outpath, str, "utf8");
}

async function genTypesFile(families) {
const outpath = path.join("generated", "types.ts");
let imprts = ``;
let exprtsT = `export type Transaction =`;
let exprtsTRaw = `export type TransactionRaw =`;
let exprtsStatus = `export type TransactionStatus =`;
let exprtsStatusRaw = `export type TransactionStatusRaw =`;
for (const family of families) {
imprts += `import { Transaction as ${family}Transaction } from "../families/${family}/types";
import { TransactionRaw as ${family}TransactionRaw } from "../families/${family}/types";
import { TransactionStatus as ${family}TransactionStatus } from "../families/${family}/types;
import { TransactionStatusRaw as ${family}TransactionStatusRaw } from "../families/${family}/types;
`;
exprtsT += `
| ${family}Transaction`;

exprtsTRaw += `
| ${family}TransactionRaw`;

exprtsStatus += `
| ${family}TransactionStatus`;

exprtsStatusRaw += `
| ${family}TransactionStatusRaw`;
}

exprtsT += `;
`;
exprtsTRaw += `;
`;
exprtsStatus += `;
`;
exprtsStatusRaw += `;
`;

const str = `${imprts}
${exprtsT}
${exprtsTRaw}
${exprtsStatus}
${exprtsStatusRaw}`;

await fs.promises.writeFile(outpath, str, "utf8");
}

await genTarget(targets, families);
await genTypesFile(families);
await getDeviceTransactionConfig(families);
Loading

0 comments on commit 6304914

Please sign in to comment.