Skip to content

Commit c356c1a

Browse files
committed
feat: node extension readme
1 parent e0e8143 commit c356c1a

File tree

2 files changed

+58
-56
lines changed

2 files changed

+58
-56
lines changed

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,64 @@ vast npm library.
1010
For creating extensions that do not need node, follow this link:
1111
https://github.com/phcode-dev/extension-template
1212

13+
## Setting up node extensions
14+
15+
In package.json, add the following section
16+
17+
```json
18+
{
19+
"nodeConfig": {
20+
"nodeIsRequired": false,
21+
"main": "node/index.js",
22+
"npmInstall": "node/"
23+
}
24+
}
25+
```
26+
27+
#### `nodeConfig` Object
28+
29+
The `nodeConfig` object indicates that this is a Node extension.
30+
31+
#### `nodeIsRequired` Field
32+
33+
- Set this field to `true` if the extension relies on Node and won't function
34+
without it.
35+
- If set to `false` or omitted, the extension can still be loaded in browser
36+
versions of Phoenix code without Node support, But will use node in native
37+
builds.
38+
- It will be shown in the extension manager dialog in browser builds as well.
39+
40+
#### `main` Field
41+
42+
- Specifies the main entry point for the Node.js component of the extension.
43+
- Should point to the main JavaScript file for the Node part of the extension.
44+
- Example: `"main": "node/index.js"`
45+
46+
#### `npmInstall` Field (Optional)
47+
48+
- Specifies the path to run `npm install` when the user installs the extension
49+
from the extension manager.
50+
- It's advisable not to package `node_modules` inside the extension. Only the
51+
package lock file should be distributed.
52+
- Example: `"npmInstall": "node/"`
53+
54+
## Communicating between node.js and Phoenix Code
55+
56+
### NodeConnector-API
57+
58+
create
59+
[NodeConnector-API](https://github.com/phcode-dev/phoenix/wiki/NodeConnector-API)
60+
to call functions and send events between your node.js and Phoenix Code
61+
extension components.
62+
63+
- This is available as a global object `global.createNodeConnector`. See above
64+
link for API docs.
65+
- Another API -
66+
[EventDispatcher-API](https://github.com/phcode-dev/phoenix/wiki/EventDispatcher-API)
67+
is also available in the global context as `global.EventDispatcher` for
68+
event trigger/listen within node.
69+
70+
# Using this template
1371
Follow the below 4 steps to start using this template:
1472

1573
Refer this

node/README.md

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)