curtis
16小時前 713024ccb5056e76bcfc9389664981da68a5139f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs');
const path = require('path');
 
// 讀取設定檔與樣板
const configPath = path.join(__dirname, '../doc/curtis/prompt/dfm_to_web/dfm_to_web_requirement.json');
const templatePath = path.join(__dirname, '../doc/curtis/prompt/dfm_to_web/dfm_to_web_prompt_template.md');
 
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const template = fs.readFileSync(templatePath, 'utf8');
 
// 產生每個檔案的專屬 prompt
const outputDir = path.join(__dirname, '../doc/curtis/prompt/dfm_to_web');
if (!fs.existsSync(outputDir)) {
    fs.mkdirSync(outputDir, { recursive: true });
}
 
console.log('Generating individual prompts based on requirement.json...');
 
config.forEach(item => {
    // 從路徑中萃取檔名
    const dfm_filename = path.basename(item.dfm);
    const pas_filename = path.basename(item.pas);
    const png_filename = path.basename(item.png);
    const vue_filename = path.basename(item.vue);
    const ts_filename = path.basename(item.ts);
    
    // 取得元件名稱 (不含副檔名)
    const componentName = path.parse(item.vue).name;
 
    // 取代樣板中的佔位符
    let promptContent = template
        .replace(/\{\{dfm\}\}/g, item.dfm)
        .replace(/\{\{pas\}\}/g, item.pas)
        .replace(/\{\{png\}\}/g, item.png)
        .replace(/\{\{vue\}\}/g, item.vue)
        .replace(/\{\{ts\}\}/g, item.ts)
        .replace(/\{\{dfm_filename\}\}/g, dfm_filename)
        .replace(/\{\{pas_filename\}\}/g, pas_filename)
        .replace(/\{\{png_filename\}\}/g, png_filename)
        .replace(/\{\{vue_filename\}\}/g, vue_filename)
        .replace(/\{\{ts_filename\}\}/g, ts_filename);
 
    // 寫入專屬的 prompt 檔案
    const promptFilePath = path.join(outputDir, `dfm_to_web_prompt_${componentName}.md`);
    fs.writeFileSync(promptFilePath, promptContent, 'utf8');
    
    console.log(`Created: ${promptFilePath}`);
});
 
console.log('\n--- Usage ---');
console.log('You can now ask the AI:');
console.log('"Please execute the conversion based on the requirements in @/doc/curtis/prompt/dfm_to_web/generated_prompts/prompt_PatchFom.md"');