@eliceio/cdk-cli 0.1.0-alpha.6 → 0.1.0-alpha.7

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 (59) hide show
  1. package/README.md +70 -71
  2. package/es/cli.js +7 -22
  3. package/es/commands/build/index.d.ts +5 -3
  4. package/es/commands/build/index.js +16 -7
  5. package/es/commands/create/scaffold.d.ts +2 -0
  6. package/es/commands/create/scaffold.js +15 -1
  7. package/es/commands/doctor/index.d.ts +1 -1
  8. package/es/commands/doctor/index.js +4 -5
  9. package/es/commands/setup/index.d.ts +4 -7
  10. package/es/commands/setup/index.js +41 -70
  11. package/es/commands/uninstall/index.d.ts +9 -8
  12. package/es/commands/uninstall/index.js +41 -47
  13. package/es/commands/update/index.d.ts +4 -2
  14. package/es/commands/update/index.js +27 -18
  15. package/es/core/config.d.ts +1 -1
  16. package/es/core/config.js +2 -2
  17. package/es/{commands/mcp/index.d.ts → core/mcp.d.ts} +11 -18
  18. package/es/{commands/mcp/index.js → core/mcp.js} +29 -51
  19. package/es/core/minify.js +31 -2
  20. package/es/core/sandbox.d.ts +25 -0
  21. package/es/core/sandbox.js +104 -5
  22. package/es/{commands/skill/index.d.ts → core/skills.d.ts} +1 -17
  23. package/es/{commands/skill/index.js → core/skills.js} +6 -22
  24. package/es/dev/grading.d.ts +1 -1
  25. package/es/dev/grading.js +1 -1
  26. package/es/dev/host-page.js +2 -2
  27. package/es/rules/check.js +3 -3
  28. package/es/rules/csp.d.ts +1 -1
  29. package/es/rules/csp.js +1 -1
  30. package/es/rules/index.d.ts +1 -1
  31. package/es/rules/index.js +1 -1
  32. package/es/rules/unused.d.ts +2 -0
  33. package/es/rules/unused.js +4 -3
  34. package/package.json +2 -2
  35. package/skills/elice-content-create/SKILL.md +2 -1
  36. package/skills/elice-content-guide/topics/01-check-the-environment.md +2 -2
  37. package/skills/elice-content-guide/topics/02-design-the-material.md +2 -0
  38. package/skills/elice-content-guide/topics/03-create-the-project.md +2 -2
  39. package/skills/elice-content-guide/topics/05-screen-code.md +44 -13
  40. package/skills/elice-content-guide/topics/10-build.md +1 -1
  41. package/skills/elice-content-guide/topics/12-upload-with-the-material-mcp.md +2 -2
  42. package/skills/elice-content-publish/SKILL.md +1 -1
  43. package/templates/_shared/lib/cdk-mock.js +2 -2
  44. package/templates/_shared/lib/elice-content-editor.d.ts +80 -0
  45. package/templates/_shared/lib/elice-content-editor.js +1062 -0
  46. package/templates/_shared/lib/elice-content.css +332 -0
  47. package/templates/_shared/lib/elice-content.js +10 -3
  48. package/templates/blank/README.md +27 -2
  49. package/templates/blank/commentary.txt +5 -0
  50. package/templates/blank/screens/edit.js +38 -17
  51. package/templates/blank/screens/instructor.js +20 -8
  52. package/templates/blank/screens/learn.js +151 -13
  53. package/templates/blank/styles.css +171 -0
  54. package/templates/blank/template.json +2 -2
  55. package/templates/quiz/core/model.js +1 -1
  56. package/templates/quiz/screens/edit.js +14 -2
  57. package/templates/quiz/styles.css +11 -0
  58. package/templates/quiz/template.json +1 -1
  59. package/templates/quiz/ui/texts.js +1 -1
@@ -5,12 +5,12 @@ import { fileURLToPath } from 'node:url';
5
5
  import { loadConfig } from '../../core/config.js';
6
6
  import { CLI_PACKAGE, LATEST_UPDATE_TIMEOUT_MS, isNewer, npmLatest } from '../../core/latest.js';
7
7
  import { SDK_PACKAGE, UPDATE_COMMAND, readProjectSdk } from '../../core/sdk.js';
8
+ import { skillsDir, reloadNotes } from '../../core/skills.js';
8
9
  import { listTemplates } from '../../core/templates.js';
9
10
  import { VERSION } from '../../version.js';
10
11
  import { templateNotice } from '../doctor/index.js';
11
- import { skillsDir, reloadNotes } from '../skill/index.js';
12
12
 
13
- const usage = `사용법: ecdk update [--check] [--yes] [--json]
13
+ const usage = `사용법: ecdk update [--project] [--check] [--json]
14
14
 
15
15
  npm latest 태그의 ecdk로 올린다. 차례로:
16
16
  1. CLI 설치: npm install -g ${CLI_PACKAGE}@<latest> (npx로 실행 중이면 건너뜀)
