@platforma-sdk/bootstrap 5.2.51 → 5.2.53

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 (176) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/block.cjs +106 -146
  3. package/dist/block.cjs.map +1 -1
  4. package/dist/block.js +100 -125
  5. package/dist/block.js.map +1 -1
  6. package/dist/cmd-opts.cjs +87 -177
  7. package/dist/cmd-opts.cjs.map +1 -1
  8. package/dist/cmd-opts.js +87 -172
  9. package/dist/cmd-opts.js.map +1 -1
  10. package/dist/commands/create-block.cjs +19 -20
  11. package/dist/commands/create-block.cjs.map +1 -1
  12. package/dist/commands/create-block.d.ts +12 -7
  13. package/dist/commands/create-block.js +17 -17
  14. package/dist/commands/create-block.js.map +1 -1
  15. package/dist/commands/reset.cjs +18 -21
  16. package/dist/commands/reset.cjs.map +1 -1
  17. package/dist/commands/reset.d.ts +12 -7
  18. package/dist/commands/reset.js +16 -18
  19. package/dist/commands/reset.js.map +1 -1
  20. package/dist/commands/start/docker/s3.cjs +64 -67
  21. package/dist/commands/start/docker/s3.cjs.map +1 -1
  22. package/dist/commands/start/docker/s3.d.ts +32 -27
  23. package/dist/commands/start/docker/s3.js +61 -64
  24. package/dist/commands/start/docker/s3.js.map +1 -1
  25. package/dist/commands/start/docker.cjs +64 -67
  26. package/dist/commands/start/docker.cjs.map +1 -1
  27. package/dist/commands/start/docker.d.ts +32 -27
  28. package/dist/commands/start/docker.js +61 -64
  29. package/dist/commands/start/docker.js.map +1 -1
  30. package/dist/commands/start/local/s3.cjs +101 -135
  31. package/dist/commands/start/local/s3.cjs.map +1 -1
  32. package/dist/commands/start/local/s3.d.ts +36 -31
  33. package/dist/commands/start/local/s3.js +97 -113
  34. package/dist/commands/start/local/s3.js.map +1 -1
  35. package/dist/commands/start/local.cjs +95 -122
  36. package/dist/commands/start/local.cjs.map +1 -1
  37. package/dist/commands/start/local.d.ts +34 -29
  38. package/dist/commands/start/local.js +91 -100
  39. package/dist/commands/start/local.js.map +1 -1
  40. package/dist/commands/start.cjs +18 -21
  41. package/dist/commands/start.cjs.map +1 -1
  42. package/dist/commands/start.d.ts +12 -7
  43. package/dist/commands/start.js +16 -18
  44. package/dist/commands/start.js.map +1 -1
  45. package/dist/commands/stop.cjs +22 -27
  46. package/dist/commands/stop.cjs.map +1 -1
  47. package/dist/commands/stop.d.ts +12 -7
  48. package/dist/commands/stop.js +20 -24
  49. package/dist/commands/stop.js.map +1 -1
  50. package/dist/commands/svc/create/arg-parser.cjs +102 -172
  51. package/dist/commands/svc/create/arg-parser.cjs.map +1 -1
  52. package/dist/commands/svc/create/arg-parser.js +102 -171
  53. package/dist/commands/svc/create/arg-parser.js.map +1 -1
  54. package/dist/commands/svc/create/docker/s3.cjs +78 -96
  55. package/dist/commands/svc/create/docker/s3.cjs.map +1 -1
  56. package/dist/commands/svc/create/docker/s3.d.ts +35 -30
  57. package/dist/commands/svc/create/docker/s3.js +75 -93
  58. package/dist/commands/svc/create/docker/s3.js.map +1 -1
  59. package/dist/commands/svc/create/docker.cjs +82 -103
  60. package/dist/commands/svc/create/docker.cjs.map +1 -1
  61. package/dist/commands/svc/create/docker.d.ts +35 -30
  62. package/dist/commands/svc/create/docker.js +79 -100
  63. package/dist/commands/svc/create/docker.js.map +1 -1
  64. package/dist/commands/svc/create/local/s3.cjs +107 -139
  65. package/dist/commands/svc/create/local/s3.cjs.map +1 -1
  66. package/dist/commands/svc/create/local/s3.d.ts +39 -34
  67. package/dist/commands/svc/create/local/s3.js +103 -117
  68. package/dist/commands/svc/create/local/s3.js.map +1 -1
  69. package/dist/commands/svc/create/local.cjs +101 -138
  70. package/dist/commands/svc/create/local.cjs.map +1 -1
  71. package/dist/commands/svc/create/local.d.ts +37 -32
  72. package/dist/commands/svc/create/local.js +97 -116
  73. package/dist/commands/svc/create/local.js.map +1 -1
  74. package/dist/commands/svc/delete.cjs +36 -38
  75. package/dist/commands/svc/delete.cjs.map +1 -1
  76. package/dist/commands/svc/delete.d.ts +16 -11
  77. package/dist/commands/svc/delete.js +34 -35
  78. package/dist/commands/svc/delete.js.map +1 -1
  79. package/dist/commands/svc/down.cjs +27 -30
  80. package/dist/commands/svc/down.cjs.map +1 -1
  81. package/dist/commands/svc/down.d.ts +15 -10
  82. package/dist/commands/svc/down.js +25 -27
  83. package/dist/commands/svc/down.js.map +1 -1
  84. package/dist/commands/svc/list.cjs +25 -29
  85. package/dist/commands/svc/list.cjs.map +1 -1
  86. package/dist/commands/svc/list.d.ts +9 -5
  87. package/dist/commands/svc/list.js +23 -26
  88. package/dist/commands/svc/list.js.map +1 -1
  89. package/dist/commands/svc/up.cjs +33 -49
  90. package/dist/commands/svc/up.cjs.map +1 -1
  91. package/dist/commands/svc/up.d.ts +15 -10
  92. package/dist/commands/svc/up.js +31 -46
  93. package/dist/commands/svc/up.js.map +1 -1
  94. package/dist/core.cjs +712 -881
  95. package/dist/core.cjs.map +1 -1
  96. package/dist/core.js +709 -877
  97. package/dist/core.js.map +1 -1
  98. package/dist/index.cjs +36 -36
  99. package/dist/index.cjs.map +1 -1
  100. package/dist/index.d.ts +37 -33
  101. package/dist/index.js +35 -34
  102. package/dist/index.js.map +1 -1
  103. package/dist/package.cjs +15 -36
  104. package/dist/package.cjs.map +1 -1
  105. package/dist/package.js +14 -14
  106. package/dist/package.js.map +1 -1
  107. package/dist/platforma.cjs +119 -148
  108. package/dist/platforma.cjs.map +1 -1
  109. package/dist/platforma.js +114 -122
  110. package/dist/platforma.js.map +1 -1
  111. package/dist/run.cjs +55 -58
  112. package/dist/run.cjs.map +1 -1
  113. package/dist/run.js +56 -56
  114. package/dist/run.js.map +1 -1
  115. package/dist/state.cjs +114 -141
  116. package/dist/state.cjs.map +1 -1
  117. package/dist/state.js +110 -139
  118. package/dist/state.js.map +1 -1
  119. package/dist/templates/compose.cjs +38 -65
  120. package/dist/templates/compose.cjs.map +1 -1
  121. package/dist/templates/compose.js +35 -63
  122. package/dist/templates/compose.js.map +1 -1
  123. package/dist/templates/pl-config.cjs +163 -165
  124. package/dist/templates/pl-config.cjs.map +1 -1
  125. package/dist/templates/pl-config.js +161 -163
  126. package/dist/templates/pl-config.js.map +1 -1
  127. package/dist/templates/types.cjs +24 -23
  128. package/dist/templates/types.cjs.map +1 -1
  129. package/dist/templates/types.js +24 -22
  130. package/dist/templates/types.js.map +1 -1
  131. package/dist/util.cjs +57 -74
  132. package/dist/util.cjs.map +1 -1
  133. package/dist/util.js +51 -72
  134. package/dist/util.js.map +1 -1
  135. package/package.json +7 -7
  136. package/dist/block.d.ts +0 -25
  137. package/dist/block.d.ts.map +0 -1
  138. package/dist/cmd-opts.d.ts +0 -89
  139. package/dist/cmd-opts.d.ts.map +0 -1
  140. package/dist/commands/create-block.d.ts.map +0 -1
  141. package/dist/commands/reset.d.ts.map +0 -1
  142. package/dist/commands/start/docker/s3.d.ts.map +0 -1
  143. package/dist/commands/start/docker.d.ts.map +0 -1
  144. package/dist/commands/start/local/s3.d.ts.map +0 -1
  145. package/dist/commands/start/local.d.ts.map +0 -1
  146. package/dist/commands/start.d.ts.map +0 -1
  147. package/dist/commands/stop.d.ts.map +0 -1
  148. package/dist/commands/svc/create/arg-parser.d.ts +0 -43
  149. package/dist/commands/svc/create/arg-parser.d.ts.map +0 -1
  150. package/dist/commands/svc/create/docker/s3.d.ts.map +0 -1
  151. package/dist/commands/svc/create/docker.d.ts.map +0 -1
  152. package/dist/commands/svc/create/local/s3.d.ts.map +0 -1
  153. package/dist/commands/svc/create/local.d.ts.map +0 -1
  154. package/dist/commands/svc/delete.d.ts.map +0 -1
  155. package/dist/commands/svc/down.d.ts.map +0 -1
  156. package/dist/commands/svc/list.d.ts.map +0 -1
  157. package/dist/commands/svc/up.d.ts.map +0 -1
  158. package/dist/core.d.ts +0 -105
  159. package/dist/core.d.ts.map +0 -1
  160. package/dist/index.d.ts.map +0 -1
  161. package/dist/package.d.ts +0 -7
  162. package/dist/package.d.ts.map +0 -1
  163. package/dist/platforma.d.ts +0 -24
  164. package/dist/platforma.d.ts.map +0 -1
  165. package/dist/run.d.ts +0 -13
  166. package/dist/run.d.ts.map +0 -1
  167. package/dist/state.d.ts +0 -63
  168. package/dist/state.d.ts.map +0 -1
  169. package/dist/templates/compose.d.ts +0 -14
  170. package/dist/templates/compose.d.ts.map +0 -1
  171. package/dist/templates/pl-config.d.ts +0 -6
  172. package/dist/templates/pl-config.d.ts.map +0 -1
  173. package/dist/templates/types.d.ts +0 -138
  174. package/dist/templates/types.d.ts.map +0 -1
  175. package/dist/util.d.ts +0 -18
  176. package/dist/util.d.ts.map +0 -1
