feat: init fitness-coach (backend + miniprogram)
- backend: NestJS service with exercise/plan data - miniprogram: WeChat mini program client - exclude node_modules, dist, runtime data-store, local env
This commit is contained in:
33
backend/scripts/ensure-data.mjs
Normal file
33
backend/scripts/ensure-data.mjs
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* prebuild 脚本:确保后端数据集存在。
|
||||
* 若 backend/src/exercises/data/exercises.json 不存在,则从 GitHub 原始数据集下载。
|
||||
*/
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const DATA_FILE = path.join(__dirname, '..', 'src', 'exercises', 'data', 'exercises.json');
|
||||
const SOURCE =
|
||||
'https://raw.githubusercontent.com/hasaneyldrm/exercises-dataset/main/data/exercises.json';
|
||||
|
||||
async function main() {
|
||||
if (fs.existsSync(DATA_FILE)) {
|
||||
console.log('[ensure-data] 数据集已存在,跳过下载。');
|
||||
return;
|
||||
}
|
||||
console.log('[ensure-data] 未找到数据集,开始从 GitHub 下载 ...');
|
||||
fs.mkdirSync(path.dirname(DATA_FILE), { recursive: true });
|
||||
|
||||
const res = await fetch(SOURCE);
|
||||
if (!res.ok) throw new Error(`下载失败: HTTP ${res.status}`);
|
||||
const buf = Buffer.from(await res.arrayBuffer());
|
||||
fs.writeFileSync(DATA_FILE, buf);
|
||||
console.log(`[ensure-data] 已保存数据集 (${(buf.length / 1024 / 1024).toFixed(1)} MB)`);
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error('[ensure-data] 错误:', e.message);
|
||||
console.error('请手动将 exercises-dataset 的 data/exercises.json 放入 backend/src/exercises/data/');
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user