@@ -18,8 +18,9 @@ const usage = `사용법: ecdk update [--check] [--yes] [--json]
18
18
  손으로 고친 스킬은 그대로 둠, 바꾸려면 ecdk setup --only skills --force
19
19
  3. 프로젝트 SDK: 현재 폴더가 ${SDK_PACKAGE}를 쓰는 프로젝트면 ${UPDATE_COMMAND} (화면 · 템플릿 코드는 바꾸지 않음)
20
20
  지금 버전이 latest와 같거나 더 새 버전이면 아무것도 하지 않는다 (내리지 않음).
21
- --check 확인만 (지금 · 최신 버전과 실행할 명령)
22
- --yes 묻지 않고 실행 (지금은 늘 묻지 않음, 스크립트용)
21
+
22
+ --project ~/.claude/skills/ 대신 현재 폴더의 .claude/skills/를 갱신한다 (2단계를 setup --only skills --project로)
23
+ --check 확인만 (지금 · 최신 버전과 실행할 명령)
23
24
 
24
25
  종료 코드: 0 최신이거나 업데이트함 · 1 최신 버전 확인 실패 · 단계 실패 · 2 잘못된 사용`;
25
26
  /** 실행 못 함(명령 없음 등)은 code -1 */
@@ -62,14 +63,15 @@ const PERMISSION = /\bEACCES\b|\bEPERM\b|permission denied/i;
62
63
  const PERMISSION_HINT = '`sudo` 대신 `npx`로 실행, 또는 fnm · Homebrew로 Node.js 재설치';
63
64
  const HELPY_NOTE = "Helpy Code 데스크톱(macOS)에서 ecdk · npm을 찾지 못하면 로그인 셸로 실행합니다: zsh -ilc 'ecdk update'";
64
65
  const cliCommand = latest => `npm install -g ${CLI_PACKAGE}@${latest}`;
65
- const SKILL_ARGS = ['setup', '--only', 'skills'];
66
- const SKILL_COMMAND = `ecdk ${SKILL_ARGS.join(' ')}`;
66
+ /** --project면 현재 폴더의 .claude/skills/ */
67
+ const skillArgs = project => ['setup', '--only', 'skills', ...(project ? ['--project'] : [])];
68
+ const skillCommandOf = project => `ecdk ${skillArgs(project).join(' ')}`;
67
69
  /**
68
70
  * npx로 실행 중이면 이 프로세스(옛 캐시일 수 있음)가 아니라 latest 버전으로 스킬을 설치한다.
69
71
  * 옛 ecdk의 update도 새로 설치한 ecdk를 실행하므로 새 명령(setup --only skills)을 써도 된다
70
72
  */
71
- const npxSkillArgs = latest => ['-y', `${CLI_PACKAGE}@${latest}`, ...SKILL_ARGS];
72
- const skillCommand = (latest, npx) => npx ? ['npx', ...npxSkillArgs(latest)].join(' ') : SKILL_COMMAND;
73
+ const npxSkillArgs = (latest, project) => ['-y', `${CLI_PACKAGE}@${latest}`, ...skillArgs(project)];
74
+ const skillCommand = (latest, npx, project) => npx ? ['npx', ...npxSkillArgs(latest, project)].join(' ') : skillCommandOf(project);
73
75
  /** 프로젝트 SDK 단계: 현재 폴더 package.json에 @eliceio/cdk가 있을 때만 */