@@ -0,0 +1,29 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
package/dist/block.cjs CHANGED
@@ -1,177 +1,137 @@
1
- 'use strict';
2
-
3
- var fs$1 = require('node:fs');
4
- var fs = require('node:fs/promises');
5
- var path = require('node:path');
6
- var node_stream = require('node:stream');
7
- var os = require('node:os');
8
- var readlineSync = require('readline-sync');
9
- var zod = require('zod');
10
- var decompress = require('decompress');
11
-
12
- function _interopNamespaceDefault(e) {
13
- var n = Object.create(null);
14
- if (e) {
15
- Object.keys(e).forEach(function (k) {
16
- if (k !== 'default') {
17
- var d = Object.getOwnPropertyDescriptor(e, k);
18
- Object.defineProperty(n, k, d.get ? d : {
19
- enumerable: true,
20
- get: function () { return e[k]; }
21
- });
22
- }
23
- });
24
- }
25
- n.default = e;
26
- return Object.freeze(n);
27
- }
28
-
29
- var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ let node_os = require("node:os");
3
+ node_os = require_runtime.__toESM(node_os);
4
+ let node_fs = require("node:fs");
5
+ let node_path = require("node:path");
6
+ node_path = require_runtime.__toESM(node_path);
7
+ let readline_sync = require("readline-sync");
8
+ readline_sync = require_runtime.__toESM(readline_sync);
9
+ let node_fs_promises = require("node:fs/promises");
10
+ node_fs_promises = require_runtime.__toESM(node_fs_promises);
11
+ let node_stream = require("node:stream");
12
+ let zod = require("zod");
13
+ let decompress = require("decompress");
14
+ decompress = require_runtime.__toESM(decompress);
30
15
 
