我正在尝试为切换(https://github.com/abpetkov/switchery)库创建一个meteor包装器。我按照"官方指南"据我所知。
所以我创建了原始的fork(https://github.com/mediatainment/switchery),在fork的根目录中创建了一个meteor文件夹,并开始添加一些基本的东西以使其工作:
Filestructure
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
{
"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
// 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
});
流星/ export.js
/*global Switchery:true*/ // Meteor creates a file-scope global for exporting. This comment prevents a potential JSHint warning.
Switchery= window.Switchery;
delete window.Switchery;
看起来非常直截了当,但我有以下错误:
•当我将本地包添加到空项目时,这会导致
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"并删除
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文件。
我做错了什么? (流星1.0.3.1)
非常感谢提前
答案 0 :(得分:1)
IMO,你这样做是错误的。 基本上,你正在分配lib的原始回购并在那里进行更改以便移植到meteor(基本上制作Meteor包)。
考虑一下原始lib repo(上游)更新的情况,但是你已经在Atomosphere中发布了包,现在你想要获得Meteor中上游的更新代码,你可能在以后的某个时候不能合并(可能)由于)。
因此,在将外部库集成为Meteor包时,常见的方法是将原始的lib repo(上游)保留为Meteor包回购的 git子模块。
喜欢
meteor-switchery
- lib
-- <original-lib-repo-git-submodule>
-package.js
-package.json
您可以参考以下包,它们被集成为外部js库的meteor包,它遵循上面提到的方法
您使用package.json中提到的版本与原始库相同的版本。 请不要这个
将其作为单独的版本。通过维护不同的版本,它可以灵活地更改版本,同时放置新版本的原始库或一些修复或升级某些依赖等等
希望这有帮助。
答案 1 :(得分:0)
我的问题是,我在root
文件夹中使用外部库的/dist
文件而不是它们。所以这是正确的方法:
api.addFiles(['dist/switchery.js', 'dist/switchery.css', 'meteor/export.js'], where);