Skip to content

Commit 850d4c0

Browse files
eedpublicweimin2.zhoudependabot[bot]renovate[bot]
authored
CodeFuse IDE Support Web IDE #32 (#54)
* WIP: CodeFuse IDE Support Web IDE #32 * Delete patches/@opensumi+ide-core-browser+3.4.4.patch * chore(deps): bump cross-spawn from 6.0.5 to 6.0.6 (#60) Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 6.0.5 to 6.0.6. - [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/v6.0.6/CHANGELOG.md) - [Commits](moxystudio/node-cross-spawn@v6.0.5...v6.0.6) --- updated-dependencies: - dependency-name: cross-spawn dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> (cherry picked from commit e1e7ae7) * chore(deps-dev): bump @electron-forge/cli from 7.4.0 to 7.5.0 (#58) Bumps [@electron-forge/cli](https://github.com/electron/forge) from 7.4.0 to 7.5.0. - [Release notes](https://github.com/electron/forge/releases) - [Changelog](https://github.com/electron/forge/blob/main/CHANGELOG.md) - [Commits](electron/forge@v7.4.0...v7.5.0) --- updated-dependencies: - dependency-name: "@electron-forge/cli" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> (cherry picked from commit b1e2b05) * chore(deps-dev): bump app-builder-lib from 24.13.3 to 25.1.8 (#59) Bumps [app-builder-lib](https://github.com/electron-userland/electron-builder/tree/HEAD/packages/app-builder-lib) from 24.13.3 to 25.1.8. - [Release notes](https://github.com/electron-userland/electron-builder/releases) - [Changelog](https://github.com/electron-userland/electron-builder/blob/master/packages/app-builder-lib/CHANGELOG.md) - [Commits](https://github.com/electron-userland/electron-builder/commits/electron-builder@25.1.8/packages/app-builder-lib) --- updated-dependencies: - dependency-name: app-builder-lib dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> (cherry picked from commit 191729d) * fix(deps): update opensumi packages to v3.6.0 (#65) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> (cherry picked from commit 771e23b) * chore(deps-dev): bump webpack-dev-server from 5.0.4 to 5.1.0 (#64) Bumps [webpack-dev-server](https://github.com/webpack/webpack-dev-server) from 5.0.4 to 5.1.0. - [Release notes](https://github.com/webpack/webpack-dev-server/releases) - [Changelog](https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md) - [Commits](webpack/webpack-dev-server@v5.0.4...v5.1.0) --- updated-dependencies: - dependency-name: webpack-dev-server dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> (cherry picked from commit c6707aa) * WIP: CodeFuse IDE Support Web IDE #32 * CodeFuse IDE Support Web IDE #32 * CodeFuse IDE Support Web IDE #32 --------- Co-authored-by: weimin2.zhou <weimin2.zhou@tcl.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent c6707aa commit 850d4c0

30 files changed

+4192
-1033
lines changed

