@eliceio/cdk-cli 1.2.0 → 1.3.0-contenttypes.0
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 +69 -60
- package/es/cli.js +11 -2
- package/es/commands/build/index.js +12 -0
- package/es/commands/create/index.js +2 -1
- package/es/commands/create/scaffold.d.ts +2 -2
- package/es/commands/create/scaffold.js +3 -3
- package/es/commands/dev/index.d.ts +10 -1
- package/es/commands/dev/index.js +47 -7
- package/es/core/config.d.ts +20 -9
- package/es/core/config.js +53 -12
- package/es/core/project-check.d.ts +3 -2
- package/es/core/project-check.js +14 -3
- package/es/core/regex.d.ts +11 -0
- package/es/core/regex.js +41 -0
- package/es/core/sandbox.d.ts +26 -0
- package/es/core/sandbox.js +240 -30
- package/es/dev/check.d.ts +30 -0
- package/es/dev/check.js +224 -34
- package/es/dev/grading.d.ts +20 -1
- package/es/dev/grading.js +38 -7
- package/es/dev/host-page.js +1 -1
- package/es/dev/mock-api.d.ts +3 -1
- package/es/dev/mock-api.js +20 -11
- package/es/engines/vite/index.js +1 -1
- package/es/engines/vite/plugin.d.ts +2 -0
- package/es/engines/vite/plugin.js +33 -5
- package/es/rules/answers.d.ts +13 -0
- package/es/rules/answers.js +94 -0
- package/es/rules/check.js +70 -1
- package/es/rules/index.d.ts +1 -0
- package/es/rules/index.js +1 -0
- package/es/rules/size.d.ts +31 -0
- package/es/rules/size.js +58 -0
- package/es/rules/types.d.ts +12 -0
- package/es/rules.json.js +2 -2
- package/package.json +2 -2
- package/rules.json +32 -3
- package/skills/_shared/always.md +3 -3
- package/skills/_shared/references/00-what-the-person-decides.md +1 -1
- package/skills/_shared/references/02-design-the-material.md +10 -7
- package/skills/_shared/references/03-create-the-project.md +2 -1
- package/skills/_shared/references/05-screen-code.md +49 -22
- package/skills/_shared/references/06-using-the-quiz-template.md +7 -6
- package/skills/_shared/references/08-fix-check-errors.md +23 -22
- package/skills/_shared/references/09-check.md +7 -6
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +13 -13
- package/skills/_shared/references/13-edit-screen-design.md +122 -0
- package/skills/_shared/references/14-layouts.md +96 -0
- package/skills/elice-content-check/SKILL.md +2 -2
- package/skills/elice-content-create/SKILL.md +1 -1
- package/skills/elice-content-migrate/SKILL.md +1 -1
- package/templates/_shared/lib/cdk-mock.d.ts +30 -3
- package/templates/_shared/lib/cdk-mock.js +88 -15
- package/templates/_shared/lib/elice-content-editor.js +89 -58
- package/templates/_shared/lib/elice-content.css +1313 -126
- package/templates/_shared/lib/elice-content.d.ts +162 -23
- package/templates/_shared/lib/elice-content.js +865 -84
- package/templates/_shared/lib/icons/empty-content.d.ts +2 -0
- package/templates/_shared/lib/icons/empty-content.js +11 -0
- package/templates/_shared/lib/icons/file-video.d.ts +2 -0
- package/templates/_shared/lib/icons/file-video.js +11 -0
- package/templates/_shared/lib/icons/file.d.ts +2 -0
- package/templates/_shared/lib/icons/file.js +11 -0
- package/templates/blank/README.md +5 -3
- package/templates/blank/edit.html +8 -2
- package/templates/blank/index.html +6 -1
- package/templates/blank/instructor.html +6 -1
- package/templates/blank/template.json +1 -1
- package/templates/quiz/README.md +28 -12
- package/templates/quiz/core/behaviors.d.ts +13 -7
- package/templates/quiz/core/behaviors.js +36 -51
- package/templates/quiz/core/editor.d.ts +10 -0
- package/templates/quiz/core/editor.js +471 -8
- package/templates/quiz/core/markdown.d.ts +4 -0
- package/templates/quiz/core/markdown.js +65 -11
- package/templates/quiz/core/model.d.ts +34 -1
- package/templates/quiz/core/model.js +89 -7
- package/templates/quiz/core/rich-text.d.ts +19 -0
- package/templates/quiz/core/rich-text.js +521 -0
- package/templates/quiz/edit.html +12 -3
- package/templates/quiz/index.html +12 -3
- package/templates/quiz/screens/edit.js +848 -168
- package/templates/quiz/screens/learn.js +90 -14
- package/templates/quiz/styles.css +889 -213
- package/templates/quiz/template.json +9 -2
- package/templates/quiz/ui/templates/edit.d.ts +19 -6
- package/templates/quiz/ui/templates/edit.js +666 -87
- package/templates/quiz/ui/templates/group.js +19 -8
- package/templates/quiz/ui/templates/order.js +25 -24
- package/templates/quiz/ui/templates/page.js +19 -8
- package/templates/quiz/ui/templates/question.js +2 -2
- package/templates/quiz/ui/texts.js +104 -35
- package/templates/quiz/ui/theme.css +8 -9
- package/templates/steps/README.md +77 -0
- package/templates/steps/commentary.txt +7 -0
- package/templates/steps/edit.html +21 -0
- package/templates/steps/gitignore +4 -0
- package/templates/steps/index.html +69 -0
- package/templates/steps/metadata.json +9 -0
- package/templates/steps/package.json +13 -0
- package/templates/steps/screens/edit.js +32 -0
- package/templates/steps/screens/learn.js +108 -0
- package/templates/steps/styles.css +54 -0
- package/templates/steps/template.json +6 -0
package/es/commands/dev/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { startDevServer } from '../../dev/server.js';
|
|
2
2
|
|
|
3
3
|
const usage = `사용법: ecdk dev [프로젝트 폴더] [--port 4170]
|
|
4
|
-
ecdk dev [프로젝트 폴더] --check [--screens learn,tutoring,instructor,edit] [--viewport desktop,mobile]
|
|
4
|
+
ecdk dev [프로젝트 폴더] --check [--screens learn,tutoring,instructor,edit] [--viewport desktop,mobile]
|
|
5
|
+
[--step all|1,2] [--theme light|dark|all] [--json]
|
|
5
6
|
|
|
6
7
|
로컬에서 운영과 같은 조건으로 콘텐츠를 띄운다.
|
|
7
8
|
- http://localhost:<port> LXP 흉내 화면: 학생 · 튜터링 · 교육자 화면 · 내용 편집
|
|
@@ -21,11 +22,15 @@ const usage = `사용법: ecdk dev [프로젝트 폴더] [--port 4170]
|
|
|
21
22
|
- 화면: 기본은 metadata.json에서 켠 화면 + 학생 화면이 있으면 tutoring. --screens로 고르기
|
|
22
23
|
- 폭: desktop(창 1280×860) · mobile(dev 화면의 모바일 폭 360px). --viewport로 고르기
|
|
23
24
|
- 화면 × 폭마다: 그려졌는지(글 · canvas · 그림, 8초 안에 "불러오는 중…"이 사라지는지) · 콘솔 오류 · 예외 ·
|
|
24
|
-
막힌 외부 요청(콘텐츠 CSP) · 실패한 요청(4xx · 5xx) · 가로
|
|
25
|
-
|
|
25
|
+
막힌 외부 요청(콘텐츠 CSP) · 실패한 요청(4xx · 5xx) · 가로 넘침 · 키트 배치(render.*: 가려진 스테퍼 버튼 · 스테퍼 버튼에 깔린 조작,
|
|
26
|
+
stage의 실시간 값 · 조작이 첫 화면 밖, 실시간 값이 무대 그림을 덮음, 레이아웃 영역 밖 내용),
|
|
27
|
+
그림 .ecdk/screens/<화면>-<폭>[-<테마>][-step<n>].png (매번 덮어씀, zip에 들어가지 않음)
|
|
28
|
+
- --step all|1,3: 키트 스테퍼(app.useStepper)가 있는 화면은 단계마다 찍는다 (canNext와 상관없이 그 단계로).
|
|
29
|
+
스테퍼가 없거나 단계 수 밖이면 그 화면 한 번 + 경고
|
|
30
|
+
- --theme light|dark|all: 콘텐츠에 EDS 테마(data-eds-theme)를 붙여 찍는다. all이면 둘 다. 없으면 프로젝트 그대로
|
|
26
31
|
- 브라우저: 환경 변수 ECDK_BROWSER(실행 파일 경로) → 설치된 Google Chrome · Microsoft Edge → playwright가 받아 둔 chromium
|
|
27
32
|
- --json: { ok, screens: [{ screen, viewport, width, rendered, loading, consoleErrors, pageErrors, blocked,
|
|
28
|
-
failedRequests, overflowX, screenshot, ms }], validate: { errors, warnings, issues }, browser, screenshotsDir }
|
|
33
|
+
failedRequests, overflowX, layout, theme, step, missingStep, screenshot, ms }], validate: { errors, warnings, issues }, browser, screenshotsDir }
|
|
29
34
|
- 종료 코드: 0 문제 없음 · 1 문제 있음(검사 오류, 화면 경고 포함) · 2 사용법 오류 · 3 브라우저 없음`;
|
|
30
35
|
async function run(args) {
|
|
31
36
|
const port = args.port === undefined ? undefined : Number(args.port);
|
|
@@ -34,9 +39,9 @@ async function run(args) {
|
|
|
34
39
|
output: `포트가 올바르지 않습니다: ${args.port}\n\n${usage}`
|
|
35
40
|
};
|
|
36
41
|
if (args.check) return check(args.target, port, args);
|
|
37
|
-
if (args.screens !== undefined || args.viewport !== undefined) return {
|
|
42
|
+
if (args.screens !== undefined || args.viewport !== undefined || args.step !== undefined || args.theme !== undefined) return {
|
|
38
43
|
exitCode: 2,
|
|
39
|
-
output: `--screens · --viewport는 --check와 같이 씁니다.\n\n${usage}`
|
|
44
|
+
output: `--screens · --viewport · --step · --theme는 --check와 같이 씁니다.\n\n${usage}`
|
|
40
45
|
};
|
|
41
46
|
const server = await startDevServer({
|
|
42
47
|
dir: args.target,
|
|
@@ -86,6 +91,20 @@ async function check(target, port, args) {
|
|
|
86
91
|
if ('error' in parsed) return fail(2, parsed.error, 'usage');
|
|
87
92
|
viewports = parsed.values;
|
|
88
93
|
}
|
|
94
|
+
let steps;
|
|
95
|
+
if (args.step !== undefined) {
|
|
96
|
+
const parsed = parseSteps(args.step);
|
|
97
|
+
if ('error' in parsed) return fail(2, parsed.error, 'usage');
|
|
98
|
+
steps = parsed.steps;
|
|
99
|
+
}
|
|
100
|
+
let themes;
|
|
101
|
+
if (args.theme !== undefined) {
|
|
102
|
+
if (args.theme.trim() === 'all') themes = [...mod.CHECK_THEMES];else {
|
|
103
|
+
const parsed = mod.parseList(args.theme, mod.CHECK_THEMES, '--theme');
|
|
104
|
+
if ('error' in parsed) return fail(2, `${parsed.error.replace(/\)$/, '')} · all)`, 'usage');
|
|
105
|
+
themes = parsed.values;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
89
108
|
try {
|
|
90
109
|
const report = await mod.runCheck({
|
|
91
110
|
dir: target,
|
|
@@ -97,6 +116,12 @@ async function check(target, port, args) {
|
|
|
97
116
|
} : {}),
|
|
98
117
|
...(viewports ? {
|
|
99
118
|
viewports
|
|
119
|
+
} : {}),
|
|
120
|
+
...(steps ? {
|
|
121
|
+
steps
|
|
122
|
+
} : {}),
|
|
123
|
+
...(themes ? {
|
|
124
|
+
themes
|
|
100
125
|
} : {})
|
|
101
126
|
});
|
|
102
127
|
return {
|
|
@@ -109,5 +134,20 @@ async function check(target, port, args) {
|
|
|
109
134
|
throw e;
|
|
110
135
|
}
|
|
111
136
|
}
|
|
137
|
+
/** --step: "all" 또는 1부터 센 단계 번호 목록 ("1,3") */
|
|
138
|
+
function parseSteps(value) {
|
|
139
|
+
const v = value.trim();
|
|
140
|
+
if (v === 'all') return {
|
|
141
|
+
steps: 'all'
|
|
142
|
+
};
|
|
143
|
+
const parts = v.split(',').map(x => x.trim()).filter(Boolean);
|
|
144
|
+
const nums = parts.map(Number);
|
|
145
|
+
if (parts.length === 0 || nums.some(n => !Number.isInteger(n) || n < 1)) return {
|
|
146
|
+
error: `--step 값이 올바르지 않습니다: ${value || '(비어 있음)'} (가능: all 또는 1부터 센 단계 번호, 예: 1,3)`
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
steps: [...new Set(nums)].sort((a, b) => a - b)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
112
152
|
|
|
113
|
-
export { run, usage };
|
|
153
|
+
export { parseSteps, run, usage };
|
package/es/core/config.d.ts
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 채점 방식 = `settings.grading.type`. 원본은 rules.json `manifest.graderTypes`.
|
|
3
|
-
* pattern: 정답 정규식 · rubric: AI 평가 기준. code_exec는 이번 범위 밖.
|
|
3
|
+
* pattern: 정답 정규식 · partial_pattern: 문항별 정답 정규식 + 점수 (부분 점수) · rubric: AI 평가 기준. code_exec는 이번 범위 밖.
|
|
4
4
|
* 완료 정책(on_access · on_submit · on_graded)은 LXP에 올린 뒤 자료 편집 화면의 '설정'에서 교육자가 고른다 (ADR 0012). 패키지 · CLI는 다루지 않는다
|
|
5
5
|
*/
|
|
6
|
-
export declare const GRADER_TYPES: readonly ["pattern", "rubric"];
|
|
6
|
+
export declare const GRADER_TYPES: readonly ["pattern", "partial_pattern", "rubric"];
|
|
7
7
|
export type GraderType = (typeof GRADER_TYPES)[number];
|
|
8
|
+
/** 정답 정규식 길이 상한 (서버와 같게) */
|
|
9
|
+
export declare const ANSWER_KEY_MAX = 500;
|
|
10
|
+
/** partial_pattern 문항 수 상한 (서버와 같게) */
|
|
11
|
+
export declare const PARTIAL_ITEMS_MAX = 50;
|
|
8
12
|
/**
|
|
9
13
|
* 채점 설정 = 운영 `settings.grading` (서버 §5.1 스키마, 2026-11-11 결정). 편집 화면이 saveSettings로 저장한다.
|
|
10
14
|
* 로컬은 `ecdk dev`의 편집 화면이 저장한 settings(`.ecdk/settings.json`)의 grading뿐이다 (grading.json은 없앰, ADR 0011).
|
|
11
15
|
*
|
|
12
16
|
* { "type": "pattern", "answer_key": "^q1=b;q2=a,d$" } // 정규식 하나. 답 문자열 앞뒤 공백을 자르고 전체 일치
|
|
17
|
+
* { "type": "partial_pattern", "answer_key": ["^b$", "(?i)^paris$"], "scores": [50, 50] } // 답은 문자열 배열, 맞은 문항 점수 합
|
|
13
18
|
* { "type": "rubric", "rubric": "핵심 개념 2개 이상 언급하면 만점" }
|
|
14
19
|
*
|
|
15
20
|
* 완료 정책(on_access · on_submit · on_graded)은 grading에 없다: LXP 자료 편집 화면의 '설정'에서 교육자가 고른다 (ADR 0012).
|
|
16
21
|
*/
|
|
17
|
-
export
|
|
18
|
-
type:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
export type GradingConfig = {
|
|
23
|
+
type: 'pattern'; /** 정답 정규식 (문자열 하나) */
|
|
24
|
+
answer_key: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'partial_pattern';
|
|
27
|
+
/** 문항별 정답 정규식 (1~50개) */
|
|
28
|
+
answer_key: string[];
|
|
29
|
+
/** 문항별 점수 (answer_key와 같은 길이, 0~100 정수, 합 100 이상) */
|
|
30
|
+
scores: number[];
|
|
31
|
+
} | {
|
|
32
|
+
type: 'rubric'; /** 평가 기준 */
|
|
33
|
+
rubric: string;
|
|
34
|
+
};
|
|
24
35
|
/**
|
|
25
36
|
* 로컬 채점 흉내에 쓰는 값: 저장한 settings의 채점 설정(`.ecdk/settings.json` grading). 채점 설정이 있으면 채점하고,
|
|
26
37
|
* 없으면 제출만 받는다 (완료 정책은 LXP 설정이라 dev는 흉내 내지 않는다, ADR 0012)
|
package/es/core/config.js
CHANGED
|
@@ -3,32 +3,37 @@ import { join, resolve, basename } from 'node:path';
|
|
|
3
3
|
import 'fflate';
|
|
4
4
|
import { rules } from '../rules/spec.js';
|
|
5
5
|
import { LEGACY_COMPLETION_SCREENS, LEGACY_COMPLETION_FIELDS, parseManifest, serializeManifest, COMPLETION_POLICIES_IGNORED, graderTypeError } from '../rules/manifest.js';
|
|
6
|
+
import { toJsRegex } from './regex.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* 채점 방식 = `settings.grading.type`. 원본은 rules.json `manifest.graderTypes`.
|
|
9
|
-
* pattern: 정답 정규식 · rubric: AI 평가 기준. code_exec는 이번 범위 밖.
|
|
10
|
+
* pattern: 정답 정규식 · partial_pattern: 문항별 정답 정규식 + 점수 (부분 점수) · rubric: AI 평가 기준. code_exec는 이번 범위 밖.
|
|
10
11
|
* 완료 정책(on_access · on_submit · on_graded)은 LXP에 올린 뒤 자료 편집 화면의 '설정'에서 교육자가 고른다 (ADR 0012). 패키지 · CLI는 다루지 않는다
|
|
11
12
|
*/
|
|
12
|
-
const GRADER_TYPES = ['pattern', 'rubric'];
|
|
13
|
+
const GRADER_TYPES = ['pattern', 'partial_pattern', 'rubric'];
|
|
13
14
|
/** 완료 정책 값 (LXP 설정). grading에 잘못 적었을 때 알려 주려고만 쓴다 */
|
|
14
15
|
const COMPLETION_POLICY_VALUES = ['on_access', 'on_submit', 'on_graded', 'manual', 'none'];
|
|
16
|
+
/** 정답 정규식 길이 상한 (서버와 같게) */
|
|
17
|
+
const ANSWER_KEY_MAX = 500;
|
|
18
|
+
/** partial_pattern 문항 수 상한 (서버와 같게) */
|
|
19
|
+
const PARTIAL_ITEMS_MAX = 50;
|
|
15
20
|
/**
|
|
16
21
|
* 로컬 settings (dev 전용): `ecdk dev` 편집 화면의 saveSettings(PATCH /draft settings)를 흉내 서버가 통째로(내용 + grading) 여기에 쓴다.
|
|
17
22
|
* 운영은 서버 material_version.settings. 프로젝트의 점(.) 폴더라 zip에 들어가지 않는다. build · check는 읽지 않는다
|
|
18
23
|
*/
|
|
19
24
|
const SETTINGS_DATA_FILE = '.ecdk/settings.json';
|
|
20
|
-
const GRADING_DATA_KEYS = ['type', 'answer_key', 'rubric'];
|
|
25
|
+
const GRADING_DATA_KEYS = ['type', 'answer_key', 'scores', 'rubric'];
|
|
21
26
|
/**
|
|
22
27
|
* 채점 설정 값 검사 (편집 화면이 저장한 settings.grading). 문제가 있으면 문장, 없으면 GradingConfig.
|
|
23
28
|
* 옛 모양(`type: on_access · on_submit`, `completion_policy` · `grader_type`, `match` · 객체 정답)은 바꾸는 법을 알려 준다.
|
|
24
29
|
*/
|
|
25
30
|
function parseGrading(data) {
|
|
26
|
-
const example = '예: { "type": "pattern", "answer_key": "^q1=b$" } · { "type": "rubric", "rubric": "…" }';
|
|
31
|
+
const example = '예: { "type": "pattern", "answer_key": "^q1=b$" } · { "type": "partial_pattern", "answer_key": ["^b$", "^c$"], "scores": [50, 50] } · { "type": "rubric", "rubric": "…" }';
|
|
27
32
|
if (typeof data !== 'object' || data === null || Array.isArray(data)) return `객체여야 합니다. ${example}`;
|
|
28
33
|
const record = data;
|
|
29
|
-
if (COMPLETION_POLICY_VALUES.includes(record.type)) return `완료 정책(${String(record.type)})은 grading에 적지 않습니다. 완료 정책은 LXP에 올린 뒤 자료 편집 화면의 '설정'에서 교육자가 고릅니다 (ADR 0012). grading은 { "type": "
|
|
34
|
+
if (COMPLETION_POLICY_VALUES.includes(record.type)) return `완료 정책(${String(record.type)})은 grading에 적지 않습니다. 완료 정책은 LXP에 올린 뒤 자료 편집 화면의 '설정'에서 교육자가 고릅니다 (ADR 0012). grading은 { "type": "${GRADER_TYPES.join('" | "')}" }만.`;
|
|
30
35
|
if (record.completion_policy !== undefined || record.grader_type !== undefined) return `completion_policy · grader_type은 쓰지 않습니다 (2026-11-11 결정: grading은 type 모양 그대로). ${example}`;
|
|
31
|
-
if (record.match !== undefined || record.answer_key !== undefined && typeof record.answer_key !== 'string') return `옛 형식입니다 (match · 객체 정답). 정답은 정규식 문자열 하나입니다: { "type": "pattern", "answer_key": "^q1=b;q2=a,d$" }. 퀴즈는 ecdk dev의 내용 편집에서 정답을 다시 고르면 새 형식으로 저장됩니다.`;
|
|
36
|
+
if (record.match !== undefined || record.type !== 'partial_pattern' && record.answer_key !== undefined && typeof record.answer_key !== 'string') return `옛 형식입니다 (match · 객체 정답). 정답은 정규식 문자열 하나입니다: { "type": "pattern", "answer_key": "^q1=b;q2=a,d$" }. 퀴즈는 ecdk dev의 내용 편집에서 정답을 다시 고르면 새 형식으로 저장됩니다.`;
|
|
32
37
|
const unknown = Object.keys(record).filter(k => !GRADING_DATA_KEYS.includes(k));
|
|
33
38
|
if (unknown.length > 0) return `알 수 없는 필드입니다: ${unknown.join(', ')} (가능: ${GRADING_DATA_KEYS.join(', ')})`;
|
|
34
39
|
const {
|
|
@@ -40,22 +45,58 @@ function parseGrading(data) {
|
|
|
40
45
|
if (typeError) return `type: ${typeError}`;
|
|
41
46
|
if (type === 'pattern') {
|
|
42
47
|
if (typeof answerKey !== 'string' || answerKey.trim() === '') return 'pattern 채점에는 정답 정규식 answer_key(문자열)가 필요합니다. 예: "^q1=b$"';
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} catch (e) {
|
|
46
|
-
return `answer_key가 올바른 정규식이 아닙니다: ${e.message}`;
|
|
47
|
-
}
|
|
48
|
+
const problem = regexError(answerKey);
|
|
49
|
+
if (problem) return `answer_key가 올바른 정규식이 아닙니다: ${problem}`;
|
|
48
50
|
return {
|
|
49
51
|
type,
|
|
50
52
|
answer_key: answerKey
|
|
51
53
|
};
|
|
52
54
|
}
|
|
55
|
+
if (type === 'partial_pattern') return parsePartialGrading(answerKey, record.scores);
|
|
53
56
|
if (typeof rubric !== 'string' || rubric.trim() === '') return 'rubric 채점에는 평가 기준 rubric(문자열)이 필요합니다.';
|
|
54
57
|
return {
|
|
55
58
|
type: 'rubric',
|
|
56
59
|
rubric
|
|
57
60
|
};
|
|
58
61
|
}
|
|
62
|
+
/** 정규식(서버는 Python re, 맨 앞 (?i) 등은 JS 플래그로)이 컴파일되는지. 문제가 있으면 이유 */
|
|
63
|
+
function regexError(key) {
|
|
64
|
+
try {
|
|
65
|
+
const {
|
|
66
|
+
source,
|
|
67
|
+
flags
|
|
68
|
+
} = toJsRegex(key);
|
|
69
|
+
new RegExp(source, flags);
|
|
70
|
+
return null;
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return e.message;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* partial_pattern 설정 검사 (서버 저장 규칙과 같게, 어기면 서버는 422): answer_key · scores 배열이 같은 길이 1~50,
|
|
77
|
+
* 점수는 0~100 정수이고 합이 100 이상, 정규식은 비어 있지 않고 500자 이하 · 컴파일됨
|
|
78
|
+
*/
|
|
79
|
+
function parsePartialGrading(answerKey, scores) {
|
|
80
|
+
const example = '예: { "type": "partial_pattern", "answer_key": ["^b$", "^c$"], "scores": [50, 50] }';
|
|
81
|
+
if (!Array.isArray(answerKey) || !Array.isArray(scores)) return `partial_pattern 채점에는 문항별 정답 정규식 배열 answer_key와 점수 배열 scores가 필요합니다. ${example}`;
|
|
82
|
+
if (answerKey.length < 1 || answerKey.length > PARTIAL_ITEMS_MAX) return `partial_pattern 문항은 1~${PARTIAL_ITEMS_MAX}개입니다 (지금 ${answerKey.length}개).`;
|
|
83
|
+
if (scores.length !== answerKey.length) return `answer_key(${answerKey.length}개)와 scores(${scores.length}개)의 길이가 같아야 합니다.`;
|
|
84
|
+
const badScore = scores.findIndex(n => !Number.isInteger(n) || n < 0 || n > 100);
|
|
85
|
+
if (badScore >= 0) return `scores[${badScore}]: 점수는 0~100 정수입니다 (지금 ${JSON.stringify(scores[badScore])}).`;
|
|
86
|
+
const total = scores.reduce((sum, n) => sum + n, 0);
|
|
87
|
+
if (total < 100) return `scores 합계가 100 이상이어야 합니다 (지금 ${total}). 100보다 작으면 다 맞혀도 완료되지 않습니다.`;
|
|
88
|
+
for (const [i, key] of answerKey.entries()) {
|
|
89
|
+
if (typeof key !== 'string' || key.trim() === '') return `answer_key[${i}]: 정답 정규식(문자열)이 필요합니다.`;
|
|
90
|
+
if (key.length > ANSWER_KEY_MAX) return `answer_key[${i}]: 정규식이 너무 깁니다 (${key.length}자, 최대 ${ANSWER_KEY_MAX}자).`;
|
|
91
|
+
const problem = regexError(key);
|
|
92
|
+
if (problem) return `answer_key[${i}]가 올바른 정규식이 아닙니다: ${problem}`;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
type: 'partial_pattern',
|
|
96
|
+
answer_key: [...answerKey],
|
|
97
|
+
scores: [...scores]
|
|
98
|
+
};
|
|
99
|
+
}
|
|
59
100
|
/** 옛 설정 파일 (ADR 0011에서 없앰). 있으면 경고하고 `ecdk doctor --fix`가 옮긴다. zip에는 들어가지 않는다 */
|
|
60
101
|
const CONFIG_FILE = 'elice.config.json';
|
|
61
102
|
const PACKAGE_FILE = 'package.json';
|
|
@@ -335,4 +376,4 @@ const LEGACY_FILES = Object.freeze({
|
|
|
335
376
|
grading: 'grading.json'
|
|
336
377
|
});
|
|
337
378
|
|
|
338
|
-
export { BUILD_OPTION_KEYS, CONFIG_FILE, GRADER_TYPES, LEGACY_FILES, PACKAGE_CONFIG_KEY, PACKAGE_FILE, PLATFORM_KEYS, SETTINGS_DATA_FILE, applyLegacyMigration, legacyCompletionWarning, legacyGradingTypesWarning, loadConfig, loadGrading, loadSavedSettings, parseGrading, planLegacyMigration, readPackageJson, savedGrading };
|
|
379
|
+
export { ANSWER_KEY_MAX, BUILD_OPTION_KEYS, CONFIG_FILE, GRADER_TYPES, LEGACY_FILES, PACKAGE_CONFIG_KEY, PACKAGE_FILE, PARTIAL_ITEMS_MAX, PLATFORM_KEYS, SETTINGS_DATA_FILE, applyLegacyMigration, legacyCompletionWarning, legacyGradingTypesWarning, loadConfig, loadGrading, loadSavedSettings, parseGrading, planLegacyMigration, readPackageJson, savedGrading };
|
|
@@ -16,8 +16,9 @@ export declare function findLegacySdkCopy(projectDir: string, config: ContentCon
|
|
|
16
16
|
* 프로젝트에만 있는 정보(예: 남은 옛 파일, 템플릿 목록)를 검사에 더할 때는 이 함수에만 더한다.
|
|
17
17
|
* 그래야 `ecdk validate <프로젝트>`와 `ecdk build` 결과가 어긋나지 않는다.
|
|
18
18
|
*
|
|
19
|
-
* `ecdk dev`가 쓰는 상태(.ecdk/settings.json)는
|
|
20
|
-
*
|
|
19
|
+
* `ecdk dev`가 쓰는 상태(.ecdk/settings.json)는 정답 노출 검사(sec.answer-in-bundle, 경고)에만 쓴다: 저장한 정답 글이
|
|
20
|
+
* 화면 코드 · 학습 참고 내용에 그대로 있는지. 그 밖의 검사 결과는 dev에서 무엇을 저장했는지에 따라 달라지지 않는다.
|
|
21
|
+
* 정답은 읽기만 하고 zip · 출력에 넣지 않는다. templates: 이 CLI가 가진 템플릿 · 버전 (build.template-unknown).
|
|
21
22
|
* legacyFiles: 남은 옛 파일 (project.legacy-file, elice.config.json · content.json · grading.json).
|
|
22
23
|
* legacySdkCopy: 옛 lib/cdk.js 복사본 (sdk.lib-copy). publicFiles: prepareContent의 public/ 파일 (ref.script-not-public)
|
|
23
24
|
*/
|
package/es/core/project-check.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { access } from 'node:fs/promises';
|
|
2
2
|
import { posix, join } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { answerNeedles } from '../rules/answers.js';
|
|
4
|
+
import { loadSavedSettings, LEGACY_FILES } from './config.js';
|
|
4
5
|
import { LEGACY_SDK_COPY } from './sdk.js';
|
|
5
6
|
import { knownTemplates } from './templates.js';
|
|
6
7
|
|
|
@@ -31,8 +32,9 @@ async function findLegacySdkCopy(projectDir, config) {
|
|
|
31
32
|
* 프로젝트에만 있는 정보(예: 남은 옛 파일, 템플릿 목록)를 검사에 더할 때는 이 함수에만 더한다.
|
|
32
33
|
* 그래야 `ecdk validate <프로젝트>`와 `ecdk build` 결과가 어긋나지 않는다.
|
|
33
34
|
*
|
|
34
|
-
* `ecdk dev`가 쓰는 상태(.ecdk/settings.json)는
|
|
35
|
-
*
|
|
35
|
+
* `ecdk dev`가 쓰는 상태(.ecdk/settings.json)는 정답 노출 검사(sec.answer-in-bundle, 경고)에만 쓴다: 저장한 정답 글이
|
|
36
|
+
* 화면 코드 · 학습 참고 내용에 그대로 있는지. 그 밖의 검사 결과는 dev에서 무엇을 저장했는지에 따라 달라지지 않는다.
|
|
37
|
+
* 정답은 읽기만 하고 zip · 출력에 넣지 않는다. templates: 이 CLI가 가진 템플릿 · 버전 (build.template-unknown).
|
|
36
38
|
* legacyFiles: 남은 옛 파일 (project.legacy-file, elice.config.json · content.json · grading.json).
|
|
37
39
|
* legacySdkCopy: 옛 lib/cdk.js 복사본 (sdk.lib-copy). publicFiles: prepareContent의 public/ 파일 (ref.script-not-public)
|
|
38
40
|
*/
|
|
@@ -44,10 +46,19 @@ async function projectCheckOptions(projectDir, config, extra) {
|
|
|
44
46
|
legacyFiles: await findLegacyFiles(projectDir, config),
|
|
45
47
|
legacySdkCopy: await findLegacySdkCopy(projectDir, config),
|
|
46
48
|
publicFiles: [...extra.publicFiles],
|
|
49
|
+
answerNeedles: await savedAnswerNeedles(projectDir),
|
|
47
50
|
...(extra.zipBytes !== undefined ? {
|
|
48
51
|
zipBytes: extra.zipBytes
|
|
49
52
|
} : {})
|
|
50
53
|
};
|
|
51
54
|
}
|
|
55
|
+
/** .ecdk/settings.json grading의 정답 글 (없거나 읽지 못하면 []: 정답 노출 검사만 건너뜀) */
|
|
56
|
+
async function savedAnswerNeedles(projectDir) {
|
|
57
|
+
try {
|
|
58
|
+
return answerNeedles((await loadSavedSettings(projectDir)).grading);
|
|
59
|
+
} catch {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
52
63
|
|
|
53
64
|
export { findLegacyFiles, findLegacySdkCopy, projectCheckOptions };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function toJsRegex(regex: string): {
|
|
2
|
+
source: string;
|
|
3
|
+
flags: string;
|
|
4
|
+
};
|
|
5
|
+
/** 서버 채점의 정규식 한 번 시간 상한(초 0.1). 넘으면 오답 */
|
|
6
|
+
export declare const REGEX_TIMEOUT_MS = 100;
|
|
7
|
+
/**
|
|
8
|
+
* 정답 정규식이 답 문자열(앞뒤 공백을 자름) 전체와 맞는지 (Python `re.fullmatch`와 같은 판정).
|
|
9
|
+
* 정규식이 틀리면 false. 서버는 0.1초가 넘으면 오답으로 보는데, JS는 도중에 멈출 수 없어 끝난 뒤 시간이 넘었으면 오답
|
|
10
|
+
*/
|
|
11
|
+
export declare function fullMatch(regex: string, text: string): boolean;
|
package/es/core/regex.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 정답 정규식은 서버(elice-material)가 Python `re`로 맞춘다. JS `RegExp`와 다른 점 중 맨 앞 전체 플래그만 바꿔 준다:
|
|
3
|
+
* `(?i)`(대소문자 무시) · `(?s)` · `(?m)`(조합 가능)는 Python에서 맨 앞에 있을 때 패턴 전체에 걸리고, JS는 이 문법을
|
|
4
|
+
* 받지 않으므로 떼고 같은 JS 플래그로 쓴다. 가운데 플래그 · `(?x)` 등은 그대로 두어 JS에서도 오류가 난다.
|
|
5
|
+
* 키트(`templates/_shared/lib/elice-content.js` toJsRegex) · 템플릿 mock(`cdk-mock.js`)과 같은 규칙.
|
|
6
|
+
*/
|
|
7
|
+
const LEADING_FLAGS = /^\(\?([ims]+)\)/;
|
|
8
|
+
function toJsRegex(regex) {
|
|
9
|
+
const m = LEADING_FLAGS.exec(regex);
|
|
10
|
+
if (!m) return {
|
|
11
|
+
source: regex,
|
|
12
|
+
flags: ''
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
source: regex.slice(m[0].length),
|
|
16
|
+
flags: [...new Set(m[1])].join('')
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** 서버 채점의 정규식 한 번 시간 상한(초 0.1). 넘으면 오답 */
|
|
20
|
+
const REGEX_TIMEOUT_MS = 100;
|
|
21
|
+
/**
|
|
22
|
+
* 정답 정규식이 답 문자열(앞뒤 공백을 자름) 전체와 맞는지 (Python `re.fullmatch`와 같은 판정).
|
|
23
|
+
* 정규식이 틀리면 false. 서버는 0.1초가 넘으면 오답으로 보는데, JS는 도중에 멈출 수 없어 끝난 뒤 시간이 넘었으면 오답
|
|
24
|
+
*/
|
|
25
|
+
function fullMatch(regex, text) {
|
|
26
|
+
let re;
|
|
27
|
+
try {
|
|
28
|
+
const {
|
|
29
|
+
source,
|
|
30
|
+
flags
|
|
31
|
+
} = toJsRegex(regex);
|
|
32
|
+
re = new RegExp(`^(?:${source})$`, flags);
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const started = performance.now();
|
|
37
|
+
const ok = re.test(text.trim());
|
|
38
|
+
return ok && performance.now() - started <= REGEX_TIMEOUT_MS;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { REGEX_TIMEOUT_MS, fullMatch, toJsRegex };
|
package/es/core/sandbox.d.ts
CHANGED
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
import type { SourceFile } from './collect.js';
|
|
2
2
|
/** build가 묶어 넣은 모듈 스크립트 표시 (검사가 본문을 건너뜀) */
|
|
3
3
|
export declare const BUNDLE_ATTR = "data-ecdk-bundle";
|
|
4
|
+
/** 화면을 열 때 실행되지 않는 chunk가 합쳐 이만큼 이상이면 따로 파일로 낸다 (그보다 작으면 요청을 늘리지 않고 HTML에) */
|
|
5
|
+
export declare const LAZY_MIN_BYTES: number;
|
|
6
|
+
/** Vite chunk 관계 (generateBundle의 chunk.imports · dynamicImports, zip 경로) */
|
|
7
|
+
export type ChunkGraph = Map<string, {
|
|
8
|
+
imports: string[];
|
|
9
|
+
dynamicImports: string[];
|
|
10
|
+
}>;
|
|
11
|
+
/** 화면(HTML)마다 열 때 받는 크기와 나중에 받는 파일 */
|
|
12
|
+
export interface SandboxScreen {
|
|
13
|
+
page: string;
|
|
14
|
+
/** 화면을 열 때 받는 JS (HTML 안 스크립트 + `<script src>` 파일, 바이트) */
|
|
15
|
+
scriptBytes: number;
|
|
16
|
+
/** 화면을 열 때 받는 CSS (`<style>` + `<link rel="stylesheet">` 파일, 바이트) */
|
|
17
|
+
styleBytes: number;
|
|
18
|
+
/** 필요할 때만 받는 파일 (동적 import()로만 닿는 chunk) */
|
|
19
|
+
lazyFiles: string[];
|
|
20
|
+
lazyBytes: number;
|
|
21
|
+
/** 나중에 받을 chunk가 있는데 나누지 못해 HTML에 넣은 이유 */
|
|
22
|
+
lazySkipped?: string | undefined;
|
|
23
|
+
}
|
|
4
24
|
export interface SandboxReport {
|
|
5
25
|
/** 모듈 스크립트를 묶어 넣은 HTML */
|
|
6
26
|
pages: string[];
|
|
27
|
+
/** 화면마다 크기 (HTML 파일 전부) */
|
|
28
|
+
screens: SandboxScreen[];
|
|
29
|
+
/** 나중에 받는 파일로 낸 chunk (zip에 남김) */
|
|
30
|
+
lazyFiles: string[];
|
|
7
31
|
}
|
|
8
32
|
export interface InlineOptions {
|
|
9
33
|
/** esbuild 작업 폴더 (기본: 실행 폴더). 테스트에서 프로젝트 폴더 안 실행을 흉내 낼 때 */
|
|
10
34
|
workingDir?: string | undefined;
|
|
11
35
|
minify?: boolean | undefined;
|
|
12
36
|
sourcemap?: boolean | undefined;
|
|
37
|
+
/** Vite chunk 관계. 있으면 화면을 열 때 실행되지 않는 큰 chunk를 나중에 받는 파일로 낸다 */
|
|
38
|
+
chunks?: ChunkGraph | undefined;
|
|
13
39
|
}
|
|
14
40
|
/** HTML의 모듈 스크립트(src)를 묶어 본문으로 넣는다. 바뀐 파일만 새로 만들어 돌려준다 */
|
|
15
41
|
export declare function inlineModuleScripts(files: SourceFile[], opts?: InlineOptions): Promise<{
|