mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-17 14:30:34 +08:00
feat(server-dev): Skip calling next and lowdefy build using npm/yarn start.
This commit is contained in:
parent
cf66a6f839
commit
1a8699a012
@ -16,6 +16,7 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import path from 'path';
|
||||
import { createRequire } from 'module';
|
||||
import yargs from 'yargs';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
|
||||
@ -30,10 +31,16 @@ import shutdownServer from './processes/shutdownServer.mjs';
|
||||
import startWatchers from './processes/startWatchers.mjs';
|
||||
|
||||
const argv = yargs(hideBin(process.argv)).argv;
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
async function getContext() {
|
||||
const { verbose = false } = argv;
|
||||
const context = {
|
||||
bin: {
|
||||
// TODO: The string replace is a little hacky and will fail if the location of the bin changes,
|
||||
lowdefyBuild: require.resolve('@lowdefy/build').replace('index.js', 'scripts/run.js'),
|
||||
next: require.resolve('next').replace('server/next.js', 'bin/next'),
|
||||
},
|
||||
directories: {
|
||||
build: path.resolve(process.cwd(), './build'),
|
||||
config: path.resolve(
|
||||
|
@ -16,12 +16,12 @@
|
||||
|
||||
import { spawnProcess } from '@lowdefy/node-utils';
|
||||
|
||||
function lowdefyBuild({ packageManager, directories }) {
|
||||
function lowdefyBuild({ bin, directories }) {
|
||||
return async () => {
|
||||
await spawnProcess({
|
||||
command: 'node',
|
||||
args: [bin.lowdefyBuild],
|
||||
logger: console,
|
||||
args: ['run', 'build:lowdefy'],
|
||||
command: packageManager,
|
||||
processOptions: {
|
||||
env: {
|
||||
...process.env,
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
import { spawnProcess } from '@lowdefy/node-utils';
|
||||
|
||||
function nextBuild({ packageManager, verbose }) {
|
||||
function nextBuild(context) {
|
||||
return async () => {
|
||||
console.log('Building app...');
|
||||
await spawnProcess({
|
||||
logger: console,
|
||||
args: ['run', 'build:next'],
|
||||
command: packageManager,
|
||||
silent: !verbose,
|
||||
command: 'node',
|
||||
args: [context.bin.next, 'build'],
|
||||
silent: !context.verbose,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -16,18 +16,18 @@
|
||||
|
||||
function shutdownServer(context) {
|
||||
return () => {
|
||||
if (context.serverProcess) {
|
||||
if (context.nextServer) {
|
||||
// console.log(
|
||||
// `Existing server ${context.serverProcess.pid}, killed: ${context.serverProcess.killed}`
|
||||
// `Existing server ${context.nextServer.pid}, killed: ${context.nextServer.killed}`
|
||||
// );
|
||||
if (!context.serverProcess.killed) {
|
||||
if (!context.nextServer.killed) {
|
||||
console.log('Shutting down server...');
|
||||
context.serverProcess.kill();
|
||||
context.nextServer.kill();
|
||||
// console.log(
|
||||
// `Killed server ${context.serverProcess.pid}, killed: ${context.serverProcess.killed}`
|
||||
// `Killed server ${context.nextServer.pid}, killed: ${context.nextServer.killed}`
|
||||
// );
|
||||
}
|
||||
context.serverProcess = null;
|
||||
context.nextServer = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -14,18 +14,15 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { createRequire } from 'module';
|
||||
import spawnProcess from '../utils/spawnProcess.mjs';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
function startServerProcess(context) {
|
||||
context.shutdownServer();
|
||||
const nextCliUrl = require.resolve('next').replace('server/next.js', 'bin/next');
|
||||
|
||||
const nextServer = spawnProcess({
|
||||
logger: console,
|
||||
command: 'node',
|
||||
args: [nextCliUrl, 'start'],
|
||||
args: [context.bin.next, 'start'],
|
||||
silent: false,
|
||||
processOptions: {
|
||||
env: {
|
||||
|
Loading…
Reference in New Issue
Block a user