From f6b6569164492339fd82519fa3b2b232fe641fa0 Mon Sep 17 00:00:00 2001 From: Konsta Purtsi Date: Mon, 19 Aug 2024 10:22:14 +0300 Subject: [PATCH] chore: use prettier to format more things. --- .github/workflows/nodejs.yml | 4 +- .prettierignore | 5 ++ .prettierrc.mjs | 4 +- astro.config.mjs | 12 +-- initialize.js | 170 ++++++++++++++++++----------------- package.json | 6 +- tailwind.config.mjs | 12 +-- tsconfig.json | 6 +- 8 files changed, 116 insertions(+), 103 deletions(-) create mode 100644 .prettierignore diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index dac3e67d..559cfe45 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -23,5 +23,5 @@ jobs: node-version: 22.6.0 cache: 'npm' - run: npm ci - - run: npm run prettier:check - - run: npm run biome:check + - run: npm run lint:check + - run: npm run format:check diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..fd590b10 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +node_modules/ +build/ +dist/ +contracts/ +package-lock.json diff --git a/.prettierrc.mjs b/.prettierrc.mjs index 8e7305ed..d2bba3d3 100644 --- a/.prettierrc.mjs +++ b/.prettierrc.mjs @@ -16,7 +16,7 @@ const config = { singleQuote: true, jsxSingleQuote: false, bracketSpacing: true, - semi: true -} + semi: true, +}; export default config; diff --git a/astro.config.mjs b/astro.config.mjs index e9ca9d81..62bb3732 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,16 +1,16 @@ import { defineConfig } from 'astro/config'; import basicSsl from '@vitejs/plugin-basic-ssl'; -import react from "@astrojs/react"; +import react from '@astrojs/react'; -import tailwind from "@astrojs/tailwind"; +import tailwind from '@astrojs/tailwind'; // https://astro.build/config export default defineConfig({ vite: { plugins: [basicSsl()], server: { - https: true - } + https: true, + }, }, - integrations: [react(), tailwind()] -}); \ No newline at end of file + integrations: [react(), tailwind()], +}); diff --git a/initialize.js b/initialize.js index d063b4f8..c4b8d531 100644 --- a/initialize.js +++ b/initialize.js @@ -1,15 +1,15 @@ -import 'dotenv/config' -import { mkdirSync, readdirSync, statSync, writeFileSync } from 'fs' -import { execSync } from 'child_process' -import path from 'path' -import { fileURLToPath } from 'url' -import crypto from 'crypto' +import 'dotenv/config'; +import { mkdirSync, readdirSync, statSync, writeFileSync } from 'fs'; +import { execSync } from 'child_process'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import crypto from 'crypto'; // Load environment variables starting with PUBLIC_ into the environment, // so we don't need to specify duplicate variables in .env for (const key in process.env) { if (key.startsWith('PUBLIC_')) { - process.env[key.substring(7)] = process.env[key] + process.env[key.substring(7)] = process.env[key]; } } @@ -20,53 +20,55 @@ const GENESIS_ACCOUNTS = { public: 'GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7', testnet: 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H', futurenet: 'GADNDFP7HM3KFVHOQBBJDBGRONMKQVUYKXI6OYNDMS2ZIK7L6HA3F2RF', - standalone: 'GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI' -} + standalone: 'GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI', +}; -console.log('###################### Initializing ########################') +console.log('###################### Initializing ########################'); // Get dirname (equivalent to the Bash version) -const __filename = fileURLToPath(import.meta.url) -const dirname = path.dirname(__filename) +const __filename = fileURLToPath(import.meta.url); +const dirname = path.dirname(__filename); // variable for later setting pinned version of soroban in "$(dirname/target/bin/soroban)" -const soroban = 'soroban' +const soroban = 'soroban'; // Function to execute and log shell commands -function exe (command) { - console.log(command) - execSync(command, { stdio: 'inherit' }) +function exe(command) { + console.log(command); + execSync(command, { stdio: 'inherit' }); } -function fundAll () { - exe(`${soroban} keys generate ${process.env.SOROBAN_ACCOUNT}`) - exe(`${soroban} keys fund ${process.env.SOROBAN_ACCOUNT}`) +function fundAll() { + exe(`${soroban} keys generate ${process.env.SOROBAN_ACCOUNT}`); + exe(`${soroban} keys fund ${process.env.SOROBAN_ACCOUNT}`); } -function buildAll () { - exe(`rm -f ${dirname}/target/wasm32-unknown-unknown/release/*.wasm`) - exe(`rm -f ${dirname}/target/wasm32-unknown-unknown/release/*.d`) +function buildAll() { + exe(`rm -f ${dirname}/target/wasm32-unknown-unknown/release/*.wasm`); + exe(`rm -f ${dirname}/target/wasm32-unknown-unknown/release/*.d`); // Tokens has to be built before others. - exe(`${soroban} contract build --package token`) + exe(`${soroban} contract build --package token`); // Then loan_pool as loan_pool uses it - exe(`${soroban} contract build --package loan_pool`) - exe(`${soroban} contract build`) + exe(`${soroban} contract build --package loan_pool`); + exe(`${soroban} contract build`); } -function filenameNoExtension (filename) { - return path.basename(filename, path.extname(filename)) +function filenameNoExtension(filename) { + return path.basename(filename, path.extname(filename)); } -function deploy (wasm) { - exe(`(${soroban} contract deploy --wasm ${wasm} --ignore-checks) > ${dirname}/.soroban/contract-ids/${filenameNoExtension(wasm)}.txt`) +function deploy(wasm) { + exe( + `(${soroban} contract deploy --wasm ${wasm} --ignore-checks) > ${dirname}/.soroban/contract-ids/${filenameNoExtension(wasm)}.txt`, + ); } -function deployFactory () { - const contractsDir = `${dirname}/.soroban/contract-ids` - mkdirSync(contractsDir, { recursive: true }) +function deployFactory() { + const contractsDir = `${dirname}/.soroban/contract-ids`; + mkdirSync(contractsDir, { recursive: true }); // try to deploy only factory contract that will be used to generate others. Maybe later it has to be some sort of admin contract? - deploy(`${dirname}/target/wasm32-unknown-unknown/release/factory.wasm`) + deploy(`${dirname}/target/wasm32-unknown-unknown/release/factory.wasm`); // Deploy loans contract as there will only be one for all // deploy(`${dirname}/target/wasm32-unknown-unknown/release/loans.wasm`) @@ -77,64 +79,72 @@ function deployFactory () { // }); } -function install (wasm) { +function install(wasm) { // Contract installer - exe(`(${soroban} contract install --wasm ${wasm} --ignore-checks) > ${dirname}/.soroban/contract-wasm-hash/${filenameNoExtension(wasm)}.txt`) + exe( + `(${soroban} contract install --wasm ${wasm} --ignore-checks) > ${dirname}/.soroban/contract-wasm-hash/${filenameNoExtension(wasm)}.txt`, + ); } -function installAll () { +function installAll() { // Install all contracts except factory and save the wasm hash to .soroban - const contractsDir = `${dirname}/.soroban/contract-wasm-hash` - mkdirSync(contractsDir, { recursive: true }) + const contractsDir = `${dirname}/.soroban/contract-wasm-hash`; + mkdirSync(contractsDir, { recursive: true }); const wasmFiles = readdirSync(`${dirname}/target/wasm32-unknown-unknown/release`) - .filter(file => file.endsWith('.wasm')) - .filter(file => file !== 'factory.wasm') + .filter((file) => file.endsWith('.wasm')) + .filter((file) => file !== 'factory.wasm'); - wasmFiles.forEach(wasmFile => { - install(`${dirname}/target/wasm32-unknown-unknown/release/${wasmFile}`) - }) + wasmFiles.forEach((wasmFile) => { + install(`${dirname}/target/wasm32-unknown-unknown/release/${wasmFile}`); + }); } -function deployLpWithFactory () { +function deployLpWithFactory() { // Deploy liquidity pool with factory contract // Read values of parameters const contractId = execSync(`cat ${dirname}/.soroban/contract-ids/factory.txt`).toString().trim(); const wasmHash = execSync(`cat ${dirname}/.soroban/contract-wasm-hash/loan_pool.txt`).toString().trim(); const shareTokenBytes = execSync(`cat ${dirname}/.soroban/contract-wasm-hash/token.txt`).toString().trim(); - const xlmTokenAddress = "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC" - const usdcTokenAddress = "CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA" + const xlmTokenAddress = 'CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC'; + const usdcTokenAddress = 'CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA'; // Generate salt const salt1 = crypto.randomBytes(32).toString('hex'); const salt2 = crypto.randomBytes(32).toString('hex'); - exe(`${soroban} contract invoke --id ${contractId} --source-account alice --network testnet -- deploy --wasm_hash ${wasmHash} --salt ${salt1} --init_fn initialize --token_wasm_hash ${shareTokenBytes} --token_contract ${xlmTokenAddress} | tr -d '"' > ${dirname}/.soroban/contract-ids/loan_pool.txt`); - exe(`${soroban} contract invoke --id ${contractId} --source-account alice --network testnet -- deploy --wasm_hash ${wasmHash} --salt ${salt2} --init_fn initialize --token_wasm_hash ${shareTokenBytes} --token_contract ${usdcTokenAddress} | tr -d '"' > ${dirname}/.soroban/contract-ids/usdc_pool.txt`); + exe( + `${soroban} contract invoke --id ${contractId} --source-account alice --network testnet -- deploy --wasm_hash ${wasmHash} --salt ${salt1} --init_fn initialize --token_wasm_hash ${shareTokenBytes} --token_contract ${xlmTokenAddress} | tr -d '"' > ${dirname}/.soroban/contract-ids/loan_pool.txt`, + ); + exe( + `${soroban} contract invoke --id ${contractId} --source-account alice --network testnet -- deploy --wasm_hash ${wasmHash} --salt ${salt2} --init_fn initialize --token_wasm_hash ${shareTokenBytes} --token_contract ${usdcTokenAddress} | tr -d '"' > ${dirname}/.soroban/contract-ids/usdc_pool.txt`, + ); } -function bind (contract) { - const filenameNoExt = filenameNoExtension(contract) - exe(`${soroban} contract bindings typescript --contract-id $(cat ${contract}) --output-dir ${dirname}/packages/${filenameNoExt} --overwrite`) +function bind(contract) { + const filenameNoExt = filenameNoExtension(contract); + exe( + `${soroban} contract bindings typescript --contract-id $(cat ${contract}) --output-dir ${dirname}/packages/${filenameNoExt} --overwrite`, + ); } -function bindAll () { - const contractIdsDir = `${dirname}/.soroban/contract-ids` - const contractFiles = readdirSync(contractIdsDir) +function bindAll() { + const contractIdsDir = `${dirname}/.soroban/contract-ids`; + const contractFiles = readdirSync(contractIdsDir); - contractFiles.forEach(contractFile => { - const contractPath = path.join(contractIdsDir, contractFile) + contractFiles.forEach((contractFile) => { + const contractPath = path.join(contractIdsDir, contractFile); if (statSync(contractPath).size > 0) { // Check if file is not empty - bind(contractPath) + bind(contractPath); } - }) + }); } -function importContract (contract) { - const filenameNoExt = filenameNoExtension(contract) - const outputDir = `${dirname}/src/contracts/` - mkdirSync(outputDir, { recursive: true }) +function importContract(contract) { + const filenameNoExt = filenameNoExtension(contract); + const outputDir = `${dirname}/src/contracts/`; + mkdirSync(outputDir, { recursive: true }); /* eslint-disable quotes */ /* eslint-disable no-constant-condition */ @@ -146,33 +156,33 @@ function importContract (contract) { ` rpcUrl,\n` + `${process.env.SOROBAN_NETWORK === 'local' || 'standalone' ? ` allowHttp: true,\n` : null}` + ` publicKey: '${GENESIS_ACCOUNTS[process.env.SOROBAN_NETWORK]}',\n` + - `});\n` + `});\n`; /* eslint-disable no-constant-condition */ /* eslint-enable quotes */ - const outputPath = `${outputDir}/${filenameNoExt}.ts` - writeFileSync(outputPath, importContent) - console.log(`Created import for ${filenameNoExt}`) + const outputPath = `${outputDir}/${filenameNoExt}.ts`; + writeFileSync(outputPath, importContent); + console.log(`Created import for ${filenameNoExt}`); } -function importAll () { - const contractIdsDir = `${dirname}/.soroban/contract-ids` - const contractFiles = readdirSync(contractIdsDir) +function importAll() { + const contractIdsDir = `${dirname}/.soroban/contract-ids`; + const contractFiles = readdirSync(contractIdsDir); - contractFiles.forEach(contractFile => { - const contractPath = path.join(contractIdsDir, contractFile) + contractFiles.forEach((contractFile) => { + const contractPath = path.join(contractIdsDir, contractFile); if (statSync(contractPath).size > 0) { // Check if file is not empty - importContract(contractPath) + importContract(contractPath); } - }) + }); } // Calling the functions (equivalent to the last part of your bash script) -fundAll() -buildAll() -deployFactory() -installAll() -deployLpWithFactory() -bindAll() -importAll() +fundAll(); +buildAll(); +deployFactory(); +installAll(); +deployLpWithFactory(); +bindAll(); +importAll(); diff --git a/package.json b/package.json index 5b48dca4..a09c2706 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,9 @@ "start": "npm run init && astro dev", "continue": "astro dev", "lint": "biome check --write ./src", - "format": "prettier --write ./src", - "prettier:check": "prettier --check ./src", - "biome:check": "biome check ./src" + "lint:check": "biome check ./src", + "format": "prettier --write \"**/*.{js,mjs,jsx,ts,tsx,json,graphql,css,astro,md}\"", + "format:check": "prettier --check \"**/*.{js,mjs,jsx,ts,tsx,json,graphql,css,astro,md}\"" }, "type": "module", "version": "0.0.1", diff --git a/tailwind.config.mjs b/tailwind.config.mjs index 19f0614d..83cac5e7 100644 --- a/tailwind.config.mjs +++ b/tailwind.config.mjs @@ -1,8 +1,8 @@ /** @type {import('tailwindcss').Config} */ export default { - content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'], - theme: { - extend: {}, - }, - plugins: [], -} + content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'], + theme: { + extend: {}, + }, + plugins: [], +}; diff --git a/tsconfig.json b/tsconfig.json index 3d314d93..32daddd4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,8 @@ { "extends": "astro/tsconfigs/strictest", - "exclude": [ - "packages" - ], + "exclude": ["packages"], "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "react" } -} \ No newline at end of file +}