humanbehavior-js 0.5.50 → 0.5.51

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.
@@ -1 +1 @@
1
- {"version":3,"file":"auto-install.d.ts","sourceRoot":"","sources":["../../src/cli/auto-install.ts"],"names":[],"mappings":";AAEA;;;;;;;GAOG;AAOH,UAAU,UAAU;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,cAAM,cAAc;IAClB,OAAO,CAAC,OAAO,CAAa;gBAEhB,OAAO,EAAE,UAAU;IAIzB,GAAG;YAyCK,SAAS;YAsBT,mBAAmB;IAQjC,OAAO,CAAC,cAAc;CA4BvB;AAoED,OAAO,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"auto-install.d.ts","sourceRoot":"","sources":["../../src/cli/auto-install.ts"],"names":[],"mappings":";AAEA;;;;;;;GAOG;AAOH,UAAU,UAAU;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,cAAM,cAAc;IAClB,OAAO,CAAC,OAAO,CAAa;gBAEhB,OAAO,EAAE,UAAU;IAIzB,GAAG;YAyCK,SAAS;YAsBT,mBAAmB;IAQjC,OAAO,CAAC,cAAc;CA4BvB;AAsED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -340,13 +340,26 @@ class AutoInstallationWizard {
340
340
  */
341
341
  async generateNextJSModifications() {
342
342
  const modifications = [];
343
- // Check for App Router
344
- const appLayoutFile = path.join(this.projectRoot, 'src', 'app', 'layout.tsx');
345
- const pagesLayoutFile = path.join(this.projectRoot, 'src', 'pages', '_app.tsx');
346
- if (fs.existsSync(appLayoutFile)) {
343
+ // Check for App Router - try both with and without src directory
344
+ const appLayoutFileWithSrc = path.join(this.projectRoot, 'src', 'app', 'layout.tsx');
345
+ const appLayoutFile = path.join(this.projectRoot, 'app', 'layout.tsx');
346
+ const pagesLayoutFileWithSrc = path.join(this.projectRoot, 'src', 'pages', '_app.tsx');
347
+ const pagesLayoutFile = path.join(this.projectRoot, 'pages', '_app.tsx');
348
+ // Determine which layout file exists and set paths accordingly
349
+ let actualAppLayoutFile = null;
350
+ let providersFilePath = null;
351
+ if (fs.existsSync(appLayoutFileWithSrc)) {
352
+ actualAppLayoutFile = appLayoutFileWithSrc;
353
+ providersFilePath = path.join(this.projectRoot, 'src', 'app', 'providers.tsx');
354
+ }
355
+ else if (fs.existsSync(appLayoutFile)) {
356
+ actualAppLayoutFile = appLayoutFile;
357
+ providersFilePath = path.join(this.projectRoot, 'app', 'providers.tsx');
358
+ }
359
+ if (actualAppLayoutFile) {
347
360
  // Create providers.tsx file for App Router
348
361
  modifications.push({
349
- filePath: path.join(this.projectRoot, 'src', 'app', 'providers.tsx'),
362
+ filePath: providersFilePath,
350
363
  action: 'create',
351
364
  content: `'use client';
352
365
 
@@ -362,19 +375,26 @@ export function Providers({ children }: { children: React.ReactNode }) {
362
375
  description: 'Created providers.tsx file for Next.js App Router'
363
376
  });
364
377
  // Modify layout.tsx to use the provider
365
- const content = fs.readFileSync(appLayoutFile, 'utf8');
378
+ const content = fs.readFileSync(actualAppLayoutFile, 'utf8');
366
379
  const modifiedContent = this.injectNextJSAppRouter(content);
367
380
  modifications.push({
368
- filePath: appLayoutFile,
381
+ filePath: actualAppLayoutFile,
369
382
  action: 'modify',
370
383
  content: modifiedContent,
371
384
  description: 'Added Providers wrapper to Next.js App Router layout'
372
385
  });
373
386
  }
374
- else if (fs.existsSync(pagesLayoutFile)) {
387
+ else if (fs.existsSync(pagesLayoutFileWithSrc) || fs.existsSync(pagesLayoutFile)) {
388
+ const actualPagesLayoutFile = fs.existsSync(pagesLayoutFileWithSrc) ? pagesLayoutFileWithSrc : pagesLayoutFile;
389
+ const providersPath = fs.existsSync(pagesLayoutFileWithSrc)
390
+ ? path.join(this.projectRoot, 'src', 'components', 'providers.tsx')
391
+ : path.join(this.projectRoot, 'components', 'providers.tsx');
392
+ const importPath = fs.existsSync(pagesLayoutFileWithSrc)
393
+ ? '../components/providers'
394
+ : './components/providers';
375
395
  // Create providers.tsx file for Pages Router
376
396
  modifications.push({
377
- filePath: path.join(this.projectRoot, 'src', 'components', 'providers.tsx'),
397
+ filePath: providersPath,
378
398
  action: 'create',
379
399
  content: `'use client';
380
400
 
@@ -390,10 +410,10 @@ export function Providers({ children }: { children: React.ReactNode }) {
390
410
  description: 'Created providers.tsx file for Pages Router'
391
411
  });
392
412
  // Modify _app.tsx to use the provider
393
- const content = fs.readFileSync(pagesLayoutFile, 'utf8');
394
- const modifiedContent = this.injectNextJSPagesRouter(content);
413
+ const content = fs.readFileSync(actualPagesLayoutFile, 'utf8');
414
+ const modifiedContent = this.injectNextJSPagesRouter(content, importPath);
395
415
  modifications.push({
396
- filePath: pagesLayoutFile,
416
+ filePath: actualPagesLayoutFile,
397
417
  action: 'modify',
398
418
  content: modifiedContent,
399
419
  description: 'Added Providers wrapper to Next.js Pages Router'
@@ -978,11 +998,11 @@ export const onClientEntry = () => {
978
998
  });
979
999
  return modifiedContent;
980
1000
  }
981
- injectNextJSPagesRouter(content) {
1001
+ injectNextJSPagesRouter(content, importPath = '../components/providers') {
982
1002
  if (content.includes('Providers')) {
983
1003
  return content;
984
1004
  }
985
- const importStatement = `import { Providers } from '../components/providers';`;
1005
+ const importStatement = `import { Providers } from '${importPath}';`;
986
1006
  return content.replace(/function MyApp/, `${importStatement}\n\nfunction MyApp`).replace(/return \(([\s\S]*?)\);/, `return (
987
1007
  <Providers>
988
1008
  $1
@@ -1504,15 +1524,17 @@ Examples:
1504
1524
  npx humanbehavior-js auto-install --project ./my-app --yes
1505
1525
  `);
1506
1526
  }
1507
- // Main execution
1508
- // For bin files, always execute when run directly
1509
- // Rollup will convert this to CommonJS, and the shebang ensures it runs with node
1510
- const options = parseArgs();
1511
- const cli = new AutoInstallCLI(options);
1512
- cli.run().catch((error) => {
1513
- clack.cancel(`Unexpected error: ${error.message}`);
1514
- process.exit(1);
1515
- });
1527
+ // Main execution (ES module compatible)
1528
+ // Check if this file is being run directly
1529
+ const isMain = import.meta.url === `file://${process.argv[1]}`;
1530
+ if (isMain) {
1531
+ const options = parseArgs();
1532
+ const cli = new AutoInstallCLI(options);
1533
+ cli.run().catch((error) => {
1534
+ clack.cancel(`Unexpected error: ${error.message}`);
1535
+ process.exit(1);
1536
+ });
1537
+ }
1516
1538
 
1517
1539
  export { AutoInstallCLI };
1518
1540
  //# sourceMappingURL=auto-install.js.map