@eliceio/cdk-cli 0.1.0-alpha.2 → 0.1.0-alpha.4
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 +263 -191
- package/es/cli.js +93 -33
- package/es/commands/build/index.d.ts +1 -1
- package/es/commands/build/index.js +21 -12
- package/es/commands/check/index.d.ts +11 -2
- package/es/commands/check/index.js +51 -5
- package/es/commands/create/index.d.ts +6 -0
- package/es/commands/create/index.js +56 -8
- package/es/commands/create/install.d.ts +17 -0
- package/es/commands/create/install.js +53 -0
- package/es/commands/create/scaffold.d.ts +6 -1
- package/es/commands/create/scaffold.js +27 -17
- package/es/commands/dev/index.d.ts +1 -1
- package/es/commands/dev/index.js +6 -2
- package/es/commands/doctor/index.d.ts +21 -0
- package/es/commands/doctor/index.js +255 -38
- package/es/commands/mcp/index.d.ts +134 -0
- package/es/commands/mcp/index.js +399 -0
- package/es/commands/setup/index.d.ts +40 -0
- package/es/commands/setup/index.js +157 -0
- package/es/commands/skill/index.d.ts +2 -5
- package/es/commands/skill/index.js +1 -29
- package/es/core/collect.d.ts +5 -2
- package/es/core/config.d.ts +141 -31
- package/es/core/config.js +341 -59
- package/es/core/manifest.d.ts +2 -1
- package/es/core/manifest.js +2 -1
- package/es/core/minify.js +2 -2
- package/es/core/prepare.d.ts +18 -2
- package/es/core/prepare.js +47 -18
- package/es/core/project-check.d.ts +26 -0
- package/es/core/project-check.js +53 -0
- package/es/core/sandbox.js +2 -2
- package/es/core/sdk.d.ts +39 -0
- package/es/core/sdk.js +95 -0
- package/es/core/templates.d.ts +25 -0
- package/es/core/templates.js +41 -0
- package/es/dev/grading.d.ts +14 -7
- package/es/dev/grading.js +27 -13
- package/es/dev/host-page.d.ts +1 -1
- package/es/dev/host-page.js +34 -34
- package/es/dev/mock-api.d.ts +19 -4
- package/es/dev/mock-api.js +75 -9
- package/es/dev/server.d.ts +7 -0
- package/es/dev/server.js +112 -32
- package/es/rules/check.js +95 -10
- package/es/rules/index.d.ts +1 -1
- package/es/rules/index.js +1 -1
- package/es/rules/manifest.d.ts +23 -9
- package/es/rules/manifest.js +60 -35
- package/es/rules/node.js +3 -1
- package/es/rules/semver.d.ts +5 -0
- package/es/rules/semver.js +32 -0
- package/es/rules/types.d.ts +38 -7
- package/es/rules.json.js +2 -2
- package/es/test-packages.d.ts +7 -0
- package/guides/content-development.md +150 -55
- package/package.json +3 -3
- package/rules.json +77 -7
- package/skills/_shared/always.md +4 -2
- package/skills/elice-content-check/SKILL.md +3 -1
- package/skills/elice-content-create/SKILL.md +5 -4
- package/skills/elice-content-migrate/SKILL.md +2 -2
- package/skills/elice-content-publish/SKILL.md +23 -0
- package/templates/_shared/lib/cdk-mock.d.ts +21 -3
- package/templates/_shared/lib/cdk-mock.js +241 -82
- package/templates/_shared/lib/elice-content.css +204 -0
- package/templates/_shared/lib/elice-content.d.ts +115 -6
- package/templates/_shared/lib/elice-content.js +656 -43
- package/templates/blank/README.md +19 -7
- package/templates/blank/completion.html +15 -0
- package/templates/blank/gitignore +1 -0
- package/templates/blank/metadata.json +11 -0
- package/templates/blank/package.json +13 -0
- package/templates/blank/screens/completion.js +7 -0
- package/templates/blank/screens/edit.js +3 -0
- package/templates/blank/screens/instructor.js +12 -5
- package/templates/blank/screens/learn.js +16 -11
- package/templates/blank/template.json +6 -0
- package/templates/quiz/README.md +41 -31
- package/templates/quiz/core/behaviors.d.ts +5 -0
- package/templates/quiz/core/behaviors.js +12 -0
- package/templates/quiz/core/editor.d.ts +12 -1
- package/templates/quiz/core/editor.js +28 -5
- package/templates/quiz/core/model.d.ts +41 -1
- package/templates/quiz/core/model.js +272 -5
- package/templates/quiz/gitignore +1 -0
- package/templates/quiz/metadata.json +11 -0
- package/templates/quiz/package.json +13 -0
- package/templates/quiz/screens/edit.js +176 -46
- package/templates/quiz/screens/instructor.js +18 -12
- package/templates/quiz/screens/learn.js +43 -38
- package/templates/quiz/styles.css +47 -0
- package/templates/quiz/template.json +6 -0
- package/templates/quiz/ui/templates/edit.d.ts +3 -0
- package/templates/quiz/ui/templates/edit.js +53 -14
- package/templates/quiz/ui/texts.js +56 -29
- package/templates/_shared/lib/cdk.js +0 -3
- package/templates/blank/content.json +0 -4
- package/templates/blank/elice.config.json +0 -12
- package/templates/quiz/content.json +0 -81
- package/templates/quiz/elice.config.json +0 -14
- package/templates/quiz/grading.json +0 -13
package/es/dev/mock-api.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { COMPLETION_POLICIES, parseGrading } from '../core/config.js';
|
|
1
2
|
import { grade } from './grading.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -20,6 +21,10 @@ const TOKEN_SCENARIOS = Object.freeze({
|
|
|
20
21
|
scope: 'edit',
|
|
21
22
|
viewer: 'instructor'
|
|
22
23
|
},
|
|
24
|
+
completionPolicy: {
|
|
25
|
+
scope: 'edit',
|
|
26
|
+
viewer: 'instructor'
|
|
27
|
+
},
|
|
23
28
|
instructor: {
|
|
24
29
|
scope: 'learn',
|
|
25
30
|
viewer: 'instructor'
|
|
@@ -74,6 +79,7 @@ function readClaims(req) {
|
|
|
74
79
|
}
|
|
75
80
|
const createState = () => ({
|
|
76
81
|
settings: {},
|
|
82
|
+
version: 1,
|
|
77
83
|
submissions: [],
|
|
78
84
|
results: new Map(),
|
|
79
85
|
recent: new Map()
|
|
@@ -163,6 +169,15 @@ async function handleMockApi(req, res, path, opts) {
|
|
|
163
169
|
if (m[1] !== claims.material_id) return fail(res, 403, 'AUTH_PERMISSION_DENIED', 'material mismatch');
|
|
164
170
|
const sub = m[2] ?? '';
|
|
165
171
|
const subject = claims.account_id;
|
|
172
|
+
// 서버처럼 학생 · 튜터 · 교육자(learn scope)에게는 settings.grading(정답)을 빼고, edit 범위에는 그대로 준다
|
|
173
|
+
const withGrading = settings => {
|
|
174
|
+
if (claims.scope === 'edit') return settings;
|
|
175
|
+
const {
|
|
176
|
+
grading: _ignored,
|
|
177
|
+
...rest
|
|
178
|
+
} = settings;
|
|
179
|
+
return rest;
|
|
180
|
+
};
|
|
166
181
|
const material = settings => ({
|
|
167
182
|
id: DEV_MATERIAL_ID,
|
|
168
183
|
lecture_page_id: 1,
|
|
@@ -172,39 +187,90 @@ async function handleMockApi(req, res, path, opts) {
|
|
|
172
187
|
text: ''
|
|
173
188
|
},
|
|
174
189
|
current_version: {
|
|
175
|
-
id:
|
|
190
|
+
id: `dev-${state.version}`,
|
|
176
191
|
content_urls: {},
|
|
192
|
+
// Like the server: metadata.json as is, with each enabled screen under `screens`.
|
|
177
193
|
metadata: {
|
|
178
|
-
|
|
194
|
+
kind: 'material',
|
|
195
|
+
screens: Object.fromEntries(Object.entries(opts.getEntries()).map(([screen, entry]) => [screen, {
|
|
196
|
+
entry,
|
|
197
|
+
enabled: true
|
|
198
|
+
}])),
|
|
199
|
+
completionPolicies: opts.getCompletionPolicies?.() ?? []
|
|
179
200
|
},
|
|
180
201
|
file_tree: [],
|
|
181
|
-
settings
|
|
202
|
+
settings: withGrading(settings),
|
|
203
|
+
completion_policy: opts.getGrading()?.completion_policy ?? 'on_access'
|
|
182
204
|
}
|
|
183
205
|
});
|
|
184
206
|
if (method === 'GET' && sub === '') return send(res, 200, material(state.settings));
|
|
185
|
-
// 편집
|
|
207
|
+
// 편집 화면의 saveSettings · 완료 정책 화면의 saveCompletionPolicy: edit 토큰으로 지금 버전을 바로 고침.
|
|
208
|
+
// 기준 버전이 다르면 409 (그 사이 다른 저장)
|
|
186
209
|
if (method === 'PATCH' && sub === '') {
|
|
187
210
|
if (claims.scope !== 'edit') return fail(res, 403, 'AUTH_PERMISSION_DENIED', 'settings only with an edit token');
|
|
188
211
|
const {
|
|
189
212
|
json
|
|
190
213
|
} = await body(req);
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
214
|
+
const request = json;
|
|
215
|
+
const settings = request?.settings;
|
|
216
|
+
const rawPolicy = request?.completion_policy;
|
|
217
|
+
if (settings === undefined && rawPolicy === undefined) return fail(res, 400, 'INVALID_INPUT', 'empty_patch');
|
|
218
|
+
if (settings !== undefined && (!settings || typeof settings !== 'object')) return fail(res, 400, 'INVALID_INPUT', 'settings must be an object');
|
|
219
|
+
if (rawPolicy !== undefined && !COMPLETION_POLICIES.includes(rawPolicy)) return fail(res, 400, 'INVALID_INPUT', `unknown completion_policy: ${JSON.stringify(rawPolicy)}`);
|
|
220
|
+
const policy = rawPolicy;
|
|
221
|
+
const expected = request?.expected_current_version_id;
|
|
222
|
+
if (expected != null && expected !== `dev-${state.version}`) return fail(res, 409, 'MATERIAL_CHANGED', `current version is dev-${state.version}`);
|
|
223
|
+
if (policy !== undefined) {
|
|
224
|
+
// 서버는 enum만 본다. dev는 metadata completionPolicies 밖의 값도 알려 준다 (완료 정책 화면은 그 안에서만 고름)
|
|
225
|
+
const allowed = opts.getCompletionPolicies?.() ?? [];
|
|
226
|
+
if (allowed.length > 0 && !allowed.includes(policy)) return fail(res, 400, 'INVALID_INPUT', `completion_policy ${policy} is not in metadata completionPolicies (${allowed.join(', ')})`);
|
|
227
|
+
// 서버처럼 채점 설정이 없는 on_graded는 거절 (편집 화면에서 답을 먼저 저장)
|
|
228
|
+
if (policy === 'on_graded' && !state.settings.grading) return fail(res, 422, 'MATERIAL_GRADING_REQUIRED', 'on_graded needs settings.grading');
|
|
229
|
+
}
|
|
230
|
+
// 편집 화면이 보낸 settings는 통째로 .ecdk/settings.json으로 (dev 전용 저장 위치). grading이 없으면 저장된 채점 설정은 그대로
|
|
231
|
+
if (settings !== undefined) {
|
|
232
|
+
const {
|
|
233
|
+
grading,
|
|
234
|
+
...rest
|
|
235
|
+
} = settings;
|
|
236
|
+
let next = rest;
|
|
237
|
+
if (grading !== undefined && grading !== null) {
|
|
238
|
+
const parsed = parseGrading(grading);
|
|
239
|
+
if (typeof parsed === 'string') return fail(res, 400, 'INVALID_INPUT', `grading: ${parsed}`);
|
|
240
|
+
next = {
|
|
241
|
+
...rest,
|
|
242
|
+
grading: parsed
|
|
243
|
+
};
|
|
244
|
+
} else if (state.settings.grading !== undefined) next = {
|
|
245
|
+
...rest,
|
|
246
|
+
grading: state.settings.grading
|
|
247
|
+
};
|
|
248
|
+
state.settings = next;
|
|
249
|
+
await opts.saveSettings?.(next);
|
|
250
|
+
log(`내용을 .ecdk/settings.json에 저장했습니다${next.grading ? ` (채점 설정 ${next.grading.type})` : ''}`);
|
|
251
|
+
}
|
|
252
|
+
if (policy !== undefined) {
|
|
253
|
+
await opts.saveCompletionPolicy?.(policy);
|
|
254
|
+
log(`완료 정책을 .ecdk/completion.json에 저장했습니다 (${policy})`);
|
|
255
|
+
}
|
|
256
|
+
state.version += 1;
|
|
257
|
+
log(`자료를 저장했습니다 (${settings !== undefined ? 'settings' : 'completion_policy'}, 버전 dev-${state.version})`);
|
|
195
258
|
return send(res, 200, material(state.settings));
|
|
196
259
|
}
|
|
197
260
|
if (method === 'GET' && sub === '/me') {
|
|
198
261
|
const user = claims.viewer === 'instructor' ? MANAGER : STUDENT;
|
|
199
|
-
if (claims.scope === 'learn' && claims.viewer === 'student' && opts.getGrading()?.
|
|
262
|
+
if (claims.scope === 'learn' && claims.viewer === 'student' && opts.getGrading()?.completion_policy === 'on_access' && !state.results.has(subject)) {
|
|
200
263
|
record(state, subject, {
|
|
201
264
|
score: 100
|
|
202
265
|
}, true);
|
|
203
266
|
log('열람 완료로 100점 (on_access)');
|
|
204
267
|
}
|
|
268
|
+
const local = opts.getGrading();
|
|
205
269
|
return send(res, 200, {
|
|
206
270
|
scope: claims.scope,
|
|
207
271
|
viewer: claims.viewer,
|
|
272
|
+
completion_policy: local?.completion_policy ?? 'on_access',
|
|
273
|
+
grading_type: local?.completion_policy === 'on_graded' ? local.grading?.type ?? null : null,
|
|
208
274
|
user: {
|
|
209
275
|
anonymous_id: user.anonymous_id,
|
|
210
276
|
fullname: user.fullname
|
package/es/dev/server.d.ts
CHANGED
|
@@ -15,6 +15,13 @@ export interface DevServer {
|
|
|
15
15
|
reload(): Promise<void>;
|
|
16
16
|
close(): Promise<void>;
|
|
17
17
|
}
|
|
18
|
+
/** 포트가 이미 쓰일 때: 어느 포트(호스트 · 콘텐츠)인지 알린다 */
|
|
19
|
+
export declare class DevPortError extends Error {
|
|
20
|
+
readonly port: number;
|
|
21
|
+
readonly role: 'host' | 'content';
|
|
22
|
+
readonly code = "EADDRINUSE";
|
|
23
|
+
constructor(port: number, role: 'host' | 'content');
|
|
24
|
+
}
|
|
18
25
|
/**
|
|
19
26
|
* 로컬에서 운영과 같은 조건으로 콘텐츠를 띄운다.
|
|
20
27
|
* - 호스트(localhost): LXP 흉내 화면 + elice-material 흉내 API(/api) + 콘솔 수집
|
package/es/dev/server.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { watch } from 'node:fs';
|
|
2
|
+
import { rm, mkdir, writeFile } from 'node:fs/promises';
|
|
2
3
|
import { createServer } from 'node:http';
|
|
3
|
-
import { resolve, extname, basename, relative, sep } from 'node:path';
|
|
4
|
-
import { loadConfig,
|
|
4
|
+
import { resolve, extname, join, basename, relative, sep, dirname } from 'node:path';
|
|
5
|
+
import { loadConfig, loadSavedSettings, savedGrading, loadCompletionPolicy, SETTINGS_DATA_FILE, PACKAGE_FILE, CONFIG_FILE, COMPLETION_DATA_FILE } from '../core/config.js';
|
|
5
6
|
import { prepareContent } from '../core/prepare.js';
|
|
7
|
+
import { projectCheckOptions } from '../core/project-check.js';
|
|
6
8
|
import { inlineModuleScripts } from '../core/sandbox.js';
|
|
9
|
+
import { missingSdkMessage } from '../core/sdk.js';
|
|
7
10
|
import { checkFiles } from '../rules/check.js';
|
|
8
11
|
import '../rules/spec.js';
|
|
9
12
|
import 'fflate';
|
|
@@ -49,6 +52,20 @@ function summarize(check) {
|
|
|
49
52
|
if (check.issues.length > 5) lines.push(` … 외 ${check.issues.length - 5}개 (ecdk check로 전체 보기)`);
|
|
50
53
|
return [head, ...lines].join('\n');
|
|
51
54
|
}
|
|
55
|
+
/** 포트가 이미 쓰일 때: 어느 포트(호스트 · 콘텐츠)인지 알린다 */
|
|
56
|
+
class DevPortError extends Error {
|
|
57
|
+
port;
|
|
58
|
+
role;
|
|
59
|
+
code = 'EADDRINUSE';
|
|
60
|
+
constructor(port, role) {
|
|
61
|
+
super(role === 'host' ? `ecdk dev 화면 포트 ${port}이(가) 이미 쓰이고 있습니다.` : `콘텐츠 서버 포트 ${port}(화면 포트 + 1)이(가) 이미 쓰이고 있습니다.`);
|
|
62
|
+
this.port = port;
|
|
63
|
+
this.role = role;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** --port 없이 열 때 기본 포트 쌍이 막혀 있으면 다음 쌍(+2)을 이만큼 더 시도한다 */
|
|
67
|
+
const DEFAULT_PORT = 4170;
|
|
68
|
+
const AUTO_PORT_TRIES = 10;
|
|
52
69
|
const listen = (server, port) => new Promise((ok, fail) => {
|
|
53
70
|
server.once('error', fail);
|
|
54
71
|
server.listen(port, '127.0.0.1', () => ok(server.address().port));
|
|
@@ -76,14 +93,48 @@ async function startDevServer(opts) {
|
|
|
76
93
|
const dir = resolve(opts.dir);
|
|
77
94
|
const log = opts.log ?? (l => process.stdout.write(`${l}\n`));
|
|
78
95
|
let config = await loadConfig(dir);
|
|
79
|
-
let grading = await loadGrading(dir, config);
|
|
80
|
-
let prepared = await prepareContent(dir, config);
|
|
81
|
-
let files = await servedFiles(prepared, log);
|
|
82
|
-
let check = checkFiles(prepared.files, {
|
|
83
|
-
input: 'zip',
|
|
84
|
-
bundlesModules: true
|
|
85
|
-
});
|
|
86
96
|
const state = createState();
|
|
97
|
+
// 편집 화면이 저장한 settings(내용 + grading)는 .ecdk/settings.json에 남겨 dev를 다시 열어도 그대로 (운영은 서버 settings)
|
|
98
|
+
state.settings = await loadSavedSettings(dir);
|
|
99
|
+
savedGrading(state.settings); // grading 형식이 틀리면 시작할 때 알린다
|
|
100
|
+
let policy = await loadCompletionPolicy(dir, config);
|
|
101
|
+
/** 로컬 채점 흉내: 완료 정책 + 저장한 settings.grading. 문제 설명은 채점 없음 */
|
|
102
|
+
const localGrading = () => config.kind === 'description' ? undefined : {
|
|
103
|
+
completion_policy: policy,
|
|
104
|
+
grading: savedGrading(state.settings)
|
|
105
|
+
};
|
|
106
|
+
async function writeJson(file, data) {
|
|
107
|
+
const path = join(dir, file);
|
|
108
|
+
await mkdir(dirname(path), {
|
|
109
|
+
recursive: true
|
|
110
|
+
});
|
|
111
|
+
await writeFile(path, `${JSON.stringify(data, null, 2)}\n`);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 편집 화면의 saveSettings(PATCH settings)를 흉내 서버가 받으면 settings 전체(내용 + grading)를 `.ecdk/settings.json`에 쓴다
|
|
115
|
+
* (운영은 material_version.settings). 값 검사는 흉내 서버가 한다. 점(.) 폴더라 감시 · zip에서 빠진다
|
|
116
|
+
*/
|
|
117
|
+
const saveSettings = settings => writeJson(SETTINGS_DATA_FILE, settings);
|
|
118
|
+
/**
|
|
119
|
+
* 완료 정책 화면의 saveCompletionPolicy(PATCH completion_policy)를 흉내 서버가 받으면 `.ecdk/completion.json`에 쓴다
|
|
120
|
+
* (운영은 material_version.completion_policy). 값 검사는 흉내 서버가 한다
|
|
121
|
+
*/
|
|
122
|
+
async function saveCompletionPolicy(next) {
|
|
123
|
+
await writeJson(COMPLETION_DATA_FILE, {
|
|
124
|
+
completion_policy: next
|
|
125
|
+
});
|
|
126
|
+
policy = await loadCompletionPolicy(dir, config);
|
|
127
|
+
}
|
|
128
|
+
// SDK를 설치하기 전에도 mock으로는 열린다 (실제 SDK 모드 ?sdk=real만 lib/cdk.js가 없어 실패, 아래에서 알림)
|
|
129
|
+
let prepared = await prepareContent(dir, config, {
|
|
130
|
+
requireSdk: false
|
|
131
|
+
});
|
|
132
|
+
const warnSdk = () => {
|
|
133
|
+
if (prepared.sdk.missing) log(`[dev] ${missingSdkMessage()} 그 전에는 mock SDK로만 열립니다 (?sdk=real은 lib/cdk.js가 없어 실패).`);
|
|
134
|
+
};
|
|
135
|
+
warnSdk();
|
|
136
|
+
let files = await servedFiles(prepared, log);
|
|
137
|
+
let check = checkFiles(prepared.files, await projectCheckOptions(dir, config));
|
|
87
138
|
const clients = new Set();
|
|
88
139
|
let hostOrigin = '';
|
|
89
140
|
let contentOrigin = '';
|
|
@@ -151,22 +202,30 @@ async function startDevServer(opts) {
|
|
|
151
202
|
for (const [k, v] of Object.entries(cors)) res.setHeader(k, v);
|
|
152
203
|
await handleMockApi(req, res, url.pathname.slice(4), {
|
|
153
204
|
state,
|
|
154
|
-
getGrading:
|
|
205
|
+
getGrading: localGrading,
|
|
206
|
+
saveSettings,
|
|
155
207
|
getEntries: entries,
|
|
208
|
+
getCompletionPolicies: () => check.manifest?.completionPolicies ?? [],
|
|
209
|
+
saveCompletionPolicy,
|
|
156
210
|
onEvent: m => log(`[api] ${m}`)
|
|
157
211
|
});
|
|
158
212
|
return;
|
|
159
213
|
}
|
|
160
|
-
// 콘텐츠 주소를 직접 열어 mock으로 돌 때:
|
|
214
|
+
// 콘텐츠 주소를 직접 열어 mock으로 돌 때: .ecdk(저장한 settings · 완료 정책)는 zip에 없어 콘텐츠 서버가 주지 않으므로
|
|
161
215
|
// 흉내 서버가 채점에 쓰는 것과 같은 로컬 채점 설정을 여기서 준다 (dev 전용)
|
|
162
|
-
// CORS *로 둔다: ecdk dev는 작성자 PC에서만 돌고 내주는 값도 작성자
|
|
216
|
+
// CORS *로 둔다: ecdk dev는 작성자 PC에서만 돌고 내주는 값도 작성자 본인이 저장한 답이라, 막아도 지킬 대상이 없다
|
|
163
217
|
// (실행마다 열쇠를 두는 방식은 콘텐츠 주소가 예측 가능해 열쇠까지 읽혀 효과가 없어서 되돌림, !19 리뷰)
|
|
164
218
|
if (url.pathname === '/__ecdk/grading') {
|
|
165
219
|
res.writeHead(200, {
|
|
166
220
|
...cors,
|
|
167
221
|
'Content-Type': 'application/json; charset=utf-8'
|
|
168
222
|
});
|
|
169
|
-
|
|
223
|
+
// { completion_policy, grading, completion_policies }: 콘텐츠를 직접 연 mock이 로컬 채점 · 완료 정책 흉내에 쓴다
|
|
224
|
+
const local = localGrading();
|
|
225
|
+
res.end(JSON.stringify(local ? {
|
|
226
|
+
...local,
|
|
227
|
+
completion_policies: check.manifest?.completionPolicies ?? []
|
|
228
|
+
} : null));
|
|
170
229
|
return;
|
|
171
230
|
}
|
|
172
231
|
if (url.pathname === '/favicon.ico') {
|
|
@@ -206,7 +265,10 @@ async function startDevServer(opts) {
|
|
|
206
265
|
}
|
|
207
266
|
if (url.pathname === '/__ecdk/reset' && req.method === 'POST') {
|
|
208
267
|
Object.assign(state, createState());
|
|
209
|
-
|
|
268
|
+
await rm(join(dir, SETTINGS_DATA_FILE), {
|
|
269
|
+
force: true
|
|
270
|
+
});
|
|
271
|
+
log(`[api] 저장 내용(${SETTINGS_DATA_FILE})과 제출 기록을 지웠습니다`);
|
|
210
272
|
res.writeHead(204).end();
|
|
211
273
|
return;
|
|
212
274
|
}
|
|
@@ -237,28 +299,46 @@ async function startDevServer(opts) {
|
|
|
237
299
|
if (!res.headersSent) res.writeHead(500).end('dev server error');
|
|
238
300
|
}
|
|
239
301
|
});
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
let
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
302
|
+
// 화면(N)과 콘텐츠(N+1) 두 포트를 쓴다. --port를 주지 않았으면 막힌 쌍을 건너뛰어 다음 쌍을 쓴다
|
|
303
|
+
const tries = opts.port === undefined ? AUTO_PORT_TRIES : 1;
|
|
304
|
+
let hostPort = 0;
|
|
305
|
+
let contentPort = 0;
|
|
306
|
+
for (let i = 0; i < tries; i++) {
|
|
307
|
+
const base = (opts.port ?? DEFAULT_PORT) + i * 2;
|
|
308
|
+
try {
|
|
309
|
+
hostPort = await listen(host, base);
|
|
310
|
+
} catch (e) {
|
|
311
|
+
if (e.code !== 'EADDRINUSE' || base === 0) throw e;
|
|
312
|
+
if (i === tries - 1) throw new DevPortError(base, 'host');
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
try {
|
|
316
|
+
contentPort = await listen(content, base === 0 ? 0 : hostPort + 1);
|
|
317
|
+
break;
|
|
318
|
+
} catch (e) {
|
|
319
|
+
// 콘텐츠 포트가 막히면 열어 둔 호스트도 닫아야 다음 쌍을 열거나 프로세스가 끝난다
|
|
320
|
+
await new Promise(r => host.close(r));
|
|
321
|
+
if (e.code !== 'EADDRINUSE') throw e;
|
|
322
|
+
if (i === tries - 1) throw new DevPortError(hostPort + 1, 'content');
|
|
323
|
+
}
|
|
249
324
|
}
|
|
325
|
+
if (opts.port === undefined && hostPort !== DEFAULT_PORT) log(`[dev] 기본 포트 ${DEFAULT_PORT} · ${DEFAULT_PORT + 1}이 쓰이고 있어 ${hostPort} · ${contentPort}로 열었습니다.`);
|
|
250
326
|
hostOrigin = `http://localhost:${hostPort}`;
|
|
251
327
|
contentOrigin = `http://127.0.0.1:${contentPort}`;
|
|
252
328
|
async function reload() {
|
|
253
329
|
try {
|
|
254
330
|
config = await loadConfig(dir);
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
331
|
+
policy = await loadCompletionPolicy(dir, config);
|
|
332
|
+
// 손으로 고친 .ecdk/settings.json도 다시 읽는다 (편집 화면 저장은 흉내 서버가 이미 state에 넣음)
|
|
333
|
+
const saved = await loadSavedSettings(dir);
|
|
334
|
+
savedGrading(saved);
|
|
335
|
+
state.settings = saved;
|
|
336
|
+
prepared = await prepareContent(dir, config, {
|
|
337
|
+
requireSdk: false
|
|
261
338
|
});
|
|
339
|
+
warnSdk();
|
|
340
|
+
files = await servedFiles(prepared, log);
|
|
341
|
+
check = checkFiles(prepared.files, await projectCheckOptions(dir, config));
|
|
262
342
|
log(summarize(check));
|
|
263
343
|
const payload = JSON.stringify(snapshot());
|
|
264
344
|
for (const c of clients) c.write(`event: reload\ndata: ${payload}\n\n`);
|
|
@@ -282,9 +362,9 @@ async function startDevServer(opts) {
|
|
|
282
362
|
} catch {
|
|
283
363
|
log('[dev] 이 환경에서는 파일 감시를 못 합니다. 고친 뒤 새로고침하세요.');
|
|
284
364
|
}
|
|
285
|
-
// 프로젝트
|
|
365
|
+
// 프로젝트 맨 위의 설정 파일(원본 폴더 밖일 수 있음): package.json "ecdk" · 옛 elice.config.json
|
|
286
366
|
const configWatcher = prepared.srcDir === dir ? null : watch(dir, (_e, name) => {
|
|
287
|
-
if (name ===
|
|
367
|
+
if (name === PACKAGE_FILE || name === CONFIG_FILE) void reload();
|
|
288
368
|
});
|
|
289
369
|
log(summarize(check));
|
|
290
370
|
return {
|
|
@@ -306,4 +386,4 @@ async function startDevServer(opts) {
|
|
|
306
386
|
};
|
|
307
387
|
}
|
|
308
388
|
|
|
309
|
-
export { CONTENT_PREFIX, startDevServer };
|
|
389
|
+
export { CONTENT_PREFIX, DevPortError, startDevServer };
|
package/es/rules/check.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { zipSync } from 'fflate';
|
|
2
|
-
import { parseManifest } from './manifest.js';
|
|
2
|
+
import { parseManifest, COMPLETION_POLICIES_EXAMPLE } from './manifest.js';
|
|
3
3
|
import { isUnsafePath, extname, globToRegExp, resolveRef } from './path.js';
|
|
4
4
|
import { lineAt, parseTags, extractRefs, classifyRef } from './refs.js';
|
|
5
|
+
import { compareVersions } from './semver.js';
|
|
5
6
|
import { lineSkipper } from './skip.js';
|
|
6
7
|
import { rules } from './spec.js';
|
|
7
8
|
|
|
@@ -51,9 +52,9 @@ function answerKeyPath(value, path = []) {
|
|
|
51
52
|
return null;
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
|
-
* 화면 코드가
|
|
55
|
-
*
|
|
56
|
-
* 편집 화면인데 저장이 없으면
|
|
55
|
+
* 화면 코드가 완료 정책 · 편집 화면과 맞는지 (ADR 0009, 키트 lib/는 빼고 콘텐츠 코드에서 함수 이름을 찾는 방식이라 경고만).
|
|
56
|
+
* 제출 · 채점으로 완료할 수 있는데 제출이 없으면 학생이 완료할 수 없고, 채점(on_graded)인데 편집 화면이 채점 설정을
|
|
57
|
+
* 저장하지 않으면 답을 정할 곳이 없고, 편집 · 완료 정책 화면인데 저장이 없으면 바꾼 내용이 LXP로 넘어가지 않는다.
|
|
57
58
|
*/
|
|
58
59
|
function checkScreenCode(files, manifest, add) {
|
|
59
60
|
const decoder = new TextDecoder();
|
|
@@ -62,10 +63,87 @@ function checkScreenCode(files, manifest, add) {
|
|
|
62
63
|
// 이런 zip은 판단하지 않는다: build가 묶기 전 원본으로 이미 검사했다
|
|
63
64
|
if (texts.some(t => /<script\b[^>]*\sdata-ecdk-bundle\b/i.test(t))) return;
|
|
64
65
|
const code = texts.join('\n');
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
// completionPolicies 안에 제출 · 채점이 있으면 (첫 값이든 완료 정책 화면에서 고를 수 있는 값이든) 제출이 있어야 한다
|
|
67
|
+
const policies = manifest.completionPolicies ?? [];
|
|
68
|
+
const submitting = policies.filter(p => p !== 'on_access');
|
|
69
|
+
if (submitting.length > 0 && !/\buseSubmit\b|\.submit\s*\(/.test(code)) add('completion.no-submit', `completionPolicies에 ${submitting.join(' · ')}가 있는데 화면 코드에 제출(app.useSubmit · sdk.submit)이 없습니다. 그 정책이면 학생이 완료할 수 없습니다. 제출을 넣거나 completionPolicies를 ["on_access"]로 바꿔 주세요.`);
|
|
70
|
+
// 채점 방식 · 답은 편집 화면이 settings.grading으로 저장한다. 주석은 빼고 본다 (blank 템플릿 주석에 예시가 있음)
|
|
71
|
+
const uncommented = code.replace(/\/\*[\s\S]*?\*\/|(^|[^:])\/\/.*$/gm, '$1');
|
|
72
|
+
if (policies.includes('on_graded') && manifest.entries.edit && !/\buseGradingBlock\b|\bgetGrading\b|\bgrading\s*:/.test(uncommented)) add('completion.no-grading', `completionPolicies에 채점해 완료(on_graded)가 있는데 편집 화면 코드가 채점 설정을 저장하지 않습니다. app.useGradingBlock()을 붙이고 useSave({ getGrading })에 넘겨 주세요 (퀴즈처럼 문항이 있으면 문항별 정답으로 { type: 'pattern', answer_key }를 만듦, ecdk guide 5).`);
|
|
73
|
+
const screen = manifest.entries.completionPolicy;
|
|
74
|
+
if (screen && !/\buseCompletion\b|\bsaveCompletionPolicy\s*\(/.test(code)) add('completion.no-save', `완료 정책 화면(${screen})을 켰는데 저장(app.useCompletion · sdk.saveCompletionPolicy)이 없습니다. 교육자가 고른 완료 정책이 저장되지 않습니다.`);
|
|
67
75
|
if (manifest.entries.edit && !/\buseSave\b|\bsaveSettings\s*\(|\bsaveContent\s*\(/.test(code)) add('edit.no-save', `편집 화면(${manifest.entries.edit})을 켰는데 저장(app.useSave · sdk.saveSettings)이 없습니다. 편집한 내용이 LXP로 넘어가지 않습니다.`);
|
|
68
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* metadata.json build.template("quiz@1.0.0")이 이 CLI가 아는 템플릿 · 버전인지. 모르는 이름이거나 더 새 버전이면
|
|
79
|
+
* 이 CLI의 검사 · 가이드가 그 템플릿을 모를 수 있다 (경고만, 옛 zip · 템플릿 없이 만든 zip은 build.template이 없음)
|
|
80
|
+
*/
|
|
81
|
+
function checkTemplate(manifest, opts, add) {
|
|
82
|
+
const ref = manifest.build?.template;
|
|
83
|
+
if (!ref || !opts.templates) return;
|
|
84
|
+
const at = ref.lastIndexOf('@');
|
|
85
|
+
const name = at > 0 ? ref.slice(0, at) : ref;
|
|
86
|
+
const version = at > 0 ? ref.slice(at + 1) : undefined;
|
|
87
|
+
const known = opts.templates[name];
|
|
88
|
+
if (known === undefined) {
|
|
89
|
+
add(`이 ecdk가 모르는 템플릿입니다: ${ref} (아는 템플릿: ${Object.entries(opts.templates).map(([n, v]) => `${n}@${v}`).join(', ')}). ecdk를 올리거나(npm i -g @eliceio/cdk-cli) package.json "ecdk"의 template을 확인해 주세요.`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (version !== undefined && (compareVersions(version, known) ?? 0) > 0) add(`${ref}은 이 ecdk가 가진 ${name}@${known}보다 새 템플릿 버전입니다. 검사 · 가이드가 새 템플릿의 변경을 모를 수 있으니 ecdk를 올려 주세요.`);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 완료 정책 · 채점 설정 (ADR 0009 2026-11-11 결정 2). 자료 본문은 completionPolicies가 필수(서버가 첫 값으로 완료 정책을
|
|
96
|
+
* 정함)이고, 그 안에 채점해 완료(on_graded)가 있으면 채점 방식 · 답을 정할 편집 화면이 있어야 한다 (운영에서
|
|
97
|
+
* settings.grading은 편집 화면만 저장). 여럿이면 완료 정책 화면이 있어야 고를 수 있다.
|
|
98
|
+
*/
|
|
99
|
+
function checkCompletion(manifest, spec, add) {
|
|
100
|
+
if ((manifest.kind ?? spec.manifest.defaultKind) === 'description') return;
|
|
101
|
+
const policies = manifest.completionPolicies ?? [];
|
|
102
|
+
if (policies.length === 0) {
|
|
103
|
+
add('manifest.completion-policies-missing', `${spec.manifest.file}에 completionPolicies(이 자료가 지원하는 완료 정책)가 ${manifest.completionPolicies ? '비어 있습니다' : '없습니다'}. 서버가 첫 값으로 완료 정책을 정하므로 자료 본문에는 꼭 적습니다. ${COMPLETION_POLICIES_EXAMPLE}. ecdk 프로젝트는 원본의 metadata.json에 적습니다.`, spec.manifest.file);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const screen = manifest.entries.completionPolicy;
|
|
107
|
+
if (policies.length > 1 && !screen) add('completion.no-screen', `completionPolicies가 ${policies.join(' · ')}인데 완료 정책 화면(screens.completionPolicy)이 없어 첫 값(${policies[0]})만 쓰입니다. 교육자가 고르게 하려면 완료 정책 화면을 켜고(app.useCompletion), 아니면 ["${policies[0]}"] 하나만 적어 주세요.`, spec.manifest.file);
|
|
108
|
+
if (policies.length === 1 && screen) add('completion.screen-unused', `completionPolicies가 ${policies[0]} 하나(고정)인데 완료 정책 화면(${screen})이 켜져 있습니다. 고를 것이 없으니 화면을 끄거나 고를 정책을 더 적어 주세요.`, spec.manifest.file);
|
|
109
|
+
if (!policies.includes('on_graded')) return;
|
|
110
|
+
if (!manifest.entries.edit) add('completion.no-edit', `completionPolicies에 채점해 완료(on_graded)가 있는데 편집 화면이 없습니다. 채점 방식 · 답(settings.grading)은 편집 화면만 저장할 수 있어, 이대로면 LXP에서 정답을 정할 곳이 없습니다 (서버는 채점 설정 없는 on_graded를 MATERIAL_GRADING_REQUIRED로 거절). 편집 화면(screens.edit)을 켜거나 on_graded를 빼 주세요.`, spec.manifest.file);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 프로젝트에 남은 옛 파일 (ADR 0011, 프로젝트 검사만). 옮기는 법을 알려 준다. 내용 · 정답은 옮기지 않고
|
|
114
|
+
* 편집 화면에서 다시 넣는다
|
|
115
|
+
*/
|
|
116
|
+
const LEGACY_FILE_MESSAGES = {
|
|
117
|
+
'elice.config.json': 'elice.config.json은 더 쓰지 않습니다 (ADR 0011). 화면 · 완료 정책 · 학습 참고 내용(kind · screens · completionPolicies · commentary)은 원본의 metadata.json에, 빌드 옵션 · template은 package.json "ecdk"에 둡니다. ecdk doctor --fix가 옮기고 elice.config.json을 지웁니다 (옮기기 전까지는 지금처럼 빌드됨).',
|
|
118
|
+
'content.json': 'content.json은 더 쓰지 않습니다 (기본 내용 파일 없음, ADR 0011). 화면은 편집 화면이 저장한 내용만 읽고, 저장하기 전에는 "아직 내용이 없습니다" 안내를 보입니다. 그 내용은 LXP에 올린 뒤 편집 화면에서 다시 넣고 파일을 지워 주세요. 화면 코드가 직접 fetch하는 데이터 파일이면 다른 이름(예: data.json)으로 바꿔 주세요.',
|
|
119
|
+
'grading.json': "grading.json은 더 쓰지 않습니다 (ADR 0011). 채점 방식 · 답은 LXP에 올린 뒤 편집 화면에서 정합니다 (ecdk dev의 '내용 편집'에 넣은 답은 로컬 견본, .ecdk/settings.json). 파일은 지워 주세요 (zip에는 들어가지 않음)."
|
|
120
|
+
};
|
|
121
|
+
function checkLegacyFiles(opts, add) {
|
|
122
|
+
for (const path of opts.legacyFiles ?? []) {
|
|
123
|
+
const name = path.split('/').pop() ?? path;
|
|
124
|
+
add(LEGACY_FILE_MESSAGES[name] ?? `${path}은 더 쓰지 않는 파일입니다 (ADR 0011).`, path);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** SDK를 올리는 명령 (ADR 0010) */
|
|
128
|
+
const SDK_UPDATE_COMMAND = 'npm update @eliceio/cdk';
|
|
129
|
+
/**
|
|
130
|
+
* SDK 버전 (ADR 0010). metadata.json build.sdk가 rules.json minVersions.sdk보다 낮으면 오류:
|
|
131
|
+
* LXP 프로토콜과 맞지 않아 저장 · 제출이 안 될 수 있다. 옛 lib/cdk.js 복사본 프로젝트는 sdk.lib-copy 경고로 알린다
|
|
132
|
+
*/
|
|
133
|
+
function checkSdk(manifest, spec, opts, add) {
|
|
134
|
+
// 옛 머리말은 "1.0.0 (브랜치@커밋)"일 수 있어 첫 낱말만 비교한다
|
|
135
|
+
const version = manifest?.build?.sdk?.split(' ')[0];
|
|
136
|
+
const min = spec.minVersions.sdk;
|
|
137
|
+
const order = version ? compareVersions(version, min) : undefined;
|
|
138
|
+
const below = order !== undefined && order < 0;
|
|
139
|
+
if (opts.legacySdkCopy) {
|
|
140
|
+
add('sdk.lib-copy', `${opts.legacySdkCopy}는 옛 ecdk create가 복사한 SDK${version ? ` ${version}` : ''}입니다${below ? ` (최소 ${min}보다 낮음)` : ''}. 이제 SDK는 package.json 의존성입니다: ecdk doctor --fix(또는 package.json dependencies에 "@eliceio/cdk": "^${min}")로 넣고 npm install 하면 ecdk build가 node_modules에서 넣습니다. 그다음 ${opts.legacySdkCopy}는 지워도 됩니다.`, opts.legacySdkCopy);
|
|
141
|
+
// 옛 복사본도 최소 미만이면 오류 (zip 검사와 같은 판정, 옛 SDK로 올리는 것을 막음)
|
|
142
|
+
if (below) add('sdk.outdated', `${opts.legacySdkCopy}의 SDK ${version}은 최소 버전 ${min}보다 낮아 LXP에서 저장 · 제출 · 교육자 화면이 안 될 수 있습니다. ecdk doctor --fix && npm install 후 다시 빌드해 주세요.`, opts.legacySdkCopy);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (below) add('sdk.outdated', `@eliceio/cdk(SDK) ${version}은 최소 버전 ${min}보다 낮아 LXP에서 저장 · 제출이 안 될 수 있습니다. 프로젝트 폴더에서 ${SDK_UPDATE_COMMAND} 후 다시 빌드해 주세요.`, spec.manifest.file);
|
|
146
|
+
}
|
|
69
147
|
/** `<script type="module" data-ecdk-bundle>` 본문을 줄 수만 남기고 비운다 (줄 번호 유지) */
|
|
70
148
|
function blankBundles(html) {
|
|
71
149
|
return html.replace(/(<script\b[^>]*\sdata-ecdk-bundle\b[^>]*>)([\s\S]*?)(<\/script\s*>)/gi, (_, open, body, close) => open + body.replace(/[^\n]/g, '') + close);
|
|
@@ -115,7 +193,10 @@ function checkFiles(input, opts = {}) {
|
|
|
115
193
|
const mfile = files.find(f => f.path === spec.manifest.file);
|
|
116
194
|
if (mfile) {
|
|
117
195
|
const parsed = parseManifest(decoder.decode(mfile.data), spec);
|
|
118
|
-
if (parsed.ok)
|
|
196
|
+
if (parsed.ok) {
|
|
197
|
+
manifest = parsed.manifest;
|
|
198
|
+
for (const w of parsed.warnings ?? []) add('manifest.grading-types', `${spec.manifest.file}: ${w}`, spec.manifest.file);
|
|
199
|
+
} else add('manifest.invalid', `${spec.manifest.file}: ${parsed.error}`, spec.manifest.file);
|
|
119
200
|
} else if (kind !== 'html' && !nestedRoot) {
|
|
120
201
|
add('manifest.missing', `최상위에 ${spec.manifest.file}이 없습니다. 학생 화면·교육자 화면 등 어떤 화면이 있는지 적어 주세요 (ecdk build가 만들어 줍니다).`);
|
|
121
202
|
}
|
|
@@ -125,7 +206,7 @@ function checkFiles(input, opts = {}) {
|
|
|
125
206
|
}
|
|
126
207
|
const commentaryFile = manifest.commentary === undefined ? undefined : files.find(f => f.path === manifest.commentary);
|
|
127
208
|
// LXP 업로드는 학습 참고 내용이 없는 자료 본문을 거절한다 (qa5에서 확인. 스펙은 선택이었음)
|
|
128
|
-
if ((manifest.kind ?? spec.manifest.defaultKind) !== 'description' && manifest.commentary === undefined) add('manifest.commentary-missing', `학습 참고 내용 파일이 없어 LXP 업로드가 거절됩니다. 프로젝트 맨 위에 ${spec.manifest.commentaryFile}(이 자료의 핵심 개념 · 활동 · 문제 의도, 정답 제외)을
|
|
209
|
+
if ((manifest.kind ?? spec.manifest.defaultKind) !== 'description' && manifest.commentary === undefined) add('manifest.commentary-missing', `학습 참고 내용 파일이 없어 LXP 업로드가 거절됩니다. 프로젝트 맨 위에 ${spec.manifest.commentaryFile}(이 자료의 핵심 개념 · 활동 · 문제 의도, 정답 제외)을 만들고 ${spec.manifest.file}에 "commentary": "${spec.manifest.commentaryFile}"를 적어 주세요.`, spec.manifest.file);
|
|
129
210
|
if (manifest.commentary !== undefined && !commentaryFile) add('manifest.entry-missing', `${spec.manifest.file}에 적은 학습 참고 내용 파일이 없습니다: ${manifest.commentary}`, spec.manifest.file);
|
|
130
211
|
// LXP 학습 참고 내용 칸으로 옮길 텍스트라 UTF-8이어야 한다 (메모장 ANSI · EUC-KR 저장이면 깨짐)
|
|
131
212
|
if (commentaryFile) {
|
|
@@ -139,8 +220,12 @@ function checkFiles(input, opts = {}) {
|
|
|
139
220
|
// 메모장 등이 붙이는 BOM은 학습 참고 내용 칸에 보이지 않는 글자로 들어간다
|
|
140
221
|
if (startsWithBom(commentaryFile.data)) add('file.bom', `학습 참고 내용 파일 맨 앞에 BOM(보이지 않는 글자)이 있습니다: ${commentaryFile.path}. "UTF-8(BOM 없음)"으로 다시 저장해 주세요.`, commentaryFile.path);
|
|
141
222
|
}
|
|
223
|
+
checkCompletion(manifest, spec, (id, message, path) => add(id, message, path));
|
|
224
|
+
checkTemplate(manifest, opts, message => add('build.template-unknown', message, spec.manifest.file));
|
|
142
225
|
checkScreenCode(files, manifest, (id, message) => add(id, message, spec.manifest.file));
|
|
143
226
|
}
|
|
227
|
+
checkLegacyFiles(opts, (message, path) => add('project.legacy-file', message, path));
|
|
228
|
+
checkSdk(manifest, spec, opts, add);
|
|
144
229
|
const entry = manifest?.entries.learn ?? spec.manifest.defaultEntry;
|
|
145
230
|
if (!manifest && !exact.has(entry)) add('entry.missing', `최상위에 ${entry} 파일이 없습니다.`);
|
|
146
231
|
// 한도
|
|
@@ -172,7 +257,7 @@ function checkFiles(input, opts = {}) {
|
|
|
172
257
|
add('file.encoding', `UTF-8이 아닌 파일입니다 (EUC-KR · ANSI로 저장하면 한글이 깨집니다): ${f.path}. UTF-8로 다시 저장해 주세요.`, f.path);
|
|
173
258
|
continue;
|
|
174
259
|
}
|
|
175
|
-
//
|
|
260
|
+
// zip 안 JSON(작성자가 넣은 데이터 파일)은 학생 브라우저로 그대로 내려간다. 파일 이름(answers.*)만 막아서는 파일 안의 정답을 못 잡는다
|
|
176
261
|
if (ext === 'json' && f.path !== spec.manifest.file) {
|
|
177
262
|
let data = null;
|
|
178
263
|
try {
|
|
@@ -181,7 +266,7 @@ function checkFiles(input, opts = {}) {
|
|
|
181
266
|
data = null;
|
|
182
267
|
}
|
|
183
268
|
const key = answerKeyPath(data);
|
|
184
|
-
if (key) add('content.answer-key', `학생에게 내려가는 JSON에 정답처럼 보이는 키가 있습니다: ${key}. 정답은
|
|
269
|
+
if (key) add('content.answer-key', `학생에게 내려가는 JSON에 정답처럼 보이는 키가 있습니다: ${key}. 정답은 편집 화면의 채점 설정(settings.grading)에 두고 zip에서 빼 주세요.`, f.path);
|
|
185
270
|
}
|
|
186
271
|
}
|
|
187
272
|
for (const paths of byLower.values()) {
|
package/es/rules/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { checkFiles } from './check.js';
|
|
2
|
-
export {
|
|
2
|
+
export { COMPLETION_POLICIES_EXAMPLE, completionPolicyError, graderTypeError, parseCompletionPolicies, parseManifest, serializeManifest, } from './manifest.js';
|
|
3
3
|
export { globToRegExp } from './path.js';
|
|
4
4
|
export { commentOnlyLines, lineSkipper } from './skip.js';
|
|
5
5
|
export { rules, RULES_VERSION } from './spec.js';
|
package/es/rules/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { checkFiles } from './check.js';
|
|
2
|
-
export {
|
|
2
|
+
export { COMPLETION_POLICIES_EXAMPLE, completionPolicyError, graderTypeError, parseCompletionPolicies, parseManifest, serializeManifest } from './manifest.js';
|
|
3
3
|
export { globToRegExp } from './path.js';
|
|
4
4
|
export { commentOnlyLines, lineSkipper } from './skip.js';
|
|
5
5
|
export { RULES_VERSION, rules } from './spec.js';
|
package/es/rules/manifest.d.ts
CHANGED
|
@@ -1,39 +1,53 @@
|
|
|
1
1
|
import type { Manifest, RulesSpec } from './types.js';
|
|
2
|
+
/** `warnings`: 받아 주지만 고쳐야 할 것 (예: 옛 `gradingTypes`). 없으면 필드도 없음 */
|
|
2
3
|
export type ParsedManifest = {
|
|
3
4
|
ok: true;
|
|
4
5
|
manifest: Manifest;
|
|
6
|
+
warnings?: string[];
|
|
5
7
|
} | {
|
|
6
8
|
ok: false;
|
|
7
9
|
error: string;
|
|
8
10
|
};
|
|
9
11
|
/**
|
|
10
|
-
*
|
|
11
|
-
* 수동 채점(manual) · 채점 없음(none)은 Custom HTML에서 쓰지 않는다.
|
|
12
|
+
* 완료 정책 하나 검사 (metadata `completionPolicies`의 값 · 로컬 `.ecdk/completion.json`, ADR 0009).
|
|
13
|
+
* 문제가 없으면 null. 수동 채점(manual) · 채점 없음(none)은 Custom HTML에서 쓰지 않는다.
|
|
12
14
|
*/
|
|
13
|
-
export declare function
|
|
15
|
+
export declare function completionPolicyError(value: unknown, allowed: readonly string[]): string | null;
|
|
16
|
+
/** 채점 방식 하나 검사 (on_graded일 때 `settings.grading.type`: pattern · rubric). 문제가 없으면 null */
|
|
17
|
+
export declare function graderTypeError(value: unknown, allowed: readonly string[]): string | null;
|
|
18
|
+
/** completionPolicies 예시 (오류 문구에 같이 보인다) */
|
|
19
|
+
export declare const COMPLETION_POLICIES_EXAMPLE = "\uC608: \"completionPolicies\": [\"on_submit\"] \u00B7 \uACE0\uB97C \uC218 \uC788\uAC8C [\"on_submit\", \"on_access\"] \u00B7 \uCC44\uC810\uD558\uB294 \uD034\uC988 [\"on_graded\"]";
|
|
20
|
+
/**
|
|
21
|
+
* `completionPolicies` 검사 (metadata.json · 옛 elice.config.json, ADR 0009 2026-11-11 결정 2): 알려진 완료 정책의 배열,
|
|
22
|
+
* 같은 값 두 번 없음. 문제가 있으면 문장, 없으면 배열. 빈 배열은 여기서 통과시키고 검사 규칙
|
|
23
|
+
* manifest.completion-policies-missing이 알린다 (없는 것과 같은 문제)
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseCompletionPolicies(value: unknown, spec: RulesSpec): string[] | string;
|
|
14
26
|
/**
|
|
15
27
|
* metadata.json (zip 최상위): 용도, 화면(모드)별 사용 여부와 진입 파일, 빌드 정보. 정답은 넣지 않는다.
|
|
16
28
|
*
|
|
17
29
|
* {
|
|
18
30
|
* "kind": "material", // 선택. material: 자료 본문(기본) · description: 문제 설명
|
|
19
|
-
* "screens": { //
|
|
31
|
+
* "screens": { // 알려진 화면을 적는다. 적지 않은 화면은 꺼짐
|
|
20
32
|
* "learn": { "enabled": true, "entry": "index.html" },
|
|
21
33
|
* "instructor": { "enabled": true, "entry": "instructor.html" },
|
|
22
|
-
* "edit": { "enabled":
|
|
34
|
+
* "edit": { "enabled": true, "entry": "edit.html" }, // 내용 편집 + 채점 방식 · 답 (ADR 0009)
|
|
35
|
+
* "completionPolicy": { "enabled": false } // 완료 정책 화면 (ADR 0009)
|
|
23
36
|
* },
|
|
24
|
-
* //
|
|
25
|
-
* //
|
|
26
|
-
* "
|
|
37
|
+
* // 자료 본문은 필수: 지원하는 완료 정책, 서버는 첫 값으로 정한다. 하나면 고정(퀴즈 ["on_graded"]),
|
|
38
|
+
* // 여럿이면 완료 정책 화면이 그 안에서 바꾼다
|
|
39
|
+
* "completionPolicies": ["on_submit", "on_access"],
|
|
27
40
|
* "commentary": "commentary.txt", // 선택. 학습 참고 내용 파일 (zip 최상위, 일반 텍스트)
|
|
28
41
|
* "build": { "cli": "0.1.0", "rules": "0.2.0", "protocol": 1, "engine": "static" } // 선택
|
|
29
42
|
* }
|
|
30
43
|
*
|
|
31
44
|
* 파싱 결과의 `entries`는 켠 화면만 담는다. 서버 `material_draft.manifest`(JSONB) · SDK `MaterialManifest`의
|
|
32
45
|
* `{ entries }`가 이 모양이라 서버는 그대로 저장할 수 있다. 형식은 서버·디자인과 확정 전 제안안 (ADR 0004).
|
|
46
|
+
* `gradingTypes`(2026-11-10 삭제, ADR 0008)가 있으면 받아 주고 경고만 낸다: 완료 정책은 completionPolicies · 완료 정책 화면, 채점 방식은 편집 화면이 정한다.
|
|
33
47
|
*/
|
|
34
48
|
export declare function parseManifest(text: string, spec: RulesSpec): ParsedManifest;
|
|
35
49
|
/**
|
|
36
|
-
*
|
|
50
|
+
* 알려진 화면의 사용 여부(enabled)를 모두 적는다. 필드 순서(kind · screens · completionPolicies · commentary · build)와 화면 순서(learn · instructor · edit · completionPolicy)를
|
|
37
51
|
* 고정해 같은 입력이면 같은 파일이 나오게 한다. kind가 없으면 기본값을 적는다.
|
|
38
52
|
*/
|
|
39
53
|
export declare function serializeManifest(manifest: Manifest, spec: RulesSpec): string;
|