@litodocs/cli 1.4.0 → 1.4.2
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/package.json
CHANGED
package/src/commands/doctor.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
|
|
2
2
|
import { resolve, join, extname } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
3
4
|
import { intro, outro, log, spinner } from '@clack/prompts';
|
|
4
5
|
import pc from 'picocolors';
|
|
5
6
|
import { validateConfig } from '../core/config-validator.js';
|
|
@@ -257,7 +258,7 @@ async function checkCommonIssues(inputPath) {
|
|
|
257
258
|
}
|
|
258
259
|
|
|
259
260
|
async function checkTemplateCache() {
|
|
260
|
-
const cacheDir = join(
|
|
261
|
+
const cacheDir = join(homedir(), '.lito', 'templates');
|
|
261
262
|
|
|
262
263
|
if (!existsSync(cacheDir)) {
|
|
263
264
|
return {
|
package/src/commands/info.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
|
|
2
2
|
import { resolve, join, extname } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
3
4
|
import { intro, outro, log } from '@clack/prompts';
|
|
4
5
|
import pc from 'picocolors';
|
|
5
6
|
import { TEMPLATE_REGISTRY } from '../core/template-registry.js';
|
|
@@ -137,7 +138,7 @@ export async function infoCommand(options) {
|
|
|
137
138
|
log.message(` ${pc.cyan('Node.js:')} ${process.version}`);
|
|
138
139
|
log.message(` ${pc.cyan('Platform:')} ${process.platform}`);
|
|
139
140
|
|
|
140
|
-
const cacheDir = join(
|
|
141
|
+
const cacheDir = join(homedir(), '.lito', 'templates');
|
|
141
142
|
if (existsSync(cacheDir)) {
|
|
142
143
|
const cached = readdirSync(cacheDir).length;
|
|
143
144
|
log.message(` ${pc.cyan('Cached templates:')} ${cached}`);
|
package/src/commands/preview.js
CHANGED
|
@@ -71,7 +71,8 @@ export async function previewCommand(options) {
|
|
|
71
71
|
} catch (serveError) {
|
|
72
72
|
// Fallback to Python's http.server if serve isn't available
|
|
73
73
|
try {
|
|
74
|
-
|
|
74
|
+
const pythonCmd = process.platform === 'win32' ? 'python' : 'python3';
|
|
75
|
+
await execa(pythonCmd, ['-m', 'http.server', port, '-d', outputPath], {
|
|
75
76
|
stdio: 'inherit',
|
|
76
77
|
cwd: process.cwd(),
|
|
77
78
|
});
|
package/src/core/config.js
CHANGED
|
@@ -108,15 +108,43 @@ export async function generateConfig(projectDir, options, frameworkConfig = null
|
|
|
108
108
|
if (await pathExists(astroConfigPath)) {
|
|
109
109
|
let content = await readFile(astroConfigPath, "utf-8");
|
|
110
110
|
|
|
111
|
-
// Add
|
|
112
|
-
const
|
|
113
|
-
|
|
111
|
+
// Add imports after the last existing import line
|
|
112
|
+
const importLines = [
|
|
113
|
+
`import _astroLlmsTxt from '@4hse/astro-llms-txt';`,
|
|
114
|
+
`import { fileURLToPath as _llmsFileURLToPath } from 'url';`,
|
|
115
|
+
];
|
|
116
|
+
// Wrapper: fix Windows dir.pathname (/C:/... → C:/...) before passing to plugin
|
|
117
|
+
const wrapperFn = `function astroLlmsTxt(opts) {
|
|
118
|
+
const inner = _astroLlmsTxt(opts);
|
|
119
|
+
const origHook = inner.hooks['astro:build:done'];
|
|
120
|
+
inner.hooks['astro:build:done'] = async (args) => {
|
|
121
|
+
if (args.dir && args.dir.pathname) {
|
|
122
|
+
const fixed = _llmsFileURLToPath(args.dir);
|
|
123
|
+
args = { ...args, dir: { ...args.dir, pathname: fixed } };
|
|
124
|
+
}
|
|
125
|
+
return origHook(args);
|
|
126
|
+
};
|
|
127
|
+
return inner;
|
|
128
|
+
}`;
|
|
129
|
+
for (const importLine of importLines) {
|
|
130
|
+
if (!content.includes(importLine)) {
|
|
131
|
+
const lines = content.split('\n');
|
|
132
|
+
let lastImportIdx = 0;
|
|
133
|
+
for (let i = 0; i < lines.length; i++) {
|
|
134
|
+
if (lines[i].startsWith('import ')) lastImportIdx = i;
|
|
135
|
+
}
|
|
136
|
+
lines.splice(lastImportIdx + 1, 0, importLine);
|
|
137
|
+
content = lines.join('\n');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Inject wrapper function after imports
|
|
141
|
+
if (!content.includes('function astroLlmsTxt(')) {
|
|
114
142
|
const lines = content.split('\n');
|
|
115
143
|
let lastImportIdx = 0;
|
|
116
144
|
for (let i = 0; i < lines.length; i++) {
|
|
117
145
|
if (lines[i].startsWith('import ')) lastImportIdx = i;
|
|
118
146
|
}
|
|
119
|
-
lines.splice(lastImportIdx + 1, 0,
|
|
147
|
+
lines.splice(lastImportIdx + 1, 0, '', wrapperFn);
|
|
120
148
|
content = lines.join('\n');
|
|
121
149
|
}
|
|
122
150
|
|
|
@@ -123,13 +123,13 @@ export async function fetchGitHubTemplate(owner, repo, ref) {
|
|
|
123
123
|
|
|
124
124
|
// Use tar to extract (available on all Unix systems and modern Windows)
|
|
125
125
|
const { execa } = await import('execa');
|
|
126
|
-
|
|
126
|
+
// Use forward slashes on Windows to avoid bsdtar issues with drive letters (C:)
|
|
127
|
+
const tarPath = tempTarPath.replace(/\\/g, '/');
|
|
128
|
+
const extractPath = cachePath.replace(/\\/g, '/');
|
|
127
129
|
const tarArgs = [
|
|
128
|
-
'-xzf',
|
|
129
|
-
'-C',
|
|
130
|
-
'--strip-components=1'
|
|
131
|
-
// On Windows, GNU tar misinterprets drive letters (C:) as remote hosts
|
|
132
|
-
...(isWin ? ['--force-local'] : [])
|
|
130
|
+
'-xzf', tarPath,
|
|
131
|
+
'-C', extractPath,
|
|
132
|
+
'--strip-components=1'
|
|
133
133
|
];
|
|
134
134
|
await execa('tar', tarArgs);
|
|
135
135
|
|