-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First basic version of serve command
- Loading branch information
Showing
3 changed files
with
111 additions
and
1 deletion.
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
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,43 @@ | ||
import { command } from 'execa'; | ||
import express from 'express'; | ||
|
||
export async function main() { | ||
const app = express(); | ||
|
||
// Plan: | ||
// Iteration 1: HTTP server, build execs out to cli | ||
// Iteration 2: HTTP server, build/appId calls out to CLI | ||
// Iteration 3: Split package up, addon calls via node API on server channel. | ||
app.post('/build', async (req, res) => { | ||
res.setHeader('access-control-allow-origin', '*'); | ||
|
||
const child = command('yarn chromatic', { stdio: 'pipe' }); | ||
|
||
let done; | ||
console.log('started child'); | ||
child.stdout.on('data', (d) => { | ||
const s = d.toString('utf8'); | ||
// console.log('got data'); | ||
// console.log(s); | ||
|
||
const match = s.match(/(https:\/\/www\.chromatic\.com\/build.*)/); | ||
if (match) { | ||
console.log(`GOT URL: ${match[0]}`); | ||
res.json({ url: match }); | ||
done = true; | ||
} | ||
}); | ||
|
||
child.on('exit', (code) => { | ||
// console.log(`child process exited with code ${code}`); | ||
|
||
if (!done) { | ||
res.status(500).json({ error: 'Shrug' }); | ||
} | ||
}); | ||
}); | ||
|
||
app.listen(8765, () => { | ||
console.log('Listening on port 8765'); | ||
}); | ||
} |
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