cloudcommerce 2.6.0 → 2.6.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.
Files changed (62) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/CHANGELOG.md +11 -0
  3. package/ecomplus-stores/barradoce/.devcontainer/devcontainer.json +10 -4
  4. package/ecomplus-stores/barradoce/.vscode/settings.json +3 -0
  5. package/ecomplus-stores/barradoce/functions/many/package.json +3 -3
  6. package/ecomplus-stores/barradoce/functions/ssr/package.json +6 -6
  7. package/ecomplus-stores/barradoce/functions/ssr/src/components/CartSidebar.vue +11 -11
  8. package/ecomplus-stores/barradoce/functions/ssr/src/components/ProductDetails.vue +23 -13
  9. package/ecomplus-stores/barradoce/functions/ssr/src/components/SearchModal.vue +9 -6
  10. package/ecomplus-stores/barradoce/functions/ssr/src/components/SearchShowcase.vue +19 -17
  11. package/ecomplus-stores/barradoce/functions/ssr/src/components/ShippingCalculator.vue +10 -10
  12. package/ecomplus-stores/barradoce/functions/ssr/src/main/content/Sections.astro +3 -0
  13. package/ecomplus-stores/barradoce/functions/ssr/src/state/midd-search-engine.ts +19 -0
  14. package/ecomplus-stores/barradoce/functions/with-apps/package.json +3 -3
  15. package/ecomplus-stores/barradoce/package.json +2 -2
  16. package/ecomplus-stores/barradoce/tailwind.config.cjs +5 -3
  17. package/package.json +2 -2
  18. package/packages/api/package.json +1 -1
  19. package/packages/apps/affiliate-program/package.json +1 -1
  20. package/packages/apps/correios/package.json +1 -1
  21. package/packages/apps/custom-payment/package.json +1 -1
  22. package/packages/apps/custom-shipping/package.json +1 -1
  23. package/packages/apps/datafrete/package.json +1 -1
  24. package/packages/apps/discounts/package.json +1 -1
  25. package/packages/apps/emails/package.json +1 -1
  26. package/packages/apps/fb-conversions/package.json +1 -1
  27. package/packages/apps/flash-courier/package.json +1 -1
  28. package/packages/apps/frenet/package.json +1 -1
  29. package/packages/apps/galaxpay/package.json +1 -1
  30. package/packages/apps/google-analytics/package.json +1 -1
  31. package/packages/apps/jadlog/package.json +1 -1
  32. package/packages/apps/loyalty-points/package.json +1 -1
  33. package/packages/apps/mandae/package.json +1 -1
  34. package/packages/apps/melhor-envio/package.json +1 -1
  35. package/packages/apps/mercadopago/package.json +1 -1
  36. package/packages/apps/pagarme/package.json +1 -1
  37. package/packages/apps/pagarme-v5/package.json +1 -1
  38. package/packages/apps/paghiper/package.json +1 -1
  39. package/packages/apps/pix/package.json +1 -1
  40. package/packages/apps/tiny-erp/package.json +1 -1
  41. package/packages/apps/webhooks/package.json +1 -1
  42. package/packages/cli/package.json +1 -1
  43. package/packages/config/package.json +1 -1
  44. package/packages/emails/package.json +1 -1
  45. package/packages/eslint/package.json +1 -1
  46. package/packages/events/package.json +1 -1
  47. package/packages/feeds/package.json +1 -1
  48. package/packages/firebase/package.json +1 -1
  49. package/packages/i18n/package.json +1 -1
  50. package/packages/modules/package.json +1 -1
  51. package/packages/passport/package.json +1 -1
  52. package/packages/ssr/package.json +1 -1
  53. package/packages/storefront/package.json +1 -1
  54. package/packages/storefront/src/lib/composables/use-search-modal.ts +3 -1
  55. package/packages/storefront/src/lib/composables/use-search-showcase.ts +2 -1
  56. package/packages/storefront/src/lib/layouts/BaseHead.astro +2 -1
  57. package/packages/storefront/src/lib/layouts/use-page-main.ts +9 -5
  58. package/packages/storefront/src/lib/state/search-engine.ts +21 -11
  59. package/packages/test-base/package.json +1 -1
  60. package/packages/types/package.json +1 -1
  61. package/packages/storefront/src/lib/scripts/experimental-web-ide.ts +0 -29
  62. package/packages/storefront/src/web-ide/webcontainer.ts +0 -104
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-datafrete",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Datafrete shipping gateway ",
6
6
  "main": "lib/datafrete.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-discounts",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app for complex discount rules",
