@eliceio/cdk-cli 0.1.0-alpha.3 → 0.1.0-alpha.5

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.
Files changed (120) hide show
  1. package/README.md +288 -200
  2. package/es/cli.js +70 -66
  3. package/es/commands/build/index.d.ts +1 -1
  4. package/es/commands/build/index.js +27 -15
  5. package/es/commands/create/index.d.ts +5 -1
  6. package/es/commands/create/index.js +34 -15
  7. package/es/commands/create/install.d.ts +17 -0
  8. package/es/commands/create/install.js +53 -0
  9. package/es/commands/create/scaffold.d.ts +4 -1
  10. package/es/commands/create/scaffold.js +19 -13
  11. package/es/commands/dev/index.d.ts +1 -1
  12. package/es/commands/dev/index.js +5 -5
  13. package/es/commands/doctor/index.d.ts +29 -2
  14. package/es/commands/doctor/index.js +253 -55
  15. package/es/commands/mcp/index.d.ts +0 -12
  16. package/es/commands/mcp/index.js +6 -57
  17. package/es/commands/setup/index.d.ts +11 -3
  18. package/es/commands/setup/index.js +112 -37
  19. package/es/commands/skill/index.d.ts +46 -8
  20. package/es/commands/skill/index.js +151 -35
  21. package/es/commands/uninstall/index.d.ts +54 -0
  22. package/es/commands/uninstall/index.js +304 -0
  23. package/es/commands/update/index.d.ts +59 -0
  24. package/es/commands/update/index.js +251 -0
  25. package/es/commands/validate/index.d.ts +18 -0
  26. package/es/commands/{check → validate}/index.js +16 -10
  27. package/es/core/collect.d.ts +5 -2
  28. package/es/core/config.d.ts +99 -50
  29. package/es/core/config.js +244 -91
  30. package/es/core/latest.d.ts +21 -0
  31. package/es/core/latest.js +43 -0
  32. package/es/core/manifest.d.ts +2 -1
  33. package/es/core/manifest.js +2 -1
  34. package/es/core/minify.js +2 -2
  35. package/es/core/prepare.d.ts +18 -2
  36. package/es/core/prepare.js +48 -16
  37. package/es/core/project-check.d.ts +19 -8
  38. package/es/core/project-check.js +36 -9
  39. package/es/core/sandbox.js +2 -2
  40. package/es/core/sdk.d.ts +39 -0
  41. package/es/core/sdk.js +95 -0
  42. package/es/core/templates.d.ts +2 -4
  43. package/es/core/templates.js +2 -5
  44. package/es/dev/grading.d.ts +7 -8
  45. package/es/dev/grading.js +6 -16
  46. package/es/dev/host-page.d.ts +1 -1
  47. package/es/dev/host-page.js +12 -10
  48. package/es/dev/mock-api.d.ts +13 -18
  49. package/es/dev/mock-api.js +56 -66
  50. package/es/dev/server.js +52 -52
  51. package/es/rules/check.js +43 -31
  52. package/es/rules/index.d.ts +1 -1
  53. package/es/rules/index.js +1 -1
  54. package/es/rules/manifest.d.ts +28 -20
  55. package/es/rules/manifest.js +58 -55
  56. package/es/rules/types.d.ts +18 -20
  57. package/es/rules.json.js +2 -2
  58. package/es/test-packages.d.ts +7 -0
  59. package/package.json +3 -4
  60. package/rules.json +27 -43
  61. package/skills/_shared/always.md +4 -4
  62. package/skills/elice-content-check/SKILL.md +11 -8
  63. package/skills/elice-content-create/SKILL.md +8 -7
  64. package/skills/elice-content-guide/SKILL.md +42 -0
  65. package/skills/elice-content-guide/topics/00-what-the-person-decides.md +11 -0
  66. package/skills/elice-content-guide/topics/01-check-the-environment.md +10 -0
  67. package/skills/elice-content-guide/topics/02-design-the-material.md +35 -0
  68. package/skills/elice-content-guide/topics/03-create-the-project.md +22 -0
  69. package/skills/elice-content-guide/topics/04-rules.md +12 -0
  70. package/skills/elice-content-guide/topics/05-screen-code.md +101 -0
  71. package/skills/elice-content-guide/topics/06-using-the-quiz-template.md +22 -0
  72. package/skills/elice-content-guide/topics/07-move-existing-html.md +10 -0
  73. package/skills/elice-content-guide/topics/08-fix-check-errors.md +24 -0
  74. package/skills/elice-content-guide/topics/09-check.md +10 -0
  75. package/skills/elice-content-guide/topics/10-build.md +8 -0
  76. package/skills/elice-content-guide/topics/11-more.md +4 -0
  77. package/skills/elice-content-guide/topics/12-upload-with-the-material-mcp.md +41 -0
  78. package/skills/elice-content-migrate/SKILL.md +8 -7
  79. package/skills/elice-content-publish/SKILL.md +8 -7
  80. package/templates/_shared/lib/cdk-mock.d.ts +5 -13
  81. package/templates/_shared/lib/cdk-mock.js +49 -144
  82. package/templates/_shared/lib/elice-content.css +68 -1
  83. package/templates/_shared/lib/elice-content.d.ts +11 -38
  84. package/templates/_shared/lib/elice-content.js +43 -248
  85. package/templates/blank/README.md +12 -10
  86. package/templates/blank/metadata.json +9 -0
  87. package/templates/blank/package.json +13 -0
  88. package/templates/blank/screens/edit.js +1 -1
  89. package/templates/blank/screens/instructor.js +12 -5
  90. package/templates/blank/screens/learn.js +16 -11
  91. package/templates/blank/template.json +2 -2
  92. package/templates/quiz/README.md +15 -12
  93. package/templates/quiz/core/behaviors.js +4 -1
  94. package/templates/quiz/core/editor.d.ts +21 -10
  95. package/templates/quiz/core/editor.js +44 -31
  96. package/templates/quiz/core/model.d.ts +14 -0
  97. package/templates/quiz/core/model.js +76 -4
  98. package/templates/quiz/metadata.json +9 -0
  99. package/templates/quiz/package.json +13 -0
  100. package/templates/quiz/screens/edit.js +101 -34
  101. package/templates/quiz/screens/instructor.js +18 -12
  102. package/templates/quiz/screens/learn.js +45 -36
  103. package/templates/quiz/styles.css +65 -22
  104. package/templates/quiz/template.json +2 -2
  105. package/templates/quiz/ui/templates/edit.d.ts +1 -0
  106. package/templates/quiz/ui/templates/edit.js +65 -19
  107. package/templates/quiz/ui/templates/group.js +10 -2
  108. package/templates/quiz/ui/texts.js +11 -11
  109. package/es/commands/check/index.d.ts +0 -15
  110. package/es/commands/guide/index.d.ts +0 -29
  111. package/es/commands/guide/index.js +0 -120
  112. package/guides/content-development.md +0 -294
  113. package/templates/_shared/lib/cdk.js +0 -3
  114. package/templates/blank/completion.html +0 -15
  115. package/templates/blank/content.json +0 -4
  116. package/templates/blank/elice.config.json +0 -10
  117. package/templates/blank/screens/completion.js +0 -7
  118. package/templates/quiz/content.json +0 -35
  119. package/templates/quiz/elice.config.json +0 -9
  120. package/templates/quiz/grading.json +0 -4
