Skip to content

Commit

Permalink
Import from deco instead of live (#23)
Browse files Browse the repository at this point in the history
* Import from deco instead of live

Signed-off-by: Marcos Candeia <[email protected]>

* Import analytics from deco-sites/std

Signed-off-by: Marcos Candeia <[email protected]>

---------

Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia authored Sep 4, 2023
1 parent afc063b commit 590cd9f
Show file tree
Hide file tree
Showing 57 changed files with 258 additions and 166 deletions.
2 changes: 1 addition & 1 deletion commerce/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App } from "$live/mod.ts";
import { App } from "deco/mod.ts";
import shopify, { Props as ShopifyProps } from "../shopify/mod.ts";
import vnda, { Props as VNDAProps } from "../vnda/mod.ts";
import vtex, { Props as VTEXProps } from "../vtex/mod.ts";
Expand Down
6 changes: 3 additions & 3 deletions compat/$live/handlers/devPage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Page } from "$live/blocks/page.ts";
import { context } from "$live/live.ts";
import { adminUrlFor, isAdmin } from "$live/utils/admin.ts";
import { Page } from "deco/blocks/page.ts";
import { context } from "deco/live.ts";
import { adminUrlFor, isAdmin } from "deco/utils/admin.ts";
import { ConnInfo } from "std/http/server.ts";
import Fresh from "../../../website/handlers/fresh.ts";
import { pageIdFromMetadata } from "../../../website/pages/Page.tsx";
Expand Down
4 changes: 2 additions & 2 deletions compat/$live/handlers/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Handler } from "$live/blocks/handler.ts";
import { FnContext } from "$live/types.ts";
import { Handler } from "deco/blocks/handler.ts";
import { FnContext } from "deco/types.ts";
import { Routes } from "../../../website/flags/audience.ts";
import { router } from "../../../website/handlers/router.ts";

Expand Down
16 changes: 8 additions & 8 deletions compat/$live/loaders/state.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Accounts } from "$live/blocks/account.ts";
import { Flag } from "$live/blocks/flag.ts";
import { Loader } from "$live/blocks/loader.ts";
import { Page } from "$live/blocks/page.ts";
import { Section } from "$live/blocks/section.ts";
import { Resolvable } from "$live/engine/core/resolver.ts";
import { Apps, LoaderContext } from "$live/mod.ts";
import { MiddlewareConfig } from "$live/routes/_middleware.ts";
import { Accounts } from "deco/blocks/account.ts";
import { Flag } from "deco/blocks/flag.ts";
import { Loader } from "deco/blocks/loader.ts";
import { Page } from "deco/blocks/page.ts";
import { Section } from "deco/blocks/section.ts";
import { Resolvable } from "deco/engine/core/resolver.ts";
import { Apps, LoaderContext } from "deco/mod.ts";
import { MiddlewareConfig } from "deco/routes/_middleware.ts";

