@fjell/docs-template
Version:
Shared documentation template for Fjell projects
64 lines (61 loc) • 2.38 kB
JavaScript
// src/scripts/copy-docs-core.ts
import { execSync } from "child_process";
import { join } from "path";
import { existsSync } from "fs";
async function copyDocs(cwd) {
try {
const workingDir = cwd || process.cwd();
const configPath = join(workingDir, "docs.config.ts");
if (!existsSync(configPath)) {
console.error("Error: docs.config.ts not found in current directory");
console.error("Please run this command from a directory containing docs.config.ts");
process.exit(1);
}
console.log("Loading configuration from:", configPath);
const configJsPath = configPath.replace(".ts", ".js");
console.log("Compiling TypeScript configuration...");
try {
execSync(`npx tsc ${configPath} --target es2022 --module esnext --moduleResolution bundler`, { cwd: workingDir });
} catch (error) {
const compileError = error;
console.error("Failed to compile TypeScript configuration:", compileError.message);
process.exit(1);
}
const configJsUrl = `file://${configJsPath}?${Date.now()}`;
const { default: config } = await import(configJsUrl);
try {
execSync(`rm ${configJsPath}`, { cwd: workingDir });
} catch {
}
if (!config.filesToCopy || !Array.isArray(config.filesToCopy)) {
console.error("Error: No filesToCopy configuration found in docs.config.ts");
console.error("Please add a filesToCopy array to your configuration");
process.exit(1);
}
console.log("Copying documentation files...");
for (const file of config.filesToCopy) {
if (!file.source || !file.destination) {
console.warn("Skipping invalid file configuration:", file);
continue;
}
const command = `cp ${file.source} ${file.destination}`;
console.log(`Executing: ${command}`);
try {
execSync(command, { cwd: workingDir });
} catch (error) {
const copyError = error;
console.error(`Failed to copy ${file.source} to ${file.destination}:`, copyError.message);
process.exit(1);
}
}
console.log("Documentation files copied successfully!");
} catch (error) {
const generalError = error;
console.error("Error copying documentation files:", generalError.message);
process.exit(1);
}
}
// src/scripts/copy-docs.ts
copyDocs();
//# sourceMappingURL=copy-docs.js.map