@dittowords/cli 3.8.0 → 3.9.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.
@@ -1,7 +1,9 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="ChangeListManager">
4
- <list default="true" id="d2834f12-3435-41b5-8efa-c62f3f4baa0d" name="Changes" comment="simplify generate-suggestions flag passing" />
4
+ <list default="true" id="d2834f12-3435-41b5-8efa-c62f3f4baa0d" name="Changes" comment="Add remaining column mappings">
5
+ <change beforePath="$PROJECT_DIR$/lib/ditto.ts" beforeDir="false" afterPath="$PROJECT_DIR$/lib/ditto.ts" afterDir="false" />
6
+ </list>
5
7
  <option name="SHOW_DIALOG" value="false" />
6
8
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
7
9
  <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -10,7 +12,7 @@
10
12
  <component name="Git.Settings">
11
13
  <option name="RECENT_BRANCH_BY_REPOSITORY">
12
14
  <map>
13
- <entry key="$PROJECT_DIR$" value="ash/dit-4251-enable-component-imports-via-the-cli" />
15
+ <entry key="$PROJECT_DIR$" value="master" />
14
16
  </map>
15
17
  </option>
16
18
  <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
@@ -86,7 +88,13 @@
86
88
  <workItem from="1686069506429" duration="76000" />
87
89
  <workItem from="1686087849012" duration="140000" />
88
90
  <workItem from="1686168915499" duration="2643000" />
89
- <workItem from="1686172029566" duration="4862000" />
91
+ <workItem from="1686172029566" duration="5629000" />
92
+ <workItem from="1686604031092" duration="6110000" />
93
+ <workItem from="1686665537695" duration="7000" />
94
+ <workItem from="1686666962638" duration="1318000" />
95
+ <workItem from="1686672751040" duration="103000" />
96
+ <workItem from="1686758001057" duration="1199000" />
97
+ <workItem from="1686764622070" duration="41000" />
90
98
  </task>
91
99
  <task id="LOCAL-00001" summary="Remove eslint">
92
100
  <created>1685986802039</created>
@@ -144,7 +152,35 @@
144
152
  <option name="project" value="LOCAL" />
145
153
  <updated>1686244114837</updated>
146
154
  </task>
147
- <option name="localTasksCounter" value="9" />
155
+ <task id="LOCAL-00009" summary="Add import-components command">
156
+ <created>1686611039840</created>
157
+ <option name="number" value="00009" />
158
+ <option name="presentableId" value="LOCAL-00009" />
159
+ <option name="project" value="LOCAL" />
160
+ <updated>1686611039840</updated>
161
+ </task>
162
+ <task id="LOCAL-00010" summary="Add flag check for csv files">
163
+ <created>1686667259055</created>
164
+ <option name="number" value="00010" />
165
+ <option name="presentableId" value="LOCAL-00010" />
166
+ <option name="project" value="LOCAL" />
167
+ <updated>1686667259055</updated>
168
+ </task>
169
+ <task id="LOCAL-00011" summary="Add (.csv format only)">
170
+ <created>1686758043695</created>
171
+ <option name="number" value="00011" />
172
+ <option name="presentableId" value="LOCAL-00011" />
173
+ <option name="project" value="LOCAL" />
174
+ <updated>1686758043695</updated>
175
+ </task>
176
+ <task id="LOCAL-00012" summary="Add remaining column mappings">
177
+ <created>1686758202293</created>
178
+ <option name="number" value="00012" />
179
+ <option name="presentableId" value="LOCAL-00012" />
180
+ <option name="project" value="LOCAL" />
181
+ <updated>1686758202293</updated>
182
+ </task>
183
+ <option name="localTasksCounter" value="13" />
148
184
  <servers />
149
185
  </component>
150
186
  <component name="TypeScriptGeneratedFilesManager">
@@ -171,7 +207,11 @@
171
207
  <MESSAGE value="Stringify print" />
172
208
  <MESSAGE value="Add import-component function" />
173
209
  <MESSAGE value="simplify generate-suggestions flag passing" />
