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

Fix errors when running the project the first time #1796

Merged
merged 9 commits into from
Mar 24, 2023
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
32 changes: 3 additions & 29 deletions packages/toolpad-app/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dotenv/config';
import arg from 'arg';
import path from 'path';
import * as fs from 'fs/promises';
import invariant from 'invariant';
import { Readable } from 'stream';
import * as readline from 'readline';
Expand Down Expand Up @@ -96,43 +95,18 @@ async function runApp(cmd: 'dev' | 'start', { devMode = false, port }: RunComman
});
}

const PROJECT_FILES_PATH = path.resolve(TOOLPAD_DIR_PATH, './cli/projectFiles');

const projectFiles = [
{
source: 'toolpad-generated-gitignore',
destination: './.toolpad-generated/.gitignore',
},
];

async function writeProjectFiles(): Promise<void> {
await Promise.all(
projectFiles.map(async ({ source, destination }) => {
const filePath = path.resolve(PROJECT_FILES_PATH, source);
const fileContent = await fs.readFile(filePath);

await fs.writeFile(path.join(process.cwd(), destination), fileContent, {
encoding: 'utf-8',
});
}),
);
}

async function devCommand(args: RunCommandArgs) {
const { default: chalk } = await import('chalk');
// eslint-disable-next-line no-console
console.log(`${chalk.blue('info')} - generating project files…`);
await writeProjectFiles();

// eslint-disable-next-line no-console
console.log(`${chalk.blue('info')} - starting Toolpad application in dev mode`);
console.log(`${chalk.blue('info')} - starting Toolpad application in dev mode...`);
await runApp('dev', args);
}

async function buildCommand() {
const { default: chalk } = await import('chalk');
// eslint-disable-next-line no-console
console.log(`${chalk.blue('info')} - building Toolpad application`);
console.log(`${chalk.blue('info')} - building Toolpad application...`);
await new Promise((resolve) => {
setTimeout(resolve, 1000);
});
Expand All @@ -143,7 +117,7 @@ async function buildCommand() {
async function startCommand(args: RunCommandArgs) {
const { default: chalk } = await import('chalk');
// eslint-disable-next-line no-console
console.log(`${chalk.blue('info')} - Starting Toolpad application`);
console.log(`${chalk.blue('info')} - Starting Toolpad application...`);
await runApp('start', args);
}

Expand Down

This file was deleted.

5 changes: 3 additions & 2 deletions packages/toolpad-app/pages/api/runtime/[[...path]].ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NextApiHandler } from 'next';
import serializeJavascript from 'serialize-javascript';
import config from '../../../src/config';
import { RUNTIME_CONFIG_WINDOW_PROPERTY } from '../../../src/constants';
import { getConfigFilePath } from '../../../src/server/localMode';
import { getConfigFilePath, getUserProjectRoot } from '../../../src/server/localMode';
import { createBuilder } from '../../../src/server/runtimeBuild';

const BASE = '/api/runtime';
Expand All @@ -16,6 +16,7 @@ declare module globalThis {
}

async function getBuilder() {
const root = getUserProjectRoot();
if (!builderPromise) {
// Not initialized yet, either first run, or after HMR

Expand All @@ -28,7 +29,7 @@ async function getBuilder() {
}

const builder = await createBuilder({
filePath: await getConfigFilePath(),
filePath: await getConfigFilePath(root),
dev: true,
});

Expand Down
Loading