Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open explorer alpha on start #976

Merged
merged 17 commits into from
Aug 7, 2024
68 changes: 68 additions & 0 deletions packages/@dcl/sdk-commands/src/commands/start/explorer-alpha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import prompts from 'prompts'
import { CliComponents } from '../../components'
import { writeGlobalConfig } from '../../components/config'

const isWindows = /^win/.test(process.platform)

export async function runExplorerAlpha(components: CliComponents, cwd: string, realm: string) {
if (await runApp(components, { cwd, realm })) {
return
}
const path = await getExplorerAlphaPath(components)
if (path && (await runApp(components, { cwd, realm, path }))) {
return
}
components.logger.log('\n')
components.logger.warn('DECENTRALAND APP NOT FOUND. ')
components.logger.warn('Please download & install it: https://dcl.gg/explorer\n\n')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: link to the new launcher

}

async function runApp(components: CliComponents, { cwd, realm, path }: { cwd: string; realm: string; path?: string }) {
const cmd = isWindows ? 'start' : 'open'
try {
await components.spawner.exec(cwd, cmd, [path ?? `decentraland://realm=${realm}`], { silent: true })
if (path) {
await writeGlobalConfig(components, 'EXPLORER_ALPHA_PATH', path)
}
return true
} catch (e: any) {
// components.logger.error('failed', e.message)
return false
}
}

export async function getExplorerAlphaPath(components: CliComponents): Promise<string | undefined> {
const path = await components.config.getString('EXPLORER_ALPHA_PATH')
if (path) return path
try {
const answer = await prompts(
{
type: 'text',
name: 'path',
message: 'Please provide the Directory where the Explorer Client is installed. i.e. /Applications/',
validate: (description) => description.length >= 5
},
{
onCancel: () => {
throw new Error('Please provide a path')
}
}
)
let path: string = answer.path
if (isWindows) {
path += '/Explorer.exe'
} else {
if (!path.includes('Decentraland.app')) {
path = path + '/Decentraland.app'
}
const MAC_PATH = '/Contents/MacOS/Explorer'
if (!path.includes(MAC_PATH)) {
path = path + MAC_PATH
}
return path.replace(/\/\//, '/')
}
return path
} catch (e: any) {
return undefined
}
}
27 changes: 20 additions & 7 deletions packages/@dcl/sdk-commands/src/commands/start/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { getValidWorkspace } from '../../logic/workspace-validations'
import { printCurrentProjectStarting, printProgressInfo, printWarning } from '../../logic/beautiful-logs'
import { Result } from 'arg'
import { startValidations } from '../../logic/project-validations'
import { runExplorerAlpha } from './explorer-alpha'

interface Options {
args: Result<typeof args>
Expand All @@ -49,7 +50,8 @@ export const args = declareArgs({
'-w': '--no-watch',
'--skip-build': Boolean,
'--desktop-client': Boolean,
'--data-layer': Boolean
'--data-layer': Boolean,
'--explorer-alpha': Boolean
})

export async function help(options: Options) {
Expand Down Expand Up @@ -90,6 +92,7 @@ export async function main(options: Options) {
const watch = !options.args['--no-watch']
const withDataLayer = options.args['--data-layer']
const enableWeb3 = options.args['--web3']
const explorerAlpha = options.args['--explorer-alpha']

let hasSmartWearable = false

Expand Down Expand Up @@ -135,7 +138,7 @@ export async function main(options: Options) {
})
const logs = await createConsoleLogComponent({})
const ws = await createWsComponent({ logs })
const server = await createServerComponent<PreviewComponents>({ config, logs, ws: ws.ws }, { cors: {} })
const server = await createServerComponent<PreviewComponents>({ config, ws: ws.ws, logs }, { cors: {} })
const rooms = await createRoomsComponent({
metrics,
logs,
Expand Down Expand Up @@ -179,7 +182,9 @@ export async function main(options: Options) {
const availableURLs: string[] = []

printProgressInfo(options.components.logger, 'Preview server is now running!')
components.logger.log('Available on:\n')
if (!explorerAlpha) {
components.logger.log('Available on:\n')
}

Object.keys(networkInterfaces).forEach((dev) => {
;(networkInterfaces[dev] || []).forEach((details) => {
Expand All @@ -203,8 +208,10 @@ export async function main(options: Options) {
return a.toLowerCase().includes('localhost') || a.includes('127.0.0.1') || a.includes('0.0.0.0') ? -1 : 1
})

for (const addr of sortedURLs) {
components.logger.log(` ${addr}`)
if (!explorerAlpha) {
for (const addr of sortedURLs) {
components.logger.log(` ${addr}`)
}
}

if (options.args['--desktop-client']) {
Expand All @@ -216,11 +223,17 @@ export async function main(options: Options) {
}
}

components.logger.log('\n Details:\n')
if (!explorerAlpha) {
components.logger.log('\n Details:\n')
}
components.logger.log('\nPress CTRL+C to exit\n')

if (explorerAlpha) {
await runExplorerAlpha(components, workingDirectory, sortedURLs[0])
}

// Open preferably localhost/127.0.0.1
if (openBrowser && sortedURLs.length && !options.args['--desktop-client']) {
if (!explorerAlpha && openBrowser && sortedURLs.length && !options.args['--desktop-client']) {
try {
await open(sortedURLs[0])
} catch (_) {
Expand Down
1 change: 1 addition & 0 deletions packages/@dcl/sdk-commands/src/components/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ConfigKeys =
| 'DCL_LAND_REGISTRY_ADDRESS' // Address of the LAND_REGISTRY smart contract
| 'DCL_ESTATE_REGISTRY_ADDRESS' // Address of the ESTATE_REGISTRY smart contract
| 'DCL_CATALYST' // Default catalyst
| 'EXPLORER_ALPHA_PATH' // Explorer alpha path to run app

export const DCL_RC = '.dclrc'

Expand Down
2 changes: 1 addition & 1 deletion packages/@dcl/sdk-commands/src/logic/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function compositeLoader(components: BundleComponents, options: SingleProjectOpt
'Some composites are not included because of errors while compiling them. There can be unexpected behavior in the scene, check the errors and try to fix them.'
)
} else if (!lastBuiltSuccessful) {
components.logger.log('Composites built without errors.')
// components.logger.log('Composites built without errors.')
}
lastBuiltSuccessful = !data.withErrors
}
Expand Down
1 change: 1 addition & 0 deletions packages/@dcl/sdk-commands/src/logic/exec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import type { spawn } from 'child_process'

interface Options {
Expand Down
Loading