(file, options)
| 15 | const { log } = console |
| 16 | |
| 17 | export default async function develop (file, options) { |
| 18 | const filepath = path.resolve(file) |
| 19 | const { |
| 20 | port = 3000, |
| 21 | open = false |
| 22 | } = options |
| 23 | |
| 24 | /** require .heml extention */ |
| 25 | if (!isHemlFile(file)) { |
| 26 | log(`${error('ERROR')} ${file} must have ${code('.heml')} extention`) |
| 27 | process.exit(1) |
| 28 | } |
| 29 | |
| 30 | try { |
| 31 | const { update, url } = await startDevServer(path.dirname(filepath), port) |
| 32 | const { html, errors, metadata } = await renderHemlFile(filepath) |
| 33 | |
| 34 | update({ html, errors, metadata }) |
| 35 | |
| 36 | if (open) openUrl(url) |
| 37 | |
| 38 | /** watch for file changes */ |
| 39 | gaze(filepath, function (err) { |
| 40 | if (err) throw err |
| 41 | |
| 42 | this.on('changed', async (changedFile) => { |
| 43 | const { html, errors, metadata } = await renderHemlFile(filepath) |
| 44 | update({ html, errors, metadata }) |
| 45 | }) |
| 46 | |
| 47 | this.on('deleted', async (changedFile) => { |
| 48 | log(`${errorBlock(' Error ')} ${code(file)} was deleted. Shutting down.`) |
| 49 | process.exit() |
| 50 | }) |
| 51 | }) |
| 52 | } catch (err) { |
| 53 | if (err.code === 'ENOENT') { |
| 54 | log(`${errorBlock(' Error ')} ${code(file)} doesn't exist`) |
| 55 | } else { |
| 56 | log(`${errorBlock(' Error ')} ${err.message}`) |
| 57 | } |
| 58 | process.exit() |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * update the cli UI |
nothing calls this directly
no test coverage detected