refactor!: remove next.js (#3267)

This commit is contained in:
Alex Yang
2023-07-19 00:53:10 +08:00
committed by GitHub
parent 79227a1e7c
commit 47f12f77f2
296 changed files with 4115 additions and 3617 deletions

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env node
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
const child = spawnSync(
process.execPath,
[
'--loader',
'ts-node/esm/transpile-only',
fileURLToPath(new URL('./build-core.ts', import.meta.url)),
...process.argv.slice(2),
],
{ stdio: 'inherit' }
);
if (child.status) process.exit(child.status);

View File

@@ -0,0 +1,48 @@
import { spawn } from 'node:child_process';
import path from 'node:path';
import type { BuildFlags } from '../config/index.js';
import { projectRoot } from '../config/index.js';
const cwd = path.resolve(projectRoot, 'apps', 'core');
const getChannel = () => {
switch (process.env.BUILD_TYPE) {
case 'canary':
case 'beta':
case 'stable':
case 'internal':
return process.env.BUILD_TYPE;
default: {
throw new Error(
'BUILD_TYPE must be one of canary, beta, stable, internal'
);
}
}
};
const flags = {
distribution: 'browser',
mode: 'production',
channel: getChannel(),
coverage: process.env.COVERAGE === 'true',
} satisfies BuildFlags;
spawn(
'node',
[
'--loader',
'ts-node/esm/transpile-only',
'../../node_modules/webpack/bin/webpack.js',
'--mode',
'production',
'--env',
'flags=' + Buffer.from(JSON.stringify(flags), 'utf-8').toString('hex'),
].filter((v): v is string => !!v),
{
cwd,
stdio: 'inherit',
shell: true,
env: process.env,
}
);

View File

@@ -7,7 +7,7 @@ const child = spawnSync(
[
'--loader',
'ts-node/esm/transpile-only',
fileURLToPath(new URL('./dev.ts', import.meta.url)),
fileURLToPath(new URL('./dev-core.ts', import.meta.url)),
...process.argv.slice(2),
],
{ stdio: 'inherit' }

View File

@@ -0,0 +1,84 @@
import { spawn } from 'node:child_process';
import path from 'node:path';
import * as p from '@clack/prompts';
import { type BuildFlags, projectRoot } from '../config/index.js';
const cwd = path.resolve(projectRoot, 'apps', 'core');
const flags: BuildFlags = {
distribution: 'browser',
mode: 'development',
channel: 'canary',
coverage: false,
};
const buildFlags = await p.group(
{
mode: () =>
p.select({
message: 'Mode',
options: [
{
value: 'development',
},
{
value: 'production',
},
],
initialValue: 'development',
}),
channel: () =>
p.select({
message: 'Channel',
options: [
{
value: 'canary',
},
{
value: 'beta',
},
{
value: 'stable',
},
],
initialValue: 'canary',
}),
coverage: () =>
p.confirm({
message: 'Enable coverage',
initialValue: process.env.COVERAGE === 'true',
}),
},
{
onCancel: () => {
p.cancel('Operation cancelled.');
process.exit(0);
},
}
);
flags.mode = buildFlags.mode as any;
flags.channel = buildFlags.channel as any;
flags.coverage = buildFlags.coverage;
spawn(
'node',
[
'--loader',
'ts-node/esm/transpile-only',
'../../node_modules/webpack/bin/webpack.js',
flags.mode === 'development' ? 'serve' : undefined,
'--mode',
flags.mode === 'development' ? 'development' : 'production',
'--env',
'flags=' + Buffer.from(JSON.stringify(flags), 'utf-8').toString('hex'),
].filter((v): v is string => !!v),
{
cwd,
stdio: 'inherit',
shell: true,
env: process.env,
}
);

View File

@@ -0,0 +1,12 @@
import { fileURLToPath } from 'node:url';
export type BuildFlags = {
distribution: 'browser' | 'desktop';
mode: 'development' | 'production';
channel: 'stable' | 'beta' | 'canary' | 'internal';
coverage?: boolean;
};
export const projectRoot = fileURLToPath(
new URL('../../../../', import.meta.url)
);

View File

@@ -1,85 +0,0 @@
#!/usr/bin/env ts-node-esm
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';
import { spawnSync } from 'child_process';
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(
{
debugBlockSuite: () =>
p.confirm({
message: 'Debug blocksuite locally?',
initialValue: false,
}),
},
{
onCancel: () => {
p.cancel('Operation cancelled.');
process.exit(0);
},
}
);
const env: Record<string, string> = {
PATH: process.env.PATH ?? '',
NODE_ENV: 'development',
PORT: '8080',
};
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 (typeof localBlockSuite !== 'string') {
throw new Error('local blocksuite PATH is required');
}
if (!fs.existsSync(localBlockSuite)) {
throw new Error(`local blocksuite not found: ${localBlockSuite}`);
}
env.LOCAL_BLOCK_SUITE = localBlockSuite;
} else {
env.LOCAL_BLOCK_SUITE = '';
}
const packages = ['infra', 'plugin-infra'];
spawnSync('nx', ['run-many', '-t', 'build', '-p', ...packages], {
env,
cwd,
stdio: 'inherit',
shell: true,
});
packages.forEach(pkg => {
const cwd = path.resolve(root, 'packages', pkg);
spawn('yarn', ['dev'], {
env,
cwd,
stdio: 'inherit',
shell: true,
});
});
spawn('yarn', ['dev', '-p', '8080'], {
env,
cwd,
stdio: 'inherit',
shell: true,
});