Yuki Takei 4 лет назад
Родитель
Сommit
f621d2c753
2 измененных файлов с 18 добавлено и 16 удалено
  1. 2 16
      packages/app/src/utils/process-utils.ts
  2. 16 0
      packages/app/src/utils/project-dir-utils.ts

+ 2 - 16
packages/app/src/utils/process-utils.ts

@@ -1,18 +1,4 @@
-/**
- * @author: @AngularClass
- * @author: Yuki Takei <yuki@weseek.co.jp>
- */
-
-const path = require('path');
-
-// Helper functions
-const ROOT = path.resolve(__dirname, '../../..');
-
-function hasProcessFlag(flag) {
+/* eslint-disable import/prefer-default-export */
+export function hasProcessFlag(flag: string): boolean {
   return process.argv.join('').indexOf(flag) > -1;
   return process.argv.join('').indexOf(flag) > -1;
 }
 }
-
-const root = path.join.bind(path, ROOT);
-
-exports.hasProcessFlag = hasProcessFlag;
-exports.root = root;

+ 16 - 0
packages/app/src/utils/project-dir-utils.ts

@@ -0,0 +1,16 @@
+/* eslint-disable import/prefer-default-export */
+
+import fs from 'fs';
+import path from 'path';
+import process from 'process';
+
+const isServer = typeof window === 'undefined';
+const isCurrentDirRoot = isServer && fs.existsSync('./next.config.js');
+
+export const projectRoot = isCurrentDirRoot
+  ? process.cwd()
+  : path.resolve(__dirname, '../../');
+
+export function resolveFromRoot(relativePath: string): string {
+  return path.resolve(projectRoot, relativePath);
+}