@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
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
|
3
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { compareVersions } from '../../rules/semver.js';
|
|
8
|
+
|
|
9
|
+
const usage = `사용법: ecdk skill install [--project] [--force] [--json]
|
|
10
|
+
|
|
11
|
+
Claude Code가 Elice 학습자료 요청을 알아보고 ecdk guide를 읽게 하는 스킬(stub)을 설치한다.
|
|
12
|
+
기본은 ~/.claude/skills/ (모든 프로젝트), --project면 현재 폴더의 .claude/skills/.
|
|
13
|
+
같은 버전이면 건너뛰고, 옛 버전이면 바꾼다. CLI보다 새 버전이거나 손으로 고친 스킬은 --force일 때만 바꾼다.
|
|
14
|
+
|
|
15
|
+
종료 코드: 0 성공 · 1 손으로 고친 스킬이 있어 건너뜀 · 2 잘못된 사용`;
|
|
16
|
+
/** CLI 패키지의 skills/ (es/commands/skill/와 src/commands/skill/ 모두 세 단계 위) */
|
|
17
|
+
const SKILLS_ROOT = fileURLToPath(new URL('../../../skills', import.meta.url));
|
|
18
|
+
/** 모든 스킬에 끼워 넣는 공통 규칙 */
|
|
19
|
+
const SHARED_DIR = '_shared';
|
|
20
|
+
const PACKAGE_VERSION = JSON.parse(readFileSync(fileURLToPath(new URL('../../../package.json', import.meta.url)), 'utf8')).version;
|
|
21
|
+
/** 설치한 스킬 맨 끝 줄. 버전 · 내용 지문으로 오래됨 · 손으로 고침을 알아본다 */
|
|
22
|
+
const STAMP = /<!-- ecdk-skill: (\S+) (\S+) (sha256-[A-Za-z0-9+/=]+) -->\s*$/;
|
|
23
|
+
const sha = text => `sha256-${createHash('sha256').update(text).digest('base64')}`;
|
|
24
|
+
/** 패키지에 든 스킬 이름 (공통 폴더 제외) */
|
|
25
|
+
function skillNames(root = SKILLS_ROOT) {
|
|
26
|
+
return readdirSync(root, {
|
|
27
|
+
withFileTypes: true
|
|
28
|
+
}).filter(d => d.isDirectory() && d.name !== SHARED_DIR).map(d => d.name).sort();
|
|
29
|
+
}
|
|
30
|
+
/** 원본에 공통 규칙과 버전 줄을 넣는다. 지문은 버전 줄을 뺀 본문으로 */
|
|
31
|
+
function renderSkill(name, root = SKILLS_ROOT, version = PACKAGE_VERSION) {
|
|
32
|
+
const always = readFileSync(join(root, SHARED_DIR, 'always.md'), 'utf8').trim();
|
|
33
|
+
const body = readFileSync(join(root, name, 'SKILL.md'), 'utf8').replace('{{always}}', always).replace(/\n*\{\{version\}\}\s*$/, '').trimEnd();
|
|
34
|
+
return `${body}\n\n<!-- ecdk-skill: ${name} ${version} ${sha(body)} -->\n`;
|
|
35
|
+
}
|
|
36
|
+
/** 설치 위치: --project면 현재 폴더, 아니면 홈 */
|
|
37
|
+
function skillsDir(opts) {
|
|
38
|
+
return opts.project ? join(resolve(opts.cwd ?? '.'), '.claude', 'skills') : join(opts.home ?? homedir(), '.claude', 'skills');
|
|
39
|
+
}
|
|
40
|
+
/** 설치된 스킬의 상태. 지문이 본문과 다르면 손으로 고친 것 */
|
|
41
|
+
function inspectSkill(dir, name, version = PACKAGE_VERSION) {
|
|
42
|
+
const path = join(dir, name, 'SKILL.md');
|
|
43
|
+
if (!existsSync(path)) return {
|
|
44
|
+
name,
|
|
45
|
+
path,
|
|
46
|
+
state: 'missing'
|
|
47
|
+
};
|
|
48
|
+
const text = readFileSync(path, 'utf8');
|
|
49
|
+
const stamp = STAMP.exec(text);
|
|
50
|
+
if (!stamp) return {
|
|
51
|
+
name,
|
|
52
|
+
path,
|
|
53
|
+
state: 'modified'
|
|
54
|
+
};
|
|
55
|
+
const body = text.slice(0, stamp.index).trimEnd();
|
|
56
|
+
if (sha(body) !== stamp[3]) return {
|
|
57
|
+
name,
|
|
58
|
+
path,
|
|
59
|
+
state: 'modified',
|
|
60
|
+
version: stamp[2]
|
|
61
|
+
};
|
|
62
|
+
const installed = stamp[2] ?? '';
|
|
63
|
+
// 홈 스킬은 모든 프로젝트가 같이 쓰므로, 더 새 CLI가 설치한 스킬을 옛 CLI가 내리지 않는다
|
|
64
|
+
const order = installed === version ? 0 : compareVersions(installed, version);
|
|
65
|
+
const state = order === 0 ? 'current' : order !== undefined && order > 0 ? 'newer' : 'outdated';
|
|
66
|
+
return {
|
|
67
|
+
name,
|
|
68
|
+
path,
|
|
69
|
+
state,
|
|
70
|
+
version: installed
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function install(opts) {
|
|
74
|
+
const root = opts.root ?? SKILLS_ROOT;
|
|
75
|
+
const version = opts.version ?? PACKAGE_VERSION;
|
|
76
|
+
const dir = skillsDir(opts);
|
|
77
|
+
const skills = [];
|
|
78
|
+
for (const name of skillNames(root)) {
|
|
79
|
+
const status = inspectSkill(dir, name, version);
|
|
80
|
+
const write = async () => {
|
|
81
|
+
await mkdir(join(dir, name), {
|
|
82
|
+
recursive: true
|
|
83
|
+
});
|
|
84
|
+
await writeFile(status.path, renderSkill(name, root, version));
|
|
85
|
+
};
|
|
86
|
+
if (status.state === 'missing') {
|
|
87
|
+
await write();
|
|
88
|
+
skills.push({
|
|
89
|
+
...status,
|
|
90
|
+
action: 'installed'
|
|
91
|
+
});
|
|
92
|
+
} else if (status.state === 'current') {
|
|
93
|
+
skills.push({
|
|
94
|
+
...status,
|
|
95
|
+
action: 'skipped'
|
|
96
|
+
});
|
|
97
|
+
} else if (status.state === 'outdated' || opts.force) {
|
|
98
|
+
await write();
|
|
99
|
+
skills.push({
|
|
100
|
+
...status,
|
|
101
|
+
action: 'updated'
|
|
102
|
+
});
|
|
103
|
+
} else if (status.state === 'newer') {
|
|
104
|
+
skills.push({
|
|
105
|
+
...status,
|
|
106
|
+
action: 'newer'
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
skills.push({
|
|
110
|
+
...status,
|
|
111
|
+
action: 'kept'
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
dir,
|
|
117
|
+
version,
|
|
118
|
+
skills
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const ACTION = {
|
|
122
|
+
installed: '설치',
|
|
123
|
+
updated: '바꿈',
|
|
124
|
+
skipped: '최신이라 건너뜀',
|
|
125
|
+
kept: '손으로 고친 스킬이라 그대로 둠 (--force로 바꿈)',
|
|
126
|
+
newer: 'CLI보다 새 버전이라 그대로 둠 (--force로 바꿈)'
|
|
127
|
+
};
|
|
128
|
+
async function run(args) {
|
|
129
|
+
if (args.sub !== 'install') return {
|
|
130
|
+
exitCode: 2,
|
|
131
|
+
output: `알 수 없는 하위 명령: ${args.sub ?? '(없음)'}\n\n${usage}`
|
|
132
|
+
};
|
|
133
|
+
const result = await install({
|
|
134
|
+
project: args.project,
|
|
135
|
+
force: args.force
|
|
136
|
+
});
|
|
137
|
+
const kept = result.skills.some(s => s.action === 'kept');
|
|
138
|
+
const output = args.json ? JSON.stringify(result, null, 2) : [`스킬 위치: ${result.dir} (ecdk ${result.version})`, ...result.skills.map(s => ` ${s.name}: ${ACTION[s.action]}`), '', 'Claude Code를 새로 열면 적용됩니다.'].join('\n');
|
|
139
|
+
return {
|
|
140
|
+
exitCode: kept ? 1 : 0,
|
|
141
|
+
output
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export { compareVersions, inspectSkill, install, renderSkill, run, skillNames, skillsDir, usage };
|
package/es/core/config.d.ts
CHANGED
|
@@ -1,25 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* 둘이 같은지는 docs.test.ts가 대조한다. 수동 채점 manual · 채점 없음 none은 Custom HTML에서 쓰지
|
|
2
|
+
* 완료 정책 (ADR 0009). 원본은 rules.json `manifest.completionPolicies`이고, 타입 검사를 위해 여기 리터럴로 둔다.
|
|
3
|
+
* 둘이 같은지는 docs.test.ts가 대조한다. 수동 채점 manual · 채점 없음 none은 Custom HTML에서 쓰지 않음.
|
|
4
|
+
* 자료가 지원하는 완료 정책은 metadata `completionPolicies`(서버가 첫 값으로 정함), 바꾸기는 완료 정책 화면 · SDK
|
|
5
|
+
* `saveCompletionPolicy`(PATCH completion_policy). settings.grading에는 없다
|
|
4
6
|
*/
|
|
5
|
-
export declare const
|
|
6
|
-
export type GradingType = (typeof GRADING_TYPES)[number];
|
|
7
|
+
export declare const COMPLETION_POLICIES: readonly ["on_access", "on_submit", "on_graded"];
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* 채점 방식 = `settings.grading.type` (on_graded일 때만). 원본은 rules.json `manifest.graderTypes`.
|
|
10
|
+
* pattern: 정답 정규식 · rubric: AI 평가 기준. code_exec는 이번 범위 밖
|
|
10
11
|
*/
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
export declare const GRADER_TYPES: readonly ["pattern", "rubric"];
|
|
13
|
+
export type CompletionPolicy = (typeof COMPLETION_POLICIES)[number];
|
|
14
|
+
export type GraderType = (typeof GRADER_TYPES)[number];
|
|
15
|
+
/**
|
|
16
|
+
* 채점 설정 = 운영 `settings.grading` (서버 §5.1 스키마, 2026-11-11 결정). 편집 화면이 saveSettings로 저장한다.
|
|
17
|
+
* 로컬은 프로젝트 맨 위 `grading.json`이고 `ecdk dev`의 편집 화면이 저장하면 이 파일에 쓴다. zip에는 들어가지 않는다 (정답).
|
|
18
|
+
*
|
|
19
|
+
* { "type": "pattern", "answer_key": "^q1=b;q2=a,d$" } // 정규식 하나. 답 문자열 앞뒤 공백을 자르고 전체 일치
|
|
20
|
+
* { "type": "rubric", "rubric": "핵심 개념 2개 이상 언급하면 만점" }
|
|
21
|
+
*
|
|
22
|
+
* on_access · on_submit은 grading에서 빠졌다 (완료 정책은 completion_policy, 2026-11-11).
|
|
23
|
+
*/
|
|
24
|
+
export interface GradingConfig {
|
|
25
|
+
type: GraderType;
|
|
26
|
+
/** pattern: 정답 정규식 (문자열 하나) */
|
|
27
|
+
answer_key?: string;
|
|
28
|
+
/** rubric: 평가 기준 */
|
|
16
29
|
rubric?: string;
|
|
17
30
|
}
|
|
18
|
-
/** 로컬
|
|
19
|
-
export interface
|
|
20
|
-
|
|
31
|
+
/** 로컬 채점 흉내에 쓰는 값: 완료 정책(로컬 `.ecdk/completion.json` · completionPolicies 첫 값)과 채점 설정(grading.json) */
|
|
32
|
+
export interface LocalGrading {
|
|
33
|
+
completion_policy: CompletionPolicy;
|
|
34
|
+
/** grading.json (없으면 null) */
|
|
35
|
+
grading: GradingConfig | null;
|
|
21
36
|
}
|
|
22
37
|
export declare const GRADING_DATA_FILE = "grading.json";
|
|
38
|
+
/**
|
|
39
|
+
* 로컬 완료 정책 (dev 전용): `ecdk dev` 완료 정책 화면의 saveCompletionPolicy를 흉내 서버가 여기에 쓴다.
|
|
40
|
+
* 운영은 서버 material_version.completion_policy. 프로젝트의 점(.) 폴더라 zip에 들어가지 않는다
|
|
41
|
+
*/
|
|
42
|
+
export declare const COMPLETION_DATA_FILE = ".ecdk/completion.json";
|
|
43
|
+
/** completionPolicies가 없을 때(검사 오류) ecdk dev가 흉내 내는 정책 (제출하면 완료) */
|
|
44
|
+
export declare const DEFAULT_COMPLETION_POLICY: CompletionPolicy;
|
|
45
|
+
/**
|
|
46
|
+
* 채점 설정 값 검사 (grading.json · 편집 화면이 저장한 settings.grading). 문제가 있으면 문장, 없으면 GradingConfig.
|
|
47
|
+
* 옛 모양(`type: on_access · on_submit`, `completion_policy` · `grader_type`, `match` · 객체 정답)은 바꾸는 법을 알려 준다.
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseGrading(data: unknown): GradingConfig | string;
|
|
23
50
|
export interface ContentConfig {
|
|
24
51
|
/** 콘텐츠 원본 폴더 (프로젝트 기준). 기본 '.' */
|
|
25
52
|
root: string;
|
|
@@ -31,8 +58,16 @@ export interface ContentConfig {
|
|
|
31
58
|
kind?: 'material' | 'description';
|
|
32
59
|
/** 화면별 진입 파일 → build가 metadata.json로 만든다. 없으면 원본의 metadata.json, 그것도 없으면 { learn: 'index.html' } */
|
|
33
60
|
screens?: Record<string, string>;
|
|
34
|
-
/**
|
|
35
|
-
|
|
61
|
+
/**
|
|
62
|
+
* 지원하는 완료 정책 → metadata.json `completionPolicies` (ADR 0009 2026-11-11 결정 2). 서버는 첫 값으로 완료 정책을 정한다.
|
|
63
|
+
* 하나면 고정(퀴즈 ["on_graded"]), 여럿이면 완료 정책 화면(screens.completionPolicy)이 그 안에서 바꾼다. 자료 본문은 필수
|
|
64
|
+
*/
|
|
65
|
+
completionPolicies?: CompletionPolicy[];
|
|
66
|
+
/**
|
|
67
|
+
* @deprecated 2026-11-10 삭제 (ADR 0008 · 0009). 완료 정책은 completionPolicies · 완료 정책 화면이, 채점 방식은 편집 화면이 정한다.
|
|
68
|
+
* 남아 있으면 build · doctor가 경고만 하고 metadata.json에 옮기지 않는다
|
|
69
|
+
*/
|
|
70
|
+
gradingTypes?: unknown;
|
|
36
71
|
/** true면 build가 JS · CSS · JSON을 줄여 zip에 넣는다 (용량 줄이기). 기본 false */
|
|
37
72
|
minify?: boolean;
|
|
38
73
|
/**
|
|
@@ -48,8 +83,17 @@ export interface ContentConfig {
|
|
|
48
83
|
export declare const CONFIG_FILE = "elice.config.json";
|
|
49
84
|
/** 1단계는 JSON만. `.ts` 설정은 Node 20의 TS 실행 지원 문제로 엔진 작업(3단계)과 함께 결정. */
|
|
50
85
|
export declare function loadConfig(projectDir: string): Promise<ContentConfig>;
|
|
86
|
+
/** elice.config.json에 옛 `gradingTypes`가 남아 있을 때 build · doctor가 보여 줄 경고. 없으면 null */
|
|
87
|
+
export declare function legacyGradingTypesWarning(config: ContentConfig): string | null;
|
|
88
|
+
/**
|
|
89
|
+
* 로컬 완료 정책 (ecdk dev 흉내): `.ecdk/completion.json`(ecdk dev 완료 정책 화면이 저장)이 completionPolicies 안에
|
|
90
|
+
* 있으면 그것, 아니면 completionPolicies 첫 값(서버가 업로드 때 정하는 값), 없으면 on_submit.
|
|
91
|
+
* completionPolicies가 바뀌어 저장해 둔 값이 목록에서 빠졌으면 첫 값으로 돌아간다
|
|
92
|
+
*/
|
|
93
|
+
export declare function loadCompletionPolicy(projectDir: string, config: ContentConfig): Promise<CompletionPolicy>;
|
|
94
|
+
/** grading.json (없으면 null). 문제가 있으면 오류 */
|
|
95
|
+
export declare function loadGradingFile(projectDir: string): Promise<GradingConfig | null>;
|
|
51
96
|
/**
|
|
52
|
-
* 로컬
|
|
53
|
-
* 지원 유형이 없으면(문제 설명) undefined.
|
|
97
|
+
* 로컬 채점 흉내용 값: 완료 정책 + grading.json. 문제 설명(채점 없음)은 undefined
|
|
54
98
|
*/
|
|
55
|
-
export declare function loadGrading(projectDir: string, config: ContentConfig): Promise<
|
|
99
|
+
export declare function loadGrading(projectDir: string, config: ContentConfig): Promise<LocalGrading | undefined>;
|
package/es/core/config.js
CHANGED
|
@@ -1,16 +1,69 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import 'fflate';
|
|
4
|
-
import {
|
|
4
|
+
import { parseCompletionPolicies, completionPolicyError, graderTypeError, COMPLETION_POLICIES_EXAMPLE } from '../rules/manifest.js';
|
|
5
5
|
import { rules } from '../rules/spec.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* 둘이 같은지는 docs.test.ts가 대조한다. 수동 채점 manual · 채점 없음 none은 Custom HTML에서 쓰지
|
|
8
|
+
* 완료 정책 (ADR 0009). 원본은 rules.json `manifest.completionPolicies`이고, 타입 검사를 위해 여기 리터럴로 둔다.
|
|
9
|
+
* 둘이 같은지는 docs.test.ts가 대조한다. 수동 채점 manual · 채점 없음 none은 Custom HTML에서 쓰지 않음.
|
|
10
|
+
* 자료가 지원하는 완료 정책은 metadata `completionPolicies`(서버가 첫 값으로 정함), 바꾸기는 완료 정책 화면 · SDK
|
|
11
|
+
* `saveCompletionPolicy`(PATCH completion_policy). settings.grading에는 없다
|
|
10
12
|
*/
|
|
11
|
-
const
|
|
13
|
+
const COMPLETION_POLICIES = ['on_access', 'on_submit', 'on_graded'];
|
|
14
|
+
/**
|
|
15
|
+
* 채점 방식 = `settings.grading.type` (on_graded일 때만). 원본은 rules.json `manifest.graderTypes`.
|
|
16
|
+
* pattern: 정답 정규식 · rubric: AI 평가 기준. code_exec는 이번 범위 밖
|
|
17
|
+
*/
|
|
18
|
+
const GRADER_TYPES = ['pattern', 'rubric'];
|
|
12
19
|
const GRADING_DATA_FILE = 'grading.json';
|
|
13
|
-
|
|
20
|
+
/**
|
|
21
|
+
* 로컬 완료 정책 (dev 전용): `ecdk dev` 완료 정책 화면의 saveCompletionPolicy를 흉내 서버가 여기에 쓴다.
|
|
22
|
+
* 운영은 서버 material_version.completion_policy. 프로젝트의 점(.) 폴더라 zip에 들어가지 않는다
|
|
23
|
+
*/
|
|
24
|
+
const COMPLETION_DATA_FILE = '.ecdk/completion.json';
|
|
25
|
+
const GRADING_DATA_KEYS = ['type', 'answer_key', 'rubric'];
|
|
26
|
+
/** completionPolicies가 없을 때(검사 오류) ecdk dev가 흉내 내는 정책 (제출하면 완료) */
|
|
27
|
+
const DEFAULT_COMPLETION_POLICY = 'on_submit';
|
|
28
|
+
/**
|
|
29
|
+
* 채점 설정 값 검사 (grading.json · 편집 화면이 저장한 settings.grading). 문제가 있으면 문장, 없으면 GradingConfig.
|
|
30
|
+
* 옛 모양(`type: on_access · on_submit`, `completion_policy` · `grader_type`, `match` · 객체 정답)은 바꾸는 법을 알려 준다.
|
|
31
|
+
*/
|
|
32
|
+
function parseGrading(data) {
|
|
33
|
+
const example = '예: { "type": "pattern", "answer_key": "^q1=b$" } · { "type": "rubric", "rubric": "…" }';
|
|
34
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data)) return `객체여야 합니다. ${example}`;
|
|
35
|
+
const record = data;
|
|
36
|
+
if (record.type === 'manual' || record.type === 'none') return completionPolicyError(record.type, COMPLETION_POLICIES) ?? '';
|
|
37
|
+
if (record.type === 'on_access' || record.type === 'on_submit') return `완료 정책(${record.type})은 grading에 적지 않습니다 (2026-11-11). 운영은 completion_policy(metadata completionPolicies 첫 값 · 완료 정책 화면), ecdk dev에서는 completionPolicies 첫 값 · 완료 정책 화면(${COMPLETION_DATA_FILE})으로 정합니다. grading은 { "type": "pattern" | "rubric" }만.`;
|
|
38
|
+
if (record.completion_policy !== undefined || record.grader_type !== undefined) return `completion_policy · grader_type은 쓰지 않습니다 (2026-11-11 결정: grading은 type 모양 그대로). ${example}`;
|
|
39
|
+
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의 내용 편집에서 정답을 다시 고르면 새 형식으로 저장됩니다.`;
|
|
40
|
+
const unknown = Object.keys(record).filter(k => !GRADING_DATA_KEYS.includes(k));
|
|
41
|
+
if (unknown.length > 0) return `알 수 없는 필드입니다: ${unknown.join(', ')} (가능: ${GRADING_DATA_KEYS.join(', ')})`;
|
|
42
|
+
const {
|
|
43
|
+
type,
|
|
44
|
+
answer_key: answerKey,
|
|
45
|
+
rubric
|
|
46
|
+
} = record;
|
|
47
|
+
const typeError = graderTypeError(type, GRADER_TYPES);
|
|
48
|
+
if (typeError) return `type: ${typeError}`;
|
|
49
|
+
if (type === 'pattern') {
|
|
50
|
+
if (typeof answerKey !== 'string' || answerKey.trim() === '') return 'pattern 채점에는 정답 정규식 answer_key(문자열)가 필요합니다. 예: "^q1=b$"';
|
|
51
|
+
try {
|
|
52
|
+
new RegExp(answerKey);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
return `answer_key가 올바른 정규식이 아닙니다: ${e.message}`;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
type,
|
|
58
|
+
answer_key: answerKey
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (typeof rubric !== 'string' || rubric.trim() === '') return 'rubric 채점에는 평가 기준 rubric(문자열)이 필요합니다.';
|
|
62
|
+
return {
|
|
63
|
+
type: 'rubric',
|
|
64
|
+
rubric
|
|
65
|
+
};
|
|
66
|
+
}
|
|
14
67
|
const CONFIG_FILE = 'elice.config.json';
|
|
15
68
|
/** JSON 형식 오류에 파일 이름을 붙인다 (SyntaxError만 나오면 어느 파일인지 모름) */
|
|
16
69
|
function parseJson(raw, fail) {
|
|
@@ -47,17 +100,22 @@ async function loadConfig(projectDir) {
|
|
|
47
100
|
if (json.screens !== undefined && !isStringRecord(json.screens)) throw fail('screens는 켤 화면만 파일 이름으로 적습니다: { "learn": "index.html", "instructor": "..." } (metadata.json의 { "enabled", "entry" } 모양과 다름).');
|
|
48
101
|
// 오타는 metadata.json 파서와 같은 문구로 막는다 (조용히 빠지면 그 화면이 꺼진 채로 만들어짐)
|
|
49
102
|
const unknownScreen = Object.keys(json.screens ?? {}).find(m => !rules.manifest.modes.includes(m));
|
|
103
|
+
if (unknownScreen === 'completion' || unknownScreen === 'grading') throw fail(`완료 정책 화면의 이름은 completionPolicy입니다 (2026-11-11): screens.${unknownScreen} → "completionPolicy": "${json.screens?.[unknownScreen] ?? 'completion.html'}"`);
|
|
50
104
|
if (unknownScreen) throw fail(`알 수 없는 화면입니다: ${unknownScreen} (가능: ${rules.manifest.modes.join(', ')})`);
|
|
51
105
|
if (json.minify !== undefined && typeof json.minify !== 'boolean') throw fail('minify는 true 또는 false여야 합니다.');
|
|
52
106
|
if (json.sourcemap !== undefined && typeof json.sourcemap !== 'boolean') throw fail('sourcemap은 true 또는 false여야 합니다.');
|
|
53
107
|
if (json.sourcemap && !json.minify) throw fail('sourcemap은 minify와 함께 씁니다 ("minify": true). 줄이지 않으면 원본 그대로라 필요 없습니다.');
|
|
54
108
|
if (json.template !== undefined && typeof json.template !== 'string') throw fail('template은 문자열이어야 합니다 (ecdk create가 적는 값).');
|
|
55
|
-
if (json.answers !== undefined) throw fail(
|
|
109
|
+
if (json.answers !== undefined) throw fail(`answers 대신 ${GRADING_DATA_FILE}에 채점 설정을 적어 주세요 (예: { "type": "pattern", "answer_key": "^q1=b$" }). 운영에서는 편집 화면이 정합니다.`);
|
|
56
110
|
const legacy = json;
|
|
57
|
-
if (legacy.grading !== undefined) throw fail(`grading
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
111
|
+
if (legacy.grading !== undefined) throw fail(`grading(채점 설정)은 elice.config.json이 아니라 ${GRADING_DATA_FILE}에 적어 주세요. 운영에서는 편집 화면이 정합니다.`);
|
|
112
|
+
const old = json;
|
|
113
|
+
if (old.completion !== undefined) throw fail(`completion 대신 completionPolicies(지원하는 완료 정책 배열, 첫 값이 기본)를 적어 주세요 (2026-11-11). ${COMPLETION_POLICIES_EXAMPLE}`);
|
|
114
|
+
if (json.completionPolicies !== undefined) {
|
|
115
|
+
if (json.kind === 'description') throw fail('문제 설명(kind: description)은 완료 · 채점하지 않으므로 completionPolicies를 넣지 않습니다.');
|
|
116
|
+
const parsed = parseCompletionPolicies(json.completionPolicies, rules);
|
|
117
|
+
if (typeof parsed === 'string') throw fail(parsed);
|
|
118
|
+
json.completionPolicies = parsed;
|
|
61
119
|
}
|
|
62
120
|
if (json.commentary !== undefined && typeof json.commentary !== 'string') throw fail('commentary는 학습 참고 내용 파일 이름(문자열)이어야 합니다. 예: "commentary.txt"');
|
|
63
121
|
if (json.kind !== undefined && json.kind !== 'material' && json.kind !== 'description') throw fail('kind는 material(자료 본문) 또는 description(문제 설명)이어야 합니다.');
|
|
@@ -67,43 +125,61 @@ async function loadConfig(projectDir) {
|
|
|
67
125
|
const extra = Object.keys(json.screens).filter(m => !allowed.includes(m));
|
|
68
126
|
if (extra.length > 0) throw fail(`${json.kind === 'description' ? '문제 설명(kind: description)' : json.kind}은 ${allowed.join(' · ')} 화면만 켤 수 있습니다. screens에서 ${extra.join(', ')}를 지워 주세요.`);
|
|
69
127
|
}
|
|
70
|
-
// 문제 설명은 채점하지 않는다: 채점은 설명을 붙인 문제 자료가 한다
|
|
71
|
-
if (json.kind === 'description' && json.gradingTypes !== undefined) throw fail('문제 설명(kind: description)은 채점하지 않습니다. gradingTypes를 지워 주세요 (채점은 문제 자료의 채점 설정에서).');
|
|
72
128
|
return {
|
|
73
129
|
...defaults,
|
|
74
130
|
...json
|
|
75
131
|
};
|
|
76
132
|
}
|
|
133
|
+
/** elice.config.json에 옛 `gradingTypes`가 남아 있을 때 build · doctor가 보여 줄 경고. 없으면 null */
|
|
134
|
+
function legacyGradingTypesWarning(config) {
|
|
135
|
+
return config.gradingTypes === undefined ? null : `${CONFIG_FILE}의 gradingTypes는 더 쓰지 않습니다 (2026-11-10, 지워 주세요). 완료 정책은 completionPolicies · 완료 정책 화면(screens.completionPolicy)이, 채점 방식 · 답은 편집 화면(settings.grading)이 정하고 (ADR 0009), 로컬 채점은 ${GRADING_DATA_FILE}로 흉내 냅니다.`;
|
|
136
|
+
}
|
|
77
137
|
/**
|
|
78
|
-
* 로컬
|
|
79
|
-
*
|
|
138
|
+
* 로컬 완료 정책 (ecdk dev 흉내): `.ecdk/completion.json`(ecdk dev 완료 정책 화면이 저장)이 completionPolicies 안에
|
|
139
|
+
* 있으면 그것, 아니면 completionPolicies 첫 값(서버가 업로드 때 정하는 값), 없으면 on_submit.
|
|
140
|
+
* completionPolicies가 바뀌어 저장해 둔 값이 목록에서 빠졌으면 첫 값으로 돌아간다
|
|
80
141
|
*/
|
|
81
|
-
async function
|
|
82
|
-
const
|
|
83
|
-
|
|
142
|
+
async function loadCompletionPolicy(projectDir, config) {
|
|
143
|
+
const policies = config.completionPolicies ?? [];
|
|
144
|
+
const first = policies[0] ?? DEFAULT_COMPLETION_POLICY;
|
|
145
|
+
try {
|
|
146
|
+
const raw = await readFile(join(projectDir, COMPLETION_DATA_FILE), 'utf8');
|
|
147
|
+
const fail = msg => new Error(`${COMPLETION_DATA_FILE}: ${msg}`);
|
|
148
|
+
// 값 이름은 서버 material_version.completion_policy와 같게
|
|
149
|
+
const json = parseJson(raw, fail);
|
|
150
|
+
const policyError = completionPolicyError(json?.completion_policy, COMPLETION_POLICIES);
|
|
151
|
+
if (policyError) throw fail(policyError);
|
|
152
|
+
const saved = json?.completion_policy;
|
|
153
|
+
return policies.includes(saved) ? saved : first;
|
|
154
|
+
} catch (e) {
|
|
155
|
+
if (e.code !== 'ENOENT') throw e;
|
|
156
|
+
}
|
|
157
|
+
return first;
|
|
158
|
+
}
|
|
159
|
+
/** grading.json (없으면 null). 문제가 있으면 오류 */
|
|
160
|
+
async function loadGradingFile(projectDir) {
|
|
84
161
|
let raw;
|
|
85
162
|
try {
|
|
86
163
|
raw = await readFile(join(projectDir, GRADING_DATA_FILE), 'utf8');
|
|
87
164
|
} catch (e) {
|
|
88
|
-
if (e.code === 'ENOENT') return
|
|
89
|
-
type: supported[0]
|
|
90
|
-
};
|
|
165
|
+
if (e.code === 'ENOENT') return null;
|
|
91
166
|
throw e;
|
|
92
167
|
}
|
|
93
168
|
const fail = msg => new Error(`${GRADING_DATA_FILE}: ${msg}`);
|
|
94
|
-
const
|
|
95
|
-
if (typeof
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (
|
|
169
|
+
const parsed = parseGrading(parseJson(raw, fail));
|
|
170
|
+
if (typeof parsed === 'string') throw fail(parsed);
|
|
171
|
+
return parsed;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 로컬 채점 흉내용 값: 완료 정책 + grading.json. 문제 설명(채점 없음)은 undefined
|
|
175
|
+
*/
|
|
176
|
+
async function loadGrading(projectDir, config) {
|
|
177
|
+
if (config.kind === 'description') return undefined;
|
|
178
|
+
const grading = await loadGradingFile(projectDir);
|
|
103
179
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
180
|
+
completion_policy: await loadCompletionPolicy(projectDir, config),
|
|
181
|
+
grading
|
|
106
182
|
};
|
|
107
183
|
}
|
|
108
184
|
|
|
109
|
-
export { CONFIG_FILE, GRADING_DATA_FILE,
|
|
185
|
+
export { COMPLETION_DATA_FILE, COMPLETION_POLICIES, CONFIG_FILE, DEFAULT_COMPLETION_POLICY, GRADER_TYPES, GRADING_DATA_FILE, legacyGradingTypesWarning, loadCompletionPolicy, loadConfig, loadGrading, loadGradingFile, parseGrading };
|
package/es/core/prepare.js
CHANGED
|
@@ -42,7 +42,7 @@ async function prepareContent(projectDir, config) {
|
|
|
42
42
|
if (config.commentary !== undefined && !hasCommentary) throw new Error(`학습 참고 내용 파일이 원본 최상위에 없습니다: ${config.commentary} (elice.config.json commentary)`);
|
|
43
43
|
const commentary = hasCommentary ? commentaryName : undefined;
|
|
44
44
|
const authored = files.find(f => f.path === rules.manifest.file);
|
|
45
|
-
const fromConfig = config.screens ? 'screens' : config.kind ? 'kind' : config.commentary !== undefined ? 'commentary' : null;
|
|
45
|
+
const fromConfig = config.screens ? 'screens' : config.kind ? 'kind' : config.completionPolicies ? 'completionPolicies' : config.commentary !== undefined ? 'commentary' : null;
|
|
46
46
|
if (authored && fromConfig) throw new Error(`원본에 ${rules.manifest.file}이 있고 ${fromConfig}도 있습니다. 둘 중 하나만 써 주세요.`);
|
|
47
47
|
if (authored) {
|
|
48
48
|
// 형식이 틀리면 그대로 두고 검사가 알려 준다. 맞으면 다른 필드는 지키고 build만 바꾼다
|
|
@@ -57,8 +57,6 @@ async function prepareContent(projectDir, config) {
|
|
|
57
57
|
build
|
|
58
58
|
}, null, 2)}\n`);
|
|
59
59
|
} else {
|
|
60
|
-
// 자료 본문은 채점 유형이 반드시 있다 (문제 설명은 채점하지 않음)
|
|
61
|
-
if ((config.kind ?? rules.manifest.defaultKind) !== 'description' && !config.gradingTypes) throw new Error(`elice.config.json에 이 자료가 지원하는 채점 유형을 적어 주세요: "gradingTypes": [${rules.manifest.gradingTypes.map(t => `"${t}"`).join(', ')}] 중 하나 이상. 보기만 하는 자료는 ["on_access"].`);
|
|
62
60
|
const entries = config.screens ?? {
|
|
63
61
|
learn: rules.manifest.defaultEntry
|
|
64
62
|
};
|
|
@@ -66,9 +64,9 @@ async function prepareContent(projectDir, config) {
|
|
|
66
64
|
path: rules.manifest.file,
|
|
67
65
|
data: new TextEncoder().encode(serializeManifest({
|
|
68
66
|
kind: config.kind,
|
|
67
|
+
// 정답은 metadata에 넣지 않는다: 편집 화면이 settings.grading에 저장. 지원하는 완료 정책만 적는다 (ADR 0009)
|
|
69
68
|
entries,
|
|
70
|
-
|
|
71
|
-
gradingTypes: config.gradingTypes,
|
|
69
|
+
completionPolicies: config.completionPolicies,
|
|
72
70
|
commentary,
|
|
73
71
|
build
|
|
74
72
|
}, rules))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CheckOptions } from '../rules/index.js';
|
|
2
|
+
import type { ContentConfig, GradingConfig } from './config.js';
|
|
3
|
+
/**
|
|
4
|
+
* 프로젝트(ecdk 프로젝트 폴더)를 검사할 때 build · dev · doctor · check가 함께 쓰는 검사 옵션.
|
|
5
|
+
* 파일은 prepareContent가 만든 zip 내용(원본)이고, 모듈 묶기는 build가 하므로 module-src는 보지 않는다.
|
|
6
|
+
* 프로젝트에만 있는 정보(예: 로컬 grading.json, 템플릿 목록)를 검사에 더할 때는 이 함수에만 더한다.
|
|
7
|
+
* 그래야 `ecdk check <프로젝트>`와 `ecdk build` 결과가 어긋나지 않는다.
|
|
8
|
+
*
|
|
9
|
+
* grading: 로컬 grading.json (loadGradingFile, 없으면 null). 읽지 못했으면 undefined → grading.missing을 보지 않는다.
|
|
10
|
+
* 문제 설명은 채점이 없어 넘기지 않는다. templates: 이 CLI가 가진 템플릿 · 버전 (build.template-unknown)
|
|
11
|
+
*/
|
|
12
|
+
export declare function projectCheckOptions(config: ContentConfig, extra?: {
|
|
13
|
+
zipBytes?: number | undefined;
|
|
14
|
+
grading?: GradingConfig | null | undefined;
|
|
15
|
+
}): CheckOptions;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { knownTemplates } from './templates.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 프로젝트(ecdk 프로젝트 폴더)를 검사할 때 build · dev · doctor · check가 함께 쓰는 검사 옵션.
|
|
5
|
+
* 파일은 prepareContent가 만든 zip 내용(원본)이고, 모듈 묶기는 build가 하므로 module-src는 보지 않는다.
|
|
6
|
+
* 프로젝트에만 있는 정보(예: 로컬 grading.json, 템플릿 목록)를 검사에 더할 때는 이 함수에만 더한다.
|
|
7
|
+
* 그래야 `ecdk check <프로젝트>`와 `ecdk build` 결과가 어긋나지 않는다.
|
|
8
|
+
*
|
|
9
|
+
* grading: 로컬 grading.json (loadGradingFile, 없으면 null). 읽지 못했으면 undefined → grading.missing을 보지 않는다.
|
|
10
|
+
* 문제 설명은 채점이 없어 넘기지 않는다. templates: 이 CLI가 가진 템플릿 · 버전 (build.template-unknown)
|
|
11
|
+
*/
|
|
12
|
+
function projectCheckOptions(config, extra = {}) {
|
|
13
|
+
return {
|
|
14
|
+
input: 'zip',
|
|
15
|
+
bundlesModules: true,
|
|
16
|
+
templates: knownTemplates(),
|
|
17
|
+
...(extra.zipBytes !== undefined ? {
|
|
18
|
+
zipBytes: extra.zipBytes
|
|
19
|
+
} : {}),
|
|
20
|
+
...(config.kind !== 'description' && extra.grading !== undefined ? {
|
|
21
|
+
grading: extra.grading
|
|
22
|
+
} : {})
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { projectCheckOptions };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SourceFile } from './collect.js';
|
|
2
|
+
/** build가 묶어 넣은 모듈 스크립트 표시 (검사가 본문을 건너뜀) */
|
|
3
|
+
export declare const BUNDLE_ATTR = "data-ecdk-bundle";
|
|
4
|
+
export interface SandboxReport {
|
|
5
|
+
/** 모듈 스크립트를 묶어 넣은 HTML */
|
|
6
|
+
pages: string[];
|
|
7
|
+
}
|
|
8
|
+
/** HTML의 모듈 스크립트(src)를 묶어 본문으로 넣는다. 바뀐 파일만 새로 만들어 돌려준다 */
|
|
9
|
+
export declare function inlineModuleScripts(files: SourceFile[],
|
|
10
|
+
/** esbuild 작업 폴더 (기본: 실행 폴더). 테스트에서 프로젝트 폴더 안 실행을 흉내 낼 때 */
|
|
11
|
+
opts?: {
|
|
12
|
+
workingDir?: string | undefined;
|
|
13
|
+
minify?: boolean | undefined;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
files: SourceFile[];
|
|
16
|
+
report: SandboxReport;
|
|
17
|
+
}>;
|