Skip to content

Commit

Permalink
Implement serve on browser feature 🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Mar 11, 2019
1 parent 44fc9e3 commit a633004
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/commands/serve/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ exports.serveProject = async (launchCmd) => {
let spinner = setInterval(() => {
logUpdate(chalk.green.bold('\n Installing dependencies in the background. Hold on... ') + chalk.cyan.bold.dim(frame()));
}, 50);
let rootPath = 'localhost';
let rootPath = 'http://localhost';
let port;

if (launchCmd === 'npm run dev') {
port = projectTemplate === 'Nuxt-js' ? '3000' : '8080';
} else {
port = '9000/api';
}

shell.exec('npm install', {silent: true}, async (err) => {
clearInterval(spinner);
logUpdate.clear();
Expand All @@ -30,14 +29,15 @@ exports.serveProject = async (launchCmd) => {
process.exit(1);
}
console.log(chalk.green.bold(`You're all set.`));
console.log(chalk.cyan.bold(`\n Available on ${chalk.green.bold(`${rootPath}/${port}`)}`));
try {
await shell.exec(launchCmd, {silent: true});
await require('child_process').exec(launchCmd);
} catch (err) {
throw err;
}
console.log(chalk.cyan.bold(`\n Running in ${chalk.green.bold(`${rootPath}/${port}`)}`));
opn(`${rootPath}`, (err) => {
throw err;
});
setTimeout(() => {
console.log(port);
opn(`${rootPath}:${port}`);
}, 2000);
});
};

0 comments on commit a633004

Please sign in to comment.