Formalize module development depending on 'napajs' (#38)

* ts and package part

* reactive hello module

* reactive module example of aync-number

* module example of plus-nubmer

* 1. refer napajs@0.1.0 in example modules; 2. fix build dependencies for plus-number module

* 1.figure out NAPAJS_ROOT by require.resolve; 2.test cases by napa zones

* make gyp as default for hello-world and async-number

* re-orgnize source tree of module examples

* update readme 'how to build and run'

* cross platform setting to link a library in binding.gyp/CMakeLists.txt

* polish Readme

* resolve inc and lib of napajs for different platforms
This commit is contained in:
Allen Wang 2017-08-16 18:44:52 -07:00 коммит произвёл GitHub
Родитель 3211319d77
Коммит 5b1aa4fd78
58 изменённых файлов: 649 добавлений и 572 удалений

Просмотреть файл

@ -1,47 +1,31 @@
## Napa module source tree
The source codes can be organized as the structure below. This is different from npm package structure since npm
doesnt contain source tree until we figure it out how to compile Napa module from npm install. This example uses
msbuild as build system until napa team finds the good one for cross-platform.
The source codes can be organized as the structure below.
```
+-- napa-module-example
+-- inc
| +-- example.h
+-- src
| +-- example.cpp
| +-- example.vcxproj
+-- node
| +-- addon.h
| +-- addon.cpp
| +-- addon.vcxproj
+-- napa
| +-- addon.vcxproj
+-- script
| +-- src
| | +-- example.ts
| +-- package.json
| +-- script.vcxproj
+-- lib
| +-- example.ts
| +-- tsconfig.json
+-- test
| +-- example-test.njsproj
| +-- test.ts
+-- README.md
```
## Napa MPM tree
This is the simple NPM package structure, which has module binaries directly. Once Napa team figure out the build system
under *npm install*, this will be changed to support cross-platform build and test.
```
+-- napa-module-example
+-- bin
| +-- addon.napa
| +-- addon.node
+-- lib
| +-- example.js
+-- types
| +-- example.d.ts
| +-- tsconfig.json
+-- binding.gyp (when build configuration is given in node-gyp)
+-- CMakeLists.txt (when build configuration is given in cmake-js)
+-- package.json
+-- tsconfig.json
+-- README.md
```
```
## How to build and test ?
For the module examples, node-gyp or cmake-js build solution is provided for your reference.
Please make sure [node-gyp](https://github.com/nodejs/node-gyp#installation) or [cmake-js](https://github.com/cmake-js/cmake-js#installation) has been set up correctly at your client, then you could follow the below steps to build and test the module examples.
```
1. go to the directory of a module example
2. run "npm install" to build the module
3. run "npm test" to build and run the module test, as well as its unittest if any
```

12
examples/modules/async-number/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,12 @@
bin
build
node_modules
types
# ignore all js files under lib
lib/*.js
# ignore all js files under test
test/*.js
package-lock.json

Просмотреть файл

@ -0,0 +1,8 @@
bin
build
# Exclude TypeScript source files.
lib/*.ts
lib/tsconfig.json
test/*.ts
test/tsconfig.json

Просмотреть файл

@ -0,0 +1,53 @@
{
"variables": {
"napajs_root": "<!(node -e \" \
var path = require('path'); \
process.stdout.write(path.resolve(path.dirname(require.resolve('napajs')), '..')); \
\")",
'conditions': [
['OS=="win"', {
"library_prefix": "",
"library_suffix": ".lib"
}],
['OS=="linux"', {
"library_prefix": "lib",
"library_suffix": ".dylib"
}],
['OS=="max"', {
"library_prefix": "lib",
"library_suffix": ".so"
}]
]
},
"targets": [
{
"target_name": "addon.node",
"type": "<(library)",
"product_extension": "",
"product_dir": "<(PRODUCT_DIR)/../../bin",
"sources": [ "src/addon.cpp"],
"defines": [
"NAPA_BINDING_EXPORTS",
"BUILDING_NODE_EXTENSION"
],
"include_dirs": ["<(napajs_root)/inc"]
},
{
"target_name": "addon.napa",
"type": "<(library)",
"product_extension": "",
"product_dir": "<(PRODUCT_DIR)/../../bin",
"sources": [ "src/addon.cpp" ],
"defines": [
"NAPA_EXPORTS",
"NAPA_BINDING_EXPORTS",
"BUILDING_NAPA_EXTENSION"
],
"include_dirs": ["<(napajs_root)/inc"],
"link_settings": {
"libraries": ["<(napajs_root)/bin/<(library_prefix)napa<(library_suffix)"]
}
}
]
}

Просмотреть файл

@ -1,12 +0,0 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<ItemGroup>
<ProjectFile Include="napa\addon.vcxproj" />
<ProjectFile Include="node\addon.vcxproj" />
<ProjectFile Include="script\script.proj" />
<ProjectFile Include="test\async-number-test.njsproj" />
</ItemGroup>
<Import Project="$(ExtendedTargetsPath)\Traversal.targets" />
</Project>

Просмотреть файл

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var addon = require('../bin/addon');
let addon = require('../bin/addon');
export function increase(value: number, callback: (now: number) => void) {
return addon.increase(value, callback);

Просмотреть файл

@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": true,
"declaration": true,
"sourceMap": false,
"lib": ["es2015"],
"declarationDir": "../types"
}
}

Просмотреть файл

@ -1,6 +0,0 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AddonType>Napa</AddonType>
</PropertyGroup>
<Import Project="..\node\addon.vcxproj" />
</Project>

Просмотреть файл

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.Default.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup>
<AddonName>addon</AddonName>
<TargetName Condition=" '$(AddonType)' != 'Napa' ">$(AddonName)</TargetName>
<TargetName Condition=" '$(AddonType)' == 'Napa' ">$(AddonName)_napa</TargetName>
</PropertyGroup>
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.props" />
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions Condition=" '$(AddonType)' != 'Napa' ">BUILDING_NODE_EXTENSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition=" '$(AddonType)' == 'Napa' ">BUILDING_NAPA_EXTENSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(NapaVanillaRoot)\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies Condition=" '$(AddonType)' == 'Napa' ">$(NapaVanillaRoot)\src\$(IntermediateOutputPath)\napa.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)\addon.cpp" />
</ItemGroup>
<Target Name="ChangeExtention" AfterTargets="Build">
<Move SourceFiles="$(OutputPath)\$(TargetFileName)" DestinationFiles="$(OutputPath)\$(AddonName).node" Condition=" '$(AddonType)' != 'Napa' " />
<Move SourceFiles="$(OutputPath)\$(TargetFileName)" DestinationFiles="$(OutputPath)\$(AddonName).napa" Condition=" '$(AddonType)' == 'Napa' " />
</Target>
<Import Project="$(Pkgnapa_nodelib_vc140)\exports_node.props" Condition=" '$(AddonType)' != 'Napa' " />
<Import Project="$(Pkgnapa_nodelib_vc140)\exports_v8_includes.props" Condition=" '$(AddonType)' == 'Napa' " />
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,26 @@
{
"name": "async-number",
"version": "0.1.0",
"author": "napajs",
"description": "Example of an async napa module.",
"main": "./lib/async-number.js",
"types": "./types/async-number.d.ts",
"gypfile": true,
"license": "MIT",
"devDependencies": {
"mocha": ">= 3.4.2",
"typescript": ">= 2.2.1",
"@types/node": ">= 7.0.8",
"@types/mocha": ">= 2.2.0",
"markdown-table": "1.1.0"
},
"dependencies": {
"napajs": ">= 0.1.0"
},
"scripts": {
"install": "node-gyp configure && node-gyp build",
"prepare": "tsc -p lib",
"pretest": "tsc -p test",
"test": "mocha test --recursive"
}
}

Просмотреть файл

@ -1,8 +0,0 @@
{
"name": "async-number",
"version": "0.0.1",
"author": "napav",
"description": "Example of an async napa module.",
"main": "./lib/async-number.js",
"types": "./types/async-number.d.ts"
}

Просмотреть файл

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<ItemGroup>
<QCustomProjectReference Include="$(NapaVanillaRoot)\examples\modules\async-number\napa\addon.vcxproj" />
<QCustomProjectReference Include="$(NapaVanillaRoot)\examples\modules\async-number\node\addon.vcxproj" />
</ItemGroup>
<ItemGroup>
<QCustomInput Include="src\async-number.ts" />
<QCustomInput Include="$(NapaBuildRoot)\**\*" />
</ItemGroup>
<Target Name="BuildScripts" AfterTargets="AfterBuild">
<Message Text="Compile scripts." />
<Exec Command="$(TSCompile) src\async-number.ts --declaration --typeRoots $(TypesRoot) --outDir $(O)" />
</Target>
<Target Name="CreateNpmPackage" DependsOnTargets="BuildScripts" AfterTargets="AfterBuild">
<Message Text="Create NPM package." />
<MakeDir Directories="$(O)\dist\bin" ContinueOnError="false" Condition="!Exists('$(O)\dist\bin')" />
<MakeDir Directories="$(O)\dist\lib" ContinueOnError="false" Condition="!Exists('$(O)\dist\lib')" />
<MakeDir Directories="$(O)\dist\types" ContinueOnError="false" Condition="!Exists('$(O)\dist\types')" />
<Copy SourceFiles="..\node\$(O)\addon.node" DestinationFolder="$(O)\dist\bin" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="..\napa\$(O)\addon.napa" DestinationFolder="$(O)\dist\bin" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(O)\async-number.js" DestinationFolder="$(O)\dist\lib" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(O)\async-number.d.ts" DestinationFolder="$(O)\dist\types" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="package.json" DestinationFolder="$(O)\dist" ContinueOnError="false" SkipUnchangedFiles="true" />
</Target>
<Import Project="$(ExtendedTargetsPath)\NoTarget.targets" />
</Project>

Просмотреть файл

@ -1,2 +0,0 @@
build/
tsconfig.json

Просмотреть файл

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<PropertyGroup>
<AssemblyName>async-number-test</AssemblyName>
</PropertyGroup>
<!-- Test files -->
<!-- It's using the default tsconfig.json@Napa.DevTools -->
<ItemGroup>
<TypeScriptCompile Include="test.ts" />
</ItemGroup>
<Import Project="$(PkgNapa_DevTools)\Napa.TestAdapter.targets" />
<ItemGroup>
<Robocopy Include="..\script\$(IntermediateOutputPath)\dist">
<DestinationFolder>$(QTestDirToDeploy)\app\node_modules\async-number</DestinationFolder>
</Robocopy>
</ItemGroup>
</Project>

Просмотреть файл

@ -1,11 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var assert = require('assert');
var asyncNumber = require('async-number');
let assert = require('assert');
import * as path from "path";
let asyncNumberDir: string = path.resolve(__dirname, '..');
let asyncNumber = require(asyncNumberDir);
let napa = require('napajs');
let zone = napa.zone.create('zone');
describe('Test suite for async-number', function() {
it('change number asynchronously on separate thread', (done: () => void) => {
this.timeout(0);
it('change number asynchronously on separate thread', () => {
let now = asyncNumber.now();
assert.equal(now, 0);
@ -15,31 +21,69 @@ describe('Test suite for async-number', function() {
now = asyncNumber.now();
assert.equal(now, 6);
done();
});
asyncNumber.increaseSync(3, (value: number) => {} );
});
it('change number synchronously on current thread', (done: () => void) => {
it('change number synchronously on current thread', () => {
let now = asyncNumber.now();
assert.equal(now, 0);
assert.equal(now, 6);
asyncNumber.increaseSync(3, (value: number) => {
// This must be called after the last statement of *it* block is executed.
assert.equal(value, 3);
assert.equal(value, 9);
now = asyncNumber.now();
assert.equal(now, 6);
done();
assert.equal(now, 12);
});
now = asyncNumber.now();
// 'now' should be 3.
assert.equal(now, 3);
// 'now' should be 9.
assert.equal(now, 9);
asyncNumber.increaseSync(3, (value: number) => {} );
});
it('change number asynchronously on separate thread in napa zone', () => {
return zone.execute((asyncNumberDir: string) => {
let assert = require('assert');
let asyncNumber = require(asyncNumberDir);
let now = asyncNumber.now();
assert.equal(now, 0);
asyncNumber.increase(3, (value: number) => {
// This must be called after the last statement of *it* block is executed.
assert(value == 3 || value == 6);
now = asyncNumber.now();
assert.equal(now, 6);
});
asyncNumber.increaseSync(3, (value: number) => {} );
}, [asyncNumberDir]);
});
it('change number synchronously on current thread in napa zone', () => {
zone.execute((asyncNumberDir: string) => {
let assert = require('assert');
let asyncNumber = require(asyncNumberDir);
let now = asyncNumber.now();
assert.equal(now, 0);
asyncNumber.increaseSync(3, (value: number) => {
// This must be called after the last statement of *it* block is executed.
assert.equal(value, 3);
now = asyncNumber.now();
assert.equal(now, 6);
});
now = asyncNumber.now();
// 'now' should be 3.
assert.equal(now, 3);
asyncNumber.increaseSync(3, (value: number) => {} );
return 1;
}, [asyncNumberDir]);
});
})

Просмотреть файл

@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": true,
"declaration": false,
"sourceMap": false,
"lib": ["es2015"]
}
}

Просмотреть файл

@ -1,11 +0,0 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<ItemGroup>
<ProjectFile Include="async-number\dirs.proj" />
<ProjectFile Include="hello-world\dirs.proj" />
<ProjectFile Include="plus-number\dirs.proj" />
</ItemGroup>
<Import Project="$(ExtendedTargetsPath)\Traversal.targets" />
</Project>

12
examples/modules/hello-world/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,12 @@
bin
build
node_modules
types
# ignore all js files under lib
lib/*.js
# ignore all js files under test
test/*.js
package-lock.json

Просмотреть файл

@ -0,0 +1,8 @@
bin
build
# Exclude TypeScript source files.
lib/*.ts
lib/tsconfig.json
test/*.ts
test/tsconfig.json

Просмотреть файл

@ -0,0 +1,52 @@
{
"variables": {
"napajs_root": "<!(node -e \" \
var path = require('path'); \
process.stdout.write(path.resolve(path.dirname(require.resolve('napajs')), '..')); \
\")",
'conditions': [
['OS=="win"', {
"library_prefix": "",
"library_suffix": ".lib"
}],
['OS=="linux"', {
"library_prefix": "lib",
"library_suffix": ".dylib"
}],
['OS=="max"', {
"library_prefix": "lib",
"library_suffix": ".so"
}]
]
},
"targets": [
{
"target_name": "addon.node",
"type": "<(library)",
"product_extension": "",
"product_dir": "<(PRODUCT_DIR)/../../bin",
"sources": [ "src/addon.cpp"],
"defines": [
"NAPA_BINDING_EXPORTS",
"BUILDING_NODE_EXTENSION"
],
"include_dirs": ["<(napajs_root)/inc"]
},
{
"target_name": "addon.napa",
"type": "<(library)",
"product_extension": "",
"product_dir": "<(PRODUCT_DIR)/../../bin",
"sources": [ "src/addon.cpp" ],
"defines": [
"NAPA_EXPORTS",
"NAPA_BINDING_EXPORTS",
"BUILDING_NAPA_EXTENSION"
],
"include_dirs": ["<(napajs_root)/inc"],
"link_settings": {
"libraries": ["<(napajs_root)/bin/<(library_prefix)napa<(library_suffix)"]
}
}
]
}

Просмотреть файл

@ -1,12 +0,0 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<ItemGroup>
<ProjectFile Include="napa\addon.vcxproj" />
<ProjectFile Include="node\addon.vcxproj" />
<ProjectFile Include="script\script.proj" />
<ProjectFile Include="test\hello-world-test.njsproj" />
</ItemGroup>
<Import Project="$(ExtendedTargetsPath)\Traversal.targets" />
</Project>

Просмотреть файл

@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var addon = require('../bin/addon');
let addon = require('../bin/addon');
export function hello(): string {
return addon.hello();
}
}

Просмотреть файл

@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": true,
"declaration": true,
"sourceMap": false,
"lib": ["es2015"],
"declarationDir": "../types"
}
}

Просмотреть файл

@ -1,6 +0,0 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AddonType>Napa</AddonType>
</PropertyGroup>
<Import Project="..\node\addon.vcxproj" />
</Project>

Просмотреть файл

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.Default.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup>
<AddonName>addon</AddonName>
<TargetName Condition=" '$(AddonType)' != 'Napa' ">$(AddonName)</TargetName>
<TargetName Condition=" '$(AddonType)' == 'Napa' ">$(AddonName)_napa</TargetName>
</PropertyGroup>
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.props" />
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions Condition=" '$(AddonType)' != 'Napa' ">BUILDING_NODE_EXTENSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition=" '$(AddonType)' == 'Napa' ">BUILDING_NAPA_EXTENSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(NapaVanillaRoot)\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies Condition=" '$(AddonType)' == 'Napa' ">$(NapaVanillaRoot)\src\$(IntermediateOutputPath)\napa.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)\addon.cpp" />
</ItemGroup>
<Target Name="ChangeExtention" AfterTargets="Build">
<Move SourceFiles="$(OutputPath)\$(TargetFileName)" DestinationFiles="$(OutputPath)\$(AddonName).node" Condition=" '$(AddonType)' != 'Napa' " />
<Move SourceFiles="$(OutputPath)\$(TargetFileName)" DestinationFiles="$(OutputPath)\$(AddonName).napa" Condition=" '$(AddonType)' == 'Napa' " />
</Target>
<Import Project="$(Pkgnapa_nodelib_vc140)\exports_node.props" Condition=" '$(AddonType)' != 'Napa' " />
<Import Project="$(Pkgnapa_nodelib_vc140)\exports_v8_includes.props" Condition=" '$(AddonType)' == 'Napa' " />
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,26 @@
{
"name": "hello-world",
"version": "0.1.0",
"author": "napajs",
"description": "Example of a simple napa module.",
"main": "./lib/hello-world.js",
"types": "./types/hello-world.d.ts",
"gypfile": true,
"license": "MIT",
"devDependencies": {
"mocha": ">= 3.4.2",
"typescript": ">= 2.2.1",
"@types/node": ">= 7.0.8",
"@types/mocha": ">= 2.2.0",
"markdown-table": "1.1.0"
},
"dependencies": {
"napajs": ">= 0.1.0"
},
"scripts": {
"install": "node-gyp configure && node-gyp build",
"prepare": "tsc -p lib",
"pretest": "tsc -p test",
"test": "mocha test --recursive"
}
}

Просмотреть файл

@ -1,8 +0,0 @@
{
"name": "hello-world",
"version": "0.0.1",
"author": "napav",
"description": "Example of a simple napa module.",
"main": "./lib/hello-world.js",
"types": "./types/hello-world.d.ts"
}

Просмотреть файл

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<ItemGroup>
<QCustomProjectReference Include="$(NapaVanillaRoot)\examples\modules\hello-world\napa\addon.vcxproj" />
<QCustomProjectReference Include="$(NapaVanillaRoot)\examples\modules\hello-world\node\addon.vcxproj" />
</ItemGroup>
<ItemGroup>
<QCustomInput Include="src\hello-world.ts" />
<QCustomInput Include="$(NapaBuildRoot)\**\*" />
</ItemGroup>
<Target Name="BuildScripts" AfterTargets="AfterBuild">
<Message Text="Compile scripts." />
<Exec Command="$(TSCompile) src\hello-world.ts --declaration --typeRoots $(TypesRoot) --outDir $(O)" />
</Target>
<Target Name="CreateNpmPackage" DependsOnTargets="BuildScripts" AfterTargets="AfterBuild">
<Message Text="Create NPM package." />
<MakeDir Directories="$(O)\dist\bin" ContinueOnError="false" Condition="!Exists('$(O)\dist\bin')" />
<MakeDir Directories="$(O)\dist\lib" ContinueOnError="false" Condition="!Exists('$(O)\dist\lib')" />
<MakeDir Directories="$(O)\dist\types" ContinueOnError="false" Condition="!Exists('$(O)\dist\types')" />
<Copy SourceFiles="..\node\$(O)\addon.node" DestinationFolder="$(O)\dist\bin" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="..\napa\$(O)\addon.napa" DestinationFolder="$(O)\dist\bin" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(O)\hello-world.js" DestinationFolder="$(O)\dist\lib" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(O)\hello-world.d.ts" DestinationFolder="$(O)\dist\types" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="package.json" DestinationFolder="$(O)\dist" ContinueOnError="false" SkipUnchangedFiles="true" />
</Target>
<Import Project="$(ExtendedTargetsPath)\NoTarget.targets" />
</Project>

Просмотреть файл

@ -1,2 +0,0 @@
build/
tsconfig.json

Просмотреть файл

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<PropertyGroup>
<AssemblyName>hello-world-test</AssemblyName>
</PropertyGroup>
<!-- Test files -->
<!-- It's using the default tsconfig.json@Napa.DevTools -->
<ItemGroup>
<TypeScriptCompile Include="test.ts" />
</ItemGroup>
<Import Project="$(PkgNapa_DevTools)\Napa.TestAdapter.targets" />
<ItemGroup>
<Robocopy Include="..\script\$(IntermediateOutputPath)\dist">
<DestinationFolder>$(QTestDirToDeploy)\app\node_modules\hello-world</DestinationFolder>
</Robocopy>
</ItemGroup>
</Project>

Просмотреть файл

@ -1,12 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var assert = require('assert');
var helloWorld = require('hello-world');
let assert = require('assert');
import * as path from "path";
let helloWorldDir: string = path.resolve(__dirname, '..');
let helloWorld = require(helloWorldDir);
let napa = require('napajs');
let zone = napa.zone.create('zone');
describe('Test suite for hello-word', function() {
this.timeout(0);
it('prints the string "world"', function() {
var result: string = helloWorld.hello();
let result: string = helloWorld.hello();
assert.equal(result, 'world');
});
it('prints the string "world" in napa zone', function() {
return zone.execute((helloWorldDir: string) => {
let helloWorld = require(helloWorldDir);
let result: string = helloWorld.hello();
return result;
}, [helloWorldDir]).then((result : any) => {
assert.equal(result.value, 'world');
});
});
})

Просмотреть файл

@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": true,
"declaration": false,
"sourceMap": false,
"lib": ["es2015"]
}
}

12
examples/modules/plus-number/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,12 @@
bin
build
node_modules
types
# ignore all js files under lib
lib/*.js
# ignore all js files under test
test/*.js
package-lock.json

Просмотреть файл

@ -0,0 +1,9 @@
bin
build
unittest
# Exclude TypeScript source files.
lib/*.ts
lib/tsconfig.json
test/*.ts
test/tsconfig.json

Просмотреть файл

@ -0,0 +1,107 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project("addon")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/bin)
# Require Cxx14 features
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Set symbol visibility to hidden by default.
# Napa shared library shares a few classes with napa-binding.node with different compile definition,
# exposing the same symbols from both shared libraries may cause improper behaviors under gcc.
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN)
# Prefix an suffix of Library name for different OS.
if (WIN32)
set(LIBRARY_PREFIX "")
set(LIBRARY_SUFFIX ".lib")
elseif (APPLE)
set(LIBRARY_PREFIX "lib")
set(LIBRARY_SUFFIX ".dylib")
else()
set(LIBRARY_PREFIX "lib")
set(LIBRARY_SUFFIX ".so")
endif()
execute_process(COMMAND node -e
"var path = require('path'); process.stdout.write(path.resolve(path.dirname(require.resolve('napajs')), '..'));"
RESULT_VARIABLE ERR
OUTPUT_VARIABLE NAPAJS_ROOT)
if(ERR)
message(FATAL_ERROR "Failed to get NAPAJS_ROOT")
endif(ERR)
#######################################################################################
# Build plus-number library.
set(LIBRARY_TARGET_NAME "plus-number")
# The generated library
add_library(${LIBRARY_TARGET_NAME} SHARED "src/plus-number.cpp")
# Include directories
target_include_directories(${LIBRARY_TARGET_NAME} PRIVATE inc)
# Compiler definitions
target_compile_definitions(${LIBRARY_TARGET_NAME} PRIVATE NAPA_EXAMPLE_API)
#######################################################################################
# Build napa addon.
set(NAPA_ADDON_TARGET_NAME "${PROJECT_NAME}.napa")
# The generated library
add_library(${NAPA_ADDON_TARGET_NAME} SHARED "src/addon.cpp")
set_target_properties(${NAPA_ADDON_TARGET_NAME} PROPERTIES PREFIX "" SUFFIX "")
# Include directories
target_include_directories(${NAPA_ADDON_TARGET_NAME} PRIVATE
inc
${CMAKE_JS_INC}
${NAPAJS_ROOT}/inc)
# Compiler definitions
target_compile_definitions(${NAPA_ADDON_TARGET_NAME} PRIVATE
NAPA_EXPORTS
NAPA_BINDING_EXPORTS
BUILDING_NAPA_EXTENSION)
# Link libraries
target_link_libraries(${NAPA_ADDON_TARGET_NAME} PRIVATE
plus-number
${CMAKE_JS_LIB}
${NAPAJS_ROOT}/bin/${LIBRARY_PREFIX}napa${LIBRARY_SUFFIX})
#######################################################################################
if (CMAKE_JS_VERSION)
# Build napa addon for node.
set(NODE_ADDON_TARGET_NAME "${PROJECT_NAME}.node")
# The generated library
add_library(${NODE_ADDON_TARGET_NAME} SHARED "src/addon.cpp")
set_target_properties(${NODE_ADDON_TARGET_NAME} PROPERTIES PREFIX "" SUFFIX "")
# Include directories
target_include_directories(${NODE_ADDON_TARGET_NAME} PRIVATE
inc
${CMAKE_JS_INC}
${NAPAJS_ROOT}/inc)
# Compiler definitions
target_compile_definitions(${NODE_ADDON_TARGET_NAME} PRIVATE
NAPA_BINDING_EXPORTS
BUILDING_NODE_EXTENSION)
# Link libraries
target_link_libraries(${NODE_ADDON_TARGET_NAME} PRIVATE
plus-number
${CMAKE_JS_LIB})
endif()

Просмотреть файл

@ -1,13 +0,0 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<ItemGroup>
<ProjectFile Include="napa\addon.vcxproj" />
<ProjectFile Include="node\addon.vcxproj" />
<ProjectFile Include="script\script.proj" />
<ProjectFile Include="src\plus-number.vcxproj" />
<ProjectFile Include="test\dirs.proj" />
</ItemGroup>
<Import Project="$(ExtendedTargetsPath)\Traversal.targets" />
</Project>

Просмотреть файл

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var addon = require('../bin/addon');
let addon = require('../bin/addon');
export declare class PlusNumber {
public add(value: number): number;

Просмотреть файл

@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": true,
"declaration": true,
"sourceMap": false,
"lib": ["es2015"],
"declarationDir": "../types"
}
}

Просмотреть файл

@ -1,6 +0,0 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AddonType>Napa</AddonType>
</PropertyGroup>
<Import Project="..\node\addon.vcxproj" />
</Project>

Просмотреть файл

@ -1,53 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.Default.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup>
<AddonName>addon</AddonName>
<TargetName Condition=" '$(AddonType)' != 'Napa' ">$(AddonName)</TargetName>
<TargetName Condition=" '$(AddonType)' == 'Napa' ">$(AddonName)_napa</TargetName>
</PropertyGroup>
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.props" />
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions Condition=" '$(AddonType)' != 'Napa' ">BUILDING_NODE_EXTENSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition=" '$(AddonType)' == 'Napa' ">BUILDING_NAPA_EXTENSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(NapaVanillaRoot)\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(NapaVanillaRoot)\examples\modules\plus-number\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies Condition=" '$(AddonType)' == 'Napa' ">$(NapaVanillaRoot)\src\$(IntermediateOutputPath)\napa.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="$(NapaVanillaRoot)\examples\modules\plus-number\src\plus-number.vcxproj" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)\addon.cpp" />
</ItemGroup>
<Target Name="ChangeExtention" AfterTargets="Build">
<Move SourceFiles="$(OutputPath)\$(TargetFileName)" DestinationFiles="$(OutputPath)\$(AddonName).node" Condition=" '$(AddonType)' != 'Napa' " />
<Move SourceFiles="$(OutputPath)\$(TargetFileName)" DestinationFiles="$(OutputPath)\$(AddonName).napa" Condition=" '$(AddonType)' == 'Napa' " />
</Target>
<Import Project="$(Pkgnapa_nodelib_vc140)\exports_node.props" Condition=" '$(AddonType)' != 'Napa' " />
<Import Project="$(Pkgnapa_nodelib_vc140)\exports_v8_includes.props" Condition=" '$(AddonType)' == 'Napa' " />
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,25 @@
{
"name": "plus-number",
"version": "0.1.0",
"author": "napajs",
"description": "Example of a napa module wrapping a class.",
"main": "./lib/plus-number.js",
"types": "./types/plus-number.d.ts",
"license": "MIT",
"devDependencies": {
"mocha": ">= 3.4.2",
"typescript": ">= 2.2.1",
"@types/node": ">= 7.0.8",
"@types/mocha": ">= 2.2.0",
"markdown-table": "1.1.0"
},
"dependencies": {
"napajs": ">= 0.1.0"
},
"scripts": {
"install": "cmake-js compile",
"prepare": "tsc -p lib",
"pretest": "cmake-js compile -d unittest && tsc -p test",
"test": "node unittest/run.js && mocha test --recursive"
}
}

Просмотреть файл

@ -1,8 +0,0 @@
{
"name": "plus-number",
"version": "0.0.1",
"author": "napav",
"description": "Example of a napa module wrapping a class.",
"main": "./lib/plus-number.js",
"types": "./types/plus-number.d.ts"
}

Просмотреть файл

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<ItemGroup>
<QCustomProjectReference Include="$(NapaVanillaRoot)\examples\modules\plus-number\napa\addon.vcxproj" />
<QCustomProjectReference Include="$(NapaVanillaRoot)\examples\modules\plus-number\node\addon.vcxproj" />
</ItemGroup>
<ItemGroup>
<QCustomInput Include="src\plus-number.ts" />
<QCustomInput Include="$(NapaBuildRoot)\**\*" />
</ItemGroup>
<Target Name="BuildScripts" AfterTargets="AfterBuild">
<Message Text="Compile scripts." />
<Exec Command="$(TSCompile) src\plus-number.ts --declaration --typeRoots $(TypesRoot) --outDir $(O)" />
</Target>
<Target Name="CreateNpmPackage" DependsOnTargets="BuildScripts" AfterTargets="AfterBuild">
<Message Text="Create NPM package." />
<MakeDir Directories="$(O)\dist\bin" ContinueOnError="false" Condition="!Exists('$(O)\dist\bin')" />
<MakeDir Directories="$(O)\dist\lib" ContinueOnError="false" Condition="!Exists('$(O)\dist\lib')" />
<MakeDir Directories="$(O)\dist\types" ContinueOnError="false" Condition="!Exists('$(O)\dist\types')" />
<Copy SourceFiles="..\node\$(O)\addon.node" DestinationFolder="$(O)\dist\bin" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="..\napa\$(O)\addon.napa" DestinationFolder="$(O)\dist\bin" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(NapaVanillaRoot)\examples\modules\plus-number\src\$(O)\plus-number.dll" DestinationFolder="$(O)\dist\bin" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(NapaVanillaRoot)\src\$(O)\napa.dll" DestinationFolder="$(O)\dist\bin" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(O)\plus-number.js" DestinationFolder="$(O)\dist\lib" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(O)\plus-number.d.ts" DestinationFolder="$(O)\dist\types" ContinueOnError="false" SkipUnchangedFiles="true" />
<Copy SourceFiles="package.json" DestinationFolder="$(O)\dist" ContinueOnError="false" SkipUnchangedFiles="true" />
</Target>
<Import Project="$(ExtendedTargetsPath)\NoTarget.targets" />
</Project>

Просмотреть файл

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.Default.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.props" />
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>NAPA_EXAMPLE_API;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="plus-number.cpp" />
</ItemGroup>
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Просмотреть файл

@ -1,10 +0,0 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<ItemGroup>
<ProjectFile Include="library-test\library-test.vcxproj" />
<ProjectFile Include="module-test\plus-number-test.njsproj" />
</ItemGroup>
<Import Project="$(ExtendedTargetsPath)\Traversal.targets" />
</Project>

Просмотреть файл

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.Default.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.props" />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(NapaVanillaRoot)\examples\modules\plus-number\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(NapaVanillaRoot)\third-party;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="$(NapaVanillaRoot)\examples\modules\plus-number\src\plus-number.vcxproj" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Target Name="CopyFiles" AfterTargets="Build">
<Copy SourceFiles="$(NapaVanillaRoot)\examples\modules\plus-number\src\$(IntermediateOutputPath)\plus-number.dll" DestinationFolder="$(OutputPath)" ContinueOnError="false" SkipUnchangedFiles="true" />
</Target>
<Import Project="$(ExtendedTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Просмотреть файл

@ -1,2 +0,0 @@
build/
tsconfig.json

Просмотреть файл

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(EnvironmentConfig)" />
<PropertyGroup>
<AssemblyName>plus-number-test</AssemblyName>
</PropertyGroup>
<!-- Test files -->
<!-- It's using the default tsconfig.json@Napa.DevTools -->
<ItemGroup>
<TypeScriptCompile Include="test.ts" />
</ItemGroup>
<Import Project="$(PkgNapa_DevTools)\Napa.TestAdapter.targets" />
<ItemGroup>
<Robocopy Include="..\..\script\$(IntermediateOutputPath)\dist">
<DestinationFolder>$(QTestDirToDeploy)\app\node_modules\plus-number</DestinationFolder>
</Robocopy>
</ItemGroup>
</Project>

Просмотреть файл

@ -1,22 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var assert = require('assert');
var plusNumber = require('plus-number');
describe('Test suite for plus-number', function() {
it('adds a given value', function() {
var po = plusNumber.createPlusNumber(3);
var result: number = po.add(4);
assert.equal(result, 7);
});
it('fails with constructor call', function() {
var failed: boolean = false;
try {
var po = new plusNumber.PlusNumber();
} catch (error) {
failed = true;
}
assert.equal(failed, true);
});
})

Просмотреть файл

@ -0,0 +1,53 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
let assert = require('assert');
import * as path from "path";
let plusNumberDir: string = path.resolve(__dirname, '..');
let plusNumber = require(plusNumberDir);
let napa = require('napajs');
let zone = napa.zone.create('zone');
describe('Test suite for plus-number', function() {
this.timeout(0);
it('adds a given value', function() {
let po = plusNumber.createPlusNumber(3);
let result: number = po.add(4);
assert.equal(result, 7);
});
it('fails with constructor call', function() {
let failed: boolean = false;
try {
let po = new plusNumber.PlusNumber();
} catch (error) {
failed = true;
}
assert.equal(failed, true);
});
it('adds a given value in napa zone', function() {
return zone.execute((plusNumberDir: string) => {
let plusNumber = require(plusNumberDir);
let po = plusNumber.createPlusNumber(3);
let result: number = po.add(4);
return result;
}, [plusNumberDir])
.then((result: any) => {
assert.equal(result.value, 7);
});
});
it('adds a given value in node zone', function() {
return napa.zone.node.execute((plusNumberDir: string) => {
let plusNumber = require(plusNumberDir);
let po = plusNumber.createPlusNumber(3);
let result: number = po.add(4);
return result;
}, [plusNumberDir])
.then((result: any) => {
assert.equal(result.value, 7);
});
});
})

Просмотреть файл

@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": true,
"declaration": false,
"sourceMap": false,
"lib": ["es2015"]
}
}

Просмотреть файл

@ -0,0 +1,62 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project("library-test")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/bin)
# Require Cxx14 features
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Set symbol visibility to hidden by default.
# Napa shared library shares a few classes with napa-binding.node with different compile definition,
# exposing the same symbols from both shared libraries may cause improper behaviors under gcc.
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN)
# Prefix an suffix of Library name for different OS.
if (WIN32)
set(LIBRARY_PREFIX "")
set(LIBRARY_SUFFIX ".lib")
elseif (APPLE)
set(LIBRARY_PREFIX "lib")
set(LIBRARY_SUFFIX ".dylib")
else()
set(LIBRARY_PREFIX "lib")
set(LIBRARY_SUFFIX ".so")
endif()
execute_process(COMMAND node -e
"var path = require('path'); process.stdout.write(path.resolve(path.dirname(require.resolve('napajs')), '..'));"
RESULT_VARIABLE ERR
OUTPUT_VARIABLE NAPAJS_ROOT)
if(ERR)
message(FATAL_ERROR "Failed to get NAPAJS_ROOT")
endif(ERR)
file(GLOB LIBRARY-FILES "../bin/*plus-number.*")
file(COPY ${LIBRARY-FILES} DESTINATION ${PROJECT_SOURCE_DIR}/bin/)
# Files to compile
file(GLOB SOURCE_FILES
"main.cpp")
# The executable name
set(TARGET_NAME "library-test")
# The generated library
add_executable(${TARGET_NAME} ${SOURCE_FILES})
# Include directories
target_include_directories(${TARGET_NAME} PRIVATE
../inc
${NAPAJS_ROOT}/third-party)
# Link libraries
target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/bin/${LIBRARY_PREFIX}plus-number${LIBRARY_SUFFIX})

Просмотреть файл

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var path = require('path');
var childProcess = require('child_process');
try {
childProcess.execFileSync(
path.join(__dirname, 'bin', process.platform === 'win32'? 'library-test.exe': 'library-test'),
[],
{
cwd: path.join(__dirname, 'bin'),
stdio: 'inherit'
}
);
}
catch(err) {
process.exit(1); // Error
}