-
Notifications
You must be signed in to change notification settings - Fork 7
/
commit.html
229 lines (199 loc) · 24.2 KB
/
commit.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!DOCTYPE html>
<html lang="zh-cn">
<head prefix="og: http://ogp.me/ns#">
<meta charset="utf-8">
<title>使用外部工具提交代码 | Screeps 中文文档</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Canonical links -->
<link rel="canonical" href="http://screeps-cn.github.io/commit.html">
<!-- Alternative links -->
<link rel="alternative" hreflang="en" href="http://screeps-cn.github.io/commit.html">
<link rel="alternative" hreflang="zh-tw" href="http://screeps-cn.github.io/zh-tw/commit.html">
<link rel="alternative" hreflang="zh-cn" href="http://screeps-cn.github.io/zh-cn/commit.html">
<link rel="alternative" hreflang="ru" href="http://screeps-cn.github.io/ru/commit.html">
<link rel="alternative" hreflang="ko" href="http://screeps-cn.github.io/ko/commit.html">
<!-- Icon -->
<link rel="apple-touch-icon" sizes="57x57" href="/icon/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="114x114" href="/icon/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="72x72" href="/icon/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="144x144" href="/icon/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="60x60" href="/icon/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="120x120" href="/icon/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="76x76" href="/icon/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="152x152" href="/icon/apple-touch-icon-152x152.png">
<link rel="icon" type="image/png" href="/icon/favicon-196x196.png" sizes="196x196">
<link rel="icon" type="image/png" href="/icon/favicon-160x160.png" sizes="160x160">
<link rel="icon" type="image/png" href="/icon/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/icon/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="/icon/favicon-32x32.png" sizes="32x32">
<meta name="msapplication-TileColor" content="#2f83cd">
<meta name="msapplication-TileImage" content="/icon/mstile-144x144.png">
<!-- CSS -->
<!-- build:css build/css/navy.css -->
<link rel="stylesheet" href="/css/navy.css?1">
<link rel="stylesheet" href="/css/prism.css">
<!-- endbuild -->
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css">
<!-- RSS -->
<link rel="alternate" href="/atom.xml" title="Screeps 中文文档">
<!-- Open Graph -->
<meta name="description" content="Screeps 拥有一个小巧的嵌入式编辑器来方便代码的编写。但是,在某些情况下(例如,您想使用 JavaScript 以外的语言或者想使用您的 IDE),您可能不得不使用其他方式将代码从外部提交至您的 Screeps 账户。
您需要先在 帐户设置 中创建一个登录令牌(auth token)来使用外部提交。
使用 Grunt 任务如果您以前从未使用过 Grunt,请务必查看 Getting Sta">
<meta property="og:type" content="website">
<meta property="og:title" content="使用外部工具提交代码">
<meta property="og:url" content="http://screeps-cn.github.io/commit.html">
<meta property="og:site_name" content="Screeps 中文文档">
<meta property="og:description" content="Screeps 拥有一个小巧的嵌入式编辑器来方便代码的编写。但是,在某些情况下(例如,您想使用 JavaScript 以外的语言或者想使用您的 IDE),您可能不得不使用其他方式将代码从外部提交至您的 Screeps 账户。
您需要先在 帐户设置 中创建一个登录令牌(auth token)来使用外部提交。
使用 Grunt 任务如果您以前从未使用过 Grunt,请务必查看 Getting Sta">
<meta property="og:updated_time" content="2024-09-20T13:38:58.407Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用外部工具提交代码">
<meta name="twitter:description" content="Screeps 拥有一个小巧的嵌入式编辑器来方便代码的编写。但是,在某些情况下(例如,您想使用 JavaScript 以外的语言或者想使用您的 IDE),您可能不得不使用其他方式将代码从外部提交至您的 Screeps 账户。
您需要先在 帐户设置 中创建一个登录令牌(auth token)来使用外部提交。
使用 Grunt 任务如果您以前从未使用过 Grunt,请务必查看 Getting Sta">
<!-- Google Analytics -->
</head>
<body>
<div id="container">
<header id="header" class="wrapper">
<div id="header-inner" class="inner">
<h1 id="logo-wrap">
<a href="https://screeps.com" id="logo">Screeps</a>
<a href="/index.html" id="logo-docs">docs</a>
</h1>
<a id="mobile-nav-toggle">
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
</a>
<div id="header-main"></div>
</div>
</header>
<div id="content-wrap">
<div id="content" class="wrapper">
<div id="content-inner">
<article class="article-container" itemscope itemtype="http://schema.org/Article">
<div class="article-inner">
<div class="article">
<div class="inner">
<header class="article-header">
<h1 class="article-title" itemprop="name" id="top">使用外部工具提交代码</h1>
<a href="https://github.com/screeps-cn/docs/edit/master/source/commit.md" class="article-edit-link" title="改进本文"><i class="fa fa-pencil"></i></a>
</header>
<div class="article-content" itemprop="articleBody">
<p>Screeps 拥有一个小巧的嵌入式编辑器来方便代码的编写。但是,在某些情况下(例如,您想使用 JavaScript 以外的语言或者想使用您的 IDE),您可能不得不使用其他方式将代码从外部提交至您的 Screeps 账户。</p>
<blockquote class="note info"><p>您需要先在 <a href="https://screeps.com/a/#!/account/auth-tokens" target="_blank" rel="external">帐户设置</a> 中创建一个登录令牌(auth token)来使用外部提交。</p>
</blockquote>
<h2 id="使用-Grunt-任务" class="article-heading"><a href="#使用-Grunt-任务" class="headerlink" title="使用 Grunt 任务"></a>使用 Grunt 任务<a class="article-anchor" href="#使用-Grunt-任务" aria-hidden="true"></a></h2><p>如果您以前从未使用过 <a href="http://gruntjs.com" target="_blank" rel="external">Grunt</a>,请务必查看 <a href="http://gruntjs.com/getting-started" target="_blank" rel="external">Getting Started</a> 指南,它会告诉您如何创建 <a href="http://gruntjs.com/sample-gruntfile" target="_blank" rel="external">Gruntfile</a> 以及如何安装和使用 Grunt 插件。在您有了一定的了解后,就可以使用以下命令安装此插件:</p>
<pre class="highlight undefined tab-undefined "><code>npm install grunt<span class="token operator">-</span>screeps</code></pre><p>配置您的 Gruntfile.js:</p>
<pre class="highlight undefined tab-undefined "><code>module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span>grunt<span class="token punctuation">)</span> <span class="token punctuation">{</span>
grunt<span class="token punctuation">.</span><span class="token function">loadNpmTasks</span><span class="token punctuation">(</span><span class="token string">'grunt-screeps'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
grunt<span class="token punctuation">.</span><span class="token function">initConfig</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
screeps<span class="token punctuation">:</span> <span class="token punctuation">{</span>
options<span class="token punctuation">:</span> <span class="token punctuation">{</span>
email<span class="token punctuation">:</span> <span class="token string">'<your e-mail>'</span><span class="token punctuation">,</span>
token<span class="token punctuation">:</span> <span class="token string">'<your auth token>'</span><span class="token punctuation">,</span>
branch<span class="token punctuation">:</span> <span class="token string">'default'</span><span class="token punctuation">,</span>
<span class="token comment" spellcheck="true">//server: 'season'</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
dist<span class="token punctuation">:</span> <span class="token punctuation">{</span>
src<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'dist/*.js'</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre><p>现在,您可以执行以下命令来将您的代码从 <code>dist</code> 文件夹提交至 Screeps 账户:</p>
<pre class="highlight undefined tab-undefined "><code>grunt screeps</code></pre><h2 id="直接通过-API-进行访问" class="article-heading"><a href="#直接通过-API-进行访问" class="headerlink" title="直接通过 API 进行访问"></a>直接通过 API 进行访问<a class="article-anchor" href="#直接通过-API-进行访问" aria-hidden="true"></a></h2><p>Screeps Web API 有一个用于上传/下载代码的接口 <code>https://screeps.com/api/user/code</code>。支持通过 <code>POST</code> 上传代码和通过 <code>GET</code> 下载代码。这两种方法都接受<a href="http://en.wikipedia.org/wiki/Basic_access_authentication" target="_blank" rel="external">基本访问鉴权</a>。接口可以接受或返回一个包含所有模块的 JSON 数据,其中模块的名作为键,模块的内容作为值。</p>
<p>使用 Node.js 提交代码的示例:</p>
<pre class="highlight undefined tab-undefined "><code><span class="token keyword">var</span> https <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'https'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> email <span class="token operator">=</span> <span class="token string">'<your e-mail>'</span><span class="token punctuation">,</span>
password <span class="token operator">=</span> <span class="token string">'<your password>'</span><span class="token punctuation">,</span>
data <span class="token operator">=</span> <span class="token punctuation">{</span>
branch<span class="token punctuation">:</span> <span class="token string">'default'</span><span class="token punctuation">,</span>
modules<span class="token punctuation">:</span> <span class="token punctuation">{</span>
main<span class="token punctuation">:</span> <span class="token string">'require("hello");'</span><span class="token punctuation">,</span>
hello<span class="token punctuation">:</span> <span class="token string">'console.log("Hello World!");'</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> req <span class="token operator">=</span> https<span class="token punctuation">.</span><span class="token function">request</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
hostname<span class="token punctuation">:</span> <span class="token string">'screeps.com'</span><span class="token punctuation">,</span>
port<span class="token punctuation">:</span> <span class="token number">443</span><span class="token punctuation">,</span>
path<span class="token punctuation">:</span> <span class="token string">'/api/user/code'</span><span class="token punctuation">,</span>
method<span class="token punctuation">:</span> <span class="token string">'POST'</span><span class="token punctuation">,</span>
auth<span class="token punctuation">:</span> email <span class="token operator">+</span> <span class="token string">':'</span> <span class="token operator">+</span> password<span class="token punctuation">,</span>
headers<span class="token punctuation">:</span> <span class="token punctuation">{</span>
<span class="token string">'Content-Type'</span><span class="token punctuation">:</span> <span class="token string">'application/json; charset=utf-8'</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
req<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>JSON<span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
req<span class="token punctuation">.</span><span class="token function">end</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><p>请求:</p>
<pre class="highlight undefined tab-undefined "><code>POST <span class="token operator">/</span>api<span class="token operator">/</span>user<span class="token operator">/</span>code HTTP<span class="token operator">/</span><span class="token number">1.1</span>
Content<span class="token operator">-</span>Type<span class="token punctuation">:</span> application<span class="token operator">/</span>json<span class="token punctuation">;</span> charset<span class="token operator">=</span>utf<span class="token number">-8</span>
Host<span class="token punctuation">:</span> screeps<span class="token punctuation">.</span>com<span class="token punctuation">:</span><span class="token number">443</span>
Authorization<span class="token punctuation">:</span> Basic PHlvdXIgZS1tYWlsPjo8eW91ciBwYXNzd29yZD4<span class="token operator">=</span>
Connection<span class="token punctuation">:</span> close
Transfer<span class="token operator">-</span>Encoding<span class="token punctuation">:</span> chunked
<span class="token punctuation">{</span><span class="token string">"branch"</span><span class="token punctuation">:</span><span class="token string">"default"</span><span class="token punctuation">,</span><span class="token string">"modules"</span><span class="token punctuation">:</span><span class="token punctuation">{</span><span class="token string">"main"</span><span class="token punctuation">:</span><span class="token string">"require(\"hello\");"</span><span class="token punctuation">,</span><span class="token string">"hello"</span><span class="token punctuation">:</span><span class="token string">"console.log(\"Hello World!\");"</span><span class="token punctuation">}</span><span class="token punctuation">}</span></code></pre><p>响应:</p>
<pre class="highlight undefined tab-undefined "><code>X<span class="token operator">-</span>Powered<span class="token operator">-</span>By<span class="token punctuation">:</span> Express
Content<span class="token operator">-</span>Type<span class="token punctuation">:</span> application<span class="token operator">/</span>json<span class="token punctuation">;</span> charset<span class="token operator">=</span>utf<span class="token number">-8</span>
Content<span class="token operator">-</span>Length<span class="token punctuation">:</span> <span class="token number">8</span>
Date<span class="token punctuation">:</span> Mon<span class="token punctuation">,</span> <span class="token number">02</span> Feb <span class="token number">2015</span> <span class="token number">18</span><span class="token punctuation">:</span><span class="token number">46</span><span class="token punctuation">:</span><span class="token number">11</span> GMT
Connection<span class="token punctuation">:</span> close
<span class="token punctuation">{</span><span class="token string">"ok"</span><span class="token punctuation">:</span><span class="token number">1</span><span class="token punctuation">}</span></code></pre>
</div>
<footer class="article-footer">
<time class="article-footer-updated" datetime="2024-09-20T13:38:58.407Z" itemprop="dateModified">上次更新:9月 20, 2024</time>
<a href="/game-loop.html" class="article-footer-prev"><i class="fa fa-chevron-left"></i><span>游戏循环</span></a><a href="/simultaneous-actions.html" class="article-footer-next"><span>同步操作</span><i class="fa fa-chevron-right"></i></a>
</footer>
</div>
</div>
<aside id="article-toc" role="navigation">
<div id="article-toc-inner">
<strong class="sidebar-title">目录</strong>
<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#使用-Grunt-任务"><span class="toc-text">使用 Grunt 任务</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#直接通过-API-进行访问"><span class="toc-text">直接通过 API 进行访问</span></a></li></ol>
<a href="#" id="article-toc-top">回到顶部</a>
</div>
</aside>
</div>
</article>
<aside id="sidebar" role="navigation">
<div class="inner"><a href="/api/" class=api-link><span>API Reference</span><img src="/img/link-external.svg"></a><a href="/index.html" class="sidebar-link">总览</a><strong class="sidebar-title">游戏环境</strong><a href="/introduction.html" class="sidebar-link">简介</a><a href="/creeps.html" class="sidebar-link">Creeps</a><a href="/control.html" class="sidebar-link">控制</a><a href="/defense.html" class="sidebar-link">防御</a><a href="/respawn.html" class="sidebar-link">重生</a><a href="/start-areas.html" class="sidebar-link">初始区域</a><a href="/resources.html" class="sidebar-link">资源</a><a href="/market.html" class="sidebar-link">市场</a><a href="/invaders.html" class="sidebar-link">NPC 入侵者</a><a href="/power.html" class="sidebar-link">超能</a><strong class="sidebar-title">脚本</strong><a href="/scripting-basics.html" class="sidebar-link">脚本基础</a><a href="/global-objects.html" class="sidebar-link">全局对象</a><a href="/modules.html" class="sidebar-link">模块</a><a href="/debugging.html" class="sidebar-link">调试</a><a href="/game-loop.html" class="sidebar-link">游戏循环</a><a href="/commit.html" class="sidebar-link current">外部提交</a><a href="/simultaneous-actions.html" class="sidebar-link">同步操作</a><a href="/cpu-limit.html" class="sidebar-link">CPU 限制</a><strong class="sidebar-title">其他</strong><a href="/architecture.html" class="sidebar-link">服务器架构</a><a href="/ptr.html" class="sidebar-link">公开测试区域 (PTR)</a><a href="/third-party.html" class="sidebar-link">第三方工具</a><a href="/auth-tokens.html" class="sidebar-link">验证令牌</a><a href="/community-servers.html" class="sidebar-link">社区服务器</a><a href="/tos.html" class="sidebar-link">服务条款</a><a href="/privacy-policy.html" class="sidebar-link">隐私政策</a><strong class="sidebar-title">资源</strong><a href="http://blog.screeps.com" class="sidebar-link">博客</a><a href="http://blog.screeps.com/categories/Changelogs/" class="sidebar-link">修改日志</a><a href="http://chat.screeps.com" class="sidebar-link">聊天室</a><a href="https://screeps.com/forum/" class="sidebar-link">论坛</a><strong class="sidebar-title">贡献文章</strong><a href="/contributed/rules.html" class="sidebar-link">贡献规则</a><a href="/contributed/advanced_grunt.html" class="sidebar-link">高级 Grunt 使用</a><a href="/contributed/modifying-prototypes.html" class="sidebar-link">修改原型</a><a href="/contributed/caching-overview.html" class="sidebar-link">缓存概述</a><a href="/contributed/ps_ubuntu.html" class="sidebar-link">私有服务器 MongoDB</a></div>
</aside>
</div>
</div>
</div>
<footer id="footer" class="wrapper">
<div class="inner">
<div id="footer-copyright">
© 2024 <a href="https://screeps.com/" target="_blank">Screeps</a><br>
Documentation licensed under <a href="http://creativecommons.org/licenses/by/4.0/" target="_blank">CC BY 4.0</a>.
</div>
<div id="footer-links">
<a href="https://github.com/screeps-cn/docs" class="footer-link" target="_blank"><i class="fa fa-github-alt"></i></a>
</div>
</div>
</footer>
</div>
<div id="mobile-nav-dimmer"></div>
<nav id="mobile-nav">
<div id="mobile-nav-inner">
<a href="/api/" class=api-link><span>API Reference</span><img src="/img/link-external.svg"></a><a href="/index.html" class="mobile-nav-link">总览</a><strong class="mobile-nav-title">游戏环境</strong><a href="/introduction.html" class="mobile-nav-link">简介</a><a href="/creeps.html" class="mobile-nav-link">Creeps</a><a href="/control.html" class="mobile-nav-link">控制</a><a href="/defense.html" class="mobile-nav-link">防御</a><a href="/respawn.html" class="mobile-nav-link">重生</a><a href="/start-areas.html" class="mobile-nav-link">初始区域</a><a href="/resources.html" class="mobile-nav-link">资源</a><a href="/market.html" class="mobile-nav-link">市场</a><a href="/invaders.html" class="mobile-nav-link">NPC 入侵者</a><a href="/power.html" class="mobile-nav-link">超能</a><strong class="mobile-nav-title">脚本</strong><a href="/scripting-basics.html" class="mobile-nav-link">脚本基础</a><a href="/global-objects.html" class="mobile-nav-link">全局对象</a><a href="/modules.html" class="mobile-nav-link">模块</a><a href="/debugging.html" class="mobile-nav-link">调试</a><a href="/game-loop.html" class="mobile-nav-link">游戏循环</a><a href="/commit.html" class="mobile-nav-link current">外部提交</a><a href="/simultaneous-actions.html" class="mobile-nav-link">同步操作</a><a href="/cpu-limit.html" class="mobile-nav-link">CPU 限制</a><strong class="mobile-nav-title">其他</strong><a href="/architecture.html" class="mobile-nav-link">服务器架构</a><a href="/ptr.html" class="mobile-nav-link">公开测试区域 (PTR)</a><a href="/third-party.html" class="mobile-nav-link">第三方工具</a><a href="/auth-tokens.html" class="mobile-nav-link">验证令牌</a><a href="/community-servers.html" class="mobile-nav-link">社区服务器</a><a href="/tos.html" class="mobile-nav-link">服务条款</a><a href="/privacy-policy.html" class="mobile-nav-link">隐私政策</a><strong class="mobile-nav-title">资源</strong><a href="http://blog.screeps.com" class="mobile-nav-link">博客</a><a href="http://blog.screeps.com/categories/Changelogs/" class="mobile-nav-link">修改日志</a><a href="http://chat.screeps.com" class="mobile-nav-link">聊天室</a><a href="https://screeps.com/forum/" class="mobile-nav-link">论坛</a><strong class="mobile-nav-title">贡献文章</strong><a href="/contributed/rules.html" class="mobile-nav-link">贡献规则</a><a href="/contributed/advanced_grunt.html" class="mobile-nav-link">高级 Grunt 使用</a><a href="/contributed/modifying-prototypes.html" class="mobile-nav-link">修改原型</a><a href="/contributed/caching-overview.html" class="mobile-nav-link">缓存概述</a><a href="/contributed/ps_ubuntu.html" class="mobile-nav-link">私有服务器 MongoDB</a>
</div>
</nav>
<!-- Scripts -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<!-- build:js build/js/main.js -->
<script src="/js/lang_select.js"></script>
<script src="/js/scrollingelement.js"></script>
<script src="/js/toc.js"></script>
<script src="/js/mobile_nav.js"></script>
<script src="/js/custom.js"></script>
<!-- endbuild -->
<script src="https://cdn.jsdelivr.net/retinajs/1.3.0/retina.min.js" async></script>
<!-- Algolia -->
</body>
</html>