зеркало из https://github.com/microsoft/napajs.git
Add source and npm tree.
This commit is contained in:
Родитель
8be152c464
Коммит
300bb391a2
|
@ -0,0 +1,47 @@
|
|||
## Napa module source tree
|
||||
|
||||
The source codes can be organized as the structure below. This is different from npm package structure since npm
|
||||
doesn’t 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.
|
||||
```
|
||||
+-- 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
|
||||
| +-- 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
|
||||
+-- typings
|
||||
| +-- example.d.ts
|
||||
+-- package.json
|
||||
+-- tsconfig.json
|
||||
+-- README.md
|
||||
```
|
|
@ -32,12 +32,26 @@ NAPA_MODULE(addon, Init)
|
|||
* *NAPA_SET_METHOD* is equivalent to *NODE_SET_METHOD*. This module will have *hello()* function.
|
||||
* *NAPA_MODULE* is equivalent to *NODE_MODULE*, which exports an initialization function.
|
||||
|
||||
## Build
|
||||
## Typescript
|
||||
It's recommended that typescript or typescript definition is provided to let the user know the APIs without
|
||||
the source codes and develop Typescript project easily.
|
||||
### hello-world.ts
|
||||
```ts
|
||||
var addon = require('../bin/addon');
|
||||
|
||||
export function hello(): string {
|
||||
return addon.hello();
|
||||
}
|
||||
```
|
||||
### hello-world.d.ts
|
||||
```d.ts
|
||||
export declare function hello(): string;
|
||||
```
|
||||
|
||||
## Mocha test
|
||||
```js
|
||||
var assert = require('assert');
|
||||
var helloWorld = require('./hello-world');
|
||||
var helloWorld = require('hello-world');
|
||||
|
||||
describe('Test suite for hello-word', function() {
|
||||
it('prints the string "world"', function() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче