首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为库创建Meteor包包装器时出现的问题

为库创建Meteor包包装器时出现的问题
EN

Stack Overflow用户
提问于 2015-02-02 18:24:24
回答 2查看 426关注 0票数 1

我正在尝试为switchery (https://github.com/abpetkov/switchery)库制作一个流星包包装器。据我所知,我遵循了“官方指南”。

所以我做了一个原始的分支(https://github.com/mediatainment/switchery),在分支的根上创建了一个流星文件夹,并开始添加一些基本的东西来让它工作:

文件结构root | |-meteor | |-export.js | |-tests.js |-package.js // I found out that this must be in root |-package.json // added devDependencies for my Package |-switchery.js |-switchery.css

package.json

代码语言:javascript
复制
{
  "name": "switchery",
  "version": "0.7.0",
  "description": "Create iOS 7 styled switches from default input checkboxes",
  "main": "switchery.js",
  "repository": {
    "type": "git",
    "url": "git://github.com/abpetkov/switchery.git"
  },
  "author": "Alexander Petkov",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/abpetkov/switchery/issues"
  },
  "devDependencies": {
    "uglify-js": "~2.4.8",
    "component": "^1.0.0",
    "uglifycss": "0.0.7",
    "grunt-exec": "latest",
    "spacejam": "latest",
    "jasmine-node": "latest",
    "coffee-script": "latest"
  }
}

package.js

代码语言:javascript
复制
// package metadata file for Meteor.js
'use strict';

var packageName = 'mediatainment:switchery'; // https://atmospherejs.com/mediatainment/switchery
var where = 'client'; // where to install: 'client' or 'server'. For both, pass nothing.

var packageJson = JSON.parse(Npm.require("fs").readFileSync('package.json'));

Package.describe({
    name: packageName,
    summary: 'Switchery (official) - turns your default HTML checkbox inputs into beautiful iOS 7 style switches in just few simple steps. Easy customizable to fit your design perfectly.',
    version: "0.0.1", //packageJson.version,
    git: 'https://github.com/mediatainment/switchery'
});

Package.onUse(function(api) {
    api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']);
    api.export('Switchery');
    api.addFiles(['switchery.js', 'switchery.css', 'meteor/export.js'], where);
});

Package.onTest(function(api) {
    api.use(packageName, where);
    api.use('tinytest', where);
    api.addFiles('meteor/tests.js', where); // testing specific files
});

meteor/export.js

代码语言:javascript
复制
/*global Switchery:true*/ // Meteor creates a file-scope global for exporting. This comment prevents a potential JSHint warning.
Switchery= window.Switchery;
delete window.Switchery;

看起来非常简单,但我有以下错误:

·当我将本地包添加到空项目中时,结果是

代码语言:javascript
复制
While reading package from `/Users/jan/WebstormProjects/packages/switchery`:
fs.js:438:18: ENOENT, no such file or directory 'package.json'
at Object.fs.openSync (fs.js:438:18)
at Object.fs.readFileSync (fs.js:289:15)
at package.js:7:48

当我对VersionNumber进行硬编码时,例如:"0.0.1“并删除

代码语言:javascript
复制
var packageJson = JSON.parse(Npm.require("fs").readFileSync('package.json'));

这个错误消失了,我可以启动应用程序了,但是·控制台中出现了新的错误:

Uncaught ReferenceError: require is not defined switchery.js:18 (anonymous function) mediatainment_switchery.js (anonymous function) mediatainment_switchery.js? (anonymous function) global-imports.js Uncaught TypeError: Cannot read property 'Switchery' of undefinedglobal-imports.js (anonymous function) template.ptest.js Uncaught ReferenceError: Template is not definedtemplate.ptest.js(anonymous function) template.ptest.js (anonymous function) ptest.js Uncaught ReferenceError: Meteor is not defined ptest.js (anonymous function) ptest.js (anonymous function) application.js:23 No valid media id detected

要包含在我的包中的库只是一个css和js文件。

我做错了什么?(Meteor 1.0.3.1)

非常感谢你提前

EN

回答 2

Stack Overflow用户

发布于 2015-02-03 00:03:49

我的意思是,你做错了。基本上,你是在派生库的原始repo,并在那里进行更改,以便移植到meteor (基本上是制作Meteor包)。

考虑这样的情况,原始的lib repo (上游)得到了更新,但你已经在Atomosphere中发布了包,现在你想要在Meteor中获得上游的更新代码,你可能无法在以后的某个时候合并(可能是由于)。

因此,在将外部库集成为Meteor包时,常用的方法是保留原始库存储库(上游)作为Meteor包存储库的git子模块

喜欢

代码语言:javascript
复制
meteor-switchery
- lib
-- <original-lib-repo-git-submodule>
-package.js
-package.json

您可以参考下面的包,它们被集成为外部js库的meteor包,它遵循我上面提到的方法。

Meteor bootstrap tagsinput

Meteor Bootstrap TokenField

并且您正在将与原始库相同的版本放入package.json中提到的版本。请不要这样做

将其本身作为单独的版本。通过维护不同的版本,它可以灵活地更改版本,同时放置原始库的新版本或一些修复程序,或者如果升级了一些依赖项等

希望这能有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2015-02-03 00:58:31

我的问题是,我使用的是外部库的root文件,而不是/dist文件夹中的文件。所以这是正确的方式:

代码语言:javascript
复制
 `api.addFiles(['dist/switchery.js', 'dist/switchery.css', 'meteor/export.js'], where);`
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28275532

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档