@contentstack/cli-audit 1.0.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/LICENSE +21 -0
- package/README.md +402 -0
- package/bin/dev +5 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/lib/base-command.d.ts +45 -0
- package/lib/base-command.js +88 -0
- package/lib/commands/cm/stacks/audit/fix.d.ts +8 -0
- package/lib/commands/cm/stacks/audit/fix.js +11 -0
- package/lib/commands/cm/stacks/audit/index.d.ts +62 -0
- package/lib/commands/cm/stacks/audit/index.js +242 -0
- package/lib/config/index.d.ts +28 -0
- package/lib/config/index.js +30 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -0
- package/lib/messages/index.d.ts +33 -0
- package/lib/messages/index.js +46 -0
- package/lib/modules/content-types.d.ts +96 -0
- package/lib/modules/content-types.js +209 -0
- package/lib/modules/entries.d.ts +121 -0
- package/lib/modules/entries.js +288 -0
- package/lib/modules/global-fields.d.ts +27 -0
- package/lib/modules/global-fields.js +43 -0
- package/lib/modules/index.d.ts +4 -0
- package/lib/modules/index.js +10 -0
- package/lib/types/content-types.d.ts +69 -0
- package/lib/types/content-types.js +12 -0
- package/lib/types/entries.d.ts +46 -0
- package/lib/types/entries.js +2 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.js +6 -0
- package/lib/types/utils.d.ts +18 -0
- package/lib/types/utils.js +2 -0
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.js +8 -0
- package/lib/util/log.d.ts +42 -0
- package/lib/util/log.js +153 -0
- package/oclif.manifest.json +134 -0
- package/package.json +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Contentstack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
<!-- Insert Nodejs CI here -->
|
|
2
|
+
<!-- Insert Audit version here -->
|
|
3
|
+
|
|
4
|
+
# @contentstack/cli-audit
|
|
5
|
+
Audit plugin
|
|
6
|
+
|
|
7
|
+
## How to install this plugin
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
$ csdx plugins:install @contentstack/cli-audit
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## How to use this plugin
|
|
14
|
+
|
|
15
|
+
This plugin requires you to be authenticated using [csdx auth:login](https://www.contentstack.com/docs/developers/cli/authenticate-with-the-cli/).
|
|
16
|
+
|
|
17
|
+
<!-- usage -->
|
|
18
|
+
```sh-session
|
|
19
|
+
$ npm install -g @contentstack/cli-audit
|
|
20
|
+
$ csdx COMMAND
|
|
21
|
+
running command...
|
|
22
|
+
$ csdx (--version|-v)
|
|
23
|
+
@contentstack/cli-audit/1.0.0 linux-x64 node-v18.18.0
|
|
24
|
+
$ csdx --help [COMMAND]
|
|
25
|
+
USAGE
|
|
26
|
+
$ csdx COMMAND
|
|
27
|
+
...
|
|
28
|
+
```
|
|
29
|
+
<!-- usagestop -->
|
|
30
|
+
|
|
31
|
+
# Commands
|
|
32
|
+
<!-- commands -->
|
|
33
|
+
* [`csdx cm::stacks:audit:fix`](#csdx-cmstacksauditfix)
|
|
34
|
+
* [`csdx cm:stacks:audit`](#csdx-cmstacksaudit)
|
|
35
|
+
* [`csdx cm:stacks:audit:fix`](#csdx-cmstacksauditfix-1)
|
|
36
|
+
* [`csdx help [COMMANDS]`](#csdx-help-commands)
|
|
37
|
+
* [`csdx plugins`](#csdx-plugins)
|
|
38
|
+
* [`csdx plugins:install PLUGIN...`](#csdx-pluginsinstall-plugin)
|
|
39
|
+
* [`csdx plugins:inspect PLUGIN...`](#csdx-pluginsinspect-plugin)
|
|
40
|
+
* [`csdx plugins:install PLUGIN...`](#csdx-pluginsinstall-plugin-1)
|
|
41
|
+
* [`csdx plugins:link PLUGIN`](#csdx-pluginslink-plugin)
|
|
42
|
+
* [`csdx plugins:uninstall PLUGIN...`](#csdx-pluginsuninstall-plugin)
|
|
43
|
+
* [`csdx plugins:uninstall PLUGIN...`](#csdx-pluginsuninstall-plugin-1)
|
|
44
|
+
* [`csdx plugins:uninstall PLUGIN...`](#csdx-pluginsuninstall-plugin-2)
|
|
45
|
+
* [`csdx plugins:update`](#csdx-pluginsupdate)
|
|
46
|
+
|
|
47
|
+
## `csdx cm::stacks:audit:fix`
|
|
48
|
+
|
|
49
|
+
Audit fix command
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
USAGE
|
|
53
|
+
$ csdx cm::stacks:audit:fix [-c <value>] [-d <value>]
|
|
54
|
+
|
|
55
|
+
FLAGS
|
|
56
|
+
-c, --config=<value> Path of the external config.
|
|
57
|
+
-d, --data-dir=<value> Path where the data is stored.
|
|
58
|
+
|
|
59
|
+
DESCRIPTION
|
|
60
|
+
Audit fix command
|
|
61
|
+
|
|
62
|
+
ALIASES
|
|
63
|
+
$ csdx cm::stacks:audit:fix
|
|
64
|
+
|
|
65
|
+
EXAMPLES
|
|
66
|
+
$ csdx cm::stacks:audit:fix
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
_See code: [src/commands/cm/stacks/audit/fix.ts](https://github.com/contentstack/audit/blob/main/packages/contentstack-audit/src/commands/cm/stacks/audit/fix.ts)_
|
|
70
|
+
|
|
71
|
+
## `csdx cm:stacks:audit`
|
|
72
|
+
|
|
73
|
+
Perform audits and find possible errors in the exported Contentstack data
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
USAGE
|
|
77
|
+
$ csdx cm:stacks:audit [-c <value>] [-d <value>] [--report-path <value>] [--modules
|
|
78
|
+
content-types|global-fields|entries] [--columns <value> | ] [--sort <value>] [--filter <value>] [--csv |
|
|
79
|
+
--no-truncate]
|
|
80
|
+
|
|
81
|
+
FLAGS
|
|
82
|
+
-c, --config=<value> Path of the external config.
|
|
83
|
+
-d, --data-dir=<value> Path where the data is stored.
|
|
84
|
+
--columns=<value> only show provided columns (comma-separated)
|
|
85
|
+
--csv output is csv format [alias: --output=csv]
|
|
86
|
+
--filter=<value> filter property by partial string matching, ex: name=foo
|
|
87
|
+
--modules=<option>... Provide the list of modules to be audited.
|
|
88
|
+
<options: content-types|global-fields|entries>
|
|
89
|
+
--no-truncate do not truncate output to fit screen
|
|
90
|
+
--report-path=<value> Path to store the audit reports.
|
|
91
|
+
--sort=<value> property to sort by (prepend '-' for descending)
|
|
92
|
+
|
|
93
|
+
DESCRIPTION
|
|
94
|
+
Perform audits and find possible errors in the exported Contentstack data
|
|
95
|
+
|
|
96
|
+
ALIASES
|
|
97
|
+
$ csdx cm:stacks:audit
|
|
98
|
+
|
|
99
|
+
EXAMPLES
|
|
100
|
+
$ csdx cm:stacks:audit
|
|
101
|
+
|
|
102
|
+
$ csdx cm:stacks:audit --report-path=<path>
|
|
103
|
+
|
|
104
|
+
$ csdx cm:stacks:audit --report-path=<path> --csv
|
|
105
|
+
|
|
106
|
+
$ csdx cm:stacks:audit --report-path=<path> --filter="name=<filter-value>"
|
|
107
|
+
|
|
108
|
+
$ csdx cm:stacks:audit --report-path=<path> --modules=content-types --filter="name="<filter-value>"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
_See code: [src/commands/cm/stacks/audit/index.ts](https://github.com/contentstack/audit/blob/main/packages/contentstack-audit/src/commands/cm/stacks/audit/index.ts)_
|
|
112
|
+
|
|
113
|
+
## `csdx cm:stacks:audit:fix`
|
|
114
|
+
|
|
115
|
+
Audit fix command
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
USAGE
|
|
119
|
+
$ csdx cm:stacks:audit:fix [-c <value>] [-d <value>]
|
|
120
|
+
|
|
121
|
+
FLAGS
|
|
122
|
+
-c, --config=<value> Path of the external config.
|
|
123
|
+
-d, --data-dir=<value> Path where the data is stored.
|
|
124
|
+
|
|
125
|
+
DESCRIPTION
|
|
126
|
+
Audit fix command
|
|
127
|
+
|
|
128
|
+
ALIASES
|
|
129
|
+
$ csdx cm::stacks:audit:fix
|
|
130
|
+
|
|
131
|
+
EXAMPLES
|
|
132
|
+
$ csdx cm:stacks:audit:fix
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
_See code: [src/commands/cm/stacks/audit/fix.ts](https://github.com/contentstack/audit/blob/main/packages/contentstack-audit/src/commands/cm/stacks/audit/fix.ts)_
|
|
136
|
+
|
|
137
|
+
## `csdx help [COMMANDS]`
|
|
138
|
+
|
|
139
|
+
Display help for csdx.
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
USAGE
|
|
143
|
+
$ csdx help [COMMANDS] [-n]
|
|
144
|
+
|
|
145
|
+
ARGUMENTS
|
|
146
|
+
COMMANDS Command to show help for.
|
|
147
|
+
|
|
148
|
+
FLAGS
|
|
149
|
+
-n, --nested-commands Include all nested commands in the output.
|
|
150
|
+
|
|
151
|
+
DESCRIPTION
|
|
152
|
+
Display help for csdx.
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.20/src/commands/help.ts)_
|
|
156
|
+
|
|
157
|
+
## `csdx plugins`
|
|
158
|
+
|
|
159
|
+
List installed plugins.
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
USAGE
|
|
163
|
+
$ csdx plugins [--json] [--core]
|
|
164
|
+
|
|
165
|
+
FLAGS
|
|
166
|
+
--core Show core plugins.
|
|
167
|
+
|
|
168
|
+
GLOBAL FLAGS
|
|
169
|
+
--json Format output as json.
|
|
170
|
+
|
|
171
|
+
DESCRIPTION
|
|
172
|
+
List installed plugins.
|
|
173
|
+
|
|
174
|
+
EXAMPLES
|
|
175
|
+
$ csdx plugins
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/index.ts)_
|
|
179
|
+
|
|
180
|
+
## `csdx plugins:install PLUGIN...`
|
|
181
|
+
|
|
182
|
+
Installs a plugin into the CLI.
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
USAGE
|
|
186
|
+
$ csdx plugins:install PLUGIN...
|
|
187
|
+
|
|
188
|
+
ARGUMENTS
|
|
189
|
+
PLUGIN Plugin to install.
|
|
190
|
+
|
|
191
|
+
FLAGS
|
|
192
|
+
-f, --force Run yarn install with force flag.
|
|
193
|
+
-h, --help Show CLI help.
|
|
194
|
+
-v, --verbose
|
|
195
|
+
|
|
196
|
+
DESCRIPTION
|
|
197
|
+
Installs a plugin into the CLI.
|
|
198
|
+
Can be installed from npm or a git url.
|
|
199
|
+
|
|
200
|
+
Installation of a user-installed plugin will override a core plugin.
|
|
201
|
+
|
|
202
|
+
e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command
|
|
203
|
+
will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
|
|
204
|
+
the CLI without the need to patch and update the whole CLI.
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
ALIASES
|
|
208
|
+
$ csdx plugins:add
|
|
209
|
+
|
|
210
|
+
EXAMPLES
|
|
211
|
+
$ csdx plugins:install myplugin
|
|
212
|
+
|
|
213
|
+
$ csdx plugins:install https://github.com/someuser/someplugin
|
|
214
|
+
|
|
215
|
+
$ csdx plugins:install someuser/someplugin
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## `csdx plugins:inspect PLUGIN...`
|
|
219
|
+
|
|
220
|
+
Displays installation properties of a plugin.
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
USAGE
|
|
224
|
+
$ csdx plugins:inspect PLUGIN...
|
|
225
|
+
|
|
226
|
+
ARGUMENTS
|
|
227
|
+
PLUGIN [default: .] Plugin to inspect.
|
|
228
|
+
|
|
229
|
+
FLAGS
|
|
230
|
+
-h, --help Show CLI help.
|
|
231
|
+
-v, --verbose
|
|
232
|
+
|
|
233
|
+
GLOBAL FLAGS
|
|
234
|
+
--json Format output as json.
|
|
235
|
+
|
|
236
|
+
DESCRIPTION
|
|
237
|
+
Displays installation properties of a plugin.
|
|
238
|
+
|
|
239
|
+
EXAMPLES
|
|
240
|
+
$ csdx plugins:inspect myplugin
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/inspect.ts)_
|
|
244
|
+
|
|
245
|
+
## `csdx plugins:install PLUGIN...`
|
|
246
|
+
|
|
247
|
+
Installs a plugin into the CLI.
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
USAGE
|
|
251
|
+
$ csdx plugins:install PLUGIN...
|
|
252
|
+
|
|
253
|
+
ARGUMENTS
|
|
254
|
+
PLUGIN Plugin to install.
|
|
255
|
+
|
|
256
|
+
FLAGS
|
|
257
|
+
-f, --force Run yarn install with force flag.
|
|
258
|
+
-h, --help Show CLI help.
|
|
259
|
+
-v, --verbose
|
|
260
|
+
|
|
261
|
+
DESCRIPTION
|
|
262
|
+
Installs a plugin into the CLI.
|
|
263
|
+
Can be installed from npm or a git url.
|
|
264
|
+
|
|
265
|
+
Installation of a user-installed plugin will override a core plugin.
|
|
266
|
+
|
|
267
|
+
e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command
|
|
268
|
+
will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
|
|
269
|
+
the CLI without the need to patch and update the whole CLI.
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
ALIASES
|
|
273
|
+
$ csdx plugins:add
|
|
274
|
+
|
|
275
|
+
EXAMPLES
|
|
276
|
+
$ csdx plugins:install myplugin
|
|
277
|
+
|
|
278
|
+
$ csdx plugins:install https://github.com/someuser/someplugin
|
|
279
|
+
|
|
280
|
+
$ csdx plugins:install someuser/someplugin
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/install.ts)_
|
|
284
|
+
|
|
285
|
+
## `csdx plugins:link PLUGIN`
|
|
286
|
+
|
|
287
|
+
Links a plugin into the CLI for development.
|
|
288
|
+
|
|
289
|
+
```
|
|
290
|
+
USAGE
|
|
291
|
+
$ csdx plugins:link PLUGIN
|
|
292
|
+
|
|
293
|
+
ARGUMENTS
|
|
294
|
+
PATH [default: .] path to plugin
|
|
295
|
+
|
|
296
|
+
FLAGS
|
|
297
|
+
-h, --help Show CLI help.
|
|
298
|
+
-v, --verbose
|
|
299
|
+
|
|
300
|
+
DESCRIPTION
|
|
301
|
+
Links a plugin into the CLI for development.
|
|
302
|
+
Installation of a linked plugin will override a user-installed or core plugin.
|
|
303
|
+
|
|
304
|
+
e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello'
|
|
305
|
+
command will override the user-installed or core plugin implementation. This is useful for development work.
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
EXAMPLES
|
|
309
|
+
$ csdx plugins:link myplugin
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/link.ts)_
|
|
313
|
+
|
|
314
|
+
## `csdx plugins:uninstall PLUGIN...`
|
|
315
|
+
|
|
316
|
+
Removes a plugin from the CLI.
|
|
317
|
+
|
|
318
|
+
```
|
|
319
|
+
USAGE
|
|
320
|
+
$ csdx plugins:uninstall PLUGIN...
|
|
321
|
+
|
|
322
|
+
ARGUMENTS
|
|
323
|
+
PLUGIN plugin to uninstall
|
|
324
|
+
|
|
325
|
+
FLAGS
|
|
326
|
+
-h, --help Show CLI help.
|
|
327
|
+
-v, --verbose
|
|
328
|
+
|
|
329
|
+
DESCRIPTION
|
|
330
|
+
Removes a plugin from the CLI.
|
|
331
|
+
|
|
332
|
+
ALIASES
|
|
333
|
+
$ csdx plugins:unlink
|
|
334
|
+
$ csdx plugins:remove
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## `csdx plugins:uninstall PLUGIN...`
|
|
338
|
+
|
|
339
|
+
Removes a plugin from the CLI.
|
|
340
|
+
|
|
341
|
+
```
|
|
342
|
+
USAGE
|
|
343
|
+
$ csdx plugins:uninstall PLUGIN...
|
|
344
|
+
|
|
345
|
+
ARGUMENTS
|
|
346
|
+
PLUGIN plugin to uninstall
|
|
347
|
+
|
|
348
|
+
FLAGS
|
|
349
|
+
-h, --help Show CLI help.
|
|
350
|
+
-v, --verbose
|
|
351
|
+
|
|
352
|
+
DESCRIPTION
|
|
353
|
+
Removes a plugin from the CLI.
|
|
354
|
+
|
|
355
|
+
ALIASES
|
|
356
|
+
$ csdx plugins:unlink
|
|
357
|
+
$ csdx plugins:remove
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/uninstall.ts)_
|
|
361
|
+
|
|
362
|
+
## `csdx plugins:uninstall PLUGIN...`
|
|
363
|
+
|
|
364
|
+
Removes a plugin from the CLI.
|
|
365
|
+
|
|
366
|
+
```
|
|
367
|
+
USAGE
|
|
368
|
+
$ csdx plugins:uninstall PLUGIN...
|
|
369
|
+
|
|
370
|
+
ARGUMENTS
|
|
371
|
+
PLUGIN plugin to uninstall
|
|
372
|
+
|
|
373
|
+
FLAGS
|
|
374
|
+
-h, --help Show CLI help.
|
|
375
|
+
-v, --verbose
|
|
376
|
+
|
|
377
|
+
DESCRIPTION
|
|
378
|
+
Removes a plugin from the CLI.
|
|
379
|
+
|
|
380
|
+
ALIASES
|
|
381
|
+
$ csdx plugins:unlink
|
|
382
|
+
$ csdx plugins:remove
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## `csdx plugins:update`
|
|
386
|
+
|
|
387
|
+
Update installed plugins.
|
|
388
|
+
|
|
389
|
+
```
|
|
390
|
+
USAGE
|
|
391
|
+
$ csdx plugins:update [-h] [-v]
|
|
392
|
+
|
|
393
|
+
FLAGS
|
|
394
|
+
-h, --help Show CLI help.
|
|
395
|
+
-v, --verbose
|
|
396
|
+
|
|
397
|
+
DESCRIPTION
|
|
398
|
+
Update installed plugins.
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/update.ts)_
|
|
402
|
+
<!-- commandsstop -->
|
package/bin/dev
ADDED
package/bin/dev.cmd
ADDED
package/bin/run
ADDED
package/bin/run.cmd
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Command } from '@contentstack/cli-command';
|
|
2
|
+
import { FlagInput, Interfaces } from '@contentstack/cli-utilities';
|
|
3
|
+
import { Logger } from './util';
|
|
4
|
+
import { ConfigType, LogFn } from './types';
|
|
5
|
+
import messages, { $t } from './messages';
|
|
6
|
+
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
|
|
7
|
+
export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)['baseFlags'] & T['flags']>;
|
|
8
|
+
export declare abstract class BaseCommand<T extends typeof Command> extends Command {
|
|
9
|
+
log: LogFn;
|
|
10
|
+
logger: Logger;
|
|
11
|
+
readonly $t: typeof $t;
|
|
12
|
+
protected sharedConfig: ConfigType;
|
|
13
|
+
readonly messages: typeof messages;
|
|
14
|
+
protected args: Args<T>;
|
|
15
|
+
protected flags: Flags<T>;
|
|
16
|
+
static baseFlags: FlagInput;
|
|
17
|
+
/**
|
|
18
|
+
* The `init` function initializes the command by parsing arguments and flags, registering search
|
|
19
|
+
* plugins, registering the configuration, and initializing the logger.
|
|
20
|
+
*/
|
|
21
|
+
init(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* The catch function is used to handle errors from a command, either by adding custom logic or
|
|
24
|
+
* returning the parent class error handling.
|
|
25
|
+
* @param err - The `err` parameter is of type `Error & { exitCode?: number }`. This means that it is
|
|
26
|
+
* an object that extends the `Error` class and may also have an optional property `exitCode` of type
|
|
27
|
+
* `number`.
|
|
28
|
+
* @returns The parent class error handling is being returned.
|
|
29
|
+
*/
|
|
30
|
+
protected catch(err: Error & {
|
|
31
|
+
exitCode?: number;
|
|
32
|
+
}): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* The `finally` function is called after the `run` and `catch` functions, regardless of whether or not
|
|
35
|
+
* an error occurred.
|
|
36
|
+
* @param {Error | undefined} _ - The parameter "_" represents an error object or undefined.
|
|
37
|
+
* @returns The `finally` method is returning the result of calling the `finally` method of the
|
|
38
|
+
* superclass, which is a promise.
|
|
39
|
+
*/
|
|
40
|
+
protected finally(_: Error | undefined): Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* The function checks if a configuration file exists and if so, reads and parses it as JSON.
|
|
43
|
+
*/
|
|
44
|
+
registerConfig(): void;
|
|
45
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseCommand = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const cli_command_1 = require("@contentstack/cli-command");
|
|
7
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
8
|
+
const config_1 = tslib_1.__importDefault(require("./config"));
|
|
9
|
+
const util_1 = require("./util");
|
|
10
|
+
const messages_1 = tslib_1.__importStar(require("./messages"));
|
|
11
|
+
class BaseCommand extends cli_command_1.Command {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.$t = messages_1.$t;
|
|
15
|
+
this.sharedConfig = Object.assign(Object.assign({}, config_1.default), { basePath: process.cwd() });
|
|
16
|
+
this.messages = messages_1.default;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The `init` function initializes the command by parsing arguments and flags, registering search
|
|
20
|
+
* plugins, registering the configuration, and initializing the logger.
|
|
21
|
+
*/
|
|
22
|
+
async init() {
|
|
23
|
+
await super.init();
|
|
24
|
+
const { args, flags } = await this.parse({
|
|
25
|
+
flags: this.ctor.flags,
|
|
26
|
+
baseFlags: super.ctor.baseFlags,
|
|
27
|
+
args: this.ctor.args,
|
|
28
|
+
strict: this.ctor.strict,
|
|
29
|
+
});
|
|
30
|
+
this.flags = flags;
|
|
31
|
+
this.args = args;
|
|
32
|
+
this.sharedConfig = Object.assign(this.sharedConfig, { flags: this.flags });
|
|
33
|
+
cli_utilities_1.cliux.registerSearchPlugin();
|
|
34
|
+
this.registerConfig();
|
|
35
|
+
// Init logger
|
|
36
|
+
const logger = new util_1.Logger(this.sharedConfig);
|
|
37
|
+
this.log = logger.log.bind(logger);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The catch function is used to handle errors from a command, either by adding custom logic or
|
|
41
|
+
* returning the parent class error handling.
|
|
42
|
+
* @param err - The `err` parameter is of type `Error & { exitCode?: number }`. This means that it is
|
|
43
|
+
* an object that extends the `Error` class and may also have an optional property `exitCode` of type
|
|
44
|
+
* `number`.
|
|
45
|
+
* @returns The parent class error handling is being returned.
|
|
46
|
+
*/
|
|
47
|
+
async catch(err) {
|
|
48
|
+
// add any custom logic to handle errors from the command
|
|
49
|
+
// or simply return the parent class error handling
|
|
50
|
+
return super.catch(err);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The `finally` function is called after the `run` and `catch` functions, regardless of whether or not
|
|
54
|
+
* an error occurred.
|
|
55
|
+
* @param {Error | undefined} _ - The parameter "_" represents an error object or undefined.
|
|
56
|
+
* @returns The `finally` method is returning the result of calling the `finally` method of the
|
|
57
|
+
* superclass, which is a promise.
|
|
58
|
+
*/
|
|
59
|
+
async finally(_) {
|
|
60
|
+
// called after run and catch regardless of whether or not the command errored
|
|
61
|
+
return super.finally(_);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The function checks if a configuration file exists and if so, reads and parses it as JSON.
|
|
65
|
+
*/
|
|
66
|
+
registerConfig() {
|
|
67
|
+
if (this.flags.config && (0, fs_1.existsSync)(this.flags.config)) {
|
|
68
|
+
try {
|
|
69
|
+
this.sharedConfig = JSON.parse((0, fs_1.readFileSync)(this.flags.config, { encoding: 'utf-8' }));
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
this.log(error, 'error');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.BaseCommand = BaseCommand;
|
|
78
|
+
// NOTE define flags that can be inherited by any command that extends BaseCommand
|
|
79
|
+
BaseCommand.baseFlags = {
|
|
80
|
+
config: cli_utilities_1.Flags.string({
|
|
81
|
+
char: 'c',
|
|
82
|
+
description: messages_1.commonMsg.CONFIG,
|
|
83
|
+
}),
|
|
84
|
+
'data-dir': cli_utilities_1.Flags.string({
|
|
85
|
+
char: 'd',
|
|
86
|
+
description: messages_1.commonMsg.DATA_DIR,
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_command_1 = require("../../../../base-command");
|
|
4
|
+
class AuditFix extends base_command_1.BaseCommand {
|
|
5
|
+
async run() { }
|
|
6
|
+
}
|
|
7
|
+
exports.default = AuditFix;
|
|
8
|
+
AuditFix.description = 'Audit fix command';
|
|
9
|
+
AuditFix.aliases = ['cm::stacks:audit:fix'];
|
|
10
|
+
AuditFix.examples = ['$ <%= config.bin %> <%= command.id %>'];
|
|
11
|
+
AuditFix.flags = {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FlagInput } from '@contentstack/cli-utilities';
|
|
2
|
+
import config from '../../../../config';
|
|
3
|
+
import { BaseCommand } from '../../../../base-command';
|
|
4
|
+
import { ContentTypeStruct } from '../../../../types';
|
|
5
|
+
export default class Audit extends BaseCommand<typeof Audit> {
|
|
6
|
+
static aliases: string[];
|
|
7
|
+
static description: string;
|
|
8
|
+
static examples: string[];
|
|
9
|
+
static flags: FlagInput;
|
|
10
|
+
/**
|
|
11
|
+
* The `run` function is an asynchronous function that performs an audit on different modules
|
|
12
|
+
* (content-types, global-fields, entries) and generates a report.
|
|
13
|
+
*/
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* The `promptQueue` function prompts the user to enter a data directory path if the `data-dir` flag
|
|
17
|
+
* is missing, and sets the `basePath` property of the `sharedConfig` object to the entered path.
|
|
18
|
+
*/
|
|
19
|
+
promptQueue(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* The function `getCtAndGfSchema` reads and parses JSON files containing content type and global
|
|
22
|
+
* field schemas, and returns them as an object.
|
|
23
|
+
* @returns The function `getCtAndGfSchema()` returns an object with two properties: `ctSchema` and
|
|
24
|
+
* `gfSchema`. The values of these properties are the parsed JSON data from two different files.
|
|
25
|
+
*/
|
|
26
|
+
getCtAndGfSchema(): {
|
|
27
|
+
ctSchema: ContentTypeStruct[];
|
|
28
|
+
gfSchema: ContentTypeStruct[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The function `showOutputOnScreen` displays missing references on the terminal screen if the
|
|
32
|
+
* `showTerminalOutput` flag is set to true.
|
|
33
|
+
* @param {{ module: string; missingRefs?: Record<string, any> }[]} allMissingRefs - An array of
|
|
34
|
+
* objects, where each object has two properties:
|
|
35
|
+
*/
|
|
36
|
+
showOutputOnScreen(allMissingRefs: {
|
|
37
|
+
module: string;
|
|
38
|
+
missingRefs?: Record<string, any>;
|
|
39
|
+
}[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* The function prepares a report by writing a JSON file and a CSV file with a list of missing
|
|
42
|
+
* references for a given module.
|
|
43
|
+
* @param moduleName - The `moduleName` parameter is a string that represents the name of a module.
|
|
44
|
+
* It is used to generate the filename for the report.
|
|
45
|
+
* @param listOfMissingRefs - The `listOfMissingRefs` parameter is a record object that contains
|
|
46
|
+
* information about missing references. It is a key-value pair where the key represents the
|
|
47
|
+
* reference name and the value represents additional information about the missing reference.
|
|
48
|
+
* @returns The function `prepareReport` returns a Promise that resolves to `void`.
|
|
49
|
+
*/
|
|
50
|
+
prepareReport(moduleName: keyof typeof config.moduleConfig, listOfMissingRefs: Record<string, any>): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* The function `prepareCSV` takes a module name and a list of missing references, and generates a
|
|
53
|
+
* CSV file with the specified columns and filtered rows.
|
|
54
|
+
* @param moduleName - The `moduleName` parameter is a string that represents the name of a module.
|
|
55
|
+
* It is used to generate the name of the CSV file that will be created.
|
|
56
|
+
* @param listOfMissingRefs - The `listOfMissingRefs` parameter is a record object that contains
|
|
57
|
+
* information about missing references. Each key in the record represents a reference, and the
|
|
58
|
+
* corresponding value is an array of objects that contain details about the missing reference.
|
|
59
|
+
* @returns The function `prepareCSV` returns a Promise that resolves to `void`.
|
|
60
|
+
*/
|
|
61
|
+
prepareCSV(moduleName: keyof typeof config.moduleConfig, listOfMissingRefs: Record<string, any>): Promise<void>;
|
|
62
|
+
}
|