/**
* @titleBy key
Expand Down
8 changes: 4 additions & 4 deletions compat/$live/mod.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// deno-lint-ignore-file no-explicit-any
import type { App } from "$live/mod.ts";
import type { App } from "deco/mod.ts";
// this should not be changed to $live because newly created versions might not include live.gen.ts.
import { buildSourceMap } from "$live/blocks/utils.tsx";
import type { Manifest as LiveManifest } from "$live/live.gen.ts";
import { buildSourceMap } from "deco/blocks/utils.tsx";
import type { Manifest as LiveManifest } from "deco/live.gen.ts";

import type { Manifest as WebSiteManifest } from "../../website/manifest.gen.ts";
import webSite, { Props } from "../../website/mod.ts";
import type { Manifest as WorkflowsManifest } from "../../workflows/manifest.gen.ts";

import { SourceMap } from "$live/blocks/app.ts";
import { SourceMap } from "deco/blocks/app.ts";
import workflows from "../../workflows/mod.ts";
import manifest, { Manifest as _Manifest } from "./manifest.gen.ts";

Expand Down
4 changes: 2 additions & 2 deletions compat/$live/sections/Conditional_Beta.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Section } from "$live/blocks/section.ts";
import { Section } from "deco/blocks/section.ts";
import { renderSection } from "../../../website/pages/Page.tsx";
import withConditions, {
Props as ConditionalProps,
} from "$live/utils/conditionals.ts";
} from "deco/utils/conditionals.ts";

export interface Props {
sections: Section[];
Expand Down
4 changes: 2 additions & 2 deletions compat/$live/sections/PageInclude.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Page } from "$live/blocks/page.ts";
import { notUndefined } from "$live/engine/core/utils.ts";
import { Page } from "deco/blocks/page.ts";
import { notUndefined } from "deco/engine/core/utils.ts";

import {
Props as LivePageProps,
Expand Down
2 changes: 1 addition & 1 deletion compat/$live/sections/Slot.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSection, Section } from "$live/blocks/section.ts";
import { isSection, Section } from "deco/blocks/section.ts";

export type WellKnownSlots =
| "content"
Expand Down
4 changes: 2 additions & 2 deletions compat/$live/sections/UseSlot.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Section } from "$live/blocks/section.ts";
import { notUndefined } from "$live/engine/core/utils.ts";
import { Section } from "deco/blocks/section.ts";
import { notUndefined } from "deco/engine/core/utils.ts";
import { useLivePageContext } from "../../../website/pages/Page.tsx";
import { WellKnownSlots } from "../sections/Slot.tsx";

Expand Down
11 changes: 5 additions & 6 deletions compat/std/deps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export type { ConfigShopify as ShopifyAccount } from "https://denopkg.com/deco-sites/[email protected]/commerce/shopify/client.ts";
export type { Manifest as StdManifest } from "https://denopkg.com/deco-sites/[email protected]/live.gen.ts";
export type { Account as VNDAAccount } from "https://denopkg.com/deco-sites/[email protected]/packs/vnda/accounts/vnda.ts";
export type { Account as VTEXAccount } from "https://denopkg.com/deco-sites/[email protected]/packs/vtex/accounts/vtex.ts";
export { default as Analytics } from "https://denopkg.com/deco-sites/[email protected]/sections/Analytics.tsx";
export { default as VTEXCompat } from "https://denopkg.com/deco-sites/[email protected]/sections/VTEXPortalDataLayerCompatibility.tsx";
export type { ConfigShopify as ShopifyAccount } from "https://denopkg.com/deco-sites/[email protected]/commerce/shopify/client.ts";
export type { Manifest as StdManifest } from "https://denopkg.com/deco-sites/[email protected]/live.gen.ts";
export type { Account as VNDAAccount } from "https://denopkg.com/deco-sites/[email protected]/packs/vnda/accounts/vnda.ts";
export type { Account as VTEXAccount } from "https://denopkg.com/deco-sites/[email protected]/packs/vtex/accounts/vtex.ts";
export { default as VTEXCompat } from "https://denopkg.com/deco-sites/[email protected]/sections/VTEXPortalDataLayerCompatibility.tsx";
83 changes: 42 additions & 41 deletions compat/std/mod.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// deno-lint-ignore-file no-explicit-any
export { onBeforeResolveProps } from "../../website/mod.ts";
import { SourceMap } from "$live/blocks/app.ts";
import { buildSourceMap } from "$live/blocks/utils.tsx";
import type { App, AppManifest } from "$live/mod.ts";
import { SourceMap } from "deco/blocks/app.ts";
import { buildSourceMap } from "deco/blocks/utils.tsx";
import type { App, AppManifest } from "deco/mod.ts";
import type { PickByValue } from "https://esm.sh/[email protected]";
import $live from "../$live/mod.ts";
import commerce, { Props as CommerceProps } from "../../commerce/mod.ts";
import type { Manifest as ShopifyManifest } from "../../shopify/manifest.gen.ts";
import shopify, { Props as ShopifyProps } from "../../shopify/mod.ts";
import type { Manifest as VNDAManifest } from "../../vnda/manifest.gen.ts";
import vnda, { Props as VNDAProps } from "../../vnda/mod.ts";
import type { Manifest as VTEXManifest } from "../../vtex/manifest.gen.ts";
import vtex, { Props as VTEXProps } from "../../vtex/mod.ts";
import commerce, { Props as CommerceProps } from "../../commerce/mod.ts";

import type { Manifest as WebSiteManifest } from "../../website/manifest.gen.ts";
import type {
Expand All @@ -31,32 +31,32 @@ export type ManifestWithStdCompat =
export type ManifestMappings = Partial<
{
[
blockType in keyof Omit<
StdManifest,
"name" | "baseUrl" | "routes" | "islands"
>
blockType in keyof Omit<
StdManifest,
"name" | "baseUrl" | "routes" | "islands"
>
]: {
[
blockKey in
& Exclude<
(keyof Omit<
StdManifest,
"name" | "baseUrl" | "routes" | "islands"
>[blockType]),
blockType extends keyof _Manifest ? keyof _Manifest[blockType] : ""
>
& `deco-sites/std/${string}`
blockKey in
& Exclude<
(keyof Omit<
StdManifest,
"name" | "baseUrl" | "routes" | "islands"
>[blockType]),
blockType extends keyof _Manifest ? keyof _Manifest[blockType] : ""
>
& `deco-sites/std/${string}`
]: blockType extends
keyof (ShopifyManifest & VNDAManifest & VTEXManifest & WebSiteManifest)
?
| (keyof (
& ShopifyManifest
& VNDAManifest
& VTEXManifest
& WebSiteManifest
)[blockType])
| null
: string;
keyof (ShopifyManifest & VNDAManifest & VTEXManifest & WebSiteManifest)
?
| (keyof (
& ShopifyManifest
& VNDAManifest
& VTEXManifest
& WebSiteManifest
)[blockType])
| null
: string;
};
}
>;
Expand Down Expand Up @@ -106,6 +106,7 @@ const manifestMappings = {
"deco-sites/std/loaders/nuvemShop/nuvemShopProductList.ts": NOT_IMPLEMENTED,
"deco-sites/std/loaders/nuvemShop/nuvemShopProductListingPage.ts":
NOT_IMPLEMENTED,
"deco-sites/std/loaders/vtex/legacy/suggestions.ts": "vtex/loaders/legacy/suggestions.ts",
"deco-sites/std/loaders/vnda/cart.ts": "vnda/loaders/cart.ts",
"deco-sites/std/loaders/vnda/productDetailsPage.ts":
"vnda/loaders/productDetailsPage.ts",
Expand Down Expand Up @@ -154,9 +155,9 @@ const manifestMappings = {
"deco-sites/std/actions/vnda/cart/addItem.ts":
"vnda/actions/cart/addItem.ts",
"deco-sites/std/actions/vnda/cart/setShippingAddress.ts":
"vnda/actions/cart/setShippingAddress.ts",
NOT_IMPLEMENTED,
"deco-sites/std/actions/vnda/cart/updateCoupon.ts":
"vnda/actions/cart/updateCoupon.ts",
NOT_IMPLEMENTED,
"deco-sites/std/actions/vnda/cart/updateItem.ts":
"vnda/actions/cart/updateItem.ts",
"deco-sites/std/actions/vtex/analytics/sendEvent.ts":
Expand Down Expand Up @@ -198,17 +199,17 @@ const manifestMappings = {
type Mappings = typeof manifestMappings;
type Manifest = {
[key in keyof ManifestWithStdCompat]: key extends keyof Mappings ? {
[
blockKey in keyof Omit<
ManifestWithStdCompat[key],
keyof PickByValue<Mappings[key], null>
>
]: Omit<
ManifestWithStdCompat[key],
keyof PickByValue<Mappings[key], null>
>[blockKey];
}
: ManifestWithStdCompat[key];
[
blockKey in keyof Omit<
ManifestWithStdCompat[key],
keyof PickByValue<Mappings[key], null>
>
]: Omit<
ManifestWithStdCompat[key],
keyof PickByValue<Mappings[key], null>
>[blockKey];
}
: ManifestWithStdCompat[key];
};

type AvailableCommerceProps = CommerceProps["commerce"];
Expand Down Expand Up @@ -311,7 +312,7 @@ export default function Std(
}
for (
const [target, { sourceMap: appSourceMap, manifest: appManifest }]
of Object.entries(targetApps)
of Object.entries(targetApps)
) {
if (to?.startsWith(target)) {
// @ts-ignore: blockkeys and from/to always exists for those types
Expand Down
2 changes: 1 addition & 1 deletion compat/std/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forApp } from "$live/clients/withManifest.ts";
import { forApp } from "deco/clients/withManifest.ts";
import app from "./mod.ts";

export const Runtime = forApp<ReturnType<typeof app>>();
94 changes: 93 additions & 1 deletion compat/std/sections/Analytics.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,93 @@
export { Analytics as default } from "../deps.ts";
import { context } from "deco/live.ts";
import GoogleTagManager from "partytown/integrations/GTM.tsx";
import GoogleTagScript from "partytown/integrations/GTAG.tsx";
import Script from "partytown/Script.tsx";
import { AnalyticsEvent } from "../../../commerce/types.ts";

/**
* This function handles all ecommerce analytics events.
* Add another ecommerce analytics modules here.
*/
const sendAnalyticsEvent = <T extends AnalyticsEvent>(
event: T,
) => {
window.dataLayer && window.dataLayer.push({ ecommerce: null });
window.dataLayer && window.dataLayer.push({
event: event.name,
ecommerce: event.params,
});

window.jitsu && window.jitsu("track", "ecommerce", event);
};

