Skip to content

Commit

Permalink
setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Seroxdesign committed Jul 5, 2024
1 parent c161634 commit 092f3c7
Show file tree
Hide file tree
Showing 16 changed files with 785 additions and 43 deletions.
2 changes: 2 additions & 0 deletions packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"axios": "1.6.7",
"chalk": "5.3.0",
"commander": "12.0.0",
"download": "8.0.0",
"esbuild": "0.20.0",
"fs-extra": "11.2.0",
"glob": "10.3.10",
Expand All @@ -44,6 +45,7 @@
"devDependencies": {
"@synthetixio/synpress-tsconfig": "0.0.1-alpha.7",
"@types/archiver": "6.0.2",
"@types/download": "8.0.5",
"@types/fs-extra": "11.0.4",
"@types/gradient-string": "1.1.5",
"@types/node": "20.11.17",
Expand Down
8 changes: 6 additions & 2 deletions packages/cache/src/cli/cliEntrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { footer } from './footer'
interface CliFlags {
keplr: boolean
metamask: boolean
phantom: boolean
headless: boolean
force: boolean
debug: boolean
Expand All @@ -34,6 +35,7 @@ export const cliEntrypoint = async () => {
.option('-d, --debug', 'If this flag is present, the compilation files are not going to be deleted', false)
.option('-k, --keplr', 'Prepare the Keplr extension', false)
.option('-m, --metamask', 'Prepare the MetaMask extension', false)
.option('-p, --phantom', 'Prepare the Phantom extension', false)
.helpOption(undefined, 'Display help for command')
.addHelpText('afterAll', `\n${footer}\n`)
.parse(process.argv)
Expand All @@ -57,12 +59,15 @@ export const cliEntrypoint = async () => {
if (flags.metamask) {
extensions.push('MetaMask')
}
if (flags.phantom) {
extensions.push('Phantom')
}
return extensions
}
let extensionNames = extensionsToSetup()

if (!extensionNames.length) {
extensionNames = ['Keplr']
extensionNames = ['Metamask']
}

if (os.platform() === 'win32') {
Expand All @@ -81,7 +86,6 @@ export const cliEntrypoint = async () => {
for (const extensionName of extensionNames) {
await createCache(compiledWalletSetupDirPath, () => prepareExtension(extensionName), flags.force) // Pass extensionName
}
// TODO: We should be using `prepareExtension` function from the wallet itself!

if (!flags.debug) {
await rimraf(compiledWalletSetupDirPath)
Expand Down
24 changes: 20 additions & 4 deletions packages/cache/src/prepareExtension.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// import download from 'download'
import { downloadFile, ensureCacheDirExists, unzipArchive } from '.'

interface ExtensionConfig {
Expand All @@ -20,6 +21,12 @@ export async function getExtensionConfig(name: string): Promise<ExtensionConfig>
version: '0.12.102',
downloadUrl:
'https://github.com/chainapsis/keplr-wallet/releases/download/v0.12.102/keplr-extension-manifest-v2-v0.12.102.zip'
},
{
name: 'Phantom',
version: 'phantom-chrome-latest',
downloadUrl:
'https://crx-backup.phantom.dev/latest.crx'
}
]
}
Expand All @@ -34,13 +41,22 @@ export async function getExtensionConfig(name: string): Promise<ExtensionConfig>
export async function prepareExtension(extensionName: string) {
const cacheDirPath = ensureCacheDirExists()
const extensionConfig = await getExtensionConfig(extensionName) // Get config

const downloadResult = await downloadFile({
let downloadResult
// if (extensionConfig.name === 'Phantom') {
// downloadResult = await download(extensionConfig.downloadUrl, cacheDirPath, {
// headers: {
// Accept: 'application/octet-stream',
// },
// });
// }
// else {

// }
downloadResult = await downloadFile({
url: extensionConfig.downloadUrl,
outputDir: cacheDirPath,
fileName: `${extensionConfig.name.toLowerCase()}-chrome-${extensionConfig.version}.zip`
fileName: extensionName === 'Phantom' ? 'latest.crx' : `${extensionConfig.name.toLowerCase()}-chrome-${extensionConfig.version}.zip`
})

const unzipResult = await unzipArchive({
archivePath: downloadResult.filePath
})
Expand Down
Loading

0 comments on commit 092f3c7

Please sign in to comment.