2022-02-15 16:17:14 -07:00
|
|
|
'use strict';
|
2022-02-15 20:33:31 -07:00
|
|
|
|
2022-06-07 19:27:22 -06:00
|
|
|
console.log('start-dev process.env.NODE_ENV', process.env.NODE_ENV);
|
|
|
|
|
2023-04-26 01:09:46 -06:00
|
|
|
// Using the `posix` version to always use forward slashes in the glob patterns for
|
|
|
|
// the nodemon `ignore` option. It wasn't matching properly otherwise.
|
|
|
|
// Ex.
|
|
|
|
// Before: `.\dist\**\!(manifest.json)`
|
|
|
|
// After: `dist/**/!(manifest.json)`
|
|
|
|
const path = require('path').posix;
|
2023-04-24 23:39:59 -06:00
|
|
|
// eslint-disable-next-line n/no-unpublished-require
|
2022-02-15 16:17:14 -07:00
|
|
|
const nodemon = require('nodemon');
|
|
|
|
|
2023-04-07 12:17:46 -06:00
|
|
|
const buildClient = require('../build-scripts/build-client');
|
2022-02-15 16:17:14 -07:00
|
|
|
|
2022-06-07 19:27:22 -06:00
|
|
|
// Build the client-side JavaScript bundle when we see any changes
|
2022-09-08 00:30:04 -06:00
|
|
|
buildClient({
|
|
|
|
build: {
|
|
|
|
// Rebuild when we see changes
|
2022-09-20 15:02:09 -06:00
|
|
|
// https://rollupjs.org/guide/en/#watch-options
|
2023-05-30 09:34:35 -06:00
|
|
|
//
|
|
|
|
// We currently can't watch for changes in the locally linked `hydrogen-view-sdk`
|
|
|
|
// because of https://github.com/vitejs/vite/issues/8619 despite what
|
|
|
|
// https://vitejs.dev/config/server-options.html#server-watch says is possible.
|
2022-09-08 00:30:04 -06:00
|
|
|
watch: true,
|
|
|
|
},
|
|
|
|
});
|
2022-02-23 20:25:05 -07:00
|
|
|
|
2023-04-24 22:50:53 -06:00
|
|
|
const nodeArgs = [];
|
2023-05-01 23:39:01 -06:00
|
|
|
if (process.argv.includes('--inspectNode')) {
|
2023-04-24 22:50:53 -06:00
|
|
|
nodeArgs.push('--inspect');
|
|
|
|
}
|
2023-05-01 23:39:01 -06:00
|
|
|
if (process.argv.includes('--traceWarningsNode')) {
|
2023-04-24 22:50:53 -06:00
|
|
|
nodeArgs.push('--trace-warnings');
|
|
|
|
}
|
|
|
|
|
2022-09-02 19:49:06 -06:00
|
|
|
// Pass through some args
|
2022-07-14 10:08:50 -06:00
|
|
|
const args = [];
|
2023-05-01 23:39:01 -06:00
|
|
|
if (process.argv.includes('--tracing')) {
|
2022-07-14 10:08:50 -06:00
|
|
|
args.push('--tracing');
|
|
|
|
}
|
|
|
|
|
2023-05-01 23:39:01 -06:00
|
|
|
if (process.argv.includes('--logOutputFromChildProcesses')) {
|
2023-04-24 22:50:53 -06:00
|
|
|
args.push('--logOutputFromChildProcesses');
|
|
|
|
}
|
|
|
|
|
2022-02-15 16:30:30 -07:00
|
|
|
// Listen for any changes to files and restart the Node.js server process
|
|
|
|
//
|
|
|
|
// For API docs, see
|
|
|
|
// https://github.com/remy/nodemon/blob/main/doc/requireable.md
|
2022-02-15 16:17:14 -07:00
|
|
|
nodemon({
|
|
|
|
script: path.join(__dirname, './server.js'),
|
|
|
|
ext: 'js json',
|
2023-04-26 01:09:46 -06:00
|
|
|
// We override `ignoreRoot` which includes `node_modules` by default because we we
|
|
|
|
// want to watch `node_modules` for changes whenever we symlink `hydrogen-view-sdk`
|
|
|
|
// in, see
|
|
|
|
// https://github.com/remy/nodemon/blob/master/faq.md#overriding-the-underlying-default-ignore-rules
|
2022-02-16 13:55:52 -07:00
|
|
|
ignoreRoot: ['.git'],
|
2023-04-26 01:09:46 -06:00
|
|
|
ignore: [
|
|
|
|
// Ignore everything in `dist/` except changes to the `manifest.json` because we
|
|
|
|
// read it on the server and we should always have an up to date copy.
|
|
|
|
path.join(__dirname, '../dist/**/!(manifest.json)'),
|
|
|
|
],
|
2022-07-14 10:08:50 -06:00
|
|
|
args,
|
2023-04-24 22:50:53 -06:00
|
|
|
nodeArgs,
|
2023-04-26 01:09:46 -06:00
|
|
|
// Helpful for debugging why things aren't watched or ignored
|
|
|
|
//verbose: true,
|
2022-02-15 16:17:14 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
nodemon
|
|
|
|
.on('start', function () {
|
|
|
|
console.log('App has started');
|
|
|
|
})
|
|
|
|
.on('quit', function () {
|
|
|
|
console.log('App has quit');
|
|
|
|
process.exit();
|
|
|
|
})
|
|
|
|
.on('restart', function (files) {
|
|
|
|
console.log('App restarted due to: ', files);
|
|
|
|
})
|
2022-06-07 19:27:22 -06:00
|
|
|
.on('crash', function () {
|
|
|
|
console.log('Nodemon: script crashed for some reason');
|
|
|
|
})
|
|
|
|
// .on('watching', (file) => {
|
2023-04-26 01:09:46 -06:00
|
|
|
// console.log('watching', file);
|
2022-06-07 19:27:22 -06:00
|
|
|
// })
|
|
|
|
.on('log', function (data) {
|
|
|
|
console.log(`Nodemon logs: ${data.type}: ${data.message}`);
|
|
|
|
});
|