@coze-arch/cli 0.0.1-alpha.1d232d → 0.0.1-alpha.21f492
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__templates__/expo/.cozeproj/scripts/deploy_build.sh +4 -3
- package/lib/__templates__/expo/.cozeproj/scripts/deploy_run.sh +8 -40
- package/lib/__templates__/expo/client/contexts/AuthContext.tsx +14 -107
- package/lib/__templates__/expo/client/screens/home/index.tsx +1 -4
- package/lib/__templates__/expo/client/screens/home/styles.ts +1 -273
- package/lib/__templates__/expo/client/utils/index.ts +1 -2
- package/lib/__templates__/expo/package.json +1 -1
- package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
- package/lib/__templates__/expo/src/index.ts +2 -2
- package/lib/__templates__/expo/template.config.js +1 -1
- package/lib/__templates__/nextjs/package.json +0 -3
- package/lib/__templates__/nextjs/pnpm-lock.yaml +0 -1020
- package/lib/__templates__/nextjs/scripts/dev.sh +1 -1
- package/lib/__templates__/nextjs/src/app/layout.tsx +18 -22
- package/lib/__templates__/nextjs/template.config.js +1 -1
- package/lib/__templates__/templates.json +7 -0
- package/lib/__templates__/vite/template.config.js +12 -3
- package/lib/__templates__/vite/vite.config.ts +1 -1
- package/lib/cli.js +71 -49
- package/package.json +1 -2
- package/lib/__templates__/nextjs/.babelrc +0 -15
- package/lib/__templates__/nextjs/server.mjs +0 -50
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Metadata } from 'next';
|
|
2
2
|
import { Geist, Geist_Mono } from 'next/font/google';
|
|
3
|
-
import { Inspector } from 'react-dev-inspector';
|
|
4
3
|
import './globals.css';
|
|
5
4
|
|
|
6
5
|
const geistSans = Geist({
|
|
@@ -34,9 +33,9 @@ export const metadata: Metadata = {
|
|
|
34
33
|
],
|
|
35
34
|
authors: [{ name: 'Coze Code Team', url: 'https://code.coze.cn' }],
|
|
36
35
|
generator: 'Coze Code',
|
|
37
|
-
icons: {
|
|
38
|
-
|
|
39
|
-
},
|
|
36
|
+
// icons: {
|
|
37
|
+
// icon: '',
|
|
38
|
+
// },
|
|
40
39
|
openGraph: {
|
|
41
40
|
title: '扣子编程 | 你的 AI 工程师已就位',
|
|
42
41
|
description:
|
|
@@ -45,22 +44,22 @@ export const metadata: Metadata = {
|
|
|
45
44
|
siteName: '扣子编程',
|
|
46
45
|
locale: 'zh_CN',
|
|
47
46
|
type: 'website',
|
|
48
|
-
images: [
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
],
|
|
56
|
-
},
|
|
57
|
-
twitter: {
|
|
58
|
-
card: 'summary_large_image',
|
|
59
|
-
title: 'Coze Code | Your AI Engineer is Here',
|
|
60
|
-
description:
|
|
61
|
-
'Build and deploy full-stack applications through AI conversation. No env setup, just flow.',
|
|
62
|
-
images: [''],
|
|
47
|
+
// images: [
|
|
48
|
+
// {
|
|
49
|
+
// url: '',
|
|
50
|
+
// width: 1200,
|
|
51
|
+
// height: 630,
|
|
52
|
+
// alt: '扣子编程 - 你的 AI 工程师',
|
|
53
|
+
// },
|
|
54
|
+
// ],
|
|
63
55
|
},
|
|
56
|
+
// twitter: {
|
|
57
|
+
// card: 'summary_large_image',
|
|
58
|
+
// title: 'Coze Code | Your AI Engineer is Here',
|
|
59
|
+
// description:
|
|
60
|
+
// 'Build and deploy full-stack applications through AI conversation. No env setup, just flow.',
|
|
61
|
+
// // images: [''],
|
|
62
|
+
// },
|
|
64
63
|
robots: {
|
|
65
64
|
index: true,
|
|
66
65
|
follow: true,
|
|
@@ -72,14 +71,11 @@ export default function RootLayout({
|
|
|
72
71
|
}: Readonly<{
|
|
73
72
|
children: React.ReactNode;
|
|
74
73
|
}>) {
|
|
75
|
-
const isDev = process.env.NODE_ENV === 'development';
|
|
76
|
-
|
|
77
74
|
return (
|
|
78
75
|
<html lang="en">
|
|
79
76
|
<body
|
|
80
77
|
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
|
81
78
|
>
|
|
82
|
-
{isDev && <Inspector />}
|
|
83
79
|
{children}
|
|
84
80
|
</body>
|
|
85
81
|
</html>
|
|
@@ -52,6 +52,13 @@
|
|
|
52
52
|
"port": {
|
|
53
53
|
"type": "number",
|
|
54
54
|
"description": "Development server port",
|
|
55
|
+
"default": 5000,
|
|
56
|
+
"minimum": 1024,
|
|
57
|
+
"maximum": 65535
|
|
58
|
+
},
|
|
59
|
+
"hmrPort": {
|
|
60
|
+
"type": "number",
|
|
61
|
+
"description": "Development HMR server port",
|
|
55
62
|
"default": 6000,
|
|
56
63
|
"minimum": 1024,
|
|
57
64
|
"maximum": 65535
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
export const paramsSchema = {
|
|
11
12
|
type: 'object',
|
|
12
13
|
properties: {
|
|
@@ -19,11 +20,18 @@ export const paramsSchema = {
|
|
|
19
20
|
},
|
|
20
21
|
port: {
|
|
21
22
|
type: 'number',
|
|
22
|
-
default:
|
|
23
|
+
default: 5000,
|
|
23
24
|
minimum: 1024,
|
|
24
25
|
maximum: 65535,
|
|
25
26
|
description: 'Development server port',
|
|
26
27
|
},
|
|
28
|
+
hmrPort: {
|
|
29
|
+
type: 'number',
|
|
30
|
+
default: 6000,
|
|
31
|
+
minimum: 1024,
|
|
32
|
+
maximum: 65535,
|
|
33
|
+
description: 'Development HMR server port',
|
|
34
|
+
},
|
|
27
35
|
},
|
|
28
36
|
required: [],
|
|
29
37
|
additionalProperties: false,
|
|
@@ -33,8 +41,9 @@ const config = {
|
|
|
33
41
|
paramsSchema,
|
|
34
42
|
|
|
35
43
|
defaultParams: {
|
|
36
|
-
port:
|
|
37
|
-
|
|
44
|
+
port: 5000,
|
|
45
|
+
hmrPort: 6000,
|
|
46
|
+
appName: 'projects',
|
|
38
47
|
},
|
|
39
48
|
|
|
40
49
|
onBeforeRender: async context => {
|
package/lib/cli.js
CHANGED
|
@@ -9,6 +9,8 @@ var perf_hooks = require('perf_hooks');
|
|
|
9
9
|
var fs$1 = require('fs/promises');
|
|
10
10
|
var toml = require('@iarna/toml');
|
|
11
11
|
var jsYaml = require('js-yaml');
|
|
12
|
+
var child_process = require('child_process');
|
|
13
|
+
var os = require('os');
|
|
12
14
|
var addFormats = require('ajv-formats');
|
|
13
15
|
var Ajv = require('ajv');
|
|
14
16
|
var minimist = require('minimist');
|
|
@@ -125,7 +127,7 @@ const generateTemplatesHelpText = () => {
|
|
|
125
127
|
return lines.join('\n');
|
|
126
128
|
};
|
|
127
129
|
|
|
128
|
-
function _nullishCoalesce$2(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$
|
|
130
|
+
function _nullishCoalesce$2(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var LogLevel; (function (LogLevel) {
|
|
129
131
|
const ERROR = 0; LogLevel[LogLevel["ERROR"] = ERROR] = "ERROR";
|
|
130
132
|
const WARN = 1; LogLevel[LogLevel["WARN"] = WARN] = "WARN";
|
|
131
133
|
const SUCCESS = 2; LogLevel[LogLevel["SUCCESS"] = SUCCESS] = "SUCCESS";
|
|
@@ -172,7 +174,7 @@ class Logger {
|
|
|
172
174
|
return level;
|
|
173
175
|
}
|
|
174
176
|
|
|
175
|
-
const envLevel = _optionalChain$
|
|
177
|
+
const envLevel = _optionalChain$3([process, 'access', _ => _.env, 'access', _2 => _2.LOG_LEVEL, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4()]);
|
|
176
178
|
if (envLevel && envLevel in LOG_LEVEL_MAP) {
|
|
177
179
|
return LOG_LEVEL_MAP[envLevel];
|
|
178
180
|
}
|
|
@@ -184,7 +186,7 @@ class Logger {
|
|
|
184
186
|
// 简单检测:Node.js 环境且支持 TTY
|
|
185
187
|
return (
|
|
186
188
|
typeof process !== 'undefined' &&
|
|
187
|
-
_optionalChain$
|
|
189
|
+
_optionalChain$3([process, 'access', _5 => _5.stdout, 'optionalAccess', _6 => _6.isTTY]) === true &&
|
|
188
190
|
process.env.NO_COLOR === undefined
|
|
189
191
|
);
|
|
190
192
|
}
|
|
@@ -593,7 +595,7 @@ const registerCommand$2 = program => {
|
|
|
593
595
|
});
|
|
594
596
|
};
|
|
595
597
|
|
|
596
|
-
function _optionalChain$
|
|
598
|
+
function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
597
599
|
// Safe JSON parsing utilities with type safety and error handling
|
|
598
600
|
// Provides fallback values, validation, and error monitoring capabilities
|
|
599
601
|
|
|
@@ -684,12 +686,12 @@ function safeJsonParse(
|
|
|
684
686
|
const parsed = JSON.parse(String(input));
|
|
685
687
|
|
|
686
688
|
// Optional validation
|
|
687
|
-
if (_optionalChain$
|
|
689
|
+
if (_optionalChain$2([options, 'optionalAccess', _ => _.validate])) {
|
|
688
690
|
if (options.validate(parsed)) {
|
|
689
691
|
return parsed;
|
|
690
692
|
} else {
|
|
691
693
|
const validationError = new Error('JSON validation failed');
|
|
692
|
-
_optionalChain$
|
|
694
|
+
_optionalChain$2([options, 'access', _2 => _2.onError, 'optionalCall', _3 => _3(validationError, input)]);
|
|
693
695
|
|
|
694
696
|
if (options.throwOnValidationError) {
|
|
695
697
|
throw validationError;
|
|
@@ -701,15 +703,15 @@ function safeJsonParse(
|
|
|
701
703
|
return parsed;
|
|
702
704
|
} catch (error) {
|
|
703
705
|
// Re-throw validation errors when throwOnValidationError is true
|
|
704
|
-
if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$
|
|
706
|
+
if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$2([options, 'optionalAccess', _4 => _4.throwOnValidationError])) {
|
|
705
707
|
throw error;
|
|
706
708
|
}
|
|
707
|
-
_optionalChain$
|
|
709
|
+
_optionalChain$2([options, 'optionalAccess', _5 => _5.onError, 'optionalCall', _6 => _6(error , input)]);
|
|
708
710
|
return defaultValue;
|
|
709
711
|
}
|
|
710
712
|
}
|
|
711
713
|
|
|
712
|
-
function _optionalChain$
|
|
714
|
+
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
713
715
|
|
|
714
716
|
|
|
715
717
|
/**
|
|
@@ -799,13 +801,13 @@ const getCommandConfig = (
|
|
|
799
801
|
// 根据命令名称映射到配置路径
|
|
800
802
|
switch (commandName) {
|
|
801
803
|
case 'dev':
|
|
802
|
-
commandConfig = _optionalChain$
|
|
804
|
+
commandConfig = _optionalChain$1([config, 'access', _ => _.dev, 'optionalAccess', _2 => _2.run]);
|
|
803
805
|
break;
|
|
804
806
|
case 'build':
|
|
805
|
-
commandConfig = _optionalChain$
|
|
807
|
+
commandConfig = _optionalChain$1([config, 'access', _3 => _3.deploy, 'optionalAccess', _4 => _4.build]);
|
|
806
808
|
break;
|
|
807
809
|
case 'start':
|
|
808
|
-
commandConfig = _optionalChain$
|
|
810
|
+
commandConfig = _optionalChain$1([config, 'access', _5 => _5.deploy, 'optionalAccess', _6 => _6.run]);
|
|
809
811
|
break;
|
|
810
812
|
default:
|
|
811
813
|
throw new Error(`Unknown command: ${commandName}`);
|
|
@@ -821,7 +823,7 @@ const getCommandConfig = (
|
|
|
821
823
|
return commandConfig;
|
|
822
824
|
};
|
|
823
825
|
|
|
824
|
-
function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain
|
|
826
|
+
function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
825
827
|
|
|
826
828
|
/**
|
|
827
829
|
* 创建日志管理器
|
|
@@ -879,12 +881,12 @@ const executeRun = async (
|
|
|
879
881
|
}
|
|
880
882
|
|
|
881
883
|
// 将输出同时写入控制台和日志文件
|
|
882
|
-
_optionalChain
|
|
884
|
+
_optionalChain([childProcess, 'access', _ => _.stdout, 'optionalAccess', _2 => _2.on, 'call', _3 => _3('data', (data) => {
|
|
883
885
|
process.stdout.write(data);
|
|
884
886
|
logStream.write(data);
|
|
885
887
|
})]);
|
|
886
888
|
|
|
887
|
-
_optionalChain
|
|
889
|
+
_optionalChain([childProcess, 'access', _4 => _4.stderr, 'optionalAccess', _5 => _5.on, 'call', _6 => _6('data', (data) => {
|
|
888
890
|
process.stderr.write(data);
|
|
889
891
|
logStream.write(data);
|
|
890
892
|
})]);
|
|
@@ -952,6 +954,45 @@ const registerCommand$1 = program => {
|
|
|
952
954
|
});
|
|
953
955
|
};
|
|
954
956
|
|
|
957
|
+
/**
|
|
958
|
+
* 在后台启动一个独立的子进程
|
|
959
|
+
* 类似于 `setsid command args >/dev/null 2>&1 &`
|
|
960
|
+
*
|
|
961
|
+
* @param command - 要执行的命令 (例如: 'npm', 'node', 'bash')
|
|
962
|
+
* @param args - 命令参数数组 (例如: ['run', 'dev'])
|
|
963
|
+
* @param options - 配置选项
|
|
964
|
+
* @returns 子进程的 PID
|
|
965
|
+
*/
|
|
966
|
+
function spawnDetached(
|
|
967
|
+
command,
|
|
968
|
+
args,
|
|
969
|
+
options,
|
|
970
|
+
) {
|
|
971
|
+
const { cwd, verbose = true } = options;
|
|
972
|
+
const isWindows = os.platform() === 'win32';
|
|
973
|
+
|
|
974
|
+
if (verbose) {
|
|
975
|
+
console.log(`Spawning detached process: ${command} ${args.join(' ')}`);
|
|
976
|
+
console.log(`Working directory: ${cwd}`);
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// 使用 spawn 创建后台子进程
|
|
980
|
+
const child = child_process.spawn(command, args, {
|
|
981
|
+
cwd,
|
|
982
|
+
detached: !isWindows, // Windows 不完全支持 detached,但仍可以使用
|
|
983
|
+
stdio: 'ignore', // 忽略所有输入输出,让进程完全独立运行
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
// 分离父子进程引用,允许父进程退出而不等待子进程
|
|
987
|
+
child.unref();
|
|
988
|
+
|
|
989
|
+
if (verbose && child.pid) {
|
|
990
|
+
console.log(`Process started with PID: ${child.pid}`);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
return child.pid;
|
|
994
|
+
}
|
|
995
|
+
|
|
955
996
|
/**
|
|
956
997
|
* 创建 AJV 验证器实例
|
|
957
998
|
*/
|
|
@@ -1465,7 +1506,7 @@ const execute = async (
|
|
|
1465
1506
|
return absoluteOutputPath;
|
|
1466
1507
|
};
|
|
1467
1508
|
|
|
1468
|
-
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
1509
|
+
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
1469
1510
|
/**
|
|
1470
1511
|
* 运行 pnpm install
|
|
1471
1512
|
*/
|
|
@@ -1568,45 +1609,26 @@ const runGitInit = (projectPath) => {
|
|
|
1568
1609
|
};
|
|
1569
1610
|
|
|
1570
1611
|
/**
|
|
1571
|
-
* 运行开发服务器
|
|
1612
|
+
* 运行开发服务器(后台模式)
|
|
1613
|
+
* 启动后台子进程运行开发服务器,父进程可以直接退出
|
|
1572
1614
|
*/
|
|
1573
1615
|
const runNpmDev = (projectPath) => {
|
|
1574
|
-
logger.info('\nStarting development server...');
|
|
1616
|
+
logger.info('\nStarting development server in background...');
|
|
1575
1617
|
logger.info(`Executing: npm run dev in ${projectPath}`);
|
|
1576
|
-
logger.info('Press Ctrl+C to stop the server\n');
|
|
1577
1618
|
|
|
1578
|
-
//
|
|
1579
|
-
const
|
|
1619
|
+
// 使用通用的后台执行函数启动开发服务器
|
|
1620
|
+
const pid = spawnDetached('npm', ['run', 'dev'], {
|
|
1580
1621
|
cwd: projectPath,
|
|
1581
|
-
|
|
1582
|
-
silent: true, // 手动处理输出以便显示详细信息
|
|
1622
|
+
verbose: false, // 不输出额外的进程信息,由 logger 统一处理
|
|
1583
1623
|
});
|
|
1584
1624
|
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
_optionalChain([child, 'access', _4 => _4.stderr, 'optionalAccess', _5 => _5.on, 'call', _6 => _6('data', (data) => {
|
|
1593
|
-
process.stderr.write(data);
|
|
1594
|
-
})]);
|
|
1595
|
-
|
|
1596
|
-
// 监听错误
|
|
1597
|
-
child.on('error', (error) => {
|
|
1598
|
-
logger.error(`Failed to start dev server: ${error.message}`);
|
|
1599
|
-
logger.error(`Error stack: ${error.stack}`);
|
|
1600
|
-
});
|
|
1601
|
-
|
|
1602
|
-
// 监听退出
|
|
1603
|
-
child.on('exit', (code, signal) => {
|
|
1604
|
-
if (code !== 0 && code !== null) {
|
|
1605
|
-
logger.error(
|
|
1606
|
-
`Dev server exited with code ${code}${signal ? ` and signal ${signal}` : ''}`,
|
|
1607
|
-
);
|
|
1608
|
-
}
|
|
1609
|
-
});
|
|
1625
|
+
logger.success('Development server started in background!');
|
|
1626
|
+
if (pid) {
|
|
1627
|
+
logger.info(`Process ID: ${pid}`);
|
|
1628
|
+
logger.info(
|
|
1629
|
+
'\nThe dev server is running independently. You can close this terminal.',
|
|
1630
|
+
);
|
|
1631
|
+
logger.info(`To stop the server later, use: kill ${pid}`);
|
|
1610
1632
|
}
|
|
1611
1633
|
};
|
|
1612
1634
|
|
|
@@ -1719,7 +1741,7 @@ const registerCommand = program => {
|
|
|
1719
1741
|
});
|
|
1720
1742
|
};
|
|
1721
1743
|
|
|
1722
|
-
var version = "0.0.1-alpha.
|
|
1744
|
+
var version = "0.0.1-alpha.21f492";
|
|
1723
1745
|
var packageJson = {
|
|
1724
1746
|
version: version};
|
|
1725
1747
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coze-arch/cli",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.21f492",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "coze coding devtools cli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"prebuild": "tsx scripts/prebuild.ts",
|
|
21
21
|
"build": "tsx scripts/build.ts",
|
|
22
|
-
"generate-templates": "tsx scripts/generate-templates-config.ts",
|
|
23
22
|
"lint": "eslint ./ --cache",
|
|
24
23
|
"postpublish": "bash scripts/sync-npmmirror.sh",
|
|
25
24
|
"test": "vitest --run --passWithNoTests",
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'node:http';
|
|
2
|
-
import next from 'next';
|
|
3
|
-
import { launchEditorMiddleware } from '@react-dev-inspector/middleware';
|
|
4
|
-
|
|
5
|
-
const dev = process.env.NODE_ENV !== 'production';
|
|
6
|
-
const hostname = process.env.HOSTNAME || 'localhost';
|
|
7
|
-
const port = parseInt(process.env.PORT || '3000', 10);
|
|
8
|
-
|
|
9
|
-
const app = next({ dev, hostname, port });
|
|
10
|
-
const handle = app.getRequestHandler();
|
|
11
|
-
|
|
12
|
-
app.prepare().then(() => {
|
|
13
|
-
createServer((req, res) => {
|
|
14
|
-
/**
|
|
15
|
-
* Middlewares, from top to bottom
|
|
16
|
-
*/
|
|
17
|
-
const middlewares = [
|
|
18
|
-
/**
|
|
19
|
-
* react-dev-inspector middleware for launching editor
|
|
20
|
-
* Only active in development mode
|
|
21
|
-
*/
|
|
22
|
-
...(dev ? [launchEditorMiddleware] : []),
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Next.js default app handler
|
|
26
|
-
*/
|
|
27
|
-
(req, res) => handle(req, res),
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Build middleware pipeline using reduceRight
|
|
32
|
-
* Executes middlewares from top to bottom
|
|
33
|
-
*/
|
|
34
|
-
const middlewarePipeline = middlewares.reduceRight(
|
|
35
|
-
(next, middleware) => () => {
|
|
36
|
-
middleware(req, res, next);
|
|
37
|
-
},
|
|
38
|
-
() => {},
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
middlewarePipeline();
|
|
42
|
-
})
|
|
43
|
-
.once('error', (err) => {
|
|
44
|
-
console.error(err);
|
|
45
|
-
process.exit(1);
|
|
46
|
-
})
|
|
47
|
-
.listen(port, () => {
|
|
48
|
-
console.log(`> Ready on http://${hostname}:${port}`);
|
|
49
|
-
});
|
|
50
|
-
});
|