@embeddables/cli 0.8.0 → 0.8.1
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/auth/index.d.ts +43 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +102 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +210 -0
- package/dist/command-history.d.ts +13 -0
- package/dist/command-history.d.ts.map +1 -0
- package/dist/command-history.js +34 -0
- package/dist/commands/branch.d.ts +4 -0
- package/dist/commands/branch.d.ts.map +1 -0
- package/dist/commands/branch.js +67 -0
- package/dist/commands/build-workbench.d.ts +5 -0
- package/dist/commands/build-workbench.d.ts.map +1 -0
- package/dist/commands/build-workbench.js +116 -0
- package/dist/commands/build.d.ts +8 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +60 -0
- package/dist/commands/builder-open.d.ts +4 -0
- package/dist/commands/builder-open.d.ts.map +1 -0
- package/dist/commands/builder-open.js +74 -0
- package/dist/commands/dev.d.ts +12 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +226 -0
- package/dist/commands/diff.d.ts +76 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +653 -0
- package/dist/commands/experiments-connect.d.ts +6 -0
- package/dist/commands/experiments-connect.d.ts.map +1 -0
- package/dist/commands/experiments-connect.js +140 -0
- package/dist/commands/feedback.d.ts +29 -0
- package/dist/commands/feedback.d.ts.map +1 -0
- package/dist/commands/feedback.js +267 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +384 -0
- package/dist/commands/inspect.d.ts +9 -0
- package/dist/commands/inspect.d.ts.map +1 -0
- package/dist/commands/inspect.js +293 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +117 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +19 -0
- package/dist/commands/pull.d.ts +16 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +395 -0
- package/dist/commands/save.d.ts +30 -0
- package/dist/commands/save.d.ts.map +1 -0
- package/dist/commands/save.js +597 -0
- package/dist/commands/upgrade.d.ts +2 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +50 -0
- package/dist/compiler/errors.d.ts +20 -0
- package/dist/compiler/errors.d.ts.map +1 -0
- package/dist/compiler/errors.js +35 -0
- package/dist/compiler/evalStatic.d.ts +3 -0
- package/dist/compiler/evalStatic.d.ts.map +1 -0
- package/dist/compiler/evalStatic.js +57 -0
- package/dist/compiler/flatten.js +1 -0
- package/dist/compiler/helpers/duplicateIds.d.ts +9 -0
- package/dist/compiler/helpers/duplicateIds.d.ts.map +1 -0
- package/dist/compiler/helpers/duplicateIds.js +71 -0
- package/dist/compiler/helpers/numericLeadingKeys.d.ts +8 -0
- package/dist/compiler/helpers/numericLeadingKeys.d.ts.map +1 -0
- package/dist/compiler/helpers/numericLeadingKeys.js +17 -0
- package/dist/compiler/index.d.ts +18 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +1272 -0
- package/dist/compiler/parsePage.d.ts +15 -0
- package/dist/compiler/parsePage.d.ts.map +1 -0
- package/dist/compiler/parsePage.js +654 -0
- package/dist/compiler/registry.d.ts +4 -0
- package/dist/compiler/registry.d.ts.map +1 -0
- package/dist/compiler/registry.js +44 -0
- package/dist/compiler/reverse.d.ts +23 -0
- package/dist/compiler/reverse.d.ts.map +1 -0
- package/dist/compiler/reverse.js +1920 -0
- package/dist/compiler/types.d.ts +21 -0
- package/dist/compiler/types.d.ts.map +1 -0
- package/dist/compiler/types.js +1 -0
- package/dist/components/index.d.ts +21 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +21 -0
- package/dist/components/primitives/BaseComponent.d.ts +33 -0
- package/dist/components/primitives/BaseComponent.d.ts.map +1 -0
- package/dist/components/primitives/BaseComponent.js +26 -0
- package/dist/components/primitives/BookMeeting.d.ts +18 -0
- package/dist/components/primitives/BookMeeting.d.ts.map +1 -0
- package/dist/components/primitives/BookMeeting.js +5 -0
- package/dist/components/primitives/Chart.d.ts +41 -0
- package/dist/components/primitives/Chart.d.ts.map +1 -0
- package/dist/components/primitives/Chart.js +5 -0
- package/dist/components/primitives/Container.d.ts +8 -0
- package/dist/components/primitives/Container.d.ts.map +1 -0
- package/dist/components/primitives/Container.js +5 -0
- package/dist/components/primitives/CustomButton.d.ts +37 -0
- package/dist/components/primitives/CustomButton.d.ts.map +1 -0
- package/dist/components/primitives/CustomButton.js +10 -0
- package/dist/components/primitives/CustomHTML.d.ts +8 -0
- package/dist/components/primitives/CustomHTML.d.ts.map +1 -0
- package/dist/components/primitives/CustomHTML.js +5 -0
- package/dist/components/primitives/FileUpload.d.ts +18 -0
- package/dist/components/primitives/FileUpload.d.ts.map +1 -0
- package/dist/components/primitives/FileUpload.js +16 -0
- package/dist/components/primitives/InputBox.d.ts +34 -0
- package/dist/components/primitives/InputBox.d.ts.map +1 -0
- package/dist/components/primitives/InputBox.js +25 -0
- package/dist/components/primitives/Lottie.d.ts +11 -0
- package/dist/components/primitives/Lottie.d.ts.map +1 -0
- package/dist/components/primitives/Lottie.js +5 -0
- package/dist/components/primitives/MediaEmbed.d.ts +13 -0
- package/dist/components/primitives/MediaEmbed.d.ts.map +1 -0
- package/dist/components/primitives/MediaEmbed.js +6 -0
- package/dist/components/primitives/MediaImage.d.ts +8 -0
- package/dist/components/primitives/MediaImage.d.ts.map +1 -0
- package/dist/components/primitives/MediaImage.js +5 -0
- package/dist/components/primitives/OptionSelector.d.ts +38 -0
- package/dist/components/primitives/OptionSelector.d.ts.map +1 -0
- package/dist/components/primitives/OptionSelector.js +8 -0
- package/dist/components/primitives/PaypalCheckout.d.ts +25 -0
- package/dist/components/primitives/PaypalCheckout.d.ts.map +1 -0
- package/dist/components/primitives/PaypalCheckout.js +5 -0
- package/dist/components/primitives/PlainText.d.ts +6 -0
- package/dist/components/primitives/PlainText.d.ts.map +1 -0
- package/dist/components/primitives/PlainText.js +5 -0
- package/dist/components/primitives/ProgressBar.d.ts +15 -0
- package/dist/components/primitives/ProgressBar.d.ts.map +1 -0
- package/dist/components/primitives/ProgressBar.js +5 -0
- package/dist/components/primitives/RichText.d.ts +6 -0
- package/dist/components/primitives/RichText.d.ts.map +1 -0
- package/dist/components/primitives/RichText.js +5 -0
- package/dist/components/primitives/RichTextMarkdown.d.ts +6 -0
- package/dist/components/primitives/RichTextMarkdown.d.ts.map +1 -0
- package/dist/components/primitives/RichTextMarkdown.js +5 -0
- package/dist/components/primitives/Rive.d.ts +16 -0
- package/dist/components/primitives/Rive.d.ts.map +1 -0
- package/dist/components/primitives/Rive.js +8 -0
- package/dist/components/primitives/StripeCheckout.d.ts +52 -0
- package/dist/components/primitives/StripeCheckout.d.ts.map +1 -0
- package/dist/components/primitives/StripeCheckout.js +5 -0
- package/dist/components/primitives/StripeCheckout2.d.ts +30 -0
- package/dist/components/primitives/StripeCheckout2.d.ts.map +1 -0
- package/dist/components/primitives/StripeCheckout2.js +7 -0
- package/dist/config/index.d.ts +23 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +42 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +9 -0
- package/dist/helpers/TEMP helpers file.d.ts +1 -0
- package/dist/helpers/TEMP helpers file.d.ts.map +1 -0
- package/dist/helpers/TEMP helpers file.js +1 -0
- package/dist/helpers/dates.d.ts +5 -0
- package/dist/helpers/dates.d.ts.map +1 -0
- package/dist/helpers/dates.js +7 -0
- package/dist/helpers/json.d.ts +47 -0
- package/dist/helpers/json.d.ts.map +1 -0
- package/dist/helpers/json.js +622 -0
- package/dist/helpers/prompt.d.ts +15 -0
- package/dist/helpers/prompt.d.ts.map +1 -0
- package/dist/helpers/prompt.js +35 -0
- package/dist/helpers/utils.d.ts +13 -0
- package/dist/helpers/utils.d.ts.map +1 -0
- package/dist/helpers/utils.js +28 -0
- package/dist/logger.d.ts +11 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +21 -0
- package/dist/patches/prompts-escape.d.ts +14 -0
- package/dist/patches/prompts-escape.d.ts.map +1 -0
- package/dist/patches/prompts-escape.js +23 -0
- package/dist/prompts/branches.d.ts +20 -0
- package/dist/prompts/branches.d.ts.map +1 -0
- package/dist/prompts/branches.js +86 -0
- package/dist/prompts/embeddables.d.ts +43 -0
- package/dist/prompts/embeddables.d.ts.map +1 -0
- package/dist/prompts/embeddables.js +200 -0
- package/dist/prompts/experiments.d.ts +28 -0
- package/dist/prompts/experiments.d.ts.map +1 -0
- package/dist/prompts/experiments.js +89 -0
- package/dist/prompts/index.d.ts +11 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +6 -0
- package/dist/prompts/projects.d.ts +22 -0
- package/dist/prompts/projects.d.ts.map +1 -0
- package/dist/prompts/projects.js +92 -0
- package/dist/prompts/versions.d.ts +18 -0
- package/dist/prompts/versions.d.ts.map +1 -0
- package/dist/prompts/versions.js +95 -0
- package/dist/proxy/injectApiInterceptor.d.ts +6 -0
- package/dist/proxy/injectApiInterceptor.d.ts.map +1 -0
- package/dist/proxy/injectApiInterceptor.js +66 -0
- package/dist/proxy/injectReload.d.ts +2 -0
- package/dist/proxy/injectReload.d.ts.map +1 -0
- package/dist/proxy/injectReload.js +14 -0
- package/dist/proxy/injectWorkbench.d.ts +5 -0
- package/dist/proxy/injectWorkbench.d.ts.map +1 -0
- package/dist/proxy/injectWorkbench.js +22 -0
- package/dist/proxy/server.d.ts +11 -0
- package/dist/proxy/server.d.ts.map +1 -0
- package/dist/proxy/server.js +304 -0
- package/dist/proxy/sse.d.ts +5 -0
- package/dist/proxy/sse.d.ts.map +1 -0
- package/dist/proxy/sse.js +17 -0
- package/dist/sentry-context.d.ts +48 -0
- package/dist/sentry-context.d.ts.map +1 -0
- package/dist/sentry-context.js +156 -0
- package/dist/stdout.d.ts +61 -0
- package/dist/stdout.d.ts.map +1 -0
- package/dist/stdout.js +163 -0
- package/dist/types-builder.d.ts +800 -0
- package/dist/types-builder.d.ts.map +1 -0
- package/dist/types-builder.js +20 -0
- package/dist/workbench/ActionsPanel.d.ts +6 -0
- package/dist/workbench/ActionsPanel.d.ts.map +1 -0
- package/dist/workbench/ActionsPanel.js +47 -0
- package/dist/workbench/AutofillPanel.d.ts +6 -0
- package/dist/workbench/AutofillPanel.d.ts.map +1 -0
- package/dist/workbench/AutofillPanel.js +543 -0
- package/dist/workbench/ComputedFieldsPanel.d.ts +6 -0
- package/dist/workbench/ComputedFieldsPanel.d.ts.map +1 -0
- package/dist/workbench/ComputedFieldsPanel.js +31 -0
- package/dist/workbench/ExperimentsPanel.d.ts +6 -0
- package/dist/workbench/ExperimentsPanel.d.ts.map +1 -0
- package/dist/workbench/ExperimentsPanel.js +182 -0
- package/dist/workbench/FieldEditorPanel.d.ts +9 -0
- package/dist/workbench/FieldEditorPanel.d.ts.map +1 -0
- package/dist/workbench/FieldEditorPanel.js +650 -0
- package/dist/workbench/InspectorPanel.d.ts +6 -0
- package/dist/workbench/InspectorPanel.d.ts.map +1 -0
- package/dist/workbench/InspectorPanel.js +341 -0
- package/dist/workbench/PageNavigator.d.ts +6 -0
- package/dist/workbench/PageNavigator.d.ts.map +1 -0
- package/dist/workbench/PageNavigator.js +123 -0
- package/dist/workbench/SchemaPanel.d.ts +6 -0
- package/dist/workbench/SchemaPanel.d.ts.map +1 -0
- package/dist/workbench/SchemaPanel.js +222 -0
- package/dist/workbench/UserDataPanel.d.ts +6 -0
- package/dist/workbench/UserDataPanel.d.ts.map +1 -0
- package/dist/workbench/UserDataPanel.js +350 -0
- package/dist/workbench/WorkbenchApp.d.ts +7 -0
- package/dist/workbench/WorkbenchApp.d.ts.map +1 -0
- package/dist/workbench/WorkbenchApp.js +193 -0
- package/dist/workbench/cloudflare-worker/README.md +31 -0
- package/dist/workbench/cloudflare-worker/public/workbench.css +1614 -0
- package/dist/workbench/cloudflare-worker/public/workbench.js +77 -0
- package/dist/workbench/cloudflare-worker/worker.js +40 -0
- package/dist/workbench/cloudflare-worker/wrangler.toml +10 -0
- package/dist/workbench/index.d.ts +10 -0
- package/dist/workbench/index.d.ts.map +1 -0
- package/dist/workbench/index.js +44 -0
- package/dist/workbench/workbench.css +1614 -0
- package/dist/workbench/workbench.js +77 -0
- package/package.json +1 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
export declare const SUPABASE_URL = "https://ierxexdtyashuotcsjyo.supabase.co";
|
|
3
|
+
export declare const SUPABASE_ANON_KEY = "sb_publishable_Vt8-msWNtn2hhOY3AA6RsQ_ueTx79Vo";
|
|
4
|
+
export interface AuthConfig {
|
|
5
|
+
access_token: string;
|
|
6
|
+
refresh_token: string;
|
|
7
|
+
expires_at: number;
|
|
8
|
+
supabase_url: string;
|
|
9
|
+
supabase_anon_key: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get the path to the auth config file
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAuthFilePath(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Read auth config from file
|
|
17
|
+
*/
|
|
18
|
+
export declare function readAuthConfig(): AuthConfig | null;
|
|
19
|
+
/**
|
|
20
|
+
* Write auth config to file
|
|
21
|
+
*/
|
|
22
|
+
export declare function writeAuthConfig(config: AuthConfig): void;
|
|
23
|
+
/**
|
|
24
|
+
* Delete auth config file (logout)
|
|
25
|
+
*/
|
|
26
|
+
export declare function deleteAuthConfig(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Check if user is logged in (has valid auth config)
|
|
29
|
+
*/
|
|
30
|
+
export declare function isLoggedIn(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Get Supabase client instance
|
|
33
|
+
*/
|
|
34
|
+
export declare function getSupabaseClient(): SupabaseClient;
|
|
35
|
+
/**
|
|
36
|
+
* Get authenticated Supabase client (with stored session)
|
|
37
|
+
*/
|
|
38
|
+
export declare function getAuthenticatedSupabaseClient(): Promise<SupabaseClient | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Get access token for authenticated requests
|
|
41
|
+
*/
|
|
42
|
+
export declare function getAccessToken(): string | null;
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAGpE,eAAO,MAAM,YAAY,6CAA6C,CAAA;AACtE,eAAO,MAAM,iBAAiB,mDAAmD,CAAA;AAEjF,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,iBAAiB,EAAE,MAAM,CAAA;CAC1B;AAMD;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,UAAU,GAAG,IAAI,CAUlD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAGxD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAIvC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAcpC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAWlD;AAED;;GAEG;AACH,wBAAsB,8BAA8B,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAcrF;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAM9C"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createClient } from '@supabase/supabase-js';
|
|
5
|
+
// TODO: Move to environment variables
|
|
6
|
+
export const SUPABASE_URL = 'https://ierxexdtyashuotcsjyo.supabase.co'; // Replace with actual Supabase URL
|
|
7
|
+
export const SUPABASE_ANON_KEY = 'sb_publishable_Vt8-msWNtn2hhOY3AA6RsQ_ueTx79Vo'; // Replace with actual Supabase anon key
|
|
8
|
+
// Store auth globally in user's home directory
|
|
9
|
+
const AUTH_DIR = path.join(os.homedir(), '.embeddables');
|
|
10
|
+
const AUTH_FILE = path.join(AUTH_DIR, 'auth.json');
|
|
11
|
+
/**
|
|
12
|
+
* Get the path to the auth config file
|
|
13
|
+
*/
|
|
14
|
+
export function getAuthFilePath() {
|
|
15
|
+
return AUTH_FILE;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Read auth config from file
|
|
19
|
+
*/
|
|
20
|
+
export function readAuthConfig() {
|
|
21
|
+
try {
|
|
22
|
+
if (!fs.existsSync(AUTH_FILE)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const content = fs.readFileSync(AUTH_FILE, 'utf8');
|
|
26
|
+
return JSON.parse(content);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Write auth config to file
|
|
34
|
+
*/
|
|
35
|
+
export function writeAuthConfig(config) {
|
|
36
|
+
fs.mkdirSync(AUTH_DIR, { recursive: true });
|
|
37
|
+
fs.writeFileSync(AUTH_FILE, JSON.stringify(config, null, 2), 'utf8');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Delete auth config file (logout)
|
|
41
|
+
*/
|
|
42
|
+
export function deleteAuthConfig() {
|
|
43
|
+
if (fs.existsSync(AUTH_FILE)) {
|
|
44
|
+
fs.unlinkSync(AUTH_FILE);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if user is logged in (has valid auth config)
|
|
49
|
+
*/
|
|
50
|
+
export function isLoggedIn() {
|
|
51
|
+
const config = readAuthConfig();
|
|
52
|
+
if (!config) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
// Check if token is expired (with 5 minute buffer)
|
|
56
|
+
const now = Math.floor(Date.now() / 1000);
|
|
57
|
+
const expiresAt = config.expires_at;
|
|
58
|
+
if (expiresAt && expiresAt < now + 300) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return !!config.access_token;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get Supabase client instance
|
|
65
|
+
*/
|
|
66
|
+
export function getSupabaseClient() {
|
|
67
|
+
const config = readAuthConfig();
|
|
68
|
+
const url = config?.supabase_url || SUPABASE_URL;
|
|
69
|
+
const anonKey = config?.supabase_anon_key || SUPABASE_ANON_KEY;
|
|
70
|
+
return createClient(url, anonKey, {
|
|
71
|
+
auth: {
|
|
72
|
+
persistSession: false, // We handle session persistence ourselves
|
|
73
|
+
autoRefreshToken: false, // No auto refresh for now
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get authenticated Supabase client (with stored session)
|
|
79
|
+
*/
|
|
80
|
+
export async function getAuthenticatedSupabaseClient() {
|
|
81
|
+
const config = readAuthConfig();
|
|
82
|
+
if (!config || !isLoggedIn()) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const client = getSupabaseClient();
|
|
86
|
+
// Set the session manually
|
|
87
|
+
await client.auth.setSession({
|
|
88
|
+
access_token: config.access_token,
|
|
89
|
+
refresh_token: config.refresh_token,
|
|
90
|
+
});
|
|
91
|
+
return client;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get access token for authenticated requests
|
|
95
|
+
*/
|
|
96
|
+
export function getAccessToken() {
|
|
97
|
+
const config = readAuthConfig();
|
|
98
|
+
if (!config || !isLoggedIn()) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return config.access_token;
|
|
102
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import * as Sentry from '@sentry/node';
|
|
2
|
+
Sentry.init({
|
|
3
|
+
dsn: 'https://1660165be6d73c50814963e5c6bbd5dc@o4510046767742976.ingest.us.sentry.io/4510908525379584',
|
|
4
|
+
tracesSampleRate: 1.0,
|
|
5
|
+
enableLogs: true,
|
|
6
|
+
// debug: true,
|
|
7
|
+
});
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { Command, Option } from 'commander';
|
|
12
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
const pkg = require(path.join(__dirname, '..', 'package.json'));
|
|
15
|
+
Sentry.getCurrentScope().setAttributes({ cliVersion: pkg.version });
|
|
16
|
+
import { isLoggedIn } from './auth/index.js';
|
|
17
|
+
import { getSentryContextFromProjectConfig, setSentryContext, setSentryUserFromAuth, } from './sentry-context.js';
|
|
18
|
+
import { runBranch } from './commands/branch.js';
|
|
19
|
+
import { runBuild } from './commands/build.js';
|
|
20
|
+
import { runDev } from './commands/dev.js';
|
|
21
|
+
import { runBuilderOpen } from './commands/builder-open.js';
|
|
22
|
+
import { runExperimentsConnect } from './commands/experiments-connect.js';
|
|
23
|
+
import { runInit } from './commands/init.js';
|
|
24
|
+
import { runInspect } from './commands/inspect.js';
|
|
25
|
+
import { runLogin } from './commands/login.js';
|
|
26
|
+
import { runLogout } from './commands/logout.js';
|
|
27
|
+
import { runPull } from './commands/pull.js';
|
|
28
|
+
import { runSave } from './commands/save.js';
|
|
29
|
+
import { runUpgrade } from './commands/upgrade.js';
|
|
30
|
+
import { exit } from './logger.js';
|
|
31
|
+
import * as stdout from './stdout.js';
|
|
32
|
+
/** Only these commands may run without being logged in. All others require login. */
|
|
33
|
+
const COMMANDS_ALLOWED_WITHOUT_LOGIN = new Set(['login', 'logout', 'upgrade']);
|
|
34
|
+
async function requireLogin(commandName) {
|
|
35
|
+
const baseCommand = commandName.split(' ')[0];
|
|
36
|
+
if (COMMANDS_ALLOWED_WITHOUT_LOGIN.has(baseCommand))
|
|
37
|
+
return;
|
|
38
|
+
if (isLoggedIn())
|
|
39
|
+
return;
|
|
40
|
+
stdout.warn('Not logged in.');
|
|
41
|
+
stdout.dim('Run "embeddables login" first.');
|
|
42
|
+
await exit(1);
|
|
43
|
+
}
|
|
44
|
+
/** Set Sentry context from config and auth for the current command. Config is set immediately; user is set in background so we don't block on auth. */
|
|
45
|
+
function setSentryContextForCommand() {
|
|
46
|
+
setSentryContext(getSentryContextFromProjectConfig());
|
|
47
|
+
void setSentryUserFromAuth();
|
|
48
|
+
}
|
|
49
|
+
const program = new Command();
|
|
50
|
+
program
|
|
51
|
+
.name('embeddables')
|
|
52
|
+
.description('Embeddables CLI')
|
|
53
|
+
.version(pkg.version, '-v, --version', 'Show CLI version')
|
|
54
|
+
.enablePositionalOptions();
|
|
55
|
+
program
|
|
56
|
+
.command('init')
|
|
57
|
+
.description('Initialize a new Embeddables project')
|
|
58
|
+
.option('-p, --project-id <id>', 'Embeddables project ID')
|
|
59
|
+
.option('-y, --yes', 'Skip prompts and use defaults')
|
|
60
|
+
.action(async (opts) => {
|
|
61
|
+
await requireLogin('init');
|
|
62
|
+
setSentryContextForCommand();
|
|
63
|
+
await runInit({ projectId: opts.projectId, yes: opts.yes });
|
|
64
|
+
});
|
|
65
|
+
program
|
|
66
|
+
.command('build')
|
|
67
|
+
.option('-i, --id <id>', 'Embeddable ID (will prompt if not provided)')
|
|
68
|
+
.option('-p, --pages <glob>', 'Pages glob')
|
|
69
|
+
.option('-o, --out <path>', 'Output json path')
|
|
70
|
+
.option('--fix', 'Apply lint fixes (duplicate IDs, keys/IDs starting with a number)')
|
|
71
|
+
.option('--pageKeyFrom <mode>', 'filename|export', 'filename')
|
|
72
|
+
.action(async (opts) => {
|
|
73
|
+
await requireLogin('build');
|
|
74
|
+
setSentryContextForCommand();
|
|
75
|
+
await runBuild(opts);
|
|
76
|
+
});
|
|
77
|
+
program
|
|
78
|
+
.command('dev')
|
|
79
|
+
.option('-i, --id <id>', 'Embeddable ID (will prompt if not provided)')
|
|
80
|
+
.option('-p, --pages <glob>', 'Pages glob')
|
|
81
|
+
.option('-o, --out <path>', 'Output json path')
|
|
82
|
+
.option('--fix', 'Apply lint fixes (duplicate IDs, keys/IDs starting with a number)')
|
|
83
|
+
.option('-L, --local', 'Use local engine (http://localhost:8787)')
|
|
84
|
+
.option('-e, --engine <url>', 'Engine origin', 'https://engine.embeddables.com')
|
|
85
|
+
.option('--port <n>', 'Dev proxy port', '3000')
|
|
86
|
+
.option('--overrideRoute <path>', 'Route to override in proxy (exact match, no wildcards yet)', '/init')
|
|
87
|
+
.option('--pageKeyFrom <mode>', 'filename|export', 'filename')
|
|
88
|
+
.action(async (opts) => {
|
|
89
|
+
await requireLogin('dev');
|
|
90
|
+
setSentryContextForCommand();
|
|
91
|
+
// --local flag overrides --engine to use local engine
|
|
92
|
+
if (opts.local) {
|
|
93
|
+
opts.engine = 'http://localhost:8787';
|
|
94
|
+
}
|
|
95
|
+
await runDev(opts);
|
|
96
|
+
});
|
|
97
|
+
program
|
|
98
|
+
.command('login')
|
|
99
|
+
.description('Login to Embeddables')
|
|
100
|
+
.action(async () => {
|
|
101
|
+
await runLogin();
|
|
102
|
+
});
|
|
103
|
+
program
|
|
104
|
+
.command('logout')
|
|
105
|
+
.description('Logout from Embeddables')
|
|
106
|
+
.action(async () => {
|
|
107
|
+
await runLogout();
|
|
108
|
+
});
|
|
109
|
+
program
|
|
110
|
+
.command('pull')
|
|
111
|
+
.description('Pull an embeddable from the cloud')
|
|
112
|
+
.option('-i, --id <id>', 'Embeddable ID to pull (interactive selection if not provided)')
|
|
113
|
+
.option('-o, --out <path>', 'Output json path')
|
|
114
|
+
.option('--version [version]', 'Version to pull; omit flag for latest, use without value for interactive selector, or pass a number')
|
|
115
|
+
.option('-b, --branch <branch_id>', 'Embeddable branch ID')
|
|
116
|
+
.option('-f, --fix', 'Fix by removing components missing required props (warn instead of error)')
|
|
117
|
+
.option('-p, --preserve', 'Preserve component order in config for forward compile')
|
|
118
|
+
.action(async (opts) => {
|
|
119
|
+
await requireLogin('pull');
|
|
120
|
+
setSentryContextForCommand();
|
|
121
|
+
const selectVersion = opts.version === true;
|
|
122
|
+
await runPull({
|
|
123
|
+
...opts,
|
|
124
|
+
version: selectVersion ? undefined : opts.version,
|
|
125
|
+
selectVersion,
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
program
|
|
129
|
+
.command('inspect')
|
|
130
|
+
.description('Fetch, reverse-compile, and rebuild an embeddable for debugging')
|
|
131
|
+
.requiredOption('-i, --id <id>', 'Embeddable ID to inspect')
|
|
132
|
+
.option('--version <version>', 'Version to inspect (number or "latest")', 'latest')
|
|
133
|
+
.option('-b, --branch <branch_id>', 'Embeddable branch ID')
|
|
134
|
+
.option('-f, --fix', 'Fix by removing components missing required props', true)
|
|
135
|
+
.option('-e, --engine <url>', 'Engine origin', 'https://engine.embeddables.com')
|
|
136
|
+
.addOption(new Option('--bypass-auth').hideHelp())
|
|
137
|
+
.action(async (opts) => {
|
|
138
|
+
if (!opts.bypassAuth) {
|
|
139
|
+
await requireLogin('inspect');
|
|
140
|
+
}
|
|
141
|
+
setSentryContextForCommand();
|
|
142
|
+
await runInspect({
|
|
143
|
+
id: opts.id,
|
|
144
|
+
version: opts.version,
|
|
145
|
+
branch: opts.branch,
|
|
146
|
+
fix: opts.fix,
|
|
147
|
+
engine: opts.engine,
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
program
|
|
151
|
+
.command('save')
|
|
152
|
+
.description('Build and save an embeddable to the cloud')
|
|
153
|
+
.option('-i, --id <id>', 'Embeddable ID (will prompt if not provided)')
|
|
154
|
+
.option('-l, --label <label>', 'Human-readable label for this version')
|
|
155
|
+
.option('-b, --branch <branch_id>', 'Branch ID to save to')
|
|
156
|
+
.option('-s, --skip-build', 'Skip the build step and use existing compiled JSON')
|
|
157
|
+
.option('--from-version <number>', 'Base version number (auto-detected from local files if not provided)')
|
|
158
|
+
.action(async (opts) => {
|
|
159
|
+
await requireLogin('save');
|
|
160
|
+
setSentryContextForCommand();
|
|
161
|
+
await runSave({
|
|
162
|
+
id: opts.id,
|
|
163
|
+
label: opts.label,
|
|
164
|
+
branch: opts.branch,
|
|
165
|
+
skipBuild: opts.skipBuild,
|
|
166
|
+
fromVersion: opts.fromVersion,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
program
|
|
170
|
+
.command('upgrade')
|
|
171
|
+
.description('Update the CLI to the latest stable version')
|
|
172
|
+
.action(async () => {
|
|
173
|
+
await runUpgrade();
|
|
174
|
+
});
|
|
175
|
+
program
|
|
176
|
+
.command('branch')
|
|
177
|
+
.description('Switch to a different branch of an embeddable')
|
|
178
|
+
.option('-i, --id <id>', 'Embeddable ID (will prompt if not provided)')
|
|
179
|
+
.action(async (opts) => {
|
|
180
|
+
await requireLogin('branch');
|
|
181
|
+
setSentryContextForCommand();
|
|
182
|
+
await runBranch(opts);
|
|
183
|
+
});
|
|
184
|
+
const builder = program.command('builder').description('Embeddables Builder utilities');
|
|
185
|
+
builder
|
|
186
|
+
.command('open')
|
|
187
|
+
.description('Open the Embeddables Builder in the browser')
|
|
188
|
+
.option('-i, --id <id>', 'Embeddable ID (will prompt if not provided)')
|
|
189
|
+
.action(async (opts) => {
|
|
190
|
+
await requireLogin('builder open');
|
|
191
|
+
setSentryContextForCommand();
|
|
192
|
+
await runBuilderOpen({ id: opts.id });
|
|
193
|
+
});
|
|
194
|
+
const experiments = program.command('experiments').description('Manage embeddable experiments');
|
|
195
|
+
experiments
|
|
196
|
+
.command('connect')
|
|
197
|
+
.description('Connect an experiment to an embeddable')
|
|
198
|
+
.option('-i, --id <id>', 'Embeddable ID (will prompt if not provided)')
|
|
199
|
+
.option('--experiment-id <id>', 'Experiment ID (will prompt to choose from project if not provided)')
|
|
200
|
+
.option('--experiment-key <key>', 'Experiment key (required if --experiment-id is set)')
|
|
201
|
+
.action(async (opts) => {
|
|
202
|
+
await requireLogin('experiments connect');
|
|
203
|
+
setSentryContextForCommand();
|
|
204
|
+
await runExperimentsConnect({
|
|
205
|
+
id: opts.id,
|
|
206
|
+
experimentId: opts.experimentId,
|
|
207
|
+
experimentKey: opts.experimentKey,
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
await program.parseAsync(process.argv);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface CommandHistoryEntry {
|
|
2
|
+
command: string;
|
|
3
|
+
args: string[];
|
|
4
|
+
exitCode: number;
|
|
5
|
+
durationMs: number;
|
|
6
|
+
timestamp: string;
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function getHistoryFilePath(): string;
|
|
10
|
+
export declare function readHistory(): CommandHistoryEntry[];
|
|
11
|
+
export declare function writeHistoryEntry(entry: CommandHistoryEntry): void;
|
|
12
|
+
export declare function getLastHistoryEntry(): CommandHistoryEntry | null;
|
|
13
|
+
//# sourceMappingURL=command-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-history.d.ts","sourceRoot":"","sources":["../src/command-history.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAgB,WAAW,IAAI,mBAAmB,EAAE,CAUnD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAMlE;AAED,wBAAgB,mBAAmB,IAAI,mBAAmB,GAAG,IAAI,CAGhE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
const MAX_ENTRIES = 20;
|
|
5
|
+
const HISTORY_DIR = path.join(os.homedir(), '.embeddables');
|
|
6
|
+
const HISTORY_FILE = path.join(HISTORY_DIR, 'history.json');
|
|
7
|
+
export function getHistoryFilePath() {
|
|
8
|
+
return HISTORY_FILE;
|
|
9
|
+
}
|
|
10
|
+
export function readHistory() {
|
|
11
|
+
try {
|
|
12
|
+
if (!fs.existsSync(HISTORY_FILE))
|
|
13
|
+
return [];
|
|
14
|
+
const raw = fs.readFileSync(HISTORY_FILE, 'utf8');
|
|
15
|
+
const parsed = JSON.parse(raw);
|
|
16
|
+
if (!Array.isArray(parsed))
|
|
17
|
+
return [];
|
|
18
|
+
return parsed;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function writeHistoryEntry(entry) {
|
|
25
|
+
const history = readHistory();
|
|
26
|
+
history.push(entry);
|
|
27
|
+
const trimmed = history.slice(-MAX_ENTRIES);
|
|
28
|
+
fs.mkdirSync(HISTORY_DIR, { recursive: true });
|
|
29
|
+
fs.writeFileSync(HISTORY_FILE, JSON.stringify(trimmed, null, 2), 'utf8');
|
|
30
|
+
}
|
|
31
|
+
export function getLastHistoryEntry() {
|
|
32
|
+
const history = readHistory();
|
|
33
|
+
return history.length > 0 ? history[history.length - 1] : null;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branch.d.ts","sourceRoot":"","sources":["../../src/commands/branch.ts"],"names":[],"mappings":"AASA,wBAAsB,SAAS,CAAC,IAAI,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,iBAqEpD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import pc from 'picocolors';
|
|
2
|
+
import { isLoggedIn } from '../auth/index.js';
|
|
3
|
+
import { runPull } from './pull.js';
|
|
4
|
+
import { promptForLocalEmbeddable, fetchBranches, promptForBranch } from '../prompts/index.js';
|
|
5
|
+
import { createLogger, exit } from '../logger.js';
|
|
6
|
+
import { getSentryContextFromProjectConfig, setSentryContext } from '../sentry-context.js';
|
|
7
|
+
import * as stdout from '../stdout.js';
|
|
8
|
+
import { inferEmbeddableFromCwd } from '../helpers/utils.js';
|
|
9
|
+
export async function runBranch(opts) {
|
|
10
|
+
const logger = createLogger('runBranch');
|
|
11
|
+
// Check login status
|
|
12
|
+
if (!isLoggedIn()) {
|
|
13
|
+
stdout.warn('Not logged in.');
|
|
14
|
+
stdout.dim('Run "embeddables login" first.');
|
|
15
|
+
logger.error('not logged in');
|
|
16
|
+
await exit(1);
|
|
17
|
+
}
|
|
18
|
+
// Get embeddable ID
|
|
19
|
+
const inferred = inferEmbeddableFromCwd();
|
|
20
|
+
let embeddableId = opts.id ?? inferred?.embeddableId;
|
|
21
|
+
if (inferred && !opts.id && embeddableId) {
|
|
22
|
+
process.chdir(inferred.projectRoot);
|
|
23
|
+
}
|
|
24
|
+
setSentryContext(getSentryContextFromProjectConfig());
|
|
25
|
+
if (!embeddableId) {
|
|
26
|
+
const selected = await promptForLocalEmbeddable();
|
|
27
|
+
if (!selected) {
|
|
28
|
+
await exit(1);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
embeddableId = selected;
|
|
32
|
+
}
|
|
33
|
+
if (embeddableId) {
|
|
34
|
+
setSentryContext({ embeddable: { id: embeddableId } });
|
|
35
|
+
}
|
|
36
|
+
// Fetch branches for this embeddable
|
|
37
|
+
const branches = await stdout.withSpinner('Fetching branches…', async () => {
|
|
38
|
+
return fetchBranches(embeddableId);
|
|
39
|
+
}, {
|
|
40
|
+
successText: (b) => `Fetched ${b.length} branch(es)`,
|
|
41
|
+
});
|
|
42
|
+
if (branches.length === 0) {
|
|
43
|
+
stdout.warn('No branches found for this embeddable.');
|
|
44
|
+
stdout.dim('Branches are created in the Embeddables Builder.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// Prompt for branch selection
|
|
48
|
+
const selectedBranch = await promptForBranch(branches);
|
|
49
|
+
stdout.gap();
|
|
50
|
+
// Pull the selected branch
|
|
51
|
+
if (selectedBranch === null) {
|
|
52
|
+
// User selected "main" - pull without branch
|
|
53
|
+
stdout.step('Switching to main (latest published version)…');
|
|
54
|
+
await runPull({ id: embeddableId, useMain: true });
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
setSentryContext({
|
|
58
|
+
branch: { id: selectedBranch.id, name: selectedBranch.name },
|
|
59
|
+
});
|
|
60
|
+
stdout.step(`Switching to branch: ${pc.bold(selectedBranch.name)}…`);
|
|
61
|
+
await runPull({
|
|
62
|
+
id: embeddableId,
|
|
63
|
+
branch: selectedBranch.id,
|
|
64
|
+
branchName: selectedBranch.name,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-workbench.d.ts","sourceRoot":"","sources":["../../src/commands/build-workbench.ts"],"names":[],"mappings":"AASA,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,iBA4H/E"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import * as esbuild from 'esbuild';
|
|
4
|
+
import postcss from 'postcss';
|
|
5
|
+
import tailwindcss from '@tailwindcss/postcss';
|
|
6
|
+
import autoprefixer from 'autoprefixer';
|
|
7
|
+
import { createLogger, exit } from '../logger.js';
|
|
8
|
+
import * as stdout from '../stdout.js';
|
|
9
|
+
export async function runBuildWorkbench(opts) {
|
|
10
|
+
const logger = createLogger('runBuildWorkbench');
|
|
11
|
+
const outDir = opts.out || 'dist/workbench';
|
|
12
|
+
const shouldMinify = opts.minify ?? true;
|
|
13
|
+
// Check if wrangler config exists in outDir (native Cloudflare Git integration mode)
|
|
14
|
+
const hasWranglerConfig = fs.existsSync(path.join(outDir, 'wrangler.jsonc')) ||
|
|
15
|
+
fs.existsSync(path.join(outDir, 'wrangler.toml'));
|
|
16
|
+
stdout.step('Building Workbench for CDN deployment…');
|
|
17
|
+
stdout.gap();
|
|
18
|
+
// Ensure output directory exists
|
|
19
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
20
|
+
const workbenchEntry = path.join(process.cwd(), 'src', 'workbench', 'index.tsx');
|
|
21
|
+
const workbenchCssEntry = path.join(process.cwd(), 'src', 'workbench', 'workbench.css');
|
|
22
|
+
// Check that source files exist
|
|
23
|
+
if (!fs.existsSync(workbenchEntry)) {
|
|
24
|
+
stdout.error(`Workbench entry not found: ${workbenchEntry}`);
|
|
25
|
+
logger.error('workbench entry not found', { path: workbenchEntry });
|
|
26
|
+
await exit(1);
|
|
27
|
+
}
|
|
28
|
+
if (!fs.existsSync(workbenchCssEntry)) {
|
|
29
|
+
stdout.error(`Workbench CSS not found: ${workbenchCssEntry}`);
|
|
30
|
+
logger.error('workbench css not found', { path: workbenchCssEntry });
|
|
31
|
+
await exit(1);
|
|
32
|
+
}
|
|
33
|
+
// Build JavaScript bundle
|
|
34
|
+
const jsResult = await stdout.withSpinner('Building JavaScript bundle…', async () => {
|
|
35
|
+
return esbuild.build({
|
|
36
|
+
entryPoints: [workbenchEntry],
|
|
37
|
+
bundle: true,
|
|
38
|
+
format: 'iife',
|
|
39
|
+
globalName: '__EmbeddablesWorkbenchBundle',
|
|
40
|
+
platform: 'browser',
|
|
41
|
+
minify: shouldMinify,
|
|
42
|
+
sourcemap: shouldMinify ? false : 'inline',
|
|
43
|
+
write: false,
|
|
44
|
+
target: ['es2020', 'chrome80', 'firefox78', 'safari14'],
|
|
45
|
+
});
|
|
46
|
+
}, { successText: 'JavaScript bundle built' });
|
|
47
|
+
const jsOutput = jsResult.outputFiles?.[0];
|
|
48
|
+
if (!jsOutput) {
|
|
49
|
+
stdout.error('Failed to build JavaScript bundle');
|
|
50
|
+
logger.error('workbench js bundle build failed');
|
|
51
|
+
await exit(1);
|
|
52
|
+
}
|
|
53
|
+
// Build CSS
|
|
54
|
+
const cssResult = await stdout.withSpinner('Building CSS…', async () => {
|
|
55
|
+
const rawCss = fs.readFileSync(workbenchCssEntry, 'utf8');
|
|
56
|
+
return postcss([tailwindcss(), autoprefixer]).process(rawCss, {
|
|
57
|
+
from: workbenchCssEntry,
|
|
58
|
+
});
|
|
59
|
+
}, { successText: 'CSS built' });
|
|
60
|
+
// CORS headers file for Cloudflare static assets
|
|
61
|
+
const headersContent = `/*
|
|
62
|
+
Access-Control-Allow-Origin: *
|
|
63
|
+
Access-Control-Allow-Methods: GET, OPTIONS
|
|
64
|
+
Access-Control-Allow-Headers: Content-Type
|
|
65
|
+
`;
|
|
66
|
+
if (hasWranglerConfig) {
|
|
67
|
+
// Native Cloudflare Git integration mode:
|
|
68
|
+
// Output directly to outDir/public
|
|
69
|
+
const publicDir = path.join(outDir, 'public');
|
|
70
|
+
fs.mkdirSync(publicDir, { recursive: true });
|
|
71
|
+
fs.writeFileSync(path.join(publicDir, 'workbench.js'), jsOutput.contents);
|
|
72
|
+
const jsSize = (jsOutput.contents.length / 1024).toFixed(1);
|
|
73
|
+
fs.writeFileSync(path.join(publicDir, 'workbench.css'), cssResult.css);
|
|
74
|
+
const cssSize = (cssResult.css.length / 1024).toFixed(1);
|
|
75
|
+
fs.writeFileSync(path.join(publicDir, '_headers'), headersContent);
|
|
76
|
+
stdout.success(`Build complete (JS: ${jsSize} KB, CSS: ${cssSize} KB)`);
|
|
77
|
+
stdout.dim('Using existing wrangler.toml for Cloudflare Git integration');
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Standalone mode: output to outDir with nested cloudflare-worker folder
|
|
81
|
+
const jsPath = path.join(outDir, 'workbench.js');
|
|
82
|
+
fs.writeFileSync(jsPath, jsOutput.contents);
|
|
83
|
+
const jsSize = (jsOutput.contents.length / 1024).toFixed(1);
|
|
84
|
+
const cssPath = path.join(outDir, 'workbench.css');
|
|
85
|
+
fs.writeFileSync(cssPath, cssResult.css);
|
|
86
|
+
const cssSize = (cssResult.css.length / 1024).toFixed(1);
|
|
87
|
+
// Generate Cloudflare static site files
|
|
88
|
+
const workerDir = path.join(outDir, 'cloudflare');
|
|
89
|
+
fs.mkdirSync(workerDir, { recursive: true });
|
|
90
|
+
const wranglerConfig = generateWranglerConfig();
|
|
91
|
+
fs.writeFileSync(path.join(workerDir, 'wrangler.jsonc'), wranglerConfig);
|
|
92
|
+
const publicDir = path.join(workerDir, 'public');
|
|
93
|
+
fs.mkdirSync(publicDir, { recursive: true });
|
|
94
|
+
fs.copyFileSync(jsPath, path.join(publicDir, 'workbench.js'));
|
|
95
|
+
fs.copyFileSync(cssPath, path.join(publicDir, 'workbench.css'));
|
|
96
|
+
fs.writeFileSync(path.join(publicDir, '_headers'), headersContent);
|
|
97
|
+
stdout.success(`Build complete (JS: ${jsSize} KB, CSS: ${cssSize} KB)`);
|
|
98
|
+
stdout.gap();
|
|
99
|
+
stdout.dim(`Deploy: cd ${workerDir} && npx wrangler deploy`);
|
|
100
|
+
}
|
|
101
|
+
stdout.gap();
|
|
102
|
+
stdout.dim('Usage: Add ?workbench=true to any engine preview URL');
|
|
103
|
+
stdout.gap();
|
|
104
|
+
}
|
|
105
|
+
function generateWranglerConfig() {
|
|
106
|
+
return `{
|
|
107
|
+
// Embeddables Workbench - Static Assets
|
|
108
|
+
// Deploy: npx wrangler deploy
|
|
109
|
+
"name": "embeddables-workbench",
|
|
110
|
+
"compatibility_date": "2024-01-01",
|
|
111
|
+
"assets": {
|
|
112
|
+
"directory": "./public"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
`;
|
|
116
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAaA,wBAAsB,QAAQ,CAAC,IAAI,EAAE;IACnC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,UAAU,GAAG,QAAQ,CAAA;CACnC,iBA2DA"}
|