@dittowords/cli 3.10.1 → 4.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/README.md +125 -36
- package/bin/add-project.js +101 -33
- package/bin/add-project.js.map +1 -1
- package/bin/api.js +49 -15
- package/bin/api.js.map +1 -1
- package/bin/component-folders.js +56 -7
- package/bin/component-folders.js.map +1 -1
- package/bin/config.js +206 -170
- package/bin/config.js.map +1 -1
- package/bin/config.test.js +92 -0
- package/bin/config.test.js.map +1 -0
- package/bin/consts.js +64 -18
- package/bin/consts.js.map +1 -1
- package/bin/ditto.js +250 -200
- package/bin/ditto.js.map +1 -1
- package/bin/generate-suggestions.js +155 -78
- package/bin/generate-suggestions.js.map +1 -1
- package/bin/generate-suggestions.test.js +189 -0
- package/bin/generate-suggestions.test.js.map +1 -0
- package/bin/http/fetchComponentFolders.js +60 -8
- package/bin/http/fetchComponentFolders.js.map +1 -1
- package/bin/http/fetchComponents.js +65 -18
- package/bin/http/fetchComponents.js.map +1 -1
- package/bin/http/fetchVariants.js +74 -14
- package/bin/http/fetchVariants.js.map +1 -1
- package/bin/http/importComponents.js +100 -49
- package/bin/http/importComponents.js.map +1 -1
- package/bin/importComponents.js +61 -10
- package/bin/importComponents.js.map +1 -1
- package/bin/init/init.js +120 -44
- package/bin/init/init.js.map +1 -1
- package/bin/init/project.js +160 -83
- package/bin/init/project.js.map +1 -1
- package/bin/init/project.test.js +49 -0
- package/bin/init/project.test.js.map +1 -0
- package/bin/init/token.js +134 -74
- package/bin/init/token.js.map +1 -1
- package/bin/init/token.test.js +69 -0
- package/bin/init/token.test.js.map +1 -0
- package/bin/output.js +72 -30
- package/bin/output.js.map +1 -1
- package/bin/pull.js +424 -213
- package/bin/pull.js.map +1 -1
- package/bin/pull.test.js +410 -0
- package/bin/pull.test.js.map +1 -0
- package/bin/remove-project.js +91 -27
- package/bin/remove-project.js.map +1 -1
- package/bin/replace.js +140 -100
- package/bin/replace.js.map +1 -1
- package/bin/replace.test.js +155 -0
- package/bin/replace.test.js.map +1 -0
- package/bin/sentry-test.js.map +1 -0
- package/bin/types.js +20 -2
- package/bin/types.js.map +1 -1
- package/bin/utils/cleanFileName.js +32 -8
- package/bin/utils/cleanFileName.js.map +1 -1
- package/bin/utils/createSentryContext.js +43 -0
- package/bin/utils/createSentryContext.js.map +1 -0
- package/bin/utils/generateJsDriver.js +114 -51
- package/bin/utils/generateJsDriver.js.map +1 -1
- package/bin/utils/getSelectedProjects.js +58 -52
- package/bin/utils/getSelectedProjects.js.map +1 -1
- package/bin/utils/processMetaOption.js +36 -11
- package/bin/utils/processMetaOption.js.map +1 -1
- package/bin/utils/processMetaOption.test.js +45 -0
- package/bin/utils/processMetaOption.test.js.map +1 -0
- package/bin/utils/projectsToText.js +52 -19
- package/bin/utils/projectsToText.js.map +1 -1
- package/bin/utils/promptForProject.js +89 -36
- package/bin/utils/promptForProject.js.map +1 -1
- package/bin/utils/quit.js +36 -7
- package/bin/utils/quit.js.map +1 -1
- package/bin/utils/sourcesToText.js +51 -19
- package/bin/utils/sourcesToText.js.map +1 -1
- package/etsc.config.js +13 -0
- package/lib/config.ts +27 -8
- package/lib/ditto.ts +6 -0
- package/lib/init/project.ts +3 -3
- package/lib/pull.ts +190 -52
- package/lib/types.ts +24 -7
- package/lib/utils/createSentryContext.ts +20 -0
- package/lib/utils/generateJsDriver.ts +40 -6
- package/lib/utils/quit.ts +2 -3
- package/package.json +10 -6
- package/tsconfig.json +4 -1
- package/bin/lib/add-project.js +0 -36
- package/bin/lib/add-project.js.map +0 -1
- package/bin/lib/api.js +0 -20
- package/bin/lib/api.js.map +0 -1
- package/bin/lib/config.js +0 -202
- package/bin/lib/config.js.map +0 -1
- package/bin/lib/consts.js +0 -21
- package/bin/lib/consts.js.map +0 -1
- package/bin/lib/ditto.js +0 -121
- package/bin/lib/ditto.js.map +0 -1
- package/bin/lib/generate-suggestions.js +0 -71
- package/bin/lib/generate-suggestions.js.map +0 -1
- package/bin/lib/http/fetchComponents.js +0 -13
- package/bin/lib/http/fetchComponents.js.map +0 -1
- package/bin/lib/http/fetchVariants.js +0 -26
- package/bin/lib/http/fetchVariants.js.map +0 -1
- package/bin/lib/init/init.js +0 -50
- package/bin/lib/init/init.js.map +0 -1
- package/bin/lib/init/project.js +0 -108
- package/bin/lib/init/project.js.map +0 -1
- package/bin/lib/init/token.js +0 -91
- package/bin/lib/init/token.js.map +0 -1
- package/bin/lib/output.js +0 -34
- package/bin/lib/output.js.map +0 -1
- package/bin/lib/pull.js +0 -264
- package/bin/lib/pull.js.map +0 -1
- package/bin/lib/remove-project.js +0 -35
- package/bin/lib/remove-project.js.map +0 -1
- package/bin/lib/replace.js +0 -107
- package/bin/lib/replace.js.map +0 -1
- package/bin/lib/types.js +0 -3
- package/bin/lib/types.js.map +0 -1
- package/bin/lib/utils/cleanFileName.js +0 -11
- package/bin/lib/utils/cleanFileName.js.map +0 -1
- package/bin/lib/utils/generateJsDriver.js +0 -56
- package/bin/lib/utils/generateJsDriver.js.map +0 -1
- package/bin/lib/utils/getSelectedProjects.js +0 -61
- package/bin/lib/utils/getSelectedProjects.js.map +0 -1
- package/bin/lib/utils/processMetaOption.js +0 -15
- package/bin/lib/utils/processMetaOption.js.map +0 -1
- package/bin/lib/utils/projectsToText.js +0 -25
- package/bin/lib/utils/projectsToText.js.map +0 -1
- package/bin/lib/utils/promptForProject.js +0 -43
- package/bin/lib/utils/promptForProject.js.map +0 -1
- package/bin/lib/utils/quit.js +0 -10
- package/bin/lib/utils/quit.js.map +0 -1
- package/bin/lib/utils/sourcesToText.js +0 -25
- package/bin/lib/utils/sourcesToText.js.map +0 -1
- package/bin/package.json +0 -76
|
@@ -1,23 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7dd5234f-c640-5939-abb0-c3c9967f3844")}catch(e){}}();
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var __async = (__this, __arguments, generator) => {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
var fulfilled = (value) => {
|
|
24
|
+
try {
|
|
25
|
+
step(generator.next(value));
|
|
26
|
+
} catch (e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var rejected = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.throw(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
38
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var fetchComponents_exports = {};
|
|
42
|
+
__export(fetchComponents_exports, {
|
|
43
|
+
fetchComponents: () => fetchComponents
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(fetchComponents_exports);
|
|
46
|
+
var import_api = require("../api");
|
|
47
|
+
function fetchComponents(options) {
|
|
48
|
+
return __async(this, null, function* () {
|
|
49
|
+
const api = (0, import_api.createApiClient)();
|
|
7
50
|
if (options.componentFolder) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
catch (e) {
|
|
13
|
-
console.log(`Failed to get components for ${options.componentFolder}. Please verify the folder's API ID.`);
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
const { data } = await api.get("/components", {});
|
|
51
|
+
try {
|
|
52
|
+
const { data } = yield api.get(`/component-folders/${options.componentFolder}/components`, {});
|
|
19
53
|
return data;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.log(`Failed to get components for ${options.componentFolder}. Please verify the folder's API ID.`);
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
const { data } = yield api.get("/components", {});
|
|
60
|
+
return data;
|
|
20
61
|
}
|
|
62
|
+
});
|
|
21
63
|
}
|
|
22
|
-
|
|
23
|
-
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
fetchComponents
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=fetchComponents.js.map
|
|
69
|
+
|
|
70
|
+
//# debugId=7dd5234f-c640-5939-abb0-c3c9967f3844
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../lib/http/fetchComponents.ts"],"sourcesContent":["import { createApiClient } from \"../api\";\n\nexport interface FetchComponentResponseComponent {\n name: string;\n text: string;\n status: \"NONE\" | \"WIP\" | \"REVIEW\" | \"FINAL\";\n folder: \"string\" | null;\n}\n\nexport interface FetchComponentResponse {\n [compApiId: string]: FetchComponentResponseComponent;\n}\n\nexport async function fetchComponents(options: {\n componentFolder?: string;\n}): Promise<FetchComponentResponse> {\n const api = createApiClient();\n\n if (options.componentFolder) {\n try {\n const { data } = await api.get<FetchComponentResponse>(`/component-folders/${options.componentFolder}/components`, {});\n\n return data;\n }\n catch (e) {\n console.log(`Failed to get components for ${options.componentFolder}. Please verify the folder's API ID.`)\n return {}\n }\n\n }\n else {\n const { data } = await api.get<FetchComponentResponse>(\"/components\", {});\n\n return data;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAgC;AAahC,SAAsB,gBAAgB,SAEF;AAAA;AAClC,UAAM,UAAM,4BAAgB;AAE5B,QAAI,QAAQ,iBAAiB;AAC3B,UAAI;AACF,cAAM,EAAE,KAAK,IAAI,MAAM,IAAI,IAA4B,sBAAsB,QAAQ,eAAe,eAAe,CAAC,CAAC;AAErH,eAAO;AAAA,MACT,SACO,GAAG;AACR,gBAAQ,IAAI,gCAAgC,QAAQ,eAAe,sCAAsC;AACzG,eAAO,CAAC;AAAA,MACV;AAAA,IAEF,OACK;AACH,YAAM,EAAE,KAAK,IAAI,MAAM,IAAI,IAA4B,eAAe,CAAC,CAAC;AAExE,aAAO;AAAA,IACT;AAAA,EACF;AAAA","debug_id":"7dd5234f-c640-5939-abb0-c3c9967f3844"}
|
|
@@ -1,24 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a797d52a-bb20-5f20-a27a-88b5d1c0d355")}catch(e){}}();
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
var __async = (__this, __arguments, generator) => {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
var fulfilled = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.next(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var rejected = (value) => {
|
|
45
|
+
try {
|
|
46
|
+
step(generator.throw(value));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
reject(e);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
52
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
var fetchVariants_exports = {};
|
|
56
|
+
__export(fetchVariants_exports, {
|
|
57
|
+
fetchVariants: () => fetchVariants
|
|
58
|
+
});
|
|
59
|
+
module.exports = __toCommonJS(fetchVariants_exports);
|
|
60
|
+
var import_api = require("../api");
|
|
61
|
+
function fetchVariants(_0) {
|
|
62
|
+
return __async(this, arguments, function* (source, options = {}) {
|
|
63
|
+
const api = (0, import_api.createApiClient)();
|
|
7
64
|
if (!source.variants) {
|
|
8
|
-
|
|
65
|
+
return null;
|
|
9
66
|
}
|
|
10
67
|
const { shouldFetchComponentLibrary, validProjects } = source;
|
|
11
68
|
const config = {
|
|
12
|
-
|
|
69
|
+
params: __spreadValues({}, options == null ? void 0 : options.meta)
|
|
13
70
|
};
|
|
14
|
-
// if we're not syncing from the component library, then we pass the project ids
|
|
15
|
-
// to limit the list of returned variants to only those that are relevant for the
|
|
16
|
-
// specified projects
|
|
17
71
|
if (validProjects.length && !shouldFetchComponentLibrary) {
|
|
18
|
-
|
|
72
|
+
config.params.projectIds = validProjects.map(({ id }) => id);
|
|
19
73
|
}
|
|
20
|
-
const { data } =
|
|
74
|
+
const { data } = yield api.get("/variants", config);
|
|
21
75
|
return data;
|
|
76
|
+
});
|
|
22
77
|
}
|
|
23
|
-
|
|
24
|
-
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
fetchVariants
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=fetchVariants.js.map
|
|
83
|
+
|
|
84
|
+
//# debugId=a797d52a-bb20-5f20-a27a-88b5d1c0d355
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../lib/http/fetchVariants.ts"],"sourcesContent":["import { AxiosRequestConfig } from \"axios\";\nimport { createApiClient } from \"../api\";\nimport { PullOptions } from \"../pull\";\nimport { SourceInformation } from \"../types\";\n\nexport async function fetchVariants(\n source: SourceInformation,\n options: PullOptions = {}\n) {\n const api = createApiClient();\n if (!source.variants) {\n return null;\n }\n\n const { shouldFetchComponentLibrary, validProjects } = source;\n\n const config: AxiosRequestConfig = {\n params: { ...options?.meta },\n };\n\n // if we're not syncing from the component library, then we pass the project ids\n // to limit the list of returned variants to only those that are relevant for the\n // specified projects\n if (validProjects.length && !shouldFetchComponentLibrary) {\n config.params.projectIds = validProjects.map(({ id }) => id);\n }\n\n const { data } = await api.get<{ apiID: string }[]>(\"/variants\", config);\n\n return data;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAgC;AAIhC,SAAsB,cACpB,IAEA;AAAA,6CAFA,QACA,UAAuB,CAAC,GACxB;AACA,UAAM,UAAM,4BAAgB;AAC5B,QAAI,CAAC,OAAO,UAAU;AACpB,aAAO;AAAA,IACT;AAEA,UAAM,EAAE,6BAA6B,cAAc,IAAI;AAEvD,UAAM,SAA6B;AAAA,MACjC,QAAQ,mBAAK,mCAAS;AAAA,IACxB;AAKA,QAAI,cAAc,UAAU,CAAC,6BAA6B;AACxD,aAAO,OAAO,aAAa,cAAc,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE;AAAA,IAC7D;AAEA,UAAM,EAAE,KAAK,IAAI,MAAM,IAAI,IAAyB,aAAa,MAAM;AAEvE,WAAO;AAAA,EACT;AAAA","debug_id":"a797d52a-bb20-5f20-a27a-88b5d1c0d355"}
|
|
@@ -1,56 +1,107 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ec7b95d4-d022-5a13-b768-78494577a7c4")}catch(e){}}();
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
27
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
42
|
+
mod
|
|
43
|
+
));
|
|
44
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
var __async = (__this, __arguments, generator) => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
var fulfilled = (value) => {
|
|
48
|
+
try {
|
|
49
|
+
step(generator.next(value));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
reject(e);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var rejected = (value) => {
|
|
55
|
+
try {
|
|
56
|
+
step(generator.throw(value));
|
|
57
|
+
} catch (e) {
|
|
58
|
+
reject(e);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
62
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
var importComponents_exports = {};
|
|
66
|
+
__export(importComponents_exports, {
|
|
67
|
+
importComponents: () => importComponents
|
|
68
|
+
});
|
|
69
|
+
module.exports = __toCommonJS(importComponents_exports);
|
|
70
|
+
var import_api = require("../api");
|
|
71
|
+
var import_form_data = __toESM(require("form-data"));
|
|
72
|
+
var import_fs = __toESM(require("fs"));
|
|
73
|
+
function importComponents(path, options) {
|
|
74
|
+
return __async(this, null, function* () {
|
|
75
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
76
|
+
const api = (0, import_api.createApiClient)();
|
|
77
|
+
const form = new import_form_data.default();
|
|
78
|
+
form.append("import", import_fs.default.createReadStream(path));
|
|
14
79
|
const requestOptions = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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,
|
|
80
|
+
method: "POST",
|
|
81
|
+
url: "/v1/components/file",
|
|
82
|
+
params: __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, ((_a = options.csvColumnMapping) == null ? void 0 : _a.name) ? { name: `[${options.csvColumnMapping.name}]` } : {}), ((_b = options.csvColumnMapping) == null ? void 0 : _b.text) ? { text: options.csvColumnMapping.text } : {}), ((_c = options.csvColumnMapping) == null ? void 0 : _c.notes) ? { notes: options.csvColumnMapping.notes } : {}), ((_d = options.csvColumnMapping) == null ? void 0 : _d.status) ? { status: options.csvColumnMapping.status } : {}), ((_e = options.csvColumnMapping) == null ? void 0 : _e.tags) ? { tags: options.csvColumnMapping.tags } : {}), ((_f = options.csvColumnMapping) == null ? void 0 : _f.componentId) ? { componentId: options.csvColumnMapping.componentId } : {}),
|
|
83
|
+
headers: {
|
|
84
|
+
"content-type": "multipart/form-data"
|
|
85
|
+
},
|
|
86
|
+
data: form
|
|
41
87
|
};
|
|
42
88
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
89
|
+
const { data } = yield api(requestOptions);
|
|
90
|
+
return data;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.error("Failed to import file.");
|
|
93
|
+
console.error(((_h = (_g = e.response) == null ? void 0 : _g.data) == null ? void 0 : _h.message) || e.message);
|
|
94
|
+
return {
|
|
95
|
+
componentsInserted: 0,
|
|
96
|
+
firstImportedId: "null"
|
|
97
|
+
};
|
|
53
98
|
}
|
|
99
|
+
});
|
|
54
100
|
}
|
|
55
|
-
|
|
56
|
-
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
importComponents
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=importComponents.js.map
|
|
106
|
+
|
|
107
|
+
//# debugId=ec7b95d4-d022-5a13-b768-78494577a7c4
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../lib/http/importComponents.ts"],"sourcesContent":["import { createApiClient } from \"../api\";\nimport FormData from \"form-data\";\nimport fs from \"fs\";\n\nexport interface ImportComponentResponse {\n componentsInserted: number;\n firstImportedId: string;\n}\n\nexport interface CsvColumnMapping {\n text: number;\n name: string;\n notes?: number;\n tags?: number;\n status?: number;\n componentId?: number;\n}\n\nexport async function importComponents(\n path: string,\n options: {\n csvColumnMapping?: CsvColumnMapping;\n }\n): Promise<ImportComponentResponse> {\n const api = createApiClient();\n\n const form = new FormData();\n form.append(\"import\", fs.createReadStream(path));\n\n const requestOptions = {\n method: \"POST\",\n url: \"/v1/components/file\",\n params: {\n ...(options.csvColumnMapping?.name\n ? { name: `[${options.csvColumnMapping.name}]` }\n : {}),\n ...(options.csvColumnMapping?.text\n ? { text: options.csvColumnMapping.text }\n : {}),\n ...(options.csvColumnMapping?.notes\n ? { notes: options.csvColumnMapping.notes }\n : {}),\n ...(options.csvColumnMapping?.status\n ? { status: options.csvColumnMapping.status }\n : {}),\n ...(options.csvColumnMapping?.tags\n ? { tags: options.csvColumnMapping.tags }\n : {}),\n ...(options.csvColumnMapping?.componentId\n ? { componentId: options.csvColumnMapping.componentId }\n : {}),\n },\n headers: {\n \"content-type\": \"multipart/form-data\",\n },\n data: form,\n };\n\n try {\n const { data } = await api(requestOptions);\n\n return data;\n } catch (e: any) {\n console.error(\"Failed to import file.\");\n console.error(e.response?.data?.message || e.message);\n return {\n componentsInserted: 0,\n firstImportedId: \"null\",\n };\n }\n}\n"],"names":["FormData","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAgC;AAChC,uBAAqB;AACrB,gBAAe;AAgBf,SAAsB,iBACpB,MACA,SAGkC;AAAA;AAvBpC;AAwBE,UAAM,UAAM,4BAAgB;AAE5B,UAAM,OAAO,IAAI,iBAAAA,QAAS;AAC1B,SAAK,OAAO,UAAU,UAAAC,QAAG,iBAAiB,IAAI,CAAC;AAE/C,UAAM,iBAAiB;AAAA,MACrB,QAAQ;AAAA,MACR,KAAK;AAAA,MACL,QAAQ,gGACF,aAAQ,qBAAR,mBAA0B,QAC1B,EAAE,MAAM,IAAI,QAAQ,iBAAiB,IAAI,IAAI,IAC7C,CAAC,MACD,aAAQ,qBAAR,mBAA0B,QAC1B,EAAE,MAAM,QAAQ,iBAAiB,KAAK,IACtC,CAAC,MACD,aAAQ,qBAAR,mBAA0B,SAC1B,EAAE,OAAO,QAAQ,iBAAiB,MAAM,IACxC,CAAC,MACD,aAAQ,qBAAR,mBAA0B,UAC1B,EAAE,QAAQ,QAAQ,iBAAiB,OAAO,IAC1C,CAAC,MACD,aAAQ,qBAAR,mBAA0B,QAC1B,EAAE,MAAM,QAAQ,iBAAiB,KAAK,IACtC,CAAC,MACD,aAAQ,qBAAR,mBAA0B,eAC1B,EAAE,aAAa,QAAQ,iBAAiB,YAAY,IACpD,CAAC;AAAA,MAEP,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM;AAAA,IACR;AAEA,QAAI;AACF,YAAM,EAAE,KAAK,IAAI,MAAM,IAAI,cAAc;AAEzC,aAAO;AAAA,IACT,SAAS,GAAQ;AACf,cAAQ,MAAM,wBAAwB;AACtC,cAAQ,QAAM,aAAE,aAAF,mBAAY,SAAZ,mBAAkB,YAAW,EAAE,OAAO;AACpD,aAAO;AAAA,QACL,oBAAoB;AAAA,QACpB,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AAAA","debug_id":"ec7b95d4-d022-5a13-b768-78494577a7c4"}
|
package/bin/importComponents.js
CHANGED
|
@@ -1,14 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3ae73857-3895-5816-b3a1-348da7b6ec1b")}catch(e){}}();
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var __async = (__this, __arguments, generator) => {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
var fulfilled = (value) => {
|
|
24
|
+
try {
|
|
25
|
+
step(generator.next(value));
|
|
26
|
+
} catch (e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var rejected = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.throw(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
38
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var importComponents_exports = {};
|
|
42
|
+
__export(importComponents_exports, {
|
|
43
|
+
importComponents: () => importComponents
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(importComponents_exports);
|
|
46
|
+
var import_importComponents = require("./http/importComponents");
|
|
47
|
+
function importComponents(filePath, options) {
|
|
48
|
+
return __async(this, null, function* () {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
if (filePath.endsWith(".csv") && (!((_a = options.csvColumnMapping) == null ? void 0 : _a.name) || !((_b = options.csvColumnMapping) == null ? void 0 : _b.text))) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
".csv files require the --component-name and --text flags."
|
|
53
|
+
);
|
|
9
54
|
}
|
|
10
|
-
const importResult =
|
|
55
|
+
const importResult = yield (0, import_importComponents.importComponents)(filePath, options);
|
|
11
56
|
console.log(JSON.stringify(importResult));
|
|
57
|
+
});
|
|
12
58
|
}
|
|
13
|
-
|
|
14
|
-
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
importComponents
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=importComponents.js.map
|
|
64
|
+
|
|
65
|
+
//# debugId=3ae73857-3895-5816-b3a1-348da7b6ec1b
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../lib/importComponents.ts"],"sourcesContent":["import {\n CsvColumnMapping,\n importComponents as importComponentsHttp,\n} from \"./http/importComponents\";\n\nasync function importComponents(\n filePath: string,\n options: {\n csvColumnMapping?: CsvColumnMapping;\n }\n) {\n if (\n filePath.endsWith(\".csv\") &&\n (!options.csvColumnMapping?.name || !options.csvColumnMapping?.text)\n ) {\n throw new Error(\n \".csv files require the --component-name and --text flags.\"\n );\n }\n const importResult = await importComponentsHttp(filePath, options);\n console.log(JSON.stringify(importResult));\n}\n\nexport { importComponents };\n"],"names":["importComponentsHttp"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAGO;AAEP,SAAe,iBACb,UACA,SAGA;AAAA;AAVF;AAWE,QACE,SAAS,SAAS,MAAM,MACvB,GAAC,aAAQ,qBAAR,mBAA0B,SAAQ,GAAC,aAAQ,qBAAR,mBAA0B,QAC/D;AACA,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,UAAM,eAAe,UAAM,wBAAAA,kBAAqB,UAAU,OAAO;AACjE,YAAQ,IAAI,KAAK,UAAU,YAAY,CAAC;AAAA,EAC1C;AAAA","debug_id":"3ae73857-3895-5816-b3a1-348da7b6ec1b"}
|