@dittowords/cli 4.5.2 → 5.0.0-beta.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.
Files changed (171) hide show
  1. package/README.md +6 -5
  2. package/bin/ditto.js +110 -285
  3. package/package.json +16 -10
  4. package/.github/actions/install-node-dependencies/action.yml +0 -24
  5. package/.github/workflows/required-checks.yml +0 -24
  6. package/.husky/pre-commit +0 -4
  7. package/.prettierignore +0 -0
  8. package/.prettierrc.json +0 -1
  9. package/__mocks__/fs.js +0 -2
  10. package/babel.config.js +0 -6
  11. package/bin/__mocks__/api.js +0 -48
  12. package/bin/__mocks__/api.js.map +0 -1
  13. package/bin/add-project.js +0 -104
  14. package/bin/add-project.js.map +0 -1
  15. package/bin/api.js +0 -54
  16. package/bin/api.js.map +0 -1
  17. package/bin/component-folders.js +0 -59
  18. package/bin/component-folders.js.map +0 -1
  19. package/bin/config.js +0 -242
  20. package/bin/config.js.map +0 -1
  21. package/bin/config.test.js +0 -93
  22. package/bin/config.test.js.map +0 -1
  23. package/bin/consts.js +0 -57
  24. package/bin/consts.js.map +0 -1
  25. package/bin/ditto.js.map +0 -1
  26. package/bin/generate-suggestions.js +0 -183
  27. package/bin/generate-suggestions.js.map +0 -1
  28. package/bin/generate-suggestions.test.js +0 -200
  29. package/bin/generate-suggestions.test.js.map +0 -1
  30. package/bin/http/__mocks__/fetchComponentFolders.js +0 -71
  31. package/bin/http/__mocks__/fetchComponentFolders.js.map +0 -1
  32. package/bin/http/__mocks__/fetchComponents.js +0 -73
  33. package/bin/http/__mocks__/fetchComponents.js.map +0 -1
  34. package/bin/http/__mocks__/fetchVariants.js +0 -71
  35. package/bin/http/__mocks__/fetchVariants.js.map +0 -1
  36. package/bin/http/fetchComponentFolders.js +0 -64
  37. package/bin/http/fetchComponentFolders.js.map +0 -1
  38. package/bin/http/fetchComponents.js +0 -78
  39. package/bin/http/fetchComponents.js.map +0 -1
  40. package/bin/http/fetchVariants.js +0 -87
  41. package/bin/http/fetchVariants.js.map +0 -1
  42. package/bin/http/http.test.js +0 -159
  43. package/bin/http/http.test.js.map +0 -1
  44. package/bin/http/importComponents.js +0 -114
  45. package/bin/http/importComponents.js.map +0 -1
  46. package/bin/importComponents.js +0 -65
  47. package/bin/importComponents.js.map +0 -1
  48. package/bin/init/init.js +0 -126
  49. package/bin/init/init.js.map +0 -1
  50. package/bin/init/project.js +0 -182
  51. package/bin/init/project.js.map +0 -1
  52. package/bin/init/project.test.js +0 -26
  53. package/bin/init/project.test.js.map +0 -1
  54. package/bin/init/token.js +0 -196
  55. package/bin/init/token.js.map +0 -1
  56. package/bin/init/token.test.js +0 -147
  57. package/bin/init/token.test.js.map +0 -1
  58. package/bin/output.js +0 -76
  59. package/bin/output.js.map +0 -1
  60. package/bin/pull-lib.test.js +0 -379
  61. package/bin/pull-lib.test.js.map +0 -1
  62. package/bin/pull.js +0 -562
  63. package/bin/pull.js.map +0 -1
  64. package/bin/pull.test.js +0 -151
  65. package/bin/pull.test.js.map +0 -1
  66. package/bin/remove-project.js +0 -99
  67. package/bin/remove-project.js.map +0 -1
  68. package/bin/replace.js +0 -171
  69. package/bin/replace.js.map +0 -1
  70. package/bin/replace.test.js +0 -197
  71. package/bin/replace.test.js.map +0 -1
  72. package/bin/types.js +0 -21
  73. package/bin/types.js.map +0 -1
  74. package/bin/utils/cleanFileName.js +0 -40
  75. package/bin/utils/cleanFileName.js.map +0 -1
  76. package/bin/utils/cleanFileName.test.js +0 -15
  77. package/bin/utils/cleanFileName.test.js.map +0 -1
  78. package/bin/utils/createSentryContext.js +0 -43
  79. package/bin/utils/createSentryContext.js.map +0 -1
  80. package/bin/utils/determineModuleType.js +0 -79
  81. package/bin/utils/determineModuleType.js.map +0 -1
  82. package/bin/utils/determineModuleType.test.js +0 -60
  83. package/bin/utils/determineModuleType.test.js.map +0 -1
  84. package/bin/utils/generateIOSBundles.js +0 -147
  85. package/bin/utils/generateIOSBundles.js.map +0 -1
  86. package/bin/utils/generateJsDriver.js +0 -178
  87. package/bin/utils/generateJsDriver.js.map +0 -1
  88. package/bin/utils/generateJsDriverTypeFile.js +0 -105
  89. package/bin/utils/generateJsDriverTypeFile.js.map +0 -1
  90. package/bin/utils/generateSwiftDriver.js +0 -93
  91. package/bin/utils/generateSwiftDriver.js.map +0 -1
  92. package/bin/utils/getSelectedProjects.js +0 -67
  93. package/bin/utils/getSelectedProjects.js.map +0 -1
  94. package/bin/utils/processMetaOption.js +0 -40
  95. package/bin/utils/processMetaOption.js.map +0 -1
  96. package/bin/utils/processMetaOption.test.js +0 -45
  97. package/bin/utils/processMetaOption.test.js.map +0 -1
  98. package/bin/utils/projectsToText.js +0 -58
  99. package/bin/utils/projectsToText.js.map +0 -1
  100. package/bin/utils/promptForProject.js +0 -96
  101. package/bin/utils/promptForProject.js.map +0 -1
  102. package/bin/utils/quit.js +0 -73
  103. package/bin/utils/quit.js.map +0 -1
  104. package/bin/utils/sourcesToText.js +0 -57
  105. package/bin/utils/sourcesToText.js.map +0 -1
  106. package/etsc.config.js +0 -13
  107. package/jest.config.ts +0 -16
  108. package/jsconfig.json +0 -5
  109. package/lib/__mocks__/api.ts +0 -12
  110. package/lib/add-project.ts +0 -48
  111. package/lib/api.ts +0 -16
  112. package/lib/component-folders.ts +0 -9
  113. package/lib/config.test.ts +0 -79
  114. package/lib/config.ts +0 -279
  115. package/lib/consts.ts +0 -22
  116. package/lib/ditto.ts +0 -285
  117. package/lib/generate-suggestions.test.ts +0 -169
  118. package/lib/generate-suggestions.ts +0 -166
  119. package/lib/http/__mocks__/fetchComponentFolders.ts +0 -23
  120. package/lib/http/__mocks__/fetchComponents.ts +0 -24
  121. package/lib/http/__mocks__/fetchVariants.ts +0 -21
  122. package/lib/http/fetchComponentFolders.ts +0 -23
  123. package/lib/http/fetchComponents.ts +0 -43
  124. package/lib/http/fetchVariants.ts +0 -42
  125. package/lib/http/http.test.ts +0 -122
  126. package/lib/http/importComponents.ts +0 -79
  127. package/lib/importComponents.ts +0 -24
  128. package/lib/init/init.ts +0 -79
  129. package/lib/init/project.test.ts +0 -26
  130. package/lib/init/project.ts +0 -136
  131. package/lib/init/token.test.ts +0 -99
  132. package/lib/init/token.ts +0 -156
  133. package/lib/output.ts +0 -21
  134. package/lib/pull-lib.test.ts +0 -367
  135. package/lib/pull.test.ts +0 -117
  136. package/lib/pull.ts +0 -629
  137. package/lib/remove-project.ts +0 -44
  138. package/lib/replace.test.ts +0 -157
  139. package/lib/replace.ts +0 -140
  140. package/lib/types.ts +0 -83
  141. package/lib/utils/cleanFileName.test.ts +0 -11
  142. package/lib/utils/cleanFileName.ts +0 -8
  143. package/lib/utils/createSentryContext.ts +0 -20
  144. package/lib/utils/determineModuleType.test.ts +0 -48
  145. package/lib/utils/determineModuleType.ts +0 -55
  146. package/lib/utils/generateIOSBundles.ts +0 -122
  147. package/lib/utils/generateJsDriver.ts +0 -207
  148. package/lib/utils/generateJsDriverTypeFile.ts +0 -75
  149. package/lib/utils/generateSwiftDriver.ts +0 -48
  150. package/lib/utils/getSelectedProjects.ts +0 -36
  151. package/lib/utils/processMetaOption.test.ts +0 -18
  152. package/lib/utils/processMetaOption.ts +0 -16
  153. package/lib/utils/projectsToText.ts +0 -29
  154. package/lib/utils/promptForProject.ts +0 -61
  155. package/lib/utils/quit.ts +0 -7
  156. package/lib/utils/sourcesToText.ts +0 -25
  157. package/pull_request_template.md +0 -20
  158. package/testfiles/en.json +0 -5
  159. package/testfiles/es.json +0 -5
  160. package/testfiles/fr.json +0 -5
  161. package/testfiles/test1.jsx +0 -18
  162. package/testfiles/test2.jsx +0 -9
  163. package/testing/.gitkeep +0 -0
  164. package/testing/fixtures/bad-yaml.yml +0 -6
  165. package/testing/fixtures/ditto-config-no-token +0 -2
  166. package/testing/fixtures/project-config-empty-projects.yml +0 -1
  167. package/testing/fixtures/project-config-no-id.yml +0 -2
  168. package/testing/fixtures/project-config-no-name.yml +0 -2
  169. package/testing/fixtures/project-config-pull.yml +0 -0
  170. package/testing/fixtures/project-config-working.yml +0 -3
  171. package/tsconfig.json +0 -16
