@eliceio/cdk-cli 0.1.0-alpha.1 → 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 +171 -136
- package/es/cli.js +119 -26
- package/es/commands/build/index.d.ts +4 -1
- package/es/commands/build/index.js +28 -9
- 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 +12 -0
- package/es/commands/doctor/index.js +217 -7
- package/es/commands/guide/index.d.ts +29 -0
- package/es/commands/guide/index.js +120 -0
- 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 +45 -0
- package/es/commands/skill/index.js +145 -0
- 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/sandbox.d.ts +17 -0
- package/es/core/sandbox.js +182 -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 +9 -1
- package/es/dev/server.js +101 -25
- package/es/rules/check.js +126 -4
- 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 +29 -6
- package/es/rules.json.js +1 -1
- package/es/version.d.ts +2 -1
- package/es/version.js +5 -1
- package/guides/content-development.md +294 -0
- package/package.json +4 -2
- package/rules.json +113 -5
- package/skills/_shared/always.md +9 -0
- package/skills/elice-content-check/SKILL.md +22 -0
- package/skills/elice-content-create/SKILL.md +21 -0
- package/skills/elice-content-migrate/SKILL.md +21 -0
- 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 +206 -0
- package/templates/_shared/lib/elice-content.d.ts +112 -5
- package/templates/_shared/lib/elice-content.js +660 -62
- package/templates/blank/README.md +14 -5
- package/templates/blank/commentary.txt +2 -0
- 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 +37 -30
- package/templates/quiz/commentary.txt +2 -0
- package/templates/quiz/content.json +17 -63
- package/templates/quiz/core/behaviors.d.ts +8 -3
- package/templates/quiz/core/behaviors.js +15 -2
- 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 +106 -32
- package/templates/quiz/screens/learn.js +13 -9
- package/templates/quiz/styles.css +84 -24
- package/templates/quiz/template.json +6 -0
- package/templates/quiz/ui/templates/edit.d.ts +2 -1
- package/templates/quiz/ui/templates/edit.js +16 -13
- package/templates/quiz/ui/templates/group.js +29 -8
- package/templates/quiz/ui/templates/question.js +3 -3
- package/templates/quiz/ui/texts.js +53 -29
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,10 +15,18 @@ 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) + 콘솔 수집
|
|
21
|
-
* - 콘텐츠(127.0.0.1, 다른 출처): build와 같은
|
|
28
|
+
* - 콘텐츠(127.0.0.1, 다른 출처): build와 같은 파일(모듈 묶기 포함)을 운영 헤더(CSP sandbox allow-scripts)로.
|
|
29
|
+
* LXP 자료 파일 서버처럼 CORS 헤더를 주지 않아, 묶지 않은 모듈 스크립트 · fetch가 LXP에서처럼 막힌다
|
|
22
30
|
* - 원본이 바뀌면 다시 준비 · 검사 → 호스트가 iframe을 다시 띄움
|
|
23
31
|
*/
|
|
24
32
|
export declare function startDevServer(opts: DevServerOptions): Promise<DevServer>;
|
package/es/dev/server.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
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';
|
|
8
|
+
import { inlineModuleScripts } from '../core/sandbox.js';
|
|
6
9
|
import { checkFiles } from '../rules/check.js';
|
|
7
10
|
import '../rules/spec.js';
|
|
8
11
|
import 'fflate';
|
|
@@ -48,14 +51,41 @@ function summarize(check) {
|
|
|
48
51
|
if (check.issues.length > 5) lines.push(` … 외 ${check.issues.length - 5}개 (ecdk check로 전체 보기)`);
|
|
49
52
|
return [head, ...lines].join('\n');
|
|
50
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;
|
|
51
68
|
const listen = (server, port) => new Promise((ok, fail) => {
|
|
52
69
|
server.once('error', fail);
|
|
53
70
|
server.listen(port, '127.0.0.1', () => ok(server.address().port));
|
|
54
71
|
});
|
|
72
|
+
/** build와 같이 모듈을 묶은 파일. 묶지 못하면 원본을 그대로 주고 이유를 알린다 (LXP에서는 막힐 것) */
|
|
73
|
+
async function servedFiles(prepared, log) {
|
|
74
|
+
try {
|
|
75
|
+
const {
|
|
76
|
+
files
|
|
77
|
+
} = await inlineModuleScripts(prepared.files);
|
|
78
|
+
return new Map(files.map(f => [f.path, f.data]));
|
|
79
|
+
} catch (e) {
|
|
80
|
+
log(`[dev] ${e.message}`);
|
|
81
|
+
return new Map(prepared.files.map(f => [f.path, f.data]));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
55
84
|
/**
|
|
56
85
|
* 로컬에서 운영과 같은 조건으로 콘텐츠를 띄운다.
|
|
57
86
|
* - 호스트(localhost): LXP 흉내 화면 + elice-material 흉내 API(/api) + 콘솔 수집
|
|
58
|
-
* - 콘텐츠(127.0.0.1, 다른 출처): build와 같은
|
|
87
|
+
* - 콘텐츠(127.0.0.1, 다른 출처): build와 같은 파일(모듈 묶기 포함)을 운영 헤더(CSP sandbox allow-scripts)로.
|
|
88
|
+
* LXP 자료 파일 서버처럼 CORS 헤더를 주지 않아, 묶지 않은 모듈 스크립트 · fetch가 LXP에서처럼 막힌다
|
|
59
89
|
* - 원본이 바뀌면 다시 준비 · 검사 → 호스트가 iframe을 다시 띄움
|
|
60
90
|
*/
|
|
61
91
|
async function startDevServer(opts) {
|
|
@@ -63,11 +93,35 @@ async function startDevServer(opts) {
|
|
|
63
93
|
const log = opts.log ?? (l => process.stdout.write(`${l}\n`));
|
|
64
94
|
let config = await loadConfig(dir);
|
|
65
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;
|
|
66
120
|
let prepared = await prepareContent(dir, config);
|
|
67
|
-
let files =
|
|
68
|
-
let check = checkFiles(prepared.files, {
|
|
69
|
-
|
|
70
|
-
});
|
|
121
|
+
let files = await servedFiles(prepared, log);
|
|
122
|
+
let check = checkFiles(prepared.files, projectCheckOptions(config, {
|
|
123
|
+
grading: grading?.grading ?? null
|
|
124
|
+
}));
|
|
71
125
|
const state = createState();
|
|
72
126
|
const clients = new Set();
|
|
73
127
|
let hostOrigin = '';
|
|
@@ -89,7 +143,6 @@ async function startDevServer(opts) {
|
|
|
89
143
|
const url = new URL(req.url ?? '/', 'http://x');
|
|
90
144
|
const headers = {
|
|
91
145
|
'Content-Security-Policy': `sandbox allow-scripts; frame-ancestors ${hostOrigin}`,
|
|
92
|
-
'Access-Control-Allow-Origin': '*',
|
|
93
146
|
'X-Content-Type-Options': 'nosniff',
|
|
94
147
|
'Referrer-Policy': 'no-referrer',
|
|
95
148
|
'Cache-Control': 'no-store'
|
|
@@ -138,7 +191,11 @@ async function startDevServer(opts) {
|
|
|
138
191
|
await handleMockApi(req, res, url.pathname.slice(4), {
|
|
139
192
|
state,
|
|
140
193
|
getGrading: () => grading,
|
|
194
|
+
getSavedGrading: savedGrading,
|
|
195
|
+
writeGradingFile,
|
|
141
196
|
getEntries: entries,
|
|
197
|
+
getCompletionPolicies: () => check.manifest?.completionPolicies ?? [],
|
|
198
|
+
saveCompletionPolicy,
|
|
142
199
|
onEvent: m => log(`[api] ${m}`)
|
|
143
200
|
});
|
|
144
201
|
return;
|
|
@@ -152,7 +209,11 @@ async function startDevServer(opts) {
|
|
|
152
209
|
...cors,
|
|
153
210
|
'Content-Type': 'application/json; charset=utf-8'
|
|
154
211
|
});
|
|
155
|
-
|
|
212
|
+
// { completion_policy, grading, completion_policies }: 콘텐츠를 직접 연 mock이 로컬 채점 · 완료 정책 흉내에 쓴다
|
|
213
|
+
res.end(JSON.stringify(grading ? {
|
|
214
|
+
...grading,
|
|
215
|
+
completion_policies: check.manifest?.completionPolicies ?? []
|
|
216
|
+
} : null));
|
|
156
217
|
return;
|
|
157
218
|
}
|
|
158
219
|
if (url.pathname === '/favicon.ico') {
|
|
@@ -223,16 +284,30 @@ async function startDevServer(opts) {
|
|
|
223
284
|
if (!res.headersSent) res.writeHead(500).end('dev server error');
|
|
224
285
|
}
|
|
225
286
|
});
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
let
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
+
}
|
|
235
309
|
}
|
|
310
|
+
if (opts.port === undefined && hostPort !== DEFAULT_PORT) log(`[dev] 기본 포트 ${DEFAULT_PORT} · ${DEFAULT_PORT + 1}이 쓰이고 있어 ${hostPort} · ${contentPort}로 열었습니다.`);
|
|
236
311
|
hostOrigin = `http://localhost:${hostPort}`;
|
|
237
312
|
contentOrigin = `http://127.0.0.1:${contentPort}`;
|
|
238
313
|
async function reload() {
|
|
@@ -240,10 +315,10 @@ async function startDevServer(opts) {
|
|
|
240
315
|
config = await loadConfig(dir);
|
|
241
316
|
grading = await loadGrading(dir, config);
|
|
242
317
|
prepared = await prepareContent(dir, config);
|
|
243
|
-
files =
|
|
244
|
-
check = checkFiles(prepared.files, {
|
|
245
|
-
|
|
246
|
-
});
|
|
318
|
+
files = await servedFiles(prepared, log);
|
|
319
|
+
check = checkFiles(prepared.files, projectCheckOptions(config, {
|
|
320
|
+
grading: grading?.grading ?? null
|
|
321
|
+
}));
|
|
247
322
|
log(summarize(check));
|
|
248
323
|
const payload = JSON.stringify(snapshot());
|
|
249
324
|
for (const c of clients) c.write(`event: reload\ndata: ${payload}\n\n`);
|
|
@@ -261,6 +336,7 @@ async function startDevServer(opts) {
|
|
|
261
336
|
}, (_e, name) => {
|
|
262
337
|
const first = String(name ?? '').split(/[\\/]/)[0];
|
|
263
338
|
if (!first || first === outRel || first === 'node_modules' || first.startsWith('.')) return;
|
|
339
|
+
if (isSelfWrite(first)) return;
|
|
264
340
|
if (timer) clearTimeout(timer);
|
|
265
341
|
timer = setTimeout(() => void reload(), 150);
|
|
266
342
|
});
|
|
@@ -269,7 +345,7 @@ async function startDevServer(opts) {
|
|
|
269
345
|
}
|
|
270
346
|
// 프로젝트 루트의 설정 파일(원본 폴더 밖일 수 있음)
|
|
271
347
|
const configWatcher = prepared.srcDir === dir ? null : watch(dir, (_e, name) => {
|
|
272
|
-
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();
|
|
273
349
|
});
|
|
274
350
|
log(summarize(check));
|
|
275
351
|
return {
|
|
@@ -291,4 +367,4 @@ async function startDevServer(opts) {
|
|
|
291
367
|
};
|
|
292
368
|
}
|
|
293
369
|
|
|
294
|
-
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
|
|
|
@@ -29,6 +30,90 @@ function baseHrefError(page, href) {
|
|
|
29
30
|
if (resolved !== pageDir) return `는 상대경로 기준을 ${resolved || 'zip 최상위'}로 바꿉니다. 검사는 파일 위치 기준이라 ./만 허용합니다. 지우고 경로를 파일 위치 기준으로 써 주세요.`;
|
|
30
31
|
return null;
|
|
31
32
|
}
|
|
33
|
+
const UTF8_BOM = [0xef, 0xbb, 0xbf];
|
|
34
|
+
const startsWithBom = data => UTF8_BOM.every((b, i) => data[i] === b);
|
|
35
|
+
/** 글자로 읽는 파일: UTF-8이 아니면 한글이 깨진다 */
|
|
36
|
+
const UTF8_EXTENSIONS = new Set(['html', 'htm', 'js', 'mjs', 'css', 'json', 'svg', 'csv', 'md']);
|
|
37
|
+
/** 학생 브라우저로 내려가는 JSON에 정답처럼 보이는 키 */
|
|
38
|
+
const ANSWER_KEYS = /^(?:answers?|correct(?:_?answers?)?|answer_?key|is_?correct|solutions?|정답)$/i;
|
|
39
|
+
function answerKeyPath(value, path = []) {
|
|
40
|
+
if (Array.isArray(value)) {
|
|
41
|
+
for (const [i, v] of value.entries()) {
|
|
42
|
+
const found = answerKeyPath(v, [...path, String(i)]);
|
|
43
|
+
if (found) return found;
|
|
44
|
+
}
|
|
45
|
+
} else if (value && typeof value === 'object') {
|
|
46
|
+
for (const [k, v] of Object.entries(value)) {
|
|
47
|
+
if (ANSWER_KEYS.test(k)) return [...path, k].join('.');
|
|
48
|
+
const found = answerKeyPath(v, [...path, k]);
|
|
49
|
+
if (found) return found;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 화면 코드가 완료 정책 · 편집 화면과 맞는지 (ADR 0009, 키트 lib/는 빼고 콘텐츠 코드에서 함수 이름을 찾는 방식이라 경고만).
|
|
56
|
+
* 제출 · 채점으로 완료할 수 있는데 제출이 없으면 학생이 완료할 수 없고, 채점(on_graded)인데 편집 화면이 채점 설정을
|
|
57
|
+
* 저장하지 않으면 답을 정할 곳이 없고, 편집 · 완료 정책 화면인데 저장이 없으면 바꾼 내용이 LXP로 넘어가지 않는다.
|
|
58
|
+
*/
|
|
59
|
+
function checkScreenCode(files, manifest, add) {
|
|
60
|
+
const decoder = new TextDecoder();
|
|
61
|
+
const texts = files.filter(f => /\.(?:m?js|html?)$/i.test(f.path) && !f.path.startsWith('lib/')).map(f => decoder.decode(f.data));
|
|
62
|
+
// ecdk build가 묶은 HTML에는 키트(useSubmit · useSave 정의)가 화면 코드와 함께 들어가 나눌 수 없다.
|
|
63
|
+
// 이런 zip은 판단하지 않는다: build가 묶기 전 원본으로 이미 검사했다
|
|
64
|
+
if (texts.some(t => /<script\b[^>]*\sdata-ecdk-bundle\b/i.test(t))) return;
|
|
65
|
+
const code = texts.join('\n');
|
|
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)이 없습니다. 교육자가 고른 완료 정책이 저장되지 않습니다.`);
|
|
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로 넘어가지 않습니다.`);
|
|
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
|
+
}
|
|
113
|
+
/** `<script type="module" data-ecdk-bundle>` 본문을 줄 수만 남기고 비운다 (줄 번호 유지) */
|
|
114
|
+
function blankBundles(html) {
|
|
115
|
+
return html.replace(/(<script\b[^>]*\sdata-ecdk-bundle\b[^>]*>)([\s\S]*?)(<\/script\s*>)/gi, (_, open, body, close) => open + body.replace(/[^\n]/g, '') + close);
|
|
116
|
+
}
|
|
32
117
|
function textKind(path) {
|
|
33
118
|
const ext = extname(path);
|
|
34
119
|
if (ext === 'html' || ext === 'htm') return 'html';
|
|
@@ -74,7 +159,10 @@ function checkFiles(input, opts = {}) {
|
|
|
74
159
|
const mfile = files.find(f => f.path === spec.manifest.file);
|
|
75
160
|
if (mfile) {
|
|
76
161
|
const parsed = parseManifest(decoder.decode(mfile.data), spec);
|
|
77
|
-
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);
|
|
78
166
|
} else if (kind !== 'html' && !nestedRoot) {
|
|
79
167
|
add('manifest.missing', `최상위에 ${spec.manifest.file}이 없습니다. 학생 화면·교육자 화면 등 어떤 화면이 있는지 적어 주세요 (ecdk build가 만들어 줍니다).`);
|
|
80
168
|
}
|
|
@@ -83,6 +171,8 @@ function checkFiles(input, opts = {}) {
|
|
|
83
171
|
if (!exact.has(file)) add('manifest.entry-missing', `${spec.manifest.file}에 적은 ${mode} 화면 파일이 없습니다: ${file}`, spec.manifest.file);
|
|
84
172
|
}
|
|
85
173
|
const commentaryFile = manifest.commentary === undefined ? undefined : files.find(f => f.path === manifest.commentary);
|
|
174
|
+
// LXP 업로드는 학습 참고 내용이 없는 자료 본문을 거절한다 (qa5에서 확인. 스펙은 선택이었음)
|
|
175
|
+
if ((manifest.kind ?? spec.manifest.defaultKind) !== 'description' && manifest.commentary === undefined) add('manifest.commentary-missing', `학습 참고 내용 파일이 없어 LXP 업로드가 거절됩니다. 프로젝트 맨 위에 ${spec.manifest.commentaryFile}(이 자료의 핵심 개념 · 활동 · 문제 의도, 정답 제외)을 만들어 주세요.`, spec.manifest.file);
|
|
86
176
|
if (manifest.commentary !== undefined && !commentaryFile) add('manifest.entry-missing', `${spec.manifest.file}에 적은 학습 참고 내용 파일이 없습니다: ${manifest.commentary}`, spec.manifest.file);
|
|
87
177
|
// LXP 학습 참고 내용 칸으로 옮길 텍스트라 UTF-8이어야 한다 (메모장 ANSI · EUC-KR 저장이면 깨짐)
|
|
88
178
|
if (commentaryFile) {
|
|
@@ -93,7 +183,12 @@ function checkFiles(input, opts = {}) {
|
|
|
93
183
|
} catch {
|
|
94
184
|
add('manifest.invalid', `학습 참고 내용 파일이 UTF-8이 아닙니다: ${commentaryFile.path}. UTF-8로 다시 저장해 주세요.`, commentaryFile.path);
|
|
95
185
|
}
|
|
186
|
+
// 메모장 등이 붙이는 BOM은 학습 참고 내용 칸에 보이지 않는 글자로 들어간다
|
|
187
|
+
if (startsWithBom(commentaryFile.data)) add('file.bom', `학습 참고 내용 파일 맨 앞에 BOM(보이지 않는 글자)이 있습니다: ${commentaryFile.path}. "UTF-8(BOM 없음)"으로 다시 저장해 주세요.`, commentaryFile.path);
|
|
96
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));
|
|
191
|
+
checkScreenCode(files, manifest, (id, message) => add(id, message, spec.manifest.file));
|
|
97
192
|
}
|
|
98
193
|
const entry = manifest?.entries.learn ?? spec.manifest.defaultEntry;
|
|
99
194
|
if (!manifest && !exact.has(entry)) add('entry.missing', `최상위에 ${entry} 파일이 없습니다.`);
|
|
@@ -115,6 +210,28 @@ function checkFiles(input, opts = {}) {
|
|
|
115
210
|
byLower.set(key, [...(byLower.get(key) ?? []), f.path]);
|
|
116
211
|
if (/[^\x21-\x7e]/.test(f.path)) add('path.non-ascii', `공백이나 ASCII 밖 문자가 든 경로입니다: ${f.path}`, f.path);
|
|
117
212
|
if (matchExclude(f.path, spec.excluded.secret)) add('file.secret', `정답·비밀 파일은 올리면 안 됩니다: ${f.path}`, f.path);else if (matchExclude(f.path, spec.excluded.dev)) add('file.dev', `개발용 폴더의 파일입니다: ${f.path}`, f.path);else if (matchExclude(f.path, spec.excluded.junk)) add('file.junk', `불필요한 파일입니다: ${f.path}`, f.path);else if (!spec.allowedExtensions.includes(extname(f.path))) add('file.extension', `허용하지 않는 파일 종류입니다: ${f.path}`, f.path);else if (spec.imageExtensions.includes(extname(f.path)) && f.data.byteLength > maxImageBytes) add('file.large-image', `${fmtMB(maxImageBytes)}가 넘는 이미지입니다 (${fmtMB(f.data.byteLength)}). 줄이면 학생 화면이 빨리 열립니다: ${f.path}`, f.path);
|
|
213
|
+
const ext = extname(f.path);
|
|
214
|
+
if (!UTF8_EXTENSIONS.has(ext) || matchExclude(f.path, spec.excluded.dev)) continue;
|
|
215
|
+
let text;
|
|
216
|
+
try {
|
|
217
|
+
text = new TextDecoder('utf-8', {
|
|
218
|
+
fatal: true
|
|
219
|
+
}).decode(f.data);
|
|
220
|
+
} catch {
|
|
221
|
+
add('file.encoding', `UTF-8이 아닌 파일입니다 (EUC-KR · ANSI로 저장하면 한글이 깨집니다): ${f.path}. UTF-8로 다시 저장해 주세요.`, f.path);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
// content.json 등은 학생 브라우저로 그대로 내려간다. 파일 이름(answers.*)만 막아서는 파일 안의 정답을 못 잡는다
|
|
225
|
+
if (ext === 'json' && f.path !== spec.manifest.file) {
|
|
226
|
+
let data = null;
|
|
227
|
+
try {
|
|
228
|
+
data = JSON.parse(text);
|
|
229
|
+
} catch {
|
|
230
|
+
data = null;
|
|
231
|
+
}
|
|
232
|
+
const key = answerKeyPath(data);
|
|
233
|
+
if (key) add('content.answer-key', `학생에게 내려가는 JSON에 정답처럼 보이는 키가 있습니다: ${key}. 정답은 grading.json · LXP 채점 설정에 두고 zip에서 빼 주세요.`, f.path);
|
|
234
|
+
}
|
|
118
235
|
}
|
|
119
236
|
for (const paths of byLower.values()) {
|
|
120
237
|
if (paths.length > 1) add('path.case-collision', `대소문자만 다른 경로가 있습니다: ${paths.join(', ')}`, paths[0]);
|
|
@@ -178,15 +295,20 @@ function checkFiles(input, opts = {}) {
|
|
|
178
295
|
const baseHref = t.name === 'base' ? t.attrs.get('href')?.trim() : undefined;
|
|
179
296
|
const baseError = baseHref === undefined ? null : baseHrefError(f.path, baseHref);
|
|
180
297
|
if (baseHref !== undefined && baseError) add('ref.root-absolute', `<base href="${baseHref}">${baseError}`, f.path, t.line);
|
|
298
|
+
// LXP는 origin null sandbox에서 열고 파일 서버가 CORS 헤더를 주지 않아, 모듈 스크립트 파일은 받지 못한다
|
|
299
|
+
const src = t.name === 'script' ? t.attrs.get('src')?.trim() : undefined;
|
|
300
|
+
if (src !== undefined && t.attrs.get('type')?.trim().toLowerCase() === 'module' && classifyRef(src) === 'local' && kind !== 'dir' && !opts.bundlesModules) add('sandbox.module-src', `<script type="module" src="${src}">는 LXP에서 막혀(CORS) 화면이 "불러오는 중"에서 멈춥니다. ecdk build로 만들면 HTML 안에 묶어 넣습니다. 직접 묶으려면 본문을 넣은 <script type="module">이나 일반 <script src>로 바꿔 주세요.`, f.path, t.line);
|
|
181
301
|
if (t.name === 'img' && !t.attrs.has('alt')) add('html.img-alt', `대체 텍스트(alt)가 없는 이미지입니다.`, f.path, t.line);
|
|
182
302
|
if (t.name === 'form') add('html.form', 'form 제출은 sandbox에서 막힙니다. 버튼 click 처리와 SDK 제출을 써 주세요.', f.path, t.line);
|
|
183
303
|
}
|
|
184
304
|
if (kindOf === 'css') continue;
|
|
185
305
|
const skip = lineSkipper(text);
|
|
306
|
+
// ecdk build가 묶어 넣은 모듈 본문은 건너뛴다: 원본을 ecdk-ignore 주석과 함께 이미 검사했고, 묶으면 주석이 사라진다
|
|
307
|
+
const scanned = kindOf === 'html' ? blankBundles(text) : text;
|
|
186
308
|
for (const api of apis) {
|
|
187
309
|
// 파일마다 처음 걸린 곳 하나만. 주석뿐인 줄과 ecdk-ignore 주석으로 끈 줄은 건너뛴다 (skip.ts)
|
|
188
|
-
for (const m of
|
|
189
|
-
const line = lineAt(
|
|
310
|
+
for (const m of scanned.matchAll(api.re)) {
|
|
311
|
+
const line = lineAt(scanned, m.index);
|
|
190
312
|
if (skip.isSkipped(line, api.id)) continue;
|
|
191
313
|
add(api.id, `${api.title}: ${m[0]}`, f.path, line);
|
|
192
314
|
break;
|
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;
|