@platforma-sdk/bootstrap 5.2.50 → 5.2.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/block.cjs +106 -146
- package/dist/block.cjs.map +1 -1
- package/dist/block.js +100 -125
- package/dist/block.js.map +1 -1
- package/dist/cmd-opts.cjs +87 -177
- package/dist/cmd-opts.cjs.map +1 -1
- package/dist/cmd-opts.js +87 -172
- package/dist/cmd-opts.js.map +1 -1
- package/dist/commands/create-block.cjs +19 -20
- package/dist/commands/create-block.cjs.map +1 -1
- package/dist/commands/create-block.d.ts +12 -7
- package/dist/commands/create-block.js +17 -17
- package/dist/commands/create-block.js.map +1 -1
- package/dist/commands/reset.cjs +18 -21
- package/dist/commands/reset.cjs.map +1 -1
- package/dist/commands/reset.d.ts +12 -7
- package/dist/commands/reset.js +16 -18
- package/dist/commands/reset.js.map +1 -1
- package/dist/commands/start/docker/s3.cjs +64 -67
- package/dist/commands/start/docker/s3.cjs.map +1 -1
- package/dist/commands/start/docker/s3.d.ts +32 -27
- package/dist/commands/start/docker/s3.js +61 -64
- package/dist/commands/start/docker/s3.js.map +1 -1
- package/dist/commands/start/docker.cjs +64 -67
- package/dist/commands/start/docker.cjs.map +1 -1
- package/dist/commands/start/docker.d.ts +32 -27
- package/dist/commands/start/docker.js +61 -64
- package/dist/commands/start/docker.js.map +1 -1
- package/dist/commands/start/local/s3.cjs +101 -135
- package/dist/commands/start/local/s3.cjs.map +1 -1
- package/dist/commands/start/local/s3.d.ts +36 -31
- package/dist/commands/start/local/s3.js +97 -113
- package/dist/commands/start/local/s3.js.map +1 -1
- package/dist/commands/start/local.cjs +95 -122
- package/dist/commands/start/local.cjs.map +1 -1
- package/dist/commands/start/local.d.ts +34 -29
- package/dist/commands/start/local.js +91 -100
- package/dist/commands/start/local.js.map +1 -1
- package/dist/commands/start.cjs +18 -21
- package/dist/commands/start.cjs.map +1 -1
- package/dist/commands/start.d.ts +12 -7
- package/dist/commands/start.js +16 -18
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/stop.cjs +22 -27
- package/dist/commands/stop.cjs.map +1 -1
- package/dist/commands/stop.d.ts +12 -7
- package/dist/commands/stop.js +20 -24
- package/dist/commands/stop.js.map +1 -1
- package/dist/commands/svc/create/arg-parser.cjs +102 -172
- package/dist/commands/svc/create/arg-parser.cjs.map +1 -1
- package/dist/commands/svc/create/arg-parser.js +102 -171
- package/dist/commands/svc/create/arg-parser.js.map +1 -1
- package/dist/commands/svc/create/docker/s3.cjs +78 -96
- package/dist/commands/svc/create/docker/s3.cjs.map +1 -1
- package/dist/commands/svc/create/docker/s3.d.ts +35 -30
- package/dist/commands/svc/create/docker/s3.js +75 -93
- package/dist/commands/svc/create/docker/s3.js.map +1 -1
- package/dist/commands/svc/create/docker.cjs +82 -103
- package/dist/commands/svc/create/docker.cjs.map +1 -1
- package/dist/commands/svc/create/docker.d.ts +35 -30
- package/dist/commands/svc/create/docker.js +79 -100
- package/dist/commands/svc/create/docker.js.map +1 -1
- package/dist/commands/svc/create/local/s3.cjs +107 -139
- package/dist/commands/svc/create/local/s3.cjs.map +1 -1
- package/dist/commands/svc/create/local/s3.d.ts +39 -34
- package/dist/commands/svc/create/local/s3.js +103 -117
- package/dist/commands/svc/create/local/s3.js.map +1 -1
- package/dist/commands/svc/create/local.cjs +101 -138
- package/dist/commands/svc/create/local.cjs.map +1 -1
- package/dist/commands/svc/create/local.d.ts +37 -32
- package/dist/commands/svc/create/local.js +97 -116
- package/dist/commands/svc/create/local.js.map +1 -1
- package/dist/commands/svc/delete.cjs +36 -38
- package/dist/commands/svc/delete.cjs.map +1 -1
- package/dist/commands/svc/delete.d.ts +16 -11
- package/dist/commands/svc/delete.js +34 -35
- package/dist/commands/svc/delete.js.map +1 -1
- package/dist/commands/svc/down.cjs +27 -30
- package/dist/commands/svc/down.cjs.map +1 -1
- package/dist/commands/svc/down.d.ts +15 -10
- package/dist/commands/svc/down.js +25 -27
- package/dist/commands/svc/down.js.map +1 -1
- package/dist/commands/svc/list.cjs +25 -29
- package/dist/commands/svc/list.cjs.map +1 -1
- package/dist/commands/svc/list.d.ts +9 -5
- package/dist/commands/svc/list.js +23 -26
- package/dist/commands/svc/list.js.map +1 -1
- package/dist/commands/svc/up.cjs +33 -49
- package/dist/commands/svc/up.cjs.map +1 -1
- package/dist/commands/svc/up.d.ts +15 -10
- package/dist/commands/svc/up.js +31 -46
- package/dist/commands/svc/up.js.map +1 -1
- package/dist/core.cjs +712 -881
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +709 -877
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +36 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +37 -33
- package/dist/index.js +35 -34
- package/dist/index.js.map +1 -1
- package/dist/package.cjs +15 -36
- package/dist/package.cjs.map +1 -1
- package/dist/package.js +14 -14
- package/dist/package.js.map +1 -1
- package/dist/platforma.cjs +119 -148
- package/dist/platforma.cjs.map +1 -1
- package/dist/platforma.js +114 -122
- package/dist/platforma.js.map +1 -1
- package/dist/run.cjs +55 -58
- package/dist/run.cjs.map +1 -1
- package/dist/run.js +56 -56
- package/dist/run.js.map +1 -1
- package/dist/state.cjs +114 -141
- package/dist/state.cjs.map +1 -1
- package/dist/state.js +110 -139
- package/dist/state.js.map +1 -1
- package/dist/templates/compose.cjs +38 -65
- package/dist/templates/compose.cjs.map +1 -1
- package/dist/templates/compose.js +35 -63
- package/dist/templates/compose.js.map +1 -1
- package/dist/templates/pl-config.cjs +163 -165
- package/dist/templates/pl-config.cjs.map +1 -1
- package/dist/templates/pl-config.js +161 -163
- package/dist/templates/pl-config.js.map +1 -1
- package/dist/templates/types.cjs +24 -23
- package/dist/templates/types.cjs.map +1 -1
- package/dist/templates/types.js +24 -22
- package/dist/templates/types.js.map +1 -1
- package/dist/util.cjs +57 -74
- package/dist/util.cjs.map +1 -1
- package/dist/util.js +51 -72
- package/dist/util.js.map +1 -1
- package/package.json +6 -6
- package/dist/block.d.ts +0 -25
- package/dist/block.d.ts.map +0 -1
- package/dist/cmd-opts.d.ts +0 -89
- package/dist/cmd-opts.d.ts.map +0 -1
- package/dist/commands/create-block.d.ts.map +0 -1
- package/dist/commands/reset.d.ts.map +0 -1
- package/dist/commands/start/docker/s3.d.ts.map +0 -1
- package/dist/commands/start/docker.d.ts.map +0 -1
- package/dist/commands/start/local/s3.d.ts.map +0 -1
- package/dist/commands/start/local.d.ts.map +0 -1
- package/dist/commands/start.d.ts.map +0 -1
- package/dist/commands/stop.d.ts.map +0 -1
- package/dist/commands/svc/create/arg-parser.d.ts +0 -43
- package/dist/commands/svc/create/arg-parser.d.ts.map +0 -1
- package/dist/commands/svc/create/docker/s3.d.ts.map +0 -1
- package/dist/commands/svc/create/docker.d.ts.map +0 -1
- package/dist/commands/svc/create/local/s3.d.ts.map +0 -1
- package/dist/commands/svc/create/local.d.ts.map +0 -1
- package/dist/commands/svc/delete.d.ts.map +0 -1
- package/dist/commands/svc/down.d.ts.map +0 -1
- package/dist/commands/svc/list.d.ts.map +0 -1
- package/dist/commands/svc/up.d.ts.map +0 -1
- package/dist/core.d.ts +0 -105
- package/dist/core.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/package.d.ts +0 -7
- package/dist/package.d.ts.map +0 -1
- package/dist/platforma.d.ts +0 -24
- package/dist/platforma.d.ts.map +0 -1
- package/dist/run.d.ts +0 -13
- package/dist/run.d.ts.map +0 -1
- package/dist/state.d.ts +0 -63
- package/dist/state.d.ts.map +0 -1
- package/dist/templates/compose.d.ts +0 -14
- package/dist/templates/compose.d.ts.map +0 -1
- package/dist/templates/pl-config.d.ts +0 -6
- package/dist/templates/pl-config.d.ts.map +0 -1
- package/dist/templates/types.d.ts +0 -138
- package/dist/templates/types.d.ts.map +0 -1
- package/dist/util.d.ts +0 -18
- 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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
151
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
166
|
-
|
|
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
|
-
|
|
129
|
+
return await replaceInFile(fPath, (content) => content.replaceAll(from, to));
|
|
171
130
|
}
|
|
172
131
|
async function deleteRegexInFile(fPath, what) {
|
|
173
|
-
|
|
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
|
package/dist/block.cjs.map
CHANGED
|
@@ -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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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,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