@eliceio/cdk-cli 0.0.0-stage → 0.1.0-alpha.2
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 +526 -2
- package/es/bin/index.d.ts +2 -0
- package/es/bin/index.js +10 -0
- package/es/cli.d.ts +5 -0
- package/es/cli.js +209 -0
- package/es/commands/build/index.d.ts +30 -0
- package/es/commands/build/index.js +163 -0
- package/es/commands/check/index.d.ts +9 -0
- package/es/commands/check/index.js +31 -0
- package/es/commands/create/index.d.ts +8 -0
- package/es/commands/create/index.js +22 -0
- package/es/commands/create/scaffold.d.ts +24 -0
- package/es/commands/create/scaffold.js +82 -0
- package/es/commands/dev/index.d.ts +6 -0
- package/es/commands/dev/index.js +40 -0
- package/es/commands/doctor/index.d.ts +34 -0
- package/es/commands/doctor/index.js +311 -0
- package/es/commands/guide/index.d.ts +29 -0
- package/es/commands/guide/index.js +120 -0
- package/es/commands/skill/index.d.ts +48 -0
- package/es/commands/skill/index.js +173 -0
- package/es/core/collect.d.ts +21 -0
- package/es/core/collect.js +89 -0
- package/es/core/config.d.ts +55 -0
- package/es/core/config.js +109 -0
- package/es/core/manifest.d.ts +15 -0
- package/es/core/manifest.js +43 -0
- package/es/core/minify.d.ts +18 -0
- package/es/core/minify.js +93 -0
- package/es/core/prepare.d.ts +12 -0
- package/es/core/prepare.js +86 -0
- package/es/core/protocol.d.ts +2 -0
- package/es/core/protocol.js +4 -0
- package/es/core/sandbox.d.ts +17 -0
- package/es/core/sandbox.js +182 -0
- package/es/core/zip.d.ts +4 -0
- package/es/core/zip.js +17 -0
- package/es/dev/grading.d.ts +15 -0
- package/es/dev/grading.js +37 -0
- package/es/dev/host-page.d.ts +7 -0
- package/es/dev/host-page.js +240 -0
- package/es/dev/inject.d.ts +8 -0
- package/es/dev/inject.js +38 -0
- package/es/dev/mock-api.d.ts +65 -0
- package/es/dev/mock-api.js +269 -0
- package/es/dev/server.d.ts +25 -0
- package/es/dev/server.js +309 -0
- package/es/engines/static/index.d.ts +3 -0
- package/es/engines/static/index.js +11 -0
- package/es/engines/types.d.ts +12 -0
- package/es/engines/vite/index.d.ts +2 -0
- package/es/engines/vite/index.js +4 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/rules/check.d.ts +2 -0
- package/es/rules/check.js +282 -0
- package/es/rules/index.d.ts +8 -0
- package/es/rules/index.js +7 -0
- package/es/rules/manifest.d.ts +39 -0
- package/es/rules/manifest.js +168 -0
- package/es/rules/node.d.ts +11 -0
- package/es/rules/node.js +87 -0
- package/es/rules/path.d.ts +7 -0
- package/es/rules/path.js +35 -0
- package/es/rules/refs.d.ts +19 -0
- package/es/rules/refs.js +111 -0
- package/es/rules/skip.d.ts +12 -0
- package/es/rules/skip.js +55 -0
- package/es/rules/spec.d.ts +3 -0
- package/es/rules/spec.js +6 -0
- package/es/rules/types.d.ts +140 -0
- package/es/rules/unused.d.ts +7 -0
- package/es/rules/unused.js +21 -0
- package/es/rules/zip.d.ts +13 -0
- package/es/rules/zip.js +45 -0
- package/es/rules.json.js +3 -0
- package/es/types.d.ts +4 -0
- package/es/version.d.ts +2 -0
- package/es/version.js +7 -0
- package/guides/content-development.md +207 -0
- package/package.json +50 -3
- package/rules.json +608 -0
- package/skills/_shared/always.md +7 -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/templates/_shared/lib/cdk-mock.d.ts +94 -0
- package/templates/_shared/lib/cdk-mock.js +429 -0
- package/templates/_shared/lib/cdk.js +3 -0
- package/templates/_shared/lib/elice-content.css +262 -0
- package/templates/_shared/lib/elice-content.d.ts +123 -0
- package/templates/_shared/lib/elice-content.js +534 -0
- package/templates/_shared/lib/elice-tokens.css +446 -0
- package/templates/blank/README.md +64 -0
- package/templates/blank/commentary.txt +2 -0
- package/templates/blank/content.json +4 -0
- package/templates/blank/edit.html +15 -0
- package/templates/blank/elice.config.json +12 -0
- package/templates/blank/gitignore +3 -0
- package/templates/blank/index.html +15 -0
- package/templates/blank/instructor.html +15 -0
- package/templates/blank/screens/edit.js +21 -0
- package/templates/blank/screens/instructor.js +9 -0
- package/templates/blank/screens/learn.js +19 -0
- package/templates/blank/styles.css +1 -0
- package/templates/quiz/README.md +108 -0
- package/templates/quiz/commentary.txt +2 -0
- package/templates/quiz/content.json +81 -0
- package/templates/quiz/core/behaviors.d.ts +59 -0
- package/templates/quiz/core/behaviors.js +310 -0
- package/templates/quiz/core/dom.d.ts +13 -0
- package/templates/quiz/core/dom.js +83 -0
- package/templates/quiz/core/editor.d.ts +48 -0
- package/templates/quiz/core/editor.js +206 -0
- package/templates/quiz/core/markdown.d.ts +2 -0
- package/templates/quiz/core/markdown.js +84 -0
- package/templates/quiz/core/model.d.ts +20 -0
- package/templates/quiz/core/model.js +203 -0
- package/templates/quiz/edit.html +17 -0
- package/templates/quiz/elice.config.json +14 -0
- package/templates/quiz/gitignore +3 -0
- package/templates/quiz/grading.json +13 -0
- package/templates/quiz/index.html +17 -0
- package/templates/quiz/instructor.html +17 -0
- package/templates/quiz/screens/edit.js +139 -0
- package/templates/quiz/screens/instructor.js +27 -0
- package/templates/quiz/screens/learn.js +55 -0
- package/templates/quiz/styles.css +570 -0
- package/templates/quiz/ui/templates/choice.js +22 -0
- package/templates/quiz/ui/templates/edit.d.ts +13 -0
- package/templates/quiz/ui/templates/edit.js +183 -0
- package/templates/quiz/ui/templates/group.js +68 -0
- package/templates/quiz/ui/templates/index.d.ts +5 -0
- package/templates/quiz/ui/templates/index.js +17 -0
- package/templates/quiz/ui/templates/order.js +35 -0
- package/templates/quiz/ui/templates/page.js +29 -0
- package/templates/quiz/ui/templates/question.js +28 -0
- package/templates/quiz/ui/templates/text.js +16 -0
- package/templates/quiz/ui/texts.d.ts +3 -0
- package/templates/quiz/ui/texts.js +127 -0
- package/templates/quiz/ui/theme.css +50 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface SourceFile {
|
|
2
|
+
path: string;
|
|
3
|
+
data: Uint8Array;
|
|
4
|
+
}
|
|
5
|
+
export interface Excluded {
|
|
6
|
+
path: string;
|
|
7
|
+
/** link: 심볼릭 링크 등 일반 파일 · 폴더가 아닌 항목 (따라가지 않고 빼되 보고는 한다) */
|
|
8
|
+
reason: 'secret' | 'dev' | 'junk' | 'project' | 'config' | 'link';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 원본 폴더에서 콘텐츠 파일만 모은다. 정답·비밀·개발용·OS 파일, 프로젝트 파일, 산출물 폴더, 설정의 exclude를 뺀다.
|
|
12
|
+
* 빠진 목록은 보고서에 남긴다 (조용히 빼지 않음).
|
|
13
|
+
*/
|
|
14
|
+
export declare function collectSources(srcDir: string, opts: {
|
|
15
|
+
skipDirs: string[];
|
|
16
|
+
exclude: string[];
|
|
17
|
+
projectRoot: boolean;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
files: SourceFile[];
|
|
20
|
+
excluded: Excluded[];
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { join, relative, sep } from 'node:path';
|
|
3
|
+
import 'fflate';
|
|
4
|
+
import { globToRegExp } from '../rules/path.js';
|
|
5
|
+
import { rules } from '../rules/spec.js';
|
|
6
|
+
|
|
7
|
+
/** 콘텐츠가 아니라 프로젝트 도구가 쓰는 파일. 원본 폴더가 프로젝트 루트일 때 빠진다. */
|
|
8
|
+
const PROJECT_FILES = ['package.json', 'package-lock.json', 'pnpm-lock.yaml', 'pnpm-workspace.yaml', 'yarn.lock', 'bun.lockb', 'tsconfig*.json', '*.d.ts',
|
|
9
|
+
// 편집기 자동완성용 타입 (템플릿 lib/elice-content.d.ts)
|
|
10
|
+
'README*', 'LICENSE*', '.*'];
|
|
11
|
+
function matcher(patterns) {
|
|
12
|
+
const names = patterns.filter(p => !p.includes('/')).map(globToRegExp);
|
|
13
|
+
const prefixes = patterns.filter(p => p.includes('/')).map(p => p.replace(/^\.\//, '').replace(/\/$/, ''));
|
|
14
|
+
return path => {
|
|
15
|
+
const name = path.slice(path.lastIndexOf('/') + 1);
|
|
16
|
+
return names.some(re => re.test(name)) || prefixes.some(pre => path === pre || path.startsWith(`${pre}/`));
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 원본 폴더에서 콘텐츠 파일만 모은다. 정답·비밀·개발용·OS 파일, 프로젝트 파일, 산출물 폴더, 설정의 exclude를 뺀다.
|
|
21
|
+
* 빠진 목록은 보고서에 남긴다 (조용히 빼지 않음).
|
|
22
|
+
*/
|
|
23
|
+
async function collectSources(srcDir, opts) {
|
|
24
|
+
const {
|
|
25
|
+
secret,
|
|
26
|
+
dev,
|
|
27
|
+
junk
|
|
28
|
+
} = rules.excluded;
|
|
29
|
+
const groups = [['secret', matcher(secret.files), new Set(secret.dirs)], ['dev', matcher(dev.files), new Set(dev.dirs)], ['junk', matcher(junk.files), new Set(junk.dirs)]];
|
|
30
|
+
const isProject = matcher(opts.projectRoot ? PROJECT_FILES : []);
|
|
31
|
+
const isConfigExcluded = matcher(opts.exclude);
|
|
32
|
+
const skip = new Set(opts.skipDirs.map(d => d.replace(/\/$/, '')));
|
|
33
|
+
const files = [];
|
|
34
|
+
const excluded = [];
|
|
35
|
+
async function walk(dir) {
|
|
36
|
+
const entries = await readdir(dir, {
|
|
37
|
+
withFileTypes: true
|
|
38
|
+
});
|
|
39
|
+
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
40
|
+
for (const e of entries) {
|
|
41
|
+
const abs = join(dir, e.name);
|
|
42
|
+
const rel = relative(srcDir, abs).split(sep).join('/');
|
|
43
|
+
if (e.isDirectory()) {
|
|
44
|
+
if (skip.has(rel)) continue;
|
|
45
|
+
const group = groups.find(([,, dirs]) => dirs.has(e.name));
|
|
46
|
+
if (group) excluded.push({
|
|
47
|
+
path: `${rel}/`,
|
|
48
|
+
reason: group[0]
|
|
49
|
+
});else if (isConfigExcluded(rel)) excluded.push({
|
|
50
|
+
path: `${rel}/`,
|
|
51
|
+
reason: 'config'
|
|
52
|
+
});else if (opts.projectRoot && e.name.startsWith('.')) excluded.push({
|
|
53
|
+
path: `${rel}/`,
|
|
54
|
+
reason: 'project'
|
|
55
|
+
});else await walk(abs);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (!e.isFile()) {
|
|
59
|
+
// 링크로 연결한 이미지 폴더 등이 조용히 빠지면 ref.missing만 보게 된다: 원인을 남긴다
|
|
60
|
+
excluded.push({
|
|
61
|
+
path: rel,
|
|
62
|
+
reason: 'link'
|
|
63
|
+
});
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const group = groups.find(([, match]) => match(rel));
|
|
67
|
+
if (group) excluded.push({
|
|
68
|
+
path: rel,
|
|
69
|
+
reason: group[0]
|
|
70
|
+
});else if (isProject(rel)) excluded.push({
|
|
71
|
+
path: rel,
|
|
72
|
+
reason: 'project'
|
|
73
|
+
});else if (isConfigExcluded(rel)) excluded.push({
|
|
74
|
+
path: rel,
|
|
75
|
+
reason: 'config'
|
|
76
|
+
});else files.push({
|
|
77
|
+
path: rel,
|
|
78
|
+
data: new Uint8Array(await readFile(abs))
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
await walk(srcDir);
|
|
83
|
+
return {
|
|
84
|
+
files,
|
|
85
|
+
excluded
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { collectSources };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 채점 유형. 원본은 rules.json `manifest.gradingTypes`이고, 타입 검사(오타 · 막아 둔 manual)를 위해 여기 리터럴로 둔다.
|
|
3
|
+
* 둘이 같은지는 docs.test.ts가 대조한다. 수동 채점 manual · 채점 없음 none은 Custom HTML에서 쓰지 않음
|
|
4
|
+
*/
|
|
5
|
+
export declare const GRADING_TYPES: readonly ["on_access", "on_submit", "pattern", "rubric"];
|
|
6
|
+
export type GradingType = (typeof GRADING_TYPES)[number];
|
|
7
|
+
/**
|
|
8
|
+
* 로컬 채점 설정(유형 · 정답 · 채점 기준). 프로젝트 맨 위 `grading.json`에 적는다. LXP 채점 설정에서 교육자가 고르고
|
|
9
|
+
* 넣는 값과 같다. zip에는 들어가지 않는다 (운영은 LXP 채점 설정). CLI · mock의 로컬 채점에만 쓴다.
|
|
10
|
+
*/
|
|
11
|
+
export interface GradingData {
|
|
12
|
+
/** 로컬에서 흉내 낼 유형 (gradingTypes 중 하나). 없으면 gradingTypes의 첫 유형 */
|
|
13
|
+
type?: GradingType;
|
|
14
|
+
match?: 'exact' | 'regex';
|
|
15
|
+
answer_key?: unknown;
|
|
16
|
+
rubric?: string;
|
|
17
|
+
}
|
|
18
|
+
/** 로컬 채점에 쓰는 값: grading.json에 유형을 채운 것. elice-material `material_version.grading`과 같은 모양 */
|
|
19
|
+
export interface GradingConfig extends GradingData {
|
|
20
|
+
type: GradingType;
|
|
21
|
+
}
|
|
22
|
+
export declare const GRADING_DATA_FILE = "grading.json";
|
|
23
|
+
export interface ContentConfig {
|
|
24
|
+
/** 콘텐츠 원본 폴더 (프로젝트 기준). 기본 '.' */
|
|
25
|
+
root: string;
|
|
26
|
+
/** 산출물 폴더. 기본 'dist' */
|
|
27
|
+
outDir: string;
|
|
28
|
+
/** 추가로 뺄 파일·폴더 (basename glob `*` 또는 프로젝트 기준 경로 접두사) */
|
|
29
|
+
exclude: string[];
|
|
30
|
+
/** 용도 → metadata.json `kind`. material: 자료 본문(기본) · description: 다른 자료(실습 등)의 문제 설명 */
|
|
31
|
+
kind?: 'material' | 'description';
|
|
32
|
+
/** 화면별 진입 파일 → build가 metadata.json로 만든다. 없으면 원본의 metadata.json, 그것도 없으면 { learn: 'index.html' } */
|
|
33
|
+
screens?: Record<string, string>;
|
|
34
|
+
/** 이 자료가 지원하는 채점 유형 → metadata.json `gradingTypes` (자료 본문은 필수). 로컬 채점 유형 · 정답은 grading.json */
|
|
35
|
+
gradingTypes?: GradingType[];
|
|
36
|
+
/** true면 build가 JS · CSS · JSON을 줄여 zip에 넣는다 (용량 줄이기). 기본 false */
|
|
37
|
+
minify?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* 학습 참고 내용 파일 이름 (원본 최상위 .txt). 기본 rules.json `manifest.commentaryFile`(commentary.txt)이 있으면 그것.
|
|
40
|
+
* zip에 그대로 들어가고 build가 metadata.json `commentary`에 이름을 적는다
|
|
41
|
+
*/
|
|
42
|
+
commentary?: string;
|
|
43
|
+
/** minify와 함께: 줄인 JS · CSS마다 .map을 zip에 넣어 운영에서도 원본 위치로 오류를 본다 (용량이 늘어남) */
|
|
44
|
+
sourcemap?: boolean;
|
|
45
|
+
/** ecdk create가 적는 템플릿과 버전 (예: "quiz@0.1.0"). metadata.json build.template으로 */
|
|
46
|
+
template?: string;
|
|
47
|
+
}
|
|
48
|
+
export declare const CONFIG_FILE = "elice.config.json";
|
|
49
|
+
/** 1단계는 JSON만. `.ts` 설정은 Node 20의 TS 실행 지원 문제로 엔진 작업(3단계)과 함께 결정. */
|
|
50
|
+
export declare function loadConfig(projectDir: string): Promise<ContentConfig>;
|
|
51
|
+
/**
|
|
52
|
+
* 로컬 채점용 설정: grading.json(있으면) + 유형. 유형은 grading.json `type`, 없으면 gradingTypes의 첫 유형.
|
|
53
|
+
* 지원 유형이 없으면(문제 설명) undefined.
|
|
54
|
+
*/
|
|
55
|
+
export declare function loadGrading(projectDir: string, config: ContentConfig): Promise<GradingConfig | undefined>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import 'fflate';
|
|
4
|
+
import { gradingTypesError } from '../rules/manifest.js';
|
|
5
|
+
import { rules } from '../rules/spec.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 채점 유형. 원본은 rules.json `manifest.gradingTypes`이고, 타입 검사(오타 · 막아 둔 manual)를 위해 여기 리터럴로 둔다.
|
|
9
|
+
* 둘이 같은지는 docs.test.ts가 대조한다. 수동 채점 manual · 채점 없음 none은 Custom HTML에서 쓰지 않음
|
|
10
|
+
*/
|
|
11
|
+
const GRADING_TYPES = ['on_access', 'on_submit', 'pattern', 'rubric'];
|
|
12
|
+
const GRADING_DATA_FILE = 'grading.json';
|
|
13
|
+
const GRADING_DATA_KEYS = ['type', 'match', 'answer_key', 'rubric'];
|
|
14
|
+
const CONFIG_FILE = 'elice.config.json';
|
|
15
|
+
/** JSON 형식 오류에 파일 이름을 붙인다 (SyntaxError만 나오면 어느 파일인지 모름) */
|
|
16
|
+
function parseJson(raw, fail) {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(raw);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw fail(`JSON 형식이 아닙니다 (${e.message}).`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const defaults = {
|
|
24
|
+
root: '.',
|
|
25
|
+
outDir: 'dist',
|
|
26
|
+
exclude: []
|
|
27
|
+
};
|
|
28
|
+
const isStringRecord = v => typeof v === 'object' && v !== null && !Array.isArray(v) && Object.values(v).every(x => typeof x === 'string');
|
|
29
|
+
/** 1단계는 JSON만. `.ts` 설정은 Node 20의 TS 실행 지원 문제로 엔진 작업(3단계)과 함께 결정. */
|
|
30
|
+
async function loadConfig(projectDir) {
|
|
31
|
+
let raw;
|
|
32
|
+
try {
|
|
33
|
+
raw = await readFile(join(projectDir, CONFIG_FILE), 'utf8');
|
|
34
|
+
} catch (e) {
|
|
35
|
+
if (e.code === 'ENOENT') return {
|
|
36
|
+
...defaults
|
|
37
|
+
};
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
const fail = msg => new Error(`${CONFIG_FILE}: ${msg}`);
|
|
41
|
+
const json = parseJson(raw, fail);
|
|
42
|
+
for (const key of ['root', 'outDir']) {
|
|
43
|
+
if (json[key] !== undefined && typeof json[key] !== 'string') throw fail(`${key}는 문자열이어야 합니다.`);
|
|
44
|
+
}
|
|
45
|
+
if (json.exclude !== undefined && !(Array.isArray(json.exclude) && json.exclude.every(x => typeof x === 'string'))) throw fail('exclude는 문자열 배열이어야 합니다.');
|
|
46
|
+
// metadata.json의 screens({ learn: { enabled, entry } })와 달리 켤 화면만 파일 이름으로 적는다 (ADR 0004)
|
|
47
|
+
if (json.screens !== undefined && !isStringRecord(json.screens)) throw fail('screens는 켤 화면만 파일 이름으로 적습니다: { "learn": "index.html", "instructor": "..." } (metadata.json의 { "enabled", "entry" } 모양과 다름).');
|
|
48
|
+
// 오타는 metadata.json 파서와 같은 문구로 막는다 (조용히 빠지면 그 화면이 꺼진 채로 만들어짐)
|
|
49
|
+
const unknownScreen = Object.keys(json.screens ?? {}).find(m => !rules.manifest.modes.includes(m));
|
|
50
|
+
if (unknownScreen) throw fail(`알 수 없는 화면입니다: ${unknownScreen} (가능: ${rules.manifest.modes.join(', ')})`);
|
|
51
|
+
if (json.minify !== undefined && typeof json.minify !== 'boolean') throw fail('minify는 true 또는 false여야 합니다.');
|
|
52
|
+
if (json.sourcemap !== undefined && typeof json.sourcemap !== 'boolean') throw fail('sourcemap은 true 또는 false여야 합니다.');
|
|
53
|
+
if (json.sourcemap && !json.minify) throw fail('sourcemap은 minify와 함께 씁니다 ("minify": true). 줄이지 않으면 원본 그대로라 필요 없습니다.');
|
|
54
|
+
if (json.template !== undefined && typeof json.template !== 'string') throw fail('template은 문자열이어야 합니다 (ecdk create가 적는 값).');
|
|
55
|
+
if (json.answers !== undefined) throw fail('answers 대신 gradingTypes와 grading.json을 써 주세요 (예: elice.config.json { "gradingTypes": ["pattern"] }, grading.json { "type": "pattern", "match": "exact", "answer_key": ... }).');
|
|
56
|
+
const legacy = json;
|
|
57
|
+
if (legacy.grading !== undefined) throw fail(`grading 대신 gradingTypes에 이 자료가 지원하는 채점 유형을 모두 적어 주세요 (예: "gradingTypes": ["on_submit", "pattern"]). 로컬에서 흉내 낼 유형과 정답은 ${GRADING_DATA_FILE}에.`);
|
|
58
|
+
if (json.gradingTypes !== undefined) {
|
|
59
|
+
const error = gradingTypesError(json.gradingTypes, GRADING_TYPES);
|
|
60
|
+
if (error) throw fail(error);
|
|
61
|
+
}
|
|
62
|
+
if (json.commentary !== undefined && typeof json.commentary !== 'string') throw fail('commentary는 학습 참고 내용 파일 이름(문자열)이어야 합니다. 예: "commentary.txt"');
|
|
63
|
+
if (json.kind !== undefined && json.kind !== 'material' && json.kind !== 'description') throw fail('kind는 material(자료 본문) 또는 description(문제 설명)이어야 합니다.');
|
|
64
|
+
// 용도별로 켤 수 있는 화면은 rules.json manifest.kindModes (문제 설명은 학생 화면만)
|
|
65
|
+
if (json.kind && json.screens) {
|
|
66
|
+
const allowed = rules.manifest.kindModes[json.kind] ?? rules.manifest.modes;
|
|
67
|
+
const extra = Object.keys(json.screens).filter(m => !allowed.includes(m));
|
|
68
|
+
if (extra.length > 0) throw fail(`${json.kind === 'description' ? '문제 설명(kind: description)' : json.kind}은 ${allowed.join(' · ')} 화면만 켤 수 있습니다. screens에서 ${extra.join(', ')}를 지워 주세요.`);
|
|
69
|
+
}
|
|
70
|
+
// 문제 설명은 채점하지 않는다: 채점은 설명을 붙인 문제 자료가 한다
|
|
71
|
+
if (json.kind === 'description' && json.gradingTypes !== undefined) throw fail('문제 설명(kind: description)은 채점하지 않습니다. gradingTypes를 지워 주세요 (채점은 문제 자료의 채점 설정에서).');
|
|
72
|
+
return {
|
|
73
|
+
...defaults,
|
|
74
|
+
...json
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 로컬 채점용 설정: grading.json(있으면) + 유형. 유형은 grading.json `type`, 없으면 gradingTypes의 첫 유형.
|
|
79
|
+
* 지원 유형이 없으면(문제 설명) undefined.
|
|
80
|
+
*/
|
|
81
|
+
async function loadGrading(projectDir, config) {
|
|
82
|
+
const supported = config.gradingTypes;
|
|
83
|
+
if (!supported || supported.length === 0) return undefined;
|
|
84
|
+
let raw;
|
|
85
|
+
try {
|
|
86
|
+
raw = await readFile(join(projectDir, GRADING_DATA_FILE), 'utf8');
|
|
87
|
+
} catch (e) {
|
|
88
|
+
if (e.code === 'ENOENT') return {
|
|
89
|
+
type: supported[0]
|
|
90
|
+
};
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
93
|
+
const fail = msg => new Error(`${GRADING_DATA_FILE}: ${msg}`);
|
|
94
|
+
const data = parseJson(raw, fail);
|
|
95
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data)) throw fail('객체여야 합니다. 예: { "type": "pattern", "match": "exact", "answer_key": { "answers": { "q1": "b" } } }');
|
|
96
|
+
const unknown = Object.keys(data).filter(k => !GRADING_DATA_KEYS.includes(k));
|
|
97
|
+
if (unknown.length > 0) throw fail(`알 수 없는 필드입니다: ${unknown.join(', ')} (가능: ${GRADING_DATA_KEYS.join(', ')})`);
|
|
98
|
+
const {
|
|
99
|
+
type,
|
|
100
|
+
...rest
|
|
101
|
+
} = data;
|
|
102
|
+
if (type !== undefined && !supported.includes(type)) throw fail(`type은 elice.config.json gradingTypes(${supported.join(', ')}) 중 하나여야 합니다: ${type}`);
|
|
103
|
+
return {
|
|
104
|
+
...rest,
|
|
105
|
+
type: type ?? supported[0]
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { CONFIG_FILE, GRADING_DATA_FILE, GRADING_TYPES, loadConfig, loadGrading };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type BuildInfo } from '../rules/index.js';
|
|
2
|
+
import type { SourceFile } from './collect.js';
|
|
3
|
+
/**
|
|
4
|
+
* metadata.json의 build. 같은 입력이면 같은 결과가 나오도록 시각 등 바뀌는 값은 넣지 않는다.
|
|
5
|
+
* template은 ecdk create가 elice.config.json에 적은 값, sdk는 묶어 넣은 SDK 파일 머리말에서 읽는다.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createBuildInfo(engine: string, extra?: {
|
|
8
|
+
template?: string | undefined;
|
|
9
|
+
files?: SourceFile[];
|
|
10
|
+
}): BuildInfo;
|
|
11
|
+
/**
|
|
12
|
+
* zip 내용의 지문. metadata.json을 뺀 파일을 이름순으로 `경로 \0 길이 \0 내용`을 이어 SHA-256.
|
|
13
|
+
* 서버나 누구든 zip을 풀어 같은 방법으로 계산하면 빌드 뒤 바뀌었는지 알 수 있다.
|
|
14
|
+
*/
|
|
15
|
+
export declare function contentDigest(files: SourceFile[], skip?: string): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import 'fflate';
|
|
3
|
+
import { RULES_VERSION } from '../rules/spec.js';
|
|
4
|
+
import { VERSION } from '../version.js';
|
|
5
|
+
import { PROTOCOL_VERSION } from './protocol.js';
|
|
6
|
+
|
|
7
|
+
/** lib/cdk.js 머리말: `/* @eliceio/cdk 1.0.0 — UMD. …` 또는 `/* @eliceio/cdk 1.0.0 (브랜치@커밋) · …` */
|
|
8
|
+
const SDK_HEADER = /^\/\* @eliceio\/cdk (\S+)(?: \(([^)]+)\))?/;
|
|
9
|
+
/**
|
|
10
|
+
* metadata.json의 build. 같은 입력이면 같은 결과가 나오도록 시각 등 바뀌는 값은 넣지 않는다.
|
|
11
|
+
* template은 ecdk create가 elice.config.json에 적은 값, sdk는 묶어 넣은 SDK 파일 머리말에서 읽는다.
|
|
12
|
+
*/
|
|
13
|
+
function createBuildInfo(engine, extra = {}) {
|
|
14
|
+
const sdkFile = extra.files?.find(f => f.path === 'lib/cdk.js');
|
|
15
|
+
const header = sdkFile ? SDK_HEADER.exec(new TextDecoder().decode(sdkFile.data.subarray(0, 300))) : null;
|
|
16
|
+
return {
|
|
17
|
+
cli: VERSION,
|
|
18
|
+
rules: RULES_VERSION,
|
|
19
|
+
protocol: PROTOCOL_VERSION,
|
|
20
|
+
engine,
|
|
21
|
+
...(extra.template ? {
|
|
22
|
+
template: extra.template
|
|
23
|
+
} : {}),
|
|
24
|
+
...(header ? {
|
|
25
|
+
sdk: header[2] ? `${header[1]} (${header[2]})` : header[1]
|
|
26
|
+
} : {})
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* zip 내용의 지문. metadata.json을 뺀 파일을 이름순으로 `경로 \0 길이 \0 내용`을 이어 SHA-256.
|
|
31
|
+
* 서버나 누구든 zip을 풀어 같은 방법으로 계산하면 빌드 뒤 바뀌었는지 알 수 있다.
|
|
32
|
+
*/
|
|
33
|
+
function contentDigest(files, skip = 'metadata.json') {
|
|
34
|
+
const hash = createHash('sha256');
|
|
35
|
+
for (const f of [...files].sort((a, b) => a.path < b.path ? -1 : 1)) {
|
|
36
|
+
if (f.path === skip) continue;
|
|
37
|
+
hash.update(`${f.path}\0${f.data.byteLength}\0`);
|
|
38
|
+
hash.update(f.data);
|
|
39
|
+
}
|
|
40
|
+
return `sha256-${hash.digest('base64')}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { contentDigest, createBuildInfo };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SourceFile } from './collect.js';
|
|
2
|
+
export interface MinifyReport {
|
|
3
|
+
/** 줄인 파일 수 */
|
|
4
|
+
files: number;
|
|
5
|
+
before: number;
|
|
6
|
+
after: number;
|
|
7
|
+
/** 만든 .map 수와 크기 (sourcemap일 때) */
|
|
8
|
+
maps?: {
|
|
9
|
+
files: number;
|
|
10
|
+
bytes: number;
|
|
11
|
+
} | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function minifyFiles(files: SourceFile[], { sourcemap }?: {
|
|
14
|
+
sourcemap?: boolean | undefined;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
files: SourceFile[];
|
|
17
|
+
report: MinifyReport;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { transform } from 'esbuild';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `elice.config.json`의 `"minify": true`일 때 zip에 넣기 전에 줄인다 (용량 줄이기).
|
|
5
|
+
* 파일 단위 변환(번들 아님)이라 경로 · import · 파일 구성은 그대로다.
|
|
6
|
+
*
|
|
7
|
+
* - JS(.js · .mjs): 공백 · 주석 제거, 이름 줄이기. ES 모듈의 import/export와 top-level await는 그대로.
|
|
8
|
+
* - CSS: 공백 · 주석 제거.
|
|
9
|
+
* - JSON: 공백 제거 (형식이 틀리면 그대로 둠, 검사가 알려 줌). metadata.json은 사람이 보도록 그대로.
|
|
10
|
+
* - HTML · 이미지 등은 그대로.
|
|
11
|
+
* - sourcemap: 줄인 JS · CSS 옆에 `<파일>.map`을 두고 끝에 sourceMappingURL을 단다 (원본 내용 포함).
|
|
12
|
+
* 이미 줄여 둔 파일(minify로 10%도 안 줄어듦, 예: lib/cdk.js)은 .map을 만들지 않는다.
|
|
13
|
+
*
|
|
14
|
+
* 검사는 minify 전 원본으로 한다 (`ecdk-ignore` 주석 · 원본 줄 번호). build 참고.
|
|
15
|
+
*/
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
const decoder = new TextDecoder();
|
|
18
|
+
const KEEP = new Set(['metadata.json']);
|
|
19
|
+
async function minifyFiles(files, {
|
|
20
|
+
sourcemap = false
|
|
21
|
+
} = {}) {
|
|
22
|
+
let count = 0;
|
|
23
|
+
let before = 0;
|
|
24
|
+
let after = 0;
|
|
25
|
+
const maps = [];
|
|
26
|
+
const out = await Promise.all(files.map(async f => {
|
|
27
|
+
if (KEEP.has(f.path)) return f;
|
|
28
|
+
const loader = /\.m?js$/i.test(f.path) ? 'js' : /\.css$/i.test(f.path) ? 'css' : null;
|
|
29
|
+
const isJson = /\.json$/i.test(f.path);
|
|
30
|
+
if (!loader && !isJson) return f;
|
|
31
|
+
const text = decoder.decode(f.data);
|
|
32
|
+
let next;
|
|
33
|
+
if (isJson) {
|
|
34
|
+
try {
|
|
35
|
+
next = JSON.stringify(JSON.parse(text));
|
|
36
|
+
} catch {
|
|
37
|
+
return f;
|
|
38
|
+
}
|
|
39
|
+
} else if (loader) {
|
|
40
|
+
const name = f.path.split('/').pop() ?? f.path;
|
|
41
|
+
try {
|
|
42
|
+
const r = await transform(text, {
|
|
43
|
+
loader,
|
|
44
|
+
minify: true,
|
|
45
|
+
target: 'es2022',
|
|
46
|
+
...(sourcemap ? {
|
|
47
|
+
sourcemap: 'external',
|
|
48
|
+
sourcefile: name
|
|
49
|
+
} : {})
|
|
50
|
+
});
|
|
51
|
+
next = r.code;
|
|
52
|
+
// 이미 줄여 둔 파일(묶어 넣은 SDK 등)은 .map이 줄인 코드를 다시 가리킬 뿐이라 용량만 늘린다
|
|
53
|
+
const alreadyMin = encoder.encode(next).byteLength > f.data.byteLength * 0.9;
|
|
54
|
+
if (sourcemap && r.map && !alreadyMin) {
|
|
55
|
+
next += loader === 'css' ? `\n/*# sourceMappingURL=${name}.map */\n` : `\n//# sourceMappingURL=${name}.map\n`;
|
|
56
|
+
maps.push({
|
|
57
|
+
path: `${f.path}.map`,
|
|
58
|
+
data: encoder.encode(r.map)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
} catch (e) {
|
|
62
|
+
const detail = e.errors?.[0];
|
|
63
|
+
throw new Error(`minify 실패: ${f.path}${detail?.location ? `:${detail.location.line}` : ''} ${detail?.text ?? e.message}. 문법을 확인하거나 elice.config.json의 minify를 끄세요.`);
|
|
64
|
+
}
|
|
65
|
+
} else return f;
|
|
66
|
+
const data = encoder.encode(next);
|
|
67
|
+
if (data.byteLength >= f.data.byteLength && !sourcemap) return f;
|
|
68
|
+
count += 1;
|
|
69
|
+
before += f.data.byteLength;
|
|
70
|
+
after += data.byteLength;
|
|
71
|
+
return {
|
|
72
|
+
path: f.path,
|
|
73
|
+
data
|
|
74
|
+
};
|
|
75
|
+
}));
|
|
76
|
+
const mapBytes = maps.reduce((s, m) => s + m.data.byteLength, 0);
|
|
77
|
+
return {
|
|
78
|
+
files: [...out, ...maps],
|
|
79
|
+
report: {
|
|
80
|
+
files: count,
|
|
81
|
+
before,
|
|
82
|
+
after,
|
|
83
|
+
...(sourcemap ? {
|
|
84
|
+
maps: {
|
|
85
|
+
files: maps.length,
|
|
86
|
+
bytes: mapBytes
|
|
87
|
+
}
|
|
88
|
+
} : {})
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { minifyFiles };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Excluded, type SourceFile } from './collect.js';
|
|
2
|
+
import type { ContentConfig } from './config.js';
|
|
3
|
+
export interface PreparedContent {
|
|
4
|
+
srcDir: string;
|
|
5
|
+
outDir: string;
|
|
6
|
+
engine: string;
|
|
7
|
+
/** zip에 들어갈 파일 전부 (metadata.json 포함) */
|
|
8
|
+
files: SourceFile[];
|
|
9
|
+
excluded: Excluded[];
|
|
10
|
+
}
|
|
11
|
+
/** build와 doctor가 같은 결과를 보도록: 수집 → 엔진 → metadata.json(화면 + 빌드 정보). 디스크에는 쓰지 않는다. */
|
|
12
|
+
export declare function prepareContent(projectDir: string, config: ContentConfig): Promise<PreparedContent>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { resolve, relative, sep, isAbsolute } from 'node:path';
|
|
2
|
+
import { staticEngine } from '../engines/static/index.js';
|
|
3
|
+
import 'fflate';
|
|
4
|
+
import { serializeManifest } from '../rules/manifest.js';
|
|
5
|
+
import { rules } from '../rules/spec.js';
|
|
6
|
+
import { collectSources } from './collect.js';
|
|
7
|
+
import { createBuildInfo } from './manifest.js';
|
|
8
|
+
|
|
9
|
+
const isInside = (parent, child) => {
|
|
10
|
+
const rel = relative(parent, child);
|
|
11
|
+
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel);
|
|
12
|
+
};
|
|
13
|
+
/** build와 doctor가 같은 결과를 보도록: 수집 → 엔진 → metadata.json(화면 + 빌드 정보). 디스크에는 쓰지 않는다. */
|
|
14
|
+
async function prepareContent(projectDir, config) {
|
|
15
|
+
const srcDir = resolve(projectDir, config.root);
|
|
16
|
+
const outDir = resolve(projectDir, config.outDir);
|
|
17
|
+
// build는 <outDir>/content/를 지우고 다시 만든다: 프로젝트 밖이나 프로젝트 폴더 자체를 가리키면 다른 데이터를 지울 수 있다
|
|
18
|
+
if (!isInside(resolve(projectDir), outDir)) throw new Error(`outDir는 프로젝트 폴더 안이어야 합니다 (예: "dist"): ${config.outDir}. 밖을 가리키면 그 아래 content/를 지울 수 있어 막습니다.`);
|
|
19
|
+
if (outDir === srcDir || isInside(outDir, srcDir)) throw new Error('outDir는 root와 같거나 root를 품을 수 없습니다.');
|
|
20
|
+
const skipDirs = isInside(srcDir, outDir) ? [relative(srcDir, outDir).split(sep).join('/')] : [];
|
|
21
|
+
const {
|
|
22
|
+
files: sources,
|
|
23
|
+
excluded
|
|
24
|
+
} = await collectSources(srcDir, {
|
|
25
|
+
skipDirs,
|
|
26
|
+
exclude: config.exclude,
|
|
27
|
+
projectRoot: srcDir === resolve(projectDir)
|
|
28
|
+
});
|
|
29
|
+
const engine = staticEngine;
|
|
30
|
+
const files = await engine.build({
|
|
31
|
+
srcDir,
|
|
32
|
+
files: sources
|
|
33
|
+
});
|
|
34
|
+
// metadata.json (zip 최상위): 설정의 kind · screens로 만들고, 없으면 원본 것에 build만 채우고, 둘 다 없으면 학생 화면만
|
|
35
|
+
const build = createBuildInfo(engine.name, {
|
|
36
|
+
template: config.template,
|
|
37
|
+
files
|
|
38
|
+
});
|
|
39
|
+
// 학습 참고 내용: 원본 최상위 .txt 파일을 zip에 그대로 두고, metadata.json commentary에 이름만 적는다
|
|
40
|
+
const commentaryName = (config.commentary ?? rules.manifest.commentaryFile).replace(/^\.\//, '');
|
|
41
|
+
const hasCommentary = files.some(f => f.path === commentaryName);
|
|
42
|
+
if (config.commentary !== undefined && !hasCommentary) throw new Error(`학습 참고 내용 파일이 원본 최상위에 없습니다: ${config.commentary} (elice.config.json commentary)`);
|
|
43
|
+
const commentary = hasCommentary ? commentaryName : undefined;
|
|
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;
|
|
46
|
+
if (authored && fromConfig) throw new Error(`원본에 ${rules.manifest.file}이 있고 ${fromConfig}도 있습니다. 둘 중 하나만 써 주세요.`);
|
|
47
|
+
if (authored) {
|
|
48
|
+
// 형식이 틀리면 그대로 두고 검사가 알려 준다. 맞으면 다른 필드는 지키고 build만 바꾼다
|
|
49
|
+
let raw = null;
|
|
50
|
+
try {
|
|
51
|
+
raw = JSON.parse(new TextDecoder().decode(authored.data));
|
|
52
|
+
} catch {
|
|
53
|
+
raw = null;
|
|
54
|
+
}
|
|
55
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) authored.data = new TextEncoder().encode(`${JSON.stringify({
|
|
56
|
+
...raw,
|
|
57
|
+
build
|
|
58
|
+
}, null, 2)}\n`);
|
|
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
|
+
const entries = config.screens ?? {
|
|
63
|
+
learn: rules.manifest.defaultEntry
|
|
64
|
+
};
|
|
65
|
+
files.push({
|
|
66
|
+
path: rules.manifest.file,
|
|
67
|
+
data: new TextEncoder().encode(serializeManifest({
|
|
68
|
+
kind: config.kind,
|
|
69
|
+
entries,
|
|
70
|
+
// 지원 채점 유형만 (교육자가 LXP 채점 설정에서 고르고 정답을 넣음). 문제 설명은 채점하지 않음
|
|
71
|
+
gradingTypes: config.gradingTypes,
|
|
72
|
+
commentary,
|
|
73
|
+
build
|
|
74
|
+
}, rules))
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
srcDir,
|
|
79
|
+
outDir,
|
|
80
|
+
engine: engine.name,
|
|
81
|
+
files,
|
|
82
|
+
excluded
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { prepareContent };
|
|
@@ -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
|
+
}>;
|