Can third party node modules be imported into extensions? - adobe-brackets

I am attempting to develop a brackets.io extension and plan on using a third party npm library? Can I import it?
define(function (require, exports, module) {
"use strict";
var ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
var CommandManager = brackets.getModule("command/CommandManager");
var Menus = brackets.getModule("command/Menus");
var modulePath = ExtensionUtils.getModulePath(module);
var thirdPartyLib = require('./node_modules/lib/lib.js'); // this is throwing an error!
});

Brackets extensions run in the webkit side, not in the node side.
Take a look at this page:
https://github.com/adobe/brackets/wiki/Brackets-Node-Process:-Overview-for-Developers

Related

Lightswitch HTML - chat application upgrade

I wanted to know if anyone has given this a go and got it working?
http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/182/Connecting-To-SignalR-With-LightSwitch-HTML-Client.aspx
Basically my issue is i cant open the file to begin with, whether it be Visual Studio 2012, 2013 or 2015, so I have followed the guide and used the files from the downloaded project for this error message to occur:
which is caused by this line under the sendmessage_execute function:
chat.server.send(screen.displayname, screen.message);
im hoping someone has got this working and could point out anything different from the user guide, heres what I have used/done:
Under the PROJECT.Server I have:
created a folder called SignalR with the file ChatHub.cs in
added the json2.js (both) and signalR (both) files to the scripts
folder
Under the Project.HTMLClient
added the json2.js (both) and signalR (both) files to the scripts
folder
referenced the scripts including the localhost in the default.htm file
Created a screen. called ChatScreen and added all the referenced code here from the guide online (3 strings and 1 button)
i also installed the Nu-GET as instructed
More research for this was required, I found this post which explains how to do it a lot easier and in an application for both 2013/2015, works a treat and can easily be adapted for other screens
https://blogs.msdn.microsoft.com/rmattsampson/2013/03/14/asp-net-signalr-and-lightswitch-vs-2012-update-2-vs-2013-and-later/
I have also managed to edit there block of code to list all messages in a string, this is not stored and refresh's each time but its now possible to have a conversation while on the same screen
var string;
myapp.ChatScreen.created = function (screen) {
string = "";
$(function () {
chat = $.connection.chatHub;
chat.client.broadcastMessage = function (message) {
string = string + message + ";";
screen.updates = string.split(';').join("\r\n");
console.log(string.split(';').join("\r\n"))
};
$.connection.hub.start()
.done(function () {
})
.fail(function () {
alert("Could not Connect! - ensure EnableCrossDomain = true");
});
});
};
It would be better practice using an array and displaying it this way but the code above demonstrates it works

How to integrate ASP.NET 5 with signalr

I'm trying to make an ASP.NET 5 web app using SignalR. I've created an empty web app, I've added an index.html page with some contents but I can't integrate SignalR. So far, in order to use SignaR, I've carried out the following step:
1) I've added the following dependency in the project.json file:
"Microsoft.AspNet.SignalR.Server": "3.0.0-rc1-final"
2) In the Startup class, I've added
services.AddSignalR();
to the ConfigureServices method, and
app.UseSignalR();
to the Configure method.
3) I've added to the project a class deriving from Microsoft.AspNet.SignalR.Hub and inserted a public method into it.
After this, in index.html I've added the logic trying to access the method but when I launch the app firefox console says
Error: $ is not defined
Here is the javascript code:
<script>
var app = angular.module("myapp", []);
app.controller("myctr", function ($scope) {
$scope.input = "";
$scope.output = "";
$.connection.myHub1.client.JSMet1 = function (x) {
$scope.$apply(function () {
$scope.output = x;
});
};
$scope.AggiornaTesto = function () {
$.connection.myHub1.server.cSMet1($scope.input);
};
$.connection.hub.start();
});
</script>
As you can see I also use AngulaJS.
Error: $ is not defined
Its because you haven't added jQuery reference to your page, please read this article from Microsoft, it will step by step demonstrate you how to implement SingnalR with ASP.NET MVC projects.

meteor-testing tutorial fails

I started the meteor-testing tutorial, but the 2nd automatic generated test fails with:
TypeError: Cannot call method 'url' of undefined
So it seems that the client variable is not defined. Did anybody experience similar issues? (btw is there a way to debug this)
i'm using ubuntu 14.04 with
Meteor 1.2.0.2
node v4.0.0
xolvio:cucumber 0.19.4_1 CucumberJS for Velocity
Update:
Generated test code intests/cucumber/features/step_definitions/sample_steps.js:
// You can include npm dependencies for support files in tests/cucumber/package.json
var _ = require('underscore');
module.exports = function () {
// You can use normal require here, cucumber is NOT run in a Meteor context (by design)
var url = require('url');
// 1st TEST OK
this.Given(/^I am a new user$/, function () {
server.call('reset'); // server is a connection to the mirror
});
// 2nd TEST FAIL
this.When(/^I navigate to "([^"]*)"$/, function (relativePath) {
// process.env.ROOT_URL always points to the mirror
client.url(url.resolve(process.env.ROOT_URL, relativePath));
});
...
};
I was said to file an issue in the chimp repository, where I was pointed to the solution:
// 2nd TEST FAIL
this.When(/^I navigate to "([^"]*)"$/, function (relativePath) {
// REPLACE client with browser
browser.url(url.resolve(process.env.ROOT_URL, relativePath));
});
This is a short fix, but I'm not sure whether you should later rather use client (seems to be wrapper for different environments).
**Update: ** meanwhile this was fixed, no adaption necessary anymore

Meteor crashes constantly even after reinstalling

I am trying to run my project on the localhost but whenever I try it crashes. I even tried deploying it directly to the meteor website but nothing happens. It happened all of a suddenly. Everything was working fine till I added packages "tap:i18n" and "accounts-facebook".
/Users/haraldur/.meteor/packages/meteor-tool/.1.1.9.1sd3e7j++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
throw(ex);
^ReferenceError: ServiceConfiguration is not defined
at lib/app.js:29:1
at /Users/haraldur/myapp/.meteor/local/build/programs/server/app/lib/app.js:47:4
at /Users/haraldur/myapp/.meteor/local/build/programs/server/boot.js:242:10
at Array.forEach (native)
at Function._.each._.forEach (/Users/haraldur/.meteor/packages/meteor-tool/.1.1.9.1sd3e7j++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
at /Users/haraldur/myapp/.meteor/local/build/programs/server/boot.js:137:5
Exited with code: 8
Your application is crashing. Waiting for file change.
This is my app.js file. I don't even have line 47. I am quite confused.
Timeouts = {};
// Initialize my collections
Rooms = new Meteor.Collection("rooms");
Videos = new Meteor.Collection("videos");
Messages = new Meteor.Collection("messages");
Votes = new Meteor.Collection("votes");
Favorites = new Meteor.Collection("favorites");
Skips = new Meteor.Collection("skips");
Cache = {};
Cache.Spotify = new Meteor.Collection("cache_spotify");
Cache.YouTube = new Meteor.Collection("cache_youtube");
Cache.Echonest = new Meteor.Collection("cache_echonest");
Cache.Freebase = new Meteor.Collection("cache_freebase");
// Dependencies for YouTube player
youtubeApiReady = false;
youtubePlayerReady = false;
youtubeApiDependency = new Deps.Dependency;
youtubePlayerDependency = new Deps.Dependency;
onYouTubeIframeAPIReady = function(){
youtubeApiReady = true;
youtubeApiDependency.changed();
}
ServiceConfiguration.configurations.remove({
service: "twitter"
});
ServiceConfiguration.configurations.insert({
service: "twitter",
consumerKey: APIKeys.twitter.consumerKey,
secret: APIKeys.twitter.secret
});
Looks like the package accounts-facebook need specific configuration for it
try add service-configuration to your application
meteor add service-configuration
Reference https://atmospherejs.com/meteor/service-configuration
Since adding those two packages seem to be the culprit, try removing them one at a time. I would first:
meteor remove tap:i18n
And try to run it. If it still fails, try:
meteor remove accounts-facebook
...and try it again.
Alternatively or first, you might want to see what's at these two locations:
lib/app.js:29:1
lib/app.js:47:4
IOW, what's at line 29, char 1, and line 47 char 4 of your app.js file. Perhaps there is something problematic there, though if it worked prior to adding those two packages, likely not.

Adobe Brackets - get path of current extension

I'm looking for the canonical way to access the directory that belongs to a running extension. At the moment I have this kludge. It allows me to access a .json located in the same directory as main.js.
var support_dir = brackets.app.getApplicationSupportDirectory(),
precursor_path,
precursor_file = "package.json"; // where this represents some config file.
support_dir += "/extensions/user/zeffii.precursor/";
precursor_path = support_dir + precursor_file;
var prototypes;
$.getJSON(precursor_path, function (data) {
prototypes = data;
});
This should work:
var ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
var path = ExtensionUtils.getModulePath(module);
(Where module comes from the define(function (require, exports, module) { at the top of your extension module).

Resources