package/es/core/config.js CHANGED
@@ -1,40 +1,32 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { join } from 'node:path';
1
+ import { readFile, writeFile, unlink } from 'node:fs/promises';
2
+ import { join, resolve, basename } from 'node:path';
3
3
  import 'fflate';
4
- import { parseCompletionPolicies, completionPolicyError, graderTypeError, COMPLETION_POLICIES_EXAMPLE } from '../rules/manifest.js';
4
+ import { COMPLETION_POLICIES_IGNORED, LEGACY_COMPLETION_SCREENS, LEGACY_COMPLETION_FIELDS, parseManifest, serializeManifest, graderTypeError } from '../rules/manifest.js';
5
5
  import { rules } from '../rules/spec.js';
6
6
 
7
7
  /**
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에는 없다
12
- */
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는 이번 범위 밖
8
+ * 채점 방식 = `settings.grading.type`. 원본은 rules.json `manifest.graderTypes`.
9
+ * pattern: 정답 정규식 · rubric: AI 평가 기준. code_exec는 이번 범위 밖.
10
+ * 완료 정책(on_access · on_submit · on_graded)은 LXP에 올린 뒤 설정 탭에서 교육자가 고른다 (ADR 0012). 패키지 · CLI는 다루지 않는다
17
11
  */
18
12
  const GRADER_TYPES = ['pattern', 'rubric'];
19
- const GRADING_DATA_FILE = 'grading.json';
13
+ /** 완료 정책 값 (LXP 설정). grading에 잘못 적었을 때 알려 주려고만 쓴다 */
14
+ const COMPLETION_POLICY_VALUES = ['on_access', 'on_submit', 'on_graded', 'manual', 'none'];
20
15
  /**
21
- * 로컬 완료 정책 (dev 전용): `ecdk dev` 완료 정책 화면의 saveCompletionPolicy를 흉내 서버가 여기에 쓴다.
22
- * 운영은 서버 material_version.completion_policy. 프로젝트의 점(.) 폴더라 zip에 들어가지 않는다
16
+ * 로컬 settings (dev 전용): `ecdk dev` 편집 화면의 saveSettings(PATCH /draft settings)를 흉내 서버가 통째로(내용 + grading) 여기에 쓴다.
17
+ * 운영은 서버 material_version.settings. 프로젝트의 점(.) 폴더라 zip에 들어가지 않는다. build · check는 읽지 않는다
23
18
  */
24
- const COMPLETION_DATA_FILE = '.ecdk/completion.json';
19
+ const SETTINGS_DATA_FILE = '.ecdk/settings.json';
25
20
  const GRADING_DATA_KEYS = ['type', 'answer_key', 'rubric'];
26
- /** completionPolicies가 없을 때(검사 오류) ecdk dev가 흉내 내는 정책 (제출하면 완료) */
27
- const DEFAULT_COMPLETION_POLICY = 'on_submit';
28
21
  /**
29
- * 채점 설정 값 검사 (grading.json · 편집 화면이 저장한 settings.grading). 문제가 있으면 문장, 없으면 GradingConfig.
22
+ * 채점 설정 값 검사 (편집 화면이 저장한 settings.grading). 문제가 있으면 문장, 없으면 GradingConfig.
30
23
  * 옛 모양(`type: on_access · on_submit`, `completion_policy` · `grader_type`, `match` · 객체 정답)은 바꾸는 법을 알려 준다.
31
24
  */