16
+ //#region src/block.ts
31
17
  const blockPlatformsToChoose = ["Python"];
32
18
  const allPlatforms = ["Tengo", "Python"];
33
19
  const CreateBlockPlatforms = zod.z.union([zod.z.literal("Tengo"), zod.z.literal("Python")]);
34
20
  const CreateBlockOptions = zod.z.object({
35
- npmOrgName: zod.z.string().min(1),
36
- orgName: zod.z.string().min(1, { message: `Organization name must be provided` }),
37
- blockName: zod.z.string().min(1, { message: `Block name must be provided` }),
38
- softwarePlatforms: zod.z.array(CreateBlockPlatforms).refine((p) => new Set(p).size === p.length, {
39
- message: "Must be an array of unique software platforms",
40
- }),
21
+ npmOrgName: zod.z.string().min(1),
22
+ orgName: zod.z.string().min(1, { message: `Organization name must be provided` }),
23
+ blockName: zod.z.string().min(1, { message: `Block name must be provided` }),
24
+ softwarePlatforms: zod.z.array(CreateBlockPlatforms).refine((p) => new Set(p).size === p.length, { message: "Must be an array of unique software platforms" })
41
25
  });
42
26
  /** Creates a block by cloning block-boilerplate repository. */
43
27
  async function createBlock(logger) {
44
- const { npmOrgName, orgName, blockName, softwarePlatforms } = askForOptions();
45
- const targetPath = path.join(process.cwd(), blockName);
46
- logger.info(`Downloading boilerplate code...`);
47
- await downloadAndUnzip(
48
- // 'https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/software_platforms.zip',
49
- // 'platforma-block-boilerplate-software_platforms',
50
- "https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip", "platforma-block-boilerplate-main", targetPath);
51
- const platformsToRemove = allPlatforms.filter((p) => softwarePlatforms.indexOf(p) < 0);
52
- const noPlatforms = blockPlatformsToChoose.length == platformsToRemove.length;
53
- logger.info(`Keep platforms '${softwarePlatforms}', remove: '${platformsToRemove}'. Will remove all platforms? ${noPlatforms}`);
54
- for (const p of platformsToRemove) {
55
- await removePlatform(targetPath, p);
56
- }
57
- if (noPlatforms) {
58
- await removePlatformsCompletely(targetPath);
59
- }
60
- logger.info(`Replace everything in the template with provided options...`);
61
- replaceRegexInAllFiles(targetPath, [
62
- // '@' literal ensures only npm org name will be renamed,
63
- // as public registry for software also is called platforma-open, but without '@'.
64
- // Also, don't rename an organization for runenv-python-3 package.
65
- { from: /@platforma-open(?!.*runenv-python-3)/g, to: `@${npmOrgName}` },
66
- { from: /my-org/g, to: orgName },
67
- { from: /block-boilerplate/g, to: blockName },
68
- ]);
28
+ const { npmOrgName, orgName, blockName, softwarePlatforms } = askForOptions();
29
+ const targetPath = node_path.default.join(process.cwd(), blockName);
30
+ logger.info(`Downloading boilerplate code...`);
31
+ await downloadAndUnzip("https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip", "platforma-block-boilerplate-main", targetPath);
32
+ const platformsToRemove = allPlatforms.filter((p) => softwarePlatforms.indexOf(p) < 0);
33
+ const noPlatforms = blockPlatformsToChoose.length == platformsToRemove.length;
34
+ logger.info(`Keep platforms '${softwarePlatforms}', remove: '${platformsToRemove}'. Will remove all platforms? ${noPlatforms}`);
35
+ for (const p of platformsToRemove) await removePlatform(targetPath, p);
36
+ if (noPlatforms) await removePlatformsCompletely(targetPath);
37
+ logger.info(`Replace everything in the template with provided options...`);
38
+ replaceRegexInAllFiles(targetPath, [
39
+ {
40
+ from: /@platforma-open(?!.*runenv-python-3)/g,
41
+ to: `@${npmOrgName}`
42
+ },
43
+ {
44
+ from: /my-org/g,
45
+ to: orgName
46
+ },
47
+ {
48
+ from: /block-boilerplate/g,
49
+ to: blockName
50
+ }
51
+ ]);
69
52
  }
70
53
  function askForOptions() {
71
- let npmOrgName = readlineSync.question('Write an organization name for npm. Default is "platforma-open": ');
72
- if (npmOrgName === "") {
73
- npmOrgName = "platforma-open";
74
- }
75
- let orgName = "";
76
- while (orgName.length < 1)
77
- orgName = readlineSync.question('Write an organization name, e.g. "my-org": ');
78
- let blockName = "";
79
- while (blockName.length < 1)
80
- blockName = readlineSync.question('Write a name of the block, e.g. "hello-world": ');
81
- const needSoftware = readlineSync.keyInYN("Create package for block's software?");
82
- let softwarePlatforms = ["Tengo"];
83
- if (needSoftware) {
84
- while (softwarePlatforms.length < allPlatforms.length) {
85
- const index = readlineSync.keyInSelect(blockPlatformsToChoose, "Choose software platform:");
86
- if (index < 0)
87
- break;
88
- softwarePlatforms.push(blockPlatformsToChoose[index]);
89
- }
90
- }
91
- softwarePlatforms = Array.from(new Set(softwarePlatforms)).sort();
92
- const result = CreateBlockOptions.safeParse({
93
- npmOrgName,
94
- orgName,
95
- blockName,
96
- softwarePlatforms,
97
- });
98
- if (!result.success && result.error.issues.length) {
99
- throw new Error(result.error.issues.map((i) => i.message).join("; "));
100
- }
101
- return result.data;
54
+ let npmOrgName = readline_sync.default.question("Write an organization name for npm. Default is \"platforma-open\": ");
55
+ if (npmOrgName === "") npmOrgName = "platforma-open";
56
+ let orgName = "";
57
+ while (orgName.length < 1) orgName = readline_sync.default.question("Write an organization name, e.g. \"my-org\": ");
58
+ let blockName = "";
59
+ while (blockName.length < 1) blockName = readline_sync.default.question("Write a name of the block, e.g. \"hello-world\": ");
60
+ const needSoftware = readline_sync.default.keyInYN("Create package for block's software?");
61
+ let softwarePlatforms = ["Tengo"];
62
+ if (needSoftware) while (softwarePlatforms.length < allPlatforms.length) {
63
+ const index = readline_sync.default.keyInSelect(blockPlatformsToChoose, "Choose software platform:");
64
+ if (index < 0) break;
65
+ softwarePlatforms.push(blockPlatformsToChoose[index]);
66
+ }
67
+ softwarePlatforms = Array.from(new Set(softwarePlatforms)).sort();
68
+ const result = CreateBlockOptions.safeParse({
69
+ npmOrgName,
70
+ orgName,
71
+ blockName,
72
+ softwarePlatforms
73
+ });
74
+ if (!result.success && result.error.issues.length) throw new Error(result.error.issues.map((i) => i.message).join("; "));
75
+ return result.data;
102
76
  }
