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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 6 deletions

View File

@ -14,6 +14,10 @@ console.info('Runtime Preset', preset);
const enableDebugLocal = path.isAbsolute(process.env.LOCAL_BLOCK_SUITE ?? '');
if (enableDebugLocal) {
console.info('Debugging local blocksuite');
}
const profileTarget = {
ac: '100.85.73.88:12001',
dev: '100.84.105.99:11001',

View File

@ -11,5 +11,8 @@
"devDependencies": {
"@clack/core": "^0.3.2",
"@clack/prompts": "^0.6.3"
},
"dependencies": {
"dotenv": "^16.0.3"
}
}

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,

View File

@ -73,6 +73,7 @@ __metadata:
dependencies:
"@clack/core": ^0.3.2
"@clack/prompts": ^0.6.3
dotenv: ^16.0.3
bin:
dev-web: ./src/dev.mjs
languageName: unknown