NodeJS addon can just be executed with self compiled nodeJS - c++

I tried some work on compiling some C++/CLI NodeJS addons.
For example, I wanted to read from Windows Event logs.
At first, I compiled nodeJS to get the node.lib file. Basicly, I followed the steps mentioned in this document: http://coderesearchlabs.com/articles/BNWCA.pdf
I set up an VisualStudio Project with include and library paths pointing to the compiled node 0.10.28 directories.
In this project I made use of the System::Diagnostics::EventLog class: http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.eventlog
After finishing my C++ project, I compiled it successfully and could use it with the node.exe from the first step.
Now, I tried to use my "EventReader.node" file on an other machine. But I couldn't require the node file:
Error: no error
This is the error I got after requiring the node-file.
Some hints:
Both machines run Windows 7 Professional
NodeJS version I self compiled: 0.10.28 src
NodeJS version I tried to run my addon with: 0.10.28 msi
Edit:
After using node-gyp, I need to set my references in the vxproj-file. In special these ones:
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
But how do I add these with the gyp-file?

Related

setting up TypeScript unit tests with Mocha

I am trying to organize a new typescript project that has unit tests, also written in TS, running in the Mocha test runner.
My project with the following directory convention:
/project/src/ for server-side code (java)
/project/test/ server's tests
/project/resources/ client-side code (typescript)
/project/test-resources/ typescript tests.
right now I have a typescript module Schema in a typescript file located at resources/many/levels/schema.ts
and I have its test, written for the mocha test runner, in a typescript file:
test-resources/many/levels/schemaTest.ts
The problem is that the typescript compiler can't find the schema module using the following import syntaxes:
TC2307 Can't find module schema
schemaTest.ts (version 1):
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
/// <reference path="../../../resources/many/levels/schema.ts" />
import s = require('schema');
schemaTest.ts (version 2):
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
/// <reference path="../../../resources/many/levels/schema.ts" />
import {Schema, SchemaFactory} from 'schema';
finally, the following version compiles but leads to a runtime error since the module is not at ../../../resources/many/level but instead is located in the dist directory
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
/// <reference path="../../../resources/many/levels/schema.ts" />
import {Schema, SchemaFactory} from '../../../resources/many/levels/schema';
schema.ts:
module Schema {
export interface Schema {
getName() : string;
getColumnByIndex(index : number) : Column;
getColumnById(id : string) : Column;
getNumberOfColumns(): number;
}
export class SchemaFactory{
...
build() : Schema {...}
}
}
I am compiling both my test and src files to a single dist directory (not ideal) and hope to run tests from there.
I am compiling with the flag --module commonjs.
if it matters, I am using IntelliJ 15 / WebStorm (and using its plugings for mocha, node, and tsc)
Is my Schema module set up incorrectly? Should it be an internal/external module? Should my tests be in the same namespace?
Thanks in advance!
I have been through these problems when I was setting up my jasmine tests but fundamentally the concepts are the same. The problem stems from the fact that while the relative path reference is specified based on the locations of the .ts files, that relative path reference is not maintained when the code is compiled over to the dist location. Below is how I got past that issue.
Separate the compilation of scripts and specs into two different tasks. I am using gulp tasks for my build process but if you are not using gulp, you can still achieve this by having a separate tsconfig.json, one in resources folder for your source code compilation and another tsconfig.json in your resources-test folder for your test scripts compilation. Basically that would logically separate your source code and test scripts as two different typescript projects.
For the typescript compilation of your source code, use the declaration compiler option set to true so that you get a schema.d.ts file. This file is going to be referenced in your schemaTest.ts. To make things super easy, have a build step that when source is compiled, copy over the .d.ts and .js files generated from the source compilation to a specific folder in the test-resources folder (lets say test-resources/compiledsource). The compiledsource folder will in this case have schema.d.ts and schema.js files.
The import statement in your test scripts (schematests.ts) will import from the compiledsource folder as below
import {Schema, SchemaFactory} from './compiledsource/schema';
Your source compilation and test scripts compilation should be done in two steps and the first step would be source compilation so that when your test scripts compile, you have the schema.d.ts available in the compiledsource folder, and when your tests run the schema.js will be available in compiledsource folder.
When typescript interprets "import" statement, it will look for the
.ts or .d.ts file and when it is compiled to javascript require
statement, it will look for the .js file.