32
25
  function parseGrading(data) {
33
26
  const example = '예: { "type": "pattern", "answer_key": "^q1=b$" } · { "type": "rubric", "rubric": "…" }';
34
27
  if (typeof data !== 'object' || data === null || Array.isArray(data)) return `객체여야 합니다. ${example}`;
35
28
  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" }만.`;
29
+ if (COMPLETION_POLICY_VALUES.includes(record.type)) return `완료 정책(${String(record.type)})은 grading에 적지 않습니다. 완료 정책은 LXP에 올린 뒤 설정 탭에서 교육자가 고릅니다 (ADR 0012). grading은 { "type": "pattern" | "rubric" }만.`;
38
30
  if (record.completion_policy !== undefined || record.grader_type !== undefined) return `completion_policy · grader_type은 쓰지 않습니다 (2026-11-11 결정: grading은 type 모양 그대로). ${example}`;
39
31
  if (record.match !== undefined || record.answer_key !== undefined && typeof record.answer_key !== 'string') return `옛 형식입니다 (match · 객체 정답). 정답은 정규식 문자열 하나입니다: { "type": "pattern", "answer_key": "^q1=b;q2=a,d$" }. 퀴즈는 ecdk dev의 내용 편집에서 정답을 다시 고르면 새 형식으로 저장됩니다.`;
40
32
  const unknown = Object.keys(record).filter(k => !GRADING_DATA_KEYS.includes(k));
@@ -64,7 +56,15 @@ function parseGrading(data) {
64
56
  rubric
65
57
  };
66
58
  }
59
+ /** 옛 설정 파일 (ADR 0011에서 없앰). 있으면 경고하고 `ecdk doctor --fix`가 옮긴다. zip에는 들어가지 않는다 */
67
60
  const CONFIG_FILE = 'elice.config.json';
61
+ const PACKAGE_FILE = 'package.json';
62
+ /** package.json에서 ecdk 빌드 옵션을 담는 키 */
63
+ const PACKAGE_CONFIG_KEY = 'ecdk';
64
+ /** package.json "ecdk"에 적을 수 있는 키 */
65
+ const BUILD_OPTION_KEYS = ['template', 'root', 'outDir', 'exclude', 'minify', 'sourcemap'];
66
+ /** metadata.json에 적는 플랫폼 필드 (package.json "ecdk" · 옛 elice.config.json에 있으면 옮기라고 알림) */
67
+ const PLATFORM_KEYS = ['kind', 'screens', 'commentary'];
68
68
  /** JSON 형식 오류에 파일 이름을 붙인다 (SyntaxError만 나오면 어느 파일인지 모름) */
