Skip to content

Commit

Permalink
Swamp out nodemon for supervisor (as supervisor has been end of life …
Browse files Browse the repository at this point in the history
…for awhile now) (#367)
  • Loading branch information
alallier committed Aug 14, 2024
1 parent cf4476d commit c1e3b24
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 75 deletions.
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

0 comments on commit c1e3b24

Please sign in to comment.