|
3 | 3 | /** |
4 | 4 | * 프레임워크 컴포넌트를 디버깅할 때 코어 바닐라 로직을 수정하면서 확인할 필요가 있을 때, |
5 | 5 | * 이 스크립트를 이용하면 바닐라 로직 수정사항이 프레임워크 컴포넌트 로컬 데모환경에도 반영된다. |
6 | | - * |
| 6 | + * 다만, 바닐라 로직 수정 이후 리액트 데모에 핫 모듈 리로딩까지는 되지 않는다. |
| 7 | + * 따라서 수정 사항들을 추가적으로 반영해주려면 바닐라를 다시 빌드해야 한다. 링크는 다시 하지 않아도 된다. |
| 8 | + * |
7 | 9 | * 인자로 프레임워크 컴포넌트 패키지의 루트 디렉토리를 제공하면 된다. |
| 10 | + * 인자를 제공하지 않으면 packages 하위의 전체 프레임워크 패키지에 대해 링크를 시도한다. |
8 | 11 | * |
9 | 12 | * 사용 예시: node core-package-link.js react-flicking |
| 13 | + * |
| 14 | + * |
| 15 | + * 개발 흐름: |
| 16 | + * 1. 이 스크립트를 실행 |
| 17 | + * 2. 바닐라 로직 수정 후 빌드 수행 |
| 18 | + * 3. 프레임워크 컴포넌트의 데모를 실행 (바닐라 로직 변경사항이 반영됨) |
| 19 | + * 4. 바닐라 로직 추가 수정 후 빌드 수행 |
| 20 | + * 5. 프레임워크 컴포넌트의 데모를 새로고침 (바닐라 로직 변경사항이 반영됨) |
| 21 | + * - 원래는 새로고침만 하면 되야 하지만 타입 에러가 발생하는 경우가 있어 데모를 중지하고 다시 실행해야 할 수도 있다. |
| 22 | + * |
| 23 | + * |
10 | 24 | */ |
11 | 25 |
|
| 26 | + |
| 27 | + |
| 28 | +function run(cmd, cwd = process.cwd()) { |
| 29 | + console.log(`\n▶️ Running: ${cmd} (in ${cwd})`); |
| 30 | + execSync(cmd, { stdio: "inherit", cwd }); |
| 31 | +} |
| 32 | + |
12 | 33 | const { execSync } = require("child_process"); |
13 | 34 | const path = require("path"); |
14 | 35 | const fs = require("fs"); |
15 | 36 |
|
| 37 | +const frameworks = [ |
| 38 | + "ngx-flicking", |
| 39 | + "preact-flicking", |
| 40 | + "react-flicking", |
| 41 | + "vue-flicking", |
| 42 | + "vue3-flicking", |
| 43 | + "svelte-flicking", |
| 44 | +]; |
| 45 | + |
16 | 46 | const args = process.argv.slice(2); |
17 | 47 | const targetDir = args[0]; |
18 | 48 |
|
19 | 49 | if (!targetDir) { |
20 | | - console.error("❌ 디렉토리명을 인자로 입력하세요."); |
21 | | - process.exit(1); |
22 | | -} |
| 50 | + console.log( |
| 51 | + "❗️ 디렉토리명을 인자로 입력하지 않았습니다. 전체 프레임워크에 대해 링크를 시도합니다." |
| 52 | + ); |
| 53 | + run("npm run build"); |
| 54 | + run("npm link"); |
| 55 | + frameworks.forEach((target) => { |
| 56 | + const fullPath = path.resolve(process.cwd(), "packages", target); |
| 57 | + if (!fs.existsSync(fullPath)) { |
| 58 | + console.error(`❌ 디렉토리 없음: ${fullPath}`); |
| 59 | + process.exit(1); |
| 60 | + } |
| 61 | + run(`npm link '@egjs/flicking'`, fullPath); |
| 62 | + }); |
| 63 | +} else { |
| 64 | + const fullPath = path.resolve(process.cwd(), "packages", targetDir); |
| 65 | + if (!fs.existsSync(fullPath)) { |
| 66 | + console.error(`❌ 디렉토리 없음: ${fullPath}`); |
| 67 | + process.exit(1); |
| 68 | + } |
23 | 69 |
|
24 | | -const fullPath = path.resolve(process.cwd(), 'packages', targetDir); |
25 | | -if (!fs.existsSync(fullPath)) { |
26 | | - console.error(`❌ 디렉토리 없음: ${fullPath}`); |
27 | | - process.exit(1); |
| 70 | + run("npm run build"); |
| 71 | + run("npm link"); |
| 72 | + run(`npm link '@egjs/flicking'`, fullPath); |
28 | 73 | } |
29 | 74 |
|
30 | | -function run(cmd, cwd = process.cwd()) { |
31 | | - console.log(`\n▶️ Running: ${cmd} (in ${cwd})`); |
32 | | - execSync(cmd, { stdio: "inherit", cwd }); |
33 | | -} |
34 | 75 |
|
35 | | -run("npm run build"); |
36 | | -run("npm link"); |
37 | | -run(`npm link '@egjs/flicking'`, fullPath); |
38 | | -run("npm run build", fullPath); |
|
0 commit comments