6
6
  "main": "lib/discounts.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-emails",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce default transactional email app",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-fb-conversions",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to send carts/orders to Facebook Conversions API",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-flash-courier",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Flash Courier",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-frenet",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app for Frenet shipping calculation",
6
6
  "main": "lib/frenet.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-galaxpay",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Galax Pay for recurring payments",
6
6
  "main": "lib/galaxpay.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-google-analytics",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to send carts/orders events to GA Measurement Protocol",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-jadlog",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app for Jadlog shipping calculation",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-loyalty-points",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to handle simple loyalty points programs",
6
6
  "main": "lib/loyalty-points.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-mandae",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Mandaê shipping intermediator",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-melhor-envio",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Melhor Envio",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-mercadopago",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Mercado Pago",
6
6
  "main": "lib/mercadopago.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-pagarme",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Pagar.me",
6
6
  "main": "lib/pagarme.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-pagarme-v5",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Pagar.me API v5 with recurring payments",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-paghiper",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate PagHiper",
6
6
  "main": "lib/paghiper.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-pix",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Pix API (Bacen)",
6
6
  "main": "lib/pix.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-tiny-erp",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app for Tiny ERP",
6
6
  "main": "lib/tiny-erp.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-webhooks",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app for general order webhooks",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/cli",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce CLI tools",
