@slim-lang/core 1.2.12 → 1.2.13
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/README.md +522 -14
- package/package.json +2 -6
- package/packages/slim/server/main.slim +433 -422
- package/run-dev-slim.js +10 -5
- package/run-slim.js +10 -20
- package/src/bin/api/github_get.js +7 -12
- package/src/bin/api/github_req.js +54 -241
- package/src/bin/api/lock.js +2 -1
- package/src/bin/api/spm.js +20 -91
- package/src/bin/cli.js +73 -102
- package/src/bin/config.default.json +11 -11
- package/src/bin/helpers.js +2 -7
- package/src/bin/spm.js +3 -7
- package/src/checker.js +1705 -388
- package/src/compile.js +131 -100
- package/src/external/classErrors.js +5 -6
- package/src/external/client.js +0 -2
- package/src/external/core.js +355 -237
- package/src/external/defaults.js +12 -4
- package/src/external/dom.js +663 -0
- package/src/external/helpers.js +87 -58
- package/src/external/reactive.js +601 -0
- package/src/external/router.js +117 -0
- package/src/external/slim-globals.d.ts +43 -4
- package/src/external/typeSyntax.js +258 -0
- package/src/external/types.js +1 -1
- package/src/format.js +183 -12
- package/src/handlers/errorHandler.js +9 -36
- package/src/jsdoc.js +36 -16
- package/src/modulePaths.js +15 -5
- package/src/reactivity.js +774 -0
- package/src/repl.js +1 -1
- package/src/suggest.js +60 -0
- package/src/syntax/babel.js +46 -0
- package/src/syntax/index.js +39 -0
- package/src/syntax/lower.js +666 -0
- package/src/syntax/markup.js +195 -0
- package/src/syntax/plugin.js +903 -0
- package/src/syntax/types.js +106 -0
- package/src/test-runner.js +5 -5
- package/src/transform.js +209 -244
- package/packages/slim/helpers/string.js +0 -43
- package/packages/slim/types/hash.js +0 -11
- package/src/handlers/parser/components.js +0 -316
- package/src/handlers/parserHandler.js +0 -789
- package/src/lexer.js +0 -174
- package/src/parser.js +0 -803
- package/src/sourcemap.js +0 -0
package/run-dev-slim.js
CHANGED
|
@@ -4,7 +4,6 @@ import { fileURLToPath } from "url";
|
|
|
4
4
|
import chokidar from "chokidar";
|
|
5
5
|
import { spawn } from "child_process";
|
|
6
6
|
|
|
7
|
-
// This script ships in the package; the compiler sits next to it there.
|
|
8
7
|
const packageRoot = path.dirname(fileURLToPath(import.meta.url));
|
|
9
8
|
const compileScript = path.join(packageRoot, "src", "compile.js");
|
|
10
9
|
|
|
@@ -22,7 +21,7 @@ let rebuilding = false;
|
|
|
22
21
|
let pending = false;
|
|
23
22
|
|
|
24
23
|
function run() {
|
|
25
|
-
app = spawn(
|
|
24
|
+
app = spawn(process.execPath, ["--enable-source-maps", "--no-warnings", entry], {
|
|
26
25
|
stdio: "inherit",
|
|
27
26
|
detached: process.platform !== "win32",
|
|
28
27
|
env: {
|
|
@@ -76,7 +75,7 @@ function stop() {
|
|
|
76
75
|
|
|
77
76
|
function compile() {
|
|
78
77
|
return new Promise(resolve => {
|
|
79
|
-
const compiler = spawn(
|
|
78
|
+
const compiler = spawn(process.execPath, [compileScript], {
|
|
80
79
|
stdio: "inherit"
|
|
81
80
|
});
|
|
82
81
|
|
|
@@ -116,7 +115,13 @@ async function rebuild() {
|
|
|
116
115
|
await rebuild();
|
|
117
116
|
|
|
118
117
|
const watchTarget = config.watch ?? ".";
|
|
119
|
-
const
|
|
118
|
+
const distPath = path.resolve(distDir);
|
|
119
|
+
|
|
120
|
+
function isIgnored(file) {
|
|
121
|
+
const abs = path.resolve(file);
|
|
122
|
+
if (abs === distPath || abs.startsWith(distPath + path.sep)) return true;
|
|
123
|
+
return file.split(/[\\/]/).some(part => part === "node_modules" || part === ".git");
|
|
124
|
+
}
|
|
120
125
|
|
|
121
126
|
const watcher = chokidar.watch(watchTarget, {
|
|
122
127
|
ignoreInitial: true,
|
|
@@ -124,7 +129,7 @@ const watcher = chokidar.watch(watchTarget, {
|
|
|
124
129
|
stabilityThreshold: 150,
|
|
125
130
|
pollInterval: 50
|
|
126
131
|
},
|
|
127
|
-
ignored:
|
|
132
|
+
ignored: isIgnored
|
|
128
133
|
});
|
|
129
134
|
|
|
130
135
|
watcher.on("all", (_, file) => {
|
package/run-slim.js
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync } from
|
|
3
|
-
import { spawn } from
|
|
4
|
-
import path from
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
2
|
+
import { readFileSync } from "node:fs"
|
|
3
|
+
import { spawn } from "node:child_process"
|
|
4
|
+
import path from "node:path"
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
const root = process.cwd()
|
|
7
|
+
const config = JSON.parse(readFileSync(path.join(root, "slimconfig.json"), "utf8").replace(/^\uFEFF/, ""))
|
|
8
|
+
const distName = config.names?.dist ?? config.dist
|
|
9
|
+
const distDir = typeof distName === "string" && distName.trim() ? distName : "slim-dist"
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
+
const entry = path.join(root, distDir, `${config.main}.js`)
|
|
12
|
+
const proc = spawn(process.execPath, ["--enable-source-maps", "--no-warnings", entry], { stdio: "inherit" })
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
const mainFile = config.main;
|
|
14
|
-
const distName = (config.names && config.names.dist) ?? config.dist;
|
|
15
|
-
const distDir = typeof distName === 'string' && distName.trim() ? distName : 'slim-dist';
|
|
16
|
-
|
|
17
|
-
const dist = path.join(root, distDir, `${mainFile}.js`);
|
|
18
|
-
const args = ['--enable-source-maps', '--no-warnings', dist];
|
|
19
|
-
|
|
20
|
-
const proc = spawn('node', args, { stdio: 'inherit' });
|
|
21
|
-
|
|
22
|
-
proc.on('exit', (code) => {
|
|
23
|
-
process.exit(code);
|
|
24
|
-
});
|
|
14
|
+
proc.on("exit", (code, signal) => process.exit(code ?? (signal ? 1 : 0)))
|
|
@@ -109,18 +109,13 @@ export async function downloadGitHubRepo(
|
|
|
109
109
|
`spm-${owner}-${repo}-${Date.now()}.tar.gz`
|
|
110
110
|
);
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
response.body,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
await extractTarGz(tempFile, destination);
|
|
122
|
-
|
|
123
|
-
await fs.promises.unlink(tempFile);
|
|
112
|
+
try {
|
|
113
|
+
await pipeline(response.body, createWriteStream(tempFile));
|
|
114
|
+
await fs.promises.mkdir(destination, { recursive: true });
|
|
115
|
+
await extractTarGz(tempFile, destination);
|
|
116
|
+
} finally {
|
|
117
|
+
await fs.promises.rm(tempFile, { force: true });
|
|
118
|
+
}
|
|
124
119
|
|
|
125
120
|
return {
|
|
126
121
|
success: true,
|
|
@@ -20,281 +20,95 @@ export async function githubRequest(token, url, options = {}) {
|
|
|
20
20
|
"Content-Type": "application/json",
|
|
21
21
|
...options.headers
|
|
22
22
|
})
|
|
23
|
-
|
|
23
|
+
});
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const data = response.status === 204 ? null : await response.json().catch(() => null);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
throw new Error(
|
|
29
|
-
data.message || `GitHub API error: ${response.status}`
|
|
30
|
-
);
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
throw new Error(data?.message || `GitHub API error: ${response.status}`);
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
return data;
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
async function getFiles(dir, base = dir) {
|
|
37
|
-
const entries = await fs.readdir(dir, {
|
|
38
|
-
withFileTypes: true
|
|
39
|
-
});
|
|
40
|
-
|
|
41
35
|
const files = [];
|
|
42
36
|
|
|
43
|
-
for (const entry of
|
|
37
|
+
for (const entry of await fs.readdir(dir, { withFileTypes: true })) {
|
|
44
38
|
const fullPath = path.join(dir, entry.name);
|
|
45
39
|
|
|
46
|
-
if (entry.isDirectory())
|
|
47
|
-
|
|
48
|
-
...(await getFiles(fullPath, base))
|
|
49
|
-
);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!entry.isFile()) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
files.push({
|
|
58
|
-
path: path.relative(base, fullPath).replaceAll("\\", "/"),
|
|
59
|
-
fullPath
|
|
60
|
-
});
|
|
40
|
+
if (entry.isDirectory()) files.push(...await getFiles(fullPath, base));
|
|
41
|
+
else if (entry.isFile()) files.push({ path: path.relative(base, fullPath).replaceAll("\\", "/"), fullPath });
|
|
61
42
|
}
|
|
62
43
|
|
|
63
44
|
return files;
|
|
64
45
|
}
|
|
65
46
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
contentPath,
|
|
70
|
-
branch = "main"
|
|
71
|
-
}) {
|
|
72
|
-
try {
|
|
73
|
-
const [owner, repoName] = repo.split("/");
|
|
47
|
+
async function commitDirectory({ token, repo, dir, message, branch = "main" }) {
|
|
48
|
+
const files = await getFiles(dir);
|
|
49
|
+
if (files.length === 0) throw new Error("Package directory is empty");
|
|
74
50
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
msg: `Invalid GitHub repository: ${repo}`
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const repository = await githubRequest(
|
|
83
|
-
token,
|
|
84
|
-
`/repos/${owner}/${repoName}`
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const files = await getFiles(contentPath);
|
|
51
|
+
const reference = await githubRequest(token, `/repos/${repo}/git/ref/heads/${branch}`);
|
|
52
|
+
const parentSha = reference.object.sha;
|
|
53
|
+
const parentCommit = await githubRequest(token, `/repos/${repo}/git/commits/${parentSha}`);
|
|
88
54
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
token,
|
|
98
|
-
`/repos/${owner}/${repoName}/git/ref/heads/${branch}`
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const parentSha = reference.object.sha;
|
|
102
|
-
|
|
103
|
-
const parentCommit = await githubRequest(
|
|
104
|
-
token,
|
|
105
|
-
`/repos/${owner}/${repoName}/git/commits/${parentSha}`
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const tree = [];
|
|
55
|
+
const tree = [];
|
|
56
|
+
for (const file of files) {
|
|
57
|
+
const blob = await githubRequest(token, `/repos/${repo}/git/blobs`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
body: JSON.stringify({ content: await fs.readFile(file.fullPath, "base64"), encoding: "base64" })
|
|
60
|
+
});
|
|
61
|
+
tree.push({ path: file.path, mode: "100644", type: "blob", sha: blob.sha });
|
|
62
|
+
}
|
|
109
63
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
);
|
|
64
|
+
const newTree = await githubRequest(token, `/repos/${repo}/git/trees`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body: JSON.stringify({ base_tree: parentCommit.tree.sha, tree })
|
|
67
|
+
});
|
|
115
68
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
method: "POST",
|
|
121
|
-
body: JSON.stringify({
|
|
122
|
-
content,
|
|
123
|
-
encoding: "base64"
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
);
|
|
69
|
+
const commit = await githubRequest(token, `/repos/${repo}/git/commits`, {
|
|
70
|
+
method: "POST",
|
|
71
|
+
body: JSON.stringify({ message, tree: newTree.sha, parents: [parentSha] })
|
|
72
|
+
});
|
|
127
73
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
sha: blob.sha
|
|
133
|
-
});
|
|
134
|
-
}
|
|
74
|
+
await githubRequest(token, `/repos/${repo}/git/refs/heads/${branch}`, {
|
|
75
|
+
method: "PATCH",
|
|
76
|
+
body: JSON.stringify({ sha: commit.sha })
|
|
77
|
+
});
|
|
135
78
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
`/repos/${owner}/${repoName}/git/trees`,
|
|
139
|
-
{
|
|
140
|
-
method: "POST",
|
|
141
|
-
body: JSON.stringify({
|
|
142
|
-
base_tree: parentCommit.tree.sha,
|
|
143
|
-
tree
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
);
|
|
79
|
+
return { commit: commit.sha, tree: newTree.sha };
|
|
80
|
+
}
|
|
147
81
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
method: "POST",
|
|
153
|
-
body: JSON.stringify({
|
|
154
|
-
message: "Publish package",
|
|
155
|
-
tree: newTree.sha,
|
|
156
|
-
parents: [parentSha]
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
);
|
|
82
|
+
export async function publishToGitHub({ token, repo, contentPath, branch = "main" }) {
|
|
83
|
+
if (!/^[^/]+\/[^/]+$/.test(repo)) {
|
|
84
|
+
return { success: false, msg: `Invalid GitHub repository: ${repo}` };
|
|
85
|
+
}
|
|
160
86
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
{
|
|
165
|
-
method: "PATCH",
|
|
166
|
-
body: JSON.stringify({
|
|
167
|
-
sha: commit.sha
|
|
168
|
-
})
|
|
169
|
-
}
|
|
170
|
-
);
|
|
87
|
+
try {
|
|
88
|
+
const repository = await githubRequest(token, `/repos/${repo}`);
|
|
89
|
+
const { commit } = await commitDirectory({ token, repo, dir: contentPath, message: "Publish package", branch });
|
|
171
90
|
|
|
172
|
-
return {
|
|
173
|
-
success: true,
|
|
174
|
-
msg: `Published ${repo}`,
|
|
175
|
-
repo: repository.full_name,
|
|
176
|
-
commit: commit.sha
|
|
177
|
-
};
|
|
91
|
+
return { success: true, msg: `Published ${repo}`, repo: repository.full_name, commit };
|
|
178
92
|
}
|
|
179
93
|
catch (error) {
|
|
180
|
-
return {
|
|
181
|
-
success: false,
|
|
182
|
-
msg: error instanceof Error
|
|
183
|
-
? error.message
|
|
184
|
-
: String(error)
|
|
185
|
-
};
|
|
94
|
+
return { success: false, msg: error instanceof Error ? error.message : String(error) };
|
|
186
95
|
}
|
|
187
96
|
}
|
|
188
97
|
|
|
189
|
-
export async function updateGitHubRepo({
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
packagePath,
|
|
193
|
-
version,
|
|
194
|
-
message = `Release ${version}`
|
|
195
|
-
}) {
|
|
196
|
-
const branch = await githubRequest(
|
|
197
|
-
token,
|
|
198
|
-
`/repos/${repo}/git/ref/heads/main`
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
const parentSha = branch.object.sha;
|
|
202
|
-
|
|
203
|
-
const parentCommit = await githubRequest(
|
|
204
|
-
token,
|
|
205
|
-
`/repos/${repo}/git/commits/${parentSha}`
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
const baseTreeSha = parentCommit.tree.sha;
|
|
98
|
+
export async function updateGitHubRepo({ token, repo, packagePath, version, message = `Release ${version}` }) {
|
|
99
|
+
try {
|
|
100
|
+
const { commit, tree } = await commitDirectory({ token, repo, dir: packagePath, message });
|
|
209
101
|
|
|
210
|
-
|
|
102
|
+
await githubRequest(token, `/repos/${repo}/git/refs`, {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: JSON.stringify({ ref: `refs/tags/v${version}`, sha: commit })
|
|
105
|
+
});
|
|
211
106
|
|
|
212
|
-
|
|
213
|
-
throw new Error("Package directory is empty");
|
|
107
|
+
return { success: true, commit, tree, version, tag: `v${version}` };
|
|
214
108
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
for (const file of files) {
|
|
219
|
-
const content = await fs.readFile(file.fullPath);
|
|
220
|
-
|
|
221
|
-
const blob = await githubRequest(
|
|
222
|
-
token,
|
|
223
|
-
`/repos/${repo}/git/blobs`,
|
|
224
|
-
{
|
|
225
|
-
method: "POST",
|
|
226
|
-
body: JSON.stringify({
|
|
227
|
-
content: content.toString("base64"),
|
|
228
|
-
encoding: "base64"
|
|
229
|
-
})
|
|
230
|
-
}
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
tree.push({
|
|
234
|
-
path: file.path,
|
|
235
|
-
mode: "100644",
|
|
236
|
-
type: "blob",
|
|
237
|
-
sha: blob.sha
|
|
238
|
-
});
|
|
109
|
+
catch (error) {
|
|
110
|
+
return { success: false, msg: error instanceof Error ? error.message : String(error) };
|
|
239
111
|
}
|
|
240
|
-
|
|
241
|
-
const newTree = await githubRequest(
|
|
242
|
-
token,
|
|
243
|
-
`/repos/${repo}/git/trees`,
|
|
244
|
-
{
|
|
245
|
-
method: "POST",
|
|
246
|
-
body: JSON.stringify({
|
|
247
|
-
base_tree: baseTreeSha,
|
|
248
|
-
tree
|
|
249
|
-
})
|
|
250
|
-
}
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
const commit = await githubRequest(
|
|
254
|
-
token,
|
|
255
|
-
`/repos/${repo}/git/commits`,
|
|
256
|
-
{
|
|
257
|
-
method: "POST",
|
|
258
|
-
body: JSON.stringify({
|
|
259
|
-
message,
|
|
260
|
-
tree: newTree.sha,
|
|
261
|
-
parents: [parentSha]
|
|
262
|
-
})
|
|
263
|
-
}
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
await githubRequest(
|
|
267
|
-
token,
|
|
268
|
-
`/repos/${repo}/git/refs/heads/main`,
|
|
269
|
-
{
|
|
270
|
-
method: "PATCH",
|
|
271
|
-
body: JSON.stringify({
|
|
272
|
-
sha: commit.sha
|
|
273
|
-
})
|
|
274
|
-
}
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
const tagRef = `refs/tags/v${version}`;
|
|
278
|
-
|
|
279
|
-
await githubRequest(
|
|
280
|
-
token,
|
|
281
|
-
`/repos/${repo}/git/refs`,
|
|
282
|
-
{
|
|
283
|
-
method: "POST",
|
|
284
|
-
body: JSON.stringify({
|
|
285
|
-
ref: tagRef,
|
|
286
|
-
sha: commit.sha
|
|
287
|
-
})
|
|
288
|
-
}
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
return {
|
|
292
|
-
success: true,
|
|
293
|
-
commit: commit.sha,
|
|
294
|
-
tree: newTree.sha,
|
|
295
|
-
version,
|
|
296
|
-
tag: `v${version}`
|
|
297
|
-
};
|
|
298
112
|
}
|
|
299
113
|
|
|
300
114
|
export async function createGitHubRepo(token, repository, organization = false) {
|
|
@@ -335,7 +149,6 @@ export async function createGitHubRepo(token, repository, organization = false)
|
|
|
335
149
|
};
|
|
336
150
|
}
|
|
337
151
|
|
|
338
|
-
// Organization repositories use the org endpoint; user repositories require ownership.
|
|
339
152
|
if (!organization) {
|
|
340
153
|
const userResponse = await fetch(
|
|
341
154
|
`${GITHUB_API}/user`,
|
package/src/bin/api/lock.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs"
|
|
2
2
|
import path from "node:path"
|
|
3
3
|
import { rootPath } from "../helpers.js"
|
|
4
|
+
import { readJson } from "../../modulePaths.js"
|
|
4
5
|
|
|
5
6
|
export function lockFile(dir = rootPath) {
|
|
6
7
|
return path.join(dir, "spm.lock.json")
|
|
@@ -8,7 +9,7 @@ export function lockFile(dir = rootPath) {
|
|
|
8
9
|
|
|
9
10
|
export function readLock(dir = rootPath) {
|
|
10
11
|
try {
|
|
11
|
-
const data =
|
|
12
|
+
const data = readJson(lockFile(dir))
|
|
12
13
|
if (!data.packages || typeof data.packages !== "object") data.packages = {}
|
|
13
14
|
return data
|
|
14
15
|
} catch {
|
package/src/bin/api/spm.js
CHANGED
|
@@ -1,103 +1,32 @@
|
|
|
1
1
|
const API_URL = "https://codemotion.yurba.one/api/spm"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const res = await fetch(`${API_URL}
|
|
5
|
-
method: "
|
|
6
|
-
headers: { "Content-Type": "application/json" },
|
|
7
|
-
body: JSON.stringify({
|
|
8
|
-
github_token: token,
|
|
9
|
-
name,
|
|
10
|
-
description,
|
|
11
|
-
version,
|
|
12
|
-
github,
|
|
13
|
-
}),
|
|
14
|
-
});
|
|
3
|
+
async function request(endpoint, body) {
|
|
4
|
+
const res = await fetch(`${API_URL}${endpoint}`, body === undefined
|
|
5
|
+
? { method: "GET", headers: { "Content-Type": "application/json" } }
|
|
6
|
+
: { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) })
|
|
15
7
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
content: data.result
|
|
22
|
-
}
|
|
8
|
+
let data
|
|
9
|
+
try {
|
|
10
|
+
data = await res.json()
|
|
11
|
+
} catch {
|
|
12
|
+
return { success: false, content: `SPM registry returned HTTP ${res.status}` }
|
|
23
13
|
}
|
|
24
14
|
|
|
25
|
-
return {
|
|
26
|
-
success: true,
|
|
27
|
-
content: data.result
|
|
28
|
-
}
|
|
15
|
+
return { success: !!data.success, content: data.result }
|
|
29
16
|
}
|
|
30
17
|
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
method: "GET",
|
|
34
|
-
headers: { "Content-Type": "application/json" }
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const data = await res.json();
|
|
38
|
-
|
|
39
|
-
if (!data.success) {
|
|
40
|
-
return {
|
|
41
|
-
success: false,
|
|
42
|
-
content: data.result
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
success: true,
|
|
48
|
-
content: data.result
|
|
49
|
-
}
|
|
18
|
+
export function publishPackage({ token, name, version, github, description = "" }) {
|
|
19
|
+
return request("/publish", { github_token: token, name, description, version, github })
|
|
50
20
|
}
|
|
51
21
|
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
method: "POST",
|
|
55
|
-
headers: { "Content-Type": "application/json" },
|
|
56
|
-
body: JSON.stringify({
|
|
57
|
-
github_token: token,
|
|
58
|
-
name,
|
|
59
|
-
description,
|
|
60
|
-
version,
|
|
61
|
-
github,
|
|
62
|
-
}),
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const data = await res.json();
|
|
66
|
-
|
|
67
|
-
if (!data.success) {
|
|
68
|
-
return {
|
|
69
|
-
success: false,
|
|
70
|
-
content: data.result
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
success: true,
|
|
76
|
-
content: data.result
|
|
77
|
-
}
|
|
22
|
+
export function getPackage({ name }) {
|
|
23
|
+
return request(`/install?name=${encodeURIComponent(name)}`)
|
|
78
24
|
}
|
|
79
25
|
|
|
80
|
-
export
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
headers: { "Content-Type": "application/json" },
|
|
84
|
-
body: JSON.stringify({
|
|
85
|
-
github_token: token,
|
|
86
|
-
name
|
|
87
|
-
}),
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const data = await res.json();
|
|
91
|
-
|
|
92
|
-
if (!data.success) {
|
|
93
|
-
return {
|
|
94
|
-
success: false,
|
|
95
|
-
content: data.result
|
|
96
|
-
}
|
|
97
|
-
}
|
|
26
|
+
export function updatePackage({ token, name, description, version, github }) {
|
|
27
|
+
return request("/update", { github_token: token, name, description, version, github })
|
|
28
|
+
}
|
|
98
29
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
}
|
|
30
|
+
export function removePackage({ token, name }) {
|
|
31
|
+
return request("/remove", { github_token: token, name })
|
|
32
|
+
}
|