對于許多留言詢問Orion使用問題的同學,在這里說一聲抱歉。
對于Meteor長期任性不向下兼容的更新,各路開發(fā)者已經(jīng)吐槽了幾十個版本了。Orion的開發(fā)者也不例外,從1.2版本開始之后,就不在對Orion這個項目進行維護更新了。
那么問題來了,我的水平目前還沒有達到修復所有更新的「Breaking Changes」,我如何使用Orion這么方便的包呢?
今天就來介紹一個Orion的繼承者 — 天蝎座 Scorpius !
好吧,meteor從1.3之后就沒更新過,作為一個被Meteor快速迭代拋棄的「新人」,我決定從頭來過!
curl https://install.meteor.com/ | sh
Removing your existing Meteor installation.
Downloading Meteor distribution
######################################################################## 100.0%
Meteor 1.4.1.1 has been installed in your home directory (~/.meteor).
Writing a launcher script to /usr/local/bin/meteor for your convenience.
To get started fast:
$ meteor create ~/my_cool_app
$ cd ~/my_cool_app
$ meteor
上了個廁所以后,Meteor的更新完成了,目測現(xiàn)在沒有很嚴重的墻的問題了。當年我們可是得等幾十分鐘的啊。
看一下1.4更(gao)新(za)了啥 https://guide.meteor.com/1.4-migration.html
所以,該怎么裝天蝎座呢?一臉懵逼中……對了,有atmosphere,趕緊查一下!
不錯,看來Orion有的擴展包,這個Scorpius都clone了一份,嘿嘿。
不管三七二十一,先把看的順眼的擴展包都裝了!
# 核心包
meteor add scorpiusjs:core
# 樣式
meteor add twbs:bootstrap fortawesome:fontawesome scorpiusjs:bootstrap
# 路由
meteor add kadira:flow-router kadira:blaze-layout
我們可以看到,和Orion一樣,Core核心包里包括了
blaze-html-templates
ecmascript
meteor
scorpiusjs:base
scorpiusjs:lang-en
scorpiusjs:collections
scorpiusjs:dictionary
scorpiusjs:accounts
scorpiusjs:attributes
scorpiusjs:config
這些東西,就是我們有了英文的翻譯,后臺集合條目CURD,字典,賬戶,屬性接口,配置管理這些功能。
來,天靈靈,地靈靈,期望編譯不出錯!終于感受到了C++程序員的痛苦了。
meteor
[[[[[ ~/Github/meteor/orion_next ]]]]]
=> Started proxy.
=> Started MongoDB.
I20160930-16:25:09.709(8)? ** You've set up some data subscriptions with Meteor.publish(), but
I20160930-16:25:09.858(8)? ** you still have autopublish turned on. Because autopublish is still
I20160930-16:25:09.858(8)? ** on, your Meteor.publish() calls won't have much effect. All data
I20160930-16:25:09.859(8)? ** will still be sent to all clients.
I20160930-16:25:09.859(8)? **
I20160930-16:25:09.859(8)? ** Turn off autopublish by removing the autopublish package:
I20160930-16:25:09.859(8)? **
I20160930-16:25:09.859(8)? ** $ meteor remove autopublish
I20160930-16:25:09.859(8)? **
I20160930-16:25:09.860(8)? ** .. and make sure you have Meteor.publish() and Meteor.subscribe() calls
I20160930-16:25:09.860(8)? ** for each collection that you want clients to see.
I20160930-16:25:09.860(8)?
I20160930-16:25:10.165(8)? Scorpius config initialized
I20160930-16:25:10.267(8)? Scorpius dictionary initialized
=> Started your app.
=> App running at: http://localhost:3000/
哇塞,居然沒有出錯!啊咧咧!
生產(chǎn)環(huán)境中,我們需要把prototyping的兩個包注釋掉,當然開發(fā)過程中可以暫時留著。
# autopublish@1.0.7 # Publish all data to the clients (for prototyping)
# insecure@1.0.7 # Allow all DB writes from clients (for prototyping)
進入/admin,看到了熟悉的登錄注冊界面,Orion指定創(chuàng)建的第一個用戶為管理員用戶。
當然,由于天蝎座只有0.3.0,所以很多功能還不完善,還得修改許多Orion和Meteor1.4的適配問題,這里創(chuàng)建完用戶之后,會出現(xiàn)這個錯誤,不過呢,第一個用戶還是創(chuàng)建了的,我們可以登入后臺/admin,可是登進去以后,左邊欄什么都沒有,果然沒有admin權限就是什么都看不到。
好在我們可以通過meteor shell
手動解決這個問題:
# 在項目路徑,新開一個shell,使用meteor shell命令登錄
# 看看剛才創(chuàng)建的用戶
> Meteor.users.findOne()
Document {
_id: 'mDBG7Fu8QBjdnY9zs',
createdAt: Fri Sep 30 2016 16:28:55 GMT+0800 (CST),
services:
{ password: { bcrypt: '$2a$10$7cX1FNRfNdrromkugyOikOnwDr6lfC8gTf404OliLGKOqP7hrDSOK' },
resume: { loginTokens: [Object] } },
emails: [ { address: 'dragonszy@163.com', verified: false } ],
profile: { name: 'dragonszy' } }
然后我們使用Roles包的賦予權限命令:
> let u = Meteor.users.findOne();
> Roles.addUserToRoles(u._id, ["admin"]);
{ numberAffected: 1, insertedId: 'QoJ6pKRnozXZppJSo' }
然后我們的后臺(的側(cè)邊欄)就完美展現(xiàn)啦!
可是還有點小問題,就是點進去看不到表格,打開瀏覽器console,發(fā)現(xiàn)報錯ReferenceError: Session is not defined
。不要著急,看看.meteor/packages
果然沒有session,我們添加它即可。
所以,經(jīng)過不懈的努力和探索,Orion->Scorpius終于可以正常使用啦!撒花!
Scorpius已被國外團隊成功使用在最近的48h Hackhaton上,所以基本功能都是沒有大問題滴!Meteor 1.2 版本以后的同學可以直接使用Scorpius在未來的項目上,文檔可以先參考Orion的,Scorpius文檔之后會陸續(xù)跟上的。
最后,當然是奉上Github地址啦!如有問題,請參見:
https://github.com/loongmxbt/orion_next
祝大家學(ru)習(keng)Meteor愉快!我接著幫大家踩Phoenix/Elixir的坑去了,別忘記關注微信公眾號「Meteor全棧開發(fā)」哦~