Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add start message with local and network url
- Loading branch information
Showing
19 changed files
with
215 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rocket/engine': patch | ||
--- | ||
|
||
Add `engine.getVersion()` method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
'@rocket/cli': patch | ||
--- | ||
|
||
Add start message for `rocket start` | ||
|
||
``` | ||
🚀 Rocket Engine v0.2.5 | ||
🚧 Local: http://localhost:8000/ | ||
🌐 Network: http://xxx.xxx.xxx.xxx:8000/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import ip from 'ip'; | ||
import { white, bold, cyan, gray } from 'colorette'; | ||
|
||
/** @typedef {import('@web/dev-server').DevServerConfig} DevServerConfig */ | ||
|
||
/** | ||
* | ||
* @param {DevServerConfig} devServerOptions | ||
* @param {string} host | ||
* @param {string} path | ||
* @returns {string} | ||
*/ | ||
function createAddress(devServerOptions, host, path) { | ||
return `http${devServerOptions.http2 ? 's' : ''}://${host}:${devServerOptions.port}${path}`; | ||
} | ||
|
||
/** | ||
* | ||
* @param {DevServerConfig} devServerOptions | ||
* @param {console} logger | ||
* @param {string} openPath | ||
*/ | ||
function logNetworkAddress(devServerOptions, logger, openPath) { | ||
try { | ||
const address = ip.address(); | ||
if (typeof address === 'string') { | ||
logger.log( | ||
`${white(' 🌐 Network:')} ${cyan(createAddress(devServerOptions, address, openPath))}`, | ||
); | ||
} | ||
} catch (_a) { | ||
// | ||
} | ||
} | ||
|
||
/** | ||
* @param {{ devServerOptions: DevServerConfig, engine: import('@rocket/engine/server').Engine}} options | ||
* @param {console} logger | ||
*/ | ||
export function logStartMessage({ devServerOptions, engine }, logger) { | ||
const prettyHost = devServerOptions.hostname ?? 'localhost'; | ||
let openPath = typeof devServerOptions.open === 'string' ? devServerOptions.open : '/'; | ||
if (!openPath.startsWith('/')) { | ||
openPath = `/${openPath}`; | ||
} | ||
|
||
logger.log(`${bold(`🚀 Rocket Engine`)} ${gray(`v${engine.getVersion()}`)}`); | ||
logger.log(''); | ||
logger.log( | ||
`${white(' 🚧 Local:')} ${cyan(createAddress(devServerOptions, prettyHost, openPath))}`, | ||
); | ||
logNetworkAddress(devServerOptions, logger, openPath); | ||
logger.log(''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import chai from 'chai'; | ||
import { white, bold } from 'colorette'; | ||
|
||
import { setupTestCli } from './test-helpers.js'; | ||
|
||
const { expect } = chai; | ||
|
||
describe('Start', () => { | ||
it('Start Message', async () => { | ||
const { cli, capturedLogs, cleanup } = await setupTestCli({ | ||
cwd: 'fixtures/05-start/01-start-message', | ||
cliOptions: ['start'], | ||
testOptions: { captureLogs: true }, | ||
}); | ||
|
||
await cli.start(); | ||
await cleanup(); | ||
|
||
expect(capturedLogs[0].startsWith(`${bold(`🚀 Rocket Engine`)} `)).to.be.true; | ||
expect(capturedLogs[1]).to.equal(''); | ||
expect(capturedLogs[2].startsWith(`${white(' 🚧 Local:')}`)).to.be.true; | ||
expect(capturedLogs[3].startsWith(`${white(' 🌐 Network:')}`)).to.be.true; | ||
expect(capturedLogs[4]).to.equal(''); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
packages/cli/test-node/fixtures/05-start/01-start-message/site/pages/index.rocket.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* START - Rocket auto generated - do not touch */ | ||
export const sourceRelativeFilePath = 'index.rocket.js'; | ||
/* END - Rocket auto generated - do not touch */ | ||
|
||
export default () => 'Hello World!'; |
8 changes: 8 additions & 0 deletions
8
...test-node/fixtures/05-start/01-start-message/site/pages/pageTreeData.rocketGenerated.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "index.rocket.js", | ||
"menuLinkText": "index.rocket.js", | ||
"url": "/", | ||
"outputRelativeFilePath": "index.html", | ||
"sourceRelativeFilePath": "index.rocket.js", | ||
"level": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.