package/bin/pull.test.js DELETED
@@ -1,151 +0,0 @@
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]="4ca59558-b2d6-536a-a5a5-bd049d48303f")}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 __copyProps = (to, from, except, desc) => {
25
- if (from && typeof from === "object" || typeof from === "function") {
26
- for (let key of __getOwnPropNames(from))
27
- if (!__hasOwnProp.call(to, key) && key !== except)
28
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29
- }
30
- return to;
31
- };
32
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
33
- // If the importer is in node compatibility mode or this is not an ESM
34
- // file that has been converted to a CommonJS file using a Babel-
35
- // compatible transform (i.e. "__esModule" has not been set), then set
36
- // "default" to the CommonJS "module.exports" for node compatibility.
37
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38
- mod
39
- ));
40
- var __async = (__this, __arguments, generator) => {
41
- return new Promise((resolve, reject) => {
42
- var fulfilled = (value) => {
43
- try {
44
- step(generator.next(value));
45
- } catch (e) {
46
- reject(e);
47
- }
48
- };
49
- var rejected = (value) => {
50
- try {
51
- step(generator.throw(value));
52
- } catch (e) {
53
- reject(e);
54
- }
55
- };
56
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
57
- step((generator = generator.apply(__this, __arguments)).next());
58
- });
59
- };
60
- var import_pull = require("./pull");
61
- var import_memfs = require("memfs");
62
- var import_consts = __toESM(require("./consts"));
63
- var import_globals = require("@jest/globals");
64
- var import_axios = __toESM(require("axios"));
65
- var import_fs = __toESM(require("fs"));
66
- const axiosMock = import_globals.jest.mocked(import_axios.default);
67
- import_globals.jest.mock("fs");
68
- import_globals.jest.mock("./api");
69
- import_globals.jest.mock("./http/fetchComponentFolders");
70
- import_globals.jest.mock("./http/fetchComponents");
71
- import_globals.jest.mock("./http/fetchVariants");
72
- const defaultEnv = __spreadValues({}, process.env);
73
- beforeEach(() => {
74
- import_memfs.vol.reset();
75
- process.env = __spreadValues({}, defaultEnv);
76
- });
77
- const mockGlobalConfigFile = `
78
- api.dittowords.com:
79
- - token: xxx-xxx-xxx
80
- `;
81
- const mockProjectConfigFile = `
82
- sources:
83
- components: true
84
- projects:
85
- - id: project-id-1
86
- name: Test Project
87
- variants: true
88
- `;
89
- describe("pull", () => {
90
- it("correctly writes files to disk per source for basic config", () => __async(exports, null, function* () {
91
- process.env.DITTO_TEXT_DIR = "/ditto";
92
- process.env.DITTO_PROJECT_CONFIG_FILE = "/ditto/config.yml";
93
- axiosMock.get.mockImplementation(
94
- () => Promise.resolve({ data: "data" })
95
- );
96
- import_memfs.vol.fromJSON({
97
- [import_consts.default.CONFIG_FILE]: mockGlobalConfigFile,
98
- [import_consts.default.PROJECT_CONFIG_FILE]: mockProjectConfigFile
99
- });
100
- yield (0, import_pull.pull)();
101
- const filesOnDiskExpected = /* @__PURE__ */ new Set([
102
- "components__example-folder__base.json",
103
- "components__example-folder__example-variant-1.json",
104
- "components__example-folder__example-variant-2.json",
105
- "components__root__base.json",
106
- "components__root__example-variant-1.json",
107
- "components__root__example-variant-2.json",
108
- "test-project__base.json",
109
- "test-project__example-variant-1.json",
110
- "test-project__example-variant-2.json",
111
- "index.d.ts",
112
- "index.js"
113
- ]);
114
- const filesOnDisk = import_fs.default.readdirSync("/ditto");
115
- filesOnDisk.forEach((file) => {
116
- filesOnDiskExpected.delete(file);
117
- });
118
- expect(filesOnDiskExpected.size).toBe(0);
119
- }));
120
- it("correctly does not write index.js or index.d.ts when `disableJsDriver: true` is specified", () => __async(exports, null, function* () {
121
- process.env.DITTO_TEXT_DIR = "/ditto";
122
- process.env.DITTO_PROJECT_CONFIG_FILE = "/ditto/config.yml";
123
- axiosMock.get.mockImplementation(
124
- () => Promise.resolve({ data: "data" })
125
- );
126
- import_memfs.vol.fromJSON({
127
- [import_consts.default.CONFIG_FILE]: mockGlobalConfigFile,
128
- [import_consts.default.PROJECT_CONFIG_FILE]: mockProjectConfigFile + "\ndisableJsDriver: true"
129
- });
130
- yield (0, import_pull.pull)();
131
- const filesOnDiskExpected = /* @__PURE__ */ new Set([
132
- "components__example-folder__base.json",
133
- "components__example-folder__example-variant-1.json",
134
- "components__example-folder__example-variant-2.json",
135
- "components__root__base.json",
136
- "components__root__example-variant-1.json",
137
- "components__root__example-variant-2.json",
138
- "test-project__base.json",
139
- "test-project__example-variant-1.json",
140
- "test-project__example-variant-2.json"
141
- ]);
142
- const filesOnDisk = import_fs.default.readdirSync("/ditto");
143
- filesOnDisk.forEach((file) => {
144
- filesOnDiskExpected.delete(file);
145
- });
146
- expect(filesOnDiskExpected.size).toBe(0);
147
- }));
148
- });
149
- //# sourceMappingURL=pull.test.js.map
150
-
151
- //# debugId=4ca59558-b2d6-536a-a5a5-bd049d48303f
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../lib/pull.test.ts"],"sourcesContent":["import { pull } from \"./pull\";\nimport { vol } from \"memfs\";\nimport consts from \"./consts\";\nimport { jest } from \"@jest/globals\";\nimport axios from \"axios\";\nconst axiosMock = jest.mocked(axios);\nimport fs from \"fs\";\n\njest.mock(\"fs\");\njest.mock(\"./api\");\n\njest.mock(\"./http/fetchComponentFolders\");\njest.mock(\"./http/fetchComponents\");\njest.mock(\"./http/fetchVariants\");\n\nconst defaultEnv = { ...process.env };\n\nbeforeEach(() => {\n vol.reset();\n process.env = { ...defaultEnv };\n});\n\nconst mockGlobalConfigFile = `\napi.dittowords.com:\n - token: xxx-xxx-xxx\n`;\nconst mockProjectConfigFile = `\nsources:\n components: true\n projects:\n - id: project-id-1\n name: Test Project\nvariants: true\n`;\n\ndescribe(\"pull\", () => {\n it(\"correctly writes files to disk per source for basic config\", async () => {\n process.env.DITTO_TEXT_DIR = \"/ditto\";\n process.env.DITTO_PROJECT_CONFIG_FILE = \"/ditto/config.yml\";\n\n // we need to manually mock responses for the http calls that happen\n // directly within the pull function; we don't need to mock the http\n // calls that happen by way of http/* function calls since those have\n // their own mocks already.\n axiosMock.get.mockImplementation(\n (): Promise<any> => Promise.resolve({ data: \"data\" })\n );\n\n vol.fromJSON({\n [consts.CONFIG_FILE]: mockGlobalConfigFile,\n [consts.PROJECT_CONFIG_FILE]: mockProjectConfigFile,\n });\n\n await pull();\n\n const filesOnDiskExpected = new Set([\n \"components__example-folder__base.json\",\n \"components__example-folder__example-variant-1.json\",\n \"components__example-folder__example-variant-2.json\",\n \"components__root__base.json\",\n \"components__root__example-variant-1.json\",\n \"components__root__example-variant-2.json\",\n \"test-project__base.json\",\n \"test-project__example-variant-1.json\",\n \"test-project__example-variant-2.json\",\n \"index.d.ts\",\n \"index.js\",\n ]);\n\n const filesOnDisk = fs.readdirSync(\"/ditto\");\n filesOnDisk.forEach((file) => {\n filesOnDiskExpected.delete(file);\n });\n\n expect(filesOnDiskExpected.size).toBe(0);\n });\n\n it(\"correctly does not write index.js or index.d.ts when `disableJsDriver: true` is specified\", async () => {\n process.env.DITTO_TEXT_DIR = \"/ditto\";\n process.env.DITTO_PROJECT_CONFIG_FILE = \"/ditto/config.yml\";\n\n // we need to manually mock responses for the http calls that happen\n // directly within the pull function; we don't need to mock the http\n // calls that happen by way of http/* function calls since those have\n // their own mocks already.\n axiosMock.get.mockImplementation(\n (): Promise<any> => Promise.resolve({ data: \"data\" })\n );\n\n vol.fromJSON({\n [consts.CONFIG_FILE]: mockGlobalConfigFile,\n [consts.PROJECT_CONFIG_FILE]:\n mockProjectConfigFile + \"\\n\" + \"disableJsDriver: true\",\n });\n\n await pull();\n\n const filesOnDiskExpected = new Set([\n \"components__example-folder__base.json\",\n \"components__example-folder__example-variant-1.json\",\n \"components__example-folder__example-variant-2.json\",\n \"components__root__base.json\",\n \"components__root__example-variant-1.json\",\n \"components__root__example-variant-2.json\",\n \"test-project__base.json\",\n \"test-project__example-variant-1.json\",\n \"test-project__example-variant-2.json\",\n ]);\n\n const filesOnDisk = fs.readdirSync(\"/ditto\");\n filesOnDisk.forEach((file) => {\n filesOnDiskExpected.delete(file);\n });\n\n expect(filesOnDiskExpected.size).toBe(0);\n });\n});\n"],"names":["axios","consts","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kBAAqB;AACrB,mBAAoB;AACpB,oBAAmB;AACnB,qBAAqB;AACrB,mBAAkB;AAElB,gBAAe;AADf,MAAM,YAAY,oBAAK,OAAO,aAAAA,OAAK;AAGnC,oBAAK,KAAK,IAAI;AACd,oBAAK,KAAK,OAAO;AAEjB,oBAAK,KAAK,8BAA8B;AACxC,oBAAK,KAAK,wBAAwB;AAClC,oBAAK,KAAK,sBAAsB;AAEhC,MAAM,aAAa,mBAAK,QAAQ;AAEhC,WAAW,MAAM;AACf,mBAAI,MAAM;AACV,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A;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,UAAM,cAAc,UAAAC,QAAG,YAAY,QAAQ;AAC3C,gBAAY,QAAQ,CAAC,SAAS;AAC5B,0BAAoB,OAAO,IAAI;AAAA,IACjC,CAAC;AAED,WAAO,oBAAoB,IAAI,EAAE,KAAK,CAAC;AAAA,EACzC,EAAC;AACH,CAAC","debug_id":"4ca59558-b2d6-536a-a5a5-bd049d48303f"}
@@ -1,99 +0,0 @@
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]="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 });
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)();
65
- if (!projects.length && !isUsingComponents) {
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;
73
- }
74
- const projectToRemove = yield (0, import_promptForProject.default)({
75
- projects,
76
- message: "Select a project to remove"
77
- });
78
- if (!projectToRemove)
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)
83
- });
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
- });
95
- }
96
- var remove_project_default = removeProject;
97
- //# sourceMappingURL=remove-project.js.map
98
-
99
- //# debugId=02db58e2-181b-532d-8678-792f107e5740
@@ -1 +0,0 @@
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 DELETED
@@ -1,171 +0,0 @@
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]="76d5bf23-fec4-53e2-9669-a83a306dc53e")}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;
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 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 = __toESM(require("fs"));
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 new Promise(
66
- (resolve, reject) => import_fs.default.readFile(filePath, "utf-8", (err, data) => {
67
- if (err) {
68
- reject(err);
69
- } else {
70
- resolve(data);
71
- }
72
- })
73
- );
74
- const ast = (0, import_parser.parse)(code, {
75
- sourceType: "module",
76
- plugins: ["jsx", "typescript"]
77
- });
78
- (0, import_traverse.default)(ast, {
79
- JSXText(path) {
80
- const { searchString, replaceWith } = replacement;
81
- const searchStringEscaped = searchString.replace(
82
- /[.*+?^${}()|[\]\\]/g,
83
- "\\$&"
84
- );
85
- const regex = new RegExp(searchStringEscaped, "gi");
86
- if (regex.test(path.node.value)) {
87
- if (flags.lineNumbers && path.node.loc && !flags.lineNumbers.includes(path.node.loc.start.line)) {
88
- return;
89
- }
90
- const splitValues = splitByCaseInsensitive(
91
- path.node.value,
92
- searchStringEscaped
93
- );
94
- const nodes = [];
95
- splitValues.forEach((splitValue) => {
96
- if (splitValue.toLowerCase() === searchString.toLowerCase()) {
97
- const identifier = t.jsxIdentifier("DittoComponent");
98
- const componentId = t.jsxAttribute(
99
- t.jsxIdentifier("componentId"),
100
- t.stringLiteral(replaceWith)
101
- );
102
- const o = t.jsxOpeningElement(identifier, [componentId], true);
103
- const jsxElement = t.jsxElement(o, void 0, [], true);
104
- nodes.push(jsxElement);
105
- } else {
106
- nodes.push(t.jsxText(splitValue));
107
- }
108
- });
109
- path.replaceWithMultiple(nodes);
110
- }
111
- }
112
- });
113
- const { code: transformedCode } = (0, import_core.transformFromAst)(ast, code, {
114
- // Don't let this codebase's Babel config affect the code we're transforming.
115
- /* @ts-ignore */
116
- configFile: false
117
- });
118
- yield new Promise(
119
- (resolve, reject) => import_fs.default.writeFile(filePath, transformedCode, (err) => {
120
- if (err) {
121
- reject(err);
122
- } else {
123
- resolve(null);
124
- }
125
- })
126
- );
127
- });
128
- }
129
- function splitByCaseInsensitive(str, delimiter) {
130
- return str.split(new RegExp(`(${delimiter})`, "gi")).filter((s) => s !== "");
131
- }
132
- function replace(options, flags) {
133
- let filePath;
134
- let searchString;
135
- let replaceWith;
136
- try {
137
- const parsedOptions = parseOptions(options);
138
- filePath = parsedOptions.filePath;
139
- searchString = parsedOptions.searchString;
140
- replaceWith = parsedOptions.replaceWith;
141
- } catch (e) {
142
- console.error(e);
143
- console.error(
144
- "Usage for replace: ditto-cli replace <file path> <search string> <replace with>"
145
- );
146
- return;
147
- }
148
- replaceJSXTextInFile(filePath, { searchString, replaceWith }, flags);
149
- }
150
- function parseOptions(options) {
151
- if (options.length !== 3) {
152
- throw new Error(
153
- "The options array must contain <file path> <search string> <replace with>."
154
- );
155
- }
156
- const filePath = options[0];
157
- const isFilePathValid = import_fs.default.existsSync(filePath) && import_fs.default.lstatSync(filePath).isFile();
158
- if (!isFilePathValid) {
159
- throw new Error(`${filePath} is not a valid file path.`);
160
- }
161
- return { filePath, searchString: options[1], replaceWith: options[2] };
162
- }
163
- // Annotate the CommonJS export names for ESM import in node:
164
- 0 && (module.exports = {
165
- parseOptions,
166
- replace,
167
- replaceJSXTextInFile
168
- });
169
- //# sourceMappingURL=replace.js.map
170
-
171
- //# debugId=76d5bf23-fec4-53e2-9669-a83a306dc53e
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../lib/replace.ts"],"sourcesContent":["import fs from \"fs\";\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 new Promise<string>((resolve, reject) =>\n fs.readFile(filePath, \"utf-8\", (err, data) => {\n if (err) {\n reject(err);\n } else {\n resolve(data);\n }\n })\n );\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 /* @ts-ignore */\n configFile: false,\n });\n\n await new Promise((resolve, reject) =>\n fs.writeFile(filePath, transformedCode, (err) => {\n if (err) {\n reject(err);\n } else {\n resolve(null);\n }\n })\n );\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, par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AAA,EACF;AAEA,QAAM,WAAW,QAAQ,CAAC;AAE1B,QAAM,kBACJ,UAAAA,QAAG,WAAW,QAAQ,KAAK,UAAAA,QAAG,UAAU,QAAQ,EAAE,OAAO;AAE3D,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI,MAAM,GAAG,QAAQ,4BAA4B;AAAA,EACzD;AAEA,SAAO,EAAE,UAAU,cAAc,QAAQ,CAAC,GAAG,aAAa,QAAQ,CAAC,EAAE;AACvE","debug_id":"76d5bf23-fec4-53e2-9669-a83a306dc53e"}
@@ -1,197 +0,0 @@
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]="8d2eb72b-d2d6-5847-b480-cd39f4da1f7e")}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_fs = __toESM(require("fs"));
47
- var import_replace = require("./replace");
48
- jest.mock("fs");
49
- function createTempJSXFile(content) {
50
- return __async(this, null, function* () {
51
- const tempFile = "/tempFile.jsx";
52
- yield new Promise((resolve, reject) => {
53
- try {
54
- import_fs.default.writeFile(tempFile, content, resolve);
55
- } catch (e) {
56
- reject(e);
57
- }
58
- });
59
- return tempFile;
60
- });
61
- }
62
- function deleteTempFile(filePath) {
63
- return __async(this, null, function* () {
64
- yield new Promise((resolve, reject) => {
65
- try {
66
- import_fs.default.unlink(filePath, resolve);
67
- } catch (e) {
68
- reject(e);
69
- }
70
- });
71
- });
72
- }
73
- describe("parseOptions", () => {
74
- test("should pass with valid input", () => __async(exports, null, function* () {
75
- const tempFile = yield createTempJSXFile("<div>Hello, world!</div>");
76
- expect(
77
- () => (0, import_replace.parseOptions)([tempFile, "secondString", "thirdString"])
78
- ).not.toThrow();
79
- const result = (0, import_replace.parseOptions)([tempFile, "secondString", "thirdString"]);
80
- expect(result).toEqual({
81
- filePath: tempFile,
82
- searchString: "secondString",
83
- replaceWith: "thirdString"
84
- });
85
- deleteTempFile(tempFile);
86
- }));
87
- test("should throw error when options array does not have exactly three strings", () => {
88
- expect(() => (0, import_replace.parseOptions)(["oneString"])).toThrow(
89
- "The options array must contain <file path> <search string> <replace with>."
90
- );
91
- expect(() => (0, import_replace.parseOptions)(["one", "two"])).toThrow(
92
- "The options array must contain <file path> <search string> <replace with>."
93
- );
94
- expect(() => (0, import_replace.parseOptions)(["one", "two", "three", "four"])).toThrow(
95
- "The options array must contain <file path> <search string> <replace with>."
96
- );
97
- });
98
- test("should throw error when the first string is not a valid file path", () => {
99
- const invalidFilePath = "/path/to/invalid/file.txt";
100
- expect(
101
- () => (0, import_replace.parseOptions)([invalidFilePath, "secondString", "thirdString"])
102
- ).toThrow(`${invalidFilePath} is not a valid file path.`);
103
- });
104
- test("should throw error when the first string is a directory", () => {
105
- const directoryPath = ".";
106
- expect(
107
- () => (0, import_replace.parseOptions)([directoryPath, "secondString", "thirdString"])
108
- ).toThrow(`${directoryPath} is not a valid file path.`);
109
- });
110
- });
111
- describe("replaceJSXTextInFile", () => {
112
- afterEach(() => __async(exports, null, function* () {
113
- yield deleteTempFile("/tempFile.jsx");
114
- }));
115
- test("should replace JSX text with a DittoComponent", () => __async(exports, null, function* () {
116
- const tempFile = yield createTempJSXFile("<div>Hello, world</div>");
117
- const searchString = "world";
118
- const replaceWith = "some-id";
119
- yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
120
- const transformedCode = yield new Promise((resolve, reject) => {
121
- import_fs.default.readFile(tempFile, "utf-8", (error, data) => {
122
- if (error) {
123
- reject(error);
124
- } else {
125
- resolve(data);
126
- }
127
- });
128
- });
129
- expect(transformedCode).toContain(
130
- `<div>Hello, <DittoComponent componentId="${replaceWith}" /></div>`
131
- );
132
- }));
133
- test("should replace JSX text with a DittoComponent with a flag", () => __async(exports, null, function* () {
134
- const tempFile = yield createTempJSXFile(
135
- `<>
136
- <div>Hello, world</div>
137
- <div>Hello, world</div>
138
- </>`
139
- );
140
- const searchString = "world";
141
- const replaceWith = "some-id";
142
- yield (0, import_replace.replaceJSXTextInFile)(
143
- tempFile,
144
- { searchString, replaceWith },
145
- { lineNumbers: [3] }
146
- );
147
- const transformedCode = yield new Promise(
148
- (resolve, reject) => import_fs.default.readFile(tempFile, "utf-8", (error, data) => {
149
- if (error)
150
- reject(error);
151
- else
152
- resolve(data);
153
- })
154
- );
155
- expect(transformedCode).toContain(
156
- `<>
157
- <div>Hello, world</div>
158
- <div>Hello, <DittoComponent componentId="some-id" /></div>
159
- </>;`
160
- );
161
- }));
162
- test("should handle case-insensitive search", () => __async(exports, null, function* () {
163
- const tempFile = yield createTempJSXFile("<div>HeLLo, WoRlD</div>");
164
- const searchString = "world";
165
- const replaceWith = "some-id";
166
- yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
167
- const transformedCode = yield new Promise(
168
- (resolve, reject) => import_fs.default.readFile(tempFile, "utf-8", (error, data) => {
169
- if (error)
170
- reject(error);
171
- else
172
- resolve(data);
173
- })
174
- );
175
- expect(transformedCode).toContain(
176
- `<div>HeLLo, <DittoComponent componentId="${replaceWith}" /></div>`
177
- );
178
- }));
179
- test("should not replace JSX text if searchString is not found", () => __async(exports, null, function* () {
180
- const tempFile = yield createTempJSXFile("<div>Hello, world!</div>");
181
- const searchString = "foobar";
182
- const replaceWith = "some-id";
183
- yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
184
- const transformedCode = yield new Promise(
185
- (resolve, reject) => import_fs.default.readFile(tempFile, "utf-8", (error, data) => {
186
- if (error)
187
- reject(error);
188
- else
189
- resolve(data);
190
- })
191
- );
192
- expect(transformedCode).toContain("<div>Hello, world!</div>");
193
- }));
194
- });
195
- //# sourceMappingURL=replace.test.js.map
196
-
197
- //# debugId=8d2eb72b-d2d6-5847-b480-cd39f4da1f7e