@asyncapi/cli 0.25.1 → 0.25.3
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/lib/base.d.ts +3 -1
- package/lib/base.js +16 -3
- package/lib/commands/config/context/add.js +8 -6
- package/lib/commands/config/context/current.js +5 -3
- package/lib/commands/config/context/index.js +6 -4
- package/lib/commands/config/context/list.js +7 -5
- package/lib/commands/config/context/remove.js +12 -10
- package/lib/commands/config/context/use.js +7 -5
- package/lib/commands/config/index.js +6 -4
- package/lib/commands/convert.js +34 -32
- package/lib/commands/diff.js +87 -83
- package/lib/commands/generate/fromTemplate.d.ts +3 -3
- package/lib/commands/generate/fromTemplate.js +89 -83
- package/lib/commands/generate/index.js +5 -3
- package/lib/commands/generate/models.js +83 -81
- package/lib/commands/new.js +96 -90
- package/lib/commands/start/index.js +5 -3
- package/lib/commands/start/studio.js +7 -5
- package/lib/commands/validate.js +24 -22
- package/lib/flags.d.ts +1 -1
- package/lib/globals.js +4 -4
- package/lib/models/Context.js +88 -74
- package/lib/models/SpecificationFile.js +122 -103
- package/lib/utils/generator.js +15 -11
- package/oclif.manifest.json +1 -1
- package/package.json +17 -14
|
@@ -6,11 +6,13 @@ const base_1 = tslib_1.__importDefault(require("../../base"));
|
|
|
6
6
|
const Studio_1 = require("../../models/Studio");
|
|
7
7
|
const SpecificationFile_1 = require("../../models/SpecificationFile");
|
|
8
8
|
class StartStudio extends base_1.default {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
run() {
|
|
10
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
const { flags } = yield this.parse(StartStudio);
|
|
12
|
+
const filePath = flags.file || (yield (0, SpecificationFile_1.load)()).getFilePath();
|
|
13
|
+
const port = flags.port;
|
|
14
|
+
(0, Studio_1.start)(filePath, port);
|
|
15
|
+
});
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
exports.default = StartStudio;
|
package/lib/commands/validate.js
CHANGED
|
@@ -9,30 +9,32 @@ const SpecificationFile_1 = require("../models/SpecificationFile");
|
|
|
9
9
|
const globals_1 = require("../globals");
|
|
10
10
|
const flags_1 = require("../flags");
|
|
11
11
|
class Validate extends base_1.default {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
if (specFile.getFilePath()) {
|
|
22
|
-
await parser.parse(specFile.text());
|
|
23
|
-
this.log(`File ${specFile.getFilePath()} successfully validated!`);
|
|
12
|
+
run() {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const { args, flags } = yield this.parse(Validate); //NOSONAR
|
|
15
|
+
const filePath = args['spec-file'];
|
|
16
|
+
const watchMode = flags['watch'];
|
|
17
|
+
const specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
18
|
+
if (watchMode) {
|
|
19
|
+
(0, globals_1.specWatcher)({ spec: specFile, handler: this, handlerName: 'validate' });
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
try {
|
|
22
|
+
if (specFile.getFilePath()) {
|
|
23
|
+
yield parser.parse(specFile.text());
|
|
24
|
+
this.log(`File ${specFile.getFilePath()} successfully validated!`);
|
|
25
|
+
}
|
|
26
|
+
else if (specFile.getFileURL()) {
|
|
27
|
+
yield parser.parse(specFile.text());
|
|
28
|
+
this.log(`URL ${specFile.getFileURL()} successfully validated`);
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new validation_error_1.ValidationError({
|
|
33
|
+
type: 'parser-error',
|
|
34
|
+
err: error
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
exports.default = Validate;
|
package/lib/flags.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const watchFlag: (description?: string) => import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
1
|
+
export declare const watchFlag: (description?: string | undefined) => import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
package/lib/globals.js
CHANGED
|
@@ -27,15 +27,15 @@ const specWatcher = (params) => {
|
|
|
27
27
|
WATCH_MESSAGES.logOnStart(filePath);
|
|
28
28
|
chokidar_1.default
|
|
29
29
|
.watch(filePath, CHOKIDAR_CONFIG)
|
|
30
|
-
.on('change',
|
|
30
|
+
.on('change', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
31
31
|
WATCH_MESSAGES.logOnChange(params.handlerName);
|
|
32
32
|
try {
|
|
33
|
-
|
|
33
|
+
yield params.handler.run();
|
|
34
34
|
}
|
|
35
35
|
catch (err) {
|
|
36
|
-
|
|
36
|
+
yield params.handler.catch(err);
|
|
37
37
|
}
|
|
38
|
-
});
|
|
38
|
+
}));
|
|
39
39
|
CHOKIDAR_INSTANCE_STORE.set(params.label || '_default', true);
|
|
40
40
|
}
|
|
41
41
|
catch (error) {
|
package/lib/models/Context.js
CHANGED
|
@@ -9,94 +9,108 @@ const context_error_1 = require("../errors/context-error");
|
|
|
9
9
|
const { readFile, writeFile } = fs_1.promises;
|
|
10
10
|
const CONTEXT_FILENAME = process.env.CONTEXT_FILENAME || '.asyncapi';
|
|
11
11
|
exports.DEFAULT_CONTEXT_FILE_PATH = path.resolve(process.env.CONTEXT_FILE_PATH || os.homedir(), CONTEXT_FILENAME);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
function loadContext(contextName) {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const fileContent = yield loadContextFile();
|
|
15
|
+
if (contextName) {
|
|
16
|
+
const context = fileContent.store[String(contextName)];
|
|
17
|
+
if (!context) {
|
|
18
|
+
throw new context_error_1.ContextNotFound(contextName);
|
|
19
|
+
}
|
|
20
|
+
return context;
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
else if (fileContent.current) {
|
|
23
|
+
const context = fileContent.store[fileContent.current];
|
|
24
|
+
if (!context) {
|
|
25
|
+
throw new context_error_1.ContextNotFound(fileContent.current);
|
|
26
|
+
}
|
|
27
|
+
return context;
|
|
25
28
|
}
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
throw new context_error_1.MissingCurrentContextError();
|
|
29
|
+
throw new context_error_1.MissingCurrentContextError();
|
|
30
|
+
});
|
|
29
31
|
}
|
|
30
32
|
exports.loadContext = loadContext;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
catch (err) {
|
|
37
|
-
if (err instanceof context_error_1.MissingContextFileError) {
|
|
38
|
-
fileContent = {
|
|
39
|
-
store: {
|
|
40
|
-
[contextName]: pathToFile,
|
|
41
|
-
}
|
|
42
|
-
};
|
|
33
|
+
function addContext(contextName, pathToFile) {
|
|
34
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
let fileContent;
|
|
36
|
+
try {
|
|
37
|
+
fileContent = yield loadContextFile();
|
|
43
38
|
}
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
catch (err) {
|
|
40
|
+
if (err instanceof context_error_1.MissingContextFileError) {
|
|
41
|
+
fileContent = {
|
|
42
|
+
store: {
|
|
43
|
+
[contextName]: pathToFile,
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
46
50
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
fileContent.store[String(contextName)] = pathToFile;
|
|
52
|
+
yield saveContextFile(fileContent);
|
|
53
|
+
});
|
|
50
54
|
}
|
|
51
55
|
exports.addContext = addContext;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
function removeContext(contextName) {
|
|
57
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const fileContent = yield loadContextFile();
|
|
59
|
+
if (!fileContent.store[String(contextName)]) {
|
|
60
|
+
throw new context_error_1.ContextNotFound(contextName);
|
|
61
|
+
}
|
|
62
|
+
if (fileContent.current === contextName) {
|
|
63
|
+
delete fileContent.current;
|
|
64
|
+
}
|
|
65
|
+
delete fileContent.store[String(contextName)];
|
|
66
|
+
yield saveContextFile(fileContent);
|
|
67
|
+
});
|
|
62
68
|
}
|
|
63
69
|
exports.removeContext = removeContext;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
function getCurrentContext() {
|
|
71
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const fileContent = yield loadContextFile();
|
|
73
|
+
const context = yield loadContext();
|
|
74
|
+
return {
|
|
75
|
+
current: fileContent.current,
|
|
76
|
+
context,
|
|
77
|
+
};
|
|
78
|
+
});
|
|
71
79
|
}
|
|
72
80
|
exports.getCurrentContext = getCurrentContext;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
function setCurrentContext(contextName) {
|
|
82
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const fileContent = yield loadContextFile();
|
|
84
|
+
if (!fileContent.store[String(contextName)]) {
|
|
85
|
+
throw new context_error_1.ContextNotFound(contextName);
|
|
86
|
+
}
|
|
87
|
+
fileContent.current = contextName;
|
|
88
|
+
yield saveContextFile(fileContent);
|
|
89
|
+
});
|
|
80
90
|
}
|
|
81
91
|
exports.setCurrentContext = setCurrentContext;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
function loadContextFile() {
|
|
93
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
try {
|
|
95
|
+
return JSON.parse(yield readFile(exports.DEFAULT_CONTEXT_FILE_PATH, { encoding: 'utf8' }));
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
throw new context_error_1.MissingContextFileError();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
89
101
|
}
|
|
90
102
|
exports.loadContextFile = loadContextFile;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
function saveContextFile(fileContent) {
|
|
104
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
try {
|
|
106
|
+
writeFile(exports.DEFAULT_CONTEXT_FILE_PATH, JSON.stringify({
|
|
107
|
+
current: fileContent.current,
|
|
108
|
+
store: fileContent.store
|
|
109
|
+
}), { encoding: 'utf8' });
|
|
110
|
+
return fileContent;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
102
116
|
}
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.fileExists = exports.isURL = exports.nameType = exports.load = exports.Specification = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
|
-
const
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const url_1 = require("url");
|
|
7
8
|
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
8
9
|
const Context_1 = require("./Context");
|
|
9
10
|
const specification_file_1 = require("../errors/specification-file");
|
|
@@ -32,28 +33,32 @@ class Specification {
|
|
|
32
33
|
getFileURL() {
|
|
33
34
|
return this.fileURL;
|
|
34
35
|
}
|
|
35
|
-
static
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
static fromFile(filepath) {
|
|
37
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
let spec;
|
|
39
|
+
try {
|
|
40
|
+
spec = yield readFile(filepath, { encoding: 'utf8' });
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw new specification_file_1.ErrorLoadingSpec('file', filepath);
|
|
44
|
+
}
|
|
45
|
+
return new Specification(spec, { filepath });
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
static fromURL(URLpath) {
|
|
49
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
let response;
|
|
51
|
+
try {
|
|
52
|
+
response = yield (0, node_fetch_1.default)(URLpath, { method: 'GET' });
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
throw new specification_file_1.ErrorLoadingSpec('url', URLpath);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
50
58
|
throw new specification_file_1.ErrorLoadingSpec('url', URLpath);
|
|
51
59
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
throw new specification_file_1.ErrorLoadingSpec('url', URLpath);
|
|
55
|
-
}
|
|
56
|
-
return new Specification(await (response === null || response === void 0 ? void 0 : response.text()), { fileURL: URLpath });
|
|
60
|
+
return new Specification(yield (response === null || response === void 0 ? void 0 : response.text()), { fileURL: URLpath });
|
|
61
|
+
});
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
exports.Specification = Specification;
|
|
@@ -64,109 +69,123 @@ class SpecificationFile {
|
|
|
64
69
|
getPath() {
|
|
65
70
|
return this.pathToFile;
|
|
66
71
|
}
|
|
67
|
-
|
|
68
|
-
return
|
|
72
|
+
read() {
|
|
73
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
return readFile(this.pathToFile, { encoding: 'utf8' });
|
|
75
|
+
});
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
78
|
exports.default = SpecificationFile;
|
|
72
79
|
/* eslint-disable sonarjs/cognitive-complexity */
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (
|
|
80
|
+
function load(filePathOrContextName, loadType) {
|
|
81
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (filePathOrContextName) {
|
|
83
|
+
if (loadType === null || loadType === void 0 ? void 0 : loadType.file) {
|
|
84
|
+
return Specification.fromFile(filePathOrContextName);
|
|
85
|
+
}
|
|
86
|
+
if (loadType === null || loadType === void 0 ? void 0 : loadType.context) {
|
|
87
|
+
return loadFromContext(filePathOrContextName);
|
|
88
|
+
}
|
|
89
|
+
if (loadType === null || loadType === void 0 ? void 0 : loadType.url) {
|
|
90
|
+
return Specification.fromURL(filePathOrContextName);
|
|
91
|
+
}
|
|
92
|
+
const type = yield nameType(filePathOrContextName);
|
|
93
|
+
if (type === TYPE_CONTEXT_NAME) {
|
|
94
|
+
return loadFromContext(filePathOrContextName);
|
|
95
|
+
}
|
|
96
|
+
if (type === TYPE_URL) {
|
|
97
|
+
return Specification.fromURL(filePathOrContextName);
|
|
98
|
+
}
|
|
99
|
+
yield fileExists(filePathOrContextName);
|
|
76
100
|
return Specification.fromFile(filePathOrContextName);
|
|
77
101
|
}
|
|
78
|
-
|
|
79
|
-
return loadFromContext(
|
|
80
|
-
}
|
|
81
|
-
if (loadType === null || loadType === void 0 ? void 0 : loadType.url) {
|
|
82
|
-
return Specification.fromURL(filePathOrContextName);
|
|
83
|
-
}
|
|
84
|
-
const type = await nameType(filePathOrContextName);
|
|
85
|
-
if (type === TYPE_CONTEXT_NAME) {
|
|
86
|
-
return loadFromContext(filePathOrContextName);
|
|
87
|
-
}
|
|
88
|
-
if (type === TYPE_URL) {
|
|
89
|
-
return Specification.fromURL(filePathOrContextName);
|
|
90
|
-
}
|
|
91
|
-
await fileExists(filePathOrContextName);
|
|
92
|
-
return Specification.fromFile(filePathOrContextName);
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
return await loadFromContext();
|
|
96
|
-
}
|
|
97
|
-
catch (e) {
|
|
98
|
-
const autoDetectedSpecFile = await detectSpecFile();
|
|
99
|
-
if (autoDetectedSpecFile) {
|
|
100
|
-
return Specification.fromFile(autoDetectedSpecFile);
|
|
102
|
+
try {
|
|
103
|
+
return yield loadFromContext();
|
|
101
104
|
}
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
catch (e) {
|
|
106
|
+
const autoDetectedSpecFile = yield detectSpecFile();
|
|
107
|
+
if (autoDetectedSpecFile) {
|
|
108
|
+
return Specification.fromFile(autoDetectedSpecFile);
|
|
109
|
+
}
|
|
110
|
+
if (e instanceof context_error_1.MissingContextFileError) {
|
|
111
|
+
throw new specification_file_1.ErrorLoadingSpec();
|
|
112
|
+
}
|
|
113
|
+
throw e;
|
|
104
114
|
}
|
|
105
|
-
|
|
106
|
-
}
|
|
115
|
+
});
|
|
107
116
|
}
|
|
108
117
|
exports.load = load;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
try {
|
|
114
|
-
if (await fileExists(name)) {
|
|
118
|
+
function nameType(name) {
|
|
119
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
if (name.startsWith('.')) {
|
|
115
121
|
return TYPE_FILE_PATH;
|
|
116
122
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return
|
|
123
|
+
try {
|
|
124
|
+
if (yield fileExists(name)) {
|
|
125
|
+
return TYPE_FILE_PATH;
|
|
126
|
+
}
|
|
127
|
+
return TYPE_CONTEXT_NAME;
|
|
122
128
|
}
|
|
123
|
-
|
|
124
|
-
|
|
129
|
+
catch (e) {
|
|
130
|
+
if (yield isURL(name)) {
|
|
131
|
+
return TYPE_URL;
|
|
132
|
+
}
|
|
133
|
+
return TYPE_CONTEXT_NAME;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
125
136
|
}
|
|
126
137
|
exports.nameType = nameType;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
138
|
+
function isURL(urlpath) {
|
|
139
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
try {
|
|
141
|
+
const url = new url_1.URL(urlpath);
|
|
142
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
135
148
|
}
|
|
136
149
|
exports.isURL = isURL;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
150
|
+
function fileExists(name) {
|
|
151
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
try {
|
|
153
|
+
if ((yield lstat(name)).isFile()) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
throw new specification_file_1.ErrorLoadingSpec('file', name);
|
|
141
157
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
catch (e) {
|
|
145
|
-
throw new specification_file_1.ErrorLoadingSpec('file', name);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.fileExists = fileExists;
|
|
149
|
-
async function loadFromContext(contextName) {
|
|
150
|
-
try {
|
|
151
|
-
const context = await (0, Context_1.loadContext)(contextName);
|
|
152
|
-
return Specification.fromFile(context);
|
|
153
|
-
}
|
|
154
|
-
catch (error) {
|
|
155
|
-
if (error instanceof context_error_1.MissingContextFileError) {
|
|
156
|
-
throw new specification_file_1.ErrorLoadingSpec();
|
|
158
|
+
catch (e) {
|
|
159
|
+
throw new specification_file_1.ErrorLoadingSpec('file', name);
|
|
157
160
|
}
|
|
158
|
-
|
|
159
|
-
}
|
|
161
|
+
});
|
|
160
162
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
+
exports.fileExists = fileExists;
|
|
164
|
+
function loadFromContext(contextName) {
|
|
165
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
163
166
|
try {
|
|
164
|
-
const
|
|
165
|
-
return
|
|
167
|
+
const context = yield (0, Context_1.loadContext)(contextName);
|
|
168
|
+
return Specification.fromFile(context);
|
|
166
169
|
}
|
|
167
|
-
catch (
|
|
168
|
-
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (error instanceof context_error_1.MissingContextFileError) {
|
|
172
|
+
throw new specification_file_1.ErrorLoadingSpec();
|
|
173
|
+
}
|
|
174
|
+
throw error;
|
|
169
175
|
}
|
|
170
|
-
})
|
|
171
|
-
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function detectSpecFile() {
|
|
179
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
const existingFileNames = yield Promise.all(allowedFileNames.map((filename) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
try {
|
|
182
|
+
const exists = yield fileExists(path_1.default.resolve(process.cwd(), filename));
|
|
183
|
+
return exists ? filename : undefined;
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
// We did our best...
|
|
187
|
+
}
|
|
188
|
+
})));
|
|
189
|
+
return existingFileNames.find(filename => filename !== undefined);
|
|
190
|
+
});
|
|
172
191
|
}
|
package/lib/utils/generator.js
CHANGED
|
@@ -7,9 +7,11 @@ const fs = tslib_1.__importStar(require("fs"));
|
|
|
7
7
|
const util_1 = require("util");
|
|
8
8
|
const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
|
|
9
9
|
const lstat = (0, util_1.promisify)(fs.lstat);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
function isLocalTemplate(templatePath) {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const stats = yield lstat(templatePath);
|
|
13
|
+
return stats.isSymbolicLink();
|
|
14
|
+
});
|
|
13
15
|
}
|
|
14
16
|
exports.isLocalTemplate = isLocalTemplate;
|
|
15
17
|
class Watcher {
|
|
@@ -45,11 +47,13 @@ class Watcher {
|
|
|
45
47
|
* This method initiate the watch for change in all files
|
|
46
48
|
* @param {*} callback called when the file(s) change
|
|
47
49
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
watch(changeCallback, errorCallback) {
|
|
51
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
for (const index in this.paths) {
|
|
53
|
+
const path = this.paths[String(index)];
|
|
54
|
+
this.initiateWatchOnPath(path, changeCallback, errorCallback);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
53
57
|
}
|
|
54
58
|
/**
|
|
55
59
|
* Should be called when a file has changed one way or another.
|
|
@@ -68,11 +72,11 @@ class Watcher {
|
|
|
68
72
|
if (this.fsWait) {
|
|
69
73
|
return;
|
|
70
74
|
}
|
|
71
|
-
this.fsWait = setTimeout(
|
|
72
|
-
|
|
75
|
+
this.fsWait = setTimeout(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
yield changeCallback(this.filesChanged);
|
|
73
77
|
this.filesChanged = {};
|
|
74
78
|
this.fsWait = false;
|
|
75
|
-
}, 500);
|
|
79
|
+
}), 500);
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
catch (e) {
|