accept-md 1.0.0

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.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI entry: accept-md init | doctor
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG"}
package/dist/cli.js ADDED
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI entry: accept-md init | doctor
4
+ */
5
+ import { createInterface } from 'node:readline';
6
+ import { resolve } from 'node:path';
7
+ import { runInit } from './init.js';
8
+ import { runDoctor, formatDoctorReport } from './doctor.js';
9
+ import { runFixRoutes } from './fix-routes.js';
10
+ import { detectProject } from './detect.js';
11
+ const args = process.argv.slice(2);
12
+ const command = args[0] || 'help';
13
+ function getProjectRoot() {
14
+ const positionArgs = args.slice(1).filter((a) => !a.startsWith('--'));
15
+ return resolve(positionArgs[0] || process.cwd());
16
+ }
17
+ function parseInitArgs() {
18
+ const projectRoot = getProjectRoot();
19
+ const overrides = {};
20
+ for (const arg of args.slice(1)) {
21
+ if (arg.startsWith('--app-dir='))
22
+ overrides.appDir = arg.slice('--app-dir='.length).trim();
23
+ else if (arg.startsWith('--pages-dir='))
24
+ overrides.pagesDir = arg.slice('--pages-dir='.length).trim();
25
+ else if (arg.startsWith('--middleware='))
26
+ overrides.middlewarePath = arg.slice('--middleware='.length).trim();
27
+ }
28
+ return { projectRoot, overrides };
29
+ }
30
+ function prompt(question, defaultAnswer) {
31
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
32
+ return new Promise((resolveAnswer) => {
33
+ const defaultText = defaultAnswer ? ` (default: ${defaultAnswer})` : '';
34
+ rl.question(`${question}${defaultText}: `, (answer) => {
35
+ rl.close();
36
+ resolveAnswer(answer.trim() || defaultAnswer);
37
+ });
38
+ });
39
+ }
40
+ async function gatherInitOverrides(projectRoot, initial) {
41
+ const hasAnyFlag = 'appDir' in initial || 'pagesDir' in initial || 'middlewarePath' in initial;
42
+ if (hasAnyFlag || !process.stdin.isTTY)
43
+ return initial;
44
+ const detection = detectProject(projectRoot);
45
+ const defaultRoutesDir = detection.routerType === 'app' ? (detection.appDir ?? 'app') : (detection.pagesDir ?? 'pages');
46
+ const routesUnderSrc = (detection.appDir ?? detection.pagesDir ?? '').startsWith('src/');
47
+ const defaultMiddleware = detection.middlewarePath ?? (routesUnderSrc ? 'src/middleware.ts' : 'middleware.ts');
48
+ const routesDir = await prompt('App or pages directory', defaultRoutesDir);
49
+ const middlewarePath = await prompt('Middleware file path', defaultMiddleware);
50
+ const overrides = { ...initial };
51
+ if (detection.routerType === 'app')
52
+ overrides.appDir = routesDir;
53
+ else
54
+ overrides.pagesDir = routesDir;
55
+ overrides.middlewarePath = middlewarePath;
56
+ return overrides;
57
+ }
58
+ async function main() {
59
+ if (command === 'init') {
60
+ const { projectRoot, overrides: initialOverrides } = parseInitArgs();
61
+ const overrides = await gatherInitOverrides(projectRoot, initialOverrides);
62
+ const result = await runInit(projectRoot, Object.keys(overrides).length ? overrides : undefined);
63
+ if (result.ok) {
64
+ console.log('accept-md init completed.\n');
65
+ result.messages.forEach((m) => console.log(' ' + m));
66
+ }
67
+ else {
68
+ console.error('Init failed:\n');
69
+ result.messages.forEach((m) => console.error(' ' + m));
70
+ process.exit(1);
71
+ }
72
+ return;
73
+ }
74
+ if (command === 'doctor') {
75
+ const report = runDoctor(getProjectRoot());
76
+ console.log(formatDoctorReport(report));
77
+ if (report.issues.length)
78
+ process.exit(1);
79
+ return;
80
+ }
81
+ if (command === 'fix-routes') {
82
+ const result = runFixRoutes(getProjectRoot());
83
+ if (result.patched)
84
+ console.log(result.message);
85
+ if (!result.ok) {
86
+ console.error(result.message);
87
+ process.exit(1);
88
+ }
89
+ return;
90
+ }
91
+ console.log(`
92
+ accept-md
93
+
94
+ Usage:
95
+ npx accept-md init [path] Add markdown middleware to a Next.js project
96
+ npx accept-md doctor [path] Report routes and check setup
97
+ npx accept-md fix-routes [path] Ensure routes-manifest has dataRoutes (Next.js 15)
98
+
99
+ Init options:
100
+ --app-dir=<path> App directory (e.g. app or src/app)
101
+ --pages-dir=<path> Pages directory (e.g. pages or src/pages)
102
+ --middleware=<path> Middleware file (e.g. middleware.ts or src/middleware.ts)
103
+ path Project root (default: current directory)
104
+
105
+ When run interactively, init will prompt for app/pages and middleware paths; press Enter for defaults.
106
+ `);
107
+ }
108
+ main().catch((err) => {
109
+ console.error(err);
110
+ process.exit(1);
111
+ });
112
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAsB,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC;AAElC,SAAS,cAAc;IACrB,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IACtE,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,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AAE,CAAC;QAC7B,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,EAAE,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,OAAO;IACT,CAAC;IAED,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;CAeb,CAAC,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Detect Next.js project, router type, and existing middleware.
3
+ */
4
+ import type { ProjectDetection } from '@accept-md/core';
5
+ export declare function detectProject(projectRoot: string): ProjectDetection;
6
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,gBAAgB,CAmEnE"}
package/dist/detect.js ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Detect Next.js project, router type, and existing middleware.
3
+ */
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+ export function detectProject(projectRoot) {
7
+ const pkgPath = join(projectRoot, 'package.json');
8
+ let nextVersion;
9
+ let isNext = false;
10
+ if (existsSync(pkgPath)) {
11
+ try {
12
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
13
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
14
+ const nextDep = deps['next'];
15
+ if (nextDep) {
16
+ isNext = true;
17
+ nextVersion = typeof nextDep === 'string' ? nextDep : undefined;
18
+ }
19
+ }
20
+ catch {
21
+ //
22
+ }
23
+ }
24
+ const appDirCandidates = ['src/app', 'app'];
25
+ const pagesDirCandidates = ['src/pages', 'pages'];
26
+ let appDir = null;
27
+ let pagesDir = null;
28
+ for (const p of appDirCandidates) {
29
+ if (existsSync(join(projectRoot, p))) {
30
+ appDir = p;
31
+ break;
32
+ }
33
+ }
34
+ for (const p of pagesDirCandidates) {
35
+ if (existsSync(join(projectRoot, p))) {
36
+ pagesDir = p;
37
+ break;
38
+ }
39
+ }
40
+ const hasAppDir = appDir !== null;
41
+ const hasPagesDir = pagesDir !== null;
42
+ const middlewarePaths = ['middleware.ts', 'middleware.js', 'src/middleware.ts', 'src/middleware.js'];
43
+ let middlewarePath = null;
44
+ for (const p of middlewarePaths) {
45
+ if (existsSync(join(projectRoot, p))) {
46
+ middlewarePath = p;
47
+ break;
48
+ }
49
+ }
50
+ const configPaths = ['accept-md.config.js', 'accept-md.config.mjs', 'next.config.js', 'next.config.mjs'];
51
+ let configPath = null;
52
+ for (const p of configPaths) {
53
+ if (existsSync(join(projectRoot, p)) && p.startsWith('accept-md')) {
54
+ configPath = p;
55
+ break;
56
+ }
57
+ }
58
+ let routerType = null;
59
+ if (hasAppDir)
60
+ routerType = 'app';
61
+ else if (hasPagesDir)
62
+ routerType = 'pages';
63
+ return {
64
+ isNext,
65
+ routerType,
66
+ hasAppDir,
67
+ hasPagesDir,
68
+ appDir,
69
+ pagesDir,
70
+ nextVersion,
71
+ middlewarePath,
72
+ configPath,
73
+ };
74
+ }
75
+ //# sourceMappingURL=detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.js","sourceRoot":"","sources":["../src/detect.ts"],"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;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Doctor command: report detected routes, conflicts, and suggestions.
3
+ */
4
+ import { type DoctorReport } from '@accept-md/core';
5
+ export declare function runDoctor(projectRoot: string): DoctorReport;
6
+ export declare function formatDoctorReport(report: DoctorReport): string;
7
+ //# sourceMappingURL=doctor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../src/doctor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAA2B,KAAK,YAAY,EAAoB,MAAM,iBAAiB,CAAC;AAE/F,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,CAyD3D;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAoC/D"}
package/dist/doctor.js ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Doctor command: report detected routes, conflicts, and suggestions.
3
+ */
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+ import { detectProject } from './detect.js';
7
+ import { scanProject, loadConfig } from '@accept-md/core';
8
+ export function runDoctor(projectRoot) {
9
+ const detected = detectProject(projectRoot);
10
+ const { routes } = scanProject(projectRoot, {
11
+ appDir: detected.appDir ?? undefined,
12
+ pagesDir: detected.pagesDir ?? undefined,
13
+ });
14
+ const conflicts = [];
15
+ const issues = [];
16
+ const suggestions = [];
17
+ if (!detected.isNext) {
18
+ issues.push('Not a Next.js project.');
19
+ return { detected, routes: [], conflicts, issues, suggestions };
20
+ }
21
+ if (!detected.routerType) {
22
+ issues.push('No app/ or pages/ directory found.');
23
+ }
24
+ if (detected.middlewarePath) {
25
+ const content = readFileSync(join(projectRoot, detected.middlewarePath), 'utf-8');
26
+ if (!content.includes('accept-md')) {
27
+ suggestions.push('Middleware exists but markdown rewrite not detected. Run `npx accept-md init` to add it.');
28
+ }
29
+ }
30
+ else {
31
+ suggestions.push('No middleware.ts found. Run init to create it.');
32
+ }
33
+ const handlerPath = detected.routerType === 'app'
34
+ ? join(projectRoot, detected.appDir ?? 'app', 'api', 'accept-md', 'route.ts')
35
+ : join(projectRoot, detected.pagesDir ?? 'pages', 'api', 'accept-md', 'index.ts');
36
+ if (!existsSync(handlerPath)) {
37
+ issues.push('Markdown handler not found. Run `npx accept-md init`.');
38
+ }
39
+ const configPath = join(projectRoot, 'accept-md.config.js');
40
+ if (!existsSync(configPath)) {
41
+ suggestions.push('No accept-md.config.js. Run init to create a default config.');
42
+ }
43
+ else {
44
+ const config = loadConfig(projectRoot);
45
+ if (config.exclude?.some((e) => e === '/api/**') && detected.routerType === 'pages') {
46
+ suggestions.push('API routes are excluded by default (correct).');
47
+ }
48
+ }
49
+ if (routes.length === 0 && (detected.hasAppDir || detected.hasPagesDir)) {
50
+ issues.push('No page routes detected. Check that you have page.tsx (app) or index/page files (pages).');
51
+ }
52
+ return {
53
+ detected,
54
+ routes,
55
+ conflicts,
56
+ issues,
57
+ suggestions,
58
+ };
59
+ }
60
+ export function formatDoctorReport(report) {
61
+ const lines = [];
62
+ lines.push('--- accept-md doctor ---');
63
+ lines.push('');
64
+ lines.push('Detection:');
65
+ lines.push(` Next.js: ${report.detected.isNext}`);
66
+ lines.push(` Router: ${report.detected.routerType ?? 'none'}`);
67
+ lines.push(` App dir: ${report.detected.hasAppDir} (${report.detected.appDir ?? 'n/a'})`);
68
+ lines.push(` Pages dir: ${report.detected.hasPagesDir} (${report.detected.pagesDir ?? 'n/a'})`);
69
+ lines.push(` Middleware: ${report.detected.middlewarePath ?? 'none'}`);
70
+ lines.push(` Config: ${report.detected.configPath ?? 'none'}`);
71
+ lines.push('');
72
+ lines.push(`Routes (${report.routes.length}):`);
73
+ for (const r of report.routes.slice(0, 30)) {
74
+ lines.push(` ${r.path} ${r.isDynamic ? '(dynamic)' : ''}`);
75
+ }
76
+ if (report.routes.length > 30) {
77
+ lines.push(` ... and ${report.routes.length - 30} more`);
78
+ }
79
+ if (report.conflicts.length) {
80
+ lines.push('');
81
+ lines.push('Conflicts:');
82
+ report.conflicts.forEach((c) => lines.push(` - ${c}`));
83
+ }
84
+ if (report.issues.length) {
85
+ lines.push('');
86
+ lines.push('Issues:');
87
+ report.issues.forEach((i) => lines.push(` - ${i}`));
88
+ }
89
+ if (report.suggestions.length) {
90
+ lines.push('');
91
+ lines.push('Suggestions:');
92
+ report.suggestions.forEach((s) => lines.push(` - ${s}`));
93
+ }
94
+ lines.push('');
95
+ return lines.join('\n');
96
+ }
97
+ //# sourceMappingURL=doctor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor.js","sourceRoot":"","sources":["../src/doctor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAuC,MAAM,iBAAiB,CAAC;AAE/F,MAAM,UAAU,SAAS,CAAC,WAAmB;IAC3C,MAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;IAC5C,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,WAAW,EAAE;QAC1C,MAAM,EAAE,QAAQ,CAAC,MAAM,IAAI,SAAS;QACpC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,IAAI,SAAS;KACzC,CAAC,CAAC;IACH,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,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IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QAC9B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC3B,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Fix routes manifest: ensure dataRoutes exists so Next.js 15+ server can iterate it.
3
+ * Addresses: [TypeError: routesManifest.dataRoutes is not iterable]
4
+ */
5
+ export interface FixRoutesResult {
6
+ ok: boolean;
7
+ patched: boolean;
8
+ message: string;
9
+ }
10
+ export declare function runFixRoutes(projectRoot: string): FixRoutesResult;
11
+ //# sourceMappingURL=fix-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-routes.d.ts","sourceRoot":"","sources":["../src/fix-routes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,eAAe,CAuCjE"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Fix routes manifest: ensure dataRoutes exists so Next.js 15+ server can iterate it.
3
+ * Addresses: [TypeError: routesManifest.dataRoutes is not iterable]
4
+ */
5
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
6
+ import { join } from 'node:path';
7
+ const ROUTES_MANIFEST = '.next/routes-manifest.json';
8
+ export function runFixRoutes(projectRoot) {
9
+ const manifestPath = join(projectRoot, ROUTES_MANIFEST);
10
+ if (!existsSync(manifestPath)) {
11
+ return { ok: true, patched: false, message: 'No .next/routes-manifest.json found (run after next build).' };
12
+ }
13
+ let manifest;
14
+ try {
15
+ const raw = readFileSync(manifestPath, 'utf-8');
16
+ manifest = JSON.parse(raw);
17
+ }
18
+ catch (err) {
19
+ return {
20
+ ok: false,
21
+ patched: false,
22
+ message: `Failed to read or parse ${ROUTES_MANIFEST}: ${err instanceof Error ? err.message : String(err)}`,
23
+ };
24
+ }
25
+ if (Array.isArray(manifest.dataRoutes)) {
26
+ return { ok: true, patched: false, message: 'routes-manifest.json already has dataRoutes.' };
27
+ }
28
+ manifest.dataRoutes = [];
29
+ try {
30
+ writeFileSync(manifestPath, JSON.stringify(manifest) + '\n', 'utf-8');
31
+ }
32
+ catch (err) {
33
+ return {
34
+ ok: false,
35
+ patched: false,
36
+ message: `Failed to write ${ROUTES_MANIFEST}: ${err instanceof Error ? err.message : String(err)}`,
37
+ };
38
+ }
39
+ return {
40
+ ok: true,
41
+ patched: true,
42
+ message: 'Added missing dataRoutes to routes-manifest.json (Next.js 15 compatibility).',
43
+ };
44
+ }
45
+ //# sourceMappingURL=fix-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-routes.js","sourceRoot":"","sources":["../src/fix-routes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,eAAe,GAAG,4BAA4B,CAAC;AAQrD,MAAM,UAAU,YAAY,CAAC,WAAmB;IAC9C,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;IAExD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EA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from './init.js';
2
+ export { runDoctor, formatDoctorReport } from './doctor.js';
3
+ export { runFixRoutes } from './fix-routes.js';
4
+ export { detectProject } from './detect.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { runInit } from './init.js';
2
+ export { runDoctor, formatDoctorReport } from './doctor.js';
3
+ export { runFixRoutes } from './fix-routes.js';
4
+ export { detectProject } from './detect.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
package/dist/init.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Init command: generate middleware, handler, config, and add dependency.
3
+ */
4
+ export interface InitOverrides {
5
+ appDir?: string;
6
+ pagesDir?: string;
7
+ middlewarePath?: string;
8
+ }
9
+ export declare function runInit(projectRoot: string, overrides?: InitOverrides): Promise<{
10
+ ok: boolean;
11
+ messages: string[];
12
+ }>;
13
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiDH,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAsB,OAAO,CAC3B,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CA6F9C"}
package/dist/init.js ADDED
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Init command: generate middleware, handler, config, and add dependency.
3
+ */
4
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+ import { detectProject } from './detect.js';
7
+ import { scanProject } from '@accept-md/core';
8
+ import { MIDDLEWARE_TEMPLATE, APP_ROUTE_HANDLER_TEMPLATE, PAGES_API_HANDLER_TEMPLATE, } from 'accept-md-runtime';
9
+ const MARKDOWN_MARKER = 'accept-md';
10
+ function getMiddlewareWithExisting(existingPath, projectRoot) {
11
+ const content = readFileSync(join(projectRoot, existingPath), 'utf-8');
12
+ if (content.includes(MARKDOWN_MARKER))
13
+ return MIDDLEWARE_TEMPLATE;
14
+ const wrapper = `// Wrapper: accept-md runs first, then your middleware
15
+ import { NextResponse } from 'next/server';
16
+ import type { NextRequest } from 'next/server';
17
+
18
+ const MARKDOWN_ACCEPT = /\\btext\\/markdown\\b/;
19
+ const EXCLUDED_PREFIXES = ['/api/', '/_next/'];
20
+
21
+ async function markdownMiddleware(request: NextRequest) {
22
+ const pathname = request.nextUrl.pathname;
23
+ const accept = request.headers.get('accept') || '';
24
+ if (!MARKDOWN_ACCEPT.test(accept)) return null;
25
+ if (EXCLUDED_PREFIXES.some((p) => pathname.startsWith(p))) return null;
26
+ const url = request.nextUrl.clone();
27
+ url.pathname = '/api/accept-md';
28
+ url.searchParams.set('path', pathname);
29
+ return NextResponse.rewrite(url);
30
+ }
31
+
32
+ export async function middleware(request: NextRequest) {
33
+ const markdownRes = await markdownMiddleware(request);
34
+ if (markdownRes) return markdownRes;
35
+ const mod = await import('./middleware.user.js');
36
+ const userMiddleware = mod.default ?? mod.middleware;
37
+ return userMiddleware(request);
38
+ }
39
+ `;
40
+ const userPath = existingPath.replace(/\.(ts|js)$/, '.user.$1');
41
+ writeFileSync(join(projectRoot, userPath), content);
42
+ return wrapper;
43
+ }
44
+ export async function runInit(projectRoot, overrides) {
45
+ const messages = [];
46
+ const detection = detectProject(projectRoot);
47
+ if (!detection.isNext) {
48
+ return { ok: false, messages: ['Not a Next.js project (no "next" in dependencies).'] };
49
+ }
50
+ if (!detection.routerType) {
51
+ return { ok: false, messages: ['No app/ or pages/ directory found.'] };
52
+ }
53
+ const appDir = overrides?.appDir ?? detection.appDir ?? 'app';
54
+ const pagesDir = overrides?.pagesDir ?? detection.pagesDir ?? 'pages';
55
+ const routesUnderSrc = appDir.startsWith('src/') || pagesDir.startsWith('src/');
56
+ const defaultMiddlewarePath = routesUnderSrc ? 'src/middleware.ts' : 'middleware.ts';
57
+ const middlewarePathRel = overrides?.middlewarePath ?? detection.middlewarePath ?? defaultMiddlewarePath;
58
+ messages.push(`Detected Next.js (${detection.routerType} router).`);
59
+ const { routes } = scanProject(projectRoot, { appDir, pagesDir });
60
+ messages.push(`Found ${routes.length} route(s).`);
61
+ const middlewarePathAbs = join(projectRoot, middlewarePathRel);
62
+ let middlewareContent;
63
+ if (detection.middlewarePath && existsSync(middlewarePathAbs)) {
64
+ middlewareContent = getMiddlewareWithExisting(middlewarePathRel, projectRoot);
65
+ if (middlewareContent.includes('middleware.user')) {
66
+ messages.push('Existing middleware backed up to middleware.user.ts – markdown runs first.');
67
+ }
68
+ }
69
+ else {
70
+ middlewareContent = MIDDLEWARE_TEMPLATE.replace(/\\\\/g, '\\');
71
+ }
72
+ writeFileSync(middlewarePathAbs, middlewareContent);
73
+ messages.push(`Wrote ${middlewarePathRel}.`);
74
+ if (detection.routerType === 'app') {
75
+ const handlerDir = join(projectRoot, appDir, 'api', 'accept-md');
76
+ mkdirSync(handlerDir, { recursive: true });
77
+ const routePath = join(handlerDir, 'route.ts');
78
+ writeFileSync(routePath, APP_ROUTE_HANDLER_TEMPLATE.replace(/\\\\/g, '\\'));
79
+ messages.push(`Wrote ${routePath}.`);
80
+ }
81
+ else {
82
+ const apiDir = join(projectRoot, pagesDir, 'api');
83
+ mkdirSync(apiDir, { recursive: true });
84
+ const markdownDir = join(apiDir, 'accept-md');
85
+ mkdirSync(markdownDir, { recursive: true });
86
+ writeFileSync(join(markdownDir, 'index.ts'), PAGES_API_HANDLER_TEMPLATE.replace(/\\\\/g, '\\'));
87
+ messages.push(`Wrote ${pagesDir}/api/accept-md/index.ts.`);
88
+ }
89
+ const configPath = join(projectRoot, 'accept-md.config.js');
90
+ if (!existsSync(configPath)) {
91
+ const configContent = `/** @type { import('accept-md-runtime').NextMarkdownConfig } */
92
+ module.exports = {
93
+ include: ['/**'],
94
+ exclude: ['/api/**', '/_next/**'],
95
+ cleanSelectors: ['nav', 'footer', '.no-markdown'],
96
+ outputMode: 'markdown',
97
+ cache: true,
98
+ transformers: [],
99
+ };
100
+ `;
101
+ writeFileSync(configPath, configContent);
102
+ messages.push('Created accept-md.config.js.');
103
+ }
104
+ else {
105
+ messages.push('accept-md.config.js already exists; skipping.');
106
+ }
107
+ const pkgPath = join(projectRoot, 'package.json');
108
+ if (existsSync(pkgPath)) {
109
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
110
+ let pkgModified = false;
111
+ if (!pkg.dependencies?.['accept-md-runtime']) {
112
+ pkg.dependencies = pkg.dependencies || {};
113
+ pkg.dependencies['accept-md-runtime'] = '^1.0.0';
114
+ pkgModified = true;
115
+ messages.push('Added accept-md-runtime to dependencies. Run pnpm install (or npm install).');
116
+ }
117
+ // Next.js 15+ expects routes-manifest.dataRoutes to be iterable; add postbuild to patch if missing
118
+ if (!pkg.scripts)
119
+ pkg.scripts = {};
120
+ if (!pkg.scripts.postbuild) {
121
+ pkg.scripts.postbuild = 'accept-md fix-routes';
122
+ pkgModified = true;
123
+ messages.push('Added postbuild script (accept-md fix-routes) for Next.js 15 compatibility.');
124
+ }
125
+ if (pkgModified)
126
+ writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
127
+ }
128
+ return { ok: true, messages };
129
+ }
130
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAE3B,MAAM,eAAe,GAAG,WAAW,CAAC;AAEpC,SAAS,yBAAyB,CAAC,YAAoB,EAAE,WAAmB;IAC1E,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC;IACvE,IAAI,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;QAAE,OAAO,mBAAmB,CAAC;IAElE,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;CAyBjB,CAAC;IACA,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAChE,aAAa,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;IACpD,OAAO,OAAO,CAAC;AACjB,CAAC;AAQD,MAAM,CA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EAAE,CAAC;QACnC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YAC3B,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,sBAAsB,CAAC;YAC/C,WAAW,GAAG,IAAI,CAAC;YACnB,QAAQ,CAAC,IAAI,CAAC,6EAA6E,CAAC,CAAC;QAC/F,CAAC;QACD,IAAI,WAAW;YAAE,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "accept-md",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/hemanthvalsaraj/accept-md.git"
8
+ },
9
+ "homepage": "https://github.com/hemanthvalsaraj/accept-md#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/hemanthvalsaraj/accept-md/issues"
12
+ },
13
+ "bin": {
14
+ "accept-md": "./dist/cli.js"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "accept-md-runtime": "1.0.0",
22
+ "@accept-md/core": "1.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "typescript": "^5.3.0"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "clean": "rm -rf dist",
30
+ "lint": "eslint src"
31
+ }
32
+ }