@asyncapi/generator 2.11.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/docs/asyncapi-document.md +1 -1
- package/docs/configuration-file.md +0 -4
- package/docs/file-templates.md +1 -59
- package/docs/generator-template-java.md +0 -2
- package/docs/generator-template.md +1 -4
- package/docs/index.md +2 -2
- package/docs/react-render-engine.md +5 -37
- package/docs/template-development.md +2 -7
- package/docs/template.md +2 -2
- package/docs/typescript-support.md +3 -5
- package/jest.config.js +1 -6
- package/lib/__mocks__/utils.js +0 -3
- package/lib/generator.js +4 -20
- package/lib/templates/bakedInTemplates/core-template-client-kafka-java-quarkus/.ageneratorrc +0 -2
- package/lib/templates/bakedInTemplates/core-template-client-kafka-java-quarkus/package.json +3 -3
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/.ageneratorrc +0 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/package.json +3 -3
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/.ageneratorrc +0 -2
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/package.json +4 -4
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/.ageneratorrc +0 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/README.md.js +5 -153
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/README.md.js.map +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/package.json +4 -4
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/template/README.md.js +2 -103
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/.ageneratorrc +0 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/README.md.js +18 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/README.md.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/package.json +3 -3
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/template/README.md.js +5 -0
- package/lib/templates/config/validator.js +3 -3
- package/lib/utils.js +0 -21
- package/package.json +5 -12
- package/Dockerfile +0 -20
- package/cli.js +0 -205
- package/docs/migration-cli.md +0 -70
- package/docs/migration-nunjucks-react.md +0 -144
- package/docs/nunjucks-render-engine.md +0 -83
- package/lib/filtersRegistry.js +0 -134
- package/lib/renderer/nunjucks.js +0 -42
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/AvailableOperations.js +0 -34
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/AvailableOperations.js.map +0 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/MessageExamples.js +0 -29
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/MessageExamples.js.map +0 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/OperationHeader.js +0 -19
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/OperationHeader.js.map +0 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/AvailableOperations.js +0 -20
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/MessageExamples.js +0 -25
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/OperationHeader.js +0 -12
- package/lib/watcher.js +0 -147
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
require('source-map-support/register');
|
|
6
|
-
var generatorReactSdk = require('@asyncapi/generator-react-sdk');
|
|
7
|
-
var OperationHeader = require('./OperationHeader.js');
|
|
8
|
-
var MessageExamples = require('./MessageExamples.js');
|
|
9
|
-
var jsxRuntime = require('/home/runner/work/generator/generator/node_modules/react/cjs/react-jsx-runtime.production.min.js');
|
|
10
|
-
require('@asyncapi/generator-helpers');
|
|
11
|
-
|
|
12
|
-
function AvailableOperations({
|
|
13
|
-
operations
|
|
14
|
-
}) {
|
|
15
|
-
if (!operations || operations.length === 0) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
19
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
20
|
-
newLines: 2,
|
|
21
|
-
children: "### Available Operations"
|
|
22
|
-
}), operations.map(operation => /*#__PURE__*/jsxRuntime.jsxs(generatorReactSdk.Text, {
|
|
23
|
-
newLines: 2,
|
|
24
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(OperationHeader, {
|
|
25
|
-
operation: operation
|
|
26
|
-
}), /*#__PURE__*/jsxRuntime.jsx(MessageExamples, {
|
|
27
|
-
operation: operation
|
|
28
|
-
})]
|
|
29
|
-
}))]
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
exports.AvailableOperations = AvailableOperations;
|
|
34
|
-
//# sourceMappingURL=AvailableOperations.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AvailableOperations.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/AvailableOperations.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\nimport OperationHeader from './OperationHeader';\nimport MessageExamples from './MessageExamples';\n\nexport function AvailableOperations({ operations }) {\n if (!operations || operations.length === 0) {\n return null;\n }\n return (\n <>\n <Text newLines={2}>### Available Operations</Text>\n {operations.map((operation) => (\n <Text newLines={2}>\n <OperationHeader operation={operation} />\n <MessageExamples operation={operation} />\n </Text>\n ))}\n </>\n );\n}\n"],"names":["AvailableOperations","operations","length","_jsxs","_Fragment","children","_jsx","Text","newLines","map","operation","OperationHeader","MessageExamples"],"mappings":";;;;;;;;;;;AAIO,SAASA,mBAAmBA,CAAC;AAAEC,EAAAA,UAAAA;AAAW,CAAC,EAAE;EAClD,IAAI,CAACA,UAAU,IAAIA,UAAU,CAACC,MAAM,KAAK,CAAC,EAAE;AAC1C,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;EACA,oBACEC,eAAA,CAAAC,mBAAA,EAAA;IAAAC,QAAA,EAAA,cACEC,cAAA,CAACC,sBAAI,EAAA;AAACC,MAAAA,QAAQ,EAAE,CAAE;AAAAH,MAAAA,QAAA,EAAC,0BAAA;KAA8B,CAAC,EACjDJ,UAAU,CAACQ,GAAG,CAAEC,SAAS,iBACxBP,eAAA,CAACI,sBAAI,EAAA;AAACC,MAAAA,QAAQ,EAAE,CAAE;MAAAH,QAAA,EAAA,cAChBC,cAAA,CAACK,eAAe,EAAA;AAACD,QAAAA,SAAS,EAAEA,SAAAA;AAAU,OAAE,CAAC,eACzCJ,cAAA,CAACM,eAAe,EAAA;AAACF,QAAAA,SAAS,EAAEA,SAAAA;AAAU,OAAE,CAAC,CAAA;AAAA,KACrC,CACP,CAAC,CAAA;AAAA,GACF,CAAC,CAAA;AAEP;;;;"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
require('source-map-support/register');
|
|
4
|
-
var generatorHelpers = require('@asyncapi/generator-helpers');
|
|
5
|
-
var generatorReactSdk = require('@asyncapi/generator-react-sdk');
|
|
6
|
-
var jsxRuntime = require('/home/runner/work/generator/generator/node_modules/react/cjs/react-jsx-runtime.production.min.js');
|
|
7
|
-
|
|
8
|
-
function MessageExamples({
|
|
9
|
-
operation
|
|
10
|
-
}) {
|
|
11
|
-
const operationId = operation.id();
|
|
12
|
-
const messageExamples = [];
|
|
13
|
-
const messages = generatorHelpers.getOperationMessages(operation) || [];
|
|
14
|
-
messages.forEach(message => {
|
|
15
|
-
const examples = generatorHelpers.getMessageExamples(message) || [];
|
|
16
|
-
examples.forEach(example => {
|
|
17
|
-
const payload = example.payload();
|
|
18
|
-
messageExamples.push(`\n\n**Example:**\n\`\`\`javascript\nclient.${operationId}(${JSON.stringify(payload, null, 2)});\n\`\`\``);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
22
|
-
children: messageExamples.map(example => /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
23
|
-
children: example
|
|
24
|
-
}))
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = MessageExamples;
|
|
29
|
-
//# sourceMappingURL=MessageExamples.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MessageExamples.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/MessageExamples.js"],"sourcesContent":["import { getMessageExamples, getOperationMessages } from '@asyncapi/generator-helpers';\nimport { Text } from '@asyncapi/generator-react-sdk';\n\nexport default function MessageExamples({operation}) {\n const operationId = operation.id();\n const messageExamples = [];\n const messages = getOperationMessages(operation) || [];\n\n messages.forEach((message) => {\n const examples = getMessageExamples(message) || [];\n examples.forEach((example) => {\n const payload = example.payload();\n messageExamples.push(`\\n\\n**Example:**\\n\\`\\`\\`javascript\\nclient.${operationId}(${JSON.stringify(payload, null, 2)});\\n\\`\\`\\``);\n });\n });\n return (\n <Text>\n {messageExamples.map(example => (\n <Text>\n {example}\n </Text>\n ))}\n </Text>\n );\n}"],"names":["MessageExamples","operation","operationId","id","messageExamples","messages","getOperationMessages","forEach","message","examples","getMessageExamples","example","payload","push","JSON","stringify","_jsx","Text","children","map"],"mappings":";;;;;;;AAGe,SAASA,eAAeA,CAAC;AAACC,EAAAA,SAAAA;AAAS,CAAC,EAAE;AACnD,EAAA,MAAMC,WAAW,GAAGD,SAAS,CAACE,EAAE,EAAE,CAAA;EAClC,MAAMC,eAAe,GAAG,EAAE,CAAA;AAC1B,EAAA,MAAMC,QAAQ,GAAGC,qCAAoB,CAACL,SAAS,CAAC,IAAI,EAAE,CAAA;AAEtDI,EAAAA,QAAQ,CAACE,OAAO,CAAEC,OAAO,IAAK;AAC5B,IAAA,MAAMC,QAAQ,GAAGC,mCAAkB,CAACF,OAAO,CAAC,IAAI,EAAE,CAAA;AAClDC,IAAAA,QAAQ,CAACF,OAAO,CAAEI,OAAO,IAAK;AAC5B,MAAA,MAAMC,OAAO,GAAGD,OAAO,CAACC,OAAO,EAAE,CAAA;AACjCR,MAAAA,eAAe,CAACS,IAAI,CAAC,CAA8CX,2CAAAA,EAAAA,WAAW,IAAIY,IAAI,CAACC,SAAS,CAACH,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,YAAY,CAAC,CAAA;AACjI,KAAC,CAAC,CAAA;AACJ,GAAC,CAAC,CAAA;EACF,oBACEI,cAAA,CAACC,sBAAI,EAAA;IAAAC,QAAA,EACFd,eAAe,CAACe,GAAG,CAACR,OAAO,iBAC1BK,cAAA,CAACC,sBAAI,EAAA;AAAAC,MAAAA,QAAA,EACFP,OAAAA;AAAO,KACJ,CACP,CAAA;AAAC,GACE,CAAC,CAAA;AAEX;;;;"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
require('source-map-support/register');
|
|
4
|
-
var generatorReactSdk = require('@asyncapi/generator-react-sdk');
|
|
5
|
-
var jsxRuntime = require('/home/runner/work/generator/generator/node_modules/react/cjs/react-jsx-runtime.production.min.js');
|
|
6
|
-
|
|
7
|
-
function OperationHeader({
|
|
8
|
-
operation
|
|
9
|
-
}) {
|
|
10
|
-
const operationId = operation.id();
|
|
11
|
-
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
12
|
-
children: `#### \`${operationId}(payload)\`
|
|
13
|
-
${operation.hasSummary() ? operation.summary() : ''}
|
|
14
|
-
${operation.hasDescription() ? `\n${operation.description()}` : ''}`
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = OperationHeader;
|
|
19
|
-
//# sourceMappingURL=OperationHeader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OperationHeader.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/OperationHeader.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport default function OperationHeader({operation}) {\n const operationId = operation.id();\n return (\n <Text>\n {`#### \\`${operationId}(payload)\\`\n${operation.hasSummary() ? operation.summary() : ''}\n${operation.hasDescription() ? `\\n${operation.description()}` : ''}`}\n </Text>\n );\n}"],"names":["OperationHeader","operation","operationId","id","_jsx","Text","children","hasSummary","summary","hasDescription","description"],"mappings":";;;;;;AAEe,SAASA,eAAeA,CAAC;AAACC,EAAAA,SAAAA;AAAS,CAAC,EAAE;AACnD,EAAA,MAAMC,WAAW,GAAGD,SAAS,CAACE,EAAE,EAAE,CAAA;EAClC,oBACEC,cAAA,CAACC,sBAAI,EAAA;IAAAC,QAAA,EACF,UAAUJ,WAAW,CAAA;AAC5B,EAAED,SAAS,CAACM,UAAU,EAAE,GAAIN,SAAS,CAACO,OAAO,EAAE,GAAG,EAAE,CAAA;AACpD,EAAEP,SAAS,CAACQ,cAAc,EAAE,GAAG,CAAA,EAAA,EAAKR,SAAS,CAACS,WAAW,EAAE,CAAA,CAAE,GAAG,EAAE,CAAA,CAAA;AAAE,GAC1D,CAAC,CAAA;AAEX;;;;"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
-
import OperationHeader from './OperationHeader';
|
|
3
|
-
import MessageExamples from './MessageExamples';
|
|
4
|
-
|
|
5
|
-
export function AvailableOperations({ operations }) {
|
|
6
|
-
if (!operations || operations.length === 0) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
return (
|
|
10
|
-
<>
|
|
11
|
-
<Text newLines={2}>### Available Operations</Text>
|
|
12
|
-
{operations.map((operation) => (
|
|
13
|
-
<Text newLines={2}>
|
|
14
|
-
<OperationHeader operation={operation} />
|
|
15
|
-
<MessageExamples operation={operation} />
|
|
16
|
-
</Text>
|
|
17
|
-
))}
|
|
18
|
-
</>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { getMessageExamples, getOperationMessages } from '@asyncapi/generator-helpers';
|
|
2
|
-
import { Text } from '@asyncapi/generator-react-sdk';
|
|
3
|
-
|
|
4
|
-
export default function MessageExamples({operation}) {
|
|
5
|
-
const operationId = operation.id();
|
|
6
|
-
const messageExamples = [];
|
|
7
|
-
const messages = getOperationMessages(operation) || [];
|
|
8
|
-
|
|
9
|
-
messages.forEach((message) => {
|
|
10
|
-
const examples = getMessageExamples(message) || [];
|
|
11
|
-
examples.forEach((example) => {
|
|
12
|
-
const payload = example.payload();
|
|
13
|
-
messageExamples.push(`\n\n**Example:**\n\`\`\`javascript\nclient.${operationId}(${JSON.stringify(payload, null, 2)});\n\`\`\``);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
return (
|
|
17
|
-
<Text>
|
|
18
|
-
{messageExamples.map(example => (
|
|
19
|
-
<Text>
|
|
20
|
-
{example}
|
|
21
|
-
</Text>
|
|
22
|
-
))}
|
|
23
|
-
</Text>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
-
|
|
3
|
-
export default function OperationHeader({operation}) {
|
|
4
|
-
const operationId = operation.id();
|
|
5
|
-
return (
|
|
6
|
-
<Text>
|
|
7
|
-
{`#### \`${operationId}(payload)\`
|
|
8
|
-
${operation.hasSummary() ? operation.summary() : ''}
|
|
9
|
-
${operation.hasDescription() ? `\n${operation.description()}` : ''}`}
|
|
10
|
-
</Text>
|
|
11
|
-
);
|
|
12
|
-
}
|
package/lib/watcher.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const chokidar = require('chokidar');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Class to watch for change in certain file(s)
|
|
6
|
-
*/
|
|
7
|
-
class Watcher {
|
|
8
|
-
constructor(paths, ignorePaths) {
|
|
9
|
-
if (Array.isArray(paths)) {
|
|
10
|
-
this.paths = paths;
|
|
11
|
-
} else {
|
|
12
|
-
this.paths = [paths];
|
|
13
|
-
}
|
|
14
|
-
//Ensure all backwards slashes are replaced with forward slash based on the requirement from chokidar
|
|
15
|
-
for (const pathIndex in this.paths) {
|
|
16
|
-
const path = this.paths[pathIndex];
|
|
17
|
-
this.paths[pathIndex] = path.replace(/[\\]/g, '/');
|
|
18
|
-
}
|
|
19
|
-
this.fsWait = false;
|
|
20
|
-
this.watchers = {};
|
|
21
|
-
this.filesChanged = {};
|
|
22
|
-
this.ignorePaths = ignorePaths;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Initiates watch on a path.
|
|
27
|
-
* @param {*} path The path the watcher is listening on.
|
|
28
|
-
* @param {*} changeCallback Callback to call when changed occur.
|
|
29
|
-
* @param {*} errorCallback Calback to call when it is no longer possible to watch a file.
|
|
30
|
-
*/
|
|
31
|
-
initiateWatchOnPath(path, changeCallback, errorCallback) {
|
|
32
|
-
const watcher = chokidar.watch(path, {ignoreInitial: true, ignored: this.ignorePaths});
|
|
33
|
-
watcher.on('all', (eventType, changedPath) => this.fileChanged(path, changedPath, eventType, changeCallback, errorCallback));
|
|
34
|
-
this.watchers[path] = watcher;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* This method initiate the watch for change in all files
|
|
39
|
-
* @param {*} callback called when the file(s) change
|
|
40
|
-
*/
|
|
41
|
-
async watch(changeCallback, errorCallback) {
|
|
42
|
-
for (const index in this.paths) {
|
|
43
|
-
const path = this.paths[index];
|
|
44
|
-
this.initiateWatchOnPath(path, changeCallback, errorCallback);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Should be called when a file has changed one way or another.
|
|
50
|
-
* @param {*} listenerPath The path the watcher is listening on.
|
|
51
|
-
* @param {*} changedPath The file/dir that was changed
|
|
52
|
-
* @param {*} eventType What kind of change
|
|
53
|
-
* @param {*} changeCallback Callback to call when changed occur.
|
|
54
|
-
* @param {*} errorCallback Calback to call when it is no longer possible to watch a file.
|
|
55
|
-
*/
|
|
56
|
-
fileChanged(listenerPath, changedPath, eventType, changeCallback, errorCallback) {
|
|
57
|
-
try {
|
|
58
|
-
if (fs.existsSync(listenerPath)) {
|
|
59
|
-
const newEventType = this.convertEventType(eventType);
|
|
60
|
-
this.filesChanged[changedPath] = { eventType: newEventType, path: changedPath};
|
|
61
|
-
// Since multiple changes can occur at the same time, lets wait a bit before processing.
|
|
62
|
-
if (this.fsWait) return;
|
|
63
|
-
this.fsWait = setTimeout(async () => {
|
|
64
|
-
await changeCallback(this.filesChanged);
|
|
65
|
-
this.filesChanged = {};
|
|
66
|
-
this.fsWait = false;
|
|
67
|
-
}, 500);
|
|
68
|
-
}
|
|
69
|
-
} catch (e) {
|
|
70
|
-
// File was not, find all files that are missing..
|
|
71
|
-
const unknownPaths = this.getAllNonExistingPaths();
|
|
72
|
-
this.closeWatchers();
|
|
73
|
-
errorCallback(unknownPaths);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Convert the event type to a more usefull one.
|
|
79
|
-
* @param {*} currentEventType The current event type (from chokidar)
|
|
80
|
-
*/
|
|
81
|
-
convertEventType(currentEventType) {
|
|
82
|
-
let newEventType = currentEventType;
|
|
83
|
-
//Change the naming of the event type
|
|
84
|
-
switch (newEventType) {
|
|
85
|
-
case 'unlink':
|
|
86
|
-
case 'unlinkDir':
|
|
87
|
-
newEventType = 'removed';
|
|
88
|
-
break;
|
|
89
|
-
case 'addDir':
|
|
90
|
-
case 'add':
|
|
91
|
-
newEventType = 'added';
|
|
92
|
-
break;
|
|
93
|
-
case 'change':
|
|
94
|
-
newEventType = 'changed';
|
|
95
|
-
break;
|
|
96
|
-
case 'rename':
|
|
97
|
-
newEventType = 'renamed';
|
|
98
|
-
break;
|
|
99
|
-
default:
|
|
100
|
-
newEventType = `unknown (${currentEventType})`;
|
|
101
|
-
}
|
|
102
|
-
return newEventType;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Get all paths which no longer exists
|
|
107
|
-
*/
|
|
108
|
-
getAllNonExistingPaths() {
|
|
109
|
-
const unknownPaths = [];
|
|
110
|
-
for (const index in this.paths) {
|
|
111
|
-
const path = this.paths[index];
|
|
112
|
-
if (!fs.existsSync(path)) {
|
|
113
|
-
unknownPaths.push(path);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return unknownPaths;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Closes all active watchers down.
|
|
121
|
-
*/
|
|
122
|
-
closeWatchers() {
|
|
123
|
-
this.filesChanged = {};
|
|
124
|
-
for (const index in this.paths) {
|
|
125
|
-
const path = this.paths[index];
|
|
126
|
-
this.closeWatcher(path);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Closes an active watcher down.
|
|
132
|
-
* @param {*} path The path to close the watcher for.
|
|
133
|
-
*/
|
|
134
|
-
closeWatcher(path) {
|
|
135
|
-
// Ensure if called before `watch` to do nothing
|
|
136
|
-
if (path !== null) {
|
|
137
|
-
const watcher = this.watchers[path];
|
|
138
|
-
if (watcher !== null) {
|
|
139
|
-
watcher.close();
|
|
140
|
-
this.watchers[path] = null;
|
|
141
|
-
} else {
|
|
142
|
-
//Watcher not found for path
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
module.exports = Watcher;
|