@joripspace/cli 0.5.6 → 0.5.7
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/LICENSE +21 -21
- package/README.md +13 -2
- package/THIRD_PARTY_NOTICES.md +137 -85
- package/bin/joripspace.js +307 -71
- package/lib/checkpoint-client.js +40 -49
- package/lib/checkpoint-commands.js +51 -15
- package/lib/credential-store.js +148 -0
- package/lib/deploy-files.js +8 -3
- package/lib/deployment-error.js +14 -14
- package/lib/github-commands.js +76 -13
- package/lib/help.js +42 -15
- package/lib/locale.js +35 -0
- package/lib/mcp-config.js +7 -1
- package/lib/project-create-policy.js +116 -0
- package/lib/project-create.js +203 -0
- package/lib/project-env.js +10 -6
- package/lib/project-paths.js +23 -4
- package/lib/remote-commands.js +14 -3
- package/lib/start-command.js +9 -3
- package/lib/start.js +1 -1
- package/lib/template-commands.js +24 -20
- package/package.json +4 -2
- package/vendor/core/cli-onboarding.cjs +3 -2
- package/vendor/core/template-publish-workflow.cjs +169 -169
- package/vendor/templates/index.js +104 -104
- package/vendor/templates/templates/basic-worker/files/worker.js +9 -9
- package/vendor/templates/templates/basic-worker/manifest.json +14 -14
- package/vendor/templates/templates/r2-file-api/files/worker.js +42 -42
- package/vendor/templates/templates/r2-file-api/manifest.json +7 -7
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
const fs = require('node:fs');
|
|
2
|
-
const path = require('node:path');
|
|
3
|
-
|
|
4
|
-
const TEMPLATES_DIR = path.join(__dirname, 'templates');
|
|
5
|
-
|
|
6
|
-
function listTemplates() {
|
|
7
|
-
return fs
|
|
8
|
-
.readdirSync(TEMPLATES_DIR, { withFileTypes: true })
|
|
9
|
-
.filter((entry) => entry.isDirectory())
|
|
10
|
-
.map((entry) => readManifest(entry.name))
|
|
11
|
-
.sort((left, right) => left.id.localeCompare(right.id));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function getTemplate(id) {
|
|
15
|
-
const safeId = assertTemplateId(id);
|
|
16
|
-
const templateDir = path.join(TEMPLATES_DIR, safeId);
|
|
17
|
-
if (!fs.existsSync(templateDir)) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return readManifest(safeId);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function buildTemplateDeployRequest(id, vars = {}) {
|
|
25
|
-
const manifest = getTemplate(id);
|
|
26
|
-
if (!manifest) {
|
|
27
|
-
throw new Error(`Unknown template: ${id}`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const variableValues = templateVariables(manifest, vars);
|
|
31
|
-
const filesDir = path.join(TEMPLATES_DIR, manifest.id, 'files');
|
|
32
|
-
const files = {};
|
|
33
|
-
for (const filePath of walkFiles(filesDir)) {
|
|
34
|
-
const relative = toPosix(path.relative(filesDir, filePath));
|
|
35
|
-
files[relative] = renderTemplate(fs.readFileSync(filePath, 'utf8'), variableValues);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!Object.prototype.hasOwnProperty.call(files, manifest.entrypoint)) {
|
|
39
|
-
throw new Error(`Template entrypoint not found: ${manifest.entrypoint}`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
manifest,
|
|
44
|
-
deployRequest: {
|
|
45
|
-
entrypoint: manifest.entrypoint,
|
|
46
|
-
files,
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function readManifest(id) {
|
|
52
|
-
const safeId = assertTemplateId(id);
|
|
53
|
-
return JSON.parse(fs.readFileSync(path.join(TEMPLATES_DIR, safeId, 'manifest.json'), 'utf8'));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function templateVariables(manifest, vars) {
|
|
57
|
-
const values = {};
|
|
58
|
-
for (const variable of manifest.variables ?? []) {
|
|
59
|
-
if (vars[variable.name] !== undefined) {
|
|
60
|
-
values[variable.name] = String(vars[variable.name]);
|
|
61
|
-
} else if (variable.default !== undefined) {
|
|
62
|
-
values[variable.name] = String(variable.default);
|
|
63
|
-
} else if (variable.required) {
|
|
64
|
-
throw new Error(`Missing template variable: ${variable.name}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return values;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function renderTemplate(source, vars) {
|
|
71
|
-
return source.replace(/\{\{\s*([A-Z0-9_]+)\s*\}\}/g, (match, name) =>
|
|
72
|
-
vars[name] === undefined ? match : vars[name]
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function walkFiles(root) {
|
|
77
|
-
const files = [];
|
|
78
|
-
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
79
|
-
const fullPath = path.join(root, entry.name);
|
|
80
|
-
if (entry.isDirectory()) {
|
|
81
|
-
files.push(...walkFiles(fullPath));
|
|
82
|
-
} else if (entry.isFile()) {
|
|
83
|
-
files.push(fullPath);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return files;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function assertTemplateId(id) {
|
|
90
|
-
if (typeof id !== 'string' || !/^[a-z0-9-]+$/.test(id)) {
|
|
91
|
-
throw new Error('Template id must contain only lowercase letters, numbers, and hyphens.');
|
|
92
|
-
}
|
|
93
|
-
return id;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function toPosix(value) {
|
|
97
|
-
return value.split(path.sep).join('/');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
module.exports = {
|
|
101
|
-
buildTemplateDeployRequest,
|
|
102
|
-
getTemplate,
|
|
103
|
-
listTemplates,
|
|
104
|
-
};
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
|
|
4
|
+
const TEMPLATES_DIR = path.join(__dirname, 'templates');
|
|
5
|
+
|
|
6
|
+
function listTemplates() {
|
|
7
|
+
return fs
|
|
8
|
+
.readdirSync(TEMPLATES_DIR, { withFileTypes: true })
|
|
9
|
+
.filter((entry) => entry.isDirectory())
|
|
10
|
+
.map((entry) => readManifest(entry.name))
|
|
11
|
+
.sort((left, right) => left.id.localeCompare(right.id));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getTemplate(id) {
|
|
15
|
+
const safeId = assertTemplateId(id);
|
|
16
|
+
const templateDir = path.join(TEMPLATES_DIR, safeId);
|
|
17
|
+
if (!fs.existsSync(templateDir)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return readManifest(safeId);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function buildTemplateDeployRequest(id, vars = {}) {
|
|
25
|
+
const manifest = getTemplate(id);
|
|
26
|
+
if (!manifest) {
|
|
27
|
+
throw new Error(`Unknown template: ${id}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const variableValues = templateVariables(manifest, vars);
|
|
31
|
+
const filesDir = path.join(TEMPLATES_DIR, manifest.id, 'files');
|
|
32
|
+
const files = {};
|
|
33
|
+
for (const filePath of walkFiles(filesDir)) {
|
|
34
|
+
const relative = toPosix(path.relative(filesDir, filePath));
|
|
35
|
+
files[relative] = renderTemplate(fs.readFileSync(filePath, 'utf8'), variableValues);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!Object.prototype.hasOwnProperty.call(files, manifest.entrypoint)) {
|
|
39
|
+
throw new Error(`Template entrypoint not found: ${manifest.entrypoint}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
manifest,
|
|
44
|
+
deployRequest: {
|
|
45
|
+
entrypoint: manifest.entrypoint,
|
|
46
|
+
files,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function readManifest(id) {
|
|
52
|
+
const safeId = assertTemplateId(id);
|
|
53
|
+
return JSON.parse(fs.readFileSync(path.join(TEMPLATES_DIR, safeId, 'manifest.json'), 'utf8'));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function templateVariables(manifest, vars) {
|
|
57
|
+
const values = {};
|
|
58
|
+
for (const variable of manifest.variables ?? []) {
|
|
59
|
+
if (vars[variable.name] !== undefined) {
|
|
60
|
+
values[variable.name] = String(vars[variable.name]);
|
|
61
|
+
} else if (variable.default !== undefined) {
|
|
62
|
+
values[variable.name] = String(variable.default);
|
|
63
|
+
} else if (variable.required) {
|
|
64
|
+
throw new Error(`Missing template variable: ${variable.name}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return values;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function renderTemplate(source, vars) {
|
|
71
|
+
return source.replace(/\{\{\s*([A-Z0-9_]+)\s*\}\}/g, (match, name) =>
|
|
72
|
+
vars[name] === undefined ? match : vars[name]
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function walkFiles(root) {
|
|
77
|
+
const files = [];
|
|
78
|
+
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
79
|
+
const fullPath = path.join(root, entry.name);
|
|
80
|
+
if (entry.isDirectory()) {
|
|
81
|
+
files.push(...walkFiles(fullPath));
|
|
82
|
+
} else if (entry.isFile()) {
|
|
83
|
+
files.push(fullPath);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return files;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function assertTemplateId(id) {
|
|
90
|
+
if (typeof id !== 'string' || !/^[a-z0-9-]+$/.test(id)) {
|
|
91
|
+
throw new Error('Template id must contain only lowercase letters, numbers, and hyphens.');
|
|
92
|
+
}
|
|
93
|
+
return id;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function toPosix(value) {
|
|
97
|
+
return value.split(path.sep).join('/');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = {
|
|
101
|
+
buildTemplateDeployRequest,
|
|
102
|
+
getTemplate,
|
|
103
|
+
listTemplates,
|
|
104
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
async fetch(request, env) {
|
|
3
|
-
return new Response('{{MESSAGE}}', {
|
|
4
|
-
headers: {
|
|
5
|
-
'Content-Type': 'text/plain',
|
|
6
|
-
},
|
|
7
|
-
});
|
|
8
|
-
},
|
|
9
|
-
};
|
|
1
|
+
export default {
|
|
2
|
+
async fetch(request, env) {
|
|
3
|
+
return new Response('{{MESSAGE}}', {
|
|
4
|
+
headers: {
|
|
5
|
+
'Content-Type': 'text/plain',
|
|
6
|
+
},
|
|
7
|
+
});
|
|
8
|
+
},
|
|
9
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "basic-worker",
|
|
3
|
-
"name": "Basic Server",
|
|
4
|
-
"description": "Plain text server response for smoke tests and first deploys.",
|
|
5
|
-
"entrypoint": "worker.js",
|
|
6
|
-
"tags": ["starter", "http"],
|
|
7
|
-
"variables": [
|
|
8
|
-
{
|
|
9
|
-
"name": "MESSAGE",
|
|
10
|
-
"description": "Response body text.",
|
|
11
|
-
"default": "Hello from JoripSpace"
|
|
12
|
-
}
|
|
13
|
-
]
|
|
14
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"id": "basic-worker",
|
|
3
|
+
"name": "Basic Server",
|
|
4
|
+
"description": "Plain text server response for smoke tests and first deploys.",
|
|
5
|
+
"entrypoint": "worker.js",
|
|
6
|
+
"tags": ["starter", "http"],
|
|
7
|
+
"variables": [
|
|
8
|
+
{
|
|
9
|
+
"name": "MESSAGE",
|
|
10
|
+
"description": "Response body text.",
|
|
11
|
+
"default": "Hello from JoripSpace"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
async function cacheTagForKey(key) {
|
|
2
|
-
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(key));
|
|
3
|
-
const hex = Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
4
|
-
return `r2-${hex}`;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
async fetch(request, env, ctx) {
|
|
9
|
-
const url = new URL(request.url);
|
|
10
|
-
const match = url.pathname.match(/^\/files\/(.+)$/);
|
|
11
|
-
if (!match) {
|
|
12
|
-
return Response.json({ ok: true, routes: ['/files/{key}'] });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const key = decodeURIComponent(match[1]);
|
|
16
|
-
if (request.method === 'GET') {
|
|
17
|
-
const object = await env.STORAGE.get(key);
|
|
18
|
-
if (!object) {
|
|
19
|
-
return new Response('Not found', { status: 404 });
|
|
20
|
-
}
|
|
21
|
-
return new Response(object.body, {
|
|
22
|
-
headers: {
|
|
23
|
-
'Content-Type': object.httpMetadata?.contentType ?? 'application/octet-stream',
|
|
24
|
-
'Cache-Control': 'public, max-age=3600',
|
|
25
|
-
'Cache-Tag': await cacheTagForKey(key),
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (request.method === 'PUT') {
|
|
31
|
-
await env.STORAGE.put(key, request.body, {
|
|
32
|
-
httpMetadata: {
|
|
33
|
-
contentType: request.headers.get('content-type') ?? 'application/octet-stream',
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
await ctx.cache.purge({ tags: [await cacheTagForKey(key)] });
|
|
37
|
-
return Response.json({ ok: true, key }, { headers: { 'Cache-Control': 'private, no-store' } });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return new Response('Method not allowed', { status: 405 });
|
|
41
|
-
},
|
|
42
|
-
};
|
|
1
|
+
async function cacheTagForKey(key) {
|
|
2
|
+
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(key));
|
|
3
|
+
const hex = Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
4
|
+
return `r2-${hex}`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
async fetch(request, env, ctx) {
|
|
9
|
+
const url = new URL(request.url);
|
|
10
|
+
const match = url.pathname.match(/^\/files\/(.+)$/);
|
|
11
|
+
if (!match) {
|
|
12
|
+
return Response.json({ ok: true, routes: ['/files/{key}'] });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const key = decodeURIComponent(match[1]);
|
|
16
|
+
if (request.method === 'GET') {
|
|
17
|
+
const object = await env.STORAGE.get(key);
|
|
18
|
+
if (!object) {
|
|
19
|
+
return new Response('Not found', { status: 404 });
|
|
20
|
+
}
|
|
21
|
+
return new Response(object.body, {
|
|
22
|
+
headers: {
|
|
23
|
+
'Content-Type': object.httpMetadata?.contentType ?? 'application/octet-stream',
|
|
24
|
+
'Cache-Control': 'public, max-age=3600',
|
|
25
|
+
'Cache-Tag': await cacheTagForKey(key),
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (request.method === 'PUT') {
|
|
31
|
+
await env.STORAGE.put(key, request.body, {
|
|
32
|
+
httpMetadata: {
|
|
33
|
+
contentType: request.headers.get('content-type') ?? 'application/octet-stream',
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
await ctx.cache.purge({ tags: [await cacheTagForKey(key)] });
|
|
37
|
+
return Response.json({ ok: true, key }, { headers: { 'Cache-Control': 'private, no-store' } });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return new Response('Method not allowed', { status: 405 });
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "r2-file-api",
|
|
3
|
-
"name": "R2 File API",
|
|
4
|
-
"description": "PUT and GET files through the project R2 bucket.",
|
|
5
|
-
"entrypoint": "worker.js",
|
|
6
|
-
"tags": ["starter", "r2", "api"]
|
|
7
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"id": "r2-file-api",
|
|
3
|
+
"name": "R2 File API",
|
|
4
|
+
"description": "PUT and GET files through the project R2 bucket.",
|
|
5
|
+
"entrypoint": "worker.js",
|
|
6
|
+
"tags": ["starter", "r2", "api"]
|
|
7
|
+
}
|