103
77
  async function downloadAndUnzip(url, pathInArchive, outputPath) {
104
- const response = await fetch(url);
105
- const content = await response.blob();
106
- const tmpDir = await fs__namespace.mkdtemp(path.join(os.tmpdir(), "create-repo"));
107
- const tmpFile = path.join(tmpDir, "packed-repo.zip");
108
- const f = node_stream.Writable.toWeb(fs$1.createWriteStream(tmpFile));
109
- await content.stream().pipeTo(f);
110
- const tmpRepo = path.join(tmpDir, "unpacked-repo");
111
- await fs__namespace.mkdir(tmpRepo);
112
- await decompress(tmpFile, tmpRepo);
113
- await fs__namespace.cp(path.join(tmpRepo, pathInArchive), outputPath, { recursive: true });
78
+ const content = await (await fetch(url)).blob();
79
+ const tmpDir = await node_fs_promises.mkdtemp(node_path.default.join(node_os.default.tmpdir(), "create-repo"));
80
+ const tmpFile = node_path.default.join(tmpDir, "packed-repo.zip");
81
+ const f = node_stream.Writable.toWeb((0, node_fs.createWriteStream)(tmpFile));
82
+ await content.stream().pipeTo(f);
83
+ const tmpRepo = node_path.default.join(tmpDir, "unpacked-repo");
84
+ await node_fs_promises.mkdir(tmpRepo);
85
+ await (0, decompress.default)(tmpFile, tmpRepo);
86
+ await node_fs_promises.cp(node_path.default.join(tmpRepo, pathInArchive), outputPath, { recursive: true });
114
87
  }
115
88
  /** Removes a bunch of dependencies to the platform. */
116
89
  async function removePlatform(dir, platform) {
117
- const p = platform.toLowerCase();
118
- // Remove <PlAlert> line from MainPage.vue
119
- // https://regex101.com/r/oCTyHk/1
120
- await deleteRegexInFile(path.join(dir, "ui", "src", "pages", "MainPage.vue"), new RegExp(`.*${p}Message.*\\n`, "g"));
121
- // Remove an output from the model.
122
- await deleteRegexInFile(path.join(dir, "model", "src", "index.ts"), new RegExp(`.*${p}Message.*\\n\\n`, "g"));
123
- // This regexp represents a block of code until the empty line.
124
- // https://regex101.com/r/Os8kX1/1
125
- await deleteRegexInFile(path.join(dir, "workflow", "src", "main.tpl.tengo"), new RegExp(`.*${p}.*exec.builder.*[\\s\\S]*?\\n\\n`, "g"));
126
- // Remove a line from the workflow output.
127
- // https://regex101.com/r/PkHwQ8/1
128
- await deleteRegexInFile(path.join(dir, "workflow", "src", "main.tpl.tengo"), new RegExp(`.*${p}Message.*\\n`, "g"));
129
- // Remove 2 lines: the one with the language message and the one with expect
130
- await deleteRegexInFile(path.join(dir, "workflow", "src", "wf.test.ts"), new RegExp(`.*${p}Message.*\\n.*expect.*\\n\\n`, "g"));
131
- await fs__namespace.rm(path.join(dir, "software", `src_${p}`), { recursive: true });
132
- await replaceInFile(path.join(dir, "software", "package.json"), (content) => {
133
- const json = JSON.parse(content);
134
- delete json["block-software"]["artifacts"][`hello-${p}-artifact`];
135
- delete json["block-software"]["entrypoints"][`hello-world-${p}`];
136
- return JSON.stringify(json, null, 2);
137
- });
90
+ const p = platform.toLowerCase();
91
+ await deleteRegexInFile(node_path.default.join(dir, "ui", "src", "pages", "MainPage.vue"), new RegExp(`.*${p}Message.*\\n`, "g"));
92
+ await deleteRegexInFile(node_path.default.join(dir, "model", "src", "index.ts"), new RegExp(`.*${p}Message.*\\n\\n`, "g"));
93
+ await deleteRegexInFile(node_path.default.join(dir, "workflow", "src", "main.tpl.tengo"), new RegExp(`.*${p}.*exec.builder.*[\\s\\S]*?\\n\\n`, "g"));
94
+ await deleteRegexInFile(node_path.default.join(dir, "workflow", "src", "main.tpl.tengo"), new RegExp(`.*${p}Message.*\\n`, "g"));
95
+ await deleteRegexInFile(node_path.default.join(dir, "workflow", "src", "wf.test.ts"), new RegExp(`.*${p}Message.*\\n.*expect.*\\n\\n`, "g"));
96
+ await node_fs_promises.rm(node_path.default.join(dir, "software", `src_${p}`), { recursive: true });
97
+ await replaceInFile(node_path.default.join(dir, "software", "package.json"), (content) => {
98
+ const json = JSON.parse(content);
99
+ delete json["block-software"]["artifacts"][`hello-${p}-artifact`];
100
+ delete json["block-software"]["entrypoints"][`hello-world-${p}`];
101
+ return JSON.stringify(json, null, 2);
102
+ });
138
103
  }