174
- <option name="LAST_COMMIT_MESSAGE" value="simplify generate-suggestions flag passing" />
210
+ <MESSAGE value="Add import-components command" />
211
+ <MESSAGE value="Add flag check for csv files" />
212
+ <MESSAGE value="Add (.csv format only)" />
213
+ <MESSAGE value="Add remaining column mappings" />
214
+ <option name="LAST_COMMIT_MESSAGE" value="Add remaining column mappings" />
175
215
  </component>
176
216
  <component name="XSLT-Support.FileAssociations.UIState">
177
217
  <expand />
package/README.md CHANGED
@@ -90,6 +90,22 @@ For more details on files generated by this command, see [Output Files](#output-
90
90
 
91
91
  **Action:** List component folders in your workspace. More information about component folders can be found here: https://www.dittowords.com/docs/component-folders.
92
92
 
93
+ ### Import components
94
+
95
+ **Usage:** `ditto-cli import-components <file_path>`
96
+
97
+ **Action:** Import components via a file. Please see https://www.dittowords.com/docs/importing-string-files for more information.
98
+ When [importing CSV files](https://www.dittowords.com/docs/importing-csv-files), the follow parameters are applicable:
99
+ ```
100
+ -t, --text [value] Text column index (Required)
101
+ -n, --component-name [value] Name column indexes (comma separated) (Required)
102
+ -no, --notes [value] Notes column index
103
+ -t, --tags [value] Tags column index
104
+ -s, --status [value] Status column index
105
+ -c, --component-id [value] Component ID column index
106
+ -h, --help display help for command
107
+ ```
108
+
93
109
  ## Configuration
94
110
 
95
111
  The `config.yml` file is the source of truth for a given directory about how the CLI should fetch and store data from Ditto. It includes information about which Ditto projects the CLI should pull text from, whether or not the component library should be included, in what format the text should be stored, and more.
package/bin/ditto.js CHANGED
@@ -18,6 +18,7 @@ const remove_project_1 = __importDefault(require("./remove-project"));
18
18
  const replace_1 = require("./replace");
19
19
  const generate_suggestions_1 = require("./generate-suggestions");
20
20
  const processMetaOption_1 = __importDefault(require("./utils/processMetaOption"));
21
+ const importComponents_1 = require("./importComponents");
21
22
  const component_folders_1 = require("./component-folders");
22
23
  function getVersion() {
23
24
  const packageJsonPath = path_1.default.join(__dirname, "..", "package.json");
@@ -75,6 +76,30 @@ const COMMANDS = [
75
76
  },
76
77
  },
77
78
  },
79
+ {
80
+ name: "import-components",
81
+ description: "Import components via a file. For more information please see: https://www.dittowords.com/docs/importing-string-files.",
82
+ flags: {
83
+ "-t, --text [value]": {
84
+ description: "Text column index (.csv format only)",
85
+ },
86
+ "-n, --component-name [value]": {
87
+ description: "Name column indexes (comma separated) (.csv format only)",
88
+ },
89
+ "-no, --notes [value]": {
90
+ description: "Notes column index (.csv format only)",
91
+ },
92
+ "-t, --tags [value]": {
93
+ description: "Tags column index (.csv format only)",
94
+ },
95
+ "-s, --status [value]": {
96
+ description: "Status column index (.csv format only)",
97
+ },
98
+ "-c, --component-id [value]": {
99
+ description: "Component ID column index (.csv format only)",
100
+ },
101
+ },
102
+ },
78
103
  ];
79
104
  const setupCommands = () => {
80
105
  commander_1.program.name("ditto-cli");
@@ -158,6 +183,22 @@ const executeCommand = async (command, options) => {
158
183
  ...(options?.lineNumbers ? { lineNumbers: options.lineNumbers } : {}),
159
184
  });
160
185
  }
