@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
package/bin/remove-project.js
CHANGED
|
@@ -1,35 +1,99 @@
|
|
|
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]="02db58e2-181b-532d-8678-792f107e5740")}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 __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
13
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
var __async = (__this, __arguments, generator) => {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
var fulfilled = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
step(generator.next(value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var rejected = (value) => {
|
|
41
|
+
try {
|
|
42
|
+
step(generator.throw(value));
|
|
43
|
+
} catch (e) {
|
|
44
|
+
reject(e);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
48
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
var remove_project_exports = {};
|
|
52
|
+
__export(remove_project_exports, {
|
|
53
|
+
default: () => remove_project_default
|
|
54
|
+
});
|
|
55
|
+
module.exports = __toCommonJS(remove_project_exports);
|
|
56
|
+
var import_config = __toESM(require("./config"));
|
|
57
|
+
var import_consts = __toESM(require("./consts"));
|
|
58
|
+
var import_output = __toESM(require("./output"));
|
|
59
|
+
var import_getSelectedProjects = require("./utils/getSelectedProjects");
|
|
60
|
+
var import_promptForProject = __toESM(require("./utils/promptForProject"));
|
|
61
|
+
function removeProject() {
|
|
62
|
+
return __async(this, null, function* () {
|
|
63
|
+
const projects = (0, import_getSelectedProjects.getSelectedProjects)();
|
|
64
|
+
const isUsingComponents = (0, import_getSelectedProjects.getIsUsingComponents)();
|
|
14
65
|
if (!projects.length && !isUsingComponents) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
66
|
+
console.log(
|
|
67
|
+
`
|
|
68
|
+
No projects found in your current configuration.
|
|
69
|
+
Try adding one with: ${import_output.default.info("ditto-cli project add")}
|
|
70
|
+
`
|
|
71
|
+
);
|
|
72
|
+
return;
|
|
19
73
|
}
|
|
20
|
-
const projectToRemove =
|
|
21
|
-
|
|
22
|
-
|
|
74
|
+
const projectToRemove = yield (0, import_promptForProject.default)({
|
|
75
|
+
projects,
|
|
76
|
+
message: "Select a project to remove"
|
|
23
77
|
});
|
|
24
78
|
if (!projectToRemove)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
79
|
+
return;
|
|
80
|
+
import_config.default.writeProjectConfigData(import_consts.default.PROJECT_CONFIG_FILE, {
|
|
81
|
+
components: isUsingComponents && projectToRemove.id !== "components",
|
|
82
|
+
projects: projects.filter(({ id }) => id !== projectToRemove.id)
|
|
29
83
|
});
|
|
30
|
-
console.log(
|
|
31
|
-
|
|
32
|
-
|
|
84
|
+
console.log(
|
|
85
|
+
`
|
|
86
|
+
${import_output.default.info(
|
|
87
|
+
projectToRemove.name
|
|
88
|
+
)} has been removed from your selected projects.
|
|
89
|
+
We saved your updated configuration to: ${import_output.default.info(
|
|
90
|
+
import_consts.default.PROJECT_CONFIG_FILE
|
|
91
|
+
)}
|
|
92
|
+
`
|
|
93
|
+
);
|
|
94
|
+
});
|
|
33
95
|
}
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=remove-project.js.map
|
|
96
|
+
var remove_project_default = removeProject;
|
|
97
|
+
//# sourceMappingURL=remove-project.js.map
|
|
98
|
+
|
|
99
|
+
//# debugId=02db58e2-181b-532d-8678-792f107e5740
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../lib/remove-project.ts"],"sourcesContent":["import config from \"./config\";\nimport consts from \"./consts\";\nimport output from \"./output\";\nimport {\n getSelectedProjects,\n getIsUsingComponents,\n} from \"./utils/getSelectedProjects\";\nimport promptForProject from \"./utils/promptForProject\";\n\nasync function removeProject() {\n const projects = getSelectedProjects();\n const isUsingComponents = getIsUsingComponents();\n if (!projects.length && !isUsingComponents) {\n console.log(\n \"\\n\" +\n \"No projects found in your current configuration.\\n\" +\n `Try adding one with: ${output.info(\"ditto-cli project add\")}\\n`\n );\n return;\n }\n\n const projectToRemove = await promptForProject({\n projects,\n message: \"Select a project to remove\",\n });\n if (!projectToRemove) return;\n\n config.writeProjectConfigData(consts.PROJECT_CONFIG_FILE, {\n components: isUsingComponents && projectToRemove.id !== \"components\",\n projects: projects.filter(({ id }) => id !== projectToRemove.id),\n });\n\n console.log(\n `\\n${output.info(\n projectToRemove.name\n )} has been removed from your selected projects. ` +\n `\\nWe saved your updated configuration to: ${output.info(\n consts.PROJECT_CONFIG_FILE\n )}` +\n \"\\n\"\n );\n}\n\nexport default removeProject;\n"],"names":["output","promptForProject","config","consts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,oBAAmB;AACnB,oBAAmB;AACnB,iCAGO;AACP,8BAA6B;AAE7B,SAAe,gBAAgB;AAAA;AAC7B,UAAM,eAAW,gDAAoB;AACrC,UAAM,wBAAoB,iDAAqB;AAC/C,QAAI,CAAC,SAAS,UAAU,CAAC,mBAAmB;AAC1C,cAAQ;AAAA,QACN;AAAA;AAAA,uBAE0B,cAAAA,QAAO,KAAK,uBAAuB,CAAC;AAAA;AAAA,MAChE;AACA;AAAA,IACF;AAEA,UAAM,kBAAkB,UAAM,wBAAAC,SAAiB;AAAA,MAC7C;AAAA,MACA,SAAS;AAAA,IACX,CAAC;AACD,QAAI,CAAC;AAAiB;AAEtB,kBAAAC,QAAO,uBAAuB,cAAAC,QAAO,qBAAqB;AAAA,MACxD,YAAY,qBAAqB,gBAAgB,OAAO;AAAA,MACxD,UAAU,SAAS,OAAO,CAAC,EAAE,GAAG,MAAM,OAAO,gBAAgB,EAAE;AAAA,IACjE,CAAC;AAED,YAAQ;AAAA,MACN;AAAA,EAAK,cAAAH,QAAO;AAAA,QACV,gBAAgB;AAAA,MAClB,CAAC;AAAA,0CAC8C,cAAAA,QAAO;AAAA,QAClD,cAAAG,QAAO;AAAA,MACT,CAAC;AAAA;AAAA,IAEL;AAAA,EACF;AAAA;AAEA,IAAO,yBAAQ","debug_id":"02db58e2-181b-532d-8678-792f107e5740"}
|
package/bin/replace.js
CHANGED
|
@@ -1,114 +1,154 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
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]="176ee92a-54a5-5a85-aae1-a4ff1f467ec8")}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 __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
24
21
|
};
|
|
25
|
-
var
|
|
26
|
-
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
var __async = (__this, __arguments, generator) => {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
var fulfilled = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
step(generator.next(value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var rejected = (value) => {
|
|
41
|
+
try {
|
|
42
|
+
step(generator.throw(value));
|
|
43
|
+
} catch (e) {
|
|
44
|
+
reject(e);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
48
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
49
|
+
});
|
|
27
50
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
var replace_exports = {};
|
|
52
|
+
__export(replace_exports, {
|
|
53
|
+
parseOptions: () => parseOptions,
|
|
54
|
+
replace: () => replace,
|
|
55
|
+
replaceJSXTextInFile: () => replaceJSXTextInFile
|
|
56
|
+
});
|
|
57
|
+
module.exports = __toCommonJS(replace_exports);
|
|
58
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
59
|
+
var import_parser = require("@babel/parser");
|
|
60
|
+
var import_traverse = __toESM(require("@babel/traverse"));
|
|
61
|
+
var t = __toESM(require("@babel/types"));
|
|
62
|
+
var import_core = require("@babel/core");
|
|
63
|
+
function replaceJSXTextInFile(filePath, replacement, flags) {
|
|
64
|
+
return __async(this, null, function* () {
|
|
65
|
+
const code = yield import_fs_extra.default.readFile(filePath, "utf-8");
|
|
66
|
+
const ast = (0, import_parser.parse)(code, {
|
|
67
|
+
sourceType: "module",
|
|
68
|
+
plugins: ["jsx", "typescript"]
|
|
40
69
|
});
|
|
41
|
-
(0,
|
|
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
|
-
|
|
70
|
+
(0, import_traverse.default)(ast, {
|
|
71
|
+
JSXText(path) {
|
|
72
|
+
const { searchString, replaceWith } = replacement;
|
|
73
|
+
const searchStringEscaped = searchString.replace(
|
|
74
|
+
/[.*+?^${}()|[\]\\]/g,
|
|
75
|
+
"\\$&"
|
|
76
|
+
);
|
|
77
|
+
const regex = new RegExp(searchStringEscaped, "gi");
|
|
78
|
+
if (regex.test(path.node.value)) {
|
|
79
|
+
if (flags.lineNumbers && path.node.loc && !flags.lineNumbers.includes(path.node.loc.start.line)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const splitValues = splitByCaseInsensitive(
|
|
83
|
+
path.node.value,
|
|
84
|
+
searchStringEscaped
|
|
85
|
+
);
|
|
86
|
+
const nodes = [];
|
|
87
|
+
splitValues.forEach((splitValue) => {
|
|
88
|
+
if (splitValue.toLowerCase() === searchString.toLowerCase()) {
|
|
89
|
+
const identifier = t.jsxIdentifier("DittoComponent");
|
|
90
|
+
const componentId = t.jsxAttribute(
|
|
91
|
+
t.jsxIdentifier("componentId"),
|
|
92
|
+
t.stringLiteral(replaceWith)
|
|
93
|
+
);
|
|
94
|
+
const o = t.jsxOpeningElement(identifier, [componentId], true);
|
|
95
|
+
const jsxElement = t.jsxElement(o, void 0, [], true);
|
|
96
|
+
nodes.push(jsxElement);
|
|
97
|
+
} else {
|
|
98
|
+
nodes.push(t.jsxText(splitValue));
|
|
68
99
|
}
|
|
69
|
-
|
|
100
|
+
});
|
|
101
|
+
path.replaceWithMultiple(nodes);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
70
104
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// Don't let this codebase's Babel config affect the code we're transforming.
|
|
75
|
-
configFile: false,
|
|
105
|
+
const { code: transformedCode } = (0, import_core.transformFromAst)(ast, code, {
|
|
106
|
+
// Don't let this codebase's Babel config affect the code we're transforming.
|
|
107
|
+
configFile: false
|
|
76
108
|
});
|
|
77
|
-
|
|
109
|
+
import_fs_extra.default.writeFile(filePath, transformedCode);
|
|
110
|
+
});
|
|
78
111
|
}
|
|
79
|
-
exports.replaceJSXTextInFile = replaceJSXTextInFile;
|
|
80
112
|
function splitByCaseInsensitive(str, delimiter) {
|
|
81
|
-
|
|
113
|
+
return str.split(new RegExp(`(${delimiter})`, "gi")).filter((s) => s !== "");
|
|
82
114
|
}
|
|
83
115
|
function replace(options, flags) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
116
|
+
let filePath;
|
|
117
|
+
let searchString;
|
|
118
|
+
let replaceWith;
|
|
119
|
+
try {
|
|
120
|
+
const parsedOptions = parseOptions(options);
|
|
121
|
+
filePath = parsedOptions.filePath;
|
|
122
|
+
searchString = parsedOptions.searchString;
|
|
123
|
+
replaceWith = parsedOptions.replaceWith;
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.error(e);
|
|
126
|
+
console.error(
|
|
127
|
+
"Usage for replace: ditto-cli replace <file path> <search string> <replace with>"
|
|
128
|
+
);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
replaceJSXTextInFile(filePath, { searchString, replaceWith }, flags);
|
|
99
132
|
}
|
|
100
|
-
exports.replace = replace;
|
|
101
133
|
function parseOptions(options) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
134
|
+
if (options.length !== 3) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
"The options array must contain <file path> <search string> <replace with>."
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
const filePath = options[0];
|
|
140
|
+
const isFilePathValid = import_fs_extra.default.existsSync(filePath) && import_fs_extra.default.lstatSync(filePath).isFile();
|
|
141
|
+
if (!isFilePathValid) {
|
|
142
|
+
throw new Error(`${filePath} is not a valid file path.`);
|
|
143
|
+
}
|
|
144
|
+
return { filePath, searchString: options[1], replaceWith: options[2] };
|
|
112
145
|
}
|
|
113
|
-
|
|
114
|
-
|
|
146
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
147
|
+
0 && (module.exports = {
|
|
148
|
+
parseOptions,
|
|
149
|
+
replace,
|
|
150
|
+
replaceJSXTextInFile
|
|
151
|
+
});
|
|
152
|
+
//# sourceMappingURL=replace.js.map
|
|
153
|
+
|
|
154
|
+
//# debugId=176ee92a-54a5-5a85-aae1-a4ff1f467ec8
|
package/bin/replace.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../lib/replace.ts"],"sourcesContent":["import fs from \"fs-extra\";\nimport { parse } from \"@babel/parser\";\nimport traverse from \"@babel/traverse\";\nimport * as t from \"@babel/types\";\nimport { transformFromAst } from \"@babel/core\";\n\nasync function replaceJSXTextInFile(\n filePath: string,\n replacement: { searchString: string; replaceWith: string },\n flags: {\n lineNumbers?: number[];\n }\n) {\n const code = await fs.readFile(filePath, \"utf-8\");\n const ast = parse(code, {\n sourceType: \"module\",\n plugins: [\"jsx\", \"typescript\"],\n });\n\n traverse(ast, {\n JSXText(path) {\n const { searchString, replaceWith } = replacement;\n\n const searchStringEscaped = searchString.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n \"\\\\$&\"\n );\n const regex = new RegExp(searchStringEscaped, \"gi\");\n if (regex.test(path.node.value)) {\n // Ignore if not on a line number that we want to replace.\n if (\n flags.lineNumbers &&\n path.node.loc &&\n !flags.lineNumbers.includes(path.node.loc.start.line)\n ) {\n return;\n }\n\n const splitValues = splitByCaseInsensitive(\n path.node.value,\n searchStringEscaped\n );\n const nodes: (t.JSXElement | t.JSXText)[] = [];\n\n splitValues.forEach((splitValue) => {\n if (splitValue.toLowerCase() === searchString.toLowerCase()) {\n const identifier = t.jsxIdentifier(\"DittoComponent\");\n const componentId = t.jsxAttribute(\n t.jsxIdentifier(\"componentId\"),\n t.stringLiteral(replaceWith)\n );\n const o = t.jsxOpeningElement(identifier, [componentId], true);\n const jsxElement = t.jsxElement(o, undefined, [], true);\n nodes.push(jsxElement);\n } else {\n nodes.push(t.jsxText(splitValue));\n }\n });\n\n path.replaceWithMultiple(nodes);\n }\n },\n });\n\n // transfromFromAst types are wrong?\n /* @ts-ignore */\n const { code: transformedCode } = transformFromAst(ast, code, {\n // Don't let this codebase's Babel config affect the code we're transforming.\n configFile: false,\n });\n fs.writeFile(filePath, transformedCode);\n}\n\nfunction splitByCaseInsensitive(str: string, delimiter: string) {\n return str.split(new RegExp(`(${delimiter})`, \"gi\")).filter((s) => s !== \"\");\n}\n\nfunction replace(options: string[], flags: { lineNumbers?: number[] }) {\n let filePath: string;\n let searchString: string;\n let replaceWith: string;\n\n try {\n const parsedOptions = parseOptions(options);\n filePath = parsedOptions.filePath;\n searchString = parsedOptions.searchString;\n replaceWith = parsedOptions.replaceWith;\n } catch (e) {\n console.error(e);\n console.error(\n \"Usage for replace: ditto-cli replace <file path> <search string> <replace with>\"\n );\n return;\n }\n\n replaceJSXTextInFile(filePath, { searchString, replaceWith }, flags);\n}\n\nfunction parseOptions(options: string[]): {\n filePath: string;\n searchString: string;\n replaceWith: string;\n} {\n if (options.length !== 3) {\n throw new Error(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n }\n\n const filePath = options[0];\n // Check if the file path exists and points to a regular file (not a directory or other file system object).\n const isFilePathValid =\n fs.existsSync(filePath) && fs.lstatSync(filePath).isFile();\n\n if (!isFilePathValid) {\n throw new Error(`${filePath} is not a valid file path.`);\n }\n\n return { filePath, searchString: options[1], replaceWith: options[2] };\n}\n\nexport { replace, parseOptions, replaceJSXTextInFile };\n"],"names":["fs","traverse"],"mappings":"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","debug_id":"176ee92a-54a5-5a85-aae1-a4ff1f467ec8"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
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]="88bc0e18-7209-5d12-95f3-62e752160eb4")}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 __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
var __async = (__this, __arguments, generator) => {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
var fulfilled = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.next(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var rejected = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.throw(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
43
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
47
|
+
var import_replace = require("./replace");
|
|
48
|
+
function createTempJSXFile(content) {
|
|
49
|
+
return __async(this, null, function* () {
|
|
50
|
+
const tempFile = "tempFile.jsx";
|
|
51
|
+
yield import_promises.default.writeFile(tempFile, content);
|
|
52
|
+
return tempFile;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function deleteTempFile(filePath) {
|
|
56
|
+
return __async(this, null, function* () {
|
|
57
|
+
yield import_promises.default.unlink(filePath);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
describe("parseOptions", () => {
|
|
61
|
+
test("should pass with valid input", () => __async(exports, null, function* () {
|
|
62
|
+
const tempFile = yield createTempJSXFile("<div>Hello, world!</div>");
|
|
63
|
+
expect(
|
|
64
|
+
() => (0, import_replace.parseOptions)([tempFile, "secondString", "thirdString"])
|
|
65
|
+
).not.toThrow();
|
|
66
|
+
const result = (0, import_replace.parseOptions)([tempFile, "secondString", "thirdString"]);
|
|
67
|
+
expect(result).toEqual({
|
|
68
|
+
filePath: tempFile,
|
|
69
|
+
searchString: "secondString",
|
|
70
|
+
replaceWith: "thirdString"
|
|
71
|
+
});
|
|
72
|
+
deleteTempFile(tempFile);
|
|
73
|
+
}));
|
|
74
|
+
test("should throw error when options array does not have exactly three strings", () => {
|
|
75
|
+
expect(() => (0, import_replace.parseOptions)(["oneString"])).toThrow(
|
|
76
|
+
"The options array must contain <file path> <search string> <replace with>."
|
|
77
|
+
);
|
|
78
|
+
expect(() => (0, import_replace.parseOptions)(["one", "two"])).toThrow(
|
|
79
|
+
"The options array must contain <file path> <search string> <replace with>."
|
|
80
|
+
);
|
|
81
|
+
expect(() => (0, import_replace.parseOptions)(["one", "two", "three", "four"])).toThrow(
|
|
82
|
+
"The options array must contain <file path> <search string> <replace with>."
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
test("should throw error when the first string is not a valid file path", () => {
|
|
86
|
+
const invalidFilePath = "/path/to/invalid/file.txt";
|
|
87
|
+
expect(
|
|
88
|
+
() => (0, import_replace.parseOptions)([invalidFilePath, "secondString", "thirdString"])
|
|
89
|
+
).toThrow(`${invalidFilePath} is not a valid file path.`);
|
|
90
|
+
});
|
|
91
|
+
test("should throw error when the first string is a directory", () => {
|
|
92
|
+
const directoryPath = ".";
|
|
93
|
+
expect(
|
|
94
|
+
() => (0, import_replace.parseOptions)([directoryPath, "secondString", "thirdString"])
|
|
95
|
+
).toThrow(`${directoryPath} is not a valid file path.`);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
describe("replaceJSXTextInFile", () => {
|
|
99
|
+
afterEach(() => __async(exports, null, function* () {
|
|
100
|
+
yield deleteTempFile("tempFile.jsx");
|
|
101
|
+
}));
|
|
102
|
+
test("should replace JSX text with a DittoComponent", () => __async(exports, null, function* () {
|
|
103
|
+
const tempFile = yield createTempJSXFile("<div>Hello, world</div>");
|
|
104
|
+
const searchString = "world";
|
|
105
|
+
const replaceWith = "some-id";
|
|
106
|
+
yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
|
|
107
|
+
const transformedCode = yield import_promises.default.readFile(tempFile, "utf-8");
|
|
108
|
+
expect(transformedCode).toContain(
|
|
109
|
+
`<div>Hello, <DittoComponent componentId="${replaceWith}" /></div>`
|
|
110
|
+
);
|
|
111
|
+
}));
|
|
112
|
+
test("should replace JSX text with a DittoComponent with a flag", () => __async(exports, null, function* () {
|
|
113
|
+
const tempFile = yield createTempJSXFile(
|
|
114
|
+
`<>
|
|
115
|
+
<div>Hello, world</div>
|
|
116
|
+
<div>Hello, world</div>
|
|
117
|
+
</>`
|
|
118
|
+
);
|
|
119
|
+
const searchString = "world";
|
|
120
|
+
const replaceWith = "some-id";
|
|
121
|
+
yield (0, import_replace.replaceJSXTextInFile)(
|
|
122
|
+
tempFile,
|
|
123
|
+
{ searchString, replaceWith },
|
|
124
|
+
{ lineNumbers: [3] }
|
|
125
|
+
);
|
|
126
|
+
const transformedCode = yield import_promises.default.readFile(tempFile, "utf-8");
|
|
127
|
+
expect(transformedCode).toContain(
|
|
128
|
+
`<>
|
|
129
|
+
<div>Hello, world</div>
|
|
130
|
+
<div>Hello, <DittoComponent componentId="some-id" /></div>
|
|
131
|
+
</>;`
|
|
132
|
+
);
|
|
133
|
+
}));
|
|
134
|
+
test("should handle case-insensitive search", () => __async(exports, null, function* () {
|
|
135
|
+
const tempFile = yield createTempJSXFile("<div>HeLLo, WoRlD</div>");
|
|
136
|
+
const searchString = "world";
|
|
137
|
+
const replaceWith = "some-id";
|
|
138
|
+
yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
|
|
139
|
+
const transformedCode = yield import_promises.default.readFile(tempFile, "utf-8");
|
|
140
|
+
expect(transformedCode).toContain(
|
|
141
|
+
`<div>HeLLo, <DittoComponent componentId="${replaceWith}" /></div>`
|
|
142
|
+
);
|
|
143
|
+
}));
|
|
144
|
+
test("should not replace JSX text if searchString is not found", () => __async(exports, null, function* () {
|
|
145
|
+
const tempFile = yield createTempJSXFile("<div>Hello, world!</div>");
|
|
146
|
+
const searchString = "foobar";
|
|
147
|
+
const replaceWith = "some-id";
|
|
148
|
+
yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
|
|
149
|
+
const transformedCode = yield import_promises.default.readFile(tempFile, "utf-8");
|
|
150
|
+
expect(transformedCode).toContain("<div>Hello, world!</div>");
|
|
151
|
+
}));
|
|
152
|
+
});
|
|
153
|
+
//# sourceMappingURL=replace.test.js.map
|
|
154
|
+
|
|
155
|
+
//# debugId=88bc0e18-7209-5d12-95f3-62e752160eb4
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/replace.test.ts"],"sourcesContent":["import fs from \"fs/promises\";\nimport { parseOptions, replaceJSXTextInFile } from \"./replace\"; // Assuming the function is exported in a separate file\n\n// Helper function to create a temporary file\nasync function createTempJSXFile(content: string): Promise<string> {\n const tempFile = \"tempFile.jsx\";\n await fs.writeFile(tempFile, content);\n return tempFile;\n}\n\n// Helper function to delete the temporary file\nasync function deleteTempFile(filePath: string): Promise<void> {\n await fs.unlink(filePath);\n}\n\ndescribe(\"parseOptions\", () => {\n test(\"should pass with valid input\", async () => {\n const tempFile = await createTempJSXFile(\"<div>Hello, world!</div>\");\n expect(() =>\n parseOptions([tempFile, \"secondString\", \"thirdString\"])\n ).not.toThrow();\n\n const result = parseOptions([tempFile, \"secondString\", \"thirdString\"]);\n expect(result).toEqual({\n filePath: tempFile,\n searchString: \"secondString\",\n replaceWith: \"thirdString\",\n });\n\n deleteTempFile(tempFile);\n });\n\n test(\"should throw error when options array does not have exactly three strings\", () => {\n expect(() => parseOptions([\"oneString\"])).toThrow(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n expect(() => parseOptions([\"one\", \"two\"])).toThrow(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n expect(() => parseOptions([\"one\", \"two\", \"three\", \"four\"])).toThrow(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n });\n\n test(\"should throw error when the first string is not a valid file path\", () => {\n const invalidFilePath = \"/path/to/invalid/file.txt\";\n expect(() =>\n parseOptions([invalidFilePath, \"secondString\", \"thirdString\"])\n ).toThrow(`${invalidFilePath} is not a valid file path.`);\n });\n\n test(\"should throw error when the first string is a directory\", () => {\n const directoryPath = \".\";\n expect(() =>\n parseOptions([directoryPath, \"secondString\", \"thirdString\"])\n ).toThrow(`${directoryPath} is not a valid file path.`);\n });\n});\n\n// TODO: this is flaky\ndescribe(\"replaceJSXTextInFile\", () => {\n afterEach(async () => {\n await deleteTempFile(\"tempFile.jsx\");\n });\n\n test(\"should replace JSX text with a DittoComponent\", async () => {\n const tempFile = await createTempJSXFile(\"<div>Hello, world</div>\");\n const searchString = \"world\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(tempFile, { searchString, replaceWith }, {});\n\n const transformedCode = await fs.readFile(tempFile, \"utf-8\");\n expect(transformedCode).toContain(\n `<div>Hello, <DittoComponent componentId=\"${replaceWith}\" /></div>`\n );\n });\n\n test(\"should replace JSX text with a DittoComponent with a flag\", async () => {\n const tempFile = await createTempJSXFile(\n `<>\\n<div>Hello, world</div>\\n<div>Hello, world</div>\\n</>`\n );\n const searchString = \"world\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(\n tempFile,\n { searchString, replaceWith },\n { lineNumbers: [3] }\n );\n\n const transformedCode = await fs.readFile(tempFile, \"utf-8\");\n expect(transformedCode).toContain(\n `<>\\n <div>Hello, world</div>\\n <div>Hello, <DittoComponent componentId=\\\"some-id\\\" /></div>\\n</>;`\n );\n });\n\n test(\"should handle case-insensitive search\", async () => {\n const tempFile = await createTempJSXFile(\"<div>HeLLo, WoRlD</div>\");\n const searchString = \"world\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(tempFile, { searchString, replaceWith }, {});\n\n const transformedCode = await fs.readFile(tempFile, \"utf-8\");\n expect(transformedCode).toContain(\n `<div>HeLLo, <DittoComponent componentId=\"${replaceWith}\" /></div>`\n );\n });\n\n test(\"should not replace JSX text if searchString is not found\", async () => {\n const tempFile = await createTempJSXFile(\"<div>Hello, world!</div>\");\n const searchString = \"foobar\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(tempFile, { searchString, replaceWith }, {});\n\n const transformedCode = await fs.readFile(tempFile, \"utf-8\");\n expect(transformedCode).toContain(\"<div>Hello, world!</div>\");\n });\n});\n"],"names":["fs"],"mappings":"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","debug_id":"88bc0e18-7209-5d12-95f3-62e752160eb4"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/sentry-test.ts"],"sourcesContent":["import * as Sentry from \"@sentry/node\";\nSentry.init({\n dsn: \"https://9c1d99fa4267f54c6b914f720b4ed3a2@o979374.ingest.sentry.io/4505705213919232\",\n debug: true,\n});\nSentry.captureException(new Error(\"new test exception\"));\nconsole.log(\"captured exception\");\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,aAAwB;AACxB,OAAO,KAAK;AAAA,EACV,KAAK;AAAA,EACL,OAAO;AACT,CAAC;AACD,OAAO,iBAAiB,IAAI,MAAM,oBAAoB,CAAC;AACvD,QAAQ,IAAI,oBAAoB","debug_id":"01741d01-3103-54ae-87e5-0199defce6e9"}
|