139
104
  /** Removes software directory completely and all references to it from the workspace. */
140
105
  async function removePlatformsCompletely(dir) {
141
- await fs__namespace.rm(path.join(dir, "software"), { recursive: true });
142
- await replaceInFile(path.join(dir, "workflow", "package.json"), (content) => {
143
- const json = JSON.parse(content);
144
- delete json["dependencies"]["@platforma-open/my-org.block-boilerplate.software"];
145
- return JSON.stringify(json, null, 2);
146
- });
147
- await deleteRegexInFile(path.join(dir, "pnpm-workspace.yaml"), /.*- software$\n/gm);
106
+ await node_fs_promises.rm(node_path.default.join(dir, "software"), { recursive: true });
107
+ await replaceInFile(node_path.default.join(dir, "workflow", "package.json"), (content) => {
108
+ const json = JSON.parse(content);
109
+ delete json["dependencies"]["@platforma-open/my-org.block-boilerplate.software"];
110
+ return JSON.stringify(json, null, 2);
111
+ });
112
+ await deleteRegexInFile(node_path.default.join(dir, "pnpm-workspace.yaml"), /.*- software$\n/gm);
148
113
  }
149
114
  async function replaceRegexInAllFiles(dir, patterns) {
150
- const files = await getAllFiles(dir);
151
- for (const { from, to } of patterns) {
152
- for (const fPath of files) {
153
- await replaceRegexInFile(fPath, from, to);
154
- }
155
- }
115
+ const files = await getAllFiles(dir);
116
+ for (const { from, to } of patterns) for (const fPath of files) await replaceRegexInFile(fPath, from, to);
156
117
  }
157
118
  async function getAllFiles(dir) {
158
- const allDirents = await fs__namespace.readdir(dir, {
159
- withFileTypes: true,
160
- recursive: true,
161
- });
162
- return allDirents.filter((f) => f.isFile()).map((f) => path.join(f.parentPath, f.name));
119
+ return (await node_fs_promises.readdir(dir, {
120
+ withFileTypes: true,
121
+ recursive: true
122
+ })).filter((f) => f.isFile()).map((f) => node_path.default.join(f.parentPath, f.name));
163
123
  }
164
124
  async function replaceInFile(fPath, replacer) {
165
- const content = await fs__namespace.readFile(fPath);
166
- const newContent = replacer(content.toString());
167
- await fs__namespace.writeFile(fPath, newContent);
125
+ const newContent = replacer((await node_fs_promises.readFile(fPath)).toString());
126
+ await node_fs_promises.writeFile(fPath, newContent);
168
127
  }
169
128
  async function replaceRegexInFile(fPath, from, to) {
170
- return await replaceInFile(fPath, (content) => content.replaceAll(from, to));
129
+ return await replaceInFile(fPath, (content) => content.replaceAll(from, to));
171
130
  }
172
131
  async function deleteRegexInFile(fPath, what) {
173
- return await replaceRegexInFile(fPath, what, "");
132
+ return await replaceRegexInFile(fPath, what, "");
174
133
  }
175
134
 
135
+ //#endregion
176
136
  exports.createBlock = createBlock;
