@eliceio/cdk-cli 0.1.0-alpha.2 → 0.1.0-alpha.3
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 +158 -138
- package/es/cli.js +88 -33
- package/es/commands/build/index.d.ts +1 -1
- package/es/commands/build/index.js +16 -6
- package/es/commands/check/index.d.ts +8 -2
- package/es/commands/check/index.js +45 -5
- package/es/commands/create/index.d.ts +2 -0
- package/es/commands/create/index.js +28 -3
- package/es/commands/create/scaffold.d.ts +2 -0
- package/es/commands/create/scaffold.js +10 -6
- package/es/commands/dev/index.d.ts +1 -1
- package/es/commands/dev/index.js +6 -2
- package/es/commands/doctor/index.d.ts +11 -0
- package/es/commands/doctor/index.js +155 -26
- 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/config.d.ts +63 -19
- package/es/core/config.js +108 -32
- package/es/core/prepare.js +3 -5
- package/es/core/project-check.d.ts +15 -0
- package/es/core/project-check.js +26 -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 +33 -33
- package/es/dev/mock-api.d.ts +20 -4
- package/es/dev/mock-api.js +70 -9
- package/es/dev/server.d.ts +7 -0
- package/es/dev/server.js +84 -23
- package/es/rules/check.js +56 -7
- 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 +27 -6
- package/es/rules.json.js +1 -1
- package/guides/content-development.md +136 -49
- package/package.json +2 -2
- package/rules.json +62 -7
- package/skills/_shared/always.md +3 -1
- package/skills/elice-content-check/SKILL.md +1 -1
- package/skills/elice-content-create/SKILL.md +4 -4
- package/skills/elice-content-migrate/SKILL.md +1 -1
- package/skills/elice-content-publish/SKILL.md +22 -0
- package/templates/_shared/lib/cdk-mock.d.ts +21 -3
- package/templates/_shared/lib/cdk-mock.js +239 -80
- package/templates/_shared/lib/cdk.js +2 -2
- package/templates/_shared/lib/elice-content.css +196 -0
- package/templates/_shared/lib/elice-content.d.ts +110 -5
- package/templates/_shared/lib/elice-content.js +643 -38
- package/templates/blank/README.md +12 -3
- package/templates/blank/completion.html +15 -0
- package/templates/blank/elice.config.json +3 -5
- package/templates/blank/gitignore +1 -0
- package/templates/blank/screens/completion.js +7 -0
- package/templates/blank/screens/edit.js +3 -0
- package/templates/blank/template.json +6 -0
- package/templates/quiz/README.md +35 -28
- package/templates/quiz/content.json +17 -63
- package/templates/quiz/core/behaviors.d.ts +5 -0
- package/templates/quiz/core/behaviors.js +12 -0
- package/templates/quiz/core/model.d.ts +27 -1
- package/templates/quiz/core/model.js +199 -4
- package/templates/quiz/elice.config.json +1 -6
- package/templates/quiz/gitignore +1 -0
- package/templates/quiz/grading.json +1 -10
- package/templates/quiz/screens/edit.js +105 -31
- package/templates/quiz/screens/learn.js +7 -8
- package/templates/quiz/template.json +6 -0
- package/templates/quiz/ui/templates/edit.d.ts +2 -0
- package/templates/quiz/ui/templates/edit.js +16 -9
- package/templates/quiz/ui/texts.js +52 -27
package/es/dev/host-page.js
CHANGED
|
@@ -2,7 +2,7 @@ import { DEV_MATERIAL_ID } from './mock-api.js';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* LXP 학습 · 편집 페이지 흉내. 보기를 바꾸고 콘텐츠를 sandbox iframe으로 띄우며,
|
|
5
|
-
* @eliceio/cdk가 보내는 postMessage(settings-
|
|
5
|
+
* @eliceio/cdk가 보내는 postMessage(settings-saved · navigate-*)를 받아 처리한다
|
|
6
6
|
*/
|
|
7
7
|
function hostPage(opts) {
|
|
8
8
|
return `<!doctype html>
|
|
@@ -51,7 +51,6 @@ function hostPage(opts) {
|
|
|
51
51
|
<button data-w="100%" aria-pressed="true">데스크톱</button><button data-w="720px">태블릿</button><button data-w="360px">모바일</button>
|
|
52
52
|
</div>
|
|
53
53
|
<span class="sep"></span>
|
|
54
|
-
<button id="save" hidden disabled title="편집 화면이 saveSettings()로 넘긴 설정을 자료에 저장합니다">저장</button>
|
|
55
54
|
<button id="reset" title="제출 기록 · 점수 · 완료, 편집 화면에서 저장한 내용을 지우고 처음 들어온 상태로 다시 엽니다">처음 상태로</button>
|
|
56
55
|
<span class="sep"></span>
|
|
57
56
|
<details id="sdk-tools">
|
|
@@ -62,6 +61,10 @@ function hostPage(opts) {
|
|
|
62
61
|
<label><input type="checkbox" id="has-prev" checked>이전 차시 있음</label>
|
|
63
62
|
<label><input type="checkbox" id="has-next" checked>다음 차시 있음</label>
|
|
64
63
|
</div>
|
|
64
|
+
<div class="tool" role="group" aria-label="저장 전 편집 화면" title="LXP 편집 페이지에서 zip을 올리고 아직 저장하지 않은 상태의 편집 화면처럼 토큰 없이 엽니다. 저장하면 SDK가 draft_not_saved로 거절합니다">
|
|
65
|
+
<b>저장 전 편집 화면</b> <code>#edit=1</code>
|
|
66
|
+
<button type="button" id="open-edit-draft">열기</button>
|
|
67
|
+
</div>
|
|
65
68
|
<div class="tool" role="group" aria-label="저장 전 미리보기" title="LXP 편집 페이지의 미리보기처럼 토큰 없이 학생 화면을 엽니다. settings가 비어 content.json 기본 내용으로 뜨고, 제출은 기록되지 않습니다(늘 100점)">
|
|
66
69
|
<b>저장 전 미리보기</b> <code>#preview=1</code>
|
|
67
70
|
<button type="button" id="open-preview">열기</button>
|
|
@@ -76,27 +79,34 @@ function hostPage(opts) {
|
|
|
76
79
|
<script type="module">
|
|
77
80
|
const MATERIAL_ID = ${JSON.stringify(DEV_MATERIAL_ID)};
|
|
78
81
|
const SDK_SOURCE = 'eliceio-content-sdk';
|
|
79
|
-
// [보기, 이름, 화면, 주소 조각]. token은 흉내 서버가
|
|
82
|
+
// [보기, 이름, 화면, 주소 조각]. token은 흉내 서버가 발급. 내용 편집은 LXP처럼 저장된 버전을 edit 토큰으로 연다
|
|
80
83
|
const SCENARIOS = [
|
|
81
84
|
['student', '학생', 'learn', 'token'],
|
|
82
85
|
['tutor', '튜터링', 'learn', 'token'],
|
|
83
86
|
['instructor', '교육자 화면', 'instructor', 'token'],
|
|
84
|
-
['edit', '내용 편집', 'edit', '
|
|
87
|
+
['edit', '내용 편집', 'edit', 'token'],
|
|
88
|
+
// 완료 정책 화면 (ADR 0009): LXP 설정 탭처럼 edit 토큰 + screen=completionPolicy. screens.completionPolicy를 켠
|
|
89
|
+
// 자료에서만 보인다 (퀴즈처럼 completionPolicies가 하나면 없음). 저장하면 .ecdk/completion.json, 채점 방식 · 답은 내용 편집
|
|
90
|
+
['completionPolicy', '완료 정책', 'completionPolicy', 'token'],
|
|
85
91
|
];
|
|
86
92
|
// 토큰 없는 미리보기(#preview=1)는 settings가 비고 늘 100점이라 학생 보기와 구분이 안 돼 보기 버튼에서 빼고,
|
|
87
93
|
// SDK 기능 안의 도구로만 연다 (SDK · 키트는 이 상태를 따로 다룸: isDraftPreview, "기록되지 않음" 안내)
|
|
88
94
|
const PREVIEW = ['preview', '저장 전 미리보기', 'learn', 'preview=1'];
|
|
89
|
-
|
|
95
|
+
// 저장 전 업로드의 편집 화면 (토큰 없음): saveSettings가 draft_not_saved로 거절되는 것을 확인할 때
|
|
96
|
+
const EDIT_DRAFT = ['edit-draft', '저장 전 편집 화면', 'edit', 'edit=1'];
|
|
97
|
+
const TOOLS = [PREVIEW, EDIT_DRAFT];
|
|
98
|
+
const scenarioOf = (name) => TOOLS.find((s) => s[0] === name) ?? SCENARIOS.find((s) => s[0] === name);
|
|
99
|
+
// LXP처럼 material API 주소를 fragment로 넘긴다 (키트는 dev에서 __ECDK_DEV__.api를 먼저 쓴다)
|
|
100
|
+
const BASE_URL = encodeURIComponent(location.origin + '/api');
|
|
90
101
|
const frame = document.getElementById('content');
|
|
91
102
|
const previewEl = document.getElementById('open-preview');
|
|
92
103
|
const scenariosEl = document.getElementById('scenarios');
|
|
93
|
-
const
|
|
104
|
+
const editDraftEl = document.getElementById('open-edit-draft');
|
|
94
105
|
const messagesEl = document.getElementById('messages');
|
|
95
106
|
let state = { kind: 'material', entries: {}, contentBase: '' };
|
|
96
107
|
// 저장소가 막힌 브라우저에서도 화면이 떠야 하므로 sessionStorage는 모두 try로 감싼다
|
|
97
108
|
let current = 'student';
|
|
98
109
|
try { current = sessionStorage.getItem('ecdk-scenario') || 'student'; } catch {}
|
|
99
|
-
let pendingSettings = null;
|
|
100
110
|
|
|
101
111
|
function note(line) {
|
|
102
112
|
const lines = (messagesEl.textContent ? messagesEl.textContent.split('\\n') : []).slice(-4);
|
|
@@ -112,24 +122,22 @@ function hostPage(opts) {
|
|
|
112
122
|
try { sessionStorage.setItem('ecdk-scenario', scenario); } catch {}
|
|
113
123
|
for (const b of scenariosEl.children) b.setAttribute('aria-pressed', String(b.dataset.scenario === scenario));
|
|
114
124
|
previewEl.setAttribute('aria-pressed', String(scenario === PREVIEW[0]));
|
|
125
|
+
editDraftEl.setAttribute('aria-pressed', String(scenario === EDIT_DRAFT[0]));
|
|
115
126
|
const [, label, screen, fragment] = scenarioOf(scenario);
|
|
116
127
|
const entry = entryOf(screen);
|
|
117
|
-
pendingSettings = null;
|
|
118
|
-
saveEl.hidden = scenario !== 'edit';
|
|
119
|
-
saveEl.disabled = true;
|
|
120
128
|
// 같은 파일이면 해시만 바뀌어 다시 로드되지 않으므로 매번 쿼리를 바꾼다
|
|
121
129
|
const url = state.contentBase + entry + '?ecdk=' + Date.now();
|
|
122
130
|
if (fragment === 'token') {
|
|
123
131
|
const { token } = await (await fetch('/__ecdk/token?scenario=' + scenario)).json();
|
|
124
|
-
frame.src = url + '#token=' + token;
|
|
132
|
+
frame.src = url + '#token=' + token + '&baseUrl=' + BASE_URL + (screen === 'completionPolicy' ? '&screen=completionPolicy' : '');
|
|
125
133
|
} else {
|
|
126
|
-
frame.src = url + '#' + fragment;
|
|
134
|
+
frame.src = url + '#' + fragment + '&baseUrl=' + BASE_URL;
|
|
127
135
|
}
|
|
128
136
|
document.getElementById('hint').textContent =
|
|
129
|
-
(state.kind === 'description' ? '문제 설명 · ' : '') + entry + ' · ' + (
|
|
137
|
+
(state.kind === 'description' ? '문제 설명 · ' : '') + entry + ' · ' + (TOOLS.some((t) => t[0] === scenario) ? label : scenario);
|
|
130
138
|
}
|
|
131
139
|
|
|
132
|
-
// 화면(learn · instructor · edit)은 검사기가 kindModes로 이미 걸러 state.entries에 켠 것만 온다.
|
|
140
|
+
// 화면(learn · instructor · edit · completionPolicy)은 검사기가 kindModes로 이미 걸러 state.entries에 켠 것만 온다.
|
|
133
141
|
// 문제 설명에는 학생 보기만 둔다: 다른 보기가 있는지는 서버 · LXP와 아직 정하지 않았다 (progress G81)
|
|
134
142
|
const available = (s) => entryOf(s[2]) && (state.kind !== 'description' || s[0] === 'student');
|
|
135
143
|
function renderScenarios() {
|
|
@@ -139,7 +147,9 @@ function hostPage(opts) {
|
|
|
139
147
|
b.onclick = () => open(scenario);
|
|
140
148
|
return b;
|
|
141
149
|
}));
|
|
142
|
-
const
|
|
150
|
+
const tool = TOOLS.find((t) => t[0] === current);
|
|
151
|
+
const keep = tool ? available(tool) : SCENARIOS.some((s) => s[0] === current && available(s));
|
|
152
|
+
editDraftEl.disabled = !available(EDIT_DRAFT);
|
|
143
153
|
if (!keep) current = 'student';
|
|
144
154
|
}
|
|
145
155
|
|
|
@@ -156,11 +166,13 @@ function hostPage(opts) {
|
|
|
156
166
|
if (!data || typeof data !== 'object' || data.source !== SDK_SOURCE) return;
|
|
157
167
|
const payload = data.payload || {};
|
|
158
168
|
switch (data.type) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
// 편집 화면의 saveSettings 결과. 저장은 콘텐츠가 edit 토큰으로 이미 했고, 편집 페이지는 표시만 한다
|
|
170
|
+
case 'settings-saved':
|
|
171
|
+
note(payload.status === 'saved'
|
|
172
|
+
? (current === 'completionPolicy'
|
|
173
|
+
? 'settings-saved: 완료 정책을 저장했습니다 (.ecdk/completion.json). 학생 보기가 이 정책으로 완료 · 채점합니다'
|
|
174
|
+
: 'settings-saved: 저장했습니다. 다른 보기에서 material.settings로 받습니다 (채점 방식 · 답은 grading.json)')
|
|
175
|
+
: 'settings-saved: 저장 실패 (' + payload.code + ')');
|
|
164
176
|
return;
|
|
165
177
|
case 'navigate-prev':
|
|
166
178
|
note('navigate-prev: 이전 차시로 이동 (dev는 이동하지 않음)');
|
|
@@ -192,19 +204,6 @@ function hostPage(opts) {
|
|
|
192
204
|
}
|
|
193
205
|
});
|
|
194
206
|
|
|
195
|
-
// 편집 페이지의 자료 저장: 마지막으로 받은 settings를 edit 토큰으로 PATCH
|
|
196
|
-
saveEl.onclick = async () => {
|
|
197
|
-
if (!pendingSettings) return;
|
|
198
|
-
const { token } = await (await fetch('/__ecdk/token?scenario=edit')).json();
|
|
199
|
-
const res = await fetch('/api/materials/' + MATERIAL_ID, {
|
|
200
|
-
method: 'PATCH',
|
|
201
|
-
headers: { Authorization: 'Bearer ' + token, 'Content-Type': 'application/json' },
|
|
202
|
-
body: JSON.stringify({ settings: pendingSettings }),
|
|
203
|
-
});
|
|
204
|
-
note(res.ok ? '저장했습니다. 다른 보기에서 material.settings로 받습니다' : '저장 실패 (' + res.status + ')');
|
|
205
|
-
if (res.ok) saveEl.disabled = true;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
207
|
for (const b of document.querySelectorAll('[data-w]')) b.onclick = () => {
|
|
209
208
|
for (const x of document.querySelectorAll('[data-w]')) x.setAttribute('aria-pressed', String(x === b));
|
|
210
209
|
frame.style.setProperty('--w', b.dataset.w);
|
|
@@ -222,6 +221,7 @@ function hostPage(opts) {
|
|
|
222
221
|
toolsEl.querySelector('summary').focus();
|
|
223
222
|
});
|
|
224
223
|
previewEl.onclick = () => { toolsEl.open = false; open(PREVIEW[0]); };
|
|
224
|
+
editDraftEl.onclick = () => { toolsEl.open = false; open(EDIT_DRAFT[0]); };
|
|
225
225
|
document.getElementById('reset').onclick = async () => { await fetch('/__ecdk/reset', { method: 'POST' }); open(current); };
|
|
226
226
|
|
|
227
227
|
state = await (await fetch('/__ecdk/state')).json();
|
package/es/dev/mock-api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type CompletionPolicy, type GradingConfig, type LocalGrading } from '../core/config.js';
|
|
1
2
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
-
import type { GradingConfig } from '../core/config.js';
|
|
3
3
|
/**
|
|
4
4
|
* elice-material API 흉내 (서버 설계 v25, @eliceio/cdk 1.x가 부르는 것만).
|
|
5
5
|
* 응답은 elib 형식 `{ data, meta }`, 필드는 snake_case. 오류는 `{ data: null, meta: { error } }`.
|
|
@@ -20,9 +20,14 @@ export type MaterialViewer = 'student' | 'instructor' | 'tutor';
|
|
|
20
20
|
/**
|
|
21
21
|
* dev 호스트 화면의 보기 (dev 전용). 토큰은 scope + viewer로 바뀐다.
|
|
22
22
|
* - student · instructor · tutor: `#token=…` (scope learn)
|
|
23
|
-
* - edit:
|
|
23
|
+
* - edit: `#token=…` (scope edit). LXP 편집 페이지처럼 저장된 버전의 편집 화면을 edit 토큰으로 열고,
|
|
24
|
+
* 콘텐츠의 `saveSettings`가 이 토큰으로 바로 PATCH한다 (토큰 없는 `#edit=1` draft는 저장할 수 없음)
|
|
25
|
+
* - completionPolicy: `#token=…&screen=completionPolicy` (scope edit). 완료 정책 화면 (ADR 0009). SDK
|
|
26
|
+
* `saveCompletionPolicy`가 보낸 `PATCH { completion_policy }`를 `.ecdk/completion.json`에 쓴다 (운영은 material_version)
|
|
27
|
+
* 편집 화면의 `saveSettings`가 보낸 `settings.grading`({ type: pattern | rubric })은 프로젝트의 grading.json에 쓰고,
|
|
28
|
+
* 학생 · 튜터 · 교육자(learn scope) 응답에는 서버처럼 `grading`을 빼고 준다
|
|
24
29
|
*/
|
|
25
|
-
export type DevScenario = 'student' | 'instructor' | 'tutor' | 'edit';
|
|
30
|
+
export type DevScenario = 'student' | 'instructor' | 'tutor' | 'edit' | 'completionPolicy';
|
|
26
31
|
/** 토큰을 발급하는 보기 */
|
|
27
32
|
export type TokenScenario = DevScenario;
|
|
28
33
|
export declare const TOKEN_SCENARIOS: Readonly<Record<DevScenario, {
|
|
@@ -47,6 +52,8 @@ interface Result {
|
|
|
47
52
|
}
|
|
48
53
|
export interface MockState {
|
|
49
54
|
settings: Record<string, unknown>;
|
|
55
|
+
/** 저장할 때마다 올라가는 버전 번호. 응답의 `current_version.id`는 `dev-{n}` */
|
|
56
|
+
version: number;
|
|
50
57
|
submissions: Submission[];
|
|
51
58
|
/** 계정별 결과. 자료당 하나이고 버전이 바뀌어도 지우지 않는다 */
|
|
52
59
|
results: Map<number, Result>;
|
|
@@ -56,8 +63,17 @@ export interface MockState {
|
|
|
56
63
|
export declare const createState: () => MockState;
|
|
57
64
|
export interface MockApiOptions {
|
|
58
65
|
state: MockState;
|
|
59
|
-
|
|
66
|
+
/** 채점에 쓰는 값 (로컬 완료 정책 + grading.json) */
|
|
67
|
+
getGrading: () => LocalGrading | undefined;
|
|
68
|
+
/** grading.json에 저장된 채점 설정 (없으면 null). edit 범위 응답의 `settings.grading` */
|
|
69
|
+
getSavedGrading?: () => GradingConfig | null;
|
|
70
|
+
/** 편집 화면이 저장한 `settings.grading`을 grading.json에 쓴다 */
|
|
71
|
+
writeGradingFile?: (grading: GradingConfig) => Promise<void>;
|
|
60
72
|
getEntries: () => Record<string, string>;
|
|
73
|
+
/** metadata completionPolicies (서버가 metadata를 그대로 돌려준다고 보고 응답에 넣는다, G132) */
|
|
74
|
+
getCompletionPolicies?: () => string[];
|
|
75
|
+
/** 완료 정책 화면이 저장한 completion_policy를 .ecdk/completion.json에 쓴다 */
|
|
76
|
+
saveCompletionPolicy?: (policy: CompletionPolicy) => Promise<void>;
|
|
61
77
|
onEvent?: (message: string) => void;
|
|
62
78
|
}
|
|
63
79
|
/** `/api` 아래 요청을 처리한다 */
|
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,18 @@ 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 범위에만 grading.json을 넣어 준다
|
|
173
|
+
const withGrading = settings => {
|
|
174
|
+
const {
|
|
175
|
+
grading: _ignored,
|
|
176
|
+
...rest
|
|
177
|
+
} = settings;
|
|
178
|
+
const saved = claims.scope === 'edit' ? opts.getSavedGrading?.() : null;
|
|
179
|
+
return saved ? {
|
|
180
|
+
...rest,
|
|
181
|
+
grading: saved
|
|
182
|
+
} : rest;
|
|
183
|
+
};
|
|
166
184
|
const material = settings => ({
|
|
167
185
|
id: DEV_MATERIAL_ID,
|
|
168
186
|
lecture_page_id: 1,
|
|
@@ -172,39 +190,82 @@ async function handleMockApi(req, res, path, opts) {
|
|
|
172
190
|
text: ''
|
|
173
191
|
},
|
|
174
192
|
current_version: {
|
|
175
|
-
id:
|
|
193
|
+
id: `dev-${state.version}`,
|
|
176
194
|
content_urls: {},
|
|
195
|
+
// Like the server: metadata.json as is, with each enabled screen under `screens`.
|
|
177
196
|
metadata: {
|
|
178
|
-
|
|
197
|
+
kind: 'material',
|
|
198
|
+
screens: Object.fromEntries(Object.entries(opts.getEntries()).map(([screen, entry]) => [screen, {
|
|
199
|
+
entry,
|
|
200
|
+
enabled: true
|
|
201
|
+
}])),
|
|
202
|
+
completionPolicies: opts.getCompletionPolicies?.() ?? []
|
|
179
203
|
},
|
|
180
204
|
file_tree: [],
|
|
181
|
-
settings
|
|
205
|
+
settings: withGrading(settings),
|
|
206
|
+
completion_policy: opts.getGrading()?.completion_policy ?? 'on_access'
|
|
182
207
|
}
|
|
183
208
|
});
|
|
184
209
|
if (method === 'GET' && sub === '') return send(res, 200, material(state.settings));
|
|
185
|
-
// 편집
|
|
210
|
+
// 편집 화면의 saveSettings · 완료 정책 화면의 saveCompletionPolicy: edit 토큰으로 지금 버전을 바로 고침.
|
|
211
|
+
// 기준 버전이 다르면 409 (그 사이 다른 저장)
|
|
186
212
|
if (method === 'PATCH' && sub === '') {
|
|
187
213
|
if (claims.scope !== 'edit') return fail(res, 403, 'AUTH_PERMISSION_DENIED', 'settings only with an edit token');
|
|
188
214
|
const {
|
|
189
215
|
json
|
|
190
216
|
} = await body(req);
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
217
|
+
const request = json;
|
|
218
|
+
const settings = request?.settings;
|
|
219
|
+
const rawPolicy = request?.completion_policy;
|
|
220
|
+
if (settings === undefined && rawPolicy === undefined) return fail(res, 400, 'INVALID_INPUT', 'empty_patch');
|
|
221
|
+
if (settings !== undefined && (!settings || typeof settings !== 'object')) return fail(res, 400, 'INVALID_INPUT', 'settings must be an object');
|
|
222
|
+
if (rawPolicy !== undefined && !COMPLETION_POLICIES.includes(rawPolicy)) return fail(res, 400, 'INVALID_INPUT', `unknown completion_policy: ${JSON.stringify(rawPolicy)}`);
|
|
223
|
+
const policy = rawPolicy;
|
|
224
|
+
const expected = request?.expected_current_version_id;
|
|
225
|
+
if (expected != null && expected !== `dev-${state.version}`) return fail(res, 409, 'MATERIAL_CHANGED', `current version is dev-${state.version}`);
|
|
226
|
+
if (policy !== undefined) {
|
|
227
|
+
// 서버는 enum만 본다. dev는 metadata completionPolicies 밖의 값도 알려 준다 (완료 정책 화면은 그 안에서만 고름)
|
|
228
|
+
const allowed = opts.getCompletionPolicies?.() ?? [];
|
|
229
|
+
if (allowed.length > 0 && !allowed.includes(policy)) return fail(res, 400, 'INVALID_INPUT', `completion_policy ${policy} is not in metadata completionPolicies (${allowed.join(', ')})`);
|
|
230
|
+
// 서버처럼 채점 설정이 없는 on_graded는 거절 (편집 화면에서 답을 먼저 저장)
|
|
231
|
+
if (policy === 'on_graded' && !opts.getSavedGrading?.()) return fail(res, 422, 'MATERIAL_GRADING_REQUIRED', 'on_graded needs settings.grading');
|
|
232
|
+
}
|
|
233
|
+
// 편집 화면이 넣은 settings.grading은 grading.json으로 (dev 전용 저장 위치). 없으면 grading.json은 그대로
|
|
234
|
+
if (settings !== undefined) {
|
|
235
|
+
const {
|
|
236
|
+
grading,
|
|
237
|
+
...rest
|
|
238
|
+
} = settings;
|
|
239
|
+
if (grading !== undefined) {
|
|
240
|
+
const parsed = parseGrading(grading);
|
|
241
|
+
if (typeof parsed === 'string') return fail(res, 400, 'INVALID_INPUT', `grading: ${parsed}`);
|
|
242
|
+
await opts.writeGradingFile?.(parsed);
|
|
243
|
+
log(`채점 설정을 grading.json에 저장했습니다 (${parsed.type})`);
|
|
244
|
+
}
|
|
245
|
+
state.settings = rest;
|
|
246
|
+
}
|
|
247
|
+
if (policy !== undefined) {
|
|
248
|
+
await opts.saveCompletionPolicy?.(policy);
|
|
249
|
+
log(`완료 정책을 .ecdk/completion.json에 저장했습니다 (${policy})`);
|
|
250
|
+
}
|
|
251
|
+
state.version += 1;
|
|
252
|
+
log(`자료를 저장했습니다 (${settings !== undefined ? 'settings' : 'completion_policy'}, 버전 dev-${state.version})`);
|
|
195
253
|
return send(res, 200, material(state.settings));
|
|
196
254
|
}
|
|
197
255
|
if (method === 'GET' && sub === '/me') {
|
|
198
256
|
const user = claims.viewer === 'instructor' ? MANAGER : STUDENT;
|
|
199
|
-
if (claims.scope === 'learn' && claims.viewer === 'student' && opts.getGrading()?.
|
|
257
|
+
if (claims.scope === 'learn' && claims.viewer === 'student' && opts.getGrading()?.completion_policy === 'on_access' && !state.results.has(subject)) {
|
|
200
258
|
record(state, subject, {
|
|
201
259
|
score: 100
|
|
202
260
|
}, true);
|
|
203
261
|
log('열람 완료로 100점 (on_access)');
|
|
204
262
|
}
|
|
263
|
+
const local = opts.getGrading();
|
|
205
264
|
return send(res, 200, {
|
|
206
265
|
scope: claims.scope,
|
|
207
266
|
viewer: claims.viewer,
|
|
267
|
+
completion_policy: local?.completion_policy ?? 'on_access',
|
|
268
|
+
grading_type: local?.completion_policy === 'on_graded' ? local.grading?.type ?? null : null,
|
|
208
269
|
user: {
|
|
209
270
|
anonymous_id: user.anonymous_id,
|
|
210
271
|
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,8 +1,10 @@
|
|
|
1
|
-
import { watch } from 'node:fs';
|
|
1
|
+
import { watch, existsSync } from 'node:fs';
|
|
2
|
+
import { 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, loadGrading, GRADING_DATA_FILE } from '../core/config.js';
|
|
4
|
+
import { resolve, join, extname, basename, relative, sep, dirname } from 'node:path';
|
|
5
|
+
import { loadConfig, loadGrading, GRADING_DATA_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';
|
|
7
9
|
import { checkFiles } from '../rules/check.js';
|
|
8
10
|
import '../rules/spec.js';
|
|
@@ -49,6 +51,20 @@ function summarize(check) {
|
|
|
49
51
|
if (check.issues.length > 5) lines.push(` … 외 ${check.issues.length - 5}개 (ecdk check로 전체 보기)`);
|
|
50
52
|
return [head, ...lines].join('\n');
|
|
51
53
|
}
|
|
54
|
+
/** 포트가 이미 쓰일 때: 어느 포트(호스트 · 콘텐츠)인지 알린다 */
|
|
55
|
+
class DevPortError extends Error {
|
|
56
|
+
port;
|
|
57
|
+
role;
|
|
58
|
+
code = 'EADDRINUSE';
|
|
59
|
+
constructor(port, role) {
|
|
60
|
+
super(role === 'host' ? `ecdk dev 화면 포트 ${port}이(가) 이미 쓰이고 있습니다.` : `콘텐츠 서버 포트 ${port}(화면 포트 + 1)이(가) 이미 쓰이고 있습니다.`);
|
|
61
|
+
this.port = port;
|
|
62
|
+
this.role = role;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** --port 없이 열 때 기본 포트 쌍이 막혀 있으면 다음 쌍(+2)을 이만큼 더 시도한다 */
|
|
66
|
+
const DEFAULT_PORT = 4170;
|
|
67
|
+
const AUTO_PORT_TRIES = 10;
|
|
52
68
|
const listen = (server, port) => new Promise((ok, fail) => {
|
|
53
69
|
server.once('error', fail);
|
|
54
70
|
server.listen(port, '127.0.0.1', () => ok(server.address().port));
|
|
@@ -77,12 +93,35 @@ async function startDevServer(opts) {
|
|
|
77
93
|
const log = opts.log ?? (l => process.stdout.write(`${l}\n`));
|
|
78
94
|
let config = await loadConfig(dir);
|
|
79
95
|
let grading = await loadGrading(dir, config);
|
|
96
|
+
const gradingPath = join(dir, GRADING_DATA_FILE);
|
|
97
|
+
// 편집 화면이 저장해 우리가 쓴 grading.json 변경은 화면을 다시 띄우지 않는다 (저장 결과 문구가 사라지지 않게)
|
|
98
|
+
let selfWriteAt = 0;
|
|
99
|
+
const savedGrading = () => existsSync(gradingPath) ? grading?.grading ?? null : null;
|
|
100
|
+
async function writeGradingFile(next) {
|
|
101
|
+
selfWriteAt = Date.now();
|
|
102
|
+
await writeFile(gradingPath, `${JSON.stringify(next, null, 2)}\n`);
|
|
103
|
+
grading = await loadGrading(dir, config);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 완료 정책 화면의 saveCompletionPolicy(PATCH completion_policy)를 흉내 서버가 받으면 `.ecdk/completion.json`에 쓴다
|
|
107
|
+
* (운영은 material_version.completion_policy). 값 검사는 흉내 서버가 한다
|
|
108
|
+
*/
|
|
109
|
+
async function saveCompletionPolicy(policy) {
|
|
110
|
+
const path = join(dir, COMPLETION_DATA_FILE);
|
|
111
|
+
await mkdir(dirname(path), {
|
|
112
|
+
recursive: true
|
|
113
|
+
});
|
|
114
|
+
await writeFile(path, `${JSON.stringify({
|
|
115
|
+
completion_policy: policy
|
|
116
|
+
}, null, 2)}\n`);
|
|
117
|
+
grading = await loadGrading(dir, config);
|
|
118
|
+
}
|
|
119
|
+
const isSelfWrite = name => name === GRADING_DATA_FILE && Date.now() - selfWriteAt < 1500;
|
|
80
120
|
let prepared = await prepareContent(dir, config);
|
|
81
121
|
let files = await servedFiles(prepared, log);
|
|
82
|
-
let check = checkFiles(prepared.files, {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
122
|
+
let check = checkFiles(prepared.files, projectCheckOptions(config, {
|
|
123
|
+
grading: grading?.grading ?? null
|
|
124
|
+
}));
|
|
86
125
|
const state = createState();
|
|
87
126
|
const clients = new Set();
|
|
88
127
|
let hostOrigin = '';
|
|
@@ -152,7 +191,11 @@ async function startDevServer(opts) {
|
|
|
152
191
|
await handleMockApi(req, res, url.pathname.slice(4), {
|
|
153
192
|
state,
|
|
154
193
|
getGrading: () => grading,
|
|
194
|
+
getSavedGrading: savedGrading,
|
|
195
|
+
writeGradingFile,
|
|
155
196
|
getEntries: entries,
|
|
197
|
+
getCompletionPolicies: () => check.manifest?.completionPolicies ?? [],
|
|
198
|
+
saveCompletionPolicy,
|
|
156
199
|
onEvent: m => log(`[api] ${m}`)
|
|
157
200
|
});
|
|
158
201
|
return;
|
|
@@ -166,7 +209,11 @@ async function startDevServer(opts) {
|
|
|
166
209
|
...cors,
|
|
167
210
|
'Content-Type': 'application/json; charset=utf-8'
|
|
168
211
|
});
|
|
169
|
-
|
|
212
|
+
// { completion_policy, grading, completion_policies }: 콘텐츠를 직접 연 mock이 로컬 채점 · 완료 정책 흉내에 쓴다
|
|
213
|
+
res.end(JSON.stringify(grading ? {
|
|
214
|
+
...grading,
|
|
215
|
+
completion_policies: check.manifest?.completionPolicies ?? []
|
|
216
|
+
} : null));
|
|
170
217
|
return;
|
|
171
218
|
}
|
|
172
219
|
if (url.pathname === '/favicon.ico') {
|
|
@@ -237,16 +284,30 @@ async function startDevServer(opts) {
|
|
|
237
284
|
if (!res.headersSent) res.writeHead(500).end('dev server error');
|
|
238
285
|
}
|
|
239
286
|
});
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
let
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
287
|
+
// 화면(N)과 콘텐츠(N+1) 두 포트를 쓴다. --port를 주지 않았으면 막힌 쌍을 건너뛰어 다음 쌍을 쓴다
|
|
288
|
+
const tries = opts.port === undefined ? AUTO_PORT_TRIES : 1;
|
|
289
|
+
let hostPort = 0;
|
|
290
|
+
let contentPort = 0;
|
|
291
|
+
for (let i = 0; i < tries; i++) {
|
|
292
|
+
const base = (opts.port ?? DEFAULT_PORT) + i * 2;
|
|
293
|
+
try {
|
|
294
|
+
hostPort = await listen(host, base);
|
|
295
|
+
} catch (e) {
|
|
296
|
+
if (e.code !== 'EADDRINUSE' || base === 0) throw e;
|
|
297
|
+
if (i === tries - 1) throw new DevPortError(base, 'host');
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
contentPort = await listen(content, base === 0 ? 0 : hostPort + 1);
|
|
302
|
+
break;
|
|
303
|
+
} catch (e) {
|
|
304
|
+
// 콘텐츠 포트가 막히면 열어 둔 호스트도 닫아야 다음 쌍을 열거나 프로세스가 끝난다
|
|
305
|
+
await new Promise(r => host.close(r));
|
|
306
|
+
if (e.code !== 'EADDRINUSE') throw e;
|
|
307
|
+
if (i === tries - 1) throw new DevPortError(hostPort + 1, 'content');
|
|
308
|
+
}
|
|
249
309
|
}
|
|
310
|
+
if (opts.port === undefined && hostPort !== DEFAULT_PORT) log(`[dev] 기본 포트 ${DEFAULT_PORT} · ${DEFAULT_PORT + 1}이 쓰이고 있어 ${hostPort} · ${contentPort}로 열었습니다.`);
|
|
250
311
|
hostOrigin = `http://localhost:${hostPort}`;
|
|
251
312
|
contentOrigin = `http://127.0.0.1:${contentPort}`;
|
|
252
313
|
async function reload() {
|
|
@@ -255,10 +316,9 @@ async function startDevServer(opts) {
|
|
|
255
316
|
grading = await loadGrading(dir, config);
|
|
256
317
|
prepared = await prepareContent(dir, config);
|
|
257
318
|
files = await servedFiles(prepared, log);
|
|
258
|
-
check = checkFiles(prepared.files, {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
});
|
|
319
|
+
check = checkFiles(prepared.files, projectCheckOptions(config, {
|
|
320
|
+
grading: grading?.grading ?? null
|
|
321
|
+
}));
|
|
262
322
|
log(summarize(check));
|
|
263
323
|
const payload = JSON.stringify(snapshot());
|
|
264
324
|
for (const c of clients) c.write(`event: reload\ndata: ${payload}\n\n`);
|
|
@@ -276,6 +336,7 @@ async function startDevServer(opts) {
|
|
|
276
336
|
}, (_e, name) => {
|
|
277
337
|
const first = String(name ?? '').split(/[\\/]/)[0];
|
|
278
338
|
if (!first || first === outRel || first === 'node_modules' || first.startsWith('.')) return;
|
|
339
|
+
if (isSelfWrite(first)) return;
|
|
279
340
|
if (timer) clearTimeout(timer);
|
|
280
341
|
timer = setTimeout(() => void reload(), 150);
|
|
281
342
|
});
|
|
@@ -284,7 +345,7 @@ async function startDevServer(opts) {
|
|
|
284
345
|
}
|
|
285
346
|
// 프로젝트 루트의 설정 파일(원본 폴더 밖일 수 있음)
|
|
286
347
|
const configWatcher = prepared.srcDir === dir ? null : watch(dir, (_e, name) => {
|
|
287
|
-
if (name === 'elice.config.json' || name === GRADING_DATA_FILE) void reload();
|
|
348
|
+
if (name === 'elice.config.json' || name === GRADING_DATA_FILE && !isSelfWrite(name)) void reload();
|
|
288
349
|
});
|
|
289
350
|
log(summarize(check));
|
|
290
351
|
return {
|
|
@@ -306,4 +367,4 @@ async function startDevServer(opts) {
|
|
|
306
367
|
};
|
|
307
368
|
}
|
|
308
369
|
|
|
309
|
-
export { CONTENT_PREFIX, startDevServer };
|
|
370
|
+
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,53 @@ 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) elice.config.json의 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은 편집 화면만 저장). 여럿이면 완료 정책 화면이 있어야 고를 수 있다. 프로젝트 검사면 grading.json도 본다.
|
|
98
|
+
*/
|
|
99
|
+
function checkCompletion(manifest, spec, opts, 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 프로젝트는 elice.config.json에 적고 ecdk build로 다시 만들어 주세요.`, 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
|
+
if (opts.grading === null) add('grading.missing', `completionPolicies에 채점해 완료(on_graded)가 있는데 grading.json이 없어 ecdk dev가 채점을 흉내 내지 못합니다 (운영에서는 편집 화면이 정함). ecdk dev의 '내용 편집'에서 답을 저장하면 생깁니다. 예: { "type": "pattern", "answer_key": "^…$" }`, 'grading.json');
|
|
112
|
+
}
|
|
69
113
|
/** `<script type="module" data-ecdk-bundle>` 본문을 줄 수만 남기고 비운다 (줄 번호 유지) */
|
|
70
114
|
function blankBundles(html) {
|
|
71
115
|
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 +159,10 @@ function checkFiles(input, opts = {}) {
|
|
|
115
159
|
const mfile = files.find(f => f.path === spec.manifest.file);
|
|
116
160
|
if (mfile) {
|
|
117
161
|
const parsed = parseManifest(decoder.decode(mfile.data), spec);
|
|
118
|
-
if (parsed.ok)
|
|
162
|
+
if (parsed.ok) {
|
|
163
|
+
manifest = parsed.manifest;
|
|
164
|
+
for (const w of parsed.warnings ?? []) add('manifest.grading-types', `${spec.manifest.file}: ${w}`, spec.manifest.file);
|
|
165
|
+
} else add('manifest.invalid', `${spec.manifest.file}: ${parsed.error}`, spec.manifest.file);
|
|
119
166
|
} else if (kind !== 'html' && !nestedRoot) {
|
|
120
167
|
add('manifest.missing', `최상위에 ${spec.manifest.file}이 없습니다. 학생 화면·교육자 화면 등 어떤 화면이 있는지 적어 주세요 (ecdk build가 만들어 줍니다).`);
|
|
121
168
|
}
|
|
@@ -139,6 +186,8 @@ function checkFiles(input, opts = {}) {
|
|
|
139
186
|
// 메모장 등이 붙이는 BOM은 학습 참고 내용 칸에 보이지 않는 글자로 들어간다
|
|
140
187
|
if (startsWithBom(commentaryFile.data)) add('file.bom', `학습 참고 내용 파일 맨 앞에 BOM(보이지 않는 글자)이 있습니다: ${commentaryFile.path}. "UTF-8(BOM 없음)"으로 다시 저장해 주세요.`, commentaryFile.path);
|
|
141
188
|
}
|
|
189
|
+
checkCompletion(manifest, spec, opts, (id, message, path) => add(id, message, path));
|
|
190
|
+
checkTemplate(manifest, opts, message => add('build.template-unknown', message, spec.manifest.file));
|
|
142
191
|
checkScreenCode(files, manifest, (id, message) => add(id, message, spec.manifest.file));
|
|
143
192
|
}
|
|
144
193
|
const entry = manifest?.entries.learn ?? spec.manifest.defaultEntry;
|