69
69
  function parseJson(raw, fail) {
70
70
  try {
@@ -78,108 +78,261 @@ const defaults = {
78
78
  outDir: 'dist',
79
79
  exclude: []
80
80
  };
81
- const isStringRecord = v => typeof v === 'object' && v !== null && !Array.isArray(v) && Object.values(v).every(x => typeof x === 'string');
82
- /** 1단계는 JSON만. `.ts` 설정은 Node 20의 TS 실행 지원 문제로 엔진 작업(3단계)과 함께 결정. */
83
- async function loadConfig(projectDir) {
84
- let raw;
81
+ const isRecord = v => typeof v === 'object' && v !== null && !Array.isArray(v);
82
+ const isStringRecord = v => isRecord(v) && Object.values(v).every(x => typeof x === 'string');
83
+ async function readOptional(path) {
85
84
  try {
86
- raw = await readFile(join(projectDir, CONFIG_FILE), 'utf8');
85
+ return await readFile(path, 'utf8');
87
86
  } catch (e) {
88
- if (e.code === 'ENOENT') return {
89
- ...defaults
90
- };
87
+ if (e.code === 'ENOENT') return null;
91
88
  throw e;
92
89
  }
93
- const fail = msg => new Error(`${CONFIG_FILE}: ${msg}`);
94
- const json = parseJson(raw, fail);
90
+ }
91
+ /** 정답은 어느 설정 파일에서든 같은 문구로 막는다 */
92
+ function rejectAnswers(json, fail) {
93
+ if (json.answers !== undefined || json.grading !== undefined) throw fail(`${json.answers !== undefined ? 'answers' : 'grading'}(정답 · 채점 설정)는 파일에 적지 않습니다. 채점 방식 · 답은 편집 화면에서 정합니다 (ecdk dev의 '내용 편집'에서 저장하면 ${SETTINGS_DATA_FILE}).`);
94
+ }
95
+ /** 빌드 옵션 (package.json "ecdk" · 옛 elice.config.json 공통) */
96
+ function parseBuildOptions(json, fail) {
95
97
  for (const key of ['root', 'outDir']) {
96
98
  if (json[key] !== undefined && typeof json[key] !== 'string') throw fail(`${key}는 문자열이어야 합니다.`);
97
99
  }
98
100
  if (json.exclude !== undefined && !(Array.isArray(json.exclude) && json.exclude.every(x => typeof x === 'string'))) throw fail('exclude는 문자열 배열이어야 합니다.');
99
- // metadata.json의 screens({ learn: { enabled, entry } })와 달리 켤 화면만 파일 이름으로 적는다 (ADR 0004)
100
- if (json.screens !== undefined && !isStringRecord(json.screens)) throw fail('screens는 켤 화면만 파일 이름으로 적습니다: { "learn": "index.html", "instructor": "..." } (metadata.json의 { "enabled", "entry" } 모양과 다름).');
101
- // 오타는 metadata.json 파서와 같은 문구로 막는다 (조용히 빠지면 그 화면이 꺼진 채로 만들어짐)
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'}"`);
104
- if (unknownScreen) throw fail(`알 수 없는 화면입니다: ${unknownScreen} (가능: ${rules.manifest.modes.join(', ')})`);
105
101
  if (json.minify !== undefined && typeof json.minify !== 'boolean') throw fail('minify는 true 또는 false여야 합니다.');
106
102
  if (json.sourcemap !== undefined && typeof json.sourcemap !== 'boolean') throw fail('sourcemap은 true 또는 false여야 합니다.');
107
103
  if (json.sourcemap && !json.minify) throw fail('sourcemap은 minify와 함께 씁니다 ("minify": true). 줄이지 않으면 원본 그대로라 필요 없습니다.');
108
104
  if (json.template !== undefined && typeof json.template !== 'string') throw fail('template은 문자열이어야 합니다 (ecdk create가 적는 값).');
109
- if (json.answers !== undefined) throw fail(`answers 대신 ${GRADING_DATA_FILE}에 채점 설정을 적어 주세요 (예: { "type": "pattern", "answer_key": "^q1=b$" }). 운영에서는 편집 화면이 정합니다.`);
110
- const legacy = json;
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;
119
- }
105
+ const out = {};
106
+ for (const key of BUILD_OPTION_KEYS) if (json[key] !== undefined) out[key] = json[key];
107
+ return out;
108
+ }
109
+ /** package.json "ecdk": 빌드 옵션만. 플랫폼 필드는 metadata.json으로 안내한다 */
110
+ function parsePackageOptions(value) {
111
+ const fail = msg => new Error(`${PACKAGE_FILE} "${PACKAGE_CONFIG_KEY}": ${msg}`);
112
+ if (!isRecord(value)) throw fail(`객체여야 합니다. 예: { "template": "quiz@1.0.0", "minify": true }`);
113
+ rejectAnswers(value, fail);
114
+ const platform = Object.keys(value).filter(k => PLATFORM_KEYS.includes(k));
115
+ if (platform.length > 0) throw fail(`${platform.join(' · ')}는 원본의 metadata.json에 적습니다 (ADR 0011). package.json "ecdk"에는 빌드 옵션(${BUILD_OPTION_KEYS.join(' · ')})만.`);
116
+ const unknown = Object.keys(value).filter(k => !BUILD_OPTION_KEYS.includes(k));
117
+ if (unknown.length > 0) throw fail(`알 수 없는 키입니다: ${unknown.join(', ')} (가능: ${BUILD_OPTION_KEYS.join(', ')})`);
118
+ return {
119
+ ...defaults,
120
+ ...parseBuildOptions(value, fail),
121
+ configFile: PACKAGE_FILE
122
+ };
123
+ }
124
+ /** 옛 elice.config.json (ADR 0011 전): 빌드 옵션 + 플랫폼 필드. 플랫폼 필드는 legacy로 둔다 */
125
+ function parseLegacyConfig(raw) {
126
+ const fail = msg => new Error(`${CONFIG_FILE}: ${msg}`);
127
+ const parsed = parseJson(raw, fail);
128
+ if (!isRecord(parsed)) throw fail('객체여야 합니다.');
129
+ const json = parsed;
130
+ rejectAnswers(json, fail);
131
+ const options = parseBuildOptions(json, fail);
132
+ // metadata.json의 screens({ learn: { enabled, entry } })와 달리 켤 화면만 파일 이름으로 적는다 (ADR 0004)
133
+ if (json.screens !== undefined && !isStringRecord(json.screens)) throw fail('screens는 켤 화면만 파일 이름으로 적습니다: { "learn": "index.html", "instructor": "..." } (metadata.json의 { "enabled", "entry" } 모양과 다름).');
134
+ // 옛 완료 정책 화면은 옮기지 않고 버린다 (완료 정책은 LXP 설정, ADR 0012). legacyCompletion이 경고한다
135
+ const screens = json.screens ? Object.fromEntries(Object.entries(json.screens).filter(([m]) => !LEGACY_COMPLETION_SCREENS.includes(m))) : undefined;
136
+ // 오타는 metadata.json 파서와 같은 문구로 막는다 (조용히 빠지면 그 화면이 꺼진 채로 만들어짐)
137
+ const unknownScreen = Object.keys(screens ?? {}).find(m => !rules.manifest.modes.includes(m));
138
+ if (unknownScreen) throw fail(`알 수 없는 화면입니다: ${unknownScreen} (가능: ${rules.manifest.modes.join(', ')})`);
139
+ const kind = json.kind;
140
+ if (kind !== undefined && kind !== 'material' && kind !== 'description') throw fail('kind는 material(자료 본문) 또는 description(문제 설명)이어야 합니다.');
141
+ const legacyCompletion = [...LEGACY_COMPLETION_FIELDS.filter(k => json[k] !== undefined), ...Object.keys(json.screens ?? {}).filter(m => LEGACY_COMPLETION_SCREENS.includes(m)).map(m => `screens.${m}`)];
120
142
  if (json.commentary !== undefined && typeof json.commentary !== 'string') throw fail('commentary는 학습 참고 내용 파일 이름(문자열)이어야 합니다. 예: "commentary.txt"');
121
- if (json.kind !== undefined && json.kind !== 'material' && json.kind !== 'description') throw fail('kind는 material(자료 본문) 또는 description(문제 설명)이어야 합니다.');
122
143
  // 용도별로 켤 수 있는 화면은 rules.json manifest.kindModes (문제 설명은 학생 화면만)
123
- if (json.kind && json.screens) {
124
- const allowed = rules.manifest.kindModes[json.kind] ?? rules.manifest.modes;
125
- const extra = Object.keys(json.screens).filter(m => !allowed.includes(m));
126
- if (extra.length > 0) throw fail(`${json.kind === 'description' ? '문제 설명(kind: description)' : json.kind}은 ${allowed.join(' · ')} 화면만 켤 수 있습니다. screens에서 ${extra.join(', ')}를 지워 주세요.`);
144
+ if (kind && screens) {
145
+ const allowed = rules.manifest.kindModes[kind] ?? rules.manifest.modes;
146
+ const extra = Object.keys(screens).filter(m => !allowed.includes(m));
147
+ if (extra.length > 0) throw fail(`${kind === 'description' ? '문제 설명(kind: description)' : kind}은 ${allowed.join(' · ')} 화면만 켤 수 있습니다. screens에서 ${extra.join(', ')}를 지워 주세요.`);
127
148
  }
149
+ const legacy = {
150
+ ...(kind ? {
151
+ kind
152
+ } : {}),
153
+ ...(screens ? {
154
+ screens
155
+ } : {}),
156
+ ...(typeof json.commentary === 'string' ? {
157
+ commentary: json.commentary
158
+ } : {}),
159
+ ...(json.gradingTypes !== undefined ? {
160
+ gradingTypes: json.gradingTypes
161
+ } : {}),
162
+ ...(legacyCompletion.length > 0 ? {
163
+ completion: legacyCompletion
164
+ } : {})
165
+ };
128
166
  return {
129
167
  ...defaults,
130
- ...json
168
+ ...options,
169
+ configFile: CONFIG_FILE,
170
+ legacy,
171
+ ...(kind ? {
172
+ kind
173
+ } : {})
131
174
  };
132
175
  }
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}로 흉내 냅니다.`;
176
+ /** 원본 metadata.json의 kind (dev · doctor용). 없거나 형식이 틀리면 비워 두고 검사가 알린다 */
177
+ async function readManifestInfo(srcDir) {
178
+ const raw = await readOptional(join(srcDir, rules.manifest.file));
179
+ if (raw === null) return {};
180
+ const parsed = parseManifest(raw, rules);
181
+ if (!parsed.ok) return {};
182
+ const {
183
+ kind
184
+ } = parsed.manifest;
185
+ return kind === 'material' || kind === 'description' ? {
186
+ kind
187
+ } : {};
188
+ }
189
+ /** package.json을 읽는다 (없으면 null). JSON 형식이 틀리면 오류 */
190
+ async function readPackageJson(projectDir) {
191
+ const raw = await readOptional(join(projectDir, PACKAGE_FILE));
192
+ if (raw === null) return null;
193
+ const json = parseJson(raw, msg => new Error(`${PACKAGE_FILE}: ${msg}`));
194
+ return isRecord(json) ? json : null;
136
195
  }
137
196
  /**
138
- * 로컬 완료 정책 (ecdk dev 흉내): `.ecdk/completion.json`(ecdk dev 완료 정책 화면이 저장)이 completionPolicies 안에
139
- * 있으면 그것, 아니면 completionPolicies 첫 값(서버가 업로드 때 정하는 값), 없으면 on_submit.
140
- * completionPolicies가 바뀌어 저장해 둔 값이 목록에서 빠졌으면 첫 값으로 돌아간다
197
+ * 프로젝트 설정 (ADR 0011): package.json "ecdk"(빌드 옵션) → 없으면 옛 elice.config.json → 없으면 기본값.
198
+ * kind는 원본 metadata.json에서 읽는다 (옛 elice.config.json이면 거기서).
199
+ * 둘 다 있으면 package.json "ecdk"를 쓰고 elice.config.json은 남은 옛 파일로 경고만 한다
141
200
  */
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;
201
+ async function loadConfig(projectDir) {
202
+ const pkg = await readPackageJson(projectDir);
203
+ let config;
204
+ if (pkg && pkg[PACKAGE_CONFIG_KEY] !== undefined) config = parsePackageOptions(pkg[PACKAGE_CONFIG_KEY]);else {
205
+ const raw = await readOptional(join(projectDir, CONFIG_FILE));
206
+ if (raw !== null) return parseLegacyConfig(raw);
207
+ config = {
208
+ ...defaults
209
+ };
156
210
  }
157
- return first;
211
+ return {
212
+ ...config,
213
+ ...(await readManifestInfo(resolve(projectDir, config.root)))
214
+ };
158
215
  }
159
- /** grading.json (없으면 null). 문제가 있으면 오류 */
160
- async function loadGradingFile(projectDir) {
161
- let raw;
162
- try {
163
- raw = await readFile(join(projectDir, GRADING_DATA_FILE), 'utf8');
164
- } catch (e) {
165
- if (e.code === 'ENOENT') return null;
166
- throw e;
216
+ /**
217
+ * 옛 elice.config.json을 metadata.json + package.json "ecdk"로 옮기는 계획 (ADR 0011). 디스크는 바꾸지 않는다.
218
+ * 플랫폼 필드는 build가 만들던 것과 같은 metadata.json으로(학습 참고 내용은 commentary.txt가 있으면), 빌드 옵션 · template은
219
+ * package.json "ecdk"로 (이미 있는 키는 그대로). 원본에 metadata.json이 이미 있는데 플랫폼 필드도 있으면 옮기지 않는다
220
+ */
221
+ async function planLegacyMigration(projectDir) {
222
+ const raw = await readFile(join(projectDir, CONFIG_FILE), 'utf8');
223
+ const config = parseLegacyConfig(raw);
224
+ const json = JSON.parse(raw);
225
+ const pkg = (await readPackageJson(projectDir)) ?? {};
226
+ const current = isRecord(pkg[PACKAGE_CONFIG_KEY]) ? pkg[PACKAGE_CONFIG_KEY] : {};
227
+ const ecdk = {};
228
+ for (const key of BUILD_OPTION_KEYS) if (json[key] !== undefined && current[key] === undefined) ecdk[key] = json[key];
229
+ const root = typeof current.root === 'string' ? current.root : config.root;
230
+ const srcDir = resolve(projectDir, root);
231
+ const legacy = config.legacy ?? {};
232
+ const dropped = [...(legacy.gradingTypes !== undefined ? ['gradingTypes'] : []), ...(legacy.completion ?? [])];
233
+ const hasPlatform = PLATFORM_KEYS.some(k => legacy[k] !== undefined);
234
+ const existing = await readOptional(join(srcDir, rules.manifest.file));
235
+ if (existing !== null) return hasPlatform ? {
236
+ ok: false,
237
+ reason: `원본에 ${rules.manifest.file}이 이미 있고 ${CONFIG_FILE}에도 ${PLATFORM_KEYS.filter(k => legacy[k] !== undefined).join(' · ')}가 있어 자동으로 합치지 않습니다. ${rules.manifest.file}에 직접 옮기고 ${CONFIG_FILE}을 지워 주세요.`,
238
+ ecdk,
239
+ metadata: null,
240
+ dropped
241
+ } : {
242
+ ok: true,
243
+ ecdk,
244
+ metadata: null,
245
+ dropped
246
+ };
247
+ const commentaryName = legacy.commentary ?? rules.manifest.commentaryFile;
248
+ const hasCommentary = (await readOptional(join(srcDir, commentaryName))) !== null;
249
+ const text = serializeManifest({
250
+ kind: legacy.kind,
251
+ entries: legacy.screens ?? {
252
+ learn: rules.manifest.defaultEntry
253
+ },
254
+ commentary: hasCommentary ? commentaryName : undefined
255
+ }, rules);
256
+ return {
257
+ ok: true,
258
+ ecdk,
259
+ metadata: {
260
+ path: join(root, rules.manifest.file).replace(/\\/g, '/'),
261
+ text
262
+ },
263
+ dropped
264
+ };
265
+ }
266
+ /**
267
+ * 계획대로 옮긴다: metadata.json을 쓰고, package.json "ecdk"에 빌드 옵션을 더하고(package.json이 없으면 만듦),
268
+ * elice.config.json을 지운다. 옮긴 파일 목록을 돌려준다
269
+ */
270
+ async function applyLegacyMigration(projectDir, plan) {
271
+ if (!plan.ok) throw new Error(plan.reason);
272
+ const changed = [];
273
+ if (plan.metadata) {
274
+ await writeFile(join(projectDir, plan.metadata.path), plan.metadata.text);
275
+ changed.push(plan.metadata.path);
167
276
  }
168
- const fail = msg => new Error(`${GRADING_DATA_FILE}: ${msg}`);
169
- const parsed = parseGrading(parseJson(raw, fail));
170
- if (typeof parsed === 'string') throw fail(parsed);
277
+ const pkg = (await readPackageJson(projectDir)) ?? {
278
+ name: basename(resolve(projectDir)).toLowerCase().replace(/[^a-z0-9-_.]+/g, '-'),
279
+ private: true
280
+ };
281
+ const current = isRecord(pkg[PACKAGE_CONFIG_KEY]) ? pkg[PACKAGE_CONFIG_KEY] : {};
282
+ pkg[PACKAGE_CONFIG_KEY] = {
283
+ ...plan.ecdk,
284
+ ...current
285
+ };
286
+ await writeFile(join(projectDir, PACKAGE_FILE), `${JSON.stringify(pkg, null, 2)}\n`);
287
+ changed.push(PACKAGE_FILE);
288
+ await unlink(join(projectDir, CONFIG_FILE));
289
+ return changed;
290
+ }
291
+ /** elice.config.json에 옛 `gradingTypes`가 남아 있을 때 build · doctor가 보여 줄 경고. 없으면 null */
292
+ function legacyGradingTypesWarning(config) {
293
+ return config.legacy?.gradingTypes === undefined ? null : `${CONFIG_FILE}의 gradingTypes는 더 쓰지 않습니다 (2026-11-10, 지워 주세요). 채점 방식 · 답은 편집 화면(settings.grading)이 정합니다 (ADR 0009).`;
294
+ }
295
+ /** elice.config.json에 옛 완료 정책 필드 · 화면이 남아 있을 때 build · doctor가 보여 줄 경고. 없으면 null */
296
+ function legacyCompletionWarning(config) {
297
+ const fields = config.legacy?.completion;
298
+ return fields === undefined || fields.length === 0 ? null : `${CONFIG_FILE}의 ${fields.join(' · ')}는 더 쓰지 않습니다. ${COMPLETION_POLICIES_IGNORED.replace('metadata.json에서', `${CONFIG_FILE}에서`)}.`;
299
+ }
300
+ /**
301
+ * `ecdk dev` 편집 화면이 저장한 settings (`.ecdk/settings.json`, 없으면 {}). 흉내 서버가 시작할 때 읽어 다시 열어도 남는다.
302
+ * 형식이 틀리면 오류
303
+ */
304
+ async function loadSavedSettings(projectDir) {
305
+ const raw = await readOptional(join(projectDir, SETTINGS_DATA_FILE));
306
+ if (raw === null) return {};
307
+ const fail = msg => new Error(`${SETTINGS_DATA_FILE}: ${msg}`);
308
+ const json = parseJson(raw, fail);
309
+ if (typeof json !== 'object' || json === null || Array.isArray(json)) throw fail('객체여야 합니다 (ecdk dev의 내용 편집이 저장한 settings).');
310
+ return json;
311
+ }
312
+ /** 저장한 settings의 grading (없으면 null). 형식이 틀리면 오류 */
313
+ function savedGrading(settings) {
314
+ if (settings.grading === undefined || settings.grading === null) return null;
315
+ const parsed = parseGrading(settings.grading);
316
+ if (typeof parsed === 'string') throw new Error(`${SETTINGS_DATA_FILE}: grading: ${parsed}`);
171
317
  return parsed;
172
318
  }
173
319
  /**
174
- * 로컬 채점 흉내용 값: 완료 정책 + grading.json. 문제 설명(채점 없음)은 undefined
320
+ * 로컬 채점 흉내용 값: `.ecdk/settings.json`의 grading. 문제 설명(채점 없음)은 undefined
175
321
  */
176
322
  async function loadGrading(projectDir, config) {
177
323
  if (config.kind === 'description') return undefined;
178
- const grading = await loadGradingFile(projectDir);
179
324
  return {
180
- completion_policy: await loadCompletionPolicy(projectDir, config),
181
- grading
325
+ grading: savedGrading(await loadSavedSettings(projectDir))
182
326
  };
183
327
  }
328
+ /**
329
+ * 더 쓰지 않는 프로젝트 파일 (ADR 0011). 있으면 build · check가 경고(project.legacy-file)하고 옮기는 법을 알려 준다.
330
+ * content.json은 원본 폴더(root), 그 밖은 프로젝트 맨 위
331
+ */
332
+ const LEGACY_FILES = Object.freeze({
333
+ config: CONFIG_FILE,
334
+ content: 'content.json',
335
+ grading: 'grading.json'
336
+ });
184
337
 
185
- export { COMPLETION_DATA_FILE, COMPLETION_POLICIES, CONFIG_FILE, DEFAULT_COMPLETION_POLICY, GRADER_TYPES, GRADING_DATA_FILE, legacyGradingTypesWarning, loadCompletionPolicy, loadConfig, loadGrading, loadGradingFile, parseGrading };
338
+ export { BUILD_OPTION_KEYS, CONFIG_FILE, GRADER_TYPES, LEGACY_FILES, PACKAGE_CONFIG_KEY, PACKAGE_FILE, PLATFORM_KEYS, SETTINGS_DATA_FILE, applyLegacyMigration, legacyCompletionWarning, legacyGradingTypesWarning, loadConfig, loadGrading, loadSavedSettings, parseGrading, planLegacyMigration, readPackageJson, savedGrading };
@@ -0,0 +1,21 @@
1
+ /** 업데이트는 npm latest 태그를 따른다 (prerelease 태그는 보지 않음, 사용자 결정 2026-11-12) */
2
+ export declare const CLI_PACKAGE = "@eliceio/cdk-cli";
3
+ /** 이 환경 변수가 있으면 doctor가 npm에 묻지 않는다 (오프라인 · CI · 테스트) */
4
+ export declare const NO_UPDATE_CHECK_ENV = "ECDK_NO_UPDATE_CHECK";
5
+ /** doctor는 오래 기다리지 않는다 (확인 못 하면 건너뜀) */
6
+ export declare const LATEST_DOCTOR_TIMEOUT_MS = 3000;
7
+ export declare const LATEST_UPDATE_TIMEOUT_MS = 10000;
8
+ export type LatestResult = {
9
+ ok: true;
10
+ version: string;
11
+ } | {
12
+ ok: false;
13
+ error: string;
14
+ };
15
+ /**
16
+ * npm latest 태그 버전. 사용자의 .npmrc · 프록시가 그대로 적용되게 npm을 실행한다 (fetch 아님).
17
+ * Windows의 npm은 npm.cmd라 셸로 실행한다
18
+ */
19
+ export declare function npmLatest(timeoutMs: number): LatestResult;
20
+ /** latest가 current보다 새 버전인지 (prerelease 포함 semver). 같거나 current가 새 버전이면 false: 내리지 않는다 */
21
+ export declare function isNewer(latest: string, current: string): boolean;
@@ -0,0 +1,43 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { compareVersions } from '../rules/semver.js';
3
+
4
+ /** 업데이트는 npm latest 태그를 따른다 (prerelease 태그는 보지 않음, 사용자 결정 2026-11-12) */
5
+ const CLI_PACKAGE = '@eliceio/cdk-cli';
6
+ /** 이 환경 변수가 있으면 doctor가 npm에 묻지 않는다 (오프라인 · CI · 테스트) */
7
+ const NO_UPDATE_CHECK_ENV = 'ECDK_NO_UPDATE_CHECK';
8
+ /** doctor는 오래 기다리지 않는다 (확인 못 하면 건너뜀) */
9
+ const LATEST_DOCTOR_TIMEOUT_MS = 3000;
10
+ const LATEST_UPDATE_TIMEOUT_MS = 10000;
11
+ /**
12
+ * npm latest 태그 버전. 사용자의 .npmrc · 프록시가 그대로 적용되게 npm을 실행한다 (fetch 아님).
13
+ * Windows의 npm은 npm.cmd라 셸로 실행한다
14
+ */
15
+ function npmLatest(timeoutMs) {
16
+ const r = spawnSync('npm', ['view', CLI_PACKAGE, 'dist-tags.latest'], {
17
+ encoding: 'utf8',
18
+ timeout: timeoutMs,
19
+ shell: process.platform === 'win32'
20
+ });
21
+ if (r.error || r.signal) return {
22
+ ok: false,
23
+ error: r.error?.code === 'ETIMEDOUT' || r.signal ? `${timeoutMs / 1000}초 안에 응답 없음` : r.error?.message ?? '실행 실패'
24
+ };
25
+ const version = (r.stdout ?? '').trim();
26
+ if (r.status !== 0 || compareVersions(version, version) === undefined) {
27
+ const detail = `${r.stderr ?? ''}`.trim().split('\n').find(l => /ERR!|error/i.test(l));
28
+ return {
29
+ ok: false,
30
+ error: detail ?? `npm view 종료 코드 ${r.status ?? '-'}`
31
+ };
32
+ }
33
+ return {
34
+ ok: true,
35
+ version
36
+ };
37
+ }
38
+ /** latest가 current보다 새 버전인지 (prerelease 포함 semver). 같거나 current가 새 버전이면 false: 내리지 않는다 */
39
+ function isNewer(latest, current) {
40
+ return (compareVersions(latest, current) ?? 0) > 0;
41
+ }
42
+
43
+ export { CLI_PACKAGE, LATEST_DOCTOR_TIMEOUT_MS, LATEST_UPDATE_TIMEOUT_MS, NO_UPDATE_CHECK_ENV, isNewer, npmLatest };
@@ -2,7 +2,8 @@ import { type BuildInfo } from '../rules/index.js';
2
2
  import type { SourceFile } from './collect.js';
3
3
  /**
4
4
  * metadata.json의 build. 같은 입력이면 같은 결과가 나오도록 시각 등 바뀌는 값은 넣지 않는다.
5
- * template은 ecdk create가 elice.config.json에 적은 값, sdk는 묶어 넣은 SDK 파일 머리말에서 읽는다.
5
+ * template은 ecdk create가 package.json "ecdk"에 적은 값. sdk는 zip lib/cdk.js 머리말에서 읽는다
6
+ * (build가 node_modules/@eliceio/cdk에서 넣으며 붙인 것, 옛 프로젝트는 복사본 머리말).
6
7
  */
7
8
  export declare function createBuildInfo(engine: string, extra?: {
8
9
  template?: string | undefined;
@@ -8,7 +8,8 @@ import { PROTOCOL_VERSION } from './protocol.js';
8
8
  const SDK_HEADER = /^\/\* @eliceio\/cdk (\S+)(?: \(([^)]+)\))?/;
9
9
  /**
10
10
  * metadata.json의 build. 같은 입력이면 같은 결과가 나오도록 시각 등 바뀌는 값은 넣지 않는다.
11
- * template은 ecdk create가 elice.config.json에 적은 값, sdk는 묶어 넣은 SDK 파일 머리말에서 읽는다.
11
+ * template은 ecdk create가 package.json "ecdk"에 적은 값. sdk는 zip lib/cdk.js 머리말에서 읽는다
12
+ * (build가 node_modules/@eliceio/cdk에서 넣으며 붙인 것, 옛 프로젝트는 복사본 머리말).
12
13
  */
13
14
  function createBuildInfo(engine, extra = {}) {
14
15
  const sdkFile = extra.files?.find(f => f.path === 'lib/cdk.js');
package/es/core/minify.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { transform } from 'esbuild';
2
2
 
3
3
  /**
4
- * `elice.config.json`의 `"minify": true`일 때 zip에 넣기 전에 줄인다 (용량 줄이기).
4
+ * package.json `"ecdk"`의 `"minify": true`일 때 zip에 넣기 전에 줄인다 (용량 줄이기).
5
5
  * 파일 단위 변환(번들 아님)이라 경로 · import · 파일 구성은 그대로다.
6
6
  *
7
7
  * - JS(.js · .mjs): 공백 · 주석 제거, 이름 줄이기. ES 모듈의 import/export와 top-level await는 그대로.
@@ -60,7 +60,7 @@ async function minifyFiles(files, {
60
60
  }
61
61
  } catch (e) {
62
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를 끄세요.`);
63
+ throw new Error(`minify 실패: ${f.path}${detail?.location ? `:${detail.location.line}` : ''} ${detail?.text ?? e.message}. 문법을 확인하거나 package.json "ecdk"의 minify를 끄세요.`);
64
64
  }
