@kurly-growth/growthman 0.1.16 → 0.1.18

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 (2) hide show
  1. package/bin/cli.js +89 -31
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -7,8 +7,9 @@ const os = require('os');
7
7
 
8
8
  const packageDir = path.resolve(__dirname, '..');
9
9
 
10
- // 사용자 홈 디렉토리에 데이터 저장
10
+ // 사용자 홈 디렉토리에 앱 및 데이터 저장
11
11
  const dataDir = path.join(os.homedir(), '.growthman');
12
+ const appDir = path.join(dataDir, 'app');
12
13
  const dbPath = path.join(dataDir, 'data.db');
13
14
 
14
15
  // 데이터 디렉토리 생성
@@ -16,6 +17,57 @@ if (!fs.existsSync(dataDir)) {
16
17
  fs.mkdirSync(dataDir, { recursive: true });
17
18
  }
18
19
 
20
+ // 패키지 버전 확인
21
+ const pkgJson = require(path.join(packageDir, 'package.json'));
22
+ const versionFile = path.join(appDir, '.version');
23
+ const currentVersion = pkgJson.version;
24
+ const installedVersion = fs.existsSync(versionFile)
25
+ ? fs.readFileSync(versionFile, 'utf-8').trim()
26
+ : null;
27
+
28
+ // 앱 파일 복사 (버전이 다르거나 없으면)
29
+ if (installedVersion !== currentVersion) {
30
+ console.log(`Installing growthman v${currentVersion}...`);
31
+
32
+ // 기존 앱 폴더 삭제
33
+ if (fs.existsSync(appDir)) {
34
+ fs.rmSync(appDir, { recursive: true });
35
+ }
36
+ fs.mkdirSync(appDir, { recursive: true });
37
+
38
+ // 필요한 파일들 복사
39
+ const filesToCopy = [
40
+ 'app',
41
+ 'components',
42
+ 'lib',
43
+ 'prisma',
44
+ 'public',
45
+ 'types',
46
+ 'next.config.ts',
47
+ 'tsconfig.json',
48
+ 'postcss.config.mjs',
49
+ 'package.json',
50
+ ];
51
+
52
+ for (const file of filesToCopy) {
53
+ const src = path.join(packageDir, file);
54
+ const dest = path.join(appDir, file);
55
+ if (fs.existsSync(src)) {
56
+ copyRecursive(src, dest);
57
+ }
58
+ }
59
+
60
+ // 버전 파일 생성
61
+ fs.writeFileSync(versionFile, currentVersion);
62
+
63
+ // 의존성 설치
64
+ console.log('Installing dependencies...');
65
+ execSync('npm install --legacy-peer-deps', {
66
+ cwd: appDir,
67
+ stdio: 'inherit',
68
+ });
69
+ }
70
+
19
71
  // 환경변수 설정
20
72
  const env = {
21
73
  ...process.env,
@@ -23,48 +75,41 @@ const env = {
23
75
  };
24
76
 
25
77
  // CLI 바이너리 경로 찾기
26
- function getBinPath(packageName, binName) {
78
+ function getBinPath(binName) {
79
+ const binPath = path.join(appDir, 'node_modules', '.bin', binName);
80
+ if (fs.existsSync(binPath)) {
81
+ return binPath;
82
+ }
83
+ // fallback: package.json에서 찾기
27
84
  try {
28
- const pkgJsonPath = require.resolve(`${packageName}/package.json`, {
29
- paths: [packageDir],
30
- });
31
- const pkgDir = path.dirname(pkgJsonPath);
32
- const pkgJson = require(pkgJsonPath);
33
-
34
- let binRelPath;
35
- if (typeof pkgJson.bin === 'string') {
36
- binRelPath = pkgJson.bin;
37
- } else if (pkgJson.bin && pkgJson.bin[binName]) {
38
- binRelPath = pkgJson.bin[binName];
39
- }
40
-
41
- if (binRelPath) {
42
- return path.join(pkgDir, binRelPath);
85
+ const pkgJsonPath = path.join(appDir, 'node_modules', binName, 'package.json');
86
+ const pkg = require(pkgJsonPath);
87
+ if (pkg.bin) {
88
+ const binRelPath = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin[binName];
89
+ return path.join(appDir, 'node_modules', binName, binRelPath);
43
90
  }
44
- } catch (e) {
45
- // fallback to node_modules/.bin
46
- }
47
- return path.join(packageDir, 'node_modules', '.bin', binName);
91
+ } catch (e) {}
92
+ return binPath;
48
93
  }
49
94
 
50
95
  // DB가 없으면 생성
51
96
  if (!fs.existsSync(dbPath)) {
52
97
  console.log('Initializing database...');
53
- const prismaPath = getBinPath('prisma', 'prisma');
98
+ const prismaPath = getBinPath('prisma');
54
99
  execSync(`node "${prismaPath}" db push`, {
55
- cwd: packageDir,
100
+ cwd: appDir,
56
101
  stdio: 'inherit',
57
102
  env,
58
103
  });
59
104
  }
60
105
 
61
- // .next 폴더가 없으면 빌드 (Turbopack은 node_modules 내 TS 파일을 지원하지 않음)
62
- const nextDir = path.join(packageDir, '.next');
106
+ // .next 폴더가 없으면 빌드
107
+ const nextDir = path.join(appDir, '.next');
63
108
  if (!fs.existsSync(nextDir)) {
64
- console.log('Building application (first run)...');
65
- const nextPath = getBinPath('next', 'next');
66
- execSync(`node "${nextPath}" build --no-turbopack`, {
67
- cwd: packageDir,
109
+ console.log('Building application...');
110
+ const nextPath = getBinPath('next');
111
+ execSync(`node "${nextPath}" build`, {
112
+ cwd: appDir,
68
113
  stdio: 'inherit',
69
114
  env,
70
115
  });
@@ -76,9 +121,9 @@ const url = `http://localhost:${port}`;
76
121
  console.log(`Database: ${dbPath}`);
77
122
  console.log(`Starting mock server at ${url}`);
78
123
 
79
- const nextPath = getBinPath('next', 'next');
124
+ const nextPath = getBinPath('next');
80
125
  const server = spawn('node', [nextPath, 'start', '-p', String(port)], {
81
- cwd: packageDir,
126
+ cwd: appDir,
82
127
  stdio: 'inherit',
83
128
  env,
84
129
  });
@@ -97,3 +142,16 @@ setTimeout(() => {
97
142
  server.on('close', (code) => {
98
143
  process.exit(code);
99
144
  });
145
+
146
+ // 재귀적 파일 복사
147
+ function copyRecursive(src, dest) {
148
+ const stat = fs.statSync(src);
149
+ if (stat.isDirectory()) {
150
+ fs.mkdirSync(dest, { recursive: true });
151
+ for (const file of fs.readdirSync(src)) {
152
+ copyRecursive(path.join(src, file), path.join(dest, file));
153
+ }
154
+ } else {
155
+ fs.copyFileSync(src, dest);
156
+ }
157
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kurly-growth/growthman",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "Local mock API server with UI dashboard",
5
5
  "bin": {
6
6
  "growthman": "./bin/cli.js"