186
+ case "import-components": {
187
+ if (options.args.length === 0) {
188
+ console.info("Please provide a file path.");
189
+ return;
190
+ }
191
+ return (0, importComponents_1.importComponents)(options.args[0], {
192
+ csvColumnMapping: {
193
+ name: options.componentName,
194
+ text: options.text,
195
+ notes: options.notes,
196
+ tags: options.tags,
197
+ status: options.status,
198
+ componentId: options.componentId,
199
+ },
200
+ });
201
+ }
161
202
  default: {
162
203
  (0, quit_1.quit)("Exiting Ditto CLI...");
163
204
  return;
package/bin/ditto.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ditto.js","sourceRoot":"","sources":["../lib/ditto.ts"],"names":[],"mappings":";;;;;;AACA,0DAA0D;AAC1D,yCAAoC;AACpC,wDAAwD;AACxD,4BAA0B;AAC1B,4CAAoB;AACpB,gDAAwB;AAExB,sCAAuD;AACvD,iCAA8B;AAC9B,uCAAoC;AACpC,gEAAuC;AACvC,sEAA6C;AAC7C,uCAAoC;AACpC,iEAA6D;AAE7D,kFAA0D;AAC1D,2DAA2D;AAE3D,SAAS,UAAU;IACjB,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;IACnE,MAAM,kBAAkB,GAAG,YAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IACpE,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAwB,CAAC;IAC1E,OAAO,WAAW,CAAC,OAAO,CAAC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CAAC;AAEF,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE;IACtB,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;IAEf,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QACrE,MAAM,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACjC,OAAO;KACR;IAED,mBAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,IAAI,EAAE,CAAC"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.importComponents = void 0;
7
+ const api_1 = require("../api");
8
+ const form_data_1 = __importDefault(require("form-data"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ async function importComponents(path, options) {
11
+ const api = (0, api_1.createApiClient)();
12
+ const form = new form_data_1.default();
13
+ form.append("import", fs_1.default.createReadStream(path));
14
+ const requestOptions = {
15
+ method: "POST",
16
+ url: "/v1/components/file",
17
+ params: {
18
+ ...(options.csvColumnMapping?.name
19
+ ? { name: `[${options.csvColumnMapping.name}]` }
20
+ : {}),
21
+ ...(options.csvColumnMapping?.text
22
+ ? { text: options.csvColumnMapping.text }
23
+ : {}),
24
+ ...(options.csvColumnMapping?.notes
25
+ ? { notes: options.csvColumnMapping.notes }
26
+ : {}),
27
+ ...(options.csvColumnMapping?.status
28
+ ? { status: options.csvColumnMapping.status }
29
+ : {}),
30
+ ...(options.csvColumnMapping?.tags
31
+ ? { tags: options.csvColumnMapping.tags }
32
+ : {}),
33
+ ...(options.csvColumnMapping?.componentId
34
+ ? { componentId: options.csvColumnMapping.componentId }
35
+ : {}),
36
+ },
37
+ headers: {
38
+ "content-type": "multipart/form-data",
39
+ },
40
+ data: form,
41
+ };
42
+ try {
43
+ const { data } = await api(requestOptions);
44
+ return data;
45
+ }
46
+ catch (e) {
47
+ console.error("Failed to import file.");
48
+ console.error(e.response?.data?.message || e.message);
49
+ return {
50
+ componentsInserted: 0,
51
+ firstImportedId: "null",
52
+ };
53
+ }
54
+ }
55
+ exports.importComponents = importComponents;
56
+ //# sourceMappingURL=importComponents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importComponents.js","sourceRoot":"","sources":["../../lib/http/importComponents.ts"],"names":[],"mappings":";;;;;;AAAA,gCAAyC;AACzC,0DAAiC;AACjC,4CAAoB;AAgBb,KAAK,UAAU,gBAAgB,CACpC,IAAY,EACZ,OAEC;IAED,MAAM,GAAG,GAAG,IAAA,qBAAe,GAAE,CAAC;IAE9B,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;IAC5B,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjD,MAAM,cAAc,GAAG;QACrB,MAAM,EAAE,MAAM;QACd,GAAG,EAAE,qBAAqB;QAC1B,MAAM,EAAE;YACN,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,IAAI;gBAChC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,OAAO,CAAC,gBAAgB,CAAC,IAAI,GAAG,EAAE;gBAChD,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,IAAI;gBAChC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE;gBACzC,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,KAAK;gBACjC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE;gBAC3C,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM;gBAClC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE;gBAC7C,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,IAAI;gBAChC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE;gBACzC,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,WAAW;gBACvC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,gBAAgB,CAAC,WAAW,EAAE;gBACvD,CAAC,CAAC,EAAE,CAAC;SACR;QACD,OAAO,EAAE;YACP,cAAc,EAAE,qBAAqB;SACtC;QACD,IAAI,EAAE,IAAI;KACX,CAAC;IAEF,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,GAAG,CAAC,cAAc,CAAC,CAAC;QAE3C,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAM,EAAE;QACf,OAAO,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;QACxC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;QACtD,OAAO;YACL,kBAAkB,EAAE,CAAC;YACrB,eAAe,EAAE,MAAM;SACxB,CAAC;KACH;AACH,CAAC;AApDD,4CAoDC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.importComponents = void 0;
4
+ const importComponents_1 = require("./http/importComponents");
5
+ async function importComponents(filePath, options) {
6
+ if (filePath.endsWith(".csv") &&
7
+ (!options.csvColumnMapping?.name || !options.csvColumnMapping?.text)) {
8
+ throw new Error(".csv files require the --component-name and --text flags.");
9
+ }
10
+ const importResult = await (0, importComponents_1.importComponents)(filePath, options);
11
+ console.log(JSON.stringify(importResult));
12
+ }
13
+ exports.importComponents = importComponents;
14
+ //# sourceMappingURL=importComponents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importComponents.js","sourceRoot":"","sources":["../lib/importComponents.ts"],"names":[],"mappings":";;;AAAA,8DAGiC;AAEjC,KAAK,UAAU,gBAAgB,CAC7B,QAAgB,EAChB,OAEC;IAED,IACE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;QACzB,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,IAAI,CAAC,EACpE;QACA,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;KACH;IACD,MAAM,YAAY,GAAG,MAAM,IAAA,mCAAoB,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACnE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;AAC5C,CAAC;AAEQ,4CAAgB"}
package/lib/ditto.ts CHANGED
@@ -15,6 +15,7 @@ import { replace } from "./replace";
15
15
  import { generateSuggestions } from "./generate-suggestions";
16
16
 
17
17
  import processMetaOption from "./utils/processMetaOption";
18
+ import { importComponents } from "./importComponents";
18
19
  import { showComponentFolders } from "./component-folders";
19
20
 
20
21
  function getVersion(): string {
@@ -33,7 +34,8 @@ type Command =
33
34
  | "project remove"
34
35
  | "component-folders"
35
36
  | "generate-suggestions"
36
- | "replace";
37
+ | "replace"
38
+ | "import-components";
37
39
 
38
40
  interface CommandConfig<T extends Command | "add" | "remove"> {
39
41
  name: T;
@@ -94,6 +96,31 @@ const COMMANDS: CommandConfig<Command>[] = [
94
96
  },
95
97
  },
96
98
  },
99
+ {
100
+ name: "import-components",
101
+ description:
102
+ "Import components via a file. For more information please see: https://www.dittowords.com/docs/importing-string-files.",
103
+ flags: {
104
+ "-t, --text [value]": {
105
+ description: "Text column index (.csv format only)",
106
+ },
107
+ "-n, --component-name [value]": {
108
+ description: "Name column indexes (comma separated) (.csv format only)",
109
+ },
110
+ "-no, --notes [value]": {
111
+ description: "Notes column index (.csv format only)",
112
+ },
113
+ "-t, --tags [value]": {
114
+ description: "Tags column index (.csv format only)",
115
+ },
116
+ "-s, --status [value]": {
117
+ description: "Status column index (.csv format only)",
118
+ },
119
+ "-c, --component-id [value]": {
120
+ description: "Component ID column index (.csv format only)",
121
+ },
122
+ },
123
+ },
97
124
  ];
98
125
 
99
126
  const setupCommands = () => {
@@ -191,6 +218,22 @@ const executeCommand = async (
191
218
  ...(options?.lineNumbers ? { lineNumbers: options.lineNumbers } : {}),
192
219
  });
193
220
  }
221
+ case "import-components": {
222
+ if (options.args.length === 0) {
223
+ console.info("Please provide a file path.");
224
+ return;
225
+ }
226
+ return importComponents(options.args[0], {
227
+ csvColumnMapping: {
228
+ name: options.componentName,
229
+ text: options.text,
230
+ notes: options.notes,
231
+ tags: options.tags,
232
+ status: options.status,
233
+ componentId: options.componentId,
234
+ },
235
+ });
236
+ }
194
237
  default: {
195
238
  quit("Exiting Ditto CLI...");
196
239
  return;
@@ -0,0 +1,71 @@
1
+ import { createApiClient } from "../api";
2
+ import FormData from "form-data";
3
+ import fs from "fs";
4
+
5
+ export interface ImportComponentResponse {
6
+ componentsInserted: number;
7
+ firstImportedId: string;
8
+ }
9
+
10
+ export interface CsvColumnMapping {
11
+ text: number;
12
+ name: string;
13
+ notes?: number;
14
+ tags?: number;
15
+ status?: number;
16
+ componentId?: number;
17
+ }
18
+
19
+ export async function importComponents(
20
+ path: string,
21
+ options: {
22
+ csvColumnMapping?: CsvColumnMapping;
23
+ }
24
+ ): Promise<ImportComponentResponse> {
25
+ const api = createApiClient();
26
+
27
+ const form = new FormData();
28
+ form.append("import", fs.createReadStream(path));
29
+
30
+ const requestOptions = {
31
+ method: "POST",
32
+ url: "/v1/components/file",
33
+ params: {
34
+ ...(options.csvColumnMapping?.name
35
+ ? { name: `[${options.csvColumnMapping.name}]` }
36
+ : {}),
37
+ ...(options.csvColumnMapping?.text
38
+ ? { text: options.csvColumnMapping.text }
39
+ : {}),
40
+ ...(options.csvColumnMapping?.notes
41
+ ? { notes: options.csvColumnMapping.notes }
42
+ : {}),
43
+ ...(options.csvColumnMapping?.status
44
+ ? { status: options.csvColumnMapping.status }
45
+ : {}),
46
+ ...(options.csvColumnMapping?.tags
47
+ ? { tags: options.csvColumnMapping.tags }
48
+ : {}),
49
+ ...(options.csvColumnMapping?.componentId
50
+ ? { componentId: options.csvColumnMapping.componentId }
51
+ : {}),
52
+ },
53
+ headers: {
54
+ "content-type": "multipart/form-data",
55
+ },
56
+ data: form,
57
+ };
58
+
59
+ try {
60
+ const { data } = await api(requestOptions);
61
+
62
+ return data;
63
+ } catch (e: any) {
64
+ console.error("Failed to import file.");
65
+ console.error(e.response?.data?.message || e.message);
66
+ return {
67
+ componentsInserted: 0,
68
+ firstImportedId: "null",
69
+ };
70
+ }
71
+ }
@@ -0,0 +1,24 @@
1
+ import {
2
+ CsvColumnMapping,
3
+ importComponents as importComponentsHttp,
4
+ } from "./http/importComponents";
5
+
6
+ async function importComponents(
7
+ filePath: string,
8
+ options: {
9
+ csvColumnMapping?: CsvColumnMapping;
10
+ }
11
+ ) {
12
+ if (
13
+ filePath.endsWith(".csv") &&
14
+ (!options.csvColumnMapping?.name || !options.csvColumnMapping?.text)
15
+ ) {
16
+ throw new Error(
17
+ ".csv files require the --component-name and --text flags."
18
+ );
19
+ }
20
+ const importResult = await importComponentsHttp(filePath, options);
21
+ console.log(JSON.stringify(importResult));
22
+ }
23
+
24
+ export { importComponents };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dittowords/cli",
3
- "version": "3.8.0",
3
+ "version": "3.9.0",
4
4
  "description": "Command Line Interface for Ditto (dittowords.com).",
5
5
  "main": "bin/index.js",
6
6
  "scripts": {
@@ -62,6 +62,7 @@
62
62
  "commander": "^6.1.0",
63
63
  "enquirer": "^2.3.6",
64
64
  "faker": "^5.1.0",
65
+ "form-data": "^4.0.0",
65
66
  "fs-extra": "^11.1.1",
66
67
  "glob": "^9.3.4",
67
68
  "js-yaml": "^4.1.0",