@asyncapi/generator 2.7.0 → 2.8.0
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 +43 -0
- package/docs/api.md +33 -0
- package/docs/baked-in-templates.md +100 -0
- package/docs/configuration-file.md +49 -31
- package/docs/template.md +22 -3
- package/lib/generator.js +31 -3
- package/lib/templates/BakedInTemplatesList.json +20 -0
- package/lib/templates/bakedInTemplates.js +53 -0
- package/package.json +9 -5
- package/test/__mocks__/@npmcli/arborist.js +0 -11
- package/test/__mocks__/@npmcli/config.js +0 -3
- package/test/__mocks__/fs.extra.js +0 -3
- package/test/__mocks__/loglevel.js +0 -3
- package/test/__mocks__/resolve-from.js +0 -8
- package/test/__mocks__/resolve-pkg.js +0 -8
- package/test/__snapshots__/integration.test.js.snap +0 -419
- package/test/docs/apiwithref.json +0 -41
- package/test/docs/dummy.yml +0 -390
- package/test/docs/dummyV3.yml +0 -31
- package/test/docs/shared.json +0 -27
- package/test/docs/ws.yml +0 -36
- package/test/generator.test.js +0 -629
- package/test/hooksRegistry.test.js +0 -173
- package/test/integration.test.js +0 -203
- package/test/parser.test.js +0 -205
- package/test/renderer.test.js +0 -62
- package/test/templateConfigValidator.test.js +0 -294
- package/test/test-project/.yarncr.yml +0 -3
- package/test/test-project/README.md +0 -8
- package/test/test-project/docker-compose.yml +0 -16
- package/test/test-project/package.json +0 -24
- package/test/test-project/test-global.test.js +0 -37
- package/test/test-project/test-project.test.js +0 -102
- package/test/test-project/test-registry.test.js +0 -62
- package/test/test-project/test.sh +0 -104
- package/test/test-project/verdaccio/config.yaml +0 -22
- package/test/test-project/verdaccio/htpasswd +0 -1
- package/test/test-templates/nunjucks-template/package-lock.json +0 -4062
- package/test/test-templates/nunjucks-template/package.json +0 -21
- package/test/test-templates/nunjucks-template/template/test-file.md +0 -5
- package/test/test-templates/react-template/.ageneratorrc +0 -33
- package/test/test-templates/react-template/package.json +0 -14
- package/test/test-templates/react-template/template/conditionalFile.txt +0 -0
- package/test/test-templates/react-template/template/conditionalFolder/conditionalFile.txt +0 -0
- package/test/test-templates/react-template/template/conditionalFolder2/input.txt +0 -0
- package/test/test-templates/react-template/template/models.js +0 -6
- package/test/test-templates/react-template/template/test-file.md.js +0 -11
- package/test/utils.test.js +0 -129
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "nunjucks-template",
|
|
3
|
-
"version": "0.0.1",
|
|
4
|
-
"description": "Simple nunjucks-based template that showcases different generator features that we can test in integration tests",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
-
},
|
|
8
|
-
"generator": {
|
|
9
|
-
"parameters": {
|
|
10
|
-
"version": {
|
|
11
|
-
"description": "Custom version to be used"
|
|
12
|
-
},
|
|
13
|
-
"mode": {
|
|
14
|
-
"description": "development or production"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@asyncapi/generator-react-sdk": "^1.1.2"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
renderer: react
|
|
2
|
-
apiVersion: v3
|
|
3
|
-
hooks:
|
|
4
|
-
"@asyncapi/generator-hooks": createAsyncapiFile
|
|
5
|
-
parameters:
|
|
6
|
-
version:
|
|
7
|
-
description: "Custom version to be used"
|
|
8
|
-
mode:
|
|
9
|
-
description: "development or production"
|
|
10
|
-
asyncapiFileDir:
|
|
11
|
-
description: >
|
|
12
|
-
This template by default also outputs the AsyncAPI document that was passed as input.
|
|
13
|
-
You can specify with this parameter what should be the location of this AsyncAPI document,
|
|
14
|
-
relative to specified template output.
|
|
15
|
-
singleFile:
|
|
16
|
-
description: "Allow to generate conditionalGeneration file only if singleFile is set to false"
|
|
17
|
-
singleFolder:
|
|
18
|
-
description: "Allow to generate conditionalGeneration folder only if singleFolder is set to false"
|
|
19
|
-
conditionalGeneration:
|
|
20
|
-
conditionalFolder:
|
|
21
|
-
parameter: singleFolder
|
|
22
|
-
validation:
|
|
23
|
-
not:
|
|
24
|
-
const: "true"
|
|
25
|
-
conditionalFile.txt:
|
|
26
|
-
parameter: singleFile
|
|
27
|
-
validation:
|
|
28
|
-
not:
|
|
29
|
-
const: "true"
|
|
30
|
-
conditionalFolder2/input.txt:
|
|
31
|
-
parameter: singleFile
|
|
32
|
-
validation:
|
|
33
|
-
enum: ["false"]
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-template",
|
|
3
|
-
"version": "0.0.1",
|
|
4
|
-
"description": "Simple react-based template that showcases different generator features that we can test in integration tests",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
-
},
|
|
8
|
-
"dependencies": {
|
|
9
|
-
"@asyncapi/generator-react-sdk": "^1.1.2",
|
|
10
|
-
"@asyncapi/generator-components": "1.0.0"
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//TODO: at the moment this template as devDependency set to "@asyncapi/generator-components": "*" in generator root but this is temporary to not complicate one PR too much. We still need to explore concept of having just one dependency in the template pointing to @asyncapi/generator and noting else, and components, react sdks and others should be just part of @asyncapi/generator dependency
|
|
2
|
-
import { Models } from '@asyncapi/generator-components';
|
|
3
|
-
|
|
4
|
-
export default async function({ asyncapi }) {
|
|
5
|
-
return await Models({asyncapi, language: 'csharp'});
|
|
6
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { File, Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
-
|
|
3
|
-
export default function({ asyncapi, params }) {
|
|
4
|
-
return (
|
|
5
|
-
<File name="test-file.md">
|
|
6
|
-
<Text>This is a markdown file for my application.</Text>
|
|
7
|
-
<Text>App name is: **{ asyncapi.info().title() }**</Text>
|
|
8
|
-
<Text>Version {params.version} running on {params.mode} mode </Text>
|
|
9
|
-
</File>
|
|
10
|
-
);
|
|
11
|
-
}
|
package/test/utils.test.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/* eslint-disable sonarjs/no-duplicate-string */
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const Generator = require('../lib/generator');
|
|
4
|
-
const log = require('loglevel');
|
|
5
|
-
const utils = jest.requireActual('../lib/utils');
|
|
6
|
-
|
|
7
|
-
const logMessage = require('./../lib/logMessages.js');
|
|
8
|
-
|
|
9
|
-
describe('Utils', () => {
|
|
10
|
-
describe('#getTemplateDetails', () => {
|
|
11
|
-
let resolvePkg, resolveFrom;
|
|
12
|
-
const templateNpmName = 'nameOfTestTemplate';
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
resolvePkg = require('resolve-pkg');
|
|
16
|
-
resolveFrom = require('resolve-from');
|
|
17
|
-
jest.mock(path.resolve('./testTemplate', 'package.json'), () => ({ name: 'nameOfTestTemplate' }), { virtual: true });
|
|
18
|
-
jest.mock(path.resolve(Generator.DEFAULT_TEMPLATES_DIR, templateNpmName, 'package.json'), () => ({ name: 'nameOfTestTemplate' }), { virtual: true });
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('works with a file system path', () => {
|
|
22
|
-
log.debug = jest.fn();
|
|
23
|
-
utils.isFileSystemPath = jest.fn(() => true);
|
|
24
|
-
const templatePath = './testTemplate';
|
|
25
|
-
const result = utils.getTemplateDetails(templatePath, 'package.json');
|
|
26
|
-
expect(log.debug).toHaveBeenCalledWith(logMessage.NODE_MODULES_INSTALL);
|
|
27
|
-
expect(result).toStrictEqual({
|
|
28
|
-
name: templateNpmName,
|
|
29
|
-
pkgPath: path.resolve('./testTemplate')
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('works with an npm package', () => {
|
|
34
|
-
log.debug = jest.fn();
|
|
35
|
-
utils.isFileSystemPath = jest.fn(() => false);
|
|
36
|
-
const packagePath = path.join(Generator.DEFAULT_TEMPLATES_DIR, templateNpmName);
|
|
37
|
-
resolvePkg.__resolvePkgValue = packagePath;
|
|
38
|
-
const result = utils.getTemplateDetails(templateNpmName, 'package.json');
|
|
39
|
-
expect(log.debug).not.toHaveBeenCalledWith(logMessage.NODE_MODULES_INSTALL);
|
|
40
|
-
expect(log.debug).not.toHaveBeenCalledWith(logMessage.templateNotFound(templateNpmName));
|
|
41
|
-
expect(result).toStrictEqual({
|
|
42
|
-
name: templateNpmName,
|
|
43
|
-
pkgPath: packagePath
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('works with global npm package', () => {
|
|
48
|
-
log.debug = jest.fn();
|
|
49
|
-
utils.isFileSystemPath = jest.fn(() => false);
|
|
50
|
-
resolvePkg.__resolvePkgValue = undefined;
|
|
51
|
-
resolveFrom.__resolveFromValue = path.join(Generator.DEFAULT_TEMPLATES_DIR, templateNpmName, 'package.json');
|
|
52
|
-
utils.getTemplateDetails(templateNpmName, 'package.json');
|
|
53
|
-
expect(log.debug).not.toHaveBeenCalledWith(logMessage.NODE_MODULES_INSTALL);
|
|
54
|
-
expect(log.debug).toHaveBeenCalledWith(logMessage.templateNotFound(templateNpmName));
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('doesnt work with a url', async () => {
|
|
58
|
-
resolvePkg.__resolvePkgValue = undefined;
|
|
59
|
-
resolveFrom.__resolveFromValue = undefined;
|
|
60
|
-
const result = utils.getTemplateDetails(templateNpmName, 'package.json');
|
|
61
|
-
expect(result).toStrictEqual(undefined);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('#exists', () => {
|
|
66
|
-
it('should return true if file exist', async () => {
|
|
67
|
-
const exists = await utils.exists(`${process.cwd()}/package.json`);
|
|
68
|
-
expect(exists).toBeTruthy();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should return false if file does not exist', async () => {
|
|
72
|
-
const exists = await utils.exists('./invalid-file');
|
|
73
|
-
expect(exists).toBeFalsy();
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('#isJsFile',() => {
|
|
78
|
-
it('should return true if file extension is .js', () => {
|
|
79
|
-
const isJsFile = utils.isJsFile('./valid-file.js');
|
|
80
|
-
expect(isJsFile).toBeTruthy();
|
|
81
|
-
});
|
|
82
|
-
it('should return true if file extension is .jsx', () => {
|
|
83
|
-
const isJsFile = utils.isJsFile('./valid-file.jsx');
|
|
84
|
-
expect(isJsFile).toBeTruthy();
|
|
85
|
-
});
|
|
86
|
-
it('should return true if file extension is .cjs', () => {
|
|
87
|
-
const isJsFile = utils.isJsFile('./valid-file.cjs');
|
|
88
|
-
expect(isJsFile).toBeTruthy();
|
|
89
|
-
});
|
|
90
|
-
it('should return false if it is not a JS file', () => {
|
|
91
|
-
const isJsFile = utils.isJsFile('./invalid-file.txt');
|
|
92
|
-
expect(isJsFile).toBeFalsy();
|
|
93
|
-
});
|
|
94
|
-
it('should return false if it is not a JS file', () => {
|
|
95
|
-
const isJsFile = utils.isJsFile('./invalid-file');
|
|
96
|
-
expect(isJsFile).toBeFalsy();
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('#isReactTemplate', () => {
|
|
101
|
-
it('should return true if it is a react template', () => {
|
|
102
|
-
const templateConfig = {
|
|
103
|
-
renderer: 'react'
|
|
104
|
-
};
|
|
105
|
-
const isReactTemplate = utils.isReactTemplate(templateConfig);
|
|
106
|
-
expect(isReactTemplate).toBeTruthy();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should return false if it is not a react template', () => {
|
|
110
|
-
const templateConfig = {
|
|
111
|
-
renderer: 'nunjucks'
|
|
112
|
-
};
|
|
113
|
-
const isReactTemplate = utils.isReactTemplate(templateConfig);
|
|
114
|
-
expect(isReactTemplate).toBeFalsy();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should return false if template config is not specified', () => {
|
|
118
|
-
const templateConfig = {};
|
|
119
|
-
const isReactTemplate = utils.isReactTemplate(templateConfig);
|
|
120
|
-
expect(isReactTemplate).toBeFalsy();
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should return false if template config is undefined', () => {
|
|
124
|
-
const templateConfig = undefined;
|
|
125
|
-
const isReactTemplate = utils.isReactTemplate(templateConfig);
|
|
126
|
-
expect(isReactTemplate).toBeFalsy();
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|