@ikas/storefront-cmd 4.0.0-alpha.49 → 4.0.0-alpha.50

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 (46) hide show
  1. package/package.json +6 -6
  2. package/{build/index.d.ts → src/index.ts} +4 -3
  3. package/src/scripts/generators/api/index.ts +27 -0
  4. package/src/scripts/generators/api/info.ts +47 -0
  5. package/src/scripts/generators/components/index.ts +270 -0
  6. package/src/scripts/generators/config/content.ts +170 -0
  7. package/src/scripts/generators/config/index.ts +113 -0
  8. package/{build/scripts/generators/index.d.ts → src/scripts/generators/index.ts} +6 -6
  9. package/src/scripts/generators/pages/index.ts +102 -0
  10. package/src/scripts/generators/pages/info.ts +161 -0
  11. package/src/scripts/generators/theme/index.ts +63 -0
  12. package/src/scripts/generators/types/index.ts +526 -0
  13. package/src/scripts/ikas.ts +45 -0
  14. package/src/scripts/theme-build/index.ts +99 -0
  15. package/src/utils/fs.ts +93 -0
  16. package/src/utils/helper.ts +20 -0
  17. package/build/_virtual/_cloneBuffer.js +0 -1
  18. package/build/_virtual/_commonjsHelpers.js +0 -1
  19. package/build/_virtual/_nodeUtil.js +0 -1
  20. package/build/_virtual/isBuffer.js +0 -1
  21. package/build/index.js +0 -1
  22. package/build/scripts/generators/api/index.d.ts +0 -5
  23. package/build/scripts/generators/api/index.js +0 -1
  24. package/build/scripts/generators/api/info.d.ts +0 -12
  25. package/build/scripts/generators/api/info.js +0 -1
  26. package/build/scripts/generators/components/index.d.ts +0 -11
  27. package/build/scripts/generators/components/index.js +0 -1
  28. package/build/scripts/generators/config/content.d.ts +0 -58
  29. package/build/scripts/generators/config/content.js +0 -1
  30. package/build/scripts/generators/config/index.d.ts +0 -9
  31. package/build/scripts/generators/config/index.js +0 -1
  32. package/build/scripts/generators/pages/index.d.ts +0 -7
  33. package/build/scripts/generators/pages/index.js +0 -1
  34. package/build/scripts/generators/pages/info.d.ts +0 -14
  35. package/build/scripts/generators/pages/info.js +0 -1
  36. package/build/scripts/generators/theme/index.d.ts +0 -6
  37. package/build/scripts/generators/theme/index.js +0 -1
  38. package/build/scripts/generators/types/index.d.ts +0 -19
  39. package/build/scripts/generators/types/index.js +0 -1
  40. package/build/scripts/ikas.d.ts +0 -1
  41. package/build/scripts/theme-build/index.d.ts +0 -3
  42. package/build/scripts/theme-build/index.js +0 -1
  43. package/build/utils/fs.d.ts +0 -28
  44. package/build/utils/fs.js +0 -1
  45. package/build/utils/helper.d.ts +0 -2
  46. package/build/utils/helper.js +0 -1