74
76
  async function projectStep(cwd) {
75
77
  if (!(await readProjectSdk(cwd))) return {
@@ -84,7 +86,7 @@ async function projectStep(cwd) {
84
86
  };
85
87
  }
86
88
  /** 할 일 (아직 실행하지 않음) */
87
- async function plan(env, latest, npx) {
89
+ async function plan(env, latest, npx, project) {
88
90
  return [npx ? {
89
91
  id: 'cli.install',
90
92
  status: 'skipped',
@@ -96,7 +98,7 @@ async function plan(env, latest, npx) {
96
98
  }, {
97
99
  id: 'skill.install',
98
100
  status: 'planned',
99
- command: skillCommand(latest, npx),
101
+ command: skillCommand(latest, npx, project),
100
102
  message: npx ? `npx로 ${latest} ecdk를 받아 설치` : '새로 설치한 ecdk로 설치'
101
103
  }, await projectStep(env.cwd)];
102
104
  }
@@ -141,7 +143,8 @@ async function update(env, opts) {
141
143
  latest: latest.version,
142
144
  upToDate: true
143
145
  });
144
- const steps = await plan(env, latest.version, npx);
146
+ const projectSkills = opts.project ?? false;
147
+ const steps = await plan(env, latest.version, npx, projectSkills);
145
148
  const result = make({
146
149
  ok: true,
147
150
  latest: latest.version,
@@ -168,24 +171,29 @@ async function update(env, opts) {
168
171
  } else env.log(`[1/3] CLI 설치 건너뜀: ${cli.message}`);
169
172
  // 2. 스킬: 새 스킬은 새 버전에 들어 있으므로 새 ecdk로 설치한다 (PATH의 새 ecdk, npx면 npx로 latest를 받아서)
170
173
  // 이 프로세스(npx 옛 캐시일 수 있음)에서 설치하면 옛 스킬을 깔고 완료로 알리게 되므로 하지 않는다
171
- const skillCmd = skills.command ?? SKILL_COMMAND;
174
+ const skillCmd = skills.command ?? skillCommandOf(projectSkills);
172
175
  // 새 ecdk가 쓰기 전에 본다 (새 ecdk의 안내는 옛 ecdk와 다를 수 있어 여기서 다시 알린다)
173
- const userSkills = skillsDir({
174
- project: false,
176
+ const skillsPath = skillsDir({
177
+ project: projectSkills,
178
+ cwd: env.cwd,
175
179
  home: env.home
176
180
  });
177
- const skillsDirExisted = existsSync(userSkills);
181
+ const skillsDirExisted = existsSync(skillsPath);
178
182
  env.log(`[2/3] 스킬 갱신: ${skillCmd}`);
179
- const sr = npx ? await env.run('npx', npxSkillArgs(latest.version)) : await env.run('ecdk', SKILL_ARGS);
183
+ // --project는 현재 폴더에 설치하므로 그 폴더에서 실행
184
+ const skillOpts = projectSkills ? {
185
+ cwd: env.cwd
186
+ } : {};
187
+ const sr = npx ? await env.run('npx', npxSkillArgs(latest.version, projectSkills), skillOpts) : await env.run('ecdk', skillArgs(projectSkills), skillOpts);
180
188
  if (sr.code === 0) skills.status = 'done';else if (sr.code === 1) {
181
189
  skills.status = 'warn';
182
- skills.message = `손으로 고친 스킬은 그대로 둠 (바꾸려면 ${SKILL_COMMAND} --force)`;
190
+ skills.message = `손으로 고친 스킬은 그대로 둠 (바꾸려면 ${skillCommandOf(projectSkills)} --force)`;
183
191
  } else {
184
192
  skills.status = 'failed';
185
193
  const why = PERMISSION.test(sr.output) ? `권한이 없어 설치하지 못했습니다 (EACCES). ${PERMISSION_HINT}` : `새 ecdk를 실행하지 못했습니다 (${sr.code < 0 ? sr.output.trim() : `종료 코드 ${sr.code}`})`;
186
194
  skills.message = npx ? `${why}. 직접 실행해 주세요: ${skillCmd}` : `${why}. 터미널을 새로 연 뒤 ${skillCmd}`;
187
195
  }
188
- result.skillsDirCreated = skills.status !== 'failed' && !skillsDirExisted && existsSync(userSkills);
196
+ result.skillsDirCreated = skills.status !== 'failed' && !skillsDirExisted && existsSync(skillsPath);
189
197
  // 3. 프로젝트 SDK (화면 · 템플릿 코드는 건드리지 않고 안내만)
190
198
  if (project.status === 'planned') {
191
199
  env.log(`[3/3] 프로젝트 SDK: ${UPDATE_COMMAND} (${env.cwd})`);
@@ -240,6 +248,7 @@ async function run(args, env = defaultUpdateEnv(), current) {
240
248
  cwd: resolve(env.cwd)
241
249
  }, {
242
250
  check: args.check,
251
+ project: args.project,
243
252
  current
244
253
  });
245
254
  return {
@@ -51,7 +51,7 @@ export interface ContentConfig {
51
51
  outDir: string;
52
52
  /** 추가로 뺄 파일·폴더 (basename glob `*` 또는 프로젝트 기준 경로 접두사) */
53
53
  exclude: string[];
54
- /** true면 build가 JS · CSS · JSON을 줄여 zip에 넣는다 (용량 줄이기). 기본 false */
54
+ /** build가 JS · CSS · JSON을 줄여(주석 빼고) zip에 넣는다. 기본 true, false면 끈다 */
55
55
  minify?: boolean;
56
56
  /** minify와 함께: 줄인 JS · CSS마다 .map을 zip에 넣어 운영에서도 원본 위치로 오류를 본다 (용량이 늘어남) */
57
57
  sourcemap?: boolean;
package/es/core/config.js CHANGED
@@ -100,7 +100,7 @@ function parseBuildOptions(json, fail) {
100
100
  if (json.exclude !== undefined && !(Array.isArray(json.exclude) && json.exclude.every(x => typeof x === 'string'))) throw fail('exclude는 문자열 배열이어야 합니다.');
101
101
  if (json.minify !== undefined && typeof json.minify !== 'boolean') throw fail('minify는 true 또는 false여야 합니다.');
102
102
  if (json.sourcemap !== undefined && typeof json.sourcemap !== 'boolean') throw fail('sourcemap은 true 또는 false여야 합니다.');
103
- if (json.sourcemap && !json.minify) throw fail('sourcemap은 minify와 함께 씁니다 ("minify": true). 줄이지 않으면 원본 그대로라 필요 없습니다.');
103
+ if (json.sourcemap && json.minify === false) throw fail('sourcemap은 minify와 함께 씁니다 ("minify": false를 지우세요). 줄이지 않으면 원본 그대로라 필요 없습니다.');
104
104
  if (json.template !== undefined && typeof json.template !== 'string') throw fail('template은 문자열이어야 합니다 (ecdk create가 적는 값).');
105
105
  const out = {};
106
106
  for (const key of BUILD_OPTION_KEYS) if (json[key] !== undefined) out[key] = json[key];
@@ -109,7 +109,7 @@ function parseBuildOptions(json, fail) {
109
109
  /** package.json "ecdk": 빌드 옵션만. 플랫폼 필드는 metadata.json으로 안내한다 */
110
110
  function parsePackageOptions(value) {
111
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 }`);
112
+ if (!isRecord(value)) throw fail(`객체여야 합니다. 예: { "template": "quiz@1.0.0", "minify": false }`);
113
113
  rejectAnswers(value, fail);
114
114
  const platform = Object.keys(value).filter(k => PLATFORM_KEYS.includes(k));
115
115
  if (platform.length > 0) throw fail(`${platform.join(' · ')}는 원본의 metadata.json에 적습니다 (ADR 0011). package.json "ecdk"에는 빌드 옵션(${BUILD_OPTION_KEYS.join(' · ')})만.`);
@@ -1,11 +1,10 @@
1
1
  export declare const MCP_NAME = "elice-material";
2
2
  /**
3
- * 서버 환경 → MCP 주소. 표는 여기 하나만 둔다.
4
- * prod는 material API 주소(api-material.elice.io)에 /mcp를 붙인 **가정**이다: 2026-11-10 운영에는 아직 MCP가 없고
5
- * (GET 405), 백엔드가 주소를 확정해 주기로 함 (백엔드 요청 B1). 그래서 등록 전에 probe로 확인한다.
3
+ * 운영 서버 MCP 주소. 그 밖의 서버는 --url로 준다 (사내 서버 주소는 패키지에 두지 않음).
4
+ * material API 주소(api-material.elice.io)에 /mcp를 붙인 **가정**이다: 2026-11-10 운영에는 아직 MCP가 없고
5
+ * (GET 405), 백엔드가 주소를 확정해 주기로 함. 그래서 등록 전에 probe로 확인한다.
6
6
  */
7
- export declare const MCP_ENVS: Record<string, string>;
8
- export declare const DEFAULT_ENV = "prod";
7
+ export declare const MCP_URL = "https://api-material.elice.io/mcp";
9
8
  export type McpTarget = 'claude' | 'helpycode';
10
9
  /** 바깥 세계(HOME · PATH · 명령 실행)를 바꿔 끼울 수 있게 (테스트는 실제 설정을 건드리지 않음) */
11
10
  export interface McpEnv {
@@ -26,8 +25,6 @@ export interface McpEnv {
26
25
  ok: boolean;
27
26
  detail: string;
28
27
  }>;
29
- /** 환경 변수 ECDK_ENV */
30
- envVar?: string | undefined;
31
28
  }
32
29
  /** MCP initialize를 POST해 본다. 로그인 전이면 401과 www-authenticate(resource_metadata)가 와야 한다 */
33
30
  export declare function probeMcp(url: string): Promise<{
@@ -37,8 +34,8 @@ export declare function probeMcp(url: string): Promise<{
37
34
  export declare function defaultMcpEnv(): McpEnv;
38
35
  export declare const helpyConfigPath: (env: McpEnv) => string;
39
36
  export declare function detectTargets(env: McpEnv): McpTarget[];
40
- /** 주소로 환경 이름 (표에 없으면 custom) */
41
- export declare const envOfUrl: (url: string) => string;
37
+ /** 주소로 환경 이름: 운영 주소면 prod, 아니면 custom (--url로 준 주소) */
38
+ export declare const envOfUrl: (url: string) => "prod" | "custom";
42
39
  export type ClaudeRegistration = {
43
40
  state: 'user';
44
41
  url: string;
@@ -59,8 +56,6 @@ export type ClaudeRegistration = {
59
56
  * Scope 줄이 없으면(옛 Claude CLI) 사용자 범위로 본다.
60
57
  */
61
58
  export declare function claudeRegistration(env: McpEnv): ClaudeRegistration;
62
- /** Claude Code 사용자 범위에 등록된 주소 (없거나 확인 못 하면 null) */
63
- export declare function claudeRegisteredUrl(env: McpEnv): string | null;
64
59
  type HelpyConfig = {
65
60
  kind: 'missing';
66
61
  } | {
@@ -75,7 +70,7 @@ type HelpyConfig = {
75
70
  export declare function readHelpyConfig(path: string): HelpyConfig;
76
71
  /** Helpy Code 설정에 등록된 주소 (없으면 null, 읽을 수 없으면 undefined) */
77
72
  export declare function helpyRegisteredUrl(env: McpEnv): string | null | undefined;
78
- export type SetupAction = 'added' | 'replaced' | 'skipped' | 'would-add' | 'would-replace' | 'conflict' | 'manual' | 'unreachable' | 'failed';
73
+ export type SetupAction = 'added' | 'replaced' | 'skipped' | 'conflict' | 'manual' | 'unreachable' | 'failed';
79
74
  export interface SetupStep {
80
75
  target: McpTarget;
81
76
  action: SetupAction;
@@ -88,7 +83,7 @@ export interface SetupResult {
88
83
  probe: {
89
84
  ok: boolean;
90
85
  detail: string;
91
- } | 'skipped';
86
+ };
92
87
  url: string;
93
88
  targets: McpTarget[];
94
89
  steps: SetupStep[];
@@ -99,7 +94,6 @@ export declare function setup(opts: {
99
94
  envName: string;
100
95
  url: string;
101
96
  target: 'claude' | 'helpycode' | 'all';
102
- dryRun: boolean;
103
97
  force: boolean;
104
98
  }): Promise<SetupResult>;
105
99
  export declare const NEEDS_PERSON: SetupAction[];
@@ -112,11 +106,10 @@ export type ResolvedUrl = {
112
106
  ok: false;
113
107
  error: string;
114
108
  };
115
- /** 주소: --url > --env > ECDK_ENV > prod */
109
+ /** 주소: --url, 없으면 운영 */
116
110
  export declare function resolveUrl(args: {
117
- envName: string | undefined;
118
111
  url: string | undefined;
119
- }, env: McpEnv): ResolvedUrl;
112
+ }): ResolvedUrl;
120
113
  /** 사람용 출력의 MCP 부분 (환경 · 서버 확인 · 도구별 결과) */
121
- export declare function formatSetupLines(result: SetupResult, source: string, dryRun: boolean): string[];
114
+ export declare function formatSetupLines(result: SetupResult, source: string): string[];
122
115
  export {};
@@ -4,20 +4,16 @@ import { homedir } from 'node:os';
4
4
  import { delimiter, join, dirname } from 'node:path';
5
5
 
6
6
  /*
7
- * Elice 학습자료 서버 MCP(elice-material)를 AI 도구에 등록한다 (명령은 ecdk setup --only mcp · ecdk setup).
7
+ * Elice 학습자료 서버 MCP(elice-material)를 AI 도구에 등록 · 확인한다 (ecdk setup · uninstall · doctor가 쓴다).
8
8
  * 등록 전에 서버에 MCP가 있는지 확인하고, 로그인은 등록 뒤 각 도구에서 한다.
9
9
  */
10
10
  const MCP_NAME = 'elice-material';
11
11
  /**
12
- * 서버 환경 → MCP 주소. 표는 여기 하나만 둔다.
13
- * prod는 material API 주소(api-material.elice.io)에 /mcp를 붙인 **가정**이다: 2026-11-10 운영에는 아직 MCP가 없고
14
- * (GET 405), 백엔드가 주소를 확정해 주기로 함 (백엔드 요청 B1). 그래서 등록 전에 probe로 확인한다.
12
+ * 운영 서버 MCP 주소. 그 밖의 서버는 --url로 준다 (사내 서버 주소는 패키지에 두지 않음).
13
+ * material API 주소(api-material.elice.io)에 /mcp를 붙인 **가정**이다: 2026-11-10 운영에는 아직 MCP가 없고
14
+ * (GET 405), 백엔드가 주소를 확정해 주기로 함. 그래서 등록 전에 probe로 확인한다.
15
15
  */
16
- const MCP_ENVS = {
17
- prod: 'https://api-material.elice.io/mcp',
18
- qa5: 'https://dev-v5-material-api.dev.elicer.io/mcp'
19
- };
20
- const DEFAULT_ENV = 'prod';
16
+ const MCP_URL = 'https://api-material.elice.io/mcp';
21
17
  const PROBE_TIMEOUT_MS = 5000;
22
18
  /** MCP initialize를 POST해 본다. 로그인 전이면 401과 www-authenticate(resource_metadata)가 와야 한다 */
23
19
  async function probeMcp(url) {
@@ -85,8 +81,7 @@ function defaultMcpEnv() {
85
81
  };
86
82
  },
87
83
  exists: existsSync,
88
- probe: probeMcp,
89
- envVar: process.env.ECDK_ENV
84
+ probe: probeMcp
90
85
  };
91
86
  }
92
87
  const helpyConfigPath = env => join(env.home, '.config', 'helpycode', 'helpycode.jsonc');
@@ -96,8 +91,8 @@ function detectTargets(env) {
96
91
  if (env.exists(join(env.home, '.config', 'helpycode')) || env.which('helpycode') || env.platform === 'darwin' && env.exists('/Applications/HelpyCode.app')) found.push('helpycode');
97
92
  return found;
98
93
  }
99
- /** 주소로 환경 이름 (표에 없으면 custom) */
100
- const envOfUrl = url => Object.entries(MCP_ENVS).find(([, u]) => u === url)?.[0] ?? 'custom';
94
+ /** 주소로 환경 이름: 운영 주소면 prod, 아니면 custom (--url로 준 주소) */
95
+ const envOfUrl = url => url === MCP_URL ? 'prod' : 'custom';
101
96
  const CLAUDE_TIMEOUT_MS = 5000;
102
97
  /**
103
98
  * Claude Code 등록 상태. `claude mcp get`은 서버 연결 상태까지 확인해 느릴 수 있으므로
@@ -129,11 +124,6 @@ function claudeRegistration(env) {
129
124
  url
130
125
  };
131
126
  }
132
- /** Claude Code 사용자 범위에 등록된 주소 (없거나 확인 못 하면 null) */
133
- function claudeRegisteredUrl(env) {
134
- const reg = claudeRegistration(env);
135
- return reg.state === 'user' ? reg.url : null;
136
- }
137
127
  /** 주석 · 끝 쉼표가 있으면 다시 쓰지 않는다 (지우면 사람이 적은 설명이 사라짐) */
138
128
  function readHelpyConfig(path) {
139
129
  if (!existsSync(path)) return {
@@ -174,7 +164,7 @@ function helpyRegisteredUrl(env) {
174
164
  const mcp = config.data.mcp;
175
165
  return mcp?.[MCP_NAME]?.url ?? null;
176
166
  }
177
- function setupClaude(env, url, dryRun, force) {
167
+ function setupClaude(env, url, force) {
178
168
  const reg = claudeRegistration(env);
179
169
  if (reg.state === 'unknown') return {
180
170
  target: 'claude',
@@ -194,11 +184,6 @@ function setupClaude(env, url, dryRun, force) {
194
184
  message: `다른 주소로 등록돼 있습니다 (${current}). 바꾸려면 --force`
195
185
  };
196
186
  const add = ['mcp', 'add', '--transport', 'http', '--scope', 'user', MCP_NAME, url];
197
- if (dryRun) return {
198
- target: 'claude',
199
- action: current ? 'would-replace' : 'would-add',
200
- message: `${current ? `claude mcp remove ${MCP_NAME} --scope user 뒤 ` : ''}claude ${add.join(' ')}${localNote}`
201
- };
202
187
  if (current) {
203
188
  const rm = env.exec('claude', ['mcp', 'remove', MCP_NAME, '--scope', 'user'], 30000);
204
189
  if (rm.code !== 0 || rm.timedOut) return {
@@ -219,7 +204,7 @@ function setupClaude(env, url, dryRun, force) {
219
204
  message: `Claude Code 사용자 설정에 ${current ? '바꿈' : '등록'} (${url})${localNote}`
220
205
  };
221
206
  }
222
- function setupHelpy(env, url, dryRun, force) {
207
+ function setupHelpy(env, url, force) {
223
208
  const path = helpyConfigPath(env);
224
209
  const config = readHelpyConfig(path);
225
210
  const block = JSON.stringify({
@@ -260,11 +245,6 @@ function setupHelpy(env, url, dryRun, force) {
260
245
  action: 'conflict',
261
246
  message: `다른 주소로 등록돼 있습니다 (${current}). 바꾸려면 --force`
262
247
  };
263
- if (dryRun) return {
264
- target: 'helpycode',
265
- action: current ? 'would-replace' : 'would-add',
266
- message: `${path}의 mcp.${MCP_NAME}를 ${url}로${config.kind === 'json' ? env.exists(`${path}.bak`) ? ' (.bak은 이미 있어 그대로 둠)' : ' (원본은 .bak)' : ' (새 파일)'}`
267
- };
268
248
  mcp[MCP_NAME] = helpyEntry(url);
269
249
  data.mcp = mcp;
270
250
  mkdirSync(dirname(path), {
@@ -294,9 +274,9 @@ async function setup(opts) {
294
274
  url
295
275
  } = opts;
296
276
  const targets = opts.target === 'all' ? detectTargets(opts.env) : [opts.target];
297
- const login = [...targets.flatMap(t => LOGIN[t]), ...(opts.envName === 'qa5' ? ['로그인 창(accounts.qa-web-5)에서 dev5 계정으로 로그인'] : [])];
298
- const probe = opts.dryRun ? 'skipped' : await opts.env.probe(url);
299
- if (probe !== 'skipped' && !probe.ok && !opts.force) return {
277
+ const login = targets.flatMap(t => LOGIN[t]);
278
+ const probe = await opts.env.probe(url);
279
+ if (!probe.ok && !opts.force) return {
300
280
  env: opts.envName,
301
281
  probe,
302
282
  url,
@@ -308,7 +288,7 @@ async function setup(opts) {
308
288
  })),
309
289
  login
310
290
  };
311
- const steps = targets.map(t => t === 'claude' ? setupClaude(opts.env, url, opts.dryRun, opts.force) : setupHelpy(opts.env, url, opts.dryRun, opts.force));
291
+ const steps = targets.map(t => t === 'claude' ? setupClaude(opts.env, url, opts.force) : setupHelpy(opts.env, url, opts.force));
312
292
  return {
313
293
  env: opts.envName,
314
294
  probe,
@@ -319,30 +299,28 @@ async function setup(opts) {
319
299
  };
320
300
  }
321
301
  const NEEDS_PERSON = ['conflict', 'manual', 'unreachable', 'failed'];
322
- /** 주소: --url > --env > ECDK_ENV > prod */
323
- function resolveUrl(args, env) {
324
- if (args.url && !/^https:\/\/\S+$/.test(args.url)) return {
325
- ok: false,
326
- error: `--url은 https 주소여야 합니다: ${args.url}`
302
+ /** 주소: --url, 없으면 운영 */
303
+ function resolveUrl(args) {
304
+ if (args.url === undefined) return {
305
+ ok: true,
306
+ envName: envOfUrl(MCP_URL),
307
+ source: '기본값',
308
+ url: MCP_URL
327
309
  };
328
- const envName = args.url ? envOfUrl(args.url) : args.envName ?? env.envVar ?? DEFAULT_ENV;
329
- const source = args.url ? '--url' : args.envName ? '--env' : env.envVar ? 'ECDK_ENV' : '기본값';
330
- const url = args.url ?? MCP_ENVS[envName];
331
- if (!url) return {
310
+ if (!/^https:\/\/\S+$/.test(args.url)) return {
332
311
  ok: false,
333
- error: `알 수 없는 환경: ${envName} (가능: ${Object.keys(MCP_ENVS).join(', ')}, 그 밖은 --url)`
312
+ error: `--url은 https 주소여야 합니다: ${args.url}`
334
313
  };
335
314
  return {
336
315
  ok: true,
337
- envName,
338
- source,
339
- url
316
+ envName: envOfUrl(args.url),
317
+ source: '--url',
318
+ url: args.url
340
319
  };
341
320
  }
342
321
  /** 사람용 출력의 MCP 부분 (환경 · 서버 확인 · 도구별 결과) */
343
- function formatSetupLines(result, source, dryRun) {
344
- const probeLine = result.probe === 'skipped' ? '서버 확인: 건너뜀 (--dry-run)' : `서버 확인: ${result.probe.ok ? 'MCP 있음' : 'MCP 없음'} (${result.probe.detail})`;
345
- return [`MCP ${MCP_NAME} · 환경 ${result.env} (${source}) · ${result.url}${dryRun ? ' · 미리보기(--dry-run)' : ''}`, probeLine, ...(result.env === 'prod' ? [] : [`※ 운영이 아닌 환경(${result.env})입니다. 운영 자료를 올리지 마세요.`]), ...result.steps.flatMap(s => [` ${s.target}: ${s.message}`, ...(s.paste ? s.paste.split('\n').map(l => ` ${l}`) : [])])];
322
+ function formatSetupLines(result, source) {
323
+ return [`MCP ${MCP_NAME} · 환경 ${result.env} (${source}) · ${result.url}`, `서버 확인: ${result.probe.ok ? 'MCP 있음' : 'MCP 없음'} (${result.probe.detail})`, ...(result.env === 'prod' ? [] : [`※ 운영이 아닌 서버(--url)입니다. 운영 자료를 올리지 마세요.`]), ...result.steps.flatMap(s => [` ${s.target}: ${s.message}`, ...(s.paste ? s.paste.split('\n').map(l => ` ${l}`) : [])])];
346
324
  }
347
325
 
348
- export { DEFAULT_ENV, MCP_ENVS, MCP_NAME, NEEDS_PERSON, claudeRegisteredUrl, claudeRegistration, defaultMcpEnv, detectTargets, envOfUrl, formatSetupLines, helpyConfigPath, helpyRegisteredUrl, probeMcp, readHelpyConfig, resolveUrl, setup };
326
+ export { MCP_NAME, MCP_URL, NEEDS_PERSON, claudeRegistration, defaultMcpEnv, detectTargets, envOfUrl, formatSetupLines, helpyConfigPath, helpyRegisteredUrl, probeMcp, readHelpyConfig, resolveUrl, setup };
package/es/core/minify.js CHANGED
@@ -1,21 +1,34 @@
1
1
  import { transform } from 'esbuild';
2
+ import { SDK_ZIP_PATH } from './sdk.js';
2
3
 
3
4
  /**
4
- * package.json `"ecdk"`의 `"minify": true`일 때 zip에 넣기 전에 줄인다 (용량 줄이기).
5
+ * zip에 넣기 전에 줄인다 (기본, package.json `"ecdk"`의 `"minify": false`면 끔). zip은 학생 브라우저가 받으므로
6
+ * 주석(작업 메모 · 티켓 번호)을 빼고 용량도 줄인다.
5
7
  * 파일 단위 변환(번들 아님)이라 경로 · import · 파일 구성은 그대로다.
6
8
  *
7
9
  * - JS(.js · .mjs): 공백 · 주석 제거, 이름 줄이기. ES 모듈의 import/export와 top-level await는 그대로.
10
+ * 라이선스 주석(/*! · @license · @preserve)은 그 자리에 남긴다 (넣은 라이브러리의 고지 의무).
8
11
  * - CSS: 공백 · 주석 제거.
9
12
  * - JSON: 공백 제거 (형식이 틀리면 그대로 둠, 검사가 알려 줌). metadata.json은 사람이 보도록 그대로.
10
13
  * - HTML · 이미지 등은 그대로.
11
14
  * - sourcemap: 줄인 JS · CSS 옆에 `<파일>.map`을 두고 끝에 sourceMappingURL을 단다 (원본 내용 포함).
12
15
  * 이미 줄여 둔 파일(minify로 10%도 안 줄어듦, 예: lib/cdk.js)은 .map을 만들지 않는다.
13
16
  *
17
+ * - `ecdk-ignore` 주석이 있던 JS · CSS는 줄인 결과가 한 줄이면 그 규칙들을 `ecdk-ignore-next-line`으로 맨 앞에 다시 단다
18
+ * (zip 검사 · 서버 업로드 검사가 같은 규칙을 다시 보므로). 여러 줄이면 줄 위치를 맞출 수 없어 그 파일은 줄이지 않는다.
19
+ * - lib/cdk.js(build가 넣는 SDK)는 이미 줄인 코드이고 머리말(버전 · ecdk-ignore)을 검사가 읽으므로 그대로 둔다.
20
+ *
14
21
  * 검사는 minify 전 원본으로 한다 (`ecdk-ignore` 주석 · 원본 줄 번호). build 참고.
15
22
  */
16
23
  const encoder = new TextEncoder();
17
24
  const decoder = new TextDecoder();
18
- const KEEP = new Set(['metadata.json']);
25
+ const KEEP = new Set(['metadata.json', SDK_ZIP_PATH]);
26
+ /** 원본의 ecdk-ignore · ecdk-ignore-next-line이 끈 규칙 id (줄여도 zip 검사에서 같은 규칙을 끄도록) */
27
+ function ignoredRules(text) {
28
+ const ids = new Set();
29
+ for (const m of text.matchAll(/ecdk-ignore(?:-next-line)?((?:[ \t]+[\w.,-]+)+)/g)) for (const id of (m[1] ?? '').split(/[\s,]+/)) if (id === 'all' || /^[a-z][\w-]*\.[\w.-]+$/.test(id)) ids.add(id);
30
+ return [...ids];
31
+ }
19
32
  async function minifyFiles(files, {
20
33
  sourcemap = false
21
34
  } = {}) {
@@ -42,6 +55,7 @@ async function minifyFiles(files, {
42
55
  const r = await transform(text, {
43
56
  loader,
44
57
  minify: true,
58
+ legalComments: 'inline',
45
59
  target: 'es2022',
46
60
  ...(sourcemap ? {
47
61
  sourcemap: 'external',
@@ -49,6 +63,21 @@ async function minifyFiles(files, {
49
63
  } : {})
50
64
  });
51
65
  next = r.code;
66
+ const ignored = ignoredRules(text);
67
+ if (ignored.length > 0) {
68
+ // 여러 줄(템플릿 문자열 등)이면 끈 줄을 맞출 수 없다: 줄이지 않고 원본 그대로
69
+ if (next.trimEnd().includes('\n')) return f;
70
+ const line = `ecdk-ignore-next-line ${ignored.join(' ')}`;
71
+ next = `${loader === 'css' ? `/* ${line} */` : `// ${line}`}\n${next}`;
72
+ // 한 줄 밀렸으니 .map도 한 줄 민다
73
+ if (r.map) {
74
+ const map = JSON.parse(r.map);
75
+ r.map = JSON.stringify({
76
+ ...map,
77
+ mappings: `;${map.mappings}`
78
+ });
79
+ }
80
+ }
52
81
  // 이미 줄여 둔 파일(묶어 넣은 SDK 등)은 .map이 줄인 코드를 다시 가리킬 뿐이라 용량만 늘린다
53
82
  const alreadyMin = encoder.encode(next).byteLength > f.data.byteLength * 0.9;
54
83
  if (sourcemap && r.map && !alreadyMin) {
@@ -5,6 +5,13 @@ export interface SandboxReport {
5
5
  /** 모듈 스크립트를 묶어 넣은 HTML */
6
6
  pages: string[];
7
7
  }
8
+ /** 묶은 결과: 원본 빼기(dropBundledSources)에 쓴다 */
9
+ export interface BundledSources {
10
+ /** 어느 페이지에든 묶여 들어간 zip 안 파일 */
11
+ inputs: Set<string>;
12
+ /** 묶은 페이지마다 다른 파일 이름을 찾을 글: 묶은 <script> 태그를 뺀 HTML + 주석을 뺀 묶음 코드 */
13
+ pageTexts: Map<string, string>;
14
+ }
8
15
  /** HTML의 모듈 스크립트(src)를 묶어 본문으로 넣는다. 바뀐 파일만 새로 만들어 돌려준다 */
9
16
  export declare function inlineModuleScripts(files: SourceFile[],
10
17
  /** esbuild 작업 폴더 (기본: 실행 폴더). 테스트에서 프로젝트 폴더 안 실행을 흉내 낼 때 */
@@ -14,4 +21,22 @@ opts?: {
14
21
  }): Promise<{
15
22
  files: SourceFile[];
16
23
  report: SandboxReport;
24
+ bundled: BundledSources;
25
+ }>;
26
+ export interface DropReport {
27
+ /** 묶어 넣었고 다른 데서 쓰지 않아 zip에서 뺀 원본 JS */
28
+ dropped: string[];
29
+ /** 빼지 않은 까닭 (모두 둔 경우만) */
30
+ keptAll?: string | undefined;
31
+ }
32
+ /**
33
+ * 묶어 넣은 원본 JS 중 다른 데서 이름이 나오지 않는 파일을 뺀다 (zip 크기 · 같은 코드 두 벌).
34
+ * 묶은 파일(.js · .mjs)마다, 남는 텍스트 파일(묶은 페이지는 BundledSources.pageTexts)에 경로나 파일 이름이 나오면 둔다:
35
+ * 일반 <script src> · new Worker('…') · fetch · HTML · CSS · 문자열로 조합한 주소. 둔 파일은 따로 받히므로 그 안의
36
+ * import도 찾아 계속 둔다. 묶음에 import()가 남았으면(변수 주소) 무엇을 받는지 몰라 하나도 빼지 않는다.
37
+ * metadata.json · 화면 진입 파일(HTML) · JSON · CSS는 JS가 아니라 대상이 아니다.
38
+ */
39
+ export declare function dropBundledSources(files: SourceFile[], bundled: BundledSources): Promise<{
40
+ files: SourceFile[];
41
+ report: DropReport;
17
42
  }>;