export interface Props {
/**
* @description google tag manager container id. For more info: https://developers.google.com/tag-platform/tag-manager/web#standard_web_page_installation .
*/
trackingIds?: string[];
/**
* @title GA Measurement Ids
* @label measurement id
* @description the google analytics property measurement id. For more info: https://support.google.com/analytics/answer/9539598
*/
googleAnalyticsIds?: string[];
/**
* @description custom url for serving google tag manager. Set either this url or the tracking id
*/
src?: string;
/**
* @description run GTM directly on the main thread, without Partytown. This is useful for debugging purposes. Default: false
*/
dangerouslyRunOnMainThread?: boolean;
}

export default function Analtyics(
{ trackingIds, src, dangerouslyRunOnMainThread, googleAnalyticsIds }: Props,
) {
const isDeploy = !!context.isDeploy;
return (
<>
{/* TODO: Add debug from query string @author Igor Brasileiro */}
{/* Add Tag Manager script during production only. To test it locally remove the condition */}
{isDeploy && trackingIds && (
trackingIds.map((trackingId) => (
<GoogleTagManager
trackingId={trackingId.trim()}
dangerouslyRunOnMainThread={dangerouslyRunOnMainThread}
/>
))
)}
{isDeploy && googleAnalyticsIds && (
googleAnalyticsIds.map((trackingId) => (
<GoogleTagScript
trackingId={trackingId.trim()}
dangerouslyRunOnMainThread={dangerouslyRunOnMainThread}
/>
))
)}
{isDeploy && src && (
<GoogleTagManager
src={src}
dangerouslyRunOnMainThread={dangerouslyRunOnMainThread}
/>
)}

<Script
dangerouslySetInnerHTML={{
// add all globals variables here
__html:
`debugGlobals = () => { console.table([["datalayer", dataLayer]]); }`,
}}
forward={["debugGlobals"]}
/>
<script
type="module"
id="analytics-script"
dangerouslySetInnerHTML={{
__html:
`window.DECO_SITES_STD = { sendAnalyticsEvent: ${sendAnalyticsEvent.toString()} }`,
}}
/>
</>
);
}
2 changes: 1 addition & 1 deletion decohub/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { App, FnContext } from "$live/mod.ts";
import type { App, FnContext } from "deco/mod.ts";
import manifest, { Manifest } from "./manifest.gen.ts";

