Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap out supervisor for nodemon in reload command line #367

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions bin/reload
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const { program } = require('commander')
const supervisor = require('supervisor')
const nodemon = require('nodemon')
const path = require('path')
const os = require('os')
const clc = require('cli-color')
Expand All @@ -24,18 +24,26 @@ const options = program.opts()
const runFile = path.join(os.tmpdir(), 'reload-' + Math.random().toString().slice(2))
const serverFile = path.join(__dirname, '../lib/reload-server.js')

if (options.exts.indexOf(',')) {
options.exts = options.exts.replace(/,/g, '|') // replace comma for pipe, that's what supervisor likes
if (options.exts.indexOf('|')) {
options.exts = options.exts.replace(/\|/g, ',') // replace pipes for commas, that's what nodemon likes
}

// Fall back to the serving directory.
if (typeof options.watchDir === 'undefined') {
options.watchDir = options.dir
}

const args = ['-e', options.exts, '-w', options.watchDir, '-q', '--', serverFile, options.port, options.dir, !!options.browser, options.hostname, runFile, options.startPage, options.fallback, options.verbose]
supervisor.run(args)

console.log('\nReload web server:')
console.log('listening on port ' + clc.blue.bold(options.port))
console.log('monitoring dir ' + clc.green.bold(options.dir))
nodemon({
ext: options.exts,
watch: path.join(options.watchDir, '/**/*'), // Watch all subdirectories
script: `${serverFile}`,
args: [`${options.port}`, `${options.dir}`, !!`${options.browser}`, `${options.hostname}`, `${runFile}`, `${options.startPage}`, `${options.fallback}`, `${options.verbose}`]
})

nodemon.on('start', function () {
console.log('\nReload web server:')
console.log('listening on port ' + clc.blue.bold(options.port))
console.log('monitoring dir ' + clc.green.bold(options.dir))
}).on('restart', function (files) {
console.log('App restarted due to: ', files)
})
Loading