feat: improve dev mode for local blocksuite (#1654)

This commit is contained in:
Himself65
2023-03-22 01:09:30 -05:00
committed by GitHub
parent ba2295c426
commit 156edb1d4b
4 changed files with 41 additions and 6 deletions

View File

@@ -1,12 +1,17 @@
#!/usr/bin/env node
import { spawn } from 'node:child_process';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import * as p from '@clack/prompts';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const root = path.resolve(__dirname, '..', '..', '..');
const cwd = path.resolve(root, 'apps', 'web');
const dev = await p.group(
{
server: () =>
@@ -30,6 +35,11 @@ const dev = await p.group(
},
],
}),
debugBlockSuite: () =>
p.confirm({
message: 'Debug blocksuite locally?',
initialValue: false,
}),
},
{
onCancel: () => {
@@ -39,17 +49,34 @@ const dev = await p.group(
}
);
if (dev.server === 'local') {
console.log('You might need setup OctoBase dev server first.');
}
const env = {
NODE_API_SERVER: dev.server,
PATH: process.env.PATH,
};
const root = path.resolve(__dirname, '..', '..', '..');
const cwd = path.resolve(root, 'apps', 'web');
if (dev.debugBlockSuite) {
const { config } = await import('dotenv');
const envLocal = config({
path: path.resolve(cwd, '.env.local'),
});
const localBlockSuite = await p.text({
message: 'local blocksuite PATH',
initialValue: envLocal.error
? undefined
: envLocal.parsed.LOCAL_BLOCK_SUITE,
});
if (!fs.existsSync(localBlockSuite)) {
throw new Error(`local blocksuite not found: ${localBlockSuite}`);
}
env.LOCAL_BLOCK_SUITE = localBlockSuite;
} else {
env.LOCAL_BLOCK_SUITE = '';
}
if (dev.server === 'local') {
console.log('You might need setup OctoBase dev server first.');
}
spawn('yarn', ['dev'], {
env,