Skip to content

Commit

Permalink
fix originDir
Browse files Browse the repository at this point in the history
  • Loading branch information
velsa committed Feb 20, 2024
1 parent 2a1174b commit defb893
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notehost",
"version": "1.0.8",
"version": "1.0.10",
"description": "NoteHost is a free and powerful Notion hosting service.",
"repository": "https://github.com/velsa/notehost",
"homepage": "https://github.com/velsa/notehost",
Expand All @@ -21,7 +21,7 @@
"type": "module",
"main": "dist/index.js",
"module": "dist/index.cjs",
"types": "dit/index.d.ts",
"types": "dist/index.d.ts",
"bin": {
"init": "./dist/cli/index.js"
},
Expand Down
28 changes: 21 additions & 7 deletions src/cli/init-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ import path from "path";
import { copyFilesToSDK } from "./output";
import { getParserConfig } from "./parser-config";

export async function initRepo(domain, options) {
export async function initRepo(domain) {
const sdkDir = path.join(process.cwd(), domain);
const originDir =
process.env.NODE_ENV === "development"
? path.join(process.argv[1], "../../../..", "notehost")
: path.join(process.argv[1], "../..", "notehost");

const originDir = buildOriginDir(process.argv[1]);
const parserConfig = await getParserConfig(domain);

const templates = fs.readdirSync(path.join(originDir, "templates"));
const template =
templates.length > 1
Expand Down Expand Up @@ -48,3 +43,22 @@ export async function initRepo(domain, options) {

process.exit(0);
}

function buildOriginDir(appPath: string) {
const runDir = appPath.match(/^(.*)\/[^/]+$/)[1];

// running locally
if (process.env.NOTION_TS_CLIENT_DEBUG) {
return path.join(runDir, "../src");
}

const parts = runDir.split("/");

if (parts[parts.length - 2] === "notion-ts-client") {
// pnpx
return path.join(runDir, "../src");
} else {
// npx
return path.join(runDir, "../notion-ts-client/src");
}
}

0 comments on commit defb893

Please sign in to comment.