Skip to content

Instantly share code, notes, and snippets.

import { ServeFullstackExecutorSchema } from './schema';
import { ExecutorContext } from '@nrwl/devkit';
import { ChildProcess, exec } from 'child_process';
import * as chalk from 'chalk';
const LARGE_BUFFER = 1024 * 1000000;
export default async function runExecutor(
options: ServeFullstackExecutorSchema,
_context: ExecutorContext
import { ServeFullstackExecutorSchema } from './schema';
import { ExecutorContext } from '@nrwl/devkit';
import { ChildProcess, exec } from 'child_process';
const LARGE_BUFFER = 1024 * 1000000;
export default async function runExecutor(
options: ServeFullstackExecutorSchema,
_context: ExecutorContext
) {
async function startBackendServer(options: ServeFullstackExecutorSchema) {
let frontendServerStarted = false;
return new Promise(() => {
const childProcess = exec(`npx nx serve ${options.backendProject}`, {
maxBuffer: LARGE_BUFFER,
});
process.on('exit', () => childProcess.kill());
process.on('SIGTERM', () => childProcess.kill());
childProcess.stdout.on('data', (data) => {
if (!frontendServerStarted && data.includes('build succeeded, watching for changes...')) {
async function startBackendServer(options: ServeFullstackExecutorSchema) {
let frontendServerStarted = false;
return new Promise(() => {
const childProcess = exec(`npx nx serve ${options.backendProject}`, {
maxBuffer: LARGE_BUFFER,
});
process.on('exit', () => childProcess.kill());
process.on('SIGTERM', () => childProcess.kill());
childProcess.stdout.on('data', (data) => {
if (!frontendServerStarted && data.includes('build succeeded, watching for changes...')) {
import { applicationGenerator as nodeAppGenerator } from '@nrwl/node';
// ...
async function createNodeApplication(
tree: Tree,
options: AppGeneratorSchema,
serverName: string,
webAppName: string
) {
import { getWorkspaceLayout, names, Tree, updateJson } from '@nrwl/devkit'
// ...
function adjustDefaultDevPort(tree: Tree, options: AppGeneratorSchema) {
const { fileName } = names(options.name);
updateJson(tree, `apps/${fileName}-web/project.json`, (json) => ({
...json,
targets: {
...json.targets,
import { names, Tree } from '@nrwl/devkit';
import { AppGeneratorSchema } from './schema';
const defaultPorts = {
frontendPort: 3000,
backendPort: 3333,
};
export default async function (tree: Tree, options: AppGeneratorSchema) {
const optionsWithDefaults = {
import { ServeFullstackExecutorSchema } from './schema';
import { ExecutorContext } from '@nrwl/devkit';
import { ChildProcess, exec } from 'child_process';
const LARGE_BUFFER = 1024 * 1000000;
export default async function runExecutor(
options: ServeFullstackExecutorSchema,
_context: ExecutorContext
) {
{
"name": "test-web",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/test-web/src",
"projectType": "application",
"targets": {
// ...
"serve-fullstack": {
"executor": "@nx-trpc-example/plugin:serve-fullstack",
"options": {
import { ServeFullstackExecutorSchema } from './schema';
import { ExecutorContext } from '@nrwl/devkit';
import { ChildProcess, exec } from 'child_process';
import * as chalk from 'chalk';
const LARGE_BUFFER = 1024 * 1000000;
export default async function runExecutor(
options: ServeFullstackExecutorSchema,
_context: ExecutorContext