// deno-lint-ignore ban-types
Expand Down
14 changes: 7 additions & 7 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"lock": false,
"tasks": {
"check": "deno fmt && deno lint",
"release": "deno eval 'import \"$live/scripts/release.ts\"'",
"start": "deno eval 'import \"$live/scripts/apps/bundle.ts\"'",
"link": "deno eval 'import \"$live/scripts/apps/link.ts\"'",
"unlink": "deno eval 'import \"$live/scripts/apps/unlink.ts\"'",
"serve": "deno eval 'import \"$live/scripts/apps/serve.ts\"'",
"watcher": "deno eval 'import \"$live/scripts/apps/watcher.ts\"'",
"update": "deno eval 'import \"$live/scripts/update.ts\"'",
"release": "deno eval 'import \"deco/scripts/release.ts\"'",
"start": "deno eval 'import \"deco/scripts/apps/bundle.ts\"'",
"link": "deno eval 'import \"deco/scripts/apps/link.ts\"'",
"unlink": "deno eval 'import \"deco/scripts/apps/unlink.ts\"'",
"serve": "deno eval 'import \"deco/scripts/apps/serve.ts\"'",
"watcher": "deno eval 'import \"deco/scripts/apps/watcher.ts\"'",
"update": "deno eval 'import \"deco/scripts/update.ts\"'",
"new": "deno run -A ./scripts/new.ts"
},
"githooks": {
Expand Down
2 changes: 1 addition & 1 deletion handlebars/deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as HTMLRenderer } from "https://denopkg.com/deco-sites/std@1.20.11/components/HTMLRenderer.tsx";
export { default as HTMLRenderer } from "https://denopkg.com/deco-sites/std@1.21.7/components/HTMLRenderer.tsx";
2 changes: 1 addition & 1 deletion handlebars/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { App, AppContext as AC } from "$live/mod.ts";
import type { App, AppContext as AC } from "deco/mod.ts";
import { SourceMap } from "deco/blocks/app.ts";
import { SectionModule } from "deco/blocks/section.ts";
import { JSONSchema7 } from "deco/deps.ts";
Expand Down
4 changes: 2 additions & 2 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"imports": {
"$live/": "https://denopkg.com/deco-cx/[email protected]/",
"$fresh/": "https://denopkg.com/denoland/[email protected]/",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
Expand All @@ -10,6 +9,7 @@
"std/": "https://deno.land/[email protected]/",
"partytown/": "https://deno.land/x/[email protected]/",
"deco-sites/std/": "https://denopkg.com/deco-sites/[email protected]/",
"deco/": "https://denopkg.com/deco-cx/[email protected]/"
"deco/": "https://deno.land/x/[email protected]/",
"$live/": "https://deno.land/x/[email protected]/"
}
}
Loading

0 comments on commit 590cd9f

Please sign in to comment.