create-aiko 0.1.3 → 0.1.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-aiko",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "CLI to create aiko-boot scaffold project (monorepo with api, admin, mobile, shared)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"template"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
+
"prepack": "npm run build",
|
|
22
23
|
"build": "tsc && node ./scripts/build-template.mjs",
|
|
23
24
|
"dev": "tsc --watch"
|
|
24
25
|
},
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import 'reflect-metadata';
|
|
6
6
|
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
7
8
|
import { fileURLToPath } from 'url';
|
|
8
9
|
import { pathToFileURL } from 'url';
|
|
9
10
|
import { dirname, join } from 'path';
|
|
@@ -12,6 +13,7 @@ import { createKyselyDatabase, getKyselyDatabase } from '@ai-partner-x/aiko-boot
|
|
|
12
13
|
import bcrypt from 'bcryptjs';
|
|
13
14
|
|
|
14
15
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
15
17
|
const dbPath = join(__dirname, '../../data/app.db');
|
|
16
18
|
const dir = dirname(dbPath);
|
|
17
19
|
if (!existsSync(dir)) {
|
|
@@ -153,7 +155,9 @@ async function tryRepairBetterSqlite(error: unknown): Promise<boolean> {
|
|
|
153
155
|
|
|
154
156
|
console.warn('\n[init-db] 检测到 better-sqlite3 原生绑定缺失,正在尝试自动重建...');
|
|
155
157
|
|
|
158
|
+
const packageRoot = join(__dirname, '../..');
|
|
156
159
|
const projectRoot = join(__dirname, '../../../..');
|
|
160
|
+
const betterSqliteDir = resolveBetterSqliteDir();
|
|
157
161
|
const rebuild = spawnSync(
|
|
158
162
|
'pnpm',
|
|
159
163
|
['rebuild', 'better-sqlite3'],
|
|
@@ -172,13 +176,35 @@ async function tryRepairBetterSqlite(error: unknown): Promise<boolean> {
|
|
|
172
176
|
return false;
|
|
173
177
|
}
|
|
174
178
|
|
|
179
|
+
if (!hasBetterSqliteBinding(betterSqliteDir)) {
|
|
180
|
+
console.warn('\n[init-db] pnpm rebuild 未生成原生绑定,正在执行 build-release 兜底...');
|
|
181
|
+
|
|
182
|
+
const fallback = spawnSync(
|
|
183
|
+
'npm',
|
|
184
|
+
['run', 'build-release'],
|
|
185
|
+
{
|
|
186
|
+
cwd: betterSqliteDir,
|
|
187
|
+
stdio: 'inherit',
|
|
188
|
+
shell: process.platform === 'win32',
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
if (fallback.error) {
|
|
193
|
+
throw fallback.error;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if ((fallback.status ?? 1) !== 0 || !hasBetterSqliteBinding(betterSqliteDir)) {
|
|
197
|
+
throw new Error('[init-db] better-sqlite3 build-release 兜底失败,请手动执行 npm run build-release');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
175
201
|
console.log('\n[init-db] better-sqlite3 重建成功,正在重试数据库初始化...');
|
|
176
202
|
|
|
177
203
|
const retry = spawnSync(
|
|
178
204
|
process.execPath,
|
|
179
205
|
['--import', '@swc-node/register/esm-register', process.argv[1]!],
|
|
180
206
|
{
|
|
181
|
-
cwd:
|
|
207
|
+
cwd: packageRoot,
|
|
182
208
|
stdio: 'inherit',
|
|
183
209
|
env: {
|
|
184
210
|
...process.env,
|
|
@@ -198,6 +224,15 @@ async function tryRepairBetterSqlite(error: unknown): Promise<boolean> {
|
|
|
198
224
|
return true;
|
|
199
225
|
}
|
|
200
226
|
|
|
227
|
+
function resolveBetterSqliteDir(): string {
|
|
228
|
+
const pkgJsonPath = require.resolve('better-sqlite3/package.json');
|
|
229
|
+
return dirname(pkgJsonPath);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function hasBetterSqliteBinding(betterSqliteDir: string): boolean {
|
|
233
|
+
return existsSync(join(betterSqliteDir, 'build/Release/better_sqlite3.node'));
|
|
234
|
+
}
|
|
235
|
+
|
|
201
236
|
async function runGeneratedModuleInitializers(dbInstance: any) {
|
|
202
237
|
const generatedDir = join(__dirname, 'generated');
|
|
203
238
|
if (!existsSync(generatedDir)) {
|