@joripspace/cli 0.4.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/LICENSE +21 -0
- package/README.md +74 -0
- package/THIRD_PARTY_NOTICES.md +85 -0
- package/bin/joripspace.js +1614 -0
- package/lib/checkpoint-client.js +446 -0
- package/lib/checkpoint-commands.js +210 -0
- package/lib/deploy-files.js +245 -0
- package/lib/deployment-error.js +14 -0
- package/lib/help.js +146 -0
- package/lib/installer-args.js +28 -0
- package/lib/installer-target.js +134 -0
- package/lib/mcp-config.js +981 -0
- package/lib/project-env.js +198 -0
- package/lib/project-paths.js +257 -0
- package/lib/realtime-v2-commands.js +42 -0
- package/lib/remote-commands.js +401 -0
- package/lib/start-command.js +132 -0
- package/lib/start.js +1430 -0
- package/lib/template-commands.js +812 -0
- package/package.json +46 -0
- package/vendor/core/github-workflow.cjs +197 -0
- package/vendor/core/onboarding.cjs +2423 -0
- package/vendor/core/template-publish-workflow.cjs +169 -0
- package/vendor/templates/index.js +104 -0
- package/vendor/templates/templates/basic-worker/files/worker.js +9 -0
- package/vendor/templates/templates/basic-worker/manifest.json +14 -0
- package/vendor/templates/templates/r2-file-api/files/worker.js +42 -0
- package/vendor/templates/templates/r2-file-api/manifest.json +7 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { safeProjectRelativePath } = require('./project-paths');
|
|
4
|
+
|
|
5
|
+
const INLINE_FILE_LIMIT = 16_000;
|
|
6
|
+
const INLINE_TOTAL_LIMIT = 64_000;
|
|
7
|
+
const IGNORED_DIRS = new Set([
|
|
8
|
+
'.git',
|
|
9
|
+
'.joripspace',
|
|
10
|
+
'.wrangler',
|
|
11
|
+
'.cache',
|
|
12
|
+
'.agents',
|
|
13
|
+
'.claude',
|
|
14
|
+
'.codex',
|
|
15
|
+
'.cursor',
|
|
16
|
+
'.gemini',
|
|
17
|
+
'.opencode',
|
|
18
|
+
'coverage',
|
|
19
|
+
'node_modules',
|
|
20
|
+
'tmp',
|
|
21
|
+
'temp',
|
|
22
|
+
]);
|
|
23
|
+
const PROTECTED_FILE_NAMES = new Set(['agents.md', 'claude.md']);
|
|
24
|
+
const PROTECTED_SOURCE_DIRS = new Set([
|
|
25
|
+
'.agents',
|
|
26
|
+
'.claude',
|
|
27
|
+
'.codex',
|
|
28
|
+
'.cursor',
|
|
29
|
+
'.gemini',
|
|
30
|
+
'.git',
|
|
31
|
+
'.joripspace',
|
|
32
|
+
'.opencode',
|
|
33
|
+
'.wrangler',
|
|
34
|
+
'node_modules',
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
function buildDeployPayload(flags) {
|
|
38
|
+
const source = stringFlag(flags, 'source');
|
|
39
|
+
if (source) {
|
|
40
|
+
const fileName = safeProjectRelativePath(stringFlag(flags, 'entrypoint') || path.basename(source));
|
|
41
|
+
assertDeployableProjectPath(fileName);
|
|
42
|
+
const resolved = resolveDeploySourceFile(source, stringFlag(flags, 'cwd'));
|
|
43
|
+
return buildInlineDeployPayload(fileName, new Map([[fileName, resolved]]));
|
|
44
|
+
}
|
|
45
|
+
const directory = stringFlag(flags, 'dir');
|
|
46
|
+
if (directory) {
|
|
47
|
+
const rawEntrypoint = stringFlag(flags, 'entrypoint');
|
|
48
|
+
if (!rawEntrypoint) throw new Error('deploy --dir requires --entrypoint');
|
|
49
|
+
const entrypoint = safeProjectRelativePath(rawEntrypoint);
|
|
50
|
+
const resolvedDirectory = resolveDeploySourceDirectory(directory, stringFlag(flags, 'cwd'));
|
|
51
|
+
const files = new Map();
|
|
52
|
+
for (const file of walkFiles(resolvedDirectory.path)) {
|
|
53
|
+
const relative = safeProjectRelativePath(toPosix(path.relative(resolvedDirectory.path, file.path)));
|
|
54
|
+
files.set(relative, file);
|
|
55
|
+
}
|
|
56
|
+
if (!files.has(entrypoint)) {
|
|
57
|
+
throw new Error(`entrypoint not found in --dir: ${entrypoint}`);
|
|
58
|
+
}
|
|
59
|
+
return buildInlineDeployPayload(entrypoint, files);
|
|
60
|
+
}
|
|
61
|
+
const mappings = arrayFlag(flags, 'file');
|
|
62
|
+
if (mappings.length) {
|
|
63
|
+
const rawEntrypoint = stringFlag(flags, 'entrypoint');
|
|
64
|
+
if (!rawEntrypoint) throw new Error('deploy --file requires --entrypoint');
|
|
65
|
+
const entrypoint = safeProjectRelativePath(rawEntrypoint);
|
|
66
|
+
const files = new Map();
|
|
67
|
+
for (const mapping of mappings) {
|
|
68
|
+
const [name, filePath] = splitFileMapping(mapping);
|
|
69
|
+
const relative = safeProjectRelativePath(name);
|
|
70
|
+
assertDeployableProjectPath(relative);
|
|
71
|
+
files.set(relative, resolveDeploySourceFile(filePath, stringFlag(flags, 'cwd')));
|
|
72
|
+
}
|
|
73
|
+
if (!files.has(entrypoint)) {
|
|
74
|
+
throw new Error(`entrypoint not found in --file mappings: ${entrypoint}`);
|
|
75
|
+
}
|
|
76
|
+
return buildInlineDeployPayload(entrypoint, files);
|
|
77
|
+
}
|
|
78
|
+
throw new Error('deploy requires --source, --dir, or --file');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function buildInlineDeployPayload(entrypoint, sources) {
|
|
82
|
+
let expectedTotal = 0;
|
|
83
|
+
for (const [fileName, source] of sources) {
|
|
84
|
+
if (source.size > INLINE_FILE_LIMIT) {
|
|
85
|
+
throw archiveRequired(`deploy source exceeds the inline file limit (${fileName})`);
|
|
86
|
+
}
|
|
87
|
+
expectedTotal += source.size;
|
|
88
|
+
}
|
|
89
|
+
if (expectedTotal > INLINE_TOTAL_LIMIT) {
|
|
90
|
+
throw archiveRequired('deploy source exceeds the inline total limit');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const buffered = [];
|
|
94
|
+
let actualTotal = 0;
|
|
95
|
+
for (const [fileName, source] of sources) {
|
|
96
|
+
const bytes = fs.readFileSync(source.path);
|
|
97
|
+
if (bytes.byteLength > INLINE_FILE_LIMIT) {
|
|
98
|
+
throw archiveRequired(`deploy source exceeds the inline file limit (${fileName})`);
|
|
99
|
+
}
|
|
100
|
+
actualTotal += bytes.byteLength;
|
|
101
|
+
if (actualTotal > INLINE_TOTAL_LIMIT) {
|
|
102
|
+
throw archiveRequired('deploy source exceeds the inline total limit');
|
|
103
|
+
}
|
|
104
|
+
if (bytes.includes(0)) {
|
|
105
|
+
throw archiveRequired(`deploy source contains binary data (${fileName})`);
|
|
106
|
+
}
|
|
107
|
+
buffered.push([fileName, bytes]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const files = {};
|
|
111
|
+
for (const [fileName, bytes] of buffered) {
|
|
112
|
+
const text = bytes.toString('utf8');
|
|
113
|
+
if (!Buffer.from(text, 'utf8').equals(bytes)) {
|
|
114
|
+
throw archiveRequired(`deploy source contains binary data (${fileName})`);
|
|
115
|
+
}
|
|
116
|
+
files[fileName] = text;
|
|
117
|
+
}
|
|
118
|
+
return { entrypoint, files };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function walkFiles(root, base = path.resolve(root)) {
|
|
122
|
+
const files = [];
|
|
123
|
+
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
124
|
+
const fullPath = path.join(root, entry.name);
|
|
125
|
+
const relative = toPosix(path.relative(base, fullPath));
|
|
126
|
+
if (entry.isDirectory() && IGNORED_DIRS.has(entry.name.toLowerCase())) continue;
|
|
127
|
+
if (isProtectedProjectPath(relative)) continue;
|
|
128
|
+
if (entry.isDirectory()) files.push(...walkFiles(fullPath, base));
|
|
129
|
+
else if (entry.isFile()) files.push(resolveDeploySourceFile(fullPath, base));
|
|
130
|
+
}
|
|
131
|
+
return files;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function assertDeployableProjectPath(value) {
|
|
135
|
+
const relative = safeProjectRelativePath(value);
|
|
136
|
+
if (isProtectedProjectPath(relative)) throw new Error(`protected file cannot be deployed: ${relative}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function assertDeployableSourceFilePath(value, workspaceDir = '') {
|
|
140
|
+
resolveDeploySourceFile(value, workspaceDir);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function resolveDeploySourceFile(value, workspaceDir = '') {
|
|
144
|
+
return resolveDeploySource(value, workspaceDir, 'file');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function resolveDeploySourceDirectory(value, workspaceDir = '') {
|
|
148
|
+
return resolveDeploySource(value, workspaceDir, 'directory');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function resolveDeploySource(value, workspaceDir, expectedType) {
|
|
152
|
+
const source = path.resolve(value);
|
|
153
|
+
const stat = fs.lstatSync(source);
|
|
154
|
+
if (stat.isSymbolicLink()) {
|
|
155
|
+
throw new Error(`protected deploy source cannot be a symbolic link or junction: ${value}`);
|
|
156
|
+
}
|
|
157
|
+
if (expectedType === 'file' ? !stat.isFile() : !stat.isDirectory()) {
|
|
158
|
+
throw new Error(`deploy source must be a regular ${expectedType}: ${value}`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const realSource = fs.realpathSync.native(source);
|
|
162
|
+
const realStat = fs.lstatSync(realSource);
|
|
163
|
+
if (realStat.isSymbolicLink() || (expectedType === 'file' ? !realStat.isFile() : !realStat.isDirectory())) {
|
|
164
|
+
throw new Error(`deploy source must be a regular ${expectedType}: ${value}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (workspaceDir) {
|
|
168
|
+
const workspace = path.resolve(workspaceDir);
|
|
169
|
+
const realWorkspace = fs.realpathSync.native(workspace);
|
|
170
|
+
if (isContainedPath(workspace, source) && !isContainedPath(realWorkspace, realSource)) {
|
|
171
|
+
throw new Error(`deploy source escapes the workspace through a symbolic link or junction: ${value}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (isProtectedSourcePath(source) || isProtectedSourcePath(realSource)) {
|
|
176
|
+
throw new Error(`protected file cannot be used as deploy source: ${value}`);
|
|
177
|
+
}
|
|
178
|
+
return { path: realSource, size: realStat.size, type: expectedType };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function isProtectedSourcePath(value) {
|
|
182
|
+
const resolved = path.resolve(value);
|
|
183
|
+
const baseName = path.basename(resolved);
|
|
184
|
+
const parts = resolved.replace(/\\/g, '/').toLowerCase().split('/');
|
|
185
|
+
return isProtectedProjectPath(baseName) || parts.some((part) => PROTECTED_SOURCE_DIRS.has(part));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function isContainedPath(root, target) {
|
|
189
|
+
const relative = path.relative(root, target);
|
|
190
|
+
return (
|
|
191
|
+
relative === '' ||
|
|
192
|
+
(relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative))
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function isProtectedProjectPath(value) {
|
|
197
|
+
const normalized = String(value || '')
|
|
198
|
+
.replace(/\\/g, '/')
|
|
199
|
+
.replace(/^\.\//, '')
|
|
200
|
+
.toLowerCase();
|
|
201
|
+
const parts = normalized.split('/');
|
|
202
|
+
const baseName = parts.at(-1) || '';
|
|
203
|
+
return (
|
|
204
|
+
parts.some((part) => IGNORED_DIRS.has(part)) ||
|
|
205
|
+
baseName === '.env.joripspace' ||
|
|
206
|
+
PROTECTED_FILE_NAMES.has(baseName) ||
|
|
207
|
+
baseName.endsWith('.log')
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function archiveRequired(message) {
|
|
212
|
+
const error = new Error(message);
|
|
213
|
+
error.code = 'archive_required';
|
|
214
|
+
return error;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function stringFlag(flags, name) {
|
|
218
|
+
const value = flags[name];
|
|
219
|
+
return Array.isArray(value) ? String(value.at(-1)) : typeof value === 'string' ? value : '';
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function arrayFlag(flags, name) {
|
|
223
|
+
const value = flags[name];
|
|
224
|
+
if (value === undefined) return [];
|
|
225
|
+
return Array.isArray(value) ? value.map(String) : [String(value)];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function splitFileMapping(value) {
|
|
229
|
+
const separator = value.indexOf('=');
|
|
230
|
+
if (separator <= 0 || separator === value.length - 1) throw new Error('--file must use name=path');
|
|
231
|
+
return [value.slice(0, separator), value.slice(separator + 1)];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function toPosix(value) {
|
|
235
|
+
return value.split(path.sep).join('/');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
module.exports = {
|
|
239
|
+
assertDeployableProjectPath,
|
|
240
|
+
assertDeployableSourceFilePath,
|
|
241
|
+
buildDeployPayload,
|
|
242
|
+
isProtectedProjectPath,
|
|
243
|
+
resolveDeploySourceDirectory,
|
|
244
|
+
resolveDeploySourceFile,
|
|
245
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function formatDeploymentFailure(message, details) {
|
|
4
|
+
if (!details || typeof details !== 'object' || !details.deployment_id) return message;
|
|
5
|
+
const lines = [message, `Deployment: ${details.deployment_id}`];
|
|
6
|
+
if (details.error_stage) lines.push(`Stage: ${details.error_stage}`);
|
|
7
|
+
if (details.error_code) lines.push(`Error code: ${details.error_code}`);
|
|
8
|
+
if (details.error_details && details.error_details !== message) {
|
|
9
|
+
lines.push(`Details: ${details.error_details}`);
|
|
10
|
+
}
|
|
11
|
+
return lines.join('\n');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = { formatDeploymentFailure };
|
package/lib/help.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
const DEFAULT_API_URL = 'https://api.joripspace.com';
|
|
2
|
+
|
|
3
|
+
function printHelp() {
|
|
4
|
+
console.log(`JoripSpace CLI
|
|
5
|
+
|
|
6
|
+
Usage:
|
|
7
|
+
joripspace login
|
|
8
|
+
joripspace login --code "복사한_연결_코드" --cwd PROJECT_FOLDER
|
|
9
|
+
joripspace login --connect-token "복사한_연결_토큰" --cwd PROJECT_FOLDER
|
|
10
|
+
joripspace me
|
|
11
|
+
joripspace projects
|
|
12
|
+
joripspace link --project PROJECT --cwd PATH
|
|
13
|
+
joripspace start PROJECT --cwd PATH --json
|
|
14
|
+
joripspace knowledge search --query "사용자 요청"
|
|
15
|
+
joripspace realtime-v2 docs
|
|
16
|
+
joripspace realtime-v2 status --project PROJECT
|
|
17
|
+
joripspace realtime-v2 activate --project PROJECT
|
|
18
|
+
joripspace realtime-v2 rotate --project PROJECT
|
|
19
|
+
joripspace realtime-v2 keys --project PROJECT --cursor CURSOR
|
|
20
|
+
joripspace realtime-v2 revoke-key --project PROJECT --kid KEY_ID
|
|
21
|
+
joripspace db schema --project PROJECT --token TOKEN
|
|
22
|
+
joripspace db query --project PROJECT --token TOKEN --sql "SELECT name FROM sqlite_schema WHERE type = 'table'"
|
|
23
|
+
joripspace db migrate --project PROJECT --token TOKEN --file migrations/001_init.sql
|
|
24
|
+
joripspace storage list --project PROJECT --token TOKEN --prefix uploads/
|
|
25
|
+
joripspace storage put --project PROJECT --token TOKEN --key uploads/hello.txt --text "hello"
|
|
26
|
+
joripspace storage get --project PROJECT --token TOKEN --key uploads/hello.txt --out hello.txt
|
|
27
|
+
joripspace storage delete --project PROJECT --token TOKEN --key uploads/hello.txt
|
|
28
|
+
joripspace deploy --project PROJECT --token TOKEN --source worker.js --label "첫 배포"
|
|
29
|
+
joripspace templates
|
|
30
|
+
joripspace template list --project PROJECT --cursor CURSOR
|
|
31
|
+
joripspace deploy-template --project PROJECT --token TOKEN --template basic-worker --label "기본 템플릿 배포" --var MESSAGE=Hello
|
|
32
|
+
joripspace install-template --project PROJECT --token TOKEN --template TEMPLATE --dir . --deploy
|
|
33
|
+
joripspace install-template --project PROJECT --token TOKEN --template TEMPLATE --dir . --files-only
|
|
34
|
+
joripspace template pull --project PROJECT --token TOKEN --dir . [--yes]
|
|
35
|
+
joripspace get --project PROJECT --token TOKEN
|
|
36
|
+
joripspace deployments --project PROJECT --token TOKEN [--include-failure-details] [--json]
|
|
37
|
+
joripspace deployment get --project PROJECT --deployment DEPLOYMENT_ID --json
|
|
38
|
+
joripspace deployment pull --project PROJECT --deployment DEPLOYMENT_ID --cwd PATH [--force]
|
|
39
|
+
joripspace checkpoint save --project PROJECT --token TOKEN --label "작업 완료"
|
|
40
|
+
joripspace checkpoint list --project PROJECT --token TOKEN --limit 20
|
|
41
|
+
joripspace checkpoint get --project PROJECT --token TOKEN --checkpoint CHECKPOINT_ID
|
|
42
|
+
joripspace checkpoint update --project PROJECT --token TOKEN --checkpoint CHECKPOINT_ID --label "이름"
|
|
43
|
+
joripspace checkpoint restore --project PROJECT --token TOKEN --checkpoint CHECKPOINT_ID
|
|
44
|
+
joripspace checkpoint deploy --project PROJECT --token TOKEN --checkpoint CHECKPOINT_ID
|
|
45
|
+
joripspace checkpoint delete --project PROJECT --token TOKEN --checkpoint CHECKPOINT_ID --yes
|
|
46
|
+
joripspace rollback --project PROJECT --token TOKEN --deployment DEPLOYMENT_ID
|
|
47
|
+
joripspace secrets --project PROJECT
|
|
48
|
+
joripspace secret list --project PROJECT
|
|
49
|
+
joripspace secret generate --project PROJECT --name SESSION_SECRET
|
|
50
|
+
joripspace crons --project PROJECT
|
|
51
|
+
joripspace cron create --project PROJECT --schedule "0 * * * *" --path /jobs/hourly
|
|
52
|
+
joripspace cron run --project PROJECT --cron-id CRON_ID
|
|
53
|
+
joripspace cron delete --project PROJECT --cron-id CRON_ID --yes
|
|
54
|
+
joripspace domains --project PROJECT --token TOKEN
|
|
55
|
+
joripspace domain create --project PROJECT --token TOKEN --hostname www.example.com
|
|
56
|
+
joripspace domain verify --project PROJECT --token TOKEN --hostname www.example.com
|
|
57
|
+
joripspace domain delete --project PROJECT --token TOKEN --hostname www.example.com --yes
|
|
58
|
+
joripspace mail connect --project PROJECT
|
|
59
|
+
joripspace mail status --project PROJECT
|
|
60
|
+
joripspace mail test --project PROJECT [--to ADDRESS] [--subject TEXT]
|
|
61
|
+
joripspace events --project PROJECT --token TOKEN --event-type error
|
|
62
|
+
joripspace usage-summary --project PROJECT --from 2026-06-01 --to 2026-06-30
|
|
63
|
+
joripspace usage-breakdown --project PROJECT --from 2026-06-01 --to 2026-06-30 --group-by day
|
|
64
|
+
joripspace usage-breakdown --project PROJECT --from 2026-06-01 --to 2026-06-30 --group-by month
|
|
65
|
+
|
|
66
|
+
Environment:
|
|
67
|
+
JORIPSPACE_API_URL Defaults to ${DEFAULT_API_URL}
|
|
68
|
+
JORIPSPACE_ACCOUNT_ID Used when --account is omitted
|
|
69
|
+
JORIPSPACE_API_TOKEN Used when --token is omitted
|
|
70
|
+
JORIPSPACE_CONNECT_TOKEN Used when no API token is provided
|
|
71
|
+
|
|
72
|
+
Login:
|
|
73
|
+
Run "joripspace login", open the shown link in a logged-in browser, approve connection,
|
|
74
|
+
then exchange the displayed 5-minute connection code with --code.
|
|
75
|
+
Existing connection tokens can still be saved with --connect-token.
|
|
76
|
+
If a token is missing, do not inspect cookies, browser storage, or profile pages to find it.
|
|
77
|
+
Open https://joripspace.com/connect/ and ask the user to paste the displayed connection code.
|
|
78
|
+
The token and matching API URL are stored only in PROJECT_FOLDER/.env.joripspace. The CLI searches
|
|
79
|
+
parent folders for this file. It never reads a generic application .env file for authentication.
|
|
80
|
+
|
|
81
|
+
Security:
|
|
82
|
+
CLI tokens are for project lookup, workspace linking, project DB/storage work, server deployment, usage, and logs.
|
|
83
|
+
Project checkpoints can be saved, restored locally, and deployed independently with the checkpoint command.
|
|
84
|
+
Deployment rollback, value-blind Secret generation/listing, crons, domains, and mail status/test are available.
|
|
85
|
+
Manage custom domains with the domain command.
|
|
86
|
+
Manage members, billing, API tokens, external Secret values, webhooks, and project deletion in the web UI.
|
|
87
|
+
|
|
88
|
+
Global flags:
|
|
89
|
+
--api-url URL
|
|
90
|
+
--cwd PATH
|
|
91
|
+
--json
|
|
92
|
+
--help
|
|
93
|
+
`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function printDeployHelp() {
|
|
97
|
+
console.log(`JoripSpace deploy
|
|
98
|
+
|
|
99
|
+
Usage:
|
|
100
|
+
joripspace deploy --project PROJECT --token TOKEN --source worker.js --label "첫 배포"
|
|
101
|
+
|
|
102
|
+
Options:
|
|
103
|
+
--source PATH Deploy one source file. Entrypoint defaults to the file basename.
|
|
104
|
+
--dir PATH Deploy every safe file under a directory. Authentication is resolved from --cwd.
|
|
105
|
+
--file NAME=PATH Add one file mapping. Can be repeated.
|
|
106
|
+
--entrypoint NAME Server module entrypoint.
|
|
107
|
+
--label TEXT Required deployment label, up to 120 characters.
|
|
108
|
+
`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function printDeployTemplateHelp() {
|
|
112
|
+
console.log(`JoripSpace deploy-template
|
|
113
|
+
|
|
114
|
+
Usage:
|
|
115
|
+
joripspace templates
|
|
116
|
+
joripspace deploy-template --project PROJECT --token TOKEN --template basic-worker --label "메시지 변경" --var MESSAGE=Hello
|
|
117
|
+
|
|
118
|
+
Options:
|
|
119
|
+
--template ID Template id from the templates command.
|
|
120
|
+
--var KEY=VALUE Template variable. Can be repeated.
|
|
121
|
+
--label TEXT Required deployment label, up to 120 characters.
|
|
122
|
+
`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function printInstallTemplateHelp() {
|
|
126
|
+
console.log(`JoripSpace install-template
|
|
127
|
+
|
|
128
|
+
Usage:
|
|
129
|
+
joripspace install-template --project PROJECT --token TOKEN --template TEMPLATE --dir . --deploy
|
|
130
|
+
|
|
131
|
+
Options:
|
|
132
|
+
--template SLUG Marketplace template slug.
|
|
133
|
+
--dir PATH Install directory. Defaults to the current directory.
|
|
134
|
+
--files-only Copy template files without connecting Git history or template pull.
|
|
135
|
+
--force Allow overwriting files with the same path.
|
|
136
|
+
--deploy Deploy after installing the files.
|
|
137
|
+
--entrypoint PATH Override the manifest entrypoint for deployment.
|
|
138
|
+
--label TEXT Deployment label. A default is used when omitted.
|
|
139
|
+
|
|
140
|
+
Template updates:
|
|
141
|
+
"joripspace template pull" checks availability without downloading. Add --yes only after reviewing
|
|
142
|
+
and approving the update; the bundle is then fetched through the local JoripSpace upstream channel.
|
|
143
|
+
`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = { printHelp, printDeployHelp, printDeployTemplateHelp, printInstallTemplateHelp };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const path = require('node:path');
|
|
2
|
+
|
|
3
|
+
function installerFlags(args) {
|
|
4
|
+
const values = Array.isArray(args) ? args : [];
|
|
5
|
+
return {
|
|
6
|
+
wantsHelp: values.includes('--help') || values.includes('-h'),
|
|
7
|
+
wantsJson: values.includes('--json'),
|
|
8
|
+
wantsQuiet: values.includes('--quiet') || values.includes('-quiet'),
|
|
9
|
+
wantsVersion: values.includes('--version') || values.includes('-v'),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function normalizeWindowsPathEntry(value, env = process.env) {
|
|
14
|
+
const variables = new Map(
|
|
15
|
+
Object.entries(env || {}).map(([name, nested]) => [name.toLowerCase(), String(nested || '')])
|
|
16
|
+
);
|
|
17
|
+
const expanded = String(value || '')
|
|
18
|
+
.trim()
|
|
19
|
+
.replace(/^"|"$/g, '')
|
|
20
|
+
.replace(/%([^%]+)%/g, (match, name) => variables.get(String(name).toLowerCase()) || match);
|
|
21
|
+
if (!expanded) return '';
|
|
22
|
+
return path.win32
|
|
23
|
+
.normalize(expanded)
|
|
24
|
+
.replace(/[\\/]+$/u, '')
|
|
25
|
+
.toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = { installerFlags, normalizeWindowsPathEntry };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
const crypto = require('node:crypto');
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
function installExecutableAtomically(sourcePath, targetPath, options = {}) {
|
|
6
|
+
const source = path.resolve(sourcePath);
|
|
7
|
+
const target = path.resolve(targetPath);
|
|
8
|
+
const platform = options.platform || process.platform;
|
|
9
|
+
const sourceStat = fs.lstatSync(source);
|
|
10
|
+
if (!sourceStat.isFile() || sourceStat.isSymbolicLink()) {
|
|
11
|
+
throw new Error('JoripSpace installer source must be a regular file.');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const directory = path.dirname(target);
|
|
15
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
16
|
+
const before = executableSnapshot(target);
|
|
17
|
+
const suffix = `${process.pid}-${Date.now()}-${crypto.randomBytes(8).toString('hex')}`;
|
|
18
|
+
const temporary = path.join(directory, `.${path.basename(target)}.tmp-${suffix}`);
|
|
19
|
+
let backup = '';
|
|
20
|
+
let installed = false;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
fs.copyFileSync(source, temporary, fs.constants.COPYFILE_EXCL);
|
|
24
|
+
fs.chmodSync(temporary, options.mode ?? 0o755);
|
|
25
|
+
fsyncFile(temporary);
|
|
26
|
+
const copied = fs.lstatSync(temporary);
|
|
27
|
+
if (!copied.isFile() || copied.isSymbolicLink() || copied.size !== sourceStat.size) {
|
|
28
|
+
throw new Error('JoripSpace installer temporary executable failed integrity checks.');
|
|
29
|
+
}
|
|
30
|
+
if (!sameSnapshot(before, executableSnapshot(target))) {
|
|
31
|
+
throw new Error('Installed JoripSpace CLI changed during upgrade.');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (platform === 'win32' && before) {
|
|
35
|
+
backup = path.join(directory, `.${path.basename(target)}.previous-${suffix}`);
|
|
36
|
+
fs.renameSync(target, backup);
|
|
37
|
+
try {
|
|
38
|
+
if (typeof options.beforePromote === 'function') options.beforePromote();
|
|
39
|
+
fs.renameSync(temporary, target);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
try {
|
|
42
|
+
if (!fs.existsSync(target)) fs.renameSync(backup, target);
|
|
43
|
+
} catch (rollbackError) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`JoripSpace CLI upgrade failed and the previous executable remains at ${backup}: ${messageOf(
|
|
46
|
+
rollbackError
|
|
47
|
+
)}`,
|
|
48
|
+
{ cause: error }
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
backup = '';
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
if (typeof options.beforePromote === 'function') options.beforePromote();
|
|
56
|
+
fs.renameSync(temporary, target);
|
|
57
|
+
}
|
|
58
|
+
installed = true;
|
|
59
|
+
fsyncDirectory(directory);
|
|
60
|
+
if (backup) {
|
|
61
|
+
try {
|
|
62
|
+
fs.rmSync(backup, { force: true });
|
|
63
|
+
backup = '';
|
|
64
|
+
fsyncDirectory(directory);
|
|
65
|
+
} catch {}
|
|
66
|
+
}
|
|
67
|
+
return { target, replaced: Boolean(before) };
|
|
68
|
+
} finally {
|
|
69
|
+
fs.rmSync(temporary, { force: true });
|
|
70
|
+
if (installed && backup) {
|
|
71
|
+
try {
|
|
72
|
+
fs.rmSync(backup, { force: true });
|
|
73
|
+
} catch {}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function executableSnapshot(filePath) {
|
|
79
|
+
let stat;
|
|
80
|
+
try {
|
|
81
|
+
stat = fs.lstatSync(filePath);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (error?.code === 'ENOENT') return null;
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
87
|
+
throw new Error('Installed JoripSpace CLI target must be a regular file.');
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
dev: stat.dev,
|
|
91
|
+
ino: stat.ino,
|
|
92
|
+
size: stat.size,
|
|
93
|
+
mtimeMs: stat.mtimeMs,
|
|
94
|
+
sha256: crypto.createHash('sha256').update(fs.readFileSync(filePath)).digest('hex'),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function sameSnapshot(left, right) {
|
|
99
|
+
if (!left || !right) return left === right;
|
|
100
|
+
return (
|
|
101
|
+
left.dev === right.dev &&
|
|
102
|
+
left.ino === right.ino &&
|
|
103
|
+
left.size === right.size &&
|
|
104
|
+
left.mtimeMs === right.mtimeMs &&
|
|
105
|
+
left.sha256 === right.sha256
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function fsyncFile(filePath) {
|
|
110
|
+
const descriptor = fs.openSync(filePath, 'r+');
|
|
111
|
+
try {
|
|
112
|
+
fs.fsyncSync(descriptor);
|
|
113
|
+
} finally {
|
|
114
|
+
fs.closeSync(descriptor);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function fsyncDirectory(directory) {
|
|
119
|
+
let descriptor;
|
|
120
|
+
try {
|
|
121
|
+
descriptor = fs.openSync(directory, 'r');
|
|
122
|
+
fs.fsyncSync(descriptor);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (!['EINVAL', 'ENOTSUP', 'EISDIR', 'EPERM'].includes(error?.code)) throw error;
|
|
125
|
+
} finally {
|
|
126
|
+
if (descriptor !== undefined) fs.closeSync(descriptor);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function messageOf(error) {
|
|
131
|
+
return error instanceof Error ? error.message : String(error);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = { installExecutableAtomically };
|