function startServer()

in scripts/serve.js [64:109]


function startServer() {
  const args = process.argv.slice(2);
  const seriesPath = path.join(__dirname, '../custom-series', args[0]);
  if (!fs.existsSync(seriesPath)) {
    console.error(chalk.red(`Custom series ${args[0]} does not exist`));
    return;
  }

  const port = 8081;
  const serverProcess = exec(`http-server ${seriesPath} -p ${port}`);

  // Add file watcher
  const watcher = chokidar.watch(path.join(seriesPath, 'src'), {
    ignored: /(^|[\/\\])\../, // ignore dotfiles
    persistent: true,
  });
  watcher.on('change', (path) => {
    console.log(chalk.gray(`File ${path} has been changed. Rebuilding...`));
    build();
  });

  serverProcess.stdout.on('data', (data) => {
    if (data.includes('Available on:')) {
      const open =
        process.platform === 'darwin'
          ? 'open'
          : process.platform === 'win32'
          ? 'start'
          : 'xdg-open';
      const url = `http://localhost:${port}/test/index.html`;
      exec(`${open} ${url}`, (error) => {
        if (error) {
          console.error(chalk.red(`Failed to open browser: ${error}`));
        }
      });
    }
  });

  serverProcess.stderr.on('data', (data) => {
    console.error(chalk.red(data.toString()));
  });

  serverProcess.on('close', (code) => {
    console.log(chalk.gray(`http-server process exited with code ${code}`));
  });
}