@embeddable.com/sdk-core 3.1.3 → 3.1.5
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/bin/embeddable +15 -3
- package/configs/tsconfig.json +4 -11
- package/lib/index.esm.js +83 -9
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +84 -9
- package/lib/index.js.map +1 -1
- package/lib/push.d.ts +5 -0
- package/lib/utils.d.ts +7 -0
- package/loader/custom-esm-loader.mjs +33 -5
- package/package.json +1 -1
- package/src/entryPoint.js +12 -0
- package/src/generate.ts +3 -0
- package/src/login.ts +1 -3
- package/src/provideConfig.ts +4 -1
- package/src/push.ts +97 -12
- package/src/utils.ts +22 -0
- package/lib/entryPoint.d.ts +0 -1
- package/src/entryPoint.ts +0 -16
package/bin/embeddable
CHANGED
|
@@ -1,26 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
const { pathToFileURL } = require("url");
|
|
5
|
+
|
|
4
6
|
const { spawn } = require("child_process");
|
|
5
7
|
const path = require("path");
|
|
6
8
|
|
|
7
9
|
// Check if the loader is already applied to avoid infinite spawning
|
|
8
10
|
if (!process.env.LOADER_APPLIED) {
|
|
9
11
|
const env = { ...process.env, LOADER_APPLIED: "1" };
|
|
10
|
-
const entryPointPath = path.join(__dirname, "../src/entryPoint.
|
|
12
|
+
const entryPointPath = path.join(__dirname, "../src/entryPoint.js");
|
|
11
13
|
const customLoaderPath = path.join(
|
|
12
14
|
__dirname,
|
|
13
15
|
"../loader/custom-esm-loader.mjs",
|
|
14
16
|
);
|
|
15
17
|
|
|
18
|
+
const isWindows = process.platform === "win32";
|
|
19
|
+
|
|
20
|
+
const entryPointPathOrUrl = isWindows
|
|
21
|
+
? pathToFileURL(entryPointPath).href
|
|
22
|
+
: entryPointPath;
|
|
23
|
+
|
|
24
|
+
const customLoaderPathOrUrl = isWindows
|
|
25
|
+
? pathToFileURL(customLoaderPath).href
|
|
26
|
+
: customLoaderPath;
|
|
27
|
+
|
|
16
28
|
const child = spawn(
|
|
17
29
|
process.execPath,
|
|
18
30
|
[
|
|
19
31
|
"--loader",
|
|
20
|
-
|
|
32
|
+
customLoaderPathOrUrl,
|
|
21
33
|
"--no-warnings=ExperimentalWarning",
|
|
22
34
|
"--enable-source-maps",
|
|
23
|
-
|
|
35
|
+
entryPointPathOrUrl,
|
|
24
36
|
...process.argv.slice(2),
|
|
25
37
|
],
|
|
26
38
|
{ stdio: ["inherit", "pipe", "inherit"], env },
|
package/configs/tsconfig.json
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
"allowUnreachableCode": false,
|
|
5
5
|
"declaration": false,
|
|
6
6
|
"experimentalDecorators": true,
|
|
7
|
-
"lib": [
|
|
8
|
-
"dom",
|
|
9
|
-
"es2017"
|
|
10
|
-
],
|
|
7
|
+
"lib": ["dom", "es2017"],
|
|
11
8
|
"moduleResolution": "node",
|
|
12
9
|
"module": "esnext",
|
|
13
10
|
"target": "es2017",
|
|
@@ -16,10 +13,6 @@
|
|
|
16
13
|
"jsx": "react",
|
|
17
14
|
"jsxFactory": "h"
|
|
18
15
|
},
|
|
19
|
-
"include": [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"exclude": [
|
|
23
|
-
"node_modules"
|
|
24
|
-
]
|
|
25
|
-
}
|
|
16
|
+
"include": ["component"],
|
|
17
|
+
"exclude": ["node_modules"]
|
|
18
|
+
}
|
package/lib/index.esm.js
CHANGED
|
@@ -8,6 +8,7 @@ import * as fs$2 from 'node:fs';
|
|
|
8
8
|
import { createNodeLogger, createNodeSys } from '@stencil/core/sys/node';
|
|
9
9
|
import { loadConfig, createCompiler } from '@stencil/core/compiler';
|
|
10
10
|
import * as YAML from 'yaml';
|
|
11
|
+
import * as url$2 from 'node:url';
|
|
11
12
|
import * as path$2 from 'path';
|
|
12
13
|
import path__default, { basename } from 'path';
|
|
13
14
|
import require$$4$1 from 'util';
|
|
@@ -420,12 +421,14 @@ async function runStencil(ctx) {
|
|
|
420
421
|
const logger = ((_a = ctx.dev) === null || _a === void 0 ? void 0 : _a.logger) || createNodeLogger({ process });
|
|
421
422
|
const sys = ((_b = ctx.dev) === null || _b === void 0 ? void 0 : _b.sys) || createNodeSys({ process });
|
|
422
423
|
const devMode = !!ctx.dev;
|
|
424
|
+
const isWindows = process.platform === "win32";
|
|
423
425
|
const validated = await loadConfig({
|
|
424
426
|
initTsConfig: true,
|
|
425
427
|
logger,
|
|
426
428
|
sys,
|
|
427
429
|
config: {
|
|
428
430
|
devMode,
|
|
431
|
+
maxConcurrentWorkers: isWindows ? 0 : 8, // workers break on windows
|
|
429
432
|
rootDir: ctx.client.buildDir,
|
|
430
433
|
configPath: path$1.resolve(ctx.client.buildDir, "stencil.config.ts"),
|
|
431
434
|
tsconfig: path$1.resolve(ctx.client.buildDir, "tsconfig.json"),
|
|
@@ -4630,10 +4633,12 @@ var provideConfig = async () => {
|
|
|
4630
4633
|
console.log("Please create a proper `embeddable.config.js` or `embeddable.config.ts` file in the root of your project.");
|
|
4631
4634
|
process.exit(1);
|
|
4632
4635
|
}
|
|
4636
|
+
const isWindows = process.platform === "win32";
|
|
4633
4637
|
const configPath = fs$2.existsSync(tsConfigFilePath)
|
|
4634
4638
|
? tsConfigFilePath
|
|
4635
4639
|
: configFilePath;
|
|
4636
|
-
|
|
4640
|
+
const pathOrUrl = isWindows ? url$2.pathToFileURL(configPath).href : configPath;
|
|
4641
|
+
return (await import(pathOrUrl)).default;
|
|
4637
4642
|
};
|
|
4638
4643
|
|
|
4639
4644
|
function getDefaultExportFromCjs (x) {
|
|
@@ -19972,6 +19977,25 @@ const checkNodeVersion = async () => {
|
|
|
19972
19977
|
process.exit(1);
|
|
19973
19978
|
}
|
|
19974
19979
|
};
|
|
19980
|
+
/**
|
|
19981
|
+
* Get the value of a process argument by key
|
|
19982
|
+
* Example: getArgumentByKey("--email") or getArgumentByKey(["--email", "-e"])
|
|
19983
|
+
* @param key The key to search for in the process arguments
|
|
19984
|
+
* @returns
|
|
19985
|
+
*/
|
|
19986
|
+
const getArgumentByKey = (key) => {
|
|
19987
|
+
if (Array.isArray(key)) {
|
|
19988
|
+
for (const k of key) {
|
|
19989
|
+
if (process.argv.includes(k)) {
|
|
19990
|
+
const index = process.argv.indexOf(k);
|
|
19991
|
+
return index !== -1 ? process.argv[index + 1] : undefined;
|
|
19992
|
+
}
|
|
19993
|
+
}
|
|
19994
|
+
return undefined;
|
|
19995
|
+
}
|
|
19996
|
+
const index = process.argv.indexOf(key);
|
|
19997
|
+
return index !== -1 ? process.argv[index + 1] : undefined;
|
|
19998
|
+
};
|
|
19975
19999
|
|
|
19976
20000
|
var build = async () => {
|
|
19977
20001
|
try {
|
|
@@ -20082,29 +20106,57 @@ const inquirerSelect = import('@inquirer/select');
|
|
|
20082
20106
|
const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
|
|
20083
20107
|
let ora$1;
|
|
20084
20108
|
var push = async () => {
|
|
20085
|
-
var _a;
|
|
20109
|
+
var _a, _b;
|
|
20086
20110
|
let spinnerPushing;
|
|
20087
20111
|
try {
|
|
20088
20112
|
checkNodeVersion();
|
|
20089
20113
|
ora$1 = (await oraP$1).default;
|
|
20090
20114
|
const config = await provideConfig();
|
|
20091
20115
|
const token = await verify(config);
|
|
20116
|
+
if (process.argv.includes("--api-key") || process.argv.includes("-k")) {
|
|
20117
|
+
spinnerPushing = ora$1("Using API key...").start();
|
|
20118
|
+
await pushByApiKey(config, spinnerPushing);
|
|
20119
|
+
spinnerPushing.succeed("Published using API key");
|
|
20120
|
+
return;
|
|
20121
|
+
}
|
|
20092
20122
|
const { workspaceId, name: workspaceName } = await selectWorkspace(config, token);
|
|
20093
|
-
|
|
20094
|
-
const filesList = await findFiles(config.client.srcDir, YAML_OR_JS_FILES);
|
|
20095
|
-
await archive(config, filesList);
|
|
20096
|
-
spinnerArchive.succeed("Bundling completed");
|
|
20123
|
+
await buildArchive(config);
|
|
20097
20124
|
spinnerPushing = ora$1(`Publishing to ${workspaceName} using ${config.pushBaseUrl}...`).start();
|
|
20098
20125
|
await sendBuild(config, { workspaceId, token });
|
|
20099
20126
|
spinnerPushing.succeed(`Published to ${workspaceName} using ${config.pushBaseUrl}`);
|
|
20100
20127
|
}
|
|
20101
20128
|
catch (error) {
|
|
20102
20129
|
spinnerPushing === null || spinnerPushing === void 0 ? void 0 : spinnerPushing.fail("Publishing failed");
|
|
20103
|
-
|
|
20130
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.statusText) === "Unauthorized") {
|
|
20131
|
+
console.error("Unauthorized. Please check your credentials.");
|
|
20132
|
+
}
|
|
20133
|
+
else {
|
|
20134
|
+
console.error(((_b = error.response) === null || _b === void 0 ? void 0 : _b.data) || (error === null || error === void 0 ? void 0 : error.message) || error);
|
|
20135
|
+
}
|
|
20104
20136
|
await reportErrorToRollbar(error);
|
|
20105
20137
|
process.exit(1);
|
|
20106
20138
|
}
|
|
20107
20139
|
};
|
|
20140
|
+
async function pushByApiKey(config, spinner) {
|
|
20141
|
+
const apiKey = getArgumentByKey(["--api-key", "-k"]);
|
|
20142
|
+
if (!apiKey) {
|
|
20143
|
+
spinner.fail("No API key provided");
|
|
20144
|
+
process.exit(1);
|
|
20145
|
+
}
|
|
20146
|
+
const email = getArgumentByKey(["--email", "-e"]);
|
|
20147
|
+
if (!email || !/\S+@\S+\.\S+/.test(email)) {
|
|
20148
|
+
spinner.fail("Invalid email provided. Please provide a valid email using --email (-e) flag");
|
|
20149
|
+
process.exit(1);
|
|
20150
|
+
}
|
|
20151
|
+
// message is optional
|
|
20152
|
+
const message = getArgumentByKey(["--message", "-m"]);
|
|
20153
|
+
await buildArchive(config);
|
|
20154
|
+
return sendBuildByApiKey(config, {
|
|
20155
|
+
apiKey,
|
|
20156
|
+
email,
|
|
20157
|
+
message,
|
|
20158
|
+
});
|
|
20159
|
+
}
|
|
20108
20160
|
async function selectWorkspace(ctx, token) {
|
|
20109
20161
|
const workspaceSpinner = ora$1({
|
|
20110
20162
|
text: `Fetching workspaces using ${ctx.pushBaseUrl}...`,
|
|
@@ -20150,6 +20202,12 @@ async function verify(ctx) {
|
|
|
20150
20202
|
}
|
|
20151
20203
|
return token;
|
|
20152
20204
|
}
|
|
20205
|
+
async function buildArchive(config) {
|
|
20206
|
+
const spinnerArchive = ora$1("Building...").start();
|
|
20207
|
+
const filesList = await findFiles(config.client.srcDir, YAML_OR_JS_FILES);
|
|
20208
|
+
await archive(config, filesList);
|
|
20209
|
+
return spinnerArchive.succeed("Bundling completed");
|
|
20210
|
+
}
|
|
20153
20211
|
async function archive(ctx, yamlFiles, includeBuild = true) {
|
|
20154
20212
|
const output = fs$2.createWriteStream(ctx.client.archiveFile);
|
|
20155
20213
|
const _archiver = archiver.create("zip", {
|
|
@@ -20170,13 +20228,30 @@ async function archive(ctx, yamlFiles, includeBuild = true) {
|
|
|
20170
20228
|
output.on("close", resolve);
|
|
20171
20229
|
});
|
|
20172
20230
|
}
|
|
20231
|
+
async function sendBuildByApiKey(ctx, { apiKey, email, message }) {
|
|
20232
|
+
var _a;
|
|
20233
|
+
const { FormData, Blob } = await import('formdata-node');
|
|
20234
|
+
const { fileFromPath } = await Promise.resolve().then(function () { return fileFromPath$1; });
|
|
20235
|
+
const file = await fileFromPath(ctx.client.archiveFile, "embeddable-build.zip");
|
|
20236
|
+
const form = new FormData();
|
|
20237
|
+
form.set("file", file, "embeddable-build.zip");
|
|
20238
|
+
const metadataBlob = new Blob([JSON.stringify({ authorEmail: email, description: message })], { type: "application/json" });
|
|
20239
|
+
form.set("metadata", metadataBlob, "metadata.json");
|
|
20240
|
+
const response = await uploadFile(form, `${ctx.pushBaseUrl}/api/v1/bundle/upload`, apiKey);
|
|
20241
|
+
await fs$1.rm(ctx.client.archiveFile);
|
|
20242
|
+
return { bundleId: (_a = response.data) === null || _a === void 0 ? void 0 : _a.bundleId, email, message };
|
|
20243
|
+
}
|
|
20173
20244
|
async function sendBuild(ctx, { workspaceId, token }) {
|
|
20174
20245
|
const { FormData } = await import('formdata-node');
|
|
20175
20246
|
const { fileFromPath } = await Promise.resolve().then(function () { return fileFromPath$1; });
|
|
20176
20247
|
const file = await fileFromPath(ctx.client.archiveFile, "embeddable-build.zip");
|
|
20177
20248
|
const form = new FormData();
|
|
20178
20249
|
form.set("file", file, "embeddable-build.zip");
|
|
20179
|
-
await
|
|
20250
|
+
await uploadFile(form, `${ctx.pushBaseUrl}/bundle/${workspaceId}/upload`, token);
|
|
20251
|
+
await fs$1.rm(ctx.client.archiveFile);
|
|
20252
|
+
}
|
|
20253
|
+
async function uploadFile(formData, url, token) {
|
|
20254
|
+
return axios.post(url, formData, {
|
|
20180
20255
|
headers: {
|
|
20181
20256
|
"Content-Type": "multipart/form-data",
|
|
20182
20257
|
Authorization: `Bearer ${token}`,
|
|
@@ -20184,7 +20259,6 @@ async function sendBuild(ctx, { workspaceId, token }) {
|
|
|
20184
20259
|
maxContentLength: Infinity,
|
|
20185
20260
|
maxBodyLength: Infinity,
|
|
20186
20261
|
});
|
|
20187
|
-
await fs$1.rm(ctx.client.archiveFile);
|
|
20188
20262
|
}
|
|
20189
20263
|
async function getWorkspaces(ctx, token, workspaceSpinner) {
|
|
20190
20264
|
var _a;
|