@platforma-sdk/bootstrap 5.2.40 → 5.2.42

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 (168) hide show
  1. package/README.md +10 -2
  2. package/assets/compose-backend.yaml +2 -2
  3. package/bin/run.js +3 -3
  4. package/dist/block.cjs +36 -31
  5. package/dist/block.cjs.map +1 -1
  6. package/dist/block.d.ts +2 -2
  7. package/dist/block.d.ts.map +1 -1
  8. package/dist/block.js +36 -31
  9. package/dist/block.js.map +1 -1
  10. package/dist/cmd-opts.cjs +74 -74
  11. package/dist/cmd-opts.cjs.map +1 -1
  12. package/dist/cmd-opts.d.ts +23 -23
  13. package/dist/cmd-opts.d.ts.map +1 -1
  14. package/dist/cmd-opts.js +74 -74
  15. package/dist/cmd-opts.js.map +1 -1
  16. package/dist/commands/create-block.cjs +3 -3
  17. package/dist/commands/create-block.cjs.map +1 -1
  18. package/dist/commands/create-block.d.ts +2 -2
  19. package/dist/commands/create-block.d.ts.map +1 -1
  20. package/dist/commands/create-block.js +3 -3
  21. package/dist/commands/create-block.js.map +1 -1
  22. package/dist/commands/reset.cjs +3 -3
  23. package/dist/commands/reset.cjs.map +1 -1
  24. package/dist/commands/reset.d.ts +2 -2
  25. package/dist/commands/reset.d.ts.map +1 -1
  26. package/dist/commands/reset.js +3 -3
  27. package/dist/commands/reset.js.map +1 -1
  28. package/dist/commands/start/docker/s3.cjs +18 -18
  29. package/dist/commands/start/docker/s3.cjs.map +1 -1
  30. package/dist/commands/start/docker/s3.d.ts +15 -15
  31. package/dist/commands/start/docker/s3.d.ts.map +1 -1
  32. package/dist/commands/start/docker/s3.js +18 -18
  33. package/dist/commands/start/docker/s3.js.map +1 -1
  34. package/dist/commands/start/docker.cjs +18 -18
  35. package/dist/commands/start/docker.cjs.map +1 -1
  36. package/dist/commands/start/docker.d.ts +16 -16
  37. package/dist/commands/start/docker.d.ts.map +1 -1
  38. package/dist/commands/start/docker.js +18 -18
  39. package/dist/commands/start/docker.js.map +1 -1
  40. package/dist/commands/start/local/s3.cjs +36 -34
  41. package/dist/commands/start/local/s3.cjs.map +1 -1
  42. package/dist/commands/start/local/s3.d.ts +18 -18
  43. package/dist/commands/start/local/s3.d.ts.map +1 -1
  44. package/dist/commands/start/local/s3.js +36 -34
  45. package/dist/commands/start/local/s3.js.map +1 -1
  46. package/dist/commands/start/local.cjs +32 -30
  47. package/dist/commands/start/local.cjs.map +1 -1
  48. package/dist/commands/start/local.d.ts +16 -16
  49. package/dist/commands/start/local.d.ts.map +1 -1
  50. package/dist/commands/start/local.js +32 -30
  51. package/dist/commands/start/local.js.map +1 -1
  52. package/dist/commands/start.cjs +3 -3
  53. package/dist/commands/start.cjs.map +1 -1
  54. package/dist/commands/start.d.ts +2 -2
  55. package/dist/commands/start.js +3 -3
  56. package/dist/commands/start.js.map +1 -1
  57. package/dist/commands/stop.cjs +4 -4
  58. package/dist/commands/stop.cjs.map +1 -1
  59. package/dist/commands/stop.d.ts +2 -2
  60. package/dist/commands/stop.js +4 -4
  61. package/dist/commands/stop.js.map +1 -1
  62. package/dist/commands/svc/create/arg-parser.cjs +13 -13
  63. package/dist/commands/svc/create/arg-parser.cjs.map +1 -1
  64. package/dist/commands/svc/create/arg-parser.d.ts +1 -1
  65. package/dist/commands/svc/create/arg-parser.js +13 -13
  66. package/dist/commands/svc/create/arg-parser.js.map +1 -1
  67. package/dist/commands/svc/create/docker/s3.cjs +27 -27
  68. package/dist/commands/svc/create/docker/s3.cjs.map +1 -1
  69. package/dist/commands/svc/create/docker/s3.d.ts +15 -15
  70. package/dist/commands/svc/create/docker/s3.d.ts.map +1 -1
  71. package/dist/commands/svc/create/docker/s3.js +27 -27
  72. package/dist/commands/svc/create/docker/s3.js.map +1 -1
  73. package/dist/commands/svc/create/docker.cjs +35 -35
  74. package/dist/commands/svc/create/docker.cjs.map +1 -1
  75. package/dist/commands/svc/create/docker.d.ts +16 -16
  76. package/dist/commands/svc/create/docker.js +35 -35
  77. package/dist/commands/svc/create/docker.js.map +1 -1
  78. package/dist/commands/svc/create/local/s3.cjs +37 -35
  79. package/dist/commands/svc/create/local/s3.cjs.map +1 -1
  80. package/dist/commands/svc/create/local/s3.d.ts +18 -18
  81. package/dist/commands/svc/create/local/s3.d.ts.map +1 -1
  82. package/dist/commands/svc/create/local/s3.js +37 -35
  83. package/dist/commands/svc/create/local/s3.js.map +1 -1
  84. package/dist/commands/svc/create/local.cjs +35 -35
  85. package/dist/commands/svc/create/local.cjs.map +1 -1
  86. package/dist/commands/svc/create/local.d.ts +16 -16
  87. package/dist/commands/svc/create/local.d.ts.map +1 -1
  88. package/dist/commands/svc/create/local.js +35 -35
  89. package/dist/commands/svc/create/local.js.map +1 -1
  90. package/dist/commands/svc/delete.cjs +4 -4
  91. package/dist/commands/svc/delete.cjs.map +1 -1
  92. package/dist/commands/svc/delete.d.ts +2 -2
  93. package/dist/commands/svc/delete.js +4 -4
  94. package/dist/commands/svc/delete.js.map +1 -1
  95. package/dist/commands/svc/down.cjs +3 -3
  96. package/dist/commands/svc/down.cjs.map +1 -1
  97. package/dist/commands/svc/down.d.ts +2 -2
  98. package/dist/commands/svc/down.js +3 -3
  99. package/dist/commands/svc/down.js.map +1 -1
  100. package/dist/commands/svc/list.cjs +5 -5
  101. package/dist/commands/svc/list.cjs.map +1 -1
  102. package/dist/commands/svc/list.d.ts +1 -1
  103. package/dist/commands/svc/list.d.ts.map +1 -1
  104. package/dist/commands/svc/list.js +5 -5
  105. package/dist/commands/svc/list.js.map +1 -1
  106. package/dist/commands/svc/up.cjs +5 -5
  107. package/dist/commands/svc/up.cjs.map +1 -1
  108. package/dist/commands/svc/up.d.ts +2 -2
  109. package/dist/commands/svc/up.d.ts.map +1 -1
  110. package/dist/commands/svc/up.js +5 -5
  111. package/dist/commands/svc/up.js.map +1 -1
  112. package/dist/core.cjs +261 -231
  113. package/dist/core.cjs.map +1 -1
  114. package/dist/core.d.ts +10 -10
  115. package/dist/core.d.ts.map +1 -1
  116. package/dist/core.js +261 -231
  117. package/dist/core.js.map +1 -1
  118. package/dist/index.cjs +16 -16
  119. package/dist/index.cjs.map +1 -1
  120. package/dist/index.d.ts +29 -29
  121. package/dist/index.js +16 -16
  122. package/dist/index.js.map +1 -1
  123. package/dist/package.cjs +2 -2
  124. package/dist/package.cjs.map +1 -1
  125. package/dist/package.js +2 -2
  126. package/dist/package.js.map +1 -1
  127. package/dist/platforma.cjs +24 -24
  128. package/dist/platforma.cjs.map +1 -1
  129. package/dist/platforma.d.ts +1 -1
  130. package/dist/platforma.d.ts.map +1 -1
  131. package/dist/platforma.js +24 -24
  132. package/dist/platforma.js.map +1 -1
  133. package/dist/run.cjs +6 -6
  134. package/dist/run.cjs.map +1 -1
  135. package/dist/run.d.ts +3 -3
  136. package/dist/run.d.ts.map +1 -1
  137. package/dist/run.js +6 -6
  138. package/dist/run.js.map +1 -1
  139. package/dist/state.cjs +16 -14
  140. package/dist/state.cjs.map +1 -1
  141. package/dist/state.d.ts +5 -5
  142. package/dist/state.d.ts.map +1 -1
  143. package/dist/state.js +16 -14
  144. package/dist/state.js.map +1 -1
  145. package/dist/templates/compose.cjs +2 -2
  146. package/dist/templates/compose.cjs.map +1 -1
  147. package/dist/templates/compose.d.ts.map +1 -1
  148. package/dist/templates/compose.js +2 -2
  149. package/dist/templates/compose.js.map +1 -1
  150. package/dist/templates/pl-config.cjs +49 -49
  151. package/dist/templates/pl-config.cjs.map +1 -1
  152. package/dist/templates/pl-config.d.ts +2 -2
  153. package/dist/templates/pl-config.d.ts.map +1 -1
  154. package/dist/templates/pl-config.js +49 -49
  155. package/dist/templates/pl-config.js.map +1 -1
  156. package/dist/templates/types.cjs +12 -12
  157. package/dist/templates/types.cjs.map +1 -1
  158. package/dist/templates/types.d.ts +6 -6
  159. package/dist/templates/types.d.ts.map +1 -1
  160. package/dist/templates/types.js +12 -12
  161. package/dist/templates/types.js.map +1 -1
  162. package/dist/util.cjs +19 -17
  163. package/dist/util.cjs.map +1 -1
  164. package/dist/util.d.ts +2 -2
  165. package/dist/util.d.ts.map +1 -1
  166. package/dist/util.js +19 -17
  167. package/dist/util.js.map +1 -1
  168. package/package.json +23 -22
package/README.md CHANGED
@@ -1,12 +1,15 @@
1
1
  # The CLI multitool for Platforma Block developers.
2
2
 
3
3
  ## Installation
4
+
4
5
  ```bash
5
6
  npm install --global @platforma-sdk/bootstrap@latest
6
7
  # or
7
8
  pnpm install --global @platforma-sdk/bootstrap@latest
8
9
  ```
10
+
9
11
  or use it without installation with
12
+
10
13
  ```bash
11
14
  npx @platforma-sdk/bootstrap@latest '<args>'
12
15
  # or
@@ -14,6 +17,7 @@ pnpx @platforma-sdk/bootstrap@latest '<args>'
14
17
  ```
15
18
 
16
19
  ## Key features:
20
+
17
21
  - empty block skeleton generation
18
22
  - local Platforma Backend service control
19
23
 
@@ -25,14 +29,16 @@ pl-dev '<command>'
25
29
  npx @platforma-sdk/bootstrap@latest '<command>'
26
30
  ```
27
31
 
28
- The tool has 'tree' command structure, like `aws-cli`, `docker`, `git` and many other CLI software:
29
- commands about specific type of operations are grouped under common prefix, i.e. all operations for
32
+ The tool has 'tree' command structure, like `aws-cli`, `docker`, `git` and many other CLI software:
33
+ commands about specific type of operations are grouped under common prefix, i.e. all operations for
30
34
  platforma backend service instances are under `svc` group:
35
+
31
36
  ```bash
32
37
  pl-dev svc create --help
33
38
  ```
34
39
 
35
40
  All commands have `--help` flag that make the command to report its usage information:
41
+
36
42
  ```bash
37
43
  pl-dev --help
38
44
  ```
@@ -40,6 +46,7 @@ pl-dev --help
40
46
  ## Local Platforma Backend service control
41
47
 
42
48
  To create, change, start, stop and delete Platforma Backend on your local computer, use commands in `svc` group:
49
+
43
50
  - `pl-dev svc create docker NAME` creates instance of Platforma Backend inside docker container on your local computer. You can start/stop this instance with `svc up NAME` and `svc down NAME` commands, and connect to it via `localhost:6345` address.
44
51
  - `pl-dev svc list` lists available service instances you created earlier.
45
52
 
@@ -79,6 +86,7 @@ The tool will download Platforma Backend archive for your OS and architecture, g
79
86
  ## Block skeleton generation
80
87
 
81
88
  To create new block skeleton, run
89
+
82
90
  ```bash
83
91
  pl-dev create-block
84
92
  ```
@@ -8,7 +8,7 @@ services:
8
8
  ports:
9
9
  - "${MINIO_PORT:-9000}:9000"
10
10
  - "${MINIO_CONSOLE_PORT:-9001}:9001"
11
-
11
+
12
12
  environment:
13
13
  MINIO_ROOT_USER: testuser
14
14
  MINIO_ROOT_PASSWORD: testpassword
@@ -23,7 +23,7 @@ services:
23
23
  - "${PL_LISTEN_ADDRESS:-127.0.0.1}:${PL_LISTEN_HTTP_PORT:-6347}:6347"
24
24
  - "${PL_MONITORING_IP:-127.0.0.1}:${PL_MONITORING_PORT:-9090}:9090"
25
25
  - "${PL_DEBUG_IP:-127.0.0.1}:${PL_DEBUG_PORT:-9091}:9091"
26
- tmpfs: [ /tmp ]
26
+ tmpfs: [/tmp]
27
27
 
28
28
  logging:
29
29
  driver: json-file
package/bin/run.js CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  // eslint-disable-next-line unicorn/prefer-top-level-await
4
4
  (async () => {
5
- const oclif = await import('@oclif/core')
6
- await oclif.execute({dir: __dirname})
7
- })()
5
+ const oclif = await import("@oclif/core");
6
+ await oclif.execute({ dir: __dirname });
7
+ })();
package/dist/block.cjs CHANGED
@@ -28,15 +28,15 @@ function _interopNamespaceDefault(e) {
28
28
 
29
29
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
30
30
 
31
- const blockPlatformsToChoose = ['Python'];
32
- const allPlatforms = ['Tengo', 'Python'];
33
- const CreateBlockPlatforms = zod.z.union([zod.z.literal('Tengo'), zod.z.literal('Python')]);
31
+ const blockPlatformsToChoose = ["Python"];
32
+ const allPlatforms = ["Tengo", "Python"];
33
+ const CreateBlockPlatforms = zod.z.union([zod.z.literal("Tengo"), zod.z.literal("Python")]);
34
34
  const CreateBlockOptions = zod.z.object({
35
35
  npmOrgName: zod.z.string().min(1),
36
36
  orgName: zod.z.string().min(1, { message: `Organization name must be provided` }),
37
37
  blockName: zod.z.string().min(1, { message: `Block name must be provided` }),
38
38
  softwarePlatforms: zod.z.array(CreateBlockPlatforms).refine((p) => new Set(p).size === p.length, {
39
- message: 'Must be an array of unique software platforms',
39
+ message: "Must be an array of unique software platforms",
40
40
  }),
41
41
  });
42
42
  /** Creates a block by cloning block-boilerplate repository. */
@@ -47,7 +47,7 @@ async function createBlock(logger) {
47
47
  await downloadAndUnzip(
48
48
  // 'https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/software_platforms.zip',
49
49
  // 'platforma-block-boilerplate-software_platforms',
50
- 'https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip', 'platforma-block-boilerplate-main', targetPath);
50
+ "https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip", "platforma-block-boilerplate-main", targetPath);
51
51
  const platformsToRemove = allPlatforms.filter((p) => softwarePlatforms.indexOf(p) < 0);
52
52
  const noPlatforms = blockPlatformsToChoose.length == platformsToRemove.length;
53
53
  logger.info(`Keep platforms '${softwarePlatforms}', remove: '${platformsToRemove}'. Will remove all platforms? ${noPlatforms}`);
@@ -69,40 +69,45 @@ async function createBlock(logger) {
69
69
  }
70
70
  function askForOptions() {
71
71
  let npmOrgName = readlineSync.question('Write an organization name for npm. Default is "platforma-open": ');
72
- if (npmOrgName === '') {
73
- npmOrgName = 'platforma-open';
72
+ if (npmOrgName === "") {
73
+ npmOrgName = "platforma-open";
74
74
  }
75
- let orgName = '';
75
+ let orgName = "";
76
76
  while (orgName.length < 1)
77
77
  orgName = readlineSync.question('Write an organization name, e.g. "my-org": ');
78
- let blockName = '';
78
+ let blockName = "";
79
79
  while (blockName.length < 1)
80
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'];
81
+ const needSoftware = readlineSync.keyInYN("Create package for block's software?");
82
+ let softwarePlatforms = ["Tengo"];
83
83
  if (needSoftware) {
84
84
  while (softwarePlatforms.length < allPlatforms.length) {
85
- const index = readlineSync.keyInSelect(blockPlatformsToChoose, 'Choose software platform:');
85
+ const index = readlineSync.keyInSelect(blockPlatformsToChoose, "Choose software platform:");
86
86
  if (index < 0)
87
87
  break;
88
88
  softwarePlatforms.push(blockPlatformsToChoose[index]);
89
89
  }
90
90
  }
91
91
  softwarePlatforms = Array.from(new Set(softwarePlatforms)).sort();
92
- const result = CreateBlockOptions.safeParse({ npmOrgName, orgName, blockName, softwarePlatforms });
92
+ const result = CreateBlockOptions.safeParse({
93
+ npmOrgName,
94
+ orgName,
95
+ blockName,
96
+ softwarePlatforms,
97
+ });
93
98
  if (!result.success && result.error.issues.length) {
94
- throw new Error(result.error.issues.map((i) => i.message).join('; '));
99
+ throw new Error(result.error.issues.map((i) => i.message).join("; "));
95
100
  }
96
101
  return result.data;
97
102
  }
98
103
  async function downloadAndUnzip(url, pathInArchive, outputPath) {
99
104
  const response = await fetch(url);
100
105
  const content = await response.blob();
101
- const tmpDir = await fs__namespace.mkdtemp(path.join(os.tmpdir(), 'create-repo'));
102
- const tmpFile = path.join(tmpDir, 'packed-repo.zip');
106
+ const tmpDir = await fs__namespace.mkdtemp(path.join(os.tmpdir(), "create-repo"));
107
+ const tmpFile = path.join(tmpDir, "packed-repo.zip");
103
108
  const f = node_stream.Writable.toWeb(fs$1.createWriteStream(tmpFile));
104
109
  await content.stream().pipeTo(f);
105
- const tmpRepo = path.join(tmpDir, 'unpacked-repo');
110
+ const tmpRepo = path.join(tmpDir, "unpacked-repo");
106
111
  await fs__namespace.mkdir(tmpRepo);
107
112
  await decompress(tmpFile, tmpRepo);
108
113
  await fs__namespace.cp(path.join(tmpRepo, pathInArchive), outputPath, { recursive: true });
@@ -112,34 +117,34 @@ async function removePlatform(dir, platform) {
112
117
  const p = platform.toLowerCase();
113
118
  // Remove <PlAlert> line from MainPage.vue
114
119
  // https://regex101.com/r/oCTyHk/1
115
- await deleteRegexInFile(path.join(dir, 'ui', 'src', 'pages', 'MainPage.vue'), new RegExp(`.*${p}Message.*\\n`, 'g'));
120
+ await deleteRegexInFile(path.join(dir, "ui", "src", "pages", "MainPage.vue"), new RegExp(`.*${p}Message.*\\n`, "g"));
116
121
  // Remove an output from the model.
117
- await deleteRegexInFile(path.join(dir, 'model', 'src', 'index.ts'), new RegExp(`.*${p}Message.*\\n\\n`, 'g'));
122
+ await deleteRegexInFile(path.join(dir, "model", "src", "index.ts"), new RegExp(`.*${p}Message.*\\n\\n`, "g"));
118
123
  // This regexp represents a block of code until the empty line.
119
124
  // https://regex101.com/r/Os8kX1/1
120
- await deleteRegexInFile(path.join(dir, 'workflow', 'src', 'main.tpl.tengo'), new RegExp(`.*${p}.*exec.builder.*[\\s\\S]*?\\n\\n`, 'g'));
125
+ await deleteRegexInFile(path.join(dir, "workflow", "src", "main.tpl.tengo"), new RegExp(`.*${p}.*exec.builder.*[\\s\\S]*?\\n\\n`, "g"));
121
126
  // Remove a line from the workflow output.
122
127
  // https://regex101.com/r/PkHwQ8/1
123
- await deleteRegexInFile(path.join(dir, 'workflow', 'src', 'main.tpl.tengo'), new RegExp(`.*${p}Message.*\\n`, 'g'));
128
+ await deleteRegexInFile(path.join(dir, "workflow", "src", "main.tpl.tengo"), new RegExp(`.*${p}Message.*\\n`, "g"));
124
129
  // Remove 2 lines: the one with the language message and the one with expect
125
- await deleteRegexInFile(path.join(dir, 'workflow', 'src', 'wf.test.ts'), new RegExp(`.*${p}Message.*\\n.*expect.*\\n\\n`, 'g'));
126
- await fs__namespace.rm(path.join(dir, 'software', `src_${p}`), { recursive: true });
127
- await replaceInFile(path.join(dir, 'software', 'package.json'), (content) => {
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) => {
128
133
  const json = JSON.parse(content);
129
- delete json['block-software']['artifacts'][`hello-${p}-artifact`];
130
- delete json['block-software']['entrypoints'][`hello-world-${p}`];
134
+ delete json["block-software"]["artifacts"][`hello-${p}-artifact`];
135
+ delete json["block-software"]["entrypoints"][`hello-world-${p}`];
131
136
  return JSON.stringify(json, null, 2);
132
137
  });
133
138
  }
134
139
  /** Removes software directory completely and all references to it from the workspace. */
135
140
  async function removePlatformsCompletely(dir) {
136
- await fs__namespace.rm(path.join(dir, 'software'), { recursive: true });
137
- await replaceInFile(path.join(dir, 'workflow', 'package.json'), (content) => {
141
+ await fs__namespace.rm(path.join(dir, "software"), { recursive: true });
142
+ await replaceInFile(path.join(dir, "workflow", "package.json"), (content) => {
138
143
  const json = JSON.parse(content);
139
- delete json['dependencies']['@platforma-open/my-org.block-boilerplate.software'];
144
+ delete json["dependencies"]["@platforma-open/my-org.block-boilerplate.software"];
140
145
  return JSON.stringify(json, null, 2);
141
146
  });
142
- await deleteRegexInFile(path.join(dir, 'pnpm-workspace.yaml'), /.*- software$\n/gm);
147
+ await deleteRegexInFile(path.join(dir, "pnpm-workspace.yaml"), /.*- software$\n/gm);
143
148
  }
144
149
  async function replaceRegexInAllFiles(dir, patterns) {
145
150
  const files = await getAllFiles(dir);
@@ -165,7 +170,7 @@ async function replaceRegexInFile(fPath, from, to) {
165
170
  return await replaceInFile(fPath, (content) => content.replaceAll(from, to));
166
171
  }
167
172
  async function deleteRegexInFile(fPath, what) {
168
- return await replaceRegexInFile(fPath, what, '');
173
+ return await replaceRegexInFile(fPath, what, "");
169
174
  }
170
175
 
171
176
  exports.createBlock = createBlock;
@@ -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(`Keep platforms '${softwarePlatforms}', remove: '${platformsToRemove}'. Will remove all platforms? ${noPlatforms}`);\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({ npmOrgName, orgName, blockName, softwarePlatforms });\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(\n path.join(dir, 'software', 'package.json'),\n (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\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(\n path.join(dir, 'workflow', 'package.json'),\n (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\n await deleteRegexInFile(\n path.join(dir, 'pnpm-workspace.yaml'),\n /.*- software$\\n/gm,\n );\n}\n\nasync function replaceRegexInAllFiles(\n dir: string,\n patterns: { from: RegExp; to: string }[],\n) {\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,IAA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,EAAE;AACnC,QAAA,KAAK,MAAM,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","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,G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,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;AAClD;;;;"}
package/dist/block.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type winston from 'winston';
2
- import { z } from 'zod';
1
+ import type winston from "winston";
2
+ import { z } from "zod";
3
3
  declare const CreateBlockPlatforms: z.ZodUnion<[z.ZodLiteral<"Tengo">, z.ZodLiteral<"Python">]>;
4
4
  export type CreateBlockPlatform = z.infer<typeof CreateBlockPlatforms>;
5
5
  declare const CreateBlockOptions: z.ZodObject<{
@@ -1 +1 @@
1
- {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,QAAA,MAAM,oBAAoB,6DAAqD,CAAC;AAChF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEvE,QAAA,MAAM,kBAAkB;;;;;;;;;;;;;;;EAOtB,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE,+DAA+D;AAC/D,wBAAsB,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,iBAkCvD"}
1
+ {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,QAAA,MAAM,oBAAoB,6DAAqD,CAAC;AAChF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEvE,QAAA,MAAM,kBAAkB;;;;;;;;;;;;;;;EAOtB,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE,+DAA+D;AAC/D,wBAAsB,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,iBAoCvD"}
package/dist/block.js CHANGED
@@ -7,15 +7,15 @@ import readlineSync from 'readline-sync';
7
7
  import { z } from 'zod';
8
8
  import decompress from 'decompress';
9
9
 
10
- const blockPlatformsToChoose = ['Python'];
11
- const allPlatforms = ['Tengo', 'Python'];
12
- const CreateBlockPlatforms = z.union([z.literal('Tengo'), z.literal('Python')]);
10
+ const blockPlatformsToChoose = ["Python"];
11
+ const allPlatforms = ["Tengo", "Python"];
12
+ const CreateBlockPlatforms = z.union([z.literal("Tengo"), z.literal("Python")]);
13
13
  const CreateBlockOptions = z.object({
14
14
  npmOrgName: z.string().min(1),
15
15
  orgName: z.string().min(1, { message: `Organization name must be provided` }),
16
16
  blockName: z.string().min(1, { message: `Block name must be provided` }),
17
17
  softwarePlatforms: z.array(CreateBlockPlatforms).refine((p) => new Set(p).size === p.length, {
18
- message: 'Must be an array of unique software platforms',
18
+ message: "Must be an array of unique software platforms",
19
19
  }),
20
20
  });
21
21
  /** Creates a block by cloning block-boilerplate repository. */
@@ -26,7 +26,7 @@ async function createBlock(logger) {
26
26
  await downloadAndUnzip(
27
27
  // 'https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/software_platforms.zip',
28
28
  // 'platforma-block-boilerplate-software_platforms',
29
- 'https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip', 'platforma-block-boilerplate-main', targetPath);
29
+ "https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip", "platforma-block-boilerplate-main", targetPath);
30
30
  const platformsToRemove = allPlatforms.filter((p) => softwarePlatforms.indexOf(p) < 0);
31
31
  const noPlatforms = blockPlatformsToChoose.length == platformsToRemove.length;
32
32
  logger.info(`Keep platforms '${softwarePlatforms}', remove: '${platformsToRemove}'. Will remove all platforms? ${noPlatforms}`);
@@ -48,40 +48,45 @@ async function createBlock(logger) {
48
48
  }
49
49
  function askForOptions() {
50
50
  let npmOrgName = readlineSync.question('Write an organization name for npm. Default is "platforma-open": ');
51
- if (npmOrgName === '') {
52
- npmOrgName = 'platforma-open';
51
+ if (npmOrgName === "") {
52
+ npmOrgName = "platforma-open";
53
53
  }
54
- let orgName = '';
54
+ let orgName = "";
55
55
  while (orgName.length < 1)
56
56
  orgName = readlineSync.question('Write an organization name, e.g. "my-org": ');
57
- let blockName = '';
57
+ let blockName = "";
58
58
  while (blockName.length < 1)
59
59
  blockName = readlineSync.question('Write a name of the block, e.g. "hello-world": ');
60
- const needSoftware = readlineSync.keyInYN('Create package for block\'s software?');
61
- let softwarePlatforms = ['Tengo'];
60
+ const needSoftware = readlineSync.keyInYN("Create package for block's software?");
61
+ let softwarePlatforms = ["Tengo"];
62
62
  if (needSoftware) {
63
63
  while (softwarePlatforms.length < allPlatforms.length) {
64
- const index = readlineSync.keyInSelect(blockPlatformsToChoose, 'Choose software platform:');
64
+ const index = readlineSync.keyInSelect(blockPlatformsToChoose, "Choose software platform:");
65
65
  if (index < 0)
66
66
  break;
67
67
  softwarePlatforms.push(blockPlatformsToChoose[index]);
68
68
  }
69
69
  }
70
70
  softwarePlatforms = Array.from(new Set(softwarePlatforms)).sort();
71
- const result = CreateBlockOptions.safeParse({ npmOrgName, orgName, blockName, softwarePlatforms });
71
+ const result = CreateBlockOptions.safeParse({
72
+ npmOrgName,
73
+ orgName,
74
+ blockName,
75
+ softwarePlatforms,
76
+ });
72
77
  if (!result.success && result.error.issues.length) {
73
- throw new Error(result.error.issues.map((i) => i.message).join('; '));
78
+ throw new Error(result.error.issues.map((i) => i.message).join("; "));
74
79
  }
75
80
  return result.data;
76
81
  }
77
82
  async function downloadAndUnzip(url, pathInArchive, outputPath) {
78
83
  const response = await fetch(url);
79
84
  const content = await response.blob();
80
- const tmpDir = await fs.mkdtemp(path.join(os__default.tmpdir(), 'create-repo'));
81
- const tmpFile = path.join(tmpDir, 'packed-repo.zip');
85
+ const tmpDir = await fs.mkdtemp(path.join(os__default.tmpdir(), "create-repo"));
86
+ const tmpFile = path.join(tmpDir, "packed-repo.zip");
82
87
  const f = Writable.toWeb(createWriteStream(tmpFile));
83
88
  await content.stream().pipeTo(f);
84
- const tmpRepo = path.join(tmpDir, 'unpacked-repo');
89
+ const tmpRepo = path.join(tmpDir, "unpacked-repo");
85
90
  await fs.mkdir(tmpRepo);
86
91
  await decompress(tmpFile, tmpRepo);
87
92
  await fs.cp(path.join(tmpRepo, pathInArchive), outputPath, { recursive: true });
@@ -91,34 +96,34 @@ async function removePlatform(dir, platform) {
91
96
  const p = platform.toLowerCase();
92
97
  // Remove <PlAlert> line from MainPage.vue
93
98
  // https://regex101.com/r/oCTyHk/1
94
- await deleteRegexInFile(path.join(dir, 'ui', 'src', 'pages', 'MainPage.vue'), new RegExp(`.*${p}Message.*\\n`, 'g'));
99
+ await deleteRegexInFile(path.join(dir, "ui", "src", "pages", "MainPage.vue"), new RegExp(`.*${p}Message.*\\n`, "g"));
95
100
  // Remove an output from the model.
96
- await deleteRegexInFile(path.join(dir, 'model', 'src', 'index.ts'), new RegExp(`.*${p}Message.*\\n\\n`, 'g'));
101
+ await deleteRegexInFile(path.join(dir, "model", "src", "index.ts"), new RegExp(`.*${p}Message.*\\n\\n`, "g"));
97
102
  // This regexp represents a block of code until the empty line.
98
103
  // https://regex101.com/r/Os8kX1/1
99
- await deleteRegexInFile(path.join(dir, 'workflow', 'src', 'main.tpl.tengo'), new RegExp(`.*${p}.*exec.builder.*[\\s\\S]*?\\n\\n`, 'g'));
104
+ await deleteRegexInFile(path.join(dir, "workflow", "src", "main.tpl.tengo"), new RegExp(`.*${p}.*exec.builder.*[\\s\\S]*?\\n\\n`, "g"));
100
105
  // Remove a line from the workflow output.
101
106
  // https://regex101.com/r/PkHwQ8/1
102
- await deleteRegexInFile(path.join(dir, 'workflow', 'src', 'main.tpl.tengo'), new RegExp(`.*${p}Message.*\\n`, 'g'));
107
+ await deleteRegexInFile(path.join(dir, "workflow", "src", "main.tpl.tengo"), new RegExp(`.*${p}Message.*\\n`, "g"));
103
108
  // Remove 2 lines: the one with the language message and the one with expect
104
- await deleteRegexInFile(path.join(dir, 'workflow', 'src', 'wf.test.ts'), new RegExp(`.*${p}Message.*\\n.*expect.*\\n\\n`, 'g'));
105
- await fs.rm(path.join(dir, 'software', `src_${p}`), { recursive: true });
106
- await replaceInFile(path.join(dir, 'software', 'package.json'), (content) => {
109
+ await deleteRegexInFile(path.join(dir, "workflow", "src", "wf.test.ts"), new RegExp(`.*${p}Message.*\\n.*expect.*\\n\\n`, "g"));
110
+ await fs.rm(path.join(dir, "software", `src_${p}`), { recursive: true });
111
+ await replaceInFile(path.join(dir, "software", "package.json"), (content) => {
107
112
  const json = JSON.parse(content);
108
- delete json['block-software']['artifacts'][`hello-${p}-artifact`];
109
- delete json['block-software']['entrypoints'][`hello-world-${p}`];
113
+ delete json["block-software"]["artifacts"][`hello-${p}-artifact`];
114
+ delete json["block-software"]["entrypoints"][`hello-world-${p}`];
110
115
  return JSON.stringify(json, null, 2);
111
116
  });
112
117
  }
113
118
  /** Removes software directory completely and all references to it from the workspace. */
114
119
  async function removePlatformsCompletely(dir) {
115
- await fs.rm(path.join(dir, 'software'), { recursive: true });
116
- await replaceInFile(path.join(dir, 'workflow', 'package.json'), (content) => {
120
+ await fs.rm(path.join(dir, "software"), { recursive: true });
121
+ await replaceInFile(path.join(dir, "workflow", "package.json"), (content) => {
117
122
  const json = JSON.parse(content);
118
- delete json['dependencies']['@platforma-open/my-org.block-boilerplate.software'];
123
+ delete json["dependencies"]["@platforma-open/my-org.block-boilerplate.software"];
119
124
  return JSON.stringify(json, null, 2);
120
125
  });
121
- await deleteRegexInFile(path.join(dir, 'pnpm-workspace.yaml'), /.*- software$\n/gm);
126
+ await deleteRegexInFile(path.join(dir, "pnpm-workspace.yaml"), /.*- software$\n/gm);
122
127
  }
123
128
  async function replaceRegexInAllFiles(dir, patterns) {
124
129
  const files = await getAllFiles(dir);
@@ -144,7 +149,7 @@ async function replaceRegexInFile(fPath, from, to) {
144
149
  return await replaceInFile(fPath, (content) => content.replaceAll(from, to));
145
150
  }
146
151
  async function deleteRegexInFile(fPath, what) {
147
- return await replaceRegexInFile(fPath, what, '');
152
+ return await replaceRegexInFile(fPath, what, "");
148
153
  }
149
154
 
150
155
  export { createBlock };
package/dist/block.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"block.js","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(`Keep platforms '${softwarePlatforms}', remove: '${platformsToRemove}'. Will remove all platforms? ${noPlatforms}`);\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({ npmOrgName, orgName, blockName, softwarePlatforms });\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(\n path.join(dir, 'software', 'package.json'),\n (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\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(\n path.join(dir, 'workflow', 'package.json'),\n (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\n await deleteRegexInFile(\n path.join(dir, 'pnpm-workspace.yaml'),\n /.*- software$\\n/gm,\n );\n}\n\nasync function replaceRegexInAllFiles(\n dir: string,\n patterns: { from: RegExp; to: string }[],\n) {\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":["os"],"mappings":";;;;;;;;;AAUA,MAAM,sBAAsB,GAAG,CAAC,QAAQ,CAAC;AACzC,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAU;AACjD,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAG/E,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,UAAU,EAAE,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E,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.js","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":["os"],"mappings":";;;;;;;;;AAUA,MAAM,sBAAsB,GAAG,CAAC,QAAQ,CAAC;AACzC,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAU;AACjD,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC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