@joripspace/cli 0.4.2 → 0.5.1
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 +27 -5
- package/bin/joripspace.js +1623 -1610
- package/lib/checkpoint-commands.js +210 -210
- package/lib/deploy-files.js +245 -245
- package/lib/deployment-error.js +14 -14
- package/lib/github-commands.js +185 -0
- package/lib/help.js +138 -137
- package/lib/installer-args.js +28 -28
- package/lib/installer-target.js +134 -134
- package/lib/mcp-config.js +981 -981
- package/lib/project-env.js +198 -198
- package/lib/project-paths.js +257 -257
- package/lib/remote-commands.js +392 -392
- package/lib/start-command.js +140 -129
- package/lib/start.js +1440 -1423
- package/lib/template-commands.js +812 -812
- package/package.json +1 -1
- package/vendor/core/cli-onboarding.cjs +79 -0
- package/vendor/core/github-workflow.cjs +199 -186
- package/vendor/core/onboarding.cjs +2409 -2405
- 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,169 +1,169 @@
|
|
|
1
|
-
function buildTemplatePublishWorkflow({
|
|
2
|
-
templateId,
|
|
3
|
-
branch = 'main',
|
|
4
|
-
manifestPath = 'joripspace-template.json',
|
|
5
|
-
}) {
|
|
6
|
-
const publishScript = `${inlineTemplatePublishMain.toString()}\n\nawait inlineTemplatePublishMain();`
|
|
7
|
-
.split('\n')
|
|
8
|
-
.map((line) => ` ${line}`)
|
|
9
|
-
.join('\n');
|
|
10
|
-
return `# joripspace-template-workflow-version: 3
|
|
11
|
-
#
|
|
12
|
-
# JoripSpace 템플릿 배포 가이드
|
|
13
|
-
# 1. 이 파일과 joripspace-template.json이 추가된 설정 PR을 기본 브랜치에 병합합니다.
|
|
14
|
-
# 2. GitHub 저장소의 Releases에서 배포할 버전 태그를 만들고 Release를 Publish합니다.
|
|
15
|
-
# 3. Release 태그가 조립스페이스에 표시되는 공식 버전이 됩니다. 예: 1.0.1 또는 v1.0.1
|
|
16
|
-
# 4. Actions 탭의 "JoripSpace Template Publish" 작업이 초록색으로 완료되는지 확인합니다.
|
|
17
|
-
#
|
|
18
|
-
# 알아두세요
|
|
19
|
-
# - 일반 push나 Release 초안 저장만으로는 배포되지 않습니다. Published Release만 배포됩니다.
|
|
20
|
-
# - 별도 API 키나 Secret은 필요하지 않습니다. GitHub OIDC로 저장소와 Release를 검증합니다.
|
|
21
|
-
# - Release 태그는 아래에 지정된 기준 브랜치에 포함된 커밋을 가리켜야 합니다.
|
|
22
|
-
# - 오류가 나면 Actions 실행에서 실패한 단계와 메시지를 먼저 확인하세요.
|
|
23
|
-
# - 이 워크플로와 joripspace-template.json을 삭제하면 이후 업데이트를 배포할 수 없습니다.
|
|
24
|
-
name: JoripSpace Template Publish
|
|
25
|
-
|
|
26
|
-
on:
|
|
27
|
-
release:
|
|
28
|
-
types: [published]
|
|
29
|
-
|
|
30
|
-
permissions:
|
|
31
|
-
contents: read
|
|
32
|
-
id-token: write
|
|
33
|
-
|
|
34
|
-
concurrency:
|
|
35
|
-
group: ${JSON.stringify(`joripspace-template-${String(templateId)}`)}
|
|
36
|
-
cancel-in-progress: false
|
|
37
|
-
|
|
38
|
-
jobs:
|
|
39
|
-
publish:
|
|
40
|
-
runs-on: ubuntu-latest
|
|
41
|
-
steps:
|
|
42
|
-
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
43
|
-
with:
|
|
44
|
-
fetch-depth: 0
|
|
45
|
-
- name: Build Git Bundle and files archive
|
|
46
|
-
shell: bash
|
|
47
|
-
env:
|
|
48
|
-
JORIPSPACE_TEMPLATE_ID: ${JSON.stringify(String(templateId))}
|
|
49
|
-
JORIPSPACE_MANIFEST_PATH: ${JSON.stringify(String(manifestPath))}
|
|
50
|
-
JORIPSPACE_SOURCE_BRANCH: ${JSON.stringify(String(branch))}
|
|
51
|
-
run: |
|
|
52
|
-
set -euo pipefail
|
|
53
|
-
manifest="$GITHUB_WORKSPACE/$JORIPSPACE_MANIFEST_PATH"
|
|
54
|
-
test -f "$manifest" || { echo "joripspace-template.json is required" >&2; exit 1; }
|
|
55
|
-
git show-ref --verify --quiet "refs/remotes/origin/$JORIPSPACE_SOURCE_BRANCH" || { echo "Registered source branch was not fetched" >&2; exit 1; }
|
|
56
|
-
git merge-base --is-ancestor "$GITHUB_SHA" "refs/remotes/origin/$JORIPSPACE_SOURCE_BRANCH" || { echo "Release tag must point to a commit on the registered source branch" >&2; exit 1; }
|
|
57
|
-
source_root=$(node -e 'const m=require(process.argv[1]); const v=String(m.source_root || "."); if (v !== "." && (v.startsWith("/") || v.includes("\\\\") || v.split("/").some((p) => !p || p === "." || p === ".."))) throw new Error("Unsafe source_root"); process.stdout.write(v)' "$manifest")
|
|
58
|
-
if [[ "$source_root" == "." ]]; then
|
|
59
|
-
distribution_sha="$GITHUB_SHA"
|
|
60
|
-
else
|
|
61
|
-
distribution_sha=$(git subtree split --prefix="$source_root" "$GITHUB_SHA")
|
|
62
|
-
fi
|
|
63
|
-
if git ls-tree -r "$distribution_sha" | grep -Eq '^(120000|160000) '; then
|
|
64
|
-
echo "Symlinks and submodules are not allowed in a template release" >&2
|
|
65
|
-
exit 1
|
|
66
|
-
fi
|
|
67
|
-
bare="$RUNNER_TEMP/joripspace-template-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT.git"
|
|
68
|
-
bundle="$RUNNER_TEMP/joripspace-template-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT.bundle"
|
|
69
|
-
archive="$RUNNER_TEMP/joripspace-template-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT.tar.gz"
|
|
70
|
-
stage="$RUNNER_TEMP/joripspace-template-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-stage"
|
|
71
|
-
git init --bare "$bare"
|
|
72
|
-
git push "$bare" "$distribution_sha:refs/heads/main"
|
|
73
|
-
git --git-dir="$bare" bundle create --version=2 "$bundle" refs/heads/main
|
|
74
|
-
git --git-dir="$bare" bundle verify "$bundle"
|
|
75
|
-
mkdir -p "$stage/release"
|
|
76
|
-
if [[ "$source_root" == "." ]]; then
|
|
77
|
-
git archive "$GITHUB_SHA" | tar -x -C "$stage/release"
|
|
78
|
-
else
|
|
79
|
-
mkdir -p "$stage/release/$source_root"
|
|
80
|
-
git archive "$GITHUB_SHA:$source_root" | tar -x -C "$stage/release/$source_root"
|
|
81
|
-
fi
|
|
82
|
-
cp "$manifest" "$stage/release/joripspace-template.json"
|
|
83
|
-
tar -czf "$archive" -C "$stage" release
|
|
84
|
-
file_count=$(git ls-tree -r --name-only "$distribution_sha" | wc -l | tr -d ' ')
|
|
85
|
-
source_bytes=$(git ls-tree -r -l "$distribution_sha" | awk '{ total += $4 } END { print total + 0 }')
|
|
86
|
-
echo "JORIPSPACE_BUNDLE_PATH=$bundle" >> "$GITHUB_ENV"
|
|
87
|
-
echo "JORIPSPACE_ARCHIVE_PATH=$archive" >> "$GITHUB_ENV"
|
|
88
|
-
echo "JORIPSPACE_MANIFEST_PATH=$manifest" >> "$GITHUB_ENV"
|
|
89
|
-
echo "JORIPSPACE_FILE_COUNT=$file_count" >> "$GITHUB_ENV"
|
|
90
|
-
echo "JORIPSPACE_SOURCE_BYTES=$source_bytes" >> "$GITHUB_ENV"
|
|
91
|
-
- name: Publish to JoripSpace
|
|
92
|
-
shell: bash
|
|
93
|
-
env:
|
|
94
|
-
JORIPSPACE_TEMPLATE_ID: ${JSON.stringify(String(templateId))}
|
|
95
|
-
JORIPSPACE_API_URL: "https://api.joripspace.com"
|
|
96
|
-
run: |
|
|
97
|
-
set -euo pipefail
|
|
98
|
-
node --input-type=module <<'JORIPSPACE_SCRIPT'
|
|
99
|
-
// Cloudflare's production bundler may annotate nested function names with
|
|
100
|
-
// __name(). Keep the generated standalone Node script compatible with it.
|
|
101
|
-
const __name = (value) => value;
|
|
102
|
-
${publishScript}
|
|
103
|
-
JORIPSPACE_SCRIPT
|
|
104
|
-
`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async function inlineTemplatePublishMain() {
|
|
108
|
-
const { readFile } = await import('node:fs/promises');
|
|
109
|
-
const audience = 'https://api.joripspace.com/v1/template-publish/github';
|
|
110
|
-
const templateId = requiredEnv('JORIPSPACE_TEMPLATE_ID');
|
|
111
|
-
const apiUrl = requiredEnv('JORIPSPACE_API_URL').replace(/\/+$/, '');
|
|
112
|
-
const [bundle, archive, manifest] = await Promise.all([
|
|
113
|
-
readFile(requiredEnv('JORIPSPACE_BUNDLE_PATH')),
|
|
114
|
-
readFile(requiredEnv('JORIPSPACE_ARCHIVE_PATH')),
|
|
115
|
-
readFile(requiredEnv('JORIPSPACE_MANIFEST_PATH')),
|
|
116
|
-
]);
|
|
117
|
-
const form = new FormData();
|
|
118
|
-
form.append('bundle', new Blob([bundle], { type: 'application/x-git-bundle' }), 'template.bundle');
|
|
119
|
-
form.append('archive', new Blob([archive], { type: 'application/gzip' }), 'template.tar.gz');
|
|
120
|
-
form.append('manifest', new Blob([manifest], { type: 'application/json' }), 'joripspace-template.json');
|
|
121
|
-
form.append('file_count', requiredEnv('JORIPSPACE_FILE_COUNT'));
|
|
122
|
-
form.append('source_bytes', requiredEnv('JORIPSPACE_SOURCE_BYTES'));
|
|
123
|
-
const token = await requestOidcToken();
|
|
124
|
-
const response = await fetch(`${apiUrl}/v1/template-publish/${encodeURIComponent(templateId)}/versions`, {
|
|
125
|
-
method: 'POST',
|
|
126
|
-
headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
|
|
127
|
-
body: form,
|
|
128
|
-
});
|
|
129
|
-
const text = await response.text();
|
|
130
|
-
const payload = text ? safeJson(text) : {};
|
|
131
|
-
if (!response.ok)
|
|
132
|
-
throw new Error(payload?.error?.message || `JoripSpace publish failed (${response.status}).`);
|
|
133
|
-
process.stdout.write(`JoripSpace template published: ${payload.version || payload.version_id}\n`);
|
|
134
|
-
|
|
135
|
-
async function requestOidcToken() {
|
|
136
|
-
const requestUrl = requiredEnv('ACTIONS_ID_TOKEN_REQUEST_URL');
|
|
137
|
-
const requestToken = requiredEnv('ACTIONS_ID_TOKEN_REQUEST_TOKEN');
|
|
138
|
-
const separator = requestUrl.includes('?') ? '&' : '?';
|
|
139
|
-
const response = await fetch(`${requestUrl}${separator}audience=${encodeURIComponent(audience)}`, {
|
|
140
|
-
headers: { Authorization: `Bearer ${requestToken}` },
|
|
141
|
-
});
|
|
142
|
-
const payload = await response.json().catch(() => ({}));
|
|
143
|
-
if (!response.ok || typeof payload.value !== 'string')
|
|
144
|
-
throw new Error(`GitHub OIDC token request failed (${response.status}).`);
|
|
145
|
-
return payload.value;
|
|
146
|
-
}
|
|
147
|
-
function safeJson(value) {
|
|
148
|
-
try {
|
|
149
|
-
return JSON.parse(value);
|
|
150
|
-
} catch {
|
|
151
|
-
return { error: { message: value.slice(0, 500) } };
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
function requiredEnv(name) {
|
|
155
|
-
const value = process.env[name];
|
|
156
|
-
if (!value) throw new Error(`${name} is required.`);
|
|
157
|
-
return value;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function templateGithubActionsPublishFile(templateConfig = {}) {
|
|
162
|
-
return buildTemplatePublishWorkflow({
|
|
163
|
-
templateId: String(templateConfig.template_id || '__JORIPSPACE_TEMPLATE_ID__'),
|
|
164
|
-
branch: String(templateConfig.default_ref || 'main'),
|
|
165
|
-
manifestPath: String(templateConfig.manifest_path || 'joripspace-template.json'),
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
module.exports = { buildTemplatePublishWorkflow, templateGithubActionsPublishFile };
|
|
1
|
+
function buildTemplatePublishWorkflow({
|
|
2
|
+
templateId,
|
|
3
|
+
branch = 'main',
|
|
4
|
+
manifestPath = 'joripspace-template.json',
|
|
5
|
+
}) {
|
|
6
|
+
const publishScript = `${inlineTemplatePublishMain.toString()}\n\nawait inlineTemplatePublishMain();`
|
|
7
|
+
.split('\n')
|
|
8
|
+
.map((line) => ` ${line}`)
|
|
9
|
+
.join('\n');
|
|
10
|
+
return `# joripspace-template-workflow-version: 3
|
|
11
|
+
#
|
|
12
|
+
# JoripSpace 템플릿 배포 가이드
|
|
13
|
+
# 1. 이 파일과 joripspace-template.json이 추가된 설정 PR을 기본 브랜치에 병합합니다.
|
|
14
|
+
# 2. GitHub 저장소의 Releases에서 배포할 버전 태그를 만들고 Release를 Publish합니다.
|
|
15
|
+
# 3. Release 태그가 조립스페이스에 표시되는 공식 버전이 됩니다. 예: 1.0.1 또는 v1.0.1
|
|
16
|
+
# 4. Actions 탭의 "JoripSpace Template Publish" 작업이 초록색으로 완료되는지 확인합니다.
|
|
17
|
+
#
|
|
18
|
+
# 알아두세요
|
|
19
|
+
# - 일반 push나 Release 초안 저장만으로는 배포되지 않습니다. Published Release만 배포됩니다.
|
|
20
|
+
# - 별도 API 키나 Secret은 필요하지 않습니다. GitHub OIDC로 저장소와 Release를 검증합니다.
|
|
21
|
+
# - Release 태그는 아래에 지정된 기준 브랜치에 포함된 커밋을 가리켜야 합니다.
|
|
22
|
+
# - 오류가 나면 Actions 실행에서 실패한 단계와 메시지를 먼저 확인하세요.
|
|
23
|
+
# - 이 워크플로와 joripspace-template.json을 삭제하면 이후 업데이트를 배포할 수 없습니다.
|
|
24
|
+
name: JoripSpace Template Publish
|
|
25
|
+
|
|
26
|
+
on:
|
|
27
|
+
release:
|
|
28
|
+
types: [published]
|
|
29
|
+
|
|
30
|
+
permissions:
|
|
31
|
+
contents: read
|
|
32
|
+
id-token: write
|
|
33
|
+
|
|
34
|
+
concurrency:
|
|
35
|
+
group: ${JSON.stringify(`joripspace-template-${String(templateId)}`)}
|
|
36
|
+
cancel-in-progress: false
|
|
37
|
+
|
|
38
|
+
jobs:
|
|
39
|
+
publish:
|
|
40
|
+
runs-on: ubuntu-latest
|
|
41
|
+
steps:
|
|
42
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
43
|
+
with:
|
|
44
|
+
fetch-depth: 0
|
|
45
|
+
- name: Build Git Bundle and files archive
|
|
46
|
+
shell: bash
|
|
47
|
+
env:
|
|
48
|
+
JORIPSPACE_TEMPLATE_ID: ${JSON.stringify(String(templateId))}
|
|
49
|
+
JORIPSPACE_MANIFEST_PATH: ${JSON.stringify(String(manifestPath))}
|
|
50
|
+
JORIPSPACE_SOURCE_BRANCH: ${JSON.stringify(String(branch))}
|
|
51
|
+
run: |
|
|
52
|
+
set -euo pipefail
|
|
53
|
+
manifest="$GITHUB_WORKSPACE/$JORIPSPACE_MANIFEST_PATH"
|
|
54
|
+
test -f "$manifest" || { echo "joripspace-template.json is required" >&2; exit 1; }
|
|
55
|
+
git show-ref --verify --quiet "refs/remotes/origin/$JORIPSPACE_SOURCE_BRANCH" || { echo "Registered source branch was not fetched" >&2; exit 1; }
|
|
56
|
+
git merge-base --is-ancestor "$GITHUB_SHA" "refs/remotes/origin/$JORIPSPACE_SOURCE_BRANCH" || { echo "Release tag must point to a commit on the registered source branch" >&2; exit 1; }
|
|
57
|
+
source_root=$(node -e 'const m=require(process.argv[1]); const v=String(m.source_root || "."); if (v !== "." && (v.startsWith("/") || v.includes("\\\\") || v.split("/").some((p) => !p || p === "." || p === ".."))) throw new Error("Unsafe source_root"); process.stdout.write(v)' "$manifest")
|
|
58
|
+
if [[ "$source_root" == "." ]]; then
|
|
59
|
+
distribution_sha="$GITHUB_SHA"
|
|
60
|
+
else
|
|
61
|
+
distribution_sha=$(git subtree split --prefix="$source_root" "$GITHUB_SHA")
|
|
62
|
+
fi
|
|
63
|
+
if git ls-tree -r "$distribution_sha" | grep -Eq '^(120000|160000) '; then
|
|
64
|
+
echo "Symlinks and submodules are not allowed in a template release" >&2
|
|
65
|
+
exit 1
|
|
66
|
+
fi
|
|
67
|
+
bare="$RUNNER_TEMP/joripspace-template-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT.git"
|
|
68
|
+
bundle="$RUNNER_TEMP/joripspace-template-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT.bundle"
|
|
69
|
+
archive="$RUNNER_TEMP/joripspace-template-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT.tar.gz"
|
|
70
|
+
stage="$RUNNER_TEMP/joripspace-template-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-stage"
|
|
71
|
+
git init --bare "$bare"
|
|
72
|
+
git push "$bare" "$distribution_sha:refs/heads/main"
|
|
73
|
+
git --git-dir="$bare" bundle create --version=2 "$bundle" refs/heads/main
|
|
74
|
+
git --git-dir="$bare" bundle verify "$bundle"
|
|
75
|
+
mkdir -p "$stage/release"
|
|
76
|
+
if [[ "$source_root" == "." ]]; then
|
|
77
|
+
git archive "$GITHUB_SHA" | tar -x -C "$stage/release"
|
|
78
|
+
else
|
|
79
|
+
mkdir -p "$stage/release/$source_root"
|
|
80
|
+
git archive "$GITHUB_SHA:$source_root" | tar -x -C "$stage/release/$source_root"
|
|
81
|
+
fi
|
|
82
|
+
cp "$manifest" "$stage/release/joripspace-template.json"
|
|
83
|
+
tar -czf "$archive" -C "$stage" release
|
|
84
|
+
file_count=$(git ls-tree -r --name-only "$distribution_sha" | wc -l | tr -d ' ')
|
|
85
|
+
source_bytes=$(git ls-tree -r -l "$distribution_sha" | awk '{ total += $4 } END { print total + 0 }')
|
|
86
|
+
echo "JORIPSPACE_BUNDLE_PATH=$bundle" >> "$GITHUB_ENV"
|
|
87
|
+
echo "JORIPSPACE_ARCHIVE_PATH=$archive" >> "$GITHUB_ENV"
|
|
88
|
+
echo "JORIPSPACE_MANIFEST_PATH=$manifest" >> "$GITHUB_ENV"
|
|
89
|
+
echo "JORIPSPACE_FILE_COUNT=$file_count" >> "$GITHUB_ENV"
|
|
90
|
+
echo "JORIPSPACE_SOURCE_BYTES=$source_bytes" >> "$GITHUB_ENV"
|
|
91
|
+
- name: Publish to JoripSpace
|
|
92
|
+
shell: bash
|
|
93
|
+
env:
|
|
94
|
+
JORIPSPACE_TEMPLATE_ID: ${JSON.stringify(String(templateId))}
|
|
95
|
+
JORIPSPACE_API_URL: "https://api.joripspace.com"
|
|
96
|
+
run: |
|
|
97
|
+
set -euo pipefail
|
|
98
|
+
node --input-type=module <<'JORIPSPACE_SCRIPT'
|
|
99
|
+
// Cloudflare's production bundler may annotate nested function names with
|
|
100
|
+
// __name(). Keep the generated standalone Node script compatible with it.
|
|
101
|
+
const __name = (value) => value;
|
|
102
|
+
${publishScript}
|
|
103
|
+
JORIPSPACE_SCRIPT
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function inlineTemplatePublishMain() {
|
|
108
|
+
const { readFile } = await import('node:fs/promises');
|
|
109
|
+
const audience = 'https://api.joripspace.com/v1/template-publish/github';
|
|
110
|
+
const templateId = requiredEnv('JORIPSPACE_TEMPLATE_ID');
|
|
111
|
+
const apiUrl = requiredEnv('JORIPSPACE_API_URL').replace(/\/+$/, '');
|
|
112
|
+
const [bundle, archive, manifest] = await Promise.all([
|
|
113
|
+
readFile(requiredEnv('JORIPSPACE_BUNDLE_PATH')),
|
|
114
|
+
readFile(requiredEnv('JORIPSPACE_ARCHIVE_PATH')),
|
|
115
|
+
readFile(requiredEnv('JORIPSPACE_MANIFEST_PATH')),
|
|
116
|
+
]);
|
|
117
|
+
const form = new FormData();
|
|
118
|
+
form.append('bundle', new Blob([bundle], { type: 'application/x-git-bundle' }), 'template.bundle');
|
|
119
|
+
form.append('archive', new Blob([archive], { type: 'application/gzip' }), 'template.tar.gz');
|
|
120
|
+
form.append('manifest', new Blob([manifest], { type: 'application/json' }), 'joripspace-template.json');
|
|
121
|
+
form.append('file_count', requiredEnv('JORIPSPACE_FILE_COUNT'));
|
|
122
|
+
form.append('source_bytes', requiredEnv('JORIPSPACE_SOURCE_BYTES'));
|
|
123
|
+
const token = await requestOidcToken();
|
|
124
|
+
const response = await fetch(`${apiUrl}/v1/template-publish/${encodeURIComponent(templateId)}/versions`, {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
|
|
127
|
+
body: form,
|
|
128
|
+
});
|
|
129
|
+
const text = await response.text();
|
|
130
|
+
const payload = text ? safeJson(text) : {};
|
|
131
|
+
if (!response.ok)
|
|
132
|
+
throw new Error(payload?.error?.message || `JoripSpace publish failed (${response.status}).`);
|
|
133
|
+
process.stdout.write(`JoripSpace template published: ${payload.version || payload.version_id}\n`);
|
|
134
|
+
|
|
135
|
+
async function requestOidcToken() {
|
|
136
|
+
const requestUrl = requiredEnv('ACTIONS_ID_TOKEN_REQUEST_URL');
|
|
137
|
+
const requestToken = requiredEnv('ACTIONS_ID_TOKEN_REQUEST_TOKEN');
|
|
138
|
+
const separator = requestUrl.includes('?') ? '&' : '?';
|
|
139
|
+
const response = await fetch(`${requestUrl}${separator}audience=${encodeURIComponent(audience)}`, {
|
|
140
|
+
headers: { Authorization: `Bearer ${requestToken}` },
|
|
141
|
+
});
|
|
142
|
+
const payload = await response.json().catch(() => ({}));
|
|
143
|
+
if (!response.ok || typeof payload.value !== 'string')
|
|
144
|
+
throw new Error(`GitHub OIDC token request failed (${response.status}).`);
|
|
145
|
+
return payload.value;
|
|
146
|
+
}
|
|
147
|
+
function safeJson(value) {
|
|
148
|
+
try {
|
|
149
|
+
return JSON.parse(value);
|
|
150
|
+
} catch {
|
|
151
|
+
return { error: { message: value.slice(0, 500) } };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function requiredEnv(name) {
|
|
155
|
+
const value = process.env[name];
|
|
156
|
+
if (!value) throw new Error(`${name} is required.`);
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function templateGithubActionsPublishFile(templateConfig = {}) {
|
|
162
|
+
return buildTemplatePublishWorkflow({
|
|
163
|
+
templateId: String(templateConfig.template_id || '__JORIPSPACE_TEMPLATE_ID__'),
|
|
164
|
+
branch: String(templateConfig.default_ref || 'main'),
|
|
165
|
+
manifestPath: String(templateConfig.manifest_path || 'joripspace-template.json'),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
module.exports = { buildTemplatePublishWorkflow, templateGithubActionsPublishFile };
|
|
@@ -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
|
+
}
|