Skip to content

Commit c4dbbd0

Browse files
devvaannshabose
authored andcommitted
fix: handle directories ending with .js
1 parent fecc4b7 commit c4dbbd0

File tree

11 files changed

+262
-161
lines changed

11 files changed

+262
-161
lines changed

build/api-docs-generator.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,30 @@ function getJsFiles() {
6767
// gets all JS files from src
6868
// (even the ones that we don't need to add in API docs)
6969
const files = glob.sync(`${SRC_DIR}/**/*.js`);
70-
7170
// this gets all the files that we need to add in API docs
7271
const requiredJSfiles = [];
7372
for (const file of files) {
73+
// Check if it's a file (not a directory)
74+
if (fs.statSync(file).isFile()) {
7475

75-
const content = fs.readFileSync(file, "utf-8");
76-
77-
// check if file has this line, if yes include it in the list
78-
if (content.includes("@INCLUDE_IN_API_DOCS")) {
76+
const content = fs.readFileSync(file, "utf-8");
77+
// check if file has this line, if yes include it in the list
78+
if (content.includes("@INCLUDE_IN_API_DOCS")) {
7979

80-
// to copy all files from into JS-Files dir,
81-
// while maintaining the sub-directory structure
82-
const relativePath = path.relative(SRC_DIR, file);
83-
const destPath = path.join(JS_FILES_DIR, relativePath);
84-
requiredJSfiles.push(destPath);
85-
fs.mkdirSync(path.dirname(destPath), { recursive: true });
86-
fs.copyFileSync(file, destPath);
80+
// to copy all files from into JS-Files dir,
81+
// while maintaining the sub-directory structure
82+
const relativePath = path.relative(SRC_DIR, file);
83+
const destPath = path.join(JS_FILES_DIR, relativePath);
84+
requiredJSfiles.push(destPath);
85+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
86+
fs.copyFileSync(file, destPath);
8787

88+
}
8889
}
8990
}
90-
9191
return requiredJSfiles;
92-
9392
}
9493

95-
9694
/**
9795
* Handles the generation of MDX from JS file
9896
* Does it in two step process,
@@ -461,16 +459,16 @@ function mdxFileModifications() {
461459
let importStatement = '';
462460
// when file has no parent sub-dir
463461
// for example NodeConnector.mdx
464-
if(directoryName.endsWith('.mdx')) {
462+
if (directoryName.endsWith('.mdx')) {
465463
importStatement =
466-
`### Import :\n\`\`\`\n` +
467-
`brackets.getModule("${fileNameWithoutExt}")\n` +
468-
`\`\`\`\n`;
464+
`### Import :\n\`\`\`\n` +
465+
`brackets.getModule("${fileNameWithoutExt}")\n` +
466+
`\`\`\`\n`;
469467
} else {
470468
importStatement =
471-
`### Import :\n\`\`\`\n` +
472-
`brackets.getModule("${directoryName}/${fileNameWithoutExt}")\n` +
473-
`\`\`\`\n`;
469+
`### Import :\n\`\`\`\n` +
470+
`brackets.getModule("${directoryName}/${fileNameWithoutExt}")\n` +
471+
`\`\`\`\n`;
474472
}
475473

476474

@@ -578,6 +576,8 @@ function moveMdxDirToDocs() {
578576
*/
579577
function driver() {
580578

579+
console.log("Process started!");
580+
581581
createRequiredDir();
582582

583583
const requiredJSfiles = getJsFiles();

docs/generatedApiDocs/features/NewFileContentManager-API.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,19 @@ A promise that resolves with the content text or rejects if there is no content
9393

9494
Returns a promise that resolves to the default text content of the given file after querying
9595
all the content providers. If no text is returned by any providers, it will return an empty string "".
96-
To get the default content given a path
97-
NewFileContentManager.getInitialContentForFile("/path/to/file.jsx");
9896

9997
### Parameters
10098

10199
* `fullPath` **[string][1]**
102100

101+
### Examples
102+
103+
To get the default content given a path
104+
105+
```javascript
106+
NewFileContentManager.getInitialContentForFile("/path/to/file.jsx");
107+
```
108+
103109
Returns **[Promise][2]<[string][1]>** The text contents
104110

105111
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

docs/generatedApiDocs/features/QuickViewManager-API.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
QuickViewManager provides support to add interactive preview popups on hover over the main editors.
66
Extensions can register to provide previews with `QuickViewManager.registerQuickViewProvider` API.
7-
!\[quick-view-image.png]\([https://docs-images.phcode.dev/phcode-sdk/quick-view-image.png][1] alt="quick view image" /)
8-
!\[quick-view-youtube.png]\([https://docs-images.phcode.dev/phcode-sdk/quick-view-youtube.png][2] alt="quick view youtube image" /)
7+
![quick-view-image.png][1]
8+
![quick-view-youtube.png][2]
99

1010
### See Related: SelectionViewManager
1111

@@ -15,7 +15,7 @@ QuickViewManager API.
1515
* SelectionViews popup only once user selects a text by mouse or hover over a region with text selection.
1616
* Quickviews popup on mouse hover.
1717

18-
!\[image]\([https://user-images.githubusercontent.com/5336369/186434397-3db55789-6077-4d02-b4e2-78ef3f663399.png][4] alt="user image" /)
18+
![image][4]
1919

2020
## Usage
2121

docs/generatedApiDocs/features/SelectionViewManager-API.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ SelectionViewManager provides support to add interactive preview popups on selec
66
This can be used to provide interactive editor controls on a selected element.
77

88
Extensions can register to provide previews with `SelectionViewManager.registerSelectionViewProvider` API.
9-
!\[image]\([https://user-images.githubusercontent.com/5336369/186434397-3db55789-6077-4d02-b4e2-78ef3f663399.png][1] alt="user image" /)
10-
!\[selection view]\([https://user-images.githubusercontent.com/5336369/186434671-c1b263e5-19a9-4a9d-8f90-507df5f881b5.gif][2] alt="user gif" /)
9+
![image][1]
10+
![selection view][2]
1111

1212
### See Related: QuickViewManager
1313

@@ -17,7 +17,7 @@ SelectionViewManager API.
1717
* SelectionViews popup only once user selects a text by mouse or hover over a region with text selection.
1818
* Quickviews popup on mouse hover.
1919

20-
!\[quick-view-youtube.png]\([https://docs-images.phcode.dev/phcode-sdk/quick-view-youtube.png][4] alt="quick view youtube image" /)
20+
![quick-view-youtube.png][4]
2121

2222
## Usage
2323

docs/generatedApiDocs/utils/EventManager-API.md

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,29 @@ EventManager.triggerEvent("drawImage-Handler", "someEventName", "param1", "param
3434
Registers a named EventHandler. Event handlers are created using the call:
3535
`EventDispatcher.makeEventDispatcher(Command.prototype);`
3636

37+
Type: [function][1]
38+
39+
### Parameters
40+
41+
* `handlerName` **[string][2]** a unique name of the handler.
42+
* `eventDispatcher` **[object][3]** An EventDispatcher that will be used to trigger events.
43+
44+
### Examples
45+
3746
To register a close dialogue event handler in an extension:
47+
48+
```javascript
3849
// in close-dialogue.js module winthin the extension, do the following:
3950
const EventDispatcher = brackets.getModule("utils/EventDispatcher"),
4051
EventDispatcher.makeEventDispatcher(exports);
4152
const EventManager = brackets.getModule("utils/EventManager");
4253

43-
// Note: for event handler names, please change the `extensionName` to your extension name
54+
// Note: for event handler names, please change the <extensionName> to your extension name
4455
// to prevent collisions. EventHandlers starting with `ph-` and `br-` are reserved as system handlers
4556
// and not available for use in extensions.
46-
EventManager.registerEventHandler("`extensionName`-closeDialogueHandler", exports);
57+
EventManager.registerEventHandler("<extensionName>-closeDialogueHandler", exports);
4758
// Once the event handler is registered, see triggerEvent API on how to raise events
48-
49-
Type: [function][1]
50-
51-
### Parameters
52-
53-
* `handlerName` **[string][2]** a unique name of the handler.
54-
* `eventDispatcher` **[object][3]** An EventDispatcher that will be used to trigger events.
59+
```
5560

5661
Returns **[boolean][4]**
5762

@@ -71,11 +76,6 @@ Returns **[boolean][4]**
7176

7277
Triggers an event on the named event handler.
7378

74-
To trigger an event to the `closeDialogue` event handler registered above
75-
// anywhere in code, do the following:
76-
const EventManager = brackets.getModule("utils/EventManager");
77-
EventManager.triggerEvent("closeDialogueHandler", "someEvent", "param1", "param2", ...);
78-
7979
Type: [function][1]
8080

8181
### Parameters
@@ -84,6 +84,16 @@ Type: [function][1]
8484
* `eventName` the event name as recognised by the handler. this is usually a string.
8585
* `eventParams` **...any** Can be a comma seperated list of args or a single argument.
8686

87+
### Examples
88+
89+
To trigger an event to the `closeDialogue` event handler registered above
90+
91+
```javascript
92+
// anywhere in code, do the following:
93+
const EventManager = brackets.getModule("utils/EventManager");
94+
EventManager.triggerEvent("closeDialogueHandler", "someEvent", "param1", "param2", ...);
95+
```
96+
8797
## onmessage
8898

8999
This function acts as a secure event handler for all 'message' events targeted at the window object.
@@ -93,33 +103,43 @@ Instead of directly overriding window.onmessage, extensions or other elements th
93103
listen to these events should register their named eventHandler with `EventManager`.
94104

95105
By default, only origins part of `window.Phoenix.TRUSTED_ORIGINS` are whitelisted. If your extension is
96-
bringing in a cross-origin ifrmame say \[`http://mydomain.com`], you should add it to the whitelist by setting
97-
`window.Phoenix.TRUSTED_ORIGINS ["http://mydomain.com"] = true;`
106+
bringing in a cross-origin ifrmame say `http://mydomain.com`, you should add it to the whitelist by setting
107+
`window.Phoenix.TRUSTED_ORIGINS["http://mydomain.com"]=true;`
98108

99109
### Parameters
100110

101111
* `event` **[MessageEvent][6]** The 'message' event targeted at the window object. The event's
102-
'data' property should have a 'handlerName' and `eventName` property that will be triggered in phcode.// We will try to communicate within an embedded iframe and an extension// In your extension in phoenix, register a handlerName to process a new kind of event.
103-
const EventDispatcher = brackets.getModule("utils/EventDispatcher"),
104-
EventDispatcher.makeEventDispatcher(exports);
105-
const EventManager = brackets.getModule("utils/EventManager");
106-
// Note: for event handler names, please change the `extensionName` to your extension name
107-
// to prevent collisions. EventHandlers starting with `ph-` and `br-` are reserved as system handlers
108-
// and not available for use in extensions.
109-
window.Phoenix.TRUSTED_ORIGINS \["[http://mydomain.com][7]"] = true;
110-
EventManager.registerEventHandler("`extensionName`-iframeMessageHandler", exports);
111-
exports.on("iframeHelloEvent", function(\_ev, event){
112-
console.log(event.data.message);
113-
});// Now from your iframe, send a message to the above event handler using:
114-
window.parent.postMessage({
115-
handlerName: "`extensionName`-iframeMessageHandler",
112+
'data' property should have a 'handlerName' and `eventName` property that will be triggered in phcode.
113+
114+
### Examples
115+
116+
```javascript
117+
// We will try to communicate within an embedded iframe and an extension
118+
119+
// In your extension in phoenix, register a handlerName to process a new kind of event.
120+
const EventDispatcher = brackets.getModule("utils/EventDispatcher"),
121+
EventDispatcher.makeEventDispatcher(exports);
122+
const EventManager = brackets.getModule("utils/EventManager");
123+
// Note: for event handler names, please change the <extensionName> to your extension name
124+
// to prevent collisions. EventHandlers starting with `ph-` and `br-` are reserved as system handlers
125+
// and not available for use in extensions.
126+
window.Phoenix.TRUSTED_ORIGINS["http://mydomain.com"]=true;
127+
EventManager.registerEventHandler("<extensionName>-iframeMessageHandler", exports);
128+
exports.on("iframeHelloEvent", function(_ev, event){
129+
console.log(event.data.message);
130+
});
131+
132+
// Now from your iframe, send a message to the above event handler using:
133+
window.parent.postMessage({
134+
handlerName: "<extensionName>-iframeMessageHandler",
116135
eventName: "iframeHelloEvent",
117136
message: "hello world"
118-
}, '\*');
119-
// `you should replace * with the trusted domains list in production for security.` See how this can be
120-
// done securely with this example: [https://github.com/phcode-dev/phcode.live/blob/6d64386fbb9d671cdb64622bc48ffe5f71959bff/docs/virtual-server-loader.js#L43][8]
121-
// Abstract is that, pass in the parentOrigin as a query string parameter in iframe, and validate it against
122-
// a trusted domains list in your iframe.
137+
}, '*');
138+
// `you should replace * with the trusted domains list in production for security.` See how this can be
139+
// done securely with this example: https://github.com/phcode-dev/phcode.live/blob/6d64386fbb9d671cdb64622bc48ffe5f71959bff/docs/virtual-server-loader.js#L43
140+
// Abstract is that, pass in the parentOrigin as a query string parameter in iframe, and validate it against
141+
// a trusted domains list in your iframe.
142+
```
123143

124144
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
125145

@@ -132,7 +152,3 @@ bringing in a cross-origin ifrmame say \[`http://mydomain.com`], you should add
132152
[5]: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
133153

134154
[6]: https://developer.mozilla.org/docs/Web/API/MessageEvent
135-
136-
[7]: http://mydomain.com
137-
138-
[8]: https://github.com/phcode-dev/phcode.live/blob/6d64386fbb9d671cdb64622bc48ffe5f71959bff/docs/virtual-server-loader.js#L43

docs/generatedApiDocs/utils/ExtensionInterface-API.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,21 @@ interface made available.
4242

4343
Registers a named extension interface. Will overwrite if an interface of the same name is already present.
4444

45-
To register an interface `angularCli`
46-
ExtensionInterface.registerExtensionInterface("angularCli", exports);
47-
4845
Type: [function][1]
4946

5047
### Parameters
5148

5249
* `extensionInterfaceName` **[string][2]**
5350
* `interfaceObject` **[Object][3]**
5451

52+
### Examples
53+
54+
To register an interface `angularCli`
55+
56+
```javascript
57+
ExtensionInterface.registerExtensionInterface("angularCli", exports);
58+
```
59+
5560
## isExistsExtensionInterface
5661

5762
Returns true is an interface of the given name exists.
@@ -69,20 +74,25 @@ Returns **[boolean][4]**
6974
Returns a promise that gets resolved only when an ExtensionInterface of the given name is registered. Use this
7075
getter to get hold of extensions interface predictably.
7176

77+
Type: [function][1]
78+
79+
### Parameters
80+
81+
* `extensionInterfaceName`
82+
83+
### Examples
84+
7285
To get a registered interface `angularCli`
86+
87+
```javascript
7388
let angularCli;
7489
ExtensionInterface.waitAndGetExtensionInterface("angularCli").then(interfaceObj=> angularCli = interfaceObj);
7590
...
7691
if(angularCli){ // check if angular cli is avilable
7792
angularCli.callSomeFunction();
7893
}
7994
...
80-
81-
Type: [function][1]
82-
83-
### Parameters
84-
85-
* `extensionInterfaceName`
95+
```
8696

8797
Returns **[Promise][5]**
8898

docs/generatedApiDocs/utils/FeatureGate-API.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ if(FeatureGate.isFeatureEnabled(FEATURE_NEW_COLORS)){
4141
## registerFeatureGate
4242

4343
Registers a named feature with the default enabled state.
44-
To register a feature gate with name `myExtension.newColors`
45-
const FEATURE_NEW_COLORS = 'myExtension.newColors';
46-
FeatureGate.registerFeatureGate(FEATURE_NEW_COLORS, false); // false is the default value here
4744

4845
Type: [function][1]
4946

@@ -52,6 +49,15 @@ Type: [function][1]
5249
* `featureName` **[string][2]**
5350
* `enabledDefault` **[boolean][3]**
5451

52+
### Examples
53+
54+
To register a feature gate with name `myExtension.newColors`
55+
56+
```javascript
57+
const FEATURE_NEW_COLORS = 'myExtension.newColors';
58+
FeatureGate.registerFeatureGate(FEATURE_NEW_COLORS, false); // false is the default value here
59+
```
60+
5561
## getAllRegisteredFeatures
5662

5763
Returns an array of all named registered feature gates.
@@ -63,18 +69,24 @@ Returns **\[[String][2]]** list of registered features
6369
## isFeatureEnabled
6470

6571
Returns true is an featureGate is enabled either by default or overridden by the user using local storage.
66-
To check if the feature `myExtension.newColors` is enabled
67-
const FEATURE_NEW_COLORS = 'myExtension.newColors';
68-
if(FeatureGate.isFeatureEnabled(FEATURE_NEW_COLORS)){
69-
// do fancy colors here
70-
}
7172

7273
Type: [function][1]
7374

7475
### Parameters
7576

7677
* `featureName` **[string][2]**
7778

79+
### Examples
80+
81+
To check if the feature `myExtension.newColors` is enabled
82+
83+
```javascript
84+
const FEATURE_NEW_COLORS = 'myExtension.newColors';
85+
if(FeatureGate.isFeatureEnabled(FEATURE_NEW_COLORS)){
86+
// do fancy colors here
87+
}
88+
```
89+
7890
Returns **[boolean][3]**
7991

8092
## setFeatureEnabled

0 commit comments

Comments
 (0)