Skip to content

Commit e6d8fd1

Browse files
committed
Adding comprehensive debug logging.
1 parent 0b100e6 commit e6d8fd1

File tree

21 files changed

+128
-19
lines changed

21 files changed

+128
-19
lines changed

src/commands/build.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BaseCommand } from '../core/BaseCommand';
33
import fs from 'fs-extra';
44
import path from 'path';
55
import { runCommand } from '../utils/shell.js';
6+
import { logger } from '../utils/logger.js';
67

78
export default class BuildCommand extends BaseCommand {
89
static paths = [['build']];
@@ -23,9 +24,12 @@ export default class BuildCommand extends BaseCommand {
2324
const contentDir = path.resolve(srcDir, 'content');
2425
const publicDir = path.resolve(this.projectRoot, 'public');
2526

27+
logger.debug('Build paths resolved:', { siteDir, srcDir, coreDir, modulesDir, contentDir, publicDir });
28+
2629
this.info('Building for production...');
2730

2831
// 1. Clean _site
32+
logger.debug(`Cleaning site directory: ${siteDir}`);
2933
await fs.remove(siteDir);
3034
await fs.ensureDir(siteDir);
3135

@@ -63,6 +67,7 @@ export default class BuildCommand extends BaseCommand {
6367
// 6. Run Astro using local binary from project root
6468
// This avoids relying on global npx or PATH issues in tests
6569
const astroBin = path.join(this.projectRoot, 'node_modules', '.bin', 'astro');
70+
logger.debug(`Using astro binary at: ${astroBin}`);
6671

6772
try {
6873
await runCommand(`${astroBin} build`, siteDir);

src/commands/clean.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { BaseCommand } from '../core/BaseCommand';
33
import fs from 'fs-extra';
44
import path from 'path';
5+
import { logger } from '../utils/logger.js';
56

67
export default class CleanCommand extends BaseCommand {
78
static paths = [['clean']];
@@ -17,6 +18,7 @@ export default class CleanCommand extends BaseCommand {
1718

1819
for (const target of targets) {
1920
const targetPath = path.resolve(process.cwd(), target);
21+
logger.debug(`Checking clean target: ${targetPath}`);
2022
if (await fs.pathExists(targetPath)) {
2123
await fs.remove(targetPath);
2224
// BaseCommand doesn't expose logger property, use helpers or import

src/commands/dev.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from 'fs-extra';
44
import path from 'path';
55
import { spawn } from 'child_process';
66
import process from 'node:process';
7+
import { logger } from '../utils/logger.js';
78

89
export default class DevCommand extends BaseCommand {
910
static paths = [['dev']];
@@ -23,6 +24,7 @@ export default class DevCommand extends BaseCommand {
2324

2425
try {
2526
const { prepareEnvironment } = await import('../utils/environment.js');
27+
logger.debug(`Preparing environment at: ${this.projectRoot}`);
2628
await prepareEnvironment(this.projectRoot);
2729
} catch (error: any) {
2830
this.error(error);
@@ -32,6 +34,7 @@ export default class DevCommand extends BaseCommand {
3234
this.success('Environment ready. Starting Astro...');
3335

3436
const astroBin = path.join(this.projectRoot, 'node_modules', '.bin', 'astro');
37+
logger.debug(`Spawning astro dev from: ${astroBin} in ${siteDir}`);
3538

3639
const child = spawn(astroBin, ['dev'], {
3740
cwd: siteDir,

src/commands/init.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as git from '../utils/git.js';
44
import { runCommand } from '../utils/shell.js';
55
import fs from 'node:fs';
66
import path from 'node:path';
7+
import { logger } from '../utils/logger.js';
78

89
export default class InitCommand extends BaseCommand {
910
static description = 'Initialize a new Astrical project';
@@ -30,8 +31,11 @@ export default class InitCommand extends BaseCommand {
3031
// Handle gh@ syntax
3132
if (repoUrl.startsWith('gh@')) {
3233
repoUrl = `https://github.com/${repoUrl.substring(3)}.git`;
34+
logger.debug(`Resolved gh@ shorthad to: ${repoUrl}`);
3335
}
3436

37+
logger.debug('Init options:', { directory, targetPath, repoUrl });
38+
3539
this.info(`Initializing project in: ${targetPath}`);
3640
this.info(`Using starter repository: ${repoUrl}`);
3741

src/commands/module/add.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BaseCommand } from '../../core/BaseCommand';
33
import fs from 'fs-extra';
44
import path from 'path';
55
import { runCommand } from '../../utils/shell.js';
6+
import { logger } from '../../utils/logger.js';
67

78
export default class ModuleAddCommand extends BaseCommand {
89
static paths = [['module', 'add']];
@@ -18,7 +19,7 @@ export default class ModuleAddCommand extends BaseCommand {
1819
};
1920

2021
async run(options: any) {
21-
console.log('DEBUG: ModuleAdd Options:', JSON.stringify(options, null, 2));
22+
logger.debug('ModuleAdd Options:', options);
2223
let { url, name } = options;
2324

2425
if (!this.projectRoot) {
@@ -54,10 +55,15 @@ export default class ModuleAddCommand extends BaseCommand {
5455

5556
this.info(`Adding submodule ${name} from ${url}...`);
5657

57-
console.log('DEBUG: projectRoot', this.projectRoot);
58-
console.log('DEBUG: targetDir', targetDir);
59-
console.log('DEBUG: relativeTargetDir', relativeTargetDir);
60-
console.log('DEBUG: Executing git submodule add', url, relativeTargetDir);
58+
this.info(`Adding submodule ${name} from ${url}...`);
59+
60+
logger.debug('Module Add Context:', {
61+
projectRoot: this.projectRoot,
62+
targetDir,
63+
relativeTargetDir,
64+
url
65+
});
66+
logger.debug('Executing git submodule add...');
6167

6268
try {
6369
await runCommand(`git submodule add ${url} ${relativeTargetDir}`, this.projectRoot);

src/commands/module/list.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { BaseCommand } from '../../core/BaseCommand';
33
import fs from 'fs-extra';
44
import path from 'path';
5+
import { logger } from '../../utils/logger.js';
56

67
export default class ModuleListCommand extends BaseCommand {
78
static paths = [['module', 'list']];
@@ -16,6 +17,7 @@ export default class ModuleListCommand extends BaseCommand {
1617
}
1718

1819
const modulesDir = path.resolve(this.projectRoot, 'src', 'modules');
20+
logger.debug(`Scanning for modules in: ${modulesDir}`);
1921

2022
if (!(await fs.pathExists(modulesDir))) {
2123
this.info('No modules installed (src/modules directory missing).');

src/commands/module/remove.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BaseCommand } from '../../core/BaseCommand';
33
import fs from 'fs-extra';
44
import path from 'path';
55
import { runCommand } from '../../utils/shell.js';
6+
import { logger } from '../../utils/logger.js';
67

78
export default class ModuleRemoveCommand extends BaseCommand {
89
static paths = [['module', 'remove']];
@@ -25,6 +26,8 @@ export default class ModuleRemoveCommand extends BaseCommand {
2526
const relativePath = `src/modules/${name}`;
2627
const fullPath = path.resolve(this.projectRoot, relativePath);
2728

29+
logger.debug('Removing module at:', fullPath);
30+
2831
if (!(await fs.pathExists(fullPath))) {
2932
this.error(`Module ${name} not found at ${relativePath}.`);
3033
return;

src/commands/module/update.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BaseCommand } from '../../core/BaseCommand';
33
import fs from 'fs-extra';
44
import path from 'path';
55
import { runCommand } from '../../utils/shell.js';
6+
import { logger } from '../../utils/logger.js';
67

78
export default class ModuleUpdateCommand extends BaseCommand {
89
static paths = [['module', 'update']];
@@ -23,6 +24,7 @@ export default class ModuleUpdateCommand extends BaseCommand {
2324
}
2425

2526
this.info(name ? `Updating module ${name}...` : 'Updating all modules...');
27+
logger.debug('Update context:', { name, projectRoot: this.projectRoot });
2628

2729
try {
2830
if (name) {

src/commands/preview.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from 'fs-extra';
44
import path from 'path';
55
import { spawn } from 'child_process';
66
import process from 'node:process';
7+
import { logger } from '../utils/logger.js';
78

89
export default class PreviewCommand extends BaseCommand {
910
static paths = [['preview']];
@@ -20,6 +21,8 @@ export default class PreviewCommand extends BaseCommand {
2021
const siteDir = path.resolve(this.projectRoot, '_site');
2122
const distDir = path.join(siteDir, 'dist');
2223

24+
logger.debug('Preview paths:', { siteDir, distDir });
25+
2326
if (!(await fs.pathExists(distDir))) {
2427
this.error("Please run 'astrical build' first.");
2528
return;
@@ -28,6 +31,7 @@ export default class PreviewCommand extends BaseCommand {
2831
this.info('Starting preview server...');
2932

3033
const astroBin = path.join(this.projectRoot, 'node_modules', '.bin', 'astro');
34+
logger.debug(`Spawning astro preview from: ${astroBin} in ${siteDir}`);
3135

3236
const child = spawn(astroBin, ['preview'], {
3337
cwd: siteDir,

src/commands/run.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from 'path';
55
import { spawn } from 'child_process';
66
import process from 'node:process';
77
import { prepareEnvironment } from '../utils/environment.js';
8+
import { logger } from '../utils/logger.js';
89

910
export default class RunCommand extends BaseCommand {
1011
static paths = [['run']];
@@ -37,6 +38,8 @@ export default class RunCommand extends BaseCommand {
3738
await prepareEnvironment(this.projectRoot!);
3839
const siteDir = path.resolve(this.projectRoot!, '_site');
3940

41+
logger.debug('Run command context:', { script, args: scriptArgs, siteDir });
42+
4043
// Initialize command to default npm run
4144
let finalCmd = 'npm';
4245
let finalArgs = ['run', script, '--', ...scriptArgs];
@@ -45,6 +48,7 @@ export default class RunCommand extends BaseCommand {
4548
if (script.includes(':')) {
4649
const [moduleName, scriptName] = script.split(':');
4750
const modulePath = path.resolve(this.projectRoot!, 'src', 'modules', moduleName);
51+
logger.debug(`Resolving module script: ${moduleName}:${scriptName} at ${modulePath}`);
4852

4953
// Check if module exists
5054
const modulePkgJsonPath = path.join(modulePath, 'package.json');
@@ -74,6 +78,8 @@ export default class RunCommand extends BaseCommand {
7478
}
7579
}
7680

81+
logger.debug(`Executing final command: ${finalCmd} ${finalArgs.join(' ')} `);
82+
7783
const child = spawn(finalCmd, finalArgs, {
7884
cwd: siteDir,
7985
stdio: 'inherit',

0 commit comments

Comments
 (0)