6
6
  "bin": {
7
7
  "cloudcommerce": "./bin/run.mjs"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/config",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce base config",
6
6
  "main": "lib/config.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/emails",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce email sender",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/eslint",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce ESLint config",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/events",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce app events",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/feeds",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce catalog feeds",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/firebase",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce on Firebase",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/i18n",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce i18n",
6
6
  "main": "lib/all.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/modules",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce modules API",
6
6
  "main": "lib/index.cjs",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/passport",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce customers authentication (passport) API",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/ssr",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce storefront SSR",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/storefront",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce storefront with Astro",
6
6
  "bin": {
7
7
  "storefront": "./scripts/build-prod.sh"
@@ -1,4 +1,5 @@
1
1
  import type { Categories } from '@cloudcommerce/api/types';
2
+ import type { SearchEngineInstance } from '@@sf/state/search-engine';
2
3
  import { ref, watch, toRef } from 'vue';
3
4
  import Wade from 'wade';
4
5
  import { clearAccents } from '@@sf/sf-lib';
@@ -8,6 +9,7 @@ export interface Props {
8
9
  term: string;
9
10
  fetchDebounce?: number;
10
11
  productsLimit?: number;
12
+ searchEngine?: SearchEngineInstance;
11
13
  }
12
14
 
13
15
  const wadeDocs: Array<{
@@ -39,7 +41,7 @@ if (wadeDocs.length) {
39
41
  }
40
42
 
41
43
  export const useSearchModal = (props: Props) => {
42
- const searchEngine = new SearchEngine({
44
+ const searchEngine = props.searchEngine || new SearchEngine({
43
45
  debounce: props.fetchDebounce || 300,
44
46
  });
45
47
  searchEngine.pageSize.value = props.productsLimit || 12;
@@ -30,6 +30,7 @@ export interface Props {
30
30
  ssrError?: string | null;
31
31
  canUseUrlParams?: boolean;
32
32
  showcase?: Ref<HTMLElement | null>;
33
+ searchEngine?: SearchEngineInstance;
33
34
  }
34
35
 
35
36
  const useSearchShowcase = (props: Props) => {
@@ -43,7 +44,7 @@ const useSearchShowcase = (props: Props) => {
43
44
  }
44
45
  }
45
46
  const products = shallowReactive<SearchItem[]>(props.products || []);
46
- const searchEngine = new SearchEngine({ debounce: 50 });
47
+ const searchEngine = props.searchEngine || new SearchEngine({ debounce: 50 });
47
48
  if (term === undefined && !import.meta.env.SSR) {
48
49
  term = new URLSearchParams(window.location.search).get('q') || null;
49
50
  }
@@ -168,6 +168,7 @@ const inlineJSONLd = JSON.stringify({
168
168
  url: `https://${domain}/`,
169
169
  logo: `https://${domain}${settings.logo}`,
170
170
  });
171
+ const generator = `e-com.plus @cloudcommerce/storefront, ${Astro.generator}`;
171
172
  ---
172
173
 
173
174
  <meta charset="UTF-8">
@@ -179,7 +180,7 @@ const inlineJSONLd = JSON.stringify({
179
180
  {title && <title>{title}</title>}
180
181
  {description && <meta name="description" content={description}>}
181
182
  <meta name="author" content={settings.name}>
182
- <meta name="generator" content={Astro.generator} />
183
+ <meta name="generator" content={generator}>
183
184
  <link rel="canonical" href={canonicalUrl} />
184
185
  {shortcutIcon && <link rel="apple-touch-icon" href={shortcutIcon} />}
185
186
  <meta name="apple-mobile-web-app-capable" content="yes">
@@ -12,6 +12,7 @@ export interface Props {
12
12
  routeContext: RouteContext;
13
13
  handleCustomSection?: (type: `${string}:${string}`, content: Record<string, any>) =>
14
14
  Promise<{ props: Record<string, any> }>;
15
+ searchEngine?: UseSearchShowcaseProps['searchEngine'];
15
16
  }
16
17
 
17
18
  type PageContentHero = Exclude<PageContent['hero'], undefined>;
@@ -48,7 +49,7 @@ type CustomSection = { type: `${string}:${string}`, props: any };
48
49
  type ProductDetailsProps = { hasDescription?: boolean, hasSpecifications?: boolean };
49
50
 
50
51
  export const usePageSections = async <T extends CustomSection = CustomSection>
51
- ({ routeContext, handleCustomSection }: Props) => {
52
+ ({ routeContext, handleCustomSection, searchEngine }: Props) => {
52
53
  const { cmsContent } = routeContext;
53
54
  let sectionsContent = cmsContent?.sections;
54
55
  if (
@@ -181,11 +182,14 @@ export const usePageSections = async <T extends CustomSection = CustomSection>
181
182
  props.term = routeContext.searchPageTerm || null;
182
183
  }
183
184
  if (props.term !== undefined || props.fixedParams) {
184
- const { searchEngine, fetching } = useSearchShowcase(props);
185
+ const {
186
+ searchEngine: resultSearchEngine,
187
+ fetching,
188
+ } = useSearchShowcase({ ...props, searchEngine });
185
189
  await fetching;
186
- props.products = searchEngine.products;
187
- props.resultMeta = searchEngine.meta;
188
- props.ssrError = searchEngine.fetchError.value?.message;
190
+ props.products = resultSearchEngine.products;
191
+ props.resultMeta = resultSearchEngine.meta;
192
+ props.ssrError = resultSearchEngine.fetchError.value?.message;
189
193
  }
190
194
  sections[index] = { type, props };
191
195
  return;
@@ -68,6 +68,8 @@ export const search = async ({
68
68
  return response;
69
69
  };
70
70
 
71
+ type SearchOptions = Parameters<typeof search>[0];
72
+
71
73
  export class SearchEngine {
72
74
  fields?: readonly string[];
73
75
  term = ref<string | null>(null);
@@ -76,6 +78,7 @@ export class SearchEngine {
76
78
  params = reactive<Exclude<ApiConfig['params'], string | undefined>>({});
77
79
  pageSize = ref(24);
78
80
  pageNumber = ref(1);
81
+ #middlewares: Array<(opt: SearchOptions) => void> = [];
79
82
  #isFetching = ref(false);
80
83
  isFetching = computed(() => this.#isFetching.value);
81
84
  #wasFetched = ref(false);
@@ -130,18 +133,22 @@ export class SearchEngine {
130
133
  });
131
134
  }
132
135
  let response: Awaited<ReturnType<typeof search>> | null | undefined;
136
+ const searchOptions = {
137
+ term: this.term.value,
138
+ params: {
139
+ ...this.params,
140
+ limit,
141
+ offset,
142
+ count: this.isWithCount.value || undefined,
143
+ buckets: this.isWithBuckets.value || undefined,
144
+ },
145
+ fields: this.fields,
146
+ };
133
147
  try {
134
- response = await this.#search({
135
- term: this.term.value,
136
- params: {
137
- ...this.params,
138
- limit,
139
- offset,
140
- count: this.isWithCount.value || undefined,
141
- buckets: this.isWithBuckets.value || undefined,
142
- },
143
- fields: this.fields,
144
- });
148
+ for (let i = 0; i < this.#middlewares.length; i++) {
149
+ this.#middlewares[i](searchOptions);
150
+ }
151
+ response = await this.#search(searchOptions);
145
152
  } catch (err: any) {
146
153
  if (this.#fulfillFetching) {
147
154
  this.#fetchError.value = err;
@@ -162,6 +169,9 @@ export class SearchEngine {
162
169
  }
163
170
  }
164
171
 
172
+ addMiddleware(cb: (options: SearchOptions) => void) {
173
+ this.#middlewares.push(cb);
174
+ }
165
175
  setResult(data: Partial<SearchResult<'v1'>>) {
166
176
  if (data.meta) {
167
177
  Object.assign(this.meta, data.meta);
@@ -2,7 +2,7 @@
2
2
  "name": "@cloudcommerce/test-base",
3
3
  "private": true,
4
4
  "type": "module",
5
- "version": "2.6.0",
5
+ "version": "2.6.1",
6
6
  "description": "E-Com Plus Cloud Commerce basic setup for testing",
7
7
  "main": "lib/index.js",
8
8
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/types",
3
3
  "type": "module",
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "E-Com Plus Cloud Commerce reusable type definitions",
6
6
  "main": "index.ts",
7
7
  "repository": {
@@ -1,29 +0,0 @@
1
- import { initVM } from '../../web-ide/webcontainer';
2
-
3
- const cliTextareaId = 'IDEcli';
4
- const serverIframeId = 'IDEserver';
5
-
6
- if (!import.meta.env.SSR) {
7
- const cliTextarea = document.createElement('textarea');
8
- cliTextarea.id = cliTextareaId;
9
- document.body.appendChild(cliTextarea);
10
- const serverIframe = document.createElement('iframe');
11
- serverIframe.id = serverIframeId;
12
- serverIframe.width = '100%';
13
- serverIframe.height = '100%';
14
- serverIframe.style.cssText = 'border: 1px solid #EEE; height: calc(100vh - 30px)';
15
- document.body.appendChild(serverIframe);
16
-
17
- const initIDE = async () => {
18
- const repo = 'ecomplus/store';
19
- const { vm, startDevServer } = await initVM({ repo, cliTextarea });
20
- vm.on('server-ready', (port, href) => {
21
- console.log({ port, href });
22
- const url = new URL(href);
23
- url.searchParams.set('webcontainer', 'dev');
24
- serverIframe.src = `${url}`;
25
- });
26
- startDevServer();
27
- };
28
- initIDE();
29
- }
@@ -1,104 +0,0 @@
1
- import { WebContainer } from '@webcontainer/api';
2
-
3
- export const genContainerFiles = ({ repo, ghToken, repoDir }: {
4
- repo: string,
5
- ghToken?: string,
6
- repoDir: string,
7
- }) => ({
8
- 'git.js': {
9
- file: {
10
- contents: `
11
- import fs from 'node:fs';
12
- import { join as joinPath } from 'node:path';
13
- import { clone, pull } from 'isomorphic-git';
14
- import * as http from 'isomorphic-git/http/node/index.cjs';
15
- const dir = joinPath(process.cwd(), '${repoDir}');
16
- const isClone = process.argv.find((val) => val === '--clone');
17
- const options = {
18
- fs,
19
- http,
20
- dir,
21
- singleBranch: true,
22
- ref: 'c59d5884ab86899da1c7fd154bf4009cac0a60e9',
23
- };
24
- ${(ghToken
25
- ? `
26
- options.oauth2format = 'github';
27
- options.token = '${ghToken}';`
28
- : '')}
29
- if (isClone) {
30
- options.url = 'https://github.com/${repo}.git';
31
- options.depth = 1;
32
- clone(options);
33
- } else {
34
- pull(options);
35
- }
36
- `,
37
- },
38
- },
39
- 'package.json': {
40
- file: {
41
- contents: `
42
- {
43
- "name": "git-app",
44
- "version": "1.0.0",
45
- "type": "module",
46
- "private": true,
47
- "description": "",
48
- "author": "",
49
- "license": "ISC",
50
- "scripts": {
51
- "git:clone": "node git.js --clone",
52
- "git:pull": "node git.js --pull"
53
- },
54
- "dependencies": {
55
- "isomorphic-git": "^1.25.3"
56
- }
57
- }`,
58
- },
59
- },
60
- });
61
-
62
- export const initVM = async ({ repo, ghToken, cliTextarea }: {
63
- repo: string,
64
- ghToken?: string,
65
- cliTextarea: HTMLTextAreaElement,
66
- }) => {
67
- const vm = await WebContainer.boot();
68
- const repoDir = 'store';
69
- const files = genContainerFiles({ repo, ghToken, repoDir });
70
- await vm.mount(files);
71
- const exec = async (command: string, args: string[]) => {
72
- const cliArgs = args.reduce((acc, opt) => `${acc} ${opt}`, '');
73
- const cli = `$ ${command}${cliArgs}\n`;
74
- cliTextarea.value += cli;
75
- const proc = await vm.spawn(command, args);
76
- if (import.meta.env.DEV || (window as any).DEBUG) {
77
- proc.output.pipeTo(new WritableStream({
78
- write(stdout) {
79
- console.debug?.('webcontainer', { stdout });
80
- },
81
- }));
82
- }
83
- if (await proc.exit !== 0) {
84
- throw new Error(`${command} failed`);
85
- }
86
- };
87
- await exec('npm', ['install']);
88
- await exec('npm', ['run', 'git:clone']);
89
- await exec('npm', ['--prefix', repoDir, 'ci', '--omit=dev', '--ignore-scripts']);
90
- const ssrDir = `${repoDir}/functions/ssr`;
91
- await exec('npm', ['--prefix', ssrDir, 'ci']);
92
- await vm.fs.writeFile(
93
- `${ssrDir}/.env`,
94
- `ECOM_STORE_ID=${window.ECOM_STORE_ID}\n`,
95
- );
96
- const startDevServer = async () => {
97
- await exec('npm', ['--prefix', repoDir, 'run', 'dev']);
98
- };
99
- return {
100
- vm,
101
- vmExec: exec,
102
- startDevServer,
103
- };
104
- };