177
- //# sourceMappingURL=block.cjs.map
137
+ //# sourceMappingURL=block.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"block.cjs","sources":["../src/block.ts"],"sourcesContent":["import { createWriteStream } from \"node:fs\";\nimport * as fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type winston from \"winston\";\nimport { Writable } from \"node:stream\";\nimport os from \"node:os\";\nimport readlineSync from \"readline-sync\";\nimport { z } from \"zod\";\nimport decompress from \"decompress\";\n\nconst blockPlatformsToChoose = [\"Python\"];\nconst allPlatforms = [\"Tengo\", \"Python\"] as const;\nconst CreateBlockPlatforms = z.union([z.literal(\"Tengo\"), z.literal(\"Python\")]);\nexport type CreateBlockPlatform = z.infer<typeof CreateBlockPlatforms>;\n\nconst CreateBlockOptions = z.object({\n npmOrgName: z.string().min(1),\n orgName: z.string().min(1, { message: `Organization name must be provided` }),\n blockName: z.string().min(1, { message: `Block name must be provided` }),\n softwarePlatforms: z.array(CreateBlockPlatforms).refine((p) => new Set(p).size === p.length, {\n message: \"Must be an array of unique software platforms\",\n }),\n});\nexport type CreateBlockOptions = z.infer<typeof CreateBlockOptions>;\n\n/** Creates a block by cloning block-boilerplate repository. */\nexport async function createBlock(logger: winston.Logger) {\n const { npmOrgName, orgName, blockName, softwarePlatforms } = askForOptions();\n const targetPath = path.join(process.cwd(), blockName);\n\n logger.info(`Downloading boilerplate code...`);\n await downloadAndUnzip(\n // 'https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/software_platforms.zip',\n // 'platforma-block-boilerplate-software_platforms',\n \"https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip\",\n \"platforma-block-boilerplate-main\",\n targetPath,\n );\n\n const platformsToRemove = allPlatforms.filter((p) => softwarePlatforms.indexOf(p) < 0);\n const noPlatforms = blockPlatformsToChoose.length == platformsToRemove.length;\n logger.info(\n `Keep platforms '${softwarePlatforms}', remove: '${platformsToRemove}'. Will remove all platforms? ${noPlatforms}`,\n );\n for (const p of platformsToRemove) {\n await removePlatform(targetPath, p);\n }\n if (noPlatforms) {\n await removePlatformsCompletely(targetPath);\n }\n\n logger.info(`Replace everything in the template with provided options...`);\n replaceRegexInAllFiles(targetPath, [\n // '@' literal ensures only npm org name will be renamed,\n // as public registry for software also is called platforma-open, but without '@'.\n // Also, don't rename an organization for runenv-python-3 package.\n { from: /@platforma-open(?!.*runenv-python-3)/g, to: `@${npmOrgName}` },\n\n { from: /my-org/g, to: orgName },\n\n { from: /block-boilerplate/g, to: blockName },\n ]);\n}\n\nfunction askForOptions(): CreateBlockOptions {\n let npmOrgName = readlineSync.question(\n 'Write an organization name for npm. Default is \"platforma-open\": ',\n );\n if (npmOrgName === \"\") {\n npmOrgName = \"platforma-open\";\n }\n\n let orgName = \"\";\n while (orgName.length < 1)\n orgName = readlineSync.question('Write an organization name, e.g. \"my-org\": ');\n\n let blockName = \"\";\n while (blockName.length < 1)\n blockName = readlineSync.question('Write a name of the block, e.g. \"hello-world\": ');\n\n const needSoftware = readlineSync.keyInYN(\"Create package for block's software?\");\n let softwarePlatforms = [\"Tengo\"];\n if (needSoftware) {\n while (softwarePlatforms.length < allPlatforms.length) {\n const index = readlineSync.keyInSelect(blockPlatformsToChoose, \"Choose software platform:\");\n if (index < 0) break;\n softwarePlatforms.push(blockPlatformsToChoose[index]);\n }\n }\n softwarePlatforms = Array.from(new Set(softwarePlatforms)).sort();\n\n const result = CreateBlockOptions.safeParse({\n npmOrgName,\n orgName,\n blockName,\n softwarePlatforms,\n });\n if (!result.success && result.error.issues.length) {\n throw new Error(result.error.issues.map((i) => i.message).join(\"; \"));\n }\n\n return result.data!;\n}\n\nasync function downloadAndUnzip(url: string, pathInArchive: string, outputPath: string) {\n const response = await fetch(url);\n const content = await response.blob();\n\n const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), \"create-repo\"));\n\n const tmpFile = path.join(tmpDir, \"packed-repo.zip\");\n const f = Writable.toWeb(createWriteStream(tmpFile));\n await content.stream().pipeTo(f);\n\n const tmpRepo = path.join(tmpDir, \"unpacked-repo\");\n await fs.mkdir(tmpRepo);\n await decompress(tmpFile, tmpRepo);\n\n await fs.cp(path.join(tmpRepo, pathInArchive), outputPath, { recursive: true });\n}\n\n/** Removes a bunch of dependencies to the platform. */\nasync function removePlatform(dir: string, platform: CreateBlockPlatform) {\n const p = platform.toLowerCase();\n\n // Remove <PlAlert> line from MainPage.vue\n // https://regex101.com/r/oCTyHk/1\n await deleteRegexInFile(\n path.join(dir, \"ui\", \"src\", \"pages\", \"MainPage.vue\"),\n new RegExp(`.*${p}Message.*\\\\n`, \"g\"),\n );\n\n // Remove an output from the model.\n await deleteRegexInFile(\n path.join(dir, \"model\", \"src\", \"index.ts\"),\n new RegExp(`.*${p}Message.*\\\\n\\\\n`, \"g\"),\n );\n\n // This regexp represents a block of code until the empty line.\n // https://regex101.com/r/Os8kX1/1\n await deleteRegexInFile(\n path.join(dir, \"workflow\", \"src\", \"main.tpl.tengo\"),\n new RegExp(`.*${p}.*exec.builder.*[\\\\s\\\\S]*?\\\\n\\\\n`, \"g\"),\n );\n\n // Remove a line from the workflow output.\n // https://regex101.com/r/PkHwQ8/1\n await deleteRegexInFile(\n path.join(dir, \"workflow\", \"src\", \"main.tpl.tengo\"),\n new RegExp(`.*${p}Message.*\\\\n`, \"g\"),\n );\n\n // Remove 2 lines: the one with the language message and the one with expect\n await deleteRegexInFile(\n path.join(dir, \"workflow\", \"src\", \"wf.test.ts\"),\n new RegExp(`.*${p}Message.*\\\\n.*expect.*\\\\n\\\\n`, \"g\"),\n );\n\n await fs.rm(path.join(dir, \"software\", `src_${p}`), { recursive: true });\n\n await replaceInFile(path.join(dir, \"software\", \"package.json\"), (content) => {\n const json = JSON.parse(content);\n delete json[\"block-software\"][\"artifacts\"][`hello-${p}-artifact`];\n delete json[\"block-software\"][\"entrypoints\"][`hello-world-${p}`];\n return JSON.stringify(json, null, 2);\n });\n}\n\n/** Removes software directory completely and all references to it from the workspace. */\nasync function removePlatformsCompletely(dir: string) {\n await fs.rm(path.join(dir, \"software\"), { recursive: true });\n\n await replaceInFile(path.join(dir, \"workflow\", \"package.json\"), (content) => {\n const json = JSON.parse(content);\n delete json[\"dependencies\"][\"@platforma-open/my-org.block-boilerplate.software\"];\n return JSON.stringify(json, null, 2);\n });\n\n await deleteRegexInFile(path.join(dir, \"pnpm-workspace.yaml\"), /.*- software$\\n/gm);\n}\n\nasync function replaceRegexInAllFiles(dir: string, patterns: { from: RegExp; to: string }[]) {\n const files = await getAllFiles(dir);\n for (const { from, to } of patterns) {\n for (const fPath of files) {\n await replaceRegexInFile(fPath, from, to);\n }\n }\n}\n\nasync function getAllFiles(dir: string): Promise<string[]> {\n const allDirents = await fs.readdir(dir, {\n withFileTypes: true,\n recursive: true,\n });\n\n return allDirents.filter((f: any) => f.isFile()).map((f: any) => path.join(f.parentPath, f.name));\n}\n\nasync function replaceInFile(fPath: string, replacer: (content: string) => any) {\n const content = await fs.readFile(fPath);\n const newContent = replacer(content.toString());\n await fs.writeFile(fPath, newContent);\n}\n\nasync function replaceRegexInFile(fPath: string, from: RegExp, to: string) {\n return await replaceInFile(fPath, (content) => content.replaceAll(from, to));\n}\n\nasync function deleteRegexInFile(fPath: string, what: RegExp) {\n return await replaceRegexInFile(fPath, what, \"\");\n}\n"],"names":["z","fs","Writable","createWriteStream"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,sBAAsB,GAAG,CAAC,QAAQ,CAAC;AACzC,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAU;AACjD,MAAM,oBAAoB,GAAGA,KAAC,CAAC,KAAK,CAAC,CAACA,KAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAEA,KAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAG/E,MAAM,kBAAkB,GAAGA,KAAC,CAAC,MAAM,CAAC;IAClC,UAAU,EAAEA,KAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7B,IAAA,OAAO,EAAEA,KAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,CAAA,kCAAA,CAAoC,EAAE,CAAC;AAC7E,IAAA,SAAS,EAAEA,KAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,CAAA,2BAAA,CAA6B,EAAE,CAAC;IACxE,iBAAiB,EAAEA,KAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI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M,KAAK,IAAI,KAAK,EAAE;YACzB,MAAM,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;QAC3C;IACF;AACF;AAEA,eAAe,WAAW,CAAC,GAAW,EAAA;IACpC,MAAM,UAAU,GAAG,MAAMA,aAAE,CAAC,OAAO,CAAC,GAAG,EAAE;AACvC,QAAA,aAAa,EAAE,IAAI;AACnB,QAAA,SAAS,EAAE,IAAI;AAChB,KAAA,CAAC;AAEF,IAAA,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAM,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AACnG;AAEA,eAAe,aAAa,CAAC,KAAa,EAAE,QAAkC,EAAA;IAC5E,MAAM,OAAO,GAAG,MAAMA,aAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;IACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC/C,MAAMA,aAAE,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC;AACvC;AAEA,eAAe,kBAAkB,CAAC,KAAa,EAAE,IAAY,EAAE,EAAU,EAAA;AACvE,IAAA,OAAO,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,OAAO,KAAK,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC9E;AAEA,eAAe,iBAAiB,CAAC,KAAa,EAAE,IAAY,EAAA;IAC1D,OAAO,MAAM,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;AAClD;;;;"}
1
+ {"version":3,"file":"block.cjs","names":["z","path","readlineSync","fs","os","Writable"],"sources":["../src/block.ts"],"sourcesContent":["import { createWriteStream } from \"node:fs\";\nimport * as fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type winston from \"winston\";\nimport { Writable } from \"node:stream\";\nimport os from \"node:os\";\nimport readlineSync from \"readline-sync\";\nimport { z } from \"zod\";\nimport decompress from \"decompress\";\n\nconst blockPlatformsToChoose = [\"Python\"];\nconst allPlatforms = [\"Tengo\", \"Python\"] as const;\nconst CreateBlockPlatforms = z.union([z.literal(\"Tengo\"), z.literal(\"Python\")]);\nexport type CreateBlockPlatform = z.infer<typeof CreateBlockPlatforms>;\n\nconst CreateBlockOptions = z.object({\n npmOrgName: z.string().min(1),\n orgName: z.string().min(1, { message: `Organization name must be provided` }),\n blockName: z.string().min(1, { message: `Block name must be provided` }),\n softwarePlatforms: z.array(CreateBlockPlatforms).refine((p) => new Set(p).size === p.length, {\n message: \"Must be an array of unique software platforms\",\n }),\n});\nexport type CreateBlockOptions = z.infer<typeof CreateBlockOptions>;\n\n/** Creates a block by cloning block-boilerplate repository. */\nexport async function createBlock(logger: winston.Logger) {\n const { npmOrgName, orgName, blockName, softwarePlatforms } = askForOptions();\n const targetPath = path.join(process.cwd(), blockName);\n\n logger.info(`Downloading boilerplate code...`);\n await downloadAndUnzip(\n // 'https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/software_platforms.zip',\n // 'platforma-block-boilerplate-software_platforms',\n \"https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip\",\n \"platforma-block-boilerplate-main\",\n targetPath,\n );\n\n const platformsToRemove = allPlatforms.filter((p) => softwarePlatforms.indexOf(p) < 0);\n const noPlatforms = blockPlatformsToChoose.length == platformsToRemove.length;\n logger.info(\n `Keep platforms '${softwarePlatforms}', remove: '${platformsToRemove}'. Will remove all platforms? ${noPlatforms}`,\n );\n for (const p of platformsToRemove) {\n await removePlatform(targetPath, p);\n }\n if (noPlatforms) {\n await removePlatformsCompletely(targetPath);\n }\n\n logger.info(`Replace everything in the template with provided options...`);\n replaceRegexInAllFiles(targetPath, [\n // '@' literal ensures only npm org name will be renamed,\n // as public registry for software also is called platforma-open, but without '@'.\n // Also, don't rename an organization for runenv-python-3 package.\n { from: /@platforma-open(?!.*runenv-python-3)/g, to: `@${npmOrgName}` },\n\n { from: /my-org/g, to: orgName },\n\n { from: /block-boilerplate/g, to: blockName },\n ]);\n}\n\nfunction askForOptions(): CreateBlockOptions {\n let npmOrgName = readlineSync.question(\n 'Write an organization name for npm. Default is \"platforma-open\": ',\n );\n if (npmOrgName === \"\") {\n npmOrgName = \"platforma-open\";\n }\n\n let orgName = \"\";\n while (orgName.length < 1)\n orgName = readlineSync.question('Write an organization name, e.g. \"my-org\": ');\n\n let blockName = \"\";\n while (blockName.length < 1)\n blockName = readlineSync.question('Write a name of the block, e.g. \"hello-world\": ');\n\n const needSoftware = readlineSync.keyInYN(\"Create package for block's software?\");\n let softwarePlatforms = [\"Tengo\"];\n if (needSoftware) {\n while (softwarePlatforms.length < allPlatforms.length) {\n const index = readlineSync.keyInSelect(blockPlatformsToChoose, \"Choose software platform:\");\n if (index < 0) break;\n softwarePlatforms.push(blockPlatformsToChoose[index]);\n }\n }\n softwarePlatforms = Array.from(new Set(softwarePlatforms)).sort();\n\n const result = CreateBlockOptions.safeParse({\n npmOrgName,\n orgName,\n blockName,\n softwarePlatforms,\n });\n if (!result.success && result.error.issues.length) {\n throw new Error(result.error.issues.map((i) => i.message).join(\"; \"));\n }\n\n return result.data!;\n}\n\nasync function downloadAndUnzip(url: string, pathInArchive: string, outputPath: string) {\n const response = await fetch(url);\n const content = await response.blob();\n\n const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), \"create-repo\"));\n\n const tmpFile = path.join(tmpDir, \"packed-repo.zip\");\n const f = Writable.toWeb(createWriteStream(tmpFile));\n await content.stream().pipeTo(f);\n\n const tmpRepo = path.join(tmpDir, \"unpacked-repo\");\n await fs.mkdir(tmpRepo);\n await decompress(tmpFile, tmpRepo);\n\n await fs.cp(path.join(tmpRepo, pathInArchive), outputPath, { recursive: true });\n}\n\n/** Removes a bunch of dependencies to the platform. */\nasync function removePlatform(dir: string, platform: CreateBlockPlatform) {\n const p = platform.toLowerCase();\n\n // Remove <PlAlert> line from MainPage.vue\n // https://regex101.com/r/oCTyHk/1\n await deleteRegexInFile(\n path.join(dir, \"ui\", \"src\", \"pages\", \"MainPage.vue\"),\n new RegExp(`.*${p}Message.*\\\\n`, \"g\"),\n );\n\n // Remove an output from the model.\n await deleteRegexInFile(\n path.join(dir, \"model\", \"src\", \"index.ts\"),\n new RegExp(`.*${p}Message.*\\\\n\\\\n`, \"g\"),\n );\n\n // This regexp represents a block of code until the empty line.\n // https://regex101.com/r/Os8kX1/1\n await deleteRegexInFile(\n path.join(dir, \"workflow\", \"src\", \"main.tpl.tengo\"),\n new RegExp(`.*${p}.*exec.builder.*[\\\\s\\\\S]*?\\\\n\\\\n`, \"g\"),\n );\n\n // Remove a line from the workflow output.\n // https://regex101.com/r/PkHwQ8/1\n await deleteRegexInFile(\n path.join(dir, \"workflow\", \"src\", \"main.tpl.tengo\"),\n new RegExp(`.*${p}Message.*\\\\n`, \"g\"),\n );\n\n // Remove 2 lines: the one with the language message and the one with expect\n await deleteRegexInFile(\n path.join(dir, \"workflow\", \"src\", \"wf.test.ts\"),\n new RegExp(`.*${p}Message.*\\\\n.*expect.*\\\\n\\\\n`, \"g\"),\n );\n\n await fs.rm(path.join(dir, \"software\", `src_${p}`), { recursive: true });\n\n await replaceInFile(path.join(dir, \"software\", \"package.json\"), (content) => {\n const json = JSON.parse(content);\n delete json[\"block-software\"][\"artifacts\"][`hello-${p}-artifact`];\n delete json[\"block-software\"][\"entrypoints\"][`hello-world-${p}`];\n return JSON.stringify(json, null, 2);\n });\n}\n\n/** Removes software directory completely and all references to it from the workspace. */\nasync function removePlatformsCompletely(dir: string) {\n await fs.rm(path.join(dir, \"software\"), { recursive: true });\n\n await replaceInFile(path.join(dir, \"workflow\", \"package.json\"), (content) => {\n const json = JSON.parse(content);\n delete json[\"dependencies\"][\"@platforma-open/my-org.block-boilerplate.software\"];\n return JSON.stringify(json, null, 2);\n });\n\n await deleteRegexInFile(path.join(dir, \"pnpm-workspace.yaml\"), /.*- software$\\n/gm);\n}\n\nasync function replaceRegexInAllFiles(dir: string, patterns: { from: RegExp; to: string }[]) {\n const files = await getAllFiles(dir);\n for (const { from, to } of patterns) {\n for (const fPath of files) {\n await replaceRegexInFile(fPath, from, to);\n }\n }\n}\n\nasync function getAllFiles(dir: string): Promise<string[]> {\n const allDirents = await fs.readdir(dir, {\n withFileTypes: true,\n recursive: true,\n });\n\n return allDirents.filter((f: any) => f.isFile()).map((f: any) => path.join(f.parentPath, f.name));\n}\n\nasync function replaceInFile(fPath: string, replacer: (content: string) => any) {\n const content = await fs.readFile(fPath);\n const newContent = replacer(content.toString());\n await fs.writeFile(fPath, newContent);\n}\n\nasync function replaceRegexInFile(fPath: string, from: RegExp, to: string) {\n return await replaceInFile(fPath, (content) => content.replaceAll(from, to));\n}\n\nasync function deleteRegexInFile(fPath: string, what: RegExp) {\n return await replaceRegexInFile(fPath, what, \"\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAUA,MAAM,yBAAyB,CAAC,SAAS;AACzC,MAAM,eAAe,CAAC,SAAS,SAAS;AACxC,MAAM,uBAAuBA,MAAE,MAAM,CAACA,MAAE,QAAQ,QAAQ,EAAEA,MAAE,QAAQ,SAAS,CAAC,CAAC;AAG/E,MAAM,qBAAqBA,MAAE,OAAO;CAClC,YAAYA,MAAE,QAAQ,CAAC,IAAI,EAAE;CAC7B,SAASA,MAAE,QAAQ,CAAC,IAAI,GAAG,EAAE,SAAS,sCAAsC,CAAC;CAC7E,WAAWA,MAAE,QAAQ,CAAC,IAAI,GAAG,EAAE,SAAS,+BAA+B,CAAC;CACxE,mBAAmBA,MAAE,MAAM,qBAAqB,CAAC,QAAQ,MAAM,IAAI,IAAI,EAAE,CAAC,SAAS,EAAE,QAAQ,EAC3F,SAAS,iDACV,CAAC;CACH,CAAC;;AAIF,eAAsB,YAAY,QAAwB;CACxD,MAAM,EAAE,YAAY,SAAS,WAAW,sBAAsB,eAAe;CAC7E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