@eliceio/cdk-cli 0.1.0-alpha.3 → 0.1.0-alpha.4
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 +196 -144
- package/es/cli.js +6 -1
- package/es/commands/build/index.d.ts +1 -1
- package/es/commands/build/index.js +11 -12
- package/es/commands/check/index.d.ts +5 -2
- package/es/commands/check/index.js +15 -9
- package/es/commands/create/index.d.ts +4 -0
- package/es/commands/create/index.js +30 -7
- package/es/commands/create/install.d.ts +17 -0
- package/es/commands/create/install.js +53 -0
- package/es/commands/create/scaffold.d.ts +4 -1
- package/es/commands/create/scaffold.js +19 -13
- package/es/commands/dev/index.d.ts +1 -1
- package/es/commands/dev/index.js +4 -4
- package/es/commands/doctor/index.d.ts +11 -1
- package/es/commands/doctor/index.js +124 -36
- package/es/core/collect.d.ts +5 -2
- package/es/core/config.d.ts +95 -29
- package/es/core/config.js +253 -47
- package/es/core/manifest.d.ts +2 -1
- package/es/core/manifest.js +2 -1
- package/es/core/minify.js +2 -2
- package/es/core/prepare.d.ts +18 -2
- package/es/core/prepare.js +46 -15
- package/es/core/project-check.d.ts +18 -7
- package/es/core/project-check.js +35 -8
- package/es/core/sandbox.js +2 -2
- package/es/core/sdk.d.ts +39 -0
- package/es/core/sdk.js +95 -0
- package/es/core/templates.d.ts +3 -3
- package/es/core/templates.js +4 -4
- package/es/dev/grading.d.ts +1 -1
- package/es/dev/grading.js +1 -1
- package/es/dev/host-page.js +2 -2
- package/es/dev/mock-api.d.ts +7 -8
- package/es/dev/mock-api.js +18 -13
- package/es/dev/server.js +62 -43
- package/es/rules/check.js +45 -9
- package/es/rules/manifest.d.ts +1 -1
- package/es/rules/manifest.js +1 -1
- package/es/rules/types.d.ts +18 -8
- package/es/rules.json.js +2 -2
- package/es/test-packages.d.ts +7 -0
- package/guides/content-development.md +63 -55
- package/package.json +2 -2
- package/rules.json +18 -3
- package/skills/_shared/always.md +2 -2
- package/skills/elice-content-check/SKILL.md +3 -1
- package/skills/elice-content-create/SKILL.md +5 -4
- package/skills/elice-content-migrate/SKILL.md +2 -2
- package/skills/elice-content-publish/SKILL.md +4 -3
- package/templates/_shared/lib/cdk-mock.js +17 -17
- package/templates/_shared/lib/elice-content.css +8 -0
- package/templates/_shared/lib/elice-content.d.ts +5 -1
- package/templates/_shared/lib/elice-content.js +20 -12
- package/templates/blank/README.md +11 -8
- package/templates/blank/metadata.json +11 -0
- package/templates/blank/package.json +13 -0
- package/templates/blank/screens/completion.js +2 -2
- package/templates/blank/screens/instructor.js +12 -5
- package/templates/blank/screens/learn.js +16 -11
- package/templates/quiz/README.md +14 -11
- package/templates/quiz/core/editor.d.ts +12 -1
- package/templates/quiz/core/editor.js +28 -5
- package/templates/quiz/core/model.d.ts +14 -0
- package/templates/quiz/core/model.js +73 -1
- package/templates/quiz/metadata.json +11 -0
- package/templates/quiz/package.json +13 -0
- package/templates/quiz/screens/edit.js +85 -29
- package/templates/quiz/screens/instructor.js +18 -12
- package/templates/quiz/screens/learn.js +42 -36
- package/templates/quiz/styles.css +47 -0
- package/templates/quiz/template.json +2 -2
- package/templates/quiz/ui/templates/edit.d.ts +1 -0
- package/templates/quiz/ui/templates/edit.js +37 -5
- package/templates/quiz/ui/texts.js +9 -7
- package/templates/_shared/lib/cdk.js +0 -3
- package/templates/blank/content.json +0 -4
- package/templates/blank/elice.config.json +0 -10
- package/templates/quiz/content.json +0 -35
- package/templates/quiz/elice.config.json +0 -9
- package/templates/quiz/grading.json +0 -4
package/es/core/project-check.js
CHANGED
|
@@ -1,26 +1,53 @@
|
|
|
1
|
+
import { access } from 'node:fs/promises';
|
|
2
|
+
import { posix, join } from 'node:path';
|
|
3
|
+
import { LEGACY_FILES } from './config.js';
|
|
4
|
+
import { SDK_ZIP_PATH, readProjectSdk } from './sdk.js';
|
|
1
5
|
import { knownTemplates } from './templates.js';
|
|
2
6
|
|
|
7
|
+
const exists = p => access(p).then(() => true, () => false);
|
|
8
|
+
/**
|
|
9
|
+
* 프로젝트에 남은 옛 파일 (ADR 0011): elice.config.json · grading.json(프로젝트 맨 위) · content.json(원본 폴더).
|
|
10
|
+
* 경로는 프로젝트 기준 (`/` 구분)
|
|
11
|
+
*/
|
|
12
|
+
async function findLegacyFiles(projectDir, config) {
|
|
13
|
+
const found = [];
|
|
14
|
+
if (await exists(join(projectDir, LEGACY_FILES.config))) found.push(LEGACY_FILES.config);
|
|
15
|
+
const content = posix.join(config.root.replace(/\\/g, '/'), LEGACY_FILES.content);
|
|
16
|
+
if (await exists(join(projectDir, content))) found.push(content);
|
|
17
|
+
if (await exists(join(projectDir, LEGACY_FILES.grading))) found.push(LEGACY_FILES.grading);
|
|
18
|
+
return found;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 옛 lib/cdk.js 복사본 (ADR 0010 최종 결정): package.json에 @eliceio/cdk가 없는데 원본에 lib/cdk.js가 있으면 그 경로
|
|
22
|
+
* (프로젝트 기준). build는 복사본을 그대로 넣고 sdk.lib-copy로 옮기는 법을 알린다
|
|
23
|
+
*/
|
|
24
|
+
async function findLegacySdkCopy(projectDir, config) {
|
|
25
|
+
const path = posix.join(config.root.replace(/\\/g, '/'), SDK_ZIP_PATH);
|
|
26
|
+
if (!(await exists(join(projectDir, path)))) return undefined;
|
|
27
|
+
return (await readProjectSdk(projectDir)) === null ? path : undefined;
|
|
28
|
+
}
|
|
3
29
|
/**
|
|
4
30
|
* 프로젝트(ecdk 프로젝트 폴더)를 검사할 때 build · dev · doctor · check가 함께 쓰는 검사 옵션.
|
|
5
31
|
* 파일은 prepareContent가 만든 zip 내용(원본)이고, 모듈 묶기는 build가 하므로 module-src는 보지 않는다.
|
|
6
|
-
* 프로젝트에만 있는 정보(예:
|
|
32
|
+
* 프로젝트에만 있는 정보(예: 남은 옛 파일, 템플릿 목록)를 검사에 더할 때는 이 함수에만 더한다.
|
|
7
33
|
* 그래야 `ecdk check <프로젝트>`와 `ecdk build` 결과가 어긋나지 않는다.
|
|
8
34
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
35
|
+
* `ecdk dev`가 쓰는 상태(.ecdk/settings.json · completion.json)는 보지 않는다: build · check 결과가 dev에서 무엇을
|
|
36
|
+
* 저장했는지에 따라 달라지지 않게. templates: 이 CLI가 가진 템플릿 · 버전 (build.template-unknown).
|
|
37
|
+
* legacyFiles: 남은 옛 파일 (project.legacy-file, elice.config.json · content.json · grading.json).
|
|
38
|
+
* legacySdkCopy: 옛 lib/cdk.js 복사본 (sdk.lib-copy)
|
|
11
39
|
*/
|
|
12
|
-
function projectCheckOptions(config, extra = {}) {
|
|
40
|
+
async function projectCheckOptions(projectDir, config, extra = {}) {
|
|
13
41
|
return {
|
|
14
42
|
input: 'zip',
|
|
15
43
|
bundlesModules: true,
|
|
16
44
|
templates: knownTemplates(),
|
|
45
|
+
legacyFiles: await findLegacyFiles(projectDir, config),
|
|
46
|
+
legacySdkCopy: await findLegacySdkCopy(projectDir, config),
|
|
17
47
|
...(extra.zipBytes !== undefined ? {
|
|
18
48
|
zipBytes: extra.zipBytes
|
|
19
|
-
} : {}),
|
|
20
|
-
...(config.kind !== 'description' && extra.grading !== undefined ? {
|
|
21
|
-
grading: extra.grading
|
|
22
49
|
} : {})
|
|
23
50
|
};
|
|
24
51
|
}
|
|
25
52
|
|
|
26
|
-
export { projectCheckOptions };
|
|
53
|
+
export { findLegacyFiles, findLegacySdkCopy, projectCheckOptions };
|
package/es/core/sandbox.js
CHANGED
|
@@ -7,13 +7,13 @@ import { rules } from '../rules/spec.js';
|
|
|
7
7
|
/**
|
|
8
8
|
* LXP는 자료를 origin이 `null`인 sandbox iframe(`allow-scripts`)에서 열고, 자료 파일 서버는
|
|
9
9
|
* `Access-Control-Allow-Origin`을 주지 않는다. 그래서 CORS 모드로 받는 요청이 모두 막힌다:
|
|
10
|
-
* `<script type="module" src>` · 그 안의 `import` · `import()` · `fetch('
|
|
10
|
+
* `<script type="module" src>` · 그 안의 `import` · `import()` · `fetch('data.json')`.
|
|
11
11
|
* (일반 `<script src>` · `<link rel="stylesheet">` · `<img>`는 CORS를 쓰지 않아 그대로 된다.)
|
|
12
12
|
*
|
|
13
13
|
* build는 zip에 넣기 전에 HTML마다:
|
|
14
14
|
* - `<script type="module" src="상대경로">`를 esbuild로 하나로 묶어 `<script type="module">` 본문으로 넣는다
|
|
15
15
|
* (zip 안 파일만 묶음. `import.meta.url`은 원래 파일 주소로 바꿔 상대경로 계산이 그대로 맞게).
|
|
16
|
-
* - zip 안 JSON(metadata.json
|
|
16
|
+
* - zip 안 JSON(metadata.json 제외, 작성자가 넣은 데이터 파일)을 페이지에 넣고 `fetch`가 그 주소를 받으면 넣어 둔 내용을 돌려준다.
|
|
17
17
|
* 원본 JS · JSON 파일은 zip에 그대로 둔다 (`ecdk dev` · 다른 참조용).
|
|
18
18
|
*/
|
|
19
19
|
const encoder = new TextEncoder();
|
package/es/core/sdk.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SourceFile } from './collect.js';
|
|
2
|
+
/**
|
|
3
|
+
* SDK(@eliceio/cdk)는 프로젝트 package.json 의존성이다 (ADR 0010 최종 결정). LXP sandbox에는 node_modules가 없으므로
|
|
4
|
+
* build · dev가 설치된 SDK의 UMD 빌드를 zip의 lib/cdk.js로 넣는다 (화면 키트 lib/elice-content.js가 같은 폴더에서 부름).
|
|
5
|
+
* 키트(lib/elice-content.js · .css · cdk-mock.js)는 ecdk create가 복사한 프로젝트 lib/ 그대로다.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SDK_PACKAGE = "@eliceio/cdk";
|
|
8
|
+
/** zip 안 SDK 파일 */
|
|
9
|
+
export declare const SDK_ZIP_PATH = "lib/cdk.js";
|
|
10
|
+
export declare const INSTALL_COMMAND = "npm install";
|
|
11
|
+
export declare const UPDATE_COMMAND = "npm update @eliceio/cdk";
|
|
12
|
+
export interface InstalledSdk {
|
|
13
|
+
version: string;
|
|
14
|
+
/** 패키지 폴더 (node_modules/@eliceio/cdk) */
|
|
15
|
+
dir: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ProjectSdk {
|
|
18
|
+
/** package.json dependencies · devDependencies에 적은 범위 (dependencies 우선) */
|
|
19
|
+
range: string;
|
|
20
|
+
/** node_modules에서 찾은 SDK. 없으면 npm install 전 */
|
|
21
|
+
installed?: InstalledSdk | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** package.json에 적은 SDK 범위 (dependencies → devDependencies). 없으면 undefined */
|
|
24
|
+
export declare function declaredSdkRange(pkg: Record<string, unknown> | null): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* 프로젝트가 SDK를 패키지로 쓰는지와 설치 상태. package.json에 @eliceio/cdk가 없으면 null
|
|
27
|
+
* (옛 lib/cdk.js 복사본 프로젝트이거나 SDK를 쓰지 않는 자료: build는 원본 그대로)
|
|
28
|
+
*/
|
|
29
|
+
export declare function readProjectSdk(projectDir: string): Promise<ProjectSdk | null>;
|
|
30
|
+
/** SDK가 설치되지 않았을 때 문구 */
|
|
31
|
+
export declare function missingSdkMessage(): string;
|
|
32
|
+
/**
|
|
33
|
+
* zip lib/cdk.js 머리말. build.sdk는 이 머리말에서 읽는다 (core/manifest.ts).
|
|
34
|
+
* SDK는 LXP 화면과 postMessage(설정 저장 결과 · 페이지 이동)로 이야기하므로 두 규칙을 이 파일에서만 끈다.
|
|
35
|
+
* 두 규칙은 client 검사라 서버 업로드 검사와는 상관없다
|
|
36
|
+
*/
|
|
37
|
+
export declare function sdkHeader(version: string): string;
|
|
38
|
+
/** 설치된 SDK의 UMD 빌드에 머리말을 붙인 zip 파일 lib/cdk.js */
|
|
39
|
+
export declare function sdkZipFile(sdk: InstalledSdk): Promise<SourceFile>;
|
package/es/core/sdk.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve, dirname } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SDK(@eliceio/cdk)는 프로젝트 package.json 의존성이다 (ADR 0010 최종 결정). LXP sandbox에는 node_modules가 없으므로
|
|
6
|
+
* build · dev가 설치된 SDK의 UMD 빌드를 zip의 lib/cdk.js로 넣는다 (화면 키트 lib/elice-content.js가 같은 폴더에서 부름).
|
|
7
|
+
* 키트(lib/elice-content.js · .css · cdk-mock.js)는 ecdk create가 복사한 프로젝트 lib/ 그대로다.
|
|
8
|
+
*/
|
|
9
|
+
const SDK_PACKAGE = '@eliceio/cdk';
|
|
10
|
+
/** zip 안 SDK 파일 */
|
|
11
|
+
const SDK_ZIP_PATH = 'lib/cdk.js';
|
|
12
|
+
/** 설치된 SDK 안의 UMD 빌드 */
|
|
13
|
+
const SDK_UMD = 'umd/index.js';
|
|
14
|
+
const INSTALL_COMMAND = 'npm install';
|
|
15
|
+
const UPDATE_COMMAND = `npm update ${SDK_PACKAGE}`;
|
|
16
|
+
async function readJson(path) {
|
|
17
|
+
try {
|
|
18
|
+
const raw = JSON.parse(await readFile(path, 'utf8'));
|
|
19
|
+
return raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : null;
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Node처럼 프로젝트 폴더부터 위로 올라가며 node_modules/@eliceio/cdk를 찾는다.
|
|
26
|
+
* SDK exports에 ./package.json이 없어 require.resolve 대신 직접 찾는다
|
|
27
|
+
*/
|
|
28
|
+
async function findInstalled(from) {
|
|
29
|
+
let cur = resolve(from);
|
|
30
|
+
for (;;) {
|
|
31
|
+
const dir = join(cur, 'node_modules', ...SDK_PACKAGE.split('/'));
|
|
32
|
+
const pkg = await readJson(join(dir, 'package.json'));
|
|
33
|
+
if (pkg && pkg.name === SDK_PACKAGE && typeof pkg.version === 'string') return {
|
|
34
|
+
version: pkg.version,
|
|
35
|
+
dir
|
|
36
|
+
};
|
|
37
|
+
const parent = dirname(cur);
|
|
38
|
+
if (parent === cur) return undefined;
|
|
39
|
+
cur = parent;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** package.json에 적은 SDK 범위 (dependencies → devDependencies). 없으면 undefined */
|
|
43
|
+
function declaredSdkRange(pkg) {
|
|
44
|
+
for (const key of ['dependencies', 'devDependencies']) {
|
|
45
|
+
const deps = pkg?.[key];
|
|
46
|
+
if (!deps || typeof deps !== 'object') continue;
|
|
47
|
+
const range = deps[SDK_PACKAGE];
|
|
48
|
+
if (typeof range === 'string') return range;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 프로젝트가 SDK를 패키지로 쓰는지와 설치 상태. package.json에 @eliceio/cdk가 없으면 null
|
|
54
|
+
* (옛 lib/cdk.js 복사본 프로젝트이거나 SDK를 쓰지 않는 자료: build는 원본 그대로)
|
|
55
|
+
*/
|
|
56
|
+
async function readProjectSdk(projectDir) {
|
|
57
|
+
const range = declaredSdkRange(await readJson(join(projectDir, 'package.json')));
|
|
58
|
+
if (range === undefined) return null;
|
|
59
|
+
return {
|
|
60
|
+
range,
|
|
61
|
+
installed: await findInstalled(projectDir)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** SDK가 설치되지 않았을 때 문구 */
|
|
65
|
+
function missingSdkMessage() {
|
|
66
|
+
return `${SDK_PACKAGE} 패키지를 찾지 못했습니다 (node_modules에 없음). 프로젝트 폴더에서 ${INSTALL_COMMAND}을 실행해 주세요.`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* zip lib/cdk.js 머리말. build.sdk는 이 머리말에서 읽는다 (core/manifest.ts).
|
|
70
|
+
* SDK는 LXP 화면과 postMessage(설정 저장 결과 · 페이지 이동)로 이야기하므로 두 규칙을 이 파일에서만 끈다.
|
|
71
|
+
* 두 규칙은 client 검사라 서버 업로드 검사와는 상관없다
|
|
72
|
+
*/
|
|
73
|
+
function sdkHeader(version) {
|
|
74
|
+
return [`/* ${SDK_PACKAGE} ${version} — UMD. Added by ecdk build from node_modules/${SDK_PACKAGE}; do not edit. */`, '// ecdk-ignore-next-line api.parent-access sec.postmessage-wildcard', ''].join('\n');
|
|
75
|
+
}
|
|
76
|
+
/** 설치된 SDK의 UMD 빌드에 머리말을 붙인 zip 파일 lib/cdk.js */
|
|
77
|
+
async function sdkZipFile(sdk) {
|
|
78
|
+
const umd = join(sdk.dir, ...SDK_UMD.split('/'));
|
|
79
|
+
let data;
|
|
80
|
+
try {
|
|
81
|
+
data = new Uint8Array(await readFile(umd));
|
|
82
|
+
} catch {
|
|
83
|
+
throw new Error(`${SDK_PACKAGE} ${sdk.version}에 UMD 빌드(${SDK_UMD})가 없습니다. ${INSTALL_COMMAND}으로 다시 설치해 주세요.`);
|
|
84
|
+
}
|
|
85
|
+
const head = new TextEncoder().encode(sdkHeader(sdk.version));
|
|
86
|
+
const joined = new Uint8Array(head.byteLength + data.byteLength);
|
|
87
|
+
joined.set(head);
|
|
88
|
+
joined.set(data, head.byteLength);
|
|
89
|
+
return {
|
|
90
|
+
path: SDK_ZIP_PATH,
|
|
91
|
+
data: joined
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { INSTALL_COMMAND, SDK_PACKAGE, SDK_ZIP_PATH, UPDATE_COMMAND, declaredSdkRange, missingSdkMessage, readProjectSdk, sdkHeader, sdkZipFile };
|
package/es/core/templates.d.ts
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
export declare const TEMPLATE_ROOT: string;
|
|
3
3
|
/**
|
|
4
4
|
* 템플릿 한 개의 정보 (`templates/<이름>/template.json`). 템플릿마다 버전을 따로 올린다 (CLI 버전과 별개).
|
|
5
|
-
* 화면 구성 · 완료 정책은 template.json에 다시 적지 않고 템플릿의
|
|
5
|
+
* 화면 구성 · 완료 정책은 template.json에 다시 적지 않고 템플릿의 metadata.json을 그대로 읽는다 (한 곳만 고치게).
|
|
6
6
|
*/
|
|
7
7
|
export interface TemplateInfo {
|
|
8
8
|
name: string;
|
|
9
9
|
version: string;
|
|
10
10
|
title: string;
|
|
11
11
|
description: string;
|
|
12
|
-
/** 템플릿
|
|
12
|
+
/** 템플릿 metadata.json에서 켠 화면 */
|
|
13
13
|
screens: string[];
|
|
14
|
-
/** 템플릿
|
|
14
|
+
/** 템플릿 metadata.json의 completionPolicies (첫 값이 기본, 하나면 고정) */
|
|
15
15
|
completionPolicies?: string[] | undefined;
|
|
16
16
|
}
|
|
17
17
|
/** 이 CLI가 가진 템플릿 (이름 순, 공통 폴더 `_shared` 제외) */
|
package/es/core/templates.js
CHANGED
|
@@ -10,15 +10,15 @@ function listTemplates(root = TEMPLATE_ROOT) {
|
|
|
10
10
|
withFileTypes: true
|
|
11
11
|
}).filter(d => d.isDirectory() && !d.name.startsWith('_')).map(d => {
|
|
12
12
|
const meta = JSON.parse(readFileSync(join(root, d.name, 'template.json'), 'utf8'));
|
|
13
|
-
const
|
|
13
|
+
const manifest = JSON.parse(readFileSync(join(root, d.name, 'metadata.json'), 'utf8'));
|
|
14
14
|
return {
|
|
15
15
|
name: meta.name,
|
|
16
16
|
version: meta.version,
|
|
17
17
|
title: meta.title,
|
|
18
18
|
description: meta.description,
|
|
19
|
-
screens: Object.
|
|
20
|
-
...(
|
|
21
|
-
completionPolicies:
|
|
19
|
+
screens: Object.entries(manifest.screens ?? {}).filter(([, s]) => s.enabled === true).map(([name]) => name),
|
|
20
|
+
...(manifest.completionPolicies ? {
|
|
21
|
+
completionPolicies: manifest.completionPolicies
|
|
22
22
|
} : {})
|
|
23
23
|
};
|
|
24
24
|
}).sort((a, b) => a.name.localeCompare(b.name));
|
package/es/dev/grading.d.ts
CHANGED
|
@@ -17,6 +17,6 @@ export declare function matchesPattern(answerKey: unknown, answer: unknown): boo
|
|
|
17
17
|
* - on_submit: 제출하면 100
|
|
18
18
|
* - on_graded + pattern: 답 문자열 전체를 정규식 하나로 비교 0 / 100
|
|
19
19
|
* - on_graded + rubric: 흉내 점수 RUBRIC_DEV_SCORE, 통과로 본다 (통과 기준 pass_threshold는 정해지지 않음, G136)
|
|
20
|
-
* - on_graded인데 grading
|
|
20
|
+
* - on_graded인데 답(편집 화면이 저장하는 settings.grading)이 아직 없으면 채점할 수 없어 `{ null, null }`
|
|
21
21
|
*/
|
|
22
22
|
export declare function grade(local: LocalGrading | undefined, answer: unknown): GradeResult;
|
package/es/dev/grading.js
CHANGED
|
@@ -18,7 +18,7 @@ function matchesPattern(answerKey, answer) {
|
|
|
18
18
|
* - on_submit: 제출하면 100
|
|
19
19
|
* - on_graded + pattern: 답 문자열 전체를 정규식 하나로 비교 0 / 100
|
|
20
20
|
* - on_graded + rubric: 흉내 점수 RUBRIC_DEV_SCORE, 통과로 본다 (통과 기준 pass_threshold는 정해지지 않음, G136)
|
|
21
|
-
* - on_graded인데 grading
|
|
21
|
+
* - on_graded인데 답(편집 화면이 저장하는 settings.grading)이 아직 없으면 채점할 수 없어 `{ null, null }`
|
|
22
22
|
*/
|
|
23
23
|
function grade(local, answer) {
|
|
24
24
|
const policy = local?.completion_policy ?? 'on_submit';
|
package/es/dev/host-page.js
CHANGED
|
@@ -65,7 +65,7 @@ function hostPage(opts) {
|
|
|
65
65
|
<b>저장 전 편집 화면</b> <code>#edit=1</code>
|
|
66
66
|
<button type="button" id="open-edit-draft">열기</button>
|
|
67
67
|
</div>
|
|
68
|
-
<div class="tool" role="group" aria-label="저장 전 미리보기" title="LXP 편집 페이지의 미리보기처럼 토큰 없이 학생 화면을 엽니다. settings가 비어
|
|
68
|
+
<div class="tool" role="group" aria-label="저장 전 미리보기" title="LXP 편집 페이지의 미리보기처럼 토큰 없이 학생 화면을 엽니다. settings가 비어 '아직 내용이 없습니다' 안내가 뜨고(기본 내용 없음), 제출은 기록되지 않습니다(늘 100점)">
|
|
69
69
|
<b>저장 전 미리보기</b> <code>#preview=1</code>
|
|
70
70
|
<button type="button" id="open-preview">열기</button>
|
|
71
71
|
</div>
|
|
@@ -171,7 +171,7 @@ function hostPage(opts) {
|
|
|
171
171
|
note(payload.status === 'saved'
|
|
172
172
|
? (current === 'completionPolicy'
|
|
173
173
|
? 'settings-saved: 완료 정책을 저장했습니다 (.ecdk/completion.json). 학생 보기가 이 정책으로 완료 · 채점합니다'
|
|
174
|
-
: 'settings-saved: 저장했습니다. 다른 보기에서 material.settings로 받습니다 (채점 방식 · 답은
|
|
174
|
+
: 'settings-saved: 저장했습니다. 다른 보기에서 material.settings로 받습니다 (내용 · 채점 방식 · 답은 .ecdk/settings.json)')
|
|
175
175
|
: 'settings-saved: 저장 실패 (' + payload.code + ')');
|
|
176
176
|
return;
|
|
177
177
|
case 'navigate-prev':
|
package/es/dev/mock-api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CompletionPolicy, type
|
|
1
|
+
import { type CompletionPolicy, type LocalGrading } from '../core/config.js';
|
|
2
2
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
3
|
/**
|
|
4
4
|
* elice-material API 흉내 (서버 설계 v25, @eliceio/cdk 1.x가 부르는 것만).
|
|
@@ -24,8 +24,8 @@ export type MaterialViewer = 'student' | 'instructor' | 'tutor';
|
|
|
24
24
|
* 콘텐츠의 `saveSettings`가 이 토큰으로 바로 PATCH한다 (토큰 없는 `#edit=1` draft는 저장할 수 없음)
|
|
25
25
|
* - completionPolicy: `#token=…&screen=completionPolicy` (scope edit). 완료 정책 화면 (ADR 0009). SDK
|
|
26
26
|
* `saveCompletionPolicy`가 보낸 `PATCH { completion_policy }`를 `.ecdk/completion.json`에 쓴다 (운영은 material_version)
|
|
27
|
-
* 편집 화면의 `saveSettings`가 보낸 `
|
|
28
|
-
* 학생 · 튜터 · 교육자(learn scope) 응답에는 서버처럼 `grading`을 빼고 준다
|
|
27
|
+
* 편집 화면의 `saveSettings`가 보낸 settings(내용 + `grading` { type: pattern | rubric })는 통째로 `.ecdk/settings.json`에 쓰고,
|
|
28
|
+
* edit 범위 응답에는 `grading`까지, 학생 · 튜터 · 교육자(learn scope) 응답에는 서버처럼 `grading`을 빼고 준다
|
|
29
29
|
*/
|
|
30
30
|
export type DevScenario = 'student' | 'instructor' | 'tutor' | 'edit' | 'completionPolicy';
|
|
31
31
|
/** 토큰을 발급하는 보기 */
|
|
@@ -51,6 +51,7 @@ interface Result {
|
|
|
51
51
|
completed_at: string | null;
|
|
52
52
|
}
|
|
53
53
|
export interface MockState {
|
|
54
|
+
/** 저장된 settings 전체 (내용 + grading). ecdk dev는 `.ecdk/settings.json`에서 읽고 저장할 때 씀 */
|
|
54
55
|
settings: Record<string, unknown>;
|
|
55
56
|
/** 저장할 때마다 올라가는 버전 번호. 응답의 `current_version.id`는 `dev-{n}` */
|
|
56
57
|
version: number;
|
|
@@ -63,12 +64,10 @@ export interface MockState {
|
|
|
63
64
|
export declare const createState: () => MockState;
|
|
64
65
|
export interface MockApiOptions {
|
|
65
66
|
state: MockState;
|
|
66
|
-
/** 채점에 쓰는 값 (로컬 완료 정책 + grading
|
|
67
|
+
/** 채점에 쓰는 값 (로컬 완료 정책 + 저장한 settings.grading) */
|
|
67
68
|
getGrading: () => LocalGrading | undefined;
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
/** 편집 화면이 저장한 `settings.grading`을 grading.json에 쓴다 */
|
|
71
|
-
writeGradingFile?: (grading: GradingConfig) => Promise<void>;
|
|
69
|
+
/** 편집 화면이 저장한 settings 전체(내용 + grading)를 `.ecdk/settings.json`에 쓴다 */
|
|
70
|
+
saveSettings?: (settings: Record<string, unknown>) => Promise<void>;
|
|
72
71
|
getEntries: () => Record<string, string>;
|
|
73
72
|
/** metadata completionPolicies (서버가 metadata를 그대로 돌려준다고 보고 응답에 넣는다, G132) */
|
|
74
73
|
getCompletionPolicies?: () => string[];
|
package/es/dev/mock-api.js
CHANGED
|
@@ -169,17 +169,14 @@ async function handleMockApi(req, res, path, opts) {
|
|
|
169
169
|
if (m[1] !== claims.material_id) return fail(res, 403, 'AUTH_PERMISSION_DENIED', 'material mismatch');
|
|
170
170
|
const sub = m[2] ?? '';
|
|
171
171
|
const subject = claims.account_id;
|
|
172
|
-
// 서버처럼 학생 · 튜터 · 교육자(learn scope)에게는 settings.grading(정답)을 빼고, edit
|
|
172
|
+
// 서버처럼 학생 · 튜터 · 교육자(learn scope)에게는 settings.grading(정답)을 빼고, edit 범위에는 그대로 준다
|
|
173
173
|
const withGrading = settings => {
|
|
174
|
+
if (claims.scope === 'edit') return settings;
|
|
174
175
|
const {
|
|
175
176
|
grading: _ignored,
|
|
176
177
|
...rest
|
|
177
178
|
} = settings;
|
|
178
|
-
|
|
179
|
-
return saved ? {
|
|
180
|
-
...rest,
|
|
181
|
-
grading: saved
|
|
182
|
-
} : rest;
|
|
179
|
+
return rest;
|
|
183
180
|
};
|
|
184
181
|
const material = settings => ({
|
|
185
182
|
id: DEV_MATERIAL_ID,
|
|
@@ -228,21 +225,29 @@ async function handleMockApi(req, res, path, opts) {
|
|
|
228
225
|
const allowed = opts.getCompletionPolicies?.() ?? [];
|
|
229
226
|
if (allowed.length > 0 && !allowed.includes(policy)) return fail(res, 400, 'INVALID_INPUT', `completion_policy ${policy} is not in metadata completionPolicies (${allowed.join(', ')})`);
|
|
230
227
|
// 서버처럼 채점 설정이 없는 on_graded는 거절 (편집 화면에서 답을 먼저 저장)
|
|
231
|
-
if (policy === 'on_graded' && !
|
|
228
|
+
if (policy === 'on_graded' && !state.settings.grading) return fail(res, 422, 'MATERIAL_GRADING_REQUIRED', 'on_graded needs settings.grading');
|
|
232
229
|
}
|
|
233
|
-
// 편집 화면이
|
|
230
|
+
// 편집 화면이 보낸 settings는 통째로 .ecdk/settings.json으로 (dev 전용 저장 위치). grading이 없으면 저장된 채점 설정은 그대로
|
|
234
231
|
if (settings !== undefined) {
|
|
235
232
|
const {
|
|
236
233
|
grading,
|
|
237
234
|
...rest
|
|
238
235
|
} = settings;
|
|
239
|
-
|
|
236
|
+
let next = rest;
|
|
237
|
+
if (grading !== undefined && grading !== null) {
|
|
240
238
|
const parsed = parseGrading(grading);
|
|
241
239
|
if (typeof parsed === 'string') return fail(res, 400, 'INVALID_INPUT', `grading: ${parsed}`);
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
240
|
+
next = {
|
|
241
|
+
...rest,
|
|
242
|
+
grading: parsed
|
|
243
|
+
};
|
|
244
|
+
} else if (state.settings.grading !== undefined) next = {
|
|
245
|
+
...rest,
|
|
246
|
+
grading: state.settings.grading
|
|
247
|
+
};
|
|
248
|
+
state.settings = next;
|
|
249
|
+
await opts.saveSettings?.(next);
|
|
250
|
+
log(`내용을 .ecdk/settings.json에 저장했습니다${next.grading ? ` (채점 설정 ${next.grading.type})` : ''}`);
|
|
246
251
|
}
|
|
247
252
|
if (policy !== undefined) {
|
|
248
253
|
await opts.saveCompletionPolicy?.(policy);
|
package/es/dev/server.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { watch
|
|
2
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
import { rm, mkdir, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { createServer } from 'node:http';
|
|
4
|
-
import { resolve,
|
|
5
|
-
import { loadConfig,
|
|
4
|
+
import { resolve, extname, join, basename, relative, sep, dirname } from 'node:path';
|
|
5
|
+
import { loadConfig, loadSavedSettings, savedGrading, loadCompletionPolicy, SETTINGS_DATA_FILE, PACKAGE_FILE, CONFIG_FILE, COMPLETION_DATA_FILE } from '../core/config.js';
|
|
6
6
|
import { prepareContent } from '../core/prepare.js';
|
|
7
7
|
import { projectCheckOptions } from '../core/project-check.js';
|
|
8
8
|
import { inlineModuleScripts } from '../core/sandbox.js';
|
|
9
|
+
import { missingSdkMessage } from '../core/sdk.js';
|
|
9
10
|
import { checkFiles } from '../rules/check.js';
|
|
10
11
|
import '../rules/spec.js';
|
|
11
12
|
import 'fflate';
|
|
@@ -92,37 +93,48 @@ async function startDevServer(opts) {
|
|
|
92
93
|
const dir = resolve(opts.dir);
|
|
93
94
|
const log = opts.log ?? (l => process.stdout.write(`${l}\n`));
|
|
94
95
|
let config = await loadConfig(dir);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
grading
|
|
96
|
+
const state = createState();
|
|
97
|
+
// 편집 화면이 저장한 settings(내용 + grading)는 .ecdk/settings.json에 남겨 dev를 다시 열어도 그대로 (운영은 서버 settings)
|
|
98
|
+
state.settings = await loadSavedSettings(dir);
|
|
99
|
+
savedGrading(state.settings); // grading 형식이 틀리면 시작할 때 알린다
|
|
100
|
+
let policy = await loadCompletionPolicy(dir, config);
|
|
101
|
+
/** 로컬 채점 흉내: 완료 정책 + 저장한 settings.grading. 문제 설명은 채점 없음 */
|
|
102
|
+
const localGrading = () => config.kind === 'description' ? undefined : {
|
|
103
|
+
completion_policy: policy,
|
|
104
|
+
grading: savedGrading(state.settings)
|
|
105
|
+
};
|
|
106
|
+
async function writeJson(file, data) {
|
|
107
|
+
const path = join(dir, file);
|
|
108
|
+
await mkdir(dirname(path), {
|
|
109
|
+
recursive: true
|
|
110
|
+
});
|
|
111
|
+
await writeFile(path, `${JSON.stringify(data, null, 2)}\n`);
|
|
104
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* 편집 화면의 saveSettings(PATCH settings)를 흉내 서버가 받으면 settings 전체(내용 + grading)를 `.ecdk/settings.json`에 쓴다
|
|
115
|
+
* (운영은 material_version.settings). 값 검사는 흉내 서버가 한다. 점(.) 폴더라 감시 · zip에서 빠진다
|
|
116
|
+
*/
|
|
117
|
+
const saveSettings = settings => writeJson(SETTINGS_DATA_FILE, settings);
|
|
105
118
|
/**
|
|
106
119
|
* 완료 정책 화면의 saveCompletionPolicy(PATCH completion_policy)를 흉내 서버가 받으면 `.ecdk/completion.json`에 쓴다
|
|
107
120
|
* (운영은 material_version.completion_policy). 값 검사는 흉내 서버가 한다
|
|
108
121
|
*/
|
|
109
|
-
async function saveCompletionPolicy(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
recursive: true
|
|
122
|
+
async function saveCompletionPolicy(next) {
|
|
123
|
+
await writeJson(COMPLETION_DATA_FILE, {
|
|
124
|
+
completion_policy: next
|
|
113
125
|
});
|
|
114
|
-
await
|
|
115
|
-
completion_policy: policy
|
|
116
|
-
}, null, 2)}\n`);
|
|
117
|
-
grading = await loadGrading(dir, config);
|
|
126
|
+
policy = await loadCompletionPolicy(dir, config);
|
|
118
127
|
}
|
|
119
|
-
|
|
120
|
-
let prepared = await prepareContent(dir, config
|
|
128
|
+
// SDK를 설치하기 전에도 mock으로는 열린다 (실제 SDK 모드 ?sdk=real만 lib/cdk.js가 없어 실패, 아래에서 알림)
|
|
129
|
+
let prepared = await prepareContent(dir, config, {
|
|
130
|
+
requireSdk: false
|
|
131
|
+
});
|
|
132
|
+
const warnSdk = () => {
|
|
133
|
+
if (prepared.sdk.missing) log(`[dev] ${missingSdkMessage()} 그 전에는 mock SDK로만 열립니다 (?sdk=real은 lib/cdk.js가 없어 실패).`);
|
|
134
|
+
};
|
|
135
|
+
warnSdk();
|
|
121
136
|
let files = await servedFiles(prepared, log);
|
|
122
|
-
let check = checkFiles(prepared.files, projectCheckOptions(
|
|
123
|
-
grading: grading?.grading ?? null
|
|
124
|
-
}));
|
|
125
|
-
const state = createState();
|
|
137
|
+
let check = checkFiles(prepared.files, await projectCheckOptions(dir, config));
|
|
126
138
|
const clients = new Set();
|
|
127
139
|
let hostOrigin = '';
|
|
128
140
|
let contentOrigin = '';
|
|
@@ -190,9 +202,8 @@ async function startDevServer(opts) {
|
|
|
190
202
|
for (const [k, v] of Object.entries(cors)) res.setHeader(k, v);
|
|
191
203
|
await handleMockApi(req, res, url.pathname.slice(4), {
|
|
192
204
|
state,
|
|
193
|
-
getGrading:
|
|
194
|
-
|
|
195
|
-
writeGradingFile,
|
|
205
|
+
getGrading: localGrading,
|
|
206
|
+
saveSettings,
|
|
196
207
|
getEntries: entries,
|
|
197
208
|
getCompletionPolicies: () => check.manifest?.completionPolicies ?? [],
|
|
198
209
|
saveCompletionPolicy,
|
|
@@ -200,9 +211,9 @@ async function startDevServer(opts) {
|
|
|
200
211
|
});
|
|
201
212
|
return;
|
|
202
213
|
}
|
|
203
|
-
// 콘텐츠 주소를 직접 열어 mock으로 돌 때:
|
|
214
|
+
// 콘텐츠 주소를 직접 열어 mock으로 돌 때: .ecdk(저장한 settings · 완료 정책)는 zip에 없어 콘텐츠 서버가 주지 않으므로
|
|
204
215
|
// 흉내 서버가 채점에 쓰는 것과 같은 로컬 채점 설정을 여기서 준다 (dev 전용)
|
|
205
|
-
// CORS *로 둔다: ecdk dev는 작성자 PC에서만 돌고 내주는 값도 작성자
|
|
216
|
+
// CORS *로 둔다: ecdk dev는 작성자 PC에서만 돌고 내주는 값도 작성자 본인이 저장한 답이라, 막아도 지킬 대상이 없다
|
|
206
217
|
// (실행마다 열쇠를 두는 방식은 콘텐츠 주소가 예측 가능해 열쇠까지 읽혀 효과가 없어서 되돌림, !19 리뷰)
|
|
207
218
|
if (url.pathname === '/__ecdk/grading') {
|
|
208
219
|
res.writeHead(200, {
|
|
@@ -210,8 +221,9 @@ async function startDevServer(opts) {
|
|
|
210
221
|
'Content-Type': 'application/json; charset=utf-8'
|
|
211
222
|
});
|
|
212
223
|
// { completion_policy, grading, completion_policies }: 콘텐츠를 직접 연 mock이 로컬 채점 · 완료 정책 흉내에 쓴다
|
|
213
|
-
|
|
214
|
-
|
|
224
|
+
const local = localGrading();
|
|
225
|
+
res.end(JSON.stringify(local ? {
|
|
226
|
+
...local,
|
|
215
227
|
completion_policies: check.manifest?.completionPolicies ?? []
|
|
216
228
|
} : null));
|
|
217
229
|
return;
|
|
@@ -253,7 +265,10 @@ async function startDevServer(opts) {
|
|
|
253
265
|
}
|
|
254
266
|
if (url.pathname === '/__ecdk/reset' && req.method === 'POST') {
|
|
255
267
|
Object.assign(state, createState());
|
|
256
|
-
|
|
268
|
+
await rm(join(dir, SETTINGS_DATA_FILE), {
|
|
269
|
+
force: true
|
|
270
|
+
});
|
|
271
|
+
log(`[api] 저장 내용(${SETTINGS_DATA_FILE})과 제출 기록을 지웠습니다`);
|
|
257
272
|
res.writeHead(204).end();
|
|
258
273
|
return;
|
|
259
274
|
}
|
|
@@ -313,12 +328,17 @@ async function startDevServer(opts) {
|
|
|
313
328
|
async function reload() {
|
|
314
329
|
try {
|
|
315
330
|
config = await loadConfig(dir);
|
|
316
|
-
|
|
317
|
-
|
|
331
|
+
policy = await loadCompletionPolicy(dir, config);
|
|
332
|
+
// 손으로 고친 .ecdk/settings.json도 다시 읽는다 (편집 화면 저장은 흉내 서버가 이미 state에 넣음)
|
|
333
|
+
const saved = await loadSavedSettings(dir);
|
|
334
|
+
savedGrading(saved);
|
|
335
|
+
state.settings = saved;
|
|
336
|
+
prepared = await prepareContent(dir, config, {
|
|
337
|
+
requireSdk: false
|
|
338
|
+
});
|
|
339
|
+
warnSdk();
|
|
318
340
|
files = await servedFiles(prepared, log);
|
|
319
|
-
check = checkFiles(prepared.files, projectCheckOptions(
|
|
320
|
-
grading: grading?.grading ?? null
|
|
321
|
-
}));
|
|
341
|
+
check = checkFiles(prepared.files, await projectCheckOptions(dir, config));
|
|
322
342
|
log(summarize(check));
|
|
323
343
|
const payload = JSON.stringify(snapshot());
|
|
324
344
|
for (const c of clients) c.write(`event: reload\ndata: ${payload}\n\n`);
|
|
@@ -336,16 +356,15 @@ async function startDevServer(opts) {
|
|
|
336
356
|
}, (_e, name) => {
|
|
337
357
|
const first = String(name ?? '').split(/[\\/]/)[0];
|
|
338
358
|
if (!first || first === outRel || first === 'node_modules' || first.startsWith('.')) return;
|
|
339
|
-
if (isSelfWrite(first)) return;
|
|
340
359
|
if (timer) clearTimeout(timer);
|
|
341
360
|
timer = setTimeout(() => void reload(), 150);
|
|
342
361
|
});
|
|
343
362
|
} catch {
|
|
344
363
|
log('[dev] 이 환경에서는 파일 감시를 못 합니다. 고친 뒤 새로고침하세요.');
|
|
345
364
|
}
|
|
346
|
-
// 프로젝트
|
|
365
|
+
// 프로젝트 맨 위의 설정 파일(원본 폴더 밖일 수 있음): package.json "ecdk" · 옛 elice.config.json
|
|
347
366
|
const configWatcher = prepared.srcDir === dir ? null : watch(dir, (_e, name) => {
|
|
348
|
-
if (name ===
|
|
367
|
+
if (name === PACKAGE_FILE || name === CONFIG_FILE) void reload();
|
|
349
368
|
});
|
|
350
369
|
log(summarize(check));
|
|
351
370
|
return {
|