@schalkneethling/miyagi-core 4.4.2 → 4.4.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/README.md +7 -2
- package/api/app.js +16 -16
- package/api/index.js +263 -262
- package/bin/miyagi.js +1 -1
- package/dist/css/iframe.css +6 -30
- package/frontend/assets/css/iframe/accordion-tabs.css +39 -39
- package/frontend/assets/css/iframe/jsontree.js.css +149 -149
- package/frontend/assets/css/iframe/prism.css +45 -45
- package/frontend/assets/css/iframe/styleguide/colors.css +27 -27
- package/frontend/assets/css/iframe/styleguide/fonts.css +23 -23
- package/frontend/assets/css/iframe/styleguide/index.css +58 -58
- package/frontend/assets/css/iframe/styleguide/spacings.css +10 -10
- package/frontend/assets/css/iframe.css +191 -191
- package/frontend/assets/css/main/menu/config-switcher.css +21 -21
- package/frontend/assets/css/main/menu/config-switchers.css +34 -34
- package/frontend/assets/css/main/menu/goto.css +16 -16
- package/frontend/assets/css/main/menu/nav.css +49 -49
- package/frontend/assets/css/main/menu/search.css +34 -34
- package/frontend/assets/css/main/menu/title.css +18 -18
- package/frontend/assets/css/main/menu.css +89 -89
- package/frontend/assets/css/main/reset.css +47 -47
- package/frontend/assets/css/main.css +41 -41
- package/frontend/assets/css/shared.css +16 -16
- package/frontend/assets/css/tokens.css +108 -107
- package/frontend/assets/js/_accordion-tabs.js +392 -392
- package/frontend/assets/js/_goto.js +59 -59
- package/frontend/assets/js/_iframe-links.js +14 -14
- package/frontend/assets/js/_is-triggered.js +3 -3
- package/frontend/assets/js/_main.js +369 -369
- package/frontend/assets/js/_mock-data.js +8 -8
- package/frontend/assets/js/_prism.js +1082 -1081
- package/frontend/assets/js/_search.js +186 -186
- package/frontend/assets/js/_socket.js +44 -44
- package/frontend/assets/js/config-switcher/development-mode.js +38 -38
- package/frontend/assets/js/config-switcher/index.js +55 -55
- package/frontend/assets/js/config-switcher/text-direction.js +22 -22
- package/frontend/assets/js/config-switcher/theme.js +68 -68
- package/frontend/assets/js/iframe.build.js +25 -25
- package/frontend/assets/js/iframe.js +38 -38
- package/frontend/assets/js/jsontree.js +979 -976
- package/frontend/assets/js/main.build.js +29 -29
- package/frontend/assets/js/main.js +31 -31
- package/frontend/assets/js/styleguide/color-converter.js +652 -652
- package/frontend/assets/js/styleguide/index.js +100 -100
- package/lib/build/index.js +1014 -1020
- package/lib/cli/app.js +16 -16
- package/lib/cli/component.js +50 -50
- package/lib/cli/doctor.js +130 -121
- package/lib/cli/drupal-assets.js +163 -157
- package/lib/cli/lint.js +196 -196
- package/lib/cli/run.js +150 -146
- package/lib/config.js +86 -86
- package/lib/constants/lint-log-levels.js +6 -6
- package/lib/drupal/load-assets-config.js +59 -60
- package/lib/drupal/resolve-library-assets.js +132 -141
- package/lib/errors.js +20 -20
- package/lib/generator/component.js +124 -124
- package/lib/generator/mocks.js +156 -156
- package/lib/helpers.js +68 -68
- package/lib/i18n/en.js +93 -93
- package/lib/i18n/index.js +8 -8
- package/lib/index.js +13 -13
- package/lib/init/args.js +153 -153
- package/lib/init/config.js +452 -438
- package/lib/init/engines.js +41 -41
- package/lib/init/index.js +83 -83
- package/lib/init/rendering.js +3 -3
- package/lib/init/static.js +90 -90
- package/lib/init/twing/cache.js +27 -27
- package/lib/init/twing/functions.js +37 -37
- package/lib/init/views.js +5 -5
- package/lib/logger.js +72 -72
- package/lib/mocks/get.js +88 -88
- package/lib/mocks/index.js +2 -2
- package/lib/mocks/resolve/ref.js +447 -447
- package/lib/mocks/resolve/tpl.js +218 -218
- package/lib/mocks/resolve.js +154 -154
- package/lib/render/helpers/resolve-assets.js +29 -39
- package/lib/render/helpers.js +27 -27
- package/lib/render/index.js +18 -18
- package/lib/render/views/iframe/component.docs.js +50 -50
- package/lib/render/views/iframe/component.js +249 -248
- package/lib/render/views/iframe/design-tokens/colors.js +38 -38
- package/lib/render/views/iframe/design-tokens/index.js +3 -3
- package/lib/render/views/iframe/design-tokens/sizes.js +35 -35
- package/lib/render/views/iframe/design-tokens/typography.js +37 -37
- package/lib/render/views/iframe/docs.js +42 -42
- package/lib/render/views/iframe/index.js +28 -28
- package/lib/render/views/iframe/variation.js +89 -89
- package/lib/render/views/iframe/variation.standalone.js +69 -68
- package/lib/render/views/main/component.docs.js +38 -38
- package/lib/render/views/main/component.js +55 -55
- package/lib/render/views/main/design-tokens.js +38 -38
- package/lib/render/views/main/docs.js +33 -33
- package/lib/render/views/main/index.js +33 -33
- package/lib/state/components.js +99 -99
- package/lib/state/css.js +33 -33
- package/lib/state/docs.js +72 -72
- package/lib/state/file-contents.js +154 -154
- package/lib/state/helpers.js +53 -53
- package/lib/state/index.js +39 -39
- package/lib/state/menu/index.js +202 -202
- package/lib/state/menu/structure.js +84 -84
- package/lib/state/partials.js +12 -12
- package/lib/state/source-tree.js +51 -51
- package/lib/styleguide/color-names.js +148 -148
- package/lib/styleguide/colors.js +113 -113
- package/lib/styleguide/helpers.js +33 -33
- package/lib/styleguide/index.js +4 -4
- package/lib/styleguide/media-queries.js +18 -18
- package/lib/styleguide/spacings.js +22 -22
- package/lib/styleguide/typography.js +46 -46
- package/lib/validator/mocks.js +110 -83
- package/lib/validator/schemas.js +236 -227
- package/package.json +118 -117
|
@@ -12,21 +12,21 @@ import { t } from "../i18n/index.js";
|
|
|
12
12
|
* @returns {Promise<string>}
|
|
13
13
|
*/
|
|
14
14
|
export default async function componentGenerator({ component, fileTypes }) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
try {
|
|
16
|
+
await createComponentFolder(component);
|
|
17
|
+
await createComponentFiles(
|
|
18
|
+
global.config.files,
|
|
19
|
+
component,
|
|
20
|
+
fileTypes,
|
|
21
|
+
global.config.components.folder,
|
|
22
|
+
);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
return Promise.resolve(
|
|
25
|
+
t("generator.component.done").replace("{{component}}", component),
|
|
26
|
+
);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
return Promise.reject(err);
|
|
29
|
+
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -36,7 +36,7 @@ export default async function componentGenerator({ component, fileTypes }) {
|
|
|
36
36
|
* @returns {Array} all file paths that should be created
|
|
37
37
|
*/
|
|
38
38
|
function getFiles(fileNames, fileTypes) {
|
|
39
|
-
|
|
39
|
+
return fileTypes.map((fileType) => fileNames[fileType]);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -47,57 +47,57 @@ function getFiles(fileNames, fileTypes) {
|
|
|
47
47
|
* @returns {string} dummy file content based on the given file type
|
|
48
48
|
*/
|
|
49
49
|
function getDummyFileContent(fileType, filesConfig, componentPath) {
|
|
50
|
-
|
|
50
|
+
let str;
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
switch (fileType) {
|
|
53
|
+
case "mocks":
|
|
54
|
+
{
|
|
55
|
+
const data = {
|
|
56
|
+
$variants: [
|
|
57
|
+
{
|
|
58
|
+
$name: "",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
if (["yaml", "yml"].includes(filesConfig.mocks.extension[0])) {
|
|
64
|
+
str = jsonToYaml.dump(data);
|
|
65
|
+
} else {
|
|
66
|
+
str = `${JSON.stringify(data, null, 2)}\n`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case "schema":
|
|
71
|
+
{
|
|
72
|
+
const id = path.join("/", componentPath);
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
if (["yaml", "yml"].includes(filesConfig.schema.extension)) {
|
|
75
|
+
str = `$schema: "http://json-schema.org/draft-07/schema"
|
|
76
76
|
$id: "${id}"
|
|
77
77
|
additionalProperties: false
|
|
78
78
|
properties:
|
|
79
79
|
required:
|
|
80
80
|
`;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
81
|
+
} else {
|
|
82
|
+
str = `${JSON.stringify(
|
|
83
|
+
{
|
|
84
|
+
$schema: "http://json-schema.org/draft-07/schema",
|
|
85
|
+
$id: id,
|
|
86
|
+
additionalProperties: false,
|
|
87
|
+
properties: {},
|
|
88
|
+
required: [],
|
|
89
|
+
},
|
|
90
|
+
null,
|
|
91
|
+
2,
|
|
92
|
+
)}\n`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
str = "";
|
|
98
|
+
}
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
return str;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
/**
|
|
@@ -109,39 +109,39 @@ required:
|
|
|
109
109
|
* @returns {Promise} gets resolved when all files have been created
|
|
110
110
|
*/
|
|
111
111
|
async function createComponentFiles(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
filesConfig,
|
|
113
|
+
componentPath,
|
|
114
|
+
fileTypes,
|
|
115
|
+
componentFolder,
|
|
116
116
|
) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
const componentName = path.basename(componentPath);
|
|
118
|
+
const fileNames = getFileNames(filesConfig, componentName);
|
|
119
|
+
const files = getFiles(fileNames, fileTypes);
|
|
120
|
+
const entries = Object.entries(fileNames);
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
for (const [type, file] of entries) {
|
|
123
|
+
if (files.includes(file)) {
|
|
124
|
+
const fullFilePath = path.join(
|
|
125
|
+
process.env.INIT_CWD || process.cwd(),
|
|
126
|
+
componentPath,
|
|
127
|
+
file,
|
|
128
|
+
);
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
130
|
+
try {
|
|
131
|
+
await writeFile(
|
|
132
|
+
fullFilePath,
|
|
133
|
+
getDummyFileContent(
|
|
134
|
+
type,
|
|
135
|
+
filesConfig,
|
|
136
|
+
path.relative(componentFolder, componentPath),
|
|
137
|
+
),
|
|
138
|
+
{ flag: "wx" },
|
|
139
|
+
);
|
|
140
|
+
} catch (err) {
|
|
141
|
+
return Promise.reject(err.message);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/**
|
|
@@ -151,21 +151,21 @@ async function createComponentFiles(
|
|
|
151
151
|
* @returns {object} all file names based on the user configuration
|
|
152
152
|
*/
|
|
153
153
|
function getFileNames(filesConfig, componentName) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
154
|
+
return {
|
|
155
|
+
tpl: `${helpers.getResolvedFileName(
|
|
156
|
+
filesConfig.templates.name,
|
|
157
|
+
componentName,
|
|
158
|
+
)}.${filesConfig.templates.extension}`,
|
|
159
|
+
mocks: `${filesConfig.mocks.name}.${filesConfig.mocks.extension[0]}`,
|
|
160
|
+
docs: "README.md",
|
|
161
|
+
css: `${helpers.getResolvedFileName(filesConfig.css.name, componentName)}.${
|
|
162
|
+
filesConfig.css.extension
|
|
163
|
+
}`,
|
|
164
|
+
js: `${helpers.getResolvedFileName(filesConfig.js.name, componentName)}.${
|
|
165
|
+
filesConfig.js.extension
|
|
166
|
+
}`,
|
|
167
|
+
schema: `${filesConfig.schema.name}.${filesConfig.schema.extension}`,
|
|
168
|
+
};
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
/**
|
|
@@ -174,26 +174,26 @@ function getFileNames(filesConfig, componentName) {
|
|
|
174
174
|
* @returns {Promise} gets resolved when the folder has been created
|
|
175
175
|
*/
|
|
176
176
|
async function createComponentFolder(folder) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
177
|
+
try {
|
|
178
|
+
await mkdir(
|
|
179
|
+
/*
|
|
180
|
+
* When using `pnpm/yarn/npm miyagi new …`, `process.env.INIT_CWD` equals
|
|
181
|
+
* the current working directory, so also subdirectories of where
|
|
182
|
+
* the package.json is located. In this case `process.cwd()` always
|
|
183
|
+
* equals the root directory though.
|
|
184
|
+
* When using node directly, `process.env.INIT_CWD` is not available,
|
|
185
|
+
* but `process.cwd()` is always the current working directory, so
|
|
186
|
+
* also subdirectories.
|
|
187
|
+
* So, if INIT_CWD is available, we know it is the directory the user
|
|
188
|
+
* cd'ed into, if it not available, then we use process.cwd(), which
|
|
189
|
+
* in that case is also the directory the user cd'ed into.
|
|
190
|
+
* It is important that we let the user create a component from their
|
|
191
|
+
* current working directory, so they can benefit from autocompletion.
|
|
192
|
+
*/
|
|
193
|
+
path.join(process.env.INIT_CWD || process.cwd(), folder),
|
|
194
|
+
{ recursive: true },
|
|
195
|
+
);
|
|
196
|
+
} catch (err) {
|
|
197
|
+
return err;
|
|
198
|
+
}
|
|
199
199
|
}
|
package/lib/generator/mocks.js
CHANGED
|
@@ -13,112 +13,112 @@ import { t } from "../i18n/index.js";
|
|
|
13
13
|
* @returns {Promise<{success, message?}>}
|
|
14
14
|
*/
|
|
15
15
|
export default async function mockGenerator(folderPath, filesConfig) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
16
|
+
if (!folderPath) {
|
|
17
|
+
return {
|
|
18
|
+
success: false,
|
|
19
|
+
message: {
|
|
20
|
+
type: "error",
|
|
21
|
+
text: t("dataGenerator.noComponentFolderDefined"),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
log("info", t("dataGenerator.starting").replace("{{fileName}}", folderPath));
|
|
27
|
+
|
|
28
|
+
const mockFilePath = `${path.join(folderPath, filesConfig.mocks.name)}.${
|
|
29
|
+
filesConfig.mocks.extension[0]
|
|
30
|
+
}`;
|
|
31
|
+
const schemaFilePath = `${path.join(folderPath, filesConfig.schema.name)}.${
|
|
32
|
+
filesConfig.schema.extension
|
|
33
|
+
}`;
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
status,
|
|
37
|
+
data: schemaData,
|
|
38
|
+
message,
|
|
39
|
+
} = await readAndParseFile(schemaFilePath, filesConfig);
|
|
40
|
+
|
|
41
|
+
if (status === "success") {
|
|
42
|
+
try {
|
|
43
|
+
const content = getContent(filesConfig.mocks.extension[0], schemaData);
|
|
44
|
+
|
|
45
|
+
const { status, data } = await readAndParseFile(
|
|
46
|
+
mockFilePath,
|
|
47
|
+
filesConfig,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (status === "success") {
|
|
51
|
+
if (data === "") {
|
|
52
|
+
const { status, message } = await createFile(content, mockFilePath);
|
|
53
|
+
|
|
54
|
+
if (status === "error") {
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
message: {
|
|
58
|
+
type: "error",
|
|
59
|
+
text: message,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
} else {
|
|
63
|
+
return {
|
|
64
|
+
success: true,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
message: {
|
|
71
|
+
type: "error",
|
|
72
|
+
text: t("dataGenerator.dataFileExists").replace(
|
|
73
|
+
"{{fileName}}",
|
|
74
|
+
mockFilePath,
|
|
75
|
+
),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const { status, message } = await createFile(content, mockFilePath);
|
|
81
|
+
|
|
82
|
+
if (status === "error") {
|
|
83
|
+
return {
|
|
84
|
+
success: false,
|
|
85
|
+
message: {
|
|
86
|
+
type: "error",
|
|
87
|
+
text: message,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
} else {
|
|
91
|
+
return {
|
|
92
|
+
success: true,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// eslint-disable-next-line no-unused-vars
|
|
97
|
+
} catch (e) {
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
message: {
|
|
101
|
+
type: "error",
|
|
102
|
+
text: t("dataGenerator.schemaFileCantBeParsed").replace(
|
|
103
|
+
"{{fileName}}",
|
|
104
|
+
schemaFilePath,
|
|
105
|
+
),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
return {
|
|
111
|
+
success: false,
|
|
112
|
+
message: {
|
|
113
|
+
type: "error",
|
|
114
|
+
text: t("dataGenerator.noSchemaFile").replace(
|
|
115
|
+
"{{fileName}}",
|
|
116
|
+
schemaFilePath,
|
|
117
|
+
),
|
|
118
|
+
verbose: message,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/**
|
|
@@ -128,26 +128,26 @@ export default async function mockGenerator(folderPath, filesConfig) {
|
|
|
128
128
|
* @returns {string} the dummy mock data
|
|
129
129
|
*/
|
|
130
130
|
function getContent(fileType, schema) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
131
|
+
let content;
|
|
132
|
+
const data = schemaFaker.sample(schema);
|
|
133
|
+
|
|
134
|
+
switch (fileType) {
|
|
135
|
+
case "yaml":
|
|
136
|
+
case "yml":
|
|
137
|
+
content = jsYaml.dump(data);
|
|
138
|
+
break;
|
|
139
|
+
case "json":
|
|
140
|
+
content = JSON.stringify(data, null, 2);
|
|
141
|
+
break;
|
|
142
|
+
case "js":
|
|
143
|
+
content = `module.exports = ${JSON.stringify(data, null, 2)}
|
|
144
144
|
`;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
content = "";
|
|
148
|
+
}
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
return content;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
/**
|
|
@@ -157,18 +157,18 @@ function getContent(fileType, schema) {
|
|
|
157
157
|
* @returns {Promise<object>}
|
|
158
158
|
*/
|
|
159
159
|
async function createFile(content, mockFilePath) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
160
|
+
try {
|
|
161
|
+
await writeFile(mockFilePath, content);
|
|
162
|
+
return {
|
|
163
|
+
status: "success",
|
|
164
|
+
message: t("generator.done"),
|
|
165
|
+
};
|
|
166
|
+
} catch (err) {
|
|
167
|
+
return {
|
|
168
|
+
status: "error",
|
|
169
|
+
message: err.message,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/**
|
|
@@ -178,24 +178,24 @@ async function createFile(content, mockFilePath) {
|
|
|
178
178
|
* @returns {Promise<object>}
|
|
179
179
|
*/
|
|
180
180
|
async function readAndParseFile(filePath, filesConfig) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
181
|
+
try {
|
|
182
|
+
const result = await readFile(filePath, "utf8");
|
|
183
|
+
let data;
|
|
184
|
+
|
|
185
|
+
if (["yaml", "yml"].includes(filesConfig.schema.extension)) {
|
|
186
|
+
data = jsYaml.load(result);
|
|
187
|
+
} else {
|
|
188
|
+
data = JSON.parse(result);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
status: "success",
|
|
193
|
+
data,
|
|
194
|
+
};
|
|
195
|
+
} catch (err) {
|
|
196
|
+
return {
|
|
197
|
+
status: "error",
|
|
198
|
+
message: err.message,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
201
|
}
|