.env.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CODE_WINDOW_CLIENT_ID=CODE_WINDOW_CLIENT_ID
2+
IDE_LOG_HOME=""
3+
IDE_SERVER_PORT=8000
4+
WS_PATH=ws://localhost:8080

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jspm_packages/
8181
dist
8282
lib
8383
out
84+
out-web
8485
.vscode/*
8586
!.vscode/launch.json
8687

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ yarn run electron-rebuild
4343
yarn run start
4444
```
4545

46+
### Start the project (web)
47+
```bash
48+
# install dependencies
49+
yarn
50+
# rebuild native dependencies for electron
51+
yarn run electron-rebuild
52+
# build web
53+
yarn run build-web
54+
# start project
55+
yarn run start-web
56+
```
57+
4658
## Links
4759

4860
- **CodeFuse**: https://codefuse.ai

build/rebuild.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ export const rebuild = async (config?: { arch?: string, cwd?: string, silent?: b
4242
}
4343

4444
if (require.main === module) {
45-
rebuild()
45+
rebuild({
46+
silent: false
47+
})
4648
}

build/webpack-web/web-start.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { exec } from 'child_process';
2+
import path from 'path';
3+
4+
// 定义每个命令的启动函数
5+
const commands = {
6+
client: 'cross-env NODE_ENV=development WEBPACK_LOG_LEVEL=info webpack-dev-server --client-logging info --config ./build/webpack-web/webpack.browser.config.ts --progress --color',
7+
webview: 'cross-env NODE_ENV=development webpack-dev-server --config ./build/webpack-web/webpack.webview.config.ts --progress --color',
8+
server: 'cross-env NODE_ENV=development node -r ts-node/register -r tsconfig-paths/register src/bootstrap-web/node/index.ts'
9+
};
10+
11+
// 启动子进程并打印输出
12+
function startProcess(command: string, name: string) {
13+
const child = exec(command, {cwd: path.resolve(__dirname, '../../')}, (error, stdout, stderr) => {
14+
if (error) {
15+
console.error(`[${name}] Error: ${error.message}`);
16+
return;
17+
}
18+
19+
if (stderr) {
20+
console.error(`[${name}] stderr: ${stderr}`);
21+
return;
22+
}
23+
24+
console.log(`[${name}] stdout: ${stdout}`);
25+
});
26+
27+
child.stdout?.on('data', (data) => {
28+
console.log(`[${name}] ${data.toString()}`);
29+
});
30+
31+
child.stderr?.on('data', (data) => {
32+
console.error(`[${name}] ${data.toString()}`);
33+
});
34+
}
35+
36+
// 启动所有进程
37+
function startAll() {
38+
Object.entries(commands).forEach(([name, command]) => {
39+
startProcess(command, name);
40+
});
41+
}
42+
43+
startAll();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Configuration, DefinePlugin } from 'webpack'
2+
import path from 'node:path'
3+
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
4+
import { merge } from 'webpack-merge'
5+
6+
export const webpackDir = path.resolve(path.join(__dirname,'..','..', 'out'))
7+
8+
export const devServerPort = 8080
9+
10+
export const codeWindowName = 'code'
11+
12+
export const updateWindowName = 'update'
13+
14+
export const createConfig = (config: Configuration | ((_env: unknown, argv: Record<string, any>) => Configuration)) => (_env: unknown, argv: Record<string, any>) => {
15+
return merge({
16+
mode: argv.mode,
17+
devtool: argv.mode === 'development' ? 'source-map': false,
18+
node: {
19+
__dirname: false,
20+
__filename: false,
21+
},
22+
output: {
23+
asyncChunks: false,
24+
},
25+
resolve: {
26+
extensions: ['.ts', '.tsx', '.mjs', '.js', '.json', '.less'],
27+
plugins: [
28+
new TsconfigPathsPlugin({
29+
configFile: path.join(__dirname, '../../tsconfig.json'),
30+
}),
31+
],
32+
},
33+
module: {
34+
// https://github.com/webpack/webpack/issues/196#issuecomment-397606728
35+
exprContextCritical: false,
36+
rules: [
37+
{
38+
test: /\.tsx?$/,
39+
loader: 'ts-loader',
40+
exclude: /(node_modules|\.webpack)/,
41+
options: {
42+
configFile: path.join(__dirname, '../../tsconfig.json'),
43+
transpileOnly: true,
44+
},
45+
},
46+
{
47+
test: /\.mjs$/,
48+
include: /node_modules/,
49+
type: 'javascript/auto',
50+
},
51+
],
52+
},
53+
plugins: [
54+
new DefinePlugin({
55+
'process.env.KTLOG_SHOW_DEBUG': argv.mode === 'development',
56+
}),
57+
],
58+
}, typeof config === 'function' ? config(_env, argv) : config);
59+
};
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
import path from 'node:path';
2+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
3+
import CopyPlugin from 'copy-webpack-plugin';
4+
import HtmlWebpackPlugin from 'html-webpack-plugin';
5+
import NodePolyfillPlugin from "node-polyfill-webpack-plugin"
6+
import {DefinePlugin} from 'webpack'
7+
import fs from 'fs'
8+
import { createConfig, webpackDir, devServerPort } from './webpack.base.config';
9+
import {config} from 'dotenv'
10+
config({
11+
path: path.join(__dirname, '../../.env')
12+
})
13+
14+
const srcDir = path.resolve('src/bootstrap-web/browser');
15+
const outDir = path.resolve(webpackDir);
16+
const publicDir = path.join(__dirname, '../../public');
17+
18+
19+
const isDevelopment = process.env.NODE_ENV === 'development';
20+
const idePkg = JSON.parse(fs.readFileSync(path.resolve(path.join(__dirname,'../../package.json'))).toString())
21+
22+
export default createConfig((_env, argv) => {
23+
const styleLoader = argv.mode === 'production' ? MiniCssExtractPlugin.loader : 'style-loader'
24+
25+
return {
26+
entry: path.resolve(srcDir, 'index.ts'),
27+
output: {
28+
filename: '[name]/index.js',
29+
path: outDir,
30+
assetModuleFilename: 'assets/[name].[hash][ext]',
31+
},
32+
devtool: argv.mode === 'production' ? false as const : 'eval-source-map',
33+
target: 'web',
34+
externalsPresets: {
35+
node: false,
36+
},
37+
module: {
38+
rules: [
39+
{
40+
test: /\.css$/,
41+
use: [styleLoader, 'css-loader'],
42+
},
43+
{
44+
test: /\.module.less$/,
45+
use: [
46+
{
47+
loader: styleLoader,
48+
options: {
49+
esModule: false,
50+
}
51+
},
52+
{
53+
loader: 'css-loader',
54+
options: {
55+
importLoaders: 0,
56+
sourceMap: true,
57+
esModule: false,
58+
modules: {
59+
localIdentName: '[local]___[hash:base64:5]',
60+
},
61+
},
62+
},
63+
{
64+
loader: 'less-loader',
65+
options: {
66+
lessOptions: {
67+
javascriptEnabled: true,
68+
},
69+
},
70+
},
71+
],
72+
},
73+
{
74+
test: /^((?!\.module).)*less$/,
75+
use: [
76+
{
77+
loader: styleLoader,
78+
options: {
79+
esModule: false,
80+
}
81+
},
82+
{
83+
loader: 'css-loader',
84+
options: {
85+
importLoaders: 0,
86+
esModule: false,
87+
},
88+
},
89+
{
90+
loader: 'less-loader',
91+
options: {
92+
lessOptions: {
93+
javascriptEnabled: true,
94+
},
95+
},
96+
},
97+
],
98+
},
99+
{
100+
test: /\.(woff(2)?|ttf|eot|svg|png)(\?v=\d+\.\d+\.\d+)?$/,
101+
type: 'asset',
102+
parser: {
103+
dataUrlCondition: {
104+
maxSize: 8 * 1024,
105+
}
106+
}
107+
},
108+
],
109+
},
110+
experiments: {
111+
syncWebAssembly: true,
112+
asyncWebAssembly: true
113+
},
114+
plugins: [
115+
new DefinePlugin({
116+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
117+
'process.platform': JSON.stringify('browser'),
118+
'process.env.WORKSPACE_DIR': JSON.stringify(
119+
isDevelopment ? path.join(__dirname, '../..', 'workspace') : process.env['WORKSPACE_DIR'],
120+
),
121+
'process.env.EXTENSION_DIR': JSON.stringify(
122+
isDevelopment ? path.join(__dirname, '../..', 'extensions') : process.env['EXTENSION_DIR'],
123+
),
124+
'process.env.REVERSION': JSON.stringify(idePkg.version || 'alpha'),
125+
'process.env.DEVELOPMENT': JSON.stringify(!!isDevelopment),
126+
'process.env.TEMPLATE_TYPE': JSON.stringify(
127+
isDevelopment ? process.env.TEMPLATE_TYPE : 'standard',
128+
),
129+
'process.env.IDE_SERVER_PORT': JSON.stringify(process.env.IDE_SERVER_PORT),
130+
'process.env.WS_PATH': JSON.stringify(process.env.WS_PATH),
131+
'process.env.STATIC_SERVER_PATH': JSON.stringify(process.env.STATIC_SERVER_PATH),
132+
'process.env.EXTENSION_WORKER_HOST': JSON.stringify(process.env.EXTENSION_WORKER_HOST),
133+
'process.env.WEBVIEW_HOST': JSON.stringify(process.env.WEBVIEW_HOST),
134+
}),
135+
new HtmlWebpackPlugin({
136+
template: path.join(publicDir, 'index.html'),
137+
}),
138+
...(argv.mode === 'production' ? [
139+
new MiniCssExtractPlugin({
140+
filename: '[name]/index.css',
141+
chunkFilename: '[id].css',
142+
})
143+
] : []),
144+
new CopyPlugin({
145+
patterns: [
146+
{
147+
from: require.resolve('@opensumi/ide-monaco/worker/editor.worker.bundle.js'),
148+
to: path.join(outDir, 'editor.worker.bundle.js'),
149+
},
150+
],
151+
}),
152+
new NodePolyfillPlugin({
153+
// excludeAliases: ['path', 'Buffer', 'process'],
154+
}),
155+
],
156+
optimization: {
157+
splitChunks: {
158+
cacheGroups: {
159+
vendor: {
160+
name: 'vendor',
161+
chunks: 'all',
162+
minChunks: 2,
163+
},
164+
},
165+
}
166+
},
167+
infrastructureLogging: {
168+
level: 'none'
169+
},
170+
stats: 'none',
171+
devServer: {
172+
hot: true,
173+
devMiddleware: {
174+
writeToDisk: true,
175+
},
176+
client: {
177+
overlay: {
178+
runtimeErrors: false,
179+
warnings: false,
180+
}
181+
},
182+
historyApiFallback: true,
183+
port: devServerPort,
184+
proxy: [
185+
{
186+
context: ['/service'],
187+
target: 'ws://localhost:8000',
188+
ws: true
189+
},
190+
],
191+
setupExitSignals: true,
192+
static: outDir,
193+
headers: {
194+
'Content-Security-Policy': "default-src 'self' 'unsafe-inline' data: file:; script-src 'self' 'unsafe-eval' 'unsafe-inline' data: file:; connect-src 'self' file:; worker-src 'self' data: blob:; img-src 'self' data: file:",
195+
},
196+
}
197+
}
198+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import path from 'node:path';
2+
import { createConfig, webpackDir } from './webpack.base.config';
3+
import { asarDeps } from '../deps'
4+
5+
const srcDir = path.resolve('src/bootstrap-web/ext-host');
6+
const outDir = path.join(webpackDir, 'ext-host');
7+
8+
module.exports = createConfig((_, argv) => ({
9+
entry: srcDir,
10+
output: {
11+
filename: 'index.js',
12+
path: outDir,
13+
},
14+
externals: [
15+
({ request }, callback) => {
16+
if (asarDeps.includes(request!)) {
17+
return callback(null, 'commonjs ' + request);
18+
}
19+
callback();
20+
},
21+
],
22+
target: 'node',
23+
}))

0 commit comments

Comments
 (0)