65
65
  } else return f;
66
66
  const data = encoder.encode(next);
@@ -1,5 +1,5 @@
1
1
  import { type Excluded, type SourceFile } from './collect.js';
2
- import type { ContentConfig } from './config.js';
2
+ import { type ContentConfig } from './config.js';
3
3
  export interface PreparedContent {
4
4
  srcDir: string;
5
5
  outDir: string;
@@ -7,6 +7,22 @@ export interface PreparedContent {
7
7
  /** zip에 들어갈 파일 전부 (metadata.json 포함) */
8
8
  files: SourceFile[];
9
9
  excluded: Excluded[];
10
+ sdk: PreparedSdk;
11
+ }
12
+ /** SDK(@eliceio/cdk)를 어디서 넣었는지 (ADR 0010 최종 결정) */
13
+ export interface PreparedSdk {
14
+ /** package.json에 @eliceio/cdk가 있는지 */
15
+ declared: boolean;
16
+ /** 적은 범위 */
17
+ range?: string | undefined;
18
+ /** zip에 넣은 설치 버전 */
19
+ version?: string | undefined;
20
+ /** 적었는데 node_modules에 없음 (requireSdk: false일 때만, 아니면 오류) */
21
+ missing: boolean;
22
+ /** package.json에 없고 원본에 lib/cdk.js 복사본이 있는 옛 프로젝트 (sdk.lib-copy 경고) */
23
+ legacyCopy: boolean;
10
24
  }
11
25
  /** build와 doctor가 같은 결과를 보도록: 수집 → 엔진 → metadata.json(화면 + 빌드 정보). 디스크에는 쓰지 않는다. */
12
- export declare function prepareContent(projectDir: string, config: ContentConfig): Promise<PreparedContent>;
26
+ export declare function prepareContent(projectDir: string, config: ContentConfig, options?: {
27
+ requireSdk?: boolean;
28
+ }): Promise<PreparedContent>;