@@ -0,0 +1,102 @@
1
+ import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
+ import path from "path";
3
+ import { createFile, deleteDirContent } from "../../../utils/fs";
4
+ import {
5
+ PageInfo,
6
+ PAGE_INFO,
7
+ CHECKOUT_PAGE_CONTENT,
8
+ EDITOR_PAGE_CONTENT,
9
+ } from "./info";
10
+
11
+ export class PageGenerator {
12
+ static async generate(workingDir?: string) {
13
+ const pagesDir = path.join(workingDir || process.cwd(), "src", "pages");
14
+ await deleteDirContent(pagesDir, ["_app.tsx", "_document.tsx", "api"]);
15
+
16
+ let pagesGenerateSuccess = true;
17
+ for (const pageInfo of PAGE_INFO) {
18
+ pagesGenerateSuccess =
19
+ pagesGenerateSuccess &&
20
+ (await PageGenerator.generatePageWithInfo(pageInfo, workingDir));
21
+ }
22
+
23
+ const checkoutPageInfo = PAGE_INFO.find((pi) => pi.isCheckout);
24
+ const editorPageInfo = PAGE_INFO.find((pi) => pi.isEditor);
25
+
26
+ const checkoutPageGenerateSuccess = checkoutPageInfo
27
+ ? await PageGenerator.generatePageWithInfo(checkoutPageInfo, workingDir)
28
+ : false;
29
+ const editorPageGenerateSuccess = editorPageInfo
30
+ ? await PageGenerator.generatePageWithInfo(editorPageInfo, workingDir)
31
+ : false;
32
+
33
+ return (
34
+ pagesGenerateSuccess &&
35
+ checkoutPageGenerateSuccess &&
36
+ editorPageGenerateSuccess
37
+ );
38
+ }
39
+
40
+ static async generatePageWithInfo(pageInfo: PageInfo, workingDir?: string) {
41
+ try {
42
+ let fileStr = "";
43
+
44
+ if (pageInfo.isCheckout) {
45
+ fileStr = CHECKOUT_PAGE_CONTENT;
46
+ } else if (pageInfo.isEditor) {
47
+ fileStr = EDITOR_PAGE_CONTENT;
48
+ } else {
49
+ const providerName = pageInfo.pageComponentName + "Next";
50
+ const pageComponentImportStr = `import { ${pageInfo.pageComponentName} } from "@ikas/storefront";\r\n`;
51
+ const providerImportStr = `import { ${pageInfo.pageComponentName} as ${providerName} } from "@ikas/storefront-next";\r\n`;
52
+ const componentsImportStr = `import Components from "src/components/__generated__/pages/${pageInfo.path.replace(
53
+ ".tsx",
54
+ ""
55
+ )}";\r\n`;
56
+
57
+ const pageComponentStr = `
58
+ const PageComponent = ${pageInfo.pageComponentName}.default;
59
+
60
+ const Page = (props: any) => {
61
+ return <PageComponent components={Components} {...props} />;
62
+ };
63
+
64
+ export default Page;\r\n`;
65
+
66
+ const getStaticPathsStr = pageInfo.isDynamicSSG
67
+ ? `export const getStaticPaths = ${providerName}.getStaticPaths;\r\n`
68
+ : "";
69
+
70
+ const dataFetchingStr = pageInfo.isSSR
71
+ ? `export const getServerSideProps = ${providerName}.getServerSideProps;\r\n`
72
+ : `export const getStaticProps = ${providerName}.getStaticProps;\r\n`;
73
+
74
+ fileStr =
75
+ pageComponentImportStr +
76
+ providerImportStr +
77
+ componentsImportStr +
78
+ pageComponentStr +
79
+ getStaticPathsStr +
80
+ dataFetchingStr;
81
+ }
82
+
83
+ return await createFile(
84
+ path.join(workingDir || process.cwd(), "src", "pages"),
85
+ pageInfo.path,
86
+ fileStr
87
+ );
88
+ } catch (err) {
89
+ console.error(err);
90
+ return false;
91
+ }
92
+ }
93
+
94
+ static async generatePageWithType(pageType: IkasThemeJsonPageType) {
95
+ const pageInfo = PAGE_INFO.find((pi) => pi.pageTypes.includes(pageType));
96
+ if (pageInfo) {
97
+ return await PageGenerator.generatePageWithInfo(pageInfo);
98
+ }
99
+
100
+ return false;
101
+ }
102
+ }
@@ -0,0 +1,161 @@
1
+ import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
+
3
+ export type PageInfo = {
4
+ path: string;
5
+ pageComponentName: string;
6
+ pageTypes: IkasThemeJsonPageType[];
7
+ isDynamicSSG?: boolean;
8
+ isSSR?: boolean;
9
+ isEditor?: boolean;
10
+ isCheckout?: boolean;
11
+ };
12
+
13
+ export const CHECKOUT_COMPONENT_ID = "checkout";
14
+
15
+ export const PAGE_INFO: PageInfo[] = [
16
+ {
17
+ path: "[slug]/index.tsx",
18
+ pageComponentName: "SlugPage",
19
+ pageTypes: [
20
+ IkasThemeJsonPageType.PRODUCT,
21
+ IkasThemeJsonPageType.CATEGORY,
22
+ IkasThemeJsonPageType.BRAND,
23
+ ],
24
+ isDynamicSSG: true,
25
+ },
26
+ {
27
+ path: "account/orders/[id].tsx",
28
+ pageComponentName: "OrderDetailPage",
29
+ pageTypes: [IkasThemeJsonPageType.ORDER_DETAIL],
30
+ isSSR: true,
31
+ },
32
+ {
33
+ path: "account/orders/index.tsx",
34
+ pageComponentName: "OrdersPage",
35
+ pageTypes: [IkasThemeJsonPageType.ORDERS],
36
+ },
37
+ {
38
+ path: "account/addresses.tsx",
39
+ pageComponentName: "AddressesPage",
40
+ pageTypes: [IkasThemeJsonPageType.ADDRESSES],
41
+ },
42
+ {
43
+ path: "account/favorite-products.tsx",
44
+ pageComponentName: "FavoriteProductsPage",
45
+ pageTypes: [IkasThemeJsonPageType.FAVORITE_PRODUCTS],
46
+ },
47
+ {
48
+ path: "account/forgot-password.tsx",
49
+ pageComponentName: "ForgotPasswordPage",
50
+ pageTypes: [IkasThemeJsonPageType.FORGOT_PASSWORD],
51
+ },
52
+ {
53
+ path: "account/index.tsx",
54
+ pageComponentName: "AccountPage",
55
+ pageTypes: [IkasThemeJsonPageType.ACCOUNT],
56
+ },
57
+ {
58
+ path: "account/login.tsx",
59
+ pageComponentName: "LoginPage",
60
+ pageTypes: [IkasThemeJsonPageType.LOGIN],
61
+ },
62
+ {
63
+ path: "account/raffles.tsx",
64
+ pageComponentName: "AccountRafflesPage",
65
+ pageTypes: [IkasThemeJsonPageType.RAFFLE_ACCOUNT],
66
+ },
67
+ {
68
+ path: "account/recover-password.tsx",
69
+ pageComponentName: "RecoverPasswordPage",
70
+ pageTypes: [IkasThemeJsonPageType.RECOVER_PASSWORD],
71
+ },
72
+ {
73
+ path: "account/register.tsx",
74
+ pageComponentName: "RegisterPage",
75
+ pageTypes: [IkasThemeJsonPageType.REGISTER],
76
+ },
77
+ {
78
+ path: "blog/[slug].tsx",
79
+ pageComponentName: "BlogSlugPage",
80
+ pageTypes: [
81
+ IkasThemeJsonPageType.BLOG,
82
+ IkasThemeJsonPageType.BLOG_CATEGORY,
83
+ ],
84
+ isDynamicSSG: true,
85
+ },
86
+ {
87
+ path: "blog/index.tsx",
88
+ pageComponentName: "BlogPage",
89
+ pageTypes: [IkasThemeJsonPageType.BLOG_INDEX],
90
+ },
91
+ {
92
+ path: "pages/[slug].tsx",
93
+ pageComponentName: "CustomPage",
94
+ pageTypes: [IkasThemeJsonPageType.CUSTOM],
95
+ isDynamicSSG: true,
96
+ },
97
+ {
98
+ path: "raffle/[slug].tsx",
99
+ pageComponentName: "RafflePage",
100
+ pageTypes: [IkasThemeJsonPageType.RAFFLE_DETAIL],
101
+ isDynamicSSG: true,
102
+ },
103
+ {
104
+ path: "raffle/index.tsx",
105
+ pageComponentName: "RafflesPage",
106
+ pageTypes: [IkasThemeJsonPageType.RAFFLE],
107
+ },
108
+ {
109
+ path: "404.tsx",
110
+ pageComponentName: "NotFoundPage",
111
+ pageTypes: [IkasThemeJsonPageType.NOT_FOUND],
112
+ },
113
+ {
114
+ path: "cart.tsx",
115
+ pageComponentName: "CartPage",
116
+ pageTypes: [IkasThemeJsonPageType.CART],
117
+ },
118
+ {
119
+ path: "index.tsx",
120
+ pageComponentName: "IndexPage",
121
+ pageTypes: [IkasThemeJsonPageType.INDEX],
122
+ },
123
+ {
124
+ path: "search.tsx",
125
+ pageComponentName: "SearchPage",
126
+ pageTypes: [IkasThemeJsonPageType.SEARCH],
127
+ },
128
+ {
129
+ path: "checkout.tsx",
130
+ pageComponentName: "CheckoutPage",
131
+ pageTypes: [],
132
+ isCheckout: true,
133
+ },
134
+ {
135
+ path: "editor.tsx",
136
+ pageComponentName: "EditorPage",
137
+ pageTypes: [],
138
+ isEditor: true,
139
+ },
140
+ ];
141
+
142
+ export const CHECKOUT_PAGE_CONTENT = `import { CheckoutPage } from "@ikas/storefront";
143
+ import { CheckoutPage as CheckoutPageNext } from "@ikas/storefront-next";
144
+
145
+ export default CheckoutPage.default;
146
+ export const getStaticProps = CheckoutPageNext.getStaticProps;
147
+ `;
148
+
149
+ export const EDITOR_PAGE_CONTENT = `import { EditorPage } from "@ikas/storefront";
150
+ import { EditorPage as EditorPageNext } from "@ikas/storefront-next";
151
+ import Components from "../components/__generated__/editor";
152
+
153
+ const PageComponent = EditorPage.default;
154
+
155
+ const Page = (props: any) => {
156
+ return <PageComponent components={Components} {...props} />;
157
+ };
158
+
159
+ export default Page;
160
+ export const getStaticProps = EditorPageNext.getStaticProps;
161
+ `;
@@ -0,0 +1,63 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import { createFile } from "../../../utils/fs";
4
+ import {
5
+ IkasThemeJson,
6
+ IkasThemeJsonPageType,
7
+ IkasThemeJsonStockPreference,
8
+ } from "@ikas/storefront-models";
9
+
10
+ export class ThemeJsonGenerator {
11
+ static generate(themeJson: IkasThemeJson) {
12
+ return createFile(
13
+ path.join(process.cwd(), "src", "theme.json"),
14
+ "",
15
+ JSON.stringify(themeJson, null, 2)
16
+ );
17
+ }
18
+
19
+ static generateInitialThemeJsonFile() {
20
+ const themeJson: IkasThemeJson = {
21
+ pages: [],
22
+ components: [],
23
+ name: "My Theme",
24
+ customData: [],
25
+ settings: {
26
+ colors: [],
27
+ favicon: {
28
+ id: null,
29
+ },
30
+ fontFamily: {
31
+ name: null,
32
+ variants: null,
33
+ },
34
+ stockPreference: IkasThemeJsonStockPreference.SHOW_ALL,
35
+ },
36
+ };
37
+
38
+ themeJson.pages.push({
39
+ id: "1",
40
+ components: [],
41
+ canonicals: null,
42
+ description: null,
43
+ disableIndex: null,
44
+ name: null,
45
+ pageTitle: null,
46
+ slug: null,
47
+ specifications: [],
48
+ type: IkasThemeJsonPageType.INDEX,
49
+ });
50
+
51
+ return ThemeJsonGenerator.generate(themeJson);
52
+ }
53
+
54
+ static async getTheme() {
55
+ try {
56
+ const themePath = path.join(process.cwd(), "src", "theme.json");
57
+ const fileBuffer = fs.readFileSync(themePath);
58
+ return fileBuffer.length ? JSON.parse(fileBuffer.toString()) : null;
59
+ } catch (err) {
60
+ console.error(err);
61
+ }
62
+ }
63
+ }