How to use the Web Publishing Pipeline and Web Deploy (MSDEPLOY) to Publish a Console Application?

I would like to use web deploy to publish a Visual Studio "Console" application to a folder on the target system.
I have had some luck, and have been able to produce something similar to what I need, but not quite.
I've added the following to the console .csproj:
added the following projectName.wpp.targets file
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
and I've added the following projectName.wpp.targets:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<DeployAsIisApp>false</DeployAsIisApp>
<IncludeSetAclProviderOnDestination>false</IncludeSetAclProviderOnDestination>
</PropertyGroup>
<ItemGroup>
<FilesForPackagingFromProject Include="$(IntermediateOutputPath)$(TargetFileName).config">
<DestinationRelativePath>bin\%(RecursiveDir)%(FileName)%(Extension)</DestinationRelativePath>
<FromTarget>projectName.wpp.targets</FromTarget>
</FilesForPackagingFromProject>
</ItemGroup>
</Project>
I then edit the .SetParameters.xml file as follows:
<parameters>
<setParameter name="IIS Web Application Name" value="c:\company\project" />
</parameters>
When I then deploy using the generated .cmd file, I get all the files deployed to C:\company\project\bin.
That's not bad, but I'd like to do better. In particular, I'd like to omit the "bin" folder and put all files in the "C:\company\project" folder, and I'd like to be able to specify the ACLs
Has anybody been able to work around these problems?
Ok, so here's the way how to omit the 'bin' folder.
First of all, I'd like to emphasize that all this msdeploy-related stuff is for web apps deployment, and 'bin' folder seems for me to be almost hardcoded deeply inside. So if you want to get rid of it - you have to do some dirty things. Which I did.
We'll have to change $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets project a little bit, so it's better to change not it, but it's copy.
Steps:
1.Backup $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(alternatively, you could install MSBuild.Microsoft.VisualStudio.Web.targets package, redirect your csproj file to Microsoft.WebApplication.targets file obtained from package and work with it).
2. In the $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplicaton.targets find the xml node which looks like <CopyPipelineFiles PipelineItems="#(FilesForPackagingFromProject)"(there are several ones of them, take the one from the line ~2570).
3. Comment the node out, replace with the custom one, so eventually it will look like:
<!--
<CopyPipelineFiles PipelineItems="#(FilesForPackagingFromProject)"
SourceDirectory="$(WebPublishPipelineProjectDirectory)"
TargetDirectory="$(WPPAllFilesInSingleFolder)"
SkipMetadataExcludeTrueItems="True"
UpdateItemSpec="True"
DeleteItemsMarkAsExcludeTrue ="True"
Condition="'#(FilesForPackagingFromProject)' != ''">
<Output TaskParameter="ResultPipelineItems" ItemName="_FilesForPackagingFromProjectTempory"/>
</CopyPipelineFiles>-->
<!-- Copying files to package folder in 'custom'(dirty) way -->
<CreateItem Include="$(OutputPath)\**\*.*">
<Output TaskParameter="Include" ItemName="YourFilesToCopy" />
</CreateItem>
<Copy SourceFiles="#(YourFilesToCopy)"
DestinationFiles="#(YourFilesToCopy->'$(WPPAllFilesInSingleFolder)\%(RecursiveDir)%(Filename)%(Extension)')" />
Then
4. Your projectName.wpp.targets don't have to have FilesForPackagingFromProject, so it will look like:
<!-- targets -->
<PropertyGroup>
<DeployAsIisApp>false</DeployAsIisApp>
<IncludeSetAclProviderOnDestination>false</IncludeSetAclProviderOnDestination>
</PropertyGroup>
<ItemGroup>
<!-- intentionally left blank -->
</ItemGroup>
</Project>
That's it. Worked for me(tm), tested. Let me be honest, I don't like this approach, but that was the only way I made it working in the needed way. It's up to you whether you'll use it in your project or not.
My opinion is not to use msdeploy here - it was not for you task.
Better to write msbuild-scripts from scratch or accept the 'bin' folder, and fight against the framework again once next customization is required.

Running unit tests for typescript in VS

I've found couple of examples of running unit tests for typescript.
All of them are based on referencing both ts and js file like
/// <reference path="../Calc.ts" />
/// <reference path="../Calc.js" />
Unfortunately when I try to reference js file I am getting the following error:
Incorrect reference: referenced file: "../Calc.js" cannot be resolved.
If there is no reference test runner doesn't load js file under test and test fails to execute.
Any ideas? Ideally I want to run tests in VS test explorer or Resharper test session.
You can use Chutzpah for that
With Chutzpah you can run your tests from command line and integrate your tests with Visual Studio Test Explorer.
Chutzpah allows you decide if you want to run the tests from .ts files, .js files, .html files or from all of them.
It also allows you to load external .js files (e.g. dependent libraries) from your .ts unit test file, with its specific :
/// <chutzpah_reference path="lib/jquery-1.9.1.min.js" />
/// <reference path="src/YourFileToBeTested.ts" />
Your unit tests can be written in TypeScript.
You can install Chutzpah from Visual Studio/Tools/Extensions and updates.
There is absolutely no reason to include a reference to a JS file :
/// <reference path="../Calc.js" />
The use for /// <reference is to provide the compiler with information about type info present in another file. It has no runtime implications, only compile time implications. And all the compile time implications (typeinfo, code generation) are taken into account when you did:
/// <reference path="../Calc.ts" />

Msbuild resolve project reference to custom project type

I've created a custom project type (cljproj instead of csproj) for a programming language called clojure. When the project compiles it outputs multiple .dll files as well as some dependent .clj files.
This is done by overriding the default CoreCompile target in the cljproj file. Which basically copies all files needing compilation to the bin directory and then executes a separate app to compile them.
<Target Name="CoreCompile">
<PropertyGroup>
<ClojureNamespaces>#(Compile -> '%(RelativeDir)%(Filename)', ' ')</ClojureNamespaces>
</PropertyGroup>
<Copy SourceFiles="#(Compile)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" DestinationFiles="#(Compile -> '$(OutDir)%(RelativeDir)%(Filename)%(Extension)')" />
<Exec WorkingDirectory="$(OutDir)" Command=""$(ClojureRuntimesDirectory)\$(ClojureVersion)\Clojure.Compile" $(ClojureNamespaces.Replace('\', '.'))" />
</Target>
I've added a reference from a c# project (csproj) to my clojure project (cljproj).
<ProjectReference Include="..\Clojure ASP.Net MVC Controller Library1\Clojure ASP.Net MVC Controller Library1.cljproj">
<Project>{8fe1995b-4b6d-4911-b563-a759467fdf53}</Project>
<Name>Clojure ASP.Net MVC Controller Library1</Name>
</ProjectReference>
Visual Studio by default doesn't resolve the project reference correctly, because it assumes there will only be one output, Clojure ASP.Net MVC Controller Library1.dll.
Examples of the actual output files are MvcApplication1.Controllers.HomeController.dll and HomeController.clj
I'd like to make this work without making any changes to the C# .csproj file, so that a .cljproj can easily be referenced from any .csproj file.
My attempt to resolve the project reference is by overriding the GetTargetPath target.
<Target Name="GetTargetPath" DependsOnTargets="$(GetTargetPathDependsOn)" Returns="#(TargetPath)">
<ItemGroup>
<TargetPath Include="$(TargetDir)\**\*.dll" />
<!-- <TargetPath Include="$(TargetDir)\**\*.clj" /> -->
</ItemGroup>
</Target>
If I set the TargetPath using *.dll, it works and copies the .dll files to the c#.csproj output directory. It even copies the .pdb files to that directory, although I didn't add them to the TargetPath. However, if I uncomment the *.clj TargetPath, CSC complains that the .clj files are corrupt (probably because they are plain text, not .net assemblies).
I'm happy to use a copy command instead of overriding TargetPath, however I'm not sure which variable to use for the directory to output them to, because $(outdir) gives me the bin of my custom project (.cljproj) not the bin of the c# project trying to resolve the project reference (.csproj). I'm not sure what other target to override besides GetTargetPath, because most clojure project (.cljproj) targets are not called when compiling the c# (.csjproj) project, for example: .cljproj:AfterBuild is only called when compiling cljproj directly, not when compiling .csproj which has a project reference to .cljproj.
I was able to get it to work by overriding the GetCopyToOutputDirectoryItems Target.
<Target Name="GetCopyToOutputDirectoryItems" Returns="#(CopyToOutputDirectoryItemsWithTargetPath)">
<ItemGroup>
<CopyToOutputDirectoryItems Include="$(TargetDir)\**\*.clj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</CopyToOutputDirectoryItems>
</ItemGroup>
<AssignTargetPath Files="#(CopyToOutputDirectoryItems)" RootFolder="$(TargetDir)">
<Output TaskParameter="AssignedFiles" ItemName="CopyToOutputDirectoryItemsWithTargetPath" />
</AssignTargetPath>
</Target>

VS 2010 pre-compile web sites with build process?

VS 2010; TFS 2010; ASP.Net 4.0; Web Deployment Projects 2010;
I am using the build process templates in order to do one-click deploys (for dev and QA only). I want my sites to be pre-compiled. I can do it with the command line, using:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler
-v /site_name
-p "C:\...\site_name"
-f "C:\...\site_name1"
and this works fine if I copy the files over from site_name1 to site_name...
but is there an option in the IDE for this?? It seems really silly to have to do this from the command line. I've read a lot about different options, but none seem applicable to building with the build definitions.
You can do this by adding the following to your .csproj file
<PropertyGroup>
<PrecompileVirtualPath>/whatever</PrecompileVirtualPath>
<PrecompilePhysicalPath>.</PrecompilePhysicalPath>
<PrecompileTargetPath>..\precompiled</PrecompileTargetPath>
<PrecompileForce>true</PrecompileForce>
<PrecompileUpdateable>false</PrecompileUpdateable>
</PropertyGroup>
<Target Name="PrecompileWeb" DependsOnTargets="Build">
<Message Importance="high" Text="Precompiling to $(PrecompileTargetPath)" />
<GetFullPath path="$(PrecompileTargetPath)">
<Output TaskParameter="fullPath" PropertyName="PrecompileTargetFullPath" />
</GetFullPath>
<Message Importance="high" Text="Precompiling to fullpath: $(PrecompileTargetFullPath)" />
<GetFullPath path="$(PrecompilePhysicalPath)">
<Output TaskParameter="fullPath" PropertyName="PrecompilePhysicalFullPath" />
</GetFullPath>
<Message Importance="high" Text="Precompiling from fullpath: $(PrecompilePhysicalFullPath)" />
<AspNetCompiler PhysicalPath="$(PrecompilePhysicalPath)" VirtualPath="$(PrecompileVirtualPath)" TargetPath="$(PrecompileTargetPath)" Debug="true" Force="$(PrecompileForce)" Updateable="$(PrecompileUpdateable)" FixedNames="true" />
Then in TFS2010's default template
your build definition
Process tab
Advanced parameters section
MSBuild Arguments
set /target="PrecompileWeb"
As it currently stands, I can not find any IDE option to pre-compile websites using the build process templates. I would love to be proved wrong, as using the command line aspnet_compiler requires us (in our setup) to crack open the actual build process template, which we are trying to avoid.
I would love to be proved wrong! :)
We have a website that is stored in TFS2010 as a Web application. I use a MSBuild command to deploy from TFS2010. If you open your project in VS2010 Team Explorer you will see there is a "Builds" option. If you add a build and in the process tab use a build argument like ...:/p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:CreatePackageOnPublish=True /p:MSDeployPublishMethod=RemoteAgent /p:MSDeployServiceUrl=http://111.111.111.111/msdeployagentservice /p:DeployIisAppPath=MySiteNameInIIS /p:UserName=myDomain\BuildUser /p:Password=BuildUserPassword In the Process tab where it says "Items to Build" you just point it to your .sln file (might work with a .cspro but then the syntax changes slightly)
We have a TFS2010 server and I deploy a few of our sites to a dev, qa, pre-production or production IIS server. I do unit testing on the dev build and if the test fail then I do not deploy.
The MSBuild command does the pre-compile, would that work for you?
A setting for precompiling has been added. The following works in Visual Studio 2015
Open a solution
Right click on the project
Select "Publish..."
Go to settings, expand "File
Check "Precompile during Publishing"