使用Theia——构建你自己的IDE

上一篇:Theia架构

构建你自己的IDE

  本指南将教你如何构建你自己的Theia应用。

必要条件

  你需要安装node 10版本(译者:事实上最新的node稳定版即可):

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
nvm install 10

  以及yarn:

npm install -g yarn

  还需要确保已安装python 2.x,可通过python --version来检查。

安装

  首先请创建一个空目录,然后切换到这个目录下:

mkdir my-app
cd my-app

  在这个目录下创建package.json

{
  "private": true,
  "dependencies": {
    "typescript": "latest",
    "@theia/typescript": "next",
    "@theia/navigator": "next",
    "@theia/terminal": "next",
    "@theia/outline-view": "next",
    "@theia/preferences": "next",
    "@theia/messages": "next",
    "@theia/git": "next",
    "@theia/file-search": "next",
    "@theia/markers": "next",
    "@theia/preview": "next",
    "@theia/callhierarchy": "next",
    "@theia/merge-conflicts": "next",
    "@theia/search-in-workspace": "next",
    "@theia/json": "next",
    "@theia/textmate-grammars": "next",
    "@theia/mini-browser": "next"
  },
  "devDependencies": {
    "@theia/cli": "next"
  }
}

  简而言之,Theia应用程序和扩展包都是Node.js包。每一个包都包含一个package.json文件,里面列出了包的一些元数据,如name、version、运行时和构建时的依赖关系等。

  我们来看看这个包的内容:
  • nameversion被省略了,因为我们不打算将它作为一个依赖项来使用。同时它被标记为private,因为不打算将它发布为一个独立的Node.js包。
  • 我们在dependencies中列出了所有运行时依赖的扩展包,如@theia/navigator
  • 我们将@theis/cli列为构建时的依赖项,它提供了构建和运行应用程序的脚本。

构建

  首先,安装所有的依赖项。

yarn

  然后,使用Theia CLI来构建应用程序。

yarn theia build

  yarn在我们应用程序的上下文中查找由@theia/cli提供的theia可执行文件,然后使用theia执行build命令。这可能需要一些时间,因为默认情况下应用程序会在production模式下进行构建,即它会进行模糊处理和最小化处理。

运行

  构建完成之后,我们就可以启动应用程序:

yarn theia start

  你可以在命令的第一个参数中指定一个workspace路径,--hostname--port选项用来指定部署的主机名和端口号。例如下面的命令在指定的位置和端口号上打开/workspace

yarn theia start /my-workspace --hostname 0.0.0.0 --port 8080

  在终端中,你应该看到Theia应用程序已经启动并监听:

   打开浏览器并输入上面显示的地址,你就可以打开应用程序了。

故障排除

通过代理构建本地依赖项

  如果你通过代理运行yarn命令,在构建本地依赖项时有可能会遇到一些问题(如onigurma),例如下面的这个错误:

[4/4] Building fresh packages...
[1/9]  XXXXX
[2/9]  XXXXX
[3/9]  XXXXX
[4/9]  XXXXX
error /theiaide/node_modules/XXXXX: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /theiaide/node_modules/XXXXX
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@8.15.0 | linux | x64
gyp http GET https://nodejs.org/download/release/v8.15.0/node-v8.15.0-headers.tar.gz
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: read ECONNRESET
gyp ERR! stack at TLSWrap.onread (net.js:622:25)
gyp ERR! System Linux 3.10.0-862.11.6.el7.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /theiaide/node_modules/XXXXX
gyp ERR! node -v v8.15.0

  这是因为node-gyp在system/NPM的代理设置中不工作。如果遇到这种情况,可以通过错误堆栈中提供的链接下载node-headers文件(如上面例子中的https://nodejs.org/download/release/v8.15.0/node-v8.15.0-headers.tar.gz),然后使用下面的命令进行构建:

npm_config_tarball=/path/to/node-v8.15.0-headers.tar.gz yarn install

 

原文地址:https://theia-ide.org/docs/composing_applications/

posted @ 2020-01-04 10:29  Jaxu  阅读(10157)  评论(0编辑  收藏  举报