Parcourir la source

add ModulePathResolver

Yuki Takei il y a 9 ans
Parent
commit
f3c7ef4abb

+ 3 - 1
packages/growi-commons/package.json

@@ -1,6 +1,6 @@
 {
   "name": "crowi-pluginkit",
-  "version": "1.0.3",
+  "version": "1.0.4",
   "description": "The Crowi Plugin Kit to develop plugins",
   "main": "lib/index.js",
   "files": [
@@ -10,6 +10,7 @@
     "build": "babel src --out-dir lib --source-maps inline",
     "clean": "npm cache clean && npm run rimraf -- lib",
     "prebuild": "npm run clean",
+    "prewatch": "npm run clean",
     "watch": "babel src --out-dir lib --watch --source-maps inline",
     "rimraf": "rimraf",
     "test": "mocha --compilers js:babel-register test/*.js"
@@ -25,6 +26,7 @@
   },
   "homepage": "https://github.com/weseek/crowi-pluginkit#readme",
   "dependencies": {
+    "app-root-path": "^2.0.1"
   },
   "devDependencies": {
     "babel-cli": "^6.23.0",

+ 2 - 1
packages/growi-commons/src/index.js

@@ -1 +1,2 @@
-export * from './lib/util/BasicInterceptor';
+export * from './util/BasicInterceptor';
+export * from './util/ModulePathResolver';

+ 0 - 0
packages/growi-commons/src/lib/util/BasicInterceptor.js → packages/growi-commons/src/util/BasicInterceptor.js


+ 13 - 0
packages/growi-commons/src/util/ModulePathResolver.js

@@ -0,0 +1,13 @@
+import * as path from 'path';
+import * as appRoot from 'app-root-path';
+
+/**
+ * Resolve path tools
+ */
+export class ModulePathResolver {
+
+  relativeFromRoot(modulePath) {
+    return path.relative(appRoot.path, path.join(__dirname, modulePath))
+  }
+
+}