@platforma-sdk/block-tools 2.1.5 → 2.1.7
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/cli.js +1 -756
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +187 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/cmd/build-meta.d.ts +10 -0
- package/dist/cmd/build-meta.d.ts.map +1 -0
- package/dist/cmd/build-model.d.ts +11 -0
- package/dist/cmd/build-model.d.ts.map +1 -0
- package/dist/cmd/index.d.ts +11 -0
- package/dist/cmd/index.d.ts.map +1 -0
- package/dist/cmd/pack-block.d.ts +10 -0
- package/dist/cmd/pack-block.d.ts.map +1 -0
- package/dist/cmd/upload-package-v1.d.ts +15 -0
- package/dist/cmd/upload-package-v1.d.ts.map +1 -0
- package/dist/common_types.d.ts +3 -0
- package/dist/common_types.d.ts.map +1 -0
- package/dist/config-BJognM_j.mjs +536 -0
- package/dist/config-BJognM_j.mjs.map +1 -0
- package/dist/config-CfA0Dj6h.js +3 -0
- package/dist/config-CfA0Dj6h.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +43 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/storage.d.ts +29 -0
- package/dist/lib/storage.d.ts.map +1 -0
- package/dist/lib.d.ts +3 -2637
- package/dist/lib.d.ts.map +1 -0
- package/dist/registry_v1/config.d.ts +12 -0
- package/dist/registry_v1/config.d.ts.map +1 -0
- package/dist/registry_v1/config_schema.d.ts +94 -0
- package/dist/registry_v1/config_schema.d.ts.map +1 -0
- package/dist/registry_v1/flags.d.ts +9 -0
- package/dist/registry_v1/flags.d.ts.map +1 -0
- package/dist/registry_v1/index.d.ts +4 -0
- package/dist/registry_v1/index.d.ts.map +1 -0
- package/dist/registry_v1/registry.d.ts +46 -0
- package/dist/registry_v1/registry.d.ts.map +1 -0
- package/dist/registry_v1/v1_repo_schema.d.ts +25 -0
- package/dist/registry_v1/v1_repo_schema.d.ts.map +1 -0
- package/dist/util.d.ts +4 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/v2/build_dist.d.ts +3 -0
- package/dist/v2/build_dist.d.ts.map +1 -0
- package/dist/v2/index.d.ts +4 -0
- package/dist/v2/index.d.ts.map +1 -0
- package/dist/v2/model/block_components.d.ts +384 -0
- package/dist/v2/model/block_components.d.ts.map +1 -0
- package/dist/v2/model/common.d.ts +3 -0
- package/dist/v2/model/common.d.ts.map +1 -0
- package/dist/v2/model/content_conversion.d.ts +35 -0
- package/dist/v2/model/content_conversion.d.ts.map +1 -0
- package/dist/v2/model/content_types.d.ts +478 -0
- package/dist/v2/model/content_types.d.ts.map +1 -0
- package/dist/{lib.d.cts → v2/model/index.d.ts} +449 -1005
- package/dist/v2/model/index.d.ts.map +1 -0
- package/dist/v2/model/meta.d.ts +805 -0
- package/dist/v2/model/meta.d.ts.map +1 -0
- package/dist/v2/registry/schema.d.ts +15 -0
- package/dist/v2/registry/schema.d.ts.map +1 -0
- package/dist/v2/source_package.d.ts +8 -0
- package/dist/v2/source_package.d.ts.map +1 -0
- package/package.json +24 -17
- package/src/cmd/build-meta.ts +38 -0
- package/src/cmd/build-model.ts +76 -0
- package/src/cmd/index.ts +12 -0
- package/src/cmd/pack-block.ts +32 -0
- package/src/cmd/upload-package-v1.ts +105 -0
- package/src/common_types.ts +3 -0
- package/src/lib/storage.test.ts +91 -0
- package/src/lib/storage.ts +140 -0
- package/src/lib.ts +2 -0
- package/src/registry_v1/config.ts +90 -0
- package/src/registry_v1/config_schema.ts +30 -0
- package/src/registry_v1/flags.ts +23 -0
- package/src/registry_v1/index.ts +3 -0
- package/src/registry_v1/registry.test.ts +122 -0
- package/src/registry_v1/registry.ts +253 -0
- package/src/registry_v1/v1_repo_schema.ts +42 -0
- package/src/util.ts +25 -0
- package/src/v2/build_dist.test.ts +16 -0
- package/src/v2/build_dist.ts +29 -0
- package/src/v2/index.ts +3 -0
- package/src/v2/model/block_components.ts +32 -0
- package/src/v2/model/common.ts +2 -0
- package/src/v2/model/content_conversion.ts +178 -0
- package/src/v2/model/content_types.ts +233 -0
- package/src/v2/model/index.ts +46 -0
- package/src/v2/model/meta.ts +36 -0
- package/src/v2/registry/schema.ts +29 -0
- package/src/v2/source_package.test.ts +27 -0
- package/src/v2/source_package.ts +82 -0
- package/dist/cli.cjs +0 -786
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -58
- package/dist/cli.d.ts +0 -58
- package/dist/lib.cjs +0 -629
- package/dist/lib.cjs.map +0 -1
- package/dist/lib.js +0 -577
- package/dist/lib.js.map +0 -1
package/dist/cli.cjs
DELETED
|
@@ -1,786 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@oclif/core');
|
|
4
|
-
var path7 = require('path');
|
|
5
|
-
var fs3 = require('fs');
|
|
6
|
-
var zod = require('zod');
|
|
7
|
-
var fsp = require('fs/promises');
|
|
8
|
-
var mime = require('mime-types');
|
|
9
|
-
var tar = require('tar');
|
|
10
|
-
var plModelMiddleLayer = require('@milaboratories/pl-model-middle-layer');
|
|
11
|
-
var tsHelpers = require('@milaboratories/ts-helpers');
|
|
12
|
-
var YAML2 = require('yaml');
|
|
13
|
-
var os = require('os');
|
|
14
|
-
var crypto = require('crypto');
|
|
15
|
-
var semver = require('semver/preload');
|
|
16
|
-
var pathPosix = require('path/posix');
|
|
17
|
-
var clientS3 = require('@aws-sdk/client-s3');
|
|
18
|
-
var tsHelpersOclif = require('@milaboratories/ts-helpers-oclif');
|
|
19
|
-
|
|
20
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
-
|
|
22
|
-
function _interopNamespace(e) {
|
|
23
|
-
if (e && e.__esModule) return e;
|
|
24
|
-
var n = Object.create(null);
|
|
25
|
-
if (e) {
|
|
26
|
-
Object.keys(e).forEach(function (k) {
|
|
27
|
-
if (k !== 'default') {
|
|
28
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
29
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () { return e[k]; }
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
n.default = e;
|
|
37
|
-
return Object.freeze(n);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
var path7__default = /*#__PURE__*/_interopDefault(path7);
|
|
41
|
-
var fs3__namespace = /*#__PURE__*/_interopNamespace(fs3);
|
|
42
|
-
var fsp__default = /*#__PURE__*/_interopDefault(fsp);
|
|
43
|
-
var mime__namespace = /*#__PURE__*/_interopNamespace(mime);
|
|
44
|
-
var tar__namespace = /*#__PURE__*/_interopNamespace(tar);
|
|
45
|
-
var YAML2__default = /*#__PURE__*/_interopDefault(YAML2);
|
|
46
|
-
var os__namespace = /*#__PURE__*/_interopNamespace(os);
|
|
47
|
-
var semver__default = /*#__PURE__*/_interopDefault(semver);
|
|
48
|
-
var pathPosix__default = /*#__PURE__*/_interopDefault(pathPosix);
|
|
49
|
-
|
|
50
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
51
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
52
|
-
}) : x)(function(x) {
|
|
53
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
54
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
55
|
-
});
|
|
56
|
-
function tryResolve(root, request) {
|
|
57
|
-
try {
|
|
58
|
-
return __require.resolve(request, {
|
|
59
|
-
paths: [root]
|
|
60
|
-
});
|
|
61
|
-
} catch (err) {
|
|
62
|
-
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
|
63
|
-
}
|
|
64
|
-
return void 0;
|
|
65
|
-
}
|
|
66
|
-
function ResolvedModuleFile(moduleRoot) {
|
|
67
|
-
return zod.z.string().transform((request, ctx) => {
|
|
68
|
-
const result = tryResolve(moduleRoot, request);
|
|
69
|
-
if (result === void 0) {
|
|
70
|
-
ctx.addIssue({
|
|
71
|
-
code: zod.z.ZodIssueCode.custom,
|
|
72
|
-
message: `Can't resolve ${request} against ${moduleRoot}`
|
|
73
|
-
});
|
|
74
|
-
return zod.z.NEVER;
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
type: "absolute-file",
|
|
78
|
-
file: result
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function ResolvedModuleFolder(moduleRoot, ...indexFilesToLookFor) {
|
|
83
|
-
return zod.z.string().transform((request, ctx) => {
|
|
84
|
-
const requestWithSlash = request.endsWith("/") ? request : `${request}/`;
|
|
85
|
-
for (const idxFile of indexFilesToLookFor) {
|
|
86
|
-
const result = tryResolve(moduleRoot, requestWithSlash + idxFile);
|
|
87
|
-
if (result !== void 0) {
|
|
88
|
-
if (!result.endsWith(idxFile))
|
|
89
|
-
throw new Error(`Unexpected resolve result ${result} with index file ${idxFile}`);
|
|
90
|
-
return {
|
|
91
|
-
type: "absolute-folder",
|
|
92
|
-
folder: result.slice(0, result.length - idxFile.length)
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
ctx.addIssue({
|
|
97
|
-
code: zod.z.ZodIssueCode.custom,
|
|
98
|
-
message: `Can't resolve ${request} folder against ${moduleRoot}, no index file found (${indexFilesToLookFor.join(", ")})`
|
|
99
|
-
});
|
|
100
|
-
return zod.z.NEVER;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
function mapLocalToAbsolute(root) {
|
|
104
|
-
return (value) => value.type === "relative" ? { type: "absolute-file", file: path7__default.default.resolve(root, value.path) } : value;
|
|
105
|
-
}
|
|
106
|
-
function absoluteToString() {
|
|
107
|
-
return async (value) => {
|
|
108
|
-
if (value.type === "absolute-file")
|
|
109
|
-
return await fsp__default.default.readFile(value.file, { encoding: "utf-8" });
|
|
110
|
-
else return value.content;
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
function absoluteToBase64() {
|
|
114
|
-
return async (value) => {
|
|
115
|
-
if (value.type === "absolute-file") {
|
|
116
|
-
const mimeType = mime__namespace.lookup(value.file);
|
|
117
|
-
if (!mimeType) throw new Error(`Can't recognize mime type of the file: ${value.file}.`);
|
|
118
|
-
return {
|
|
119
|
-
type: "explicit-base64",
|
|
120
|
-
mimeType,
|
|
121
|
-
content: await fsp__default.default.readFile(value.file, { encoding: "base64" })
|
|
122
|
-
};
|
|
123
|
-
} else return value;
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function cpAbsoluteToRelative(dstFolder, fileAccumulator) {
|
|
127
|
-
return async (value) => {
|
|
128
|
-
if (value.type === "absolute-file") {
|
|
129
|
-
const fileName = path7__default.default.basename(value.file);
|
|
130
|
-
const dst = path7__default.default.resolve(dstFolder, fileName);
|
|
131
|
-
fileAccumulator?.push(fileName);
|
|
132
|
-
await fsp__default.default.cp(value.file, dst);
|
|
133
|
-
return { type: "relative", path: fileName };
|
|
134
|
-
} else return value;
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
function packFolderToRelativeTgz(dstFolder, tgzName, fileAccumulator) {
|
|
138
|
-
if (!tgzName.endsWith(".tgz")) throw new Error(`Unexpected tgz file name: ${tgzName}`);
|
|
139
|
-
return async (value) => {
|
|
140
|
-
const dst = path7__default.default.resolve(dstFolder, tgzName);
|
|
141
|
-
await tar__namespace.create(
|
|
142
|
-
{
|
|
143
|
-
gzip: true,
|
|
144
|
-
file: dst,
|
|
145
|
-
cwd: value.folder
|
|
146
|
-
},
|
|
147
|
-
[value.folder]
|
|
148
|
-
);
|
|
149
|
-
fileAccumulator?.push(tgzName);
|
|
150
|
-
return { type: "relative", path: tgzName };
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function BlockComponentsDescription(moduleRoot) {
|
|
154
|
-
return plModelMiddleLayer.BlockComponents(
|
|
155
|
-
ResolvedModuleFile(moduleRoot),
|
|
156
|
-
ResolvedModuleFolder(moduleRoot, "index.html")
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
function BlockComponentsConsolidate(dstFolder, fileAccumulator) {
|
|
160
|
-
return plModelMiddleLayer.BlockComponents(
|
|
161
|
-
plModelMiddleLayer.ContentAbsoluteBinaryLocal.transform(cpAbsoluteToRelative(dstFolder, fileAccumulator)),
|
|
162
|
-
plModelMiddleLayer.ContentAbsoluteFolder.transform(packFolderToRelativeTgz(dstFolder, "ui.tgz", fileAccumulator))
|
|
163
|
-
).pipe(plModelMiddleLayer.BlockComponentsManifest);
|
|
164
|
-
}
|
|
165
|
-
function BlockPackMetaDescription(root) {
|
|
166
|
-
return plModelMiddleLayer.BlockPackMeta(
|
|
167
|
-
plModelMiddleLayer.DescriptionContentText.transform(mapLocalToAbsolute(root)),
|
|
168
|
-
plModelMiddleLayer.DescriptionContentBinary.transform(mapLocalToAbsolute(root))
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
function BlockPackMetaConsolidate(dstFolder, fileAccumulator) {
|
|
172
|
-
return plModelMiddleLayer.BlockPackMeta(
|
|
173
|
-
plModelMiddleLayer.ContentAbsoluteTextLocal.transform(cpAbsoluteToRelative(dstFolder, fileAccumulator)),
|
|
174
|
-
plModelMiddleLayer.ContentAbsoluteBinaryLocal.transform(cpAbsoluteToRelative(dstFolder, fileAccumulator))
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
var BlockPackMetaEmbed = plModelMiddleLayer.BlockPackMeta(
|
|
178
|
-
plModelMiddleLayer.ContentAbsoluteTextLocal.transform(absoluteToString()),
|
|
179
|
-
plModelMiddleLayer.ContentAbsoluteBinaryLocal.transform(absoluteToBase64())
|
|
180
|
-
).pipe(plModelMiddleLayer.BlockPackMetaEmbeddedContent);
|
|
181
|
-
|
|
182
|
-
// src/v2/model/index.ts
|
|
183
|
-
function ResolvedBlockPackDescriptionFromPackageJson(root) {
|
|
184
|
-
return plModelMiddleLayer.CreateBlockPackDescriptionSchema(
|
|
185
|
-
BlockComponentsDescription(root),
|
|
186
|
-
BlockPackMetaDescription(root)
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
function BlockPackDescriptionConsolidateToFolder(dstFolder, fileAccumulator) {
|
|
190
|
-
return plModelMiddleLayer.CreateBlockPackDescriptionSchema(
|
|
191
|
-
BlockComponentsConsolidate(dstFolder, fileAccumulator),
|
|
192
|
-
//BlockPackMetaToExplicit
|
|
193
|
-
BlockPackMetaConsolidate(dstFolder, fileAccumulator)
|
|
194
|
-
).pipe(BlockPackDescriptionManifest);
|
|
195
|
-
}
|
|
196
|
-
var BlockPackDescriptionManifest = plModelMiddleLayer.CreateBlockPackDescriptionSchema(
|
|
197
|
-
plModelMiddleLayer.BlockComponentsManifest,
|
|
198
|
-
plModelMiddleLayer.BlockPackMetaManifest
|
|
199
|
-
);
|
|
200
|
-
var BlockPackManifest = BlockPackDescriptionManifest.extend({
|
|
201
|
-
schema: zod.z.literal("v1"),
|
|
202
|
-
files: zod.z.array(zod.z.string())
|
|
203
|
-
});
|
|
204
|
-
var BlockPackManifestFile = "manifest.json";
|
|
205
|
-
async function buildBlockPackDist(description, dst) {
|
|
206
|
-
await fsp__default.default.mkdir(dst, { recursive: true });
|
|
207
|
-
const files = [];
|
|
208
|
-
const descriptionRelative = await BlockPackDescriptionConsolidateToFolder(dst, files).parseAsync(
|
|
209
|
-
description
|
|
210
|
-
);
|
|
211
|
-
const manifest = BlockPackManifest.parse({
|
|
212
|
-
schema: "v1",
|
|
213
|
-
...descriptionRelative,
|
|
214
|
-
files
|
|
215
|
-
});
|
|
216
|
-
await fsp__default.default.writeFile(path7__default.default.resolve(dst, BlockPackManifestFile), JSON.stringify(manifest));
|
|
217
|
-
return manifest;
|
|
218
|
-
}
|
|
219
|
-
async function tryLoadFile(file, map) {
|
|
220
|
-
try {
|
|
221
|
-
return map(await fsp__default.default.readFile(file));
|
|
222
|
-
} catch (err) {
|
|
223
|
-
if (err.code == "ENOENT") return void 0;
|
|
224
|
-
else throw new Error("", { cause: err });
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
var BlockDescriptionPackageJsonField = "block";
|
|
228
|
-
var ConventionPackageNamePattern = /(?:@[a-zA-Z0-9-.]+\/)?(?<organization>[a-zA-Z0-9-]+)\.(?<name>[a-zA-Z0-9-]+)/;
|
|
229
|
-
function parsePackageName(packageName) {
|
|
230
|
-
const match = packageName.match(ConventionPackageNamePattern);
|
|
231
|
-
if (!match)
|
|
232
|
-
throw new Error(
|
|
233
|
-
`Malformed package name (${packageName}), can't infer organization and block pack name.`
|
|
234
|
-
);
|
|
235
|
-
const { name, organization } = match.groups;
|
|
236
|
-
return { name, organization };
|
|
237
|
-
}
|
|
238
|
-
async function loadPackDescriptionRaw(moduleRoot) {
|
|
239
|
-
const fullPackageJsonPath = path7__default.default.resolve(moduleRoot, "package.json");
|
|
240
|
-
const packageJson = JSON.parse(await fsp__default.default.readFile(fullPackageJsonPath, { encoding: "utf-8" }));
|
|
241
|
-
const descriptionNotParsed = packageJson[BlockDescriptionPackageJsonField];
|
|
242
|
-
if (descriptionNotParsed === void 0)
|
|
243
|
-
throw new Error(
|
|
244
|
-
`Block description (field ${BlockDescriptionPackageJsonField}) not found in ${fullPackageJsonPath}.`
|
|
245
|
-
);
|
|
246
|
-
return {
|
|
247
|
-
...plModelMiddleLayer.BlockPackDescriptionFromPackageJsonRaw.parse(descriptionNotParsed),
|
|
248
|
-
id: {
|
|
249
|
-
...parsePackageName(
|
|
250
|
-
tsHelpers.notEmpty(packageJson["name"], `"name" not found in ${fullPackageJsonPath}`)
|
|
251
|
-
),
|
|
252
|
-
version: plModelMiddleLayer.SemVer.parse(packageJson["version"])
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
async function loadPackDescription(moduleRoot) {
|
|
257
|
-
const descriptionRaw = await loadPackDescriptionRaw(moduleRoot);
|
|
258
|
-
return await ResolvedBlockPackDescriptionFromPackageJson(moduleRoot).parseAsync(descriptionRaw);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// src/cmd/build-meta.ts
|
|
262
|
-
var BuildMeta = class _BuildMeta extends core.Command {
|
|
263
|
-
static description = "Extracts meta information from blocks package.json and outputs meta.json with embedded binary and textual information linked from the meta section.";
|
|
264
|
-
static flags = {
|
|
265
|
-
modulePath: core.Flags.string({
|
|
266
|
-
char: "i",
|
|
267
|
-
summary: "input module path",
|
|
268
|
-
helpValue: "<path>",
|
|
269
|
-
default: "."
|
|
270
|
-
}),
|
|
271
|
-
destination: core.Flags.string({
|
|
272
|
-
char: "o",
|
|
273
|
-
summary: "output meta.json file",
|
|
274
|
-
helpValue: "<path>",
|
|
275
|
-
required: true
|
|
276
|
-
})
|
|
277
|
-
};
|
|
278
|
-
async run() {
|
|
279
|
-
const { flags } = await this.parse(_BuildMeta);
|
|
280
|
-
const modulePath = path7__default.default.resolve(flags.modulePath);
|
|
281
|
-
const descriptionRaw = await loadPackDescriptionRaw(modulePath);
|
|
282
|
-
const metaEmbedded = await BlockPackMetaEmbed.parseAsync(
|
|
283
|
-
BlockPackMetaDescription(modulePath).parse(descriptionRaw.meta)
|
|
284
|
-
);
|
|
285
|
-
await fs3__namespace.default.promises.writeFile(path7__default.default.resolve(flags.destination), JSON.stringify(metaEmbedded));
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
async function getFileContent(path9) {
|
|
289
|
-
try {
|
|
290
|
-
return await fs3__namespace.default.promises.readFile(path9, "utf8");
|
|
291
|
-
} catch (error) {
|
|
292
|
-
if (error.code === "ENOENT") {
|
|
293
|
-
return void 0;
|
|
294
|
-
}
|
|
295
|
-
throw error;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
var BuildModel = class _BuildModel extends core.Command {
|
|
299
|
-
static description = "Extracts and outputs block model JSON from pre-built block model module";
|
|
300
|
-
static flags = {
|
|
301
|
-
modulePath: core.Flags.string({
|
|
302
|
-
char: "i",
|
|
303
|
-
summary: "input module path",
|
|
304
|
-
helpValue: "<path>",
|
|
305
|
-
default: "."
|
|
306
|
-
}),
|
|
307
|
-
sourceBundle: core.Flags.string({
|
|
308
|
-
char: "b",
|
|
309
|
-
summary: "bundled model code to embed into the model for callback-based rendering to work",
|
|
310
|
-
helpValue: "<path>",
|
|
311
|
-
default: "./dist/bundle.js"
|
|
312
|
-
}),
|
|
313
|
-
destination: core.Flags.string({
|
|
314
|
-
char: "o",
|
|
315
|
-
summary: "output model file",
|
|
316
|
-
helpValue: "<path>",
|
|
317
|
-
default: "./dist/model.json"
|
|
318
|
-
})
|
|
319
|
-
};
|
|
320
|
-
async run() {
|
|
321
|
-
const { flags } = await this.parse(_BuildModel);
|
|
322
|
-
const modulePath = path7__default.default.resolve(flags.modulePath);
|
|
323
|
-
let { model, platforma } = __require(modulePath);
|
|
324
|
-
if (!model) model = platforma;
|
|
325
|
-
if (!model) throw new Error('"model" export not found');
|
|
326
|
-
const { config } = model;
|
|
327
|
-
if (!config)
|
|
328
|
-
throw new Error(
|
|
329
|
-
'Malformed "model" object, check it is created with "BlockModel" and ".done()" is executed as the call in the chain.'
|
|
330
|
-
);
|
|
331
|
-
if (!("canRun" in config || "inputsValid" in config) || !("outputs" in config) || !("sections" in config))
|
|
332
|
-
throw new Error('"config" has unexpected structure');
|
|
333
|
-
const code = await getFileContent(flags.sourceBundle);
|
|
334
|
-
if (code !== void 0) {
|
|
335
|
-
config.code = {
|
|
336
|
-
type: "plain",
|
|
337
|
-
content: code
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
await fs3__namespace.default.promises.writeFile(path7__default.default.resolve(flags.destination), JSON.stringify(config));
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
var PackBlock = class _PackBlock extends core.Command {
|
|
344
|
-
static description = "Builds block pack and outputs a block pack manifest consolidating all references assets into a single folder";
|
|
345
|
-
static flags = {
|
|
346
|
-
modulePath: core.Flags.string({
|
|
347
|
-
char: "i",
|
|
348
|
-
summary: "input module path",
|
|
349
|
-
helpValue: "<path>",
|
|
350
|
-
default: "."
|
|
351
|
-
}),
|
|
352
|
-
destinationPath: core.Flags.string({
|
|
353
|
-
char: "o",
|
|
354
|
-
summary: "output folder",
|
|
355
|
-
helpValue: "<path>",
|
|
356
|
-
default: "./block-pack"
|
|
357
|
-
})
|
|
358
|
-
};
|
|
359
|
-
async run() {
|
|
360
|
-
const { flags } = await this.parse(_PackBlock);
|
|
361
|
-
const description = await loadPackDescription(path7__default.default.resolve(flags.modulePath));
|
|
362
|
-
await buildBlockPackDist(description, path7__default.default.resolve(flags.destinationPath));
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
var PlRegAddress = zod.z.string().regex(/^(?:s3:|file:)/);
|
|
366
|
-
var PlPackageConfigData = zod.z.object({
|
|
367
|
-
organization: zod.z.string(),
|
|
368
|
-
package: zod.z.string(),
|
|
369
|
-
version: plModelMiddleLayer.SemVer.optional(),
|
|
370
|
-
files: zod.z.record(zod.z.string().regex(/^[^\/]+$/), zod.z.string()).default({}),
|
|
371
|
-
meta: zod.z.object({}).passthrough()
|
|
372
|
-
});
|
|
373
|
-
var PlRegCommonConfigData = zod.z.object({
|
|
374
|
-
registries: zod.z.record(zod.z.string(), PlRegAddress).default({}),
|
|
375
|
-
registry: zod.z.string().optional()
|
|
376
|
-
});
|
|
377
|
-
var PlRegFullPackageConfigData = PlRegCommonConfigData.merge(PlPackageConfigData).required(
|
|
378
|
-
{ registry: true, version: true }
|
|
379
|
-
);
|
|
380
|
-
var PlRegPackageConfigDataShard = PlRegFullPackageConfigData.partial().required({
|
|
381
|
-
registries: true,
|
|
382
|
-
files: true
|
|
383
|
-
});
|
|
384
|
-
var PlPackageJsonConfigFile = "pl.package.json";
|
|
385
|
-
var PlPackageYamlConfigFile = "pl.package.yaml";
|
|
386
|
-
|
|
387
|
-
// src/registry_v1/v1_repo_schema.ts
|
|
388
|
-
var MainPrefix = "v1/";
|
|
389
|
-
function payloadFilePath(bp, file) {
|
|
390
|
-
return `${MainPrefix}${bp.organization}/${bp.package}/${bp.version}/${file}`;
|
|
391
|
-
}
|
|
392
|
-
function packageOverviewPath(bp) {
|
|
393
|
-
return `${MainPrefix}${bp.organization}/${bp.package}/overview.json`;
|
|
394
|
-
}
|
|
395
|
-
var GlobalOverviewPath = `${MainPrefix}overview.json`;
|
|
396
|
-
var MetaFile = "meta.json";
|
|
397
|
-
|
|
398
|
-
// src/registry_v1/registry.ts
|
|
399
|
-
var VersionUpdatesPrefix = "_updates_v1/per_package_version/";
|
|
400
|
-
function packageUpdatePath(bp, seed) {
|
|
401
|
-
return `${VersionUpdatesPrefix}${bp.organization}/${bp.package}/${bp.version}/${seed}`;
|
|
402
|
-
}
|
|
403
|
-
var PackageUpdatePattern = /(?<packageKeyWithoutVersion>(?<organization>[^\/]+)\/(?<pkg>[^\/]+))\/(?<version>[^\/]+)\/(?<seed>[^\/]+)$/;
|
|
404
|
-
var GlobalUpdateSeedInFile = "_updates_v1/_global_update_in";
|
|
405
|
-
var GlobalUpdateSeedOutFile = "_updates_v1/_global_update_out";
|
|
406
|
-
var BlockRegistry = class {
|
|
407
|
-
constructor(storage, logger) {
|
|
408
|
-
this.storage = storage;
|
|
409
|
-
this.logger = logger;
|
|
410
|
-
}
|
|
411
|
-
constructNewPackage(pack) {
|
|
412
|
-
return new BlockRegistryPackConstructor(this.storage, pack);
|
|
413
|
-
}
|
|
414
|
-
async updateRegistry() {
|
|
415
|
-
this.logger?.info("Initiating registry refresh...");
|
|
416
|
-
const packagesToUpdate = /* @__PURE__ */ new Map();
|
|
417
|
-
const seedPaths = [];
|
|
418
|
-
const rawSeedPaths = await this.storage.listFiles(VersionUpdatesPrefix);
|
|
419
|
-
this.logger?.info("Packages to be updated:");
|
|
420
|
-
for (const seedPath of rawSeedPaths) {
|
|
421
|
-
const match = seedPath.match(PackageUpdatePattern);
|
|
422
|
-
if (!match) continue;
|
|
423
|
-
seedPaths.push(seedPath);
|
|
424
|
-
const { packageKeyWithoutVersion, organization, pkg, version, seed } = match.groups;
|
|
425
|
-
let update = packagesToUpdate.get(packageKeyWithoutVersion);
|
|
426
|
-
if (!update) {
|
|
427
|
-
packagesToUpdate.set(packageKeyWithoutVersion, {
|
|
428
|
-
package: { organization, package: pkg },
|
|
429
|
-
versions: /* @__PURE__ */ new Set([version])
|
|
430
|
-
});
|
|
431
|
-
} else if (!update.versions.has(version)) {
|
|
432
|
-
update.versions.add(version);
|
|
433
|
-
}
|
|
434
|
-
this.logger?.info(` - ${organization}:${pkg}:${version}`);
|
|
435
|
-
}
|
|
436
|
-
const overviewContent = await this.storage.getFile(GlobalOverviewPath);
|
|
437
|
-
let overview = overviewContent === void 0 ? [] : JSON.parse(overviewContent.toString());
|
|
438
|
-
this.logger?.info(`Global overview loaded, ${overview.length} records`);
|
|
439
|
-
for (const [, packageInfo] of packagesToUpdate.entries()) {
|
|
440
|
-
const overviewFile = packageOverviewPath(packageInfo.package);
|
|
441
|
-
const pOverviewContent = await this.storage.getFile(overviewFile);
|
|
442
|
-
let packageOverview = pOverviewContent === void 0 ? [] : JSON.parse(pOverviewContent.toString());
|
|
443
|
-
this.logger?.info(
|
|
444
|
-
`Updating ${packageInfo.package.organization}:${packageInfo.package.package} overview, ${packageOverview.length} records`
|
|
445
|
-
);
|
|
446
|
-
packageOverview = packageOverview.filter((e) => !packageInfo.versions.has(e.version));
|
|
447
|
-
for (const [v] of packageInfo.versions.entries()) {
|
|
448
|
-
const version = v.toString();
|
|
449
|
-
const metaContent = await this.storage.getFile(
|
|
450
|
-
payloadFilePath(
|
|
451
|
-
{
|
|
452
|
-
...packageInfo.package,
|
|
453
|
-
version
|
|
454
|
-
},
|
|
455
|
-
MetaFile
|
|
456
|
-
)
|
|
457
|
-
);
|
|
458
|
-
if (!metaContent) continue;
|
|
459
|
-
packageOverview.push({ version, meta: JSON.parse(metaContent.toString()) });
|
|
460
|
-
}
|
|
461
|
-
packageOverview.sort((e1, e2) => semver__default.default.compare(e2.version, e1.version));
|
|
462
|
-
await this.storage.putFile(overviewFile, Buffer.from(JSON.stringify(packageOverview)));
|
|
463
|
-
this.logger?.info(`Done (${packageOverview.length} records)`);
|
|
464
|
-
overview = overview.filter(
|
|
465
|
-
(e) => e.organization !== packageInfo.package.organization || e.package !== packageInfo.package.package
|
|
466
|
-
);
|
|
467
|
-
overview.push({
|
|
468
|
-
organization: packageInfo.package.organization,
|
|
469
|
-
package: packageInfo.package.package,
|
|
470
|
-
allVersions: packageOverview.map((e) => e.version).reverse(),
|
|
471
|
-
latestVersion: packageOverview[0].version,
|
|
472
|
-
latestMeta: packageOverview[0].meta
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
await this.storage.putFile(GlobalOverviewPath, Buffer.from(JSON.stringify(overview)));
|
|
476
|
-
this.logger?.info(`Global overview updated (${overview.length} records)`);
|
|
477
|
-
await this.storage.deleteFiles(...seedPaths.map((sp) => `${VersionUpdatesPrefix}${sp}`));
|
|
478
|
-
this.logger?.info(`Version update requests cleared`);
|
|
479
|
-
}
|
|
480
|
-
async updateIfNeeded(force = false) {
|
|
481
|
-
this.logger?.info(`Checking if registry requires refresh...`);
|
|
482
|
-
const updateRequestSeed = await this.storage.getFile(GlobalUpdateSeedInFile);
|
|
483
|
-
const currentUpdatedSeed = await this.storage.getFile(GlobalUpdateSeedOutFile);
|
|
484
|
-
if (!force && updateRequestSeed === void 0 && currentUpdatedSeed === void 0) return;
|
|
485
|
-
if (!force && updateRequestSeed !== void 0 && currentUpdatedSeed !== void 0 && updateRequestSeed.equals(currentUpdatedSeed))
|
|
486
|
-
return;
|
|
487
|
-
await this.updateRegistry();
|
|
488
|
-
if (updateRequestSeed) {
|
|
489
|
-
await this.storage.putFile(GlobalUpdateSeedOutFile, updateRequestSeed);
|
|
490
|
-
this.logger?.info(`Refresh finished`);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
async getPackageOverview(name) {
|
|
494
|
-
const content = await this.storage.getFile(packageOverviewPath(name));
|
|
495
|
-
if (content === void 0) return void 0;
|
|
496
|
-
return JSON.parse(content.toString());
|
|
497
|
-
}
|
|
498
|
-
async getGlobalOverview() {
|
|
499
|
-
const content = await this.storage.getFile(GlobalOverviewPath);
|
|
500
|
-
if (content === void 0) return void 0;
|
|
501
|
-
return JSON.parse(content.toString());
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
var BlockRegistryPackConstructor = class {
|
|
505
|
-
constructor(storage, name) {
|
|
506
|
-
this.storage = storage;
|
|
507
|
-
this.name = name;
|
|
508
|
-
}
|
|
509
|
-
metaAdded = false;
|
|
510
|
-
seed = crypto.randomUUID();
|
|
511
|
-
async addFile(file, content) {
|
|
512
|
-
await this.storage.putFile(payloadFilePath(this.name, file), content);
|
|
513
|
-
}
|
|
514
|
-
async writeMeta(meta) {
|
|
515
|
-
await this.addFile(MetaFile, Buffer.from(JSON.stringify(meta)));
|
|
516
|
-
this.metaAdded = true;
|
|
517
|
-
}
|
|
518
|
-
async finish() {
|
|
519
|
-
if (!this.metaAdded) throw new Error("meta not added");
|
|
520
|
-
await this.storage.putFile(packageUpdatePath(this.name, this.seed), Buffer.of(0));
|
|
521
|
-
await this.storage.putFile(GlobalUpdateSeedInFile, Buffer.from(this.seed));
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
var S3Storage = class {
|
|
525
|
-
constructor(client, bucket, root) {
|
|
526
|
-
this.client = client;
|
|
527
|
-
this.bucket = bucket;
|
|
528
|
-
this.root = root;
|
|
529
|
-
}
|
|
530
|
-
async getFile(file) {
|
|
531
|
-
try {
|
|
532
|
-
return Buffer.from(
|
|
533
|
-
await (await this.client.getObject({
|
|
534
|
-
Bucket: this.bucket,
|
|
535
|
-
Key: pathPosix__default.default.join(this.root, file)
|
|
536
|
-
})).Body.transformToByteArray()
|
|
537
|
-
);
|
|
538
|
-
} catch (e) {
|
|
539
|
-
if (e.name === "NoSuchKey") return void 0;
|
|
540
|
-
else throw e;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
async listFiles(prefix) {
|
|
544
|
-
const listRoot = pathPosix__default.default.join(this.root, prefix);
|
|
545
|
-
const paginator = clientS3.paginateListObjectsV2(
|
|
546
|
-
{ client: this.client },
|
|
547
|
-
{
|
|
548
|
-
Bucket: this.bucket,
|
|
549
|
-
Prefix: listRoot
|
|
550
|
-
}
|
|
551
|
-
);
|
|
552
|
-
const result = [];
|
|
553
|
-
for await (const page of paginator)
|
|
554
|
-
result.push(...page.Contents.map((e) => pathPosix__default.default.relative(listRoot, e.Key)));
|
|
555
|
-
return result;
|
|
556
|
-
}
|
|
557
|
-
async putFile(file, buffer) {
|
|
558
|
-
await this.client.putObject({
|
|
559
|
-
Bucket: this.bucket,
|
|
560
|
-
Key: pathPosix__default.default.join(this.root, file),
|
|
561
|
-
Body: buffer
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
async deleteFiles(...files) {
|
|
565
|
-
const results = await this.client.deleteObjects({
|
|
566
|
-
Bucket: this.bucket,
|
|
567
|
-
Delete: {
|
|
568
|
-
Objects: files.map((file) => ({
|
|
569
|
-
Key: pathPosix__default.default.join(this.root, file)
|
|
570
|
-
}))
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
if (results.Errors !== void 0 && results.Errors.length > 0)
|
|
574
|
-
throw new Error(`Errors encountered while deleting files: ${results.Errors.join("\n")}`);
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
var FSStorage = class {
|
|
578
|
-
/** Absolute path */
|
|
579
|
-
root;
|
|
580
|
-
constructor(_root) {
|
|
581
|
-
this.root = path7__default.default.resolve(_root);
|
|
582
|
-
}
|
|
583
|
-
toAbsolutePath(localPath) {
|
|
584
|
-
if (pathPosix__default.default.isAbsolute(localPath)) throw new Error("absolute path");
|
|
585
|
-
return path7__default.default.resolve(this.root, localPath.split(pathPosix__default.default.sep).join(path7__default.default.sep));
|
|
586
|
-
}
|
|
587
|
-
async getFile(address) {
|
|
588
|
-
try {
|
|
589
|
-
return await fs3__namespace.promises.readFile(this.toAbsolutePath(address));
|
|
590
|
-
} catch (err) {
|
|
591
|
-
if (err.code == "ENOENT") return void 0;
|
|
592
|
-
else throw new Error("", { cause: err });
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
async listFiles(prefix) {
|
|
596
|
-
try {
|
|
597
|
-
const listRoot = this.toAbsolutePath(prefix);
|
|
598
|
-
return (await fs3__namespace.promises.readdir(listRoot, { recursive: true, withFileTypes: true })).filter((e) => e.isFile()).map(
|
|
599
|
-
(e) => path7__default.default.relative(listRoot, path7__default.default.resolve(e.path, e.name)).split(path7__default.default.sep).join(pathPosix__default.default.sep)
|
|
600
|
-
);
|
|
601
|
-
} catch (err) {
|
|
602
|
-
if (err.code == "ENOENT") return [];
|
|
603
|
-
else throw new Error("", { cause: err });
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
async putFile(address, buffer) {
|
|
607
|
-
const absoluteAddress = this.toAbsolutePath(address);
|
|
608
|
-
await fs3__namespace.promises.mkdir(path7__default.default.dirname(absoluteAddress), { recursive: true });
|
|
609
|
-
await fs3__namespace.promises.writeFile(absoluteAddress, buffer);
|
|
610
|
-
}
|
|
611
|
-
async deleteFiles(...files) {
|
|
612
|
-
for (const file of files) await fs3__namespace.promises.rm(this.toAbsolutePath(file));
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
function storageByUrl(address) {
|
|
616
|
-
const url = new URL(address, `file:${path7__default.default.resolve(".").split(path7__default.default.sep).join(pathPosix__default.default.sep)}/`);
|
|
617
|
-
switch (url.protocol) {
|
|
618
|
-
case "file:":
|
|
619
|
-
const root = path7__default.default.resolve(url.pathname);
|
|
620
|
-
return new FSStorage(root);
|
|
621
|
-
case "s3:":
|
|
622
|
-
const options = {};
|
|
623
|
-
const region = url.searchParams.get("region");
|
|
624
|
-
if (region) options.region = region;
|
|
625
|
-
const bucket = url.hostname;
|
|
626
|
-
return new S3Storage(new clientS3.S3(options), bucket, url.pathname.replace(/^\//, ""));
|
|
627
|
-
default:
|
|
628
|
-
throw new Error(`Unknown protocol: ${url.protocol}`);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// src/registry_v1/config.ts
|
|
633
|
-
function mergeConfigs(c1, c2) {
|
|
634
|
-
if (c2 === void 0) return c1;
|
|
635
|
-
return {
|
|
636
|
-
...c1,
|
|
637
|
-
...c2,
|
|
638
|
-
registries: { ...c1.registries, ...c2.registries },
|
|
639
|
-
files: { ...c1.files, ...c2.files }
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
async function tryLoadJsonConfigFromFile(file) {
|
|
643
|
-
return tryLoadFile(file, (buf) => PlRegPackageConfigDataShard.parse(JSON.parse(buf.toString())));
|
|
644
|
-
}
|
|
645
|
-
async function tryLoadYamlConfigFromFile(file) {
|
|
646
|
-
return tryLoadFile(file, (buf) => PlRegPackageConfigDataShard.parse(YAML2__default.default.parse(buf.toString())));
|
|
647
|
-
}
|
|
648
|
-
async function loadConfigShard() {
|
|
649
|
-
let conf = PlRegPackageConfigDataShard.parse({});
|
|
650
|
-
conf = mergeConfigs(conf, await tryLoadJsonConfigFromFile("./.pl.reg.json"));
|
|
651
|
-
conf = mergeConfigs(conf, await tryLoadYamlConfigFromFile("./.pl.reg.yaml"));
|
|
652
|
-
conf = mergeConfigs(conf, await tryLoadJsonConfigFromFile(`${os__namespace.homedir()}/.pl.reg.json`));
|
|
653
|
-
conf = mergeConfigs(conf, await tryLoadYamlConfigFromFile(`${os__namespace.homedir()}/.pl.reg.yaml`));
|
|
654
|
-
conf = mergeConfigs(conf, await tryLoadJsonConfigFromFile(PlPackageJsonConfigFile));
|
|
655
|
-
conf = mergeConfigs(conf, await tryLoadYamlConfigFromFile(PlPackageYamlConfigFile));
|
|
656
|
-
return conf;
|
|
657
|
-
}
|
|
658
|
-
var PlRegPackageConfig = class {
|
|
659
|
-
constructor(conf) {
|
|
660
|
-
this.conf = conf;
|
|
661
|
-
}
|
|
662
|
-
createRegistry(logger) {
|
|
663
|
-
let address = this.conf.registry;
|
|
664
|
-
if (!address.startsWith("file:") && !address.startsWith("s3:")) {
|
|
665
|
-
const regByAlias = this.conf.registries[address];
|
|
666
|
-
if (!regByAlias) throw new Error(`Registry with alias "${address}" not found`);
|
|
667
|
-
address = regByAlias;
|
|
668
|
-
}
|
|
669
|
-
return new BlockRegistry(storageByUrl(address), logger);
|
|
670
|
-
}
|
|
671
|
-
get fullPackageName() {
|
|
672
|
-
return {
|
|
673
|
-
organization: this.conf.organization,
|
|
674
|
-
package: this.conf.package,
|
|
675
|
-
version: this.conf.version
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
};
|
|
679
|
-
async function getConfig(finalShard) {
|
|
680
|
-
const confShard = await loadConfigShard();
|
|
681
|
-
return new PlRegPackageConfig(
|
|
682
|
-
PlRegFullPackageConfigData.parse(mergeConfigs(confShard, finalShard))
|
|
683
|
-
);
|
|
684
|
-
}
|
|
685
|
-
function parseTargetFile(arg) {
|
|
686
|
-
const match = arg.match(/(?<destName>[^\/\\]+)=(?<src>.*)/);
|
|
687
|
-
if (match) {
|
|
688
|
-
const { src, destName } = match.groups;
|
|
689
|
-
return { src, destName };
|
|
690
|
-
} else {
|
|
691
|
-
return { src: arg, destName: path7__default.default.basename(arg) };
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
var targetFile = core.Flags.custom({
|
|
695
|
-
summary: "target files to upload",
|
|
696
|
-
helpValue: "file_path | package_name=file_path",
|
|
697
|
-
parse: async (arg) => parseTargetFile(arg)
|
|
698
|
-
});
|
|
699
|
-
var BasicConfigFields = ["registry", "organization", "package", "version"];
|
|
700
|
-
var UploadPackageV1 = class _UploadPackageV1 extends core.Command {
|
|
701
|
-
static description = "Uploads V1 package and refreshes the registry";
|
|
702
|
-
static flags = {
|
|
703
|
-
registry: core.Flags.string({
|
|
704
|
-
char: "r",
|
|
705
|
-
summary: "full address of the registry or alias from .pl.reg",
|
|
706
|
-
helpValue: "<address|alias>",
|
|
707
|
-
env: "PL_REGISTRY"
|
|
708
|
-
}),
|
|
709
|
-
organization: core.Flags.string({
|
|
710
|
-
char: "o",
|
|
711
|
-
summary: "target organisation",
|
|
712
|
-
env: "PL_PACKAGE_ORGANIZATION"
|
|
713
|
-
}),
|
|
714
|
-
package: core.Flags.string({
|
|
715
|
-
char: "p",
|
|
716
|
-
summary: "target package",
|
|
717
|
-
env: "PL_PACKAGE_NAME"
|
|
718
|
-
}),
|
|
719
|
-
version: core.Flags.string({
|
|
720
|
-
char: "v",
|
|
721
|
-
summary: "target version",
|
|
722
|
-
env: "PL_PACKAGE_VERSION"
|
|
723
|
-
}),
|
|
724
|
-
meta: core.Flags.file({
|
|
725
|
-
char: "m",
|
|
726
|
-
summary: "json file containing meta information to associate with tha package",
|
|
727
|
-
exists: true
|
|
728
|
-
}),
|
|
729
|
-
file: targetFile({
|
|
730
|
-
char: "f",
|
|
731
|
-
summary: "package files",
|
|
732
|
-
multiple: true,
|
|
733
|
-
default: []
|
|
734
|
-
}),
|
|
735
|
-
refresh: core.Flags.boolean({
|
|
736
|
-
summary: "refresh repository after adding the package",
|
|
737
|
-
default: true,
|
|
738
|
-
allowNo: true,
|
|
739
|
-
env: "PL_REGISTRY_REFRESH"
|
|
740
|
-
})
|
|
741
|
-
};
|
|
742
|
-
async run() {
|
|
743
|
-
const { flags } = await this.parse(_UploadPackageV1);
|
|
744
|
-
const configFromFlags = PlRegPackageConfigDataShard.parse({});
|
|
745
|
-
for (const field of BasicConfigFields) if (flags[field]) configFromFlags[field] = flags[field];
|
|
746
|
-
if (flags.meta) {
|
|
747
|
-
if (flags.meta.endsWith(".json"))
|
|
748
|
-
configFromFlags.meta = JSON.parse(
|
|
749
|
-
await fs3__namespace.default.promises.readFile(flags.meta, { encoding: "utf-8" })
|
|
750
|
-
);
|
|
751
|
-
else if (flags.meta.endsWith(".yaml"))
|
|
752
|
-
configFromFlags.meta = YAML2__default.default.parse(
|
|
753
|
-
await fs3__namespace.default.promises.readFile(flags.meta, { encoding: "utf-8" })
|
|
754
|
-
);
|
|
755
|
-
}
|
|
756
|
-
for (const targetFile2 of flags.file) {
|
|
757
|
-
configFromFlags.files[targetFile2.destName] = targetFile2.src;
|
|
758
|
-
}
|
|
759
|
-
const conf = await getConfig(configFromFlags);
|
|
760
|
-
this.log(YAML2__default.default.stringify(conf.conf));
|
|
761
|
-
const registry = conf.createRegistry(new tsHelpersOclif.OclifLoggerAdapter(this));
|
|
762
|
-
const name = conf.fullPackageName;
|
|
763
|
-
const builder = registry.constructNewPackage(name);
|
|
764
|
-
for (const [dst, src] of Object.entries(conf.conf.files)) {
|
|
765
|
-
this.log(`Uploading ${src} -> ${dst} ...`);
|
|
766
|
-
const content = await fs3__namespace.default.promises.readFile(src);
|
|
767
|
-
await builder.addFile(dst, content);
|
|
768
|
-
}
|
|
769
|
-
this.log(`Uploading meta information...`);
|
|
770
|
-
await builder.writeMeta(conf.conf.meta);
|
|
771
|
-
await builder.finish();
|
|
772
|
-
if (flags.refresh) await registry.updateIfNeeded();
|
|
773
|
-
}
|
|
774
|
-
};
|
|
775
|
-
|
|
776
|
-
// src/cmd/index.ts
|
|
777
|
-
var COMMANDS = {
|
|
778
|
-
"upload-package-v1": UploadPackageV1,
|
|
779
|
-
"pack": PackBlock,
|
|
780
|
-
"build-model": BuildModel,
|
|
781
|
-
"build-meta": BuildMeta
|
|
782
|
-
};
|
|
783
|
-
|
|
784
|
-
exports.COMMANDS = COMMANDS;
|
|
785
|
-
//# sourceMappingURL=cli.cjs.map
|
|
786
|
-
//# sourceMappingURL=cli.cjs.map
|