mega-brain-ai 1.2.2 → 1.2.3

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.
@@ -13,7 +13,7 @@
13
13
  * 6. Post-install summary
14
14
  */
15
15
 
16
- import { existsSync, mkdirSync, cpSync, writeFileSync, readFileSync } from 'fs';
16
+ import { existsSync, mkdirSync, cpSync, writeFileSync, readFileSync, readdirSync } from 'fs';
17
17
  import { resolve, dirname, join } from 'path';
18
18
  import { fileURLToPath } from 'url';
19
19
  import { execSync } from 'child_process';
@@ -298,22 +298,21 @@ async function fetchPremiumContent(targetDir, token, spinner) {
298
298
  spinner.text = 'Integrando conteúdo premium na estrutura...';
299
299
 
300
300
  // Copy premium content over the shell (merge, not replace)
301
- const excludeDirs = ['.git', 'node_modules', 'bin', '.layer-sync'];
302
- const normalizedTemp = resolve(tempDir);
303
- cpSync(tempDir, targetDir, {
304
- recursive: true,
305
- force: true,
306
- filter: (src) => {
307
- const rel = resolve(src).slice(normalizedTemp.length);
308
- for (const exclude of excludeDirs) {
309
- if (rel.includes(`/${exclude}/`) || rel.includes(`\\${exclude}\\`)
310
- || rel.endsWith(`/${exclude}`) || rel.endsWith(`\\${exclude}`)) {
311
- return false;
312
- }
313
- }
314
- return true;
315
- },
316
- });
301
+ const premiumExclude = ['.git', 'node_modules', 'bin', '.layer-sync'];
302
+ const premiumEntries = readdirSync(tempDir, { withFileTypes: true });
303
+
304
+ for (const entry of premiumEntries) {
305
+ if (premiumExclude.includes(entry.name)) continue;
306
+
307
+ const srcPath = join(tempDir, entry.name);
308
+ const destPath = join(targetDir, entry.name);
309
+
310
+ if (entry.isDirectory()) {
311
+ cpSync(srcPath, destPath, { recursive: true, force: true });
312
+ } else {
313
+ cpSync(srcPath, destPath, { force: true });
314
+ }
315
+ }
317
316
 
318
317
  // NOTE: .layer-sync/ is intentionally NOT deleted.
319
318
  // It is listed in .gitignore and contains no sensitive data
@@ -369,30 +368,38 @@ function showPostInstallCommunity() {
369
368
  }
370
369
 
371
370
  function copyTemplateFiles(source, target, excludeDirs) {
372
- // Normalize source path for reliable relative path computation
373
- const normalizedSource = resolve(source);
371
+ if (!existsSync(source)) {
372
+ throw new Error(`Template não encontrado: ${source}`);
373
+ }
374
374
 
375
- try {
376
- cpSync(source, target, {
377
- recursive: true,
378
- filter: (src) => {
379
- // Get the path RELATIVE to the source root.
380
- // This is critical because when running via npx, the absolute path
381
- // contains "node_modules/" which would match the exclude filter
382
- // and block ALL files from being copied.
383
- const relativePath = resolve(src).slice(normalizedSource.length);
384
-
385
- for (const exclude of excludeDirs) {
386
- if (relativePath.includes(`/${exclude}/`) || relativePath.includes(`\\${exclude}\\`)
387
- || relativePath.endsWith(`/${exclude}`) || relativePath.endsWith(`\\${exclude}`)) {
388
- return false;
389
- }
390
- }
391
- return true;
392
- },
393
- });
394
- } catch (err) {
395
- throw new Error(`Erro ao copiar arquivos: ${err.message}. Certifique-se de usar Node.js 18+.`);
375
+ const entries = readdirSync(source, { withFileTypes: true });
376
+
377
+ if (entries.length === 0) {
378
+ throw new Error(`Template vazio: ${source}`);
379
+ }
380
+
381
+ let copied = 0;
382
+ for (const entry of entries) {
383
+ if (excludeDirs.includes(entry.name)) continue;
384
+
385
+ const srcPath = join(source, entry.name);
386
+ const destPath = join(target, entry.name);
387
+
388
+ try {
389
+ if (entry.isDirectory()) {
390
+ cpSync(srcPath, destPath, { recursive: true, force: true });
391
+ } else {
392
+ mkdirSync(dirname(destPath), { recursive: true });
393
+ cpSync(srcPath, destPath, { force: true });
394
+ }
395
+ copied++;
396
+ } catch (err) {
397
+ console.error(` Aviso: falha ao copiar ${entry.name}: ${err.message}`);
398
+ }
399
+ }
400
+
401
+ if (copied === 0) {
402
+ throw new Error(`Nenhum arquivo copiado. Source: ${source} (${entries.length} entries, ${excludeDirs.length} excluded)`);
396
403
  }
397
404
  }
398
405
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mega-brain-ai",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "AI Knowledge Management System - Transform expert materials into actionable playbooks",
5
5
  "type": "module",
6
6
  "bin": {