如何获取流星智能包中的当前目录 [英] How to get the current directory within a meteor Smart Package

查看:43
本文介绍了如何获取流星智能包中的当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为要在 Atmosphere 上发布的meteor 构建一个包,我需要获取安装该包的当前目录.我在包中包含的文件中尝试了 process.cwd() ,但它获取了我的应用程序的当前目录.该软件包已安装并正常工作,看起来该软件包与应用程序在同一进程中运行,因此 process.cwd() 正在获取当前应用程序目录.有谁知道获取包当前目录的技巧?

I am building a package for meteor to be published on Atmosphere and I need to get the current directory that the package is installed. I have tried process.cwd() in a file that's included in the package, but that gets the current directory of my app. The package is installed and working correctly, it just seems that the package is running in the same process as the app, hence process.cwd() is getting the current app dir. Does anyone know of a trick to get the current directory of the package?

这是我在包文件中的内容:

This is what I have in the package files:

package.js

Package.on_use(function (api) {
    api.use('sync-methods', 'server');
    api.add_files(["lib/api_server.js"], "server");
    api.add_files(["lib/api_client.js"], "client");
});

api_server.js

api_server.js

var cwd = process.cwd();
console.log(cwd);

这会显示 /home/dknell/meteor-apps/testApp

推荐答案

如果你不想要内容,而是另一个工具的绝对路径,你可以试试

If you don't want the content, but an absolute path for another tool, you can try

var path = Npm.require('path');
var base = path.resolve('.');
var assetsBase = path.join(base, '/assets/packages/<author_smart-package-name>');

对于 输入您的包名,但如果它包含您的meteor 用户名,请将冒号 (:) 更改为下划线 (_)

For the <author_smart-package-name> enter your package name, but if it has your meteor user name included, change the colon (:) to underscore (_)

这在 OS X 和 Linux 上似乎没问题,可能也适用于 Windows.

That seems okay on OS X and Linux, probably works in windows as well.

这篇关于如何获取流星智能包中的当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