Skip to content

Commit

Permalink
add explorer alpha flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gonpombo8 committed Jul 10, 2024
1 parent 26bf9cd commit c8d333a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 40 deletions.
21 changes: 10 additions & 11 deletions packages/@dcl/sdk-commands/src/commands/start/explorer-alpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ import prompts from 'prompts'
import { CliComponents } from '../../components'
import { writeGlobalConfig } from '../../components/config'

export async function runExplorerAlpha(components: CliComponents, cwd: string) {
if (await runApp(components, cwd)) {
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, path))) {
if (path && (await runApp(components, { cwd, realm, path }))) {
return
}
components.logger.log('\n')
components.logger.warn('EXPLORER APP NOT FOUND. ')
components.logger.warn('DECENTRALAND APP NOT FOUND. ')
components.logger.warn('Please download & install it: https://dcl.gg/explorer\n\n')
}

async function runApp(components: CliComponents, cwd: string, path?: string) {
async function runApp(components: CliComponents, { cwd, realm, path }: { cwd: string; realm: string; path?: string }) {
const cmd = isWindows ? 'start' : 'open'
try {
//'--realm http://127.0.0.1:8000'
await components.spawner.exec(cwd, cmd, [path ?? 'decentraland://'], { silent: true })
await components.spawner.exec(cwd, cmd, [path ?? `decentraland://realm=${realm}`], { silent: true })
if (path) {
await writeGlobalConfig(components, 'EXPLORER_ALPHA_PATH_2', path)
await writeGlobalConfig(components, 'EXPLORER_ALPHA_PATH', path)
}
return true
} catch (e: any) {
Expand All @@ -30,10 +31,8 @@ async function runApp(components: CliComponents, cwd: string, path?: string) {
}
}

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

export async function getExplorerAlphaPath(components: CliComponents): Promise<string | undefined> {
const path = await components.config.getString('EXPLORER_ALPHA_PATH_2')
const path = await components.config.getString('EXPLORER_ALPHA_PATH')
if (path) return path
try {
const answer = await prompts(
Expand Down
47 changes: 18 additions & 29 deletions packages/@dcl/sdk-commands/src/commands/start/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,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 @@ -91,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 All @@ -100,17 +102,6 @@ export async function main(options: Options) {
if (workspace.projects.length > 1)
printWarning(options.components.logger, 'Support for multiple projects is still experimental.')

const EXPLORER_ALPHA = true
const port = await getPort(options.args['--port'] || 0)
const config = createRecordConfigComponent({
HTTP_SERVER_PORT: port.toString(),
HTTP_SERVER_HOST: '0.0.0.0',
...process.env
})
if (EXPLORER_ALPHA) {
await runExplorerAlpha({ ...options.components, config }, workingDirectory)
}

for (const project of workspace.projects) {
if (project.kind === 'smart-wearable') hasSmartWearable = true
if (project.kind === 'scene' || project.kind === 'smart-wearable') {
Expand All @@ -136,24 +127,18 @@ export async function main(options: Options) {

printProgressInfo(options.components.logger, 'Starting preview server')

const port = await getPort(options.args['--port'] || 0)
const program = await Lifecycle.run<PreviewComponents>({
async initComponents(): Promise<PreviewComponents> {
const metrics = createTestMetricsComponent(roomsMetrics)

const config = createRecordConfigComponent({
HTTP_SERVER_PORT: port.toString(),
HTTP_SERVER_HOST: '0.0.0.0',
...process.env
})
const logs = await createConsoleLogComponent({})
const ws = await createWsComponent({ logs })
const fakeLog = {
getLogger(v: string) {
return {
log() {},
error() {},
info() {},
debug() {},
warn() {}
}
}
}
const server = await createServerComponent<PreviewComponents>({ config, ws: ws.ws, logs: fakeLog }, { cors: {} })
const server = await createServerComponent<PreviewComponents>({ config, ws: ws.ws, logs }, { cors: {} })
const rooms = await createRoomsComponent({
metrics,
logs,
Expand Down Expand Up @@ -197,7 +182,7 @@ export async function main(options: Options) {
const availableURLs: string[] = []

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

Expand All @@ -223,7 +208,7 @@ 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
})

if (!EXPLORER_ALPHA) {
if (!explorerAlpha) {
for (const addr of sortedURLs) {
components.logger.log(` ${addr}`)
}
Expand All @@ -238,13 +223,17 @@ export async function main(options: Options) {
}
}

if (!EXPLORER_ALPHA) {
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 (false && openBrowser && sortedURLs.length && !options.args['--desktop-client']) {
if (!explorerAlpha && openBrowser && sortedURLs.length && !options.args['--desktop-client']) {
try {
await open(sortedURLs[0])
} catch (_) {
Expand Down

0 comments on commit c8d333a

Please sign in to comment.