Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make paths in plugin be system-independent #28

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ import generateTypeScriptFile from "./generateTypeScriptFile";
import mkdirp from "mkdirp";
import fs from "fs";
import chokidar from "chokidar";
import path from "path";

const packageName = "next-type-safe-routes";
const typeFolder = `@types/${packageName}`;
const typeFolder = path.join("@types", packageName);

const log = (message: string) => {
console.log(`\x1b[36m${packageName}\x1b[0m: ${message}`);
};

const writeTypesToDisc = (nextPagesDirectory: string) => {
const srcDir = nextPagesDirectory.replace("/pages", "");
const typeFolderPath = `${srcDir}/${typeFolder}`;
// we assume the src directory is the directory containing the pages directory
const srcDir = path.dirname(nextPagesDirectory);
const typeFolderPath = path.join(srcDir, typeFolder);
const typeScriptFile = generateTypeScriptFile(nextPagesDirectory);

mkdirp.sync(typeFolderPath);
fs.writeFileSync(`${typeFolderPath}/index.d.ts`, typeScriptFile);
fs.writeFileSync(path.join(typeFolderPath, "index.d.ts"), typeScriptFile);

log(`types written to ${typeFolder}`);
};
Expand Down