Typescript requirejs web essentials 2.9 - import

I just update Web essentials and Typescript to new version.
Result that my project don't work anymore.
Here's my typescript code:
/// <reference path="DefinitelyTyped/jqueryui.d.ts" />
/// <reference path="DefinitelyTyped/jquery-datatable.d.ts" />
import Common = module("Common");
import GMap = module("GMap");
declare var $: JQueryStatic;
export class Polygon extends GMap.Polygon {
Before update my generated code (that worked) was:
var __extends = this.__extends || function (d, b) {
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
define(["require", "exports", "GMap", "Common"], function(require, exports, __GMap__, __Common__) {
var GMap = __GMap__;
var Common = __Common__;
var Polygon = (function (_super) {
__extends(Polygon, _super);
function Polygon() {
_super.apply(this, arguments);
}
Now it look-like:
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Common = require("./Common");
var GMap = require("./GMap");
var Polygon = (function (_super) {
__extends(Polygon, _super);
In my console I have this error:
Uncaught Error: Module name "Common" has not been loaded yet for context: _. Use require([])
I try to add Common in the config. But before update It s just working fine.
Anyone can help me, maybe something need to be change in my code to have back my project working.
Thanks,
Jérôme
UPDATE
I just see that is due to Web Essentials 2.9, I don't have anymore the option to specify compiler option for amd module.
I just remove the extension and install back the version 2.7:
http://vswebessentials.com/nightly/webessentials2012-2.7.vsix

I would just add to this that Web Essentials does indeed support AMD modules in version 2.8 but that the option has gone missing in 2.9 - check out the comments on the download page.
You'll find the setting (in 2.8 or below) in...
Tools > Options > Web Essentials > TypeScript > "Use the AMD module"

You need to compile with the amd option. i.e.
tsc yourfile.ts --module "amd"
It defaults to "commonjs" which is the output that you are seeing at the moment.

Related

Hide template visibility depending on VS version?

I have created a VSIX with 2 templates, one is for VS2012 and another is for VS2013.
But if I use the VSIX, both templates are visible for both VS versions in "New Project" window. I want to restrict it. Is there any way?
This is not a great solution, but only one I've found for this problem.
You can register your package to initialize early on in the Visual Studio startup with the following attribute.
[ProvideAutoLoad(UIContextGuids80.NoSolution)]
public sealed YourPackage : Package
Then in your override void Initialize() method you'll want to register a new DTEEvent.
DTEEvents dte_events;
private void RegisterStartupEvents()
{
if(dte == null)
dte = (DTE)GetService(typeof(DTE));
if (dte != null)
{
dte_events = dte.Events.DTEEvents;
dte_events.OnStartupComplete += OnStartupComplete;
}
}
The OnStartupComplete will fire on startup before any templates have been initialized. To remove them from the list for the current VS version, the bundled zip template files that are copied when your VSIX package is installed will have to be deleted. This method could probably be nicer, but you get the idea.
private void OnStartupComplete()
{
dte_events.OnStartupComplete -= OnStartupComplete;
dte_events = null;
var cleanupList = TemplateCleanupByVsVersion[MajorVisualStudioVersion];
foreach (var deleteTemplate in cleanupList)
{
DirectoryInfo localVsDir = new DirectoryInfo(UserLocalDataPath);
// Locate root path of your extension installation directory.
var packageDllFileInfo = localVsDir.GetFiles("MyVsPackage.dll", SearchOption.AllDirectories)[0];
DirectoryInfo extensionDirInfo = packageDllFileInfo.Directory;
if (extensionDirInfo == null)
{
// Failed to locate extension install directory, bail.
return;
}
var files = extensionDirInfo.GetFiles(deleteTemplate + ".zip", SearchOption.AllDirectories);
if (files.Length > 0)
{
File.Delete(files[0].FullName);
}
}
ServiceProvider.GetWritableSettingsStore().SetPackageReady(true);
}
TemplateCleanupByVsVersion is a Dictionart<int,List<string>> that maps Visual Studio Major version with a list of zip file names (without extension) that you don't want showing up in the mapped Visual Studio version. Eg,
public readonly Dictionary<int, List<string>> TemplateCleanupByVsVersion = new Dictionary<int, List<string>>
{
{11,new List<string> { "MyTemplate1.csharp", "MyTemplate2.csharp", "MyTemplate3.csharp" } },
{12,new List<string> { "MyTemplate1.csharp" }},
{14,new List<string>()}
};
MajorVisualStudioVersion comes from parsing dte.Version. eg,
public int MajorVisualStudioVersion => int.Parse(dte.Version.Substring(0, 2));
The result being specific Visual Studio versions can remove any templates from your VSIX that don't work well. Hope that helps.

jsTree customize <li> using the alternative JSON format along with AJAX

I am using the alternative JSON format along with AJAX to load data in tree. Now there is a new ask, I am required to add a new element at the end of <li> tag.
I have created sample URL to display what I am currently doing.
Tree crated using alternative JSON format along with AJAX
And how the new LI should appear
Tree created using hard coded HTML but shows how the LI should look like
I think I should be able to do this if I use HTML Data but since the project is already live with JSON format this would require me to change a lot so before I start making this major change I just wanted to check if this is possible using JSON and AJAX format or not.
So I got answer from Ivan - Answer
In short there is misc.js in the src folder which has question mark plugin, this is the best example of what I wanted to do.
I tweaked its code for my needs and here is the new code.
(function ($, undefined) {
"use strict";
var span = document.createElement('span');
span.className = 'glyphicons glyphicons-comments flip jstree-comment'
$.jstree.defaults.commenticon = $.noop;
$.jstree.plugins.commenticon = function (options, parent) {
this.bind = function () {
parent.bind.call(this);
};
this.teardown = function () {
if (this.settings.commenticon) {
this.element.find(".jstree-comment").remove();
}
parent.teardown.call(this);
};
this.redraw_node = function (obj, deep, callback, force_draw) {
var addCommentIcon = true;
var data = this.get_node(obj).data;
//....Code for deciding whether comment icon is needed or not based on "data"
var li = parent.redraw_node.call(this, obj, deep, callback, force_draw);
if (li && addCommentIcon) {
var tmp = span.cloneNode(true);
tmp.id = li.id + "_commenticon";
var $a = $("a", li);
$a.append(tmp);
}
return li;
};
};
})(jQuery);

Meteor 0.6.4.1 changes confuses coffeescript?

After upgrading from Meteor 0.5.4 to Meteor 0.6.4.1 I modified my coffeescript code accordingly to reflect changes of the variable scope. For some reason I think the changes confused the coffeescript to javascript interpretation?
Current code:
#liveObjects = {}
test = () ->
if liveObjects.intervalID?
donothing;
liveObjects = {} --Maybe this is what caused the confusion? Mistaken as a local variable declaration?
From the Chrome tool I noticed that the javascript code as
(function() { var test;
this.liveObjects = {};
test = function() {
var liveObjects;
if (liveObjects.intervalID != null) { --ReferenceError: liveObjects is not defined
donothing;
}
liveOjects = {};
You have to set it using this/# again.
#liveObjects = {}
test = () ->
if liveObjects.intervalID?
donothing;
#liveObjects = {}

Calling class function within a constructor isn't being recognised

Answer:
It turns out I had neglected to use the new keyword when creating the class instance. The code in the question itself is fine.
Question:
I have a fairly simple class where the constructor calls another method on the class (editor_for_node). The call happens inside a jQuery each() loop, but I've also tried moving it outside.
define ['jquery'], ($) ->
class Editor
constructor: (#node, #data, #template) ->
#node.widgets().each (i, elem) =>
data = if #data then #data[i] else null
node = $(elem)
#editor_for_node node, data
editor_for_node: (node, data) ->
console.log 'hello!'
return {
'Editor': Editor,
}
When the line #editor_for_node node, data gets called, I get an error (in Firebug) saying this.editor_for_node is not a function.
I really can't see why this isn't working properly, the only possible source of weirdness that I can see is my use of require.js's define function at the start.
Edit: Generated output
(function() {
define(['jquery'], function($) {
var Editor;
Editor = (function() {
Editor.name = 'Editor';
function Editor(node, data, template) {
var _this = this;
this.node = node;
this.data = data;
this.template = template;
this.node.widgets().each(function(i, elem) {
data = _this.data ? _this.data[i] : null;
node = $(elem);
return _this.editor_for_node(node, data);
});
}
Editor.prototype.editor_for_node = function(node, data) {
return console.log('hello!');
};
return Editor;
})();
return {
'Editor': Editor
};
});
}).call(this);
First: Which version of CoffeeScript are you using? The fat arrow has been a source of bugs in certain previous releases.
If you're using the latest (1.3.1), then I'm going to go ahead and say that this is an indentation issue. When I copy and paste your code, it works fine. Are you mixing tabs and spaces? Verify that the compiled output contains the line
Editor.prototype.editor_for_node = ...
Update: See the comments on this answer. Turns out the problem was that the new keyword wasn't being used when invoking the constructor.

How to find orphan plugins in eclipse RCPs?

Update sites with RCPs prohibits orphan plugins, otherwise plugins that are not in a feature.
If this condition is not filled, the update manager returns the following error:
Resulting configuration does not contain the platform.
Unfortunately, no way to determine which plugins are orphan.
How to find orphan plugins ?
Here's a starting point (this applies for Eclipse 3.4 and later, when the P2 repository was introduced, earlier versions store their configuration differently. IIRC you could see all the plugins and features in platform.xml).
Create a new plugin project (New->Other->Plug-in Development->Plug-in Project) with the "Hello World" template then drop this code into the run method of the SampleAction.
Run the plugin as a test Eclipse Application and select Sample Menu->Sample Action, the plugins that don't belong to a feature will be output to the parent workspace's console. When I ran this there were quite a few more than I expected, I've had a few looks through and can't spot the logic error.
Edit, found logic error, was using the wrong array index used in innermost loop. Still not quite right though.
Edit 2. (Facepalm moment) Found the problem. Be sure to run the target workspace with all workspace and enabled target plugins enabled, or it will skew your results, obviously. If you install the plugin and dress it up a little bit you won't have this problem.
//get all the plugins that belong to features
IBundleGroupProvider[] providers = Platform.getBundleGroupProviders();
Map<Long, IBundleGroup> bundlesMap = new HashMap<Long, IBundleGroup>();
if (providers != null) {
for (int i = 0; i < providers.length; i++) {
IBundleGroup[] bundleGroups = providers[i].getBundleGroups();
System.out.println("Bundle groups:");
for (int j = 0; j < bundleGroups.length; j++) {
Bundle[] bundles = bundleGroups[j] == null ? new Bundle[0] : bundleGroups[j]
.getBundles();
System.out.println(bundleGroups[j].getIdentifier());
for (int k = 0; k < bundles.length; k++) {
bundlesMap.put(bundles[k].getBundleId(), bundleGroups[j]);
}
}
}
}
BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext();
if(bundleContext instanceof BundleContextImpl) {
Bundle[] bundles = ((BundleContextImpl)bundleContext).getBundles();
System.out.println("Orphan Bundles:");
for (int i = 0; i < bundles.length; i++) {
if(!bundlesMap.containsKey(bundles[i].getBundleId())) {
System.out.println(bundles[i].getSymbolicName());
}
}
}