@ikas/storefront-next 4.0.0-alpha.9 → 4.0.0-beta.10

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 (110) hide show
  1. package/build/api/getComponentDirs.d.ts +3 -0
  2. package/build/api/getComponentDirs.js +1 -0
  3. package/build/api/getTheme.d.ts +3 -0
  4. package/build/api/getTheme.js +1 -0
  5. package/{src/api/index.ts → build/api/index.d.ts} +11 -14
  6. package/build/api/index.js +1 -0
  7. package/build/api/middleware.d.ts +3 -0
  8. package/build/api/middleware.js +1 -0
  9. package/build/api/updateTheme.d.ts +9 -0
  10. package/build/api/updateTheme.js +1 -0
  11. package/build/api/uploadTheme.d.ts +3 -0
  12. package/build/api/uploadTheme.js +1 -0
  13. package/build/ext/tslib/tslib.es6.js +1 -0
  14. package/{src/index.ts → build/index.d.ts} +4 -4
  15. package/build/index.js +1 -0
  16. package/build/packages/cmd/build/ext/tslib/tslib.es6.js +1 -0
  17. package/build/packages/cmd/build/scripts/generators/api/index.js +1 -0
  18. package/build/packages/cmd/build/scripts/generators/api/info.js +1 -0
  19. package/build/packages/cmd/build/scripts/generators/components/index.js +1 -0
  20. package/build/packages/cmd/build/scripts/generators/pages/index.js +1 -0
  21. package/build/packages/cmd/build/scripts/generators/pages/info.js +1 -0
  22. package/build/packages/cmd/build/scripts/generators/theme/index.js +1 -0
  23. package/build/packages/cmd/build/scripts/generators/types/index.js +1 -0
  24. package/build/packages/cmd/build/utils/fs.js +1 -0
  25. package/build/packages/cmd/build/utils/helper.js +1 -0
  26. package/build/pages/404.d.ts +2 -0
  27. package/build/pages/404.js +1 -0
  28. package/build/pages/[slug]/index.d.ts +3 -0
  29. package/build/pages/_slug_/index.js +1 -0
  30. package/build/pages/account/addresses.d.ts +2 -0
  31. package/build/pages/account/addresses.js +1 -0
  32. package/build/pages/account/favorite-products.d.ts +2 -0
  33. package/build/pages/account/favorite-products.js +1 -0
  34. package/build/pages/account/forgot-password.d.ts +2 -0
  35. package/build/pages/account/forgot-password.js +1 -0
  36. package/build/pages/account/index.d.ts +2 -0
  37. package/build/pages/account/index.js +1 -0
  38. package/build/pages/account/login.d.ts +2 -0
  39. package/build/pages/account/login.js +1 -0
  40. package/build/pages/account/orders/[id].d.ts +2 -0
  41. package/build/pages/account/orders/_id_.js +1 -0
  42. package/build/pages/account/orders/index.d.ts +2 -0
  43. package/build/pages/account/orders/index.js +1 -0
  44. package/build/pages/account/raffles.d.ts +2 -0
  45. package/build/pages/account/raffles.js +1 -0
  46. package/build/pages/account/recover-password.d.ts +2 -0
  47. package/build/pages/account/recover-password.js +1 -0
  48. package/build/pages/account/register.d.ts +2 -0
  49. package/build/pages/account/register.js +1 -0
  50. package/build/pages/blog/[slug].d.ts +3 -0
  51. package/build/pages/blog/_slug_.js +1 -0
  52. package/build/pages/blog/index.d.ts +2 -0
  53. package/build/pages/blog/index.js +1 -0
  54. package/build/pages/cart.d.ts +2 -0
  55. package/build/pages/cart.js +1 -0
  56. package/build/pages/checkout.d.ts +2 -0
  57. package/build/pages/checkout.js +1 -0
  58. package/build/pages/editor.d.ts +2 -0
  59. package/build/pages/editor.js +1 -0
  60. package/build/pages/home.d.ts +2 -0
  61. package/build/pages/home.js +1 -0
  62. package/{src/pages/index.ts → build/pages/index.d.ts} +22 -22
  63. package/build/pages/pages/[slug].d.ts +3 -0
  64. package/build/pages/pages/_slug_.js +1 -0
  65. package/build/pages/raffle/[slug].d.ts +3 -0
  66. package/build/pages/raffle/_slug_.js +1 -0
  67. package/build/pages/raffle/index.d.ts +2 -0
  68. package/build/pages/raffle/index.js +1 -0
  69. package/build/pages/search.d.ts +2 -0
  70. package/build/pages/search.js +1 -0
  71. package/build/provider/page-data-next.d.ts +94 -0
  72. package/build/provider/page-data-next.js +1 -0
  73. package/build/utils/fs.d.ts +28 -0
  74. package/build/utils/fs.js +1 -0
  75. package/build/utils/google-fonts.d.ts +2 -0
  76. package/build/utils/google-fonts.js +1 -0
  77. package/build/utils/i18n.d.ts +9 -0
  78. package/build/utils/i18n.js +1 -0
  79. package/package.json +19 -18
  80. package/src/api/getComponentDirs.ts +0 -39
  81. package/src/api/getTheme.ts +0 -22
  82. package/src/api/middleware.ts +0 -24
  83. package/src/api/updateTheme.ts +0 -33
  84. package/src/api/uploadTheme.ts +0 -307
  85. package/src/pages/404.tsx +0 -18
  86. package/src/pages/[slug]/index.tsx +0 -18
  87. package/src/pages/account/addresses.tsx +0 -10
  88. package/src/pages/account/favorite-products.tsx +0 -10
  89. package/src/pages/account/forgot-password.tsx +0 -10
  90. package/src/pages/account/index.tsx +0 -10
  91. package/src/pages/account/login.tsx +0 -10
  92. package/src/pages/account/orders/[id].tsx +0 -10
  93. package/src/pages/account/orders/index.tsx +0 -10
  94. package/src/pages/account/raffles.tsx +0 -10
  95. package/src/pages/account/recover-password.tsx +0 -10
  96. package/src/pages/account/register.tsx +0 -10
  97. package/src/pages/blog/[slug].tsx +0 -17
  98. package/src/pages/blog/index.tsx +0 -10
  99. package/src/pages/cart.tsx +0 -10
  100. package/src/pages/checkout.tsx +0 -10
  101. package/src/pages/editor.tsx +0 -11
  102. package/src/pages/home.tsx +0 -10
  103. package/src/pages/pages/[slug].tsx +0 -72
  104. package/src/pages/raffle/[slug].tsx +0 -17
  105. package/src/pages/raffle/index.tsx +0 -10
  106. package/src/pages/search.tsx +0 -10
  107. package/src/provider/page-data-next.ts +0 -618
  108. package/src/utils/fs.ts +0 -93
  109. package/src/utils/google-fonts.ts +0 -52
  110. package/src/utils/i18n.ts +0 -80
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Divides the given filePath string into directory part and fileName part
3
+ * @param path Path for the file
4
+ */
5
+ export declare function getFilePathParts(path: string): {
6
+ dirParts: string[];
7
+ filePart: string;
8
+ } | {
9
+ filePart: string;
10
+ dirParts?: undefined;
11
+ };
12
+ /**
13
+ * Deletes the contents of the given directory, exluding the ignoreFiles
14
+ * @param dirPath Path for the directory
15
+ * @param ignoreFiles List of files to keep in directory. Does not accept recursive paths, only first level files
16
+ *
17
+ * @returns true for successfull operation, false otherwise
18
+ */
19
+ export declare function deleteDirContent(dirPath: string, ignoreFiles?: string[]): Promise<boolean>;
20
+ /**
21
+ * Creates the given file and directories for the filePath
22
+ * @param basePath Base directory path for the file
23
+ * @param fileSubPath Filename or the sub directory path for the file to write
24
+ * @param fileStr File contents
25
+ *
26
+ * @returns true for successfull operation, false otherwise
27
+ */
28
+ export declare function createFile(basePath: string, fileSubPath: string, fileStr: string): Promise<boolean>;
@@ -0,0 +1 @@
1
+ import{__awaiter as r,__generator as t,__spreadArray as n}from'./../ext/tslib/tslib.es6.js';import i from"fs";import e from"path";function o(r){var t=r.split("/");return t.length>1?{dirParts:t.slice(0,t.length-1),filePart:t[t.length-1]}:{filePart:r}}function u(n,o){return r(this,void 0,void 0,(function(){return t(this,(function(r){try{return i.readdirSync(n).forEach((function(r){(null==o?void 0:o.includes(r))||i.unlinkSync(e.join(n,r))})),[2,!0]}catch(r){return[2,!1]}return[2]}))}))}function c(u,c,l){var s;return r(this,void 0,void 0,(function(){var r,d,f;return t(this,(function(t){try{return r=u,d=o(c),(null===(s=d.dirParts)||void 0===s?void 0:s.length)&&(r=e.join.apply(e,n([r],d.dirParts,!1))),i.existsSync(r)||i.mkdirSync(r,{recursive:!0}),f=e.join(r,d.filePart),i.writeFileSync(f,l),[2,!0]}catch(r){return console.error(r),[2,!1]}return[2]}))}))}export{c as createFile,u as deleteDirContent,o as getFilePathParts};
@@ -0,0 +1,2 @@
1
+ import { IkasThemeJsonFontFamily } from "@ikas/storefront-models";
2
+ export declare const getGoogleFontHref: (fontFamily: IkasThemeJsonFontFamily) => string | undefined;
@@ -0,0 +1 @@
1
+ var a=function(a){if(a.name){var t=a.name.replace(/ /g,"+"),e="";if(a.variants){e+=":";var r=a.variants.some((function(a){return"italic"===a}));if(r&&(e+="ital,"),e+="wght@",r){var n=new RegExp("italic","i");e+=a.variants.reduce((function(a,t){return n.test(t)?a:a+"0,".concat(t.replace("regular","400"),";")}),""),e+=a.variants.reduce((function(a,t){return n.test(t)?a+"1,".concat("italic"===t?"400":t.replace("italic",""),";"):a}),"")}else e+=a.variants.reduce((function(a,t){return a+"".concat(t.replace("regular","400"),";")}),"");e=e.substring(0,e.length-1),e+="&display=swap"}return"https://fonts.googleapis.com/css2?family=".concat(t).concat(e)}};export{a as getGoogleFontHref};
@@ -0,0 +1,9 @@
1
+ export declare const CHECKOUT_TRANSLATION_NAMESPACE = "checkout-page";
2
+ export declare class I18NFileReader {
3
+ locale: string;
4
+ namespaces: string[];
5
+ localePath?: string;
6
+ constructor(locale: string, namespaces: string[], localePath?: string);
7
+ read(): Promise<Record<string, any>>;
8
+ private readLocaleFile;
9
+ }
@@ -0,0 +1 @@
1
+ import{__awaiter as e,__generator as t}from'./../ext/tslib/tslib.es6.js';import s from"fs";import r from"path";var o="checkout-page",n=function(){function o(e,t,s){this.locale=e,this.namespaces=t,this.localePath=s}return o.prototype.read=function(){return e(this,void 0,void 0,(function(){var e,o,n,a,c,i,l,u,h;return t(this,(function(t){switch(t.label){case 0:e={},o=0,n=this.namespaces,t.label=1;case 1:if(!(o<n.length))return[3,14];a=n[o],t.label=2;case 2:return t.trys.push([2,12,,13]),c=this.localePath?r.join(this.localePath,this.locale,a+".json"):r.join(process.cwd(),"public","locales",this.locale,a+".json"),s.existsSync(c)?[4,this.readLocaleFile(c)]:[3,4];case 3:return i=t.sent(),e[a]=i,[3,11];case 4:return"checkout-page"!==a?[3,11]:(l={},"tr"!==this.locale?[3,6]:[4,import("@ikas/storefront-assets/checkout/tr.js")]);case 5:return u=t.sent(),l=u.default,[3,10];case 6:return"de"!==this.locale?[3,8]:[4,import("@ikas/storefront-assets/checkout/de.js")];case 7:return u=t.sent(),l=u.default,[3,10];case 8:return[4,import("@ikas/storefront-assets/checkout/en.js")];case 9:u=t.sent(),l=u.default,t.label=10;case 10:e[a]=l,t.label=11;case 11:return[3,13];case 12:return h=t.sent(),console.error(h),[3,13];case 13:return o++,[3,1];case 14:return[2,e]}}))}))},o.prototype.readLocaleFile=function(r){return e(this,void 0,void 0,(function(){return t(this,(function(e){return[2,new Promise((function(e,t){s.readFile(r,{flag:"r"},(function(s,r){if(s)return t(s);var o=r.length?JSON.parse(r.toString()):{};e(o)}))}))]}))}))},o}();export{o as CHECKOUT_TRANSLATION_NAMESPACE,n as I18NFileReader};
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@ikas/storefront-next",
3
- "version": "4.0.0-alpha.9",
3
+ "version": "4.0.0-beta.10",
4
4
  "description": "Next.js specific functions for ikas storefront themes.",
5
- "author": "Umut Ozan Yıldırım",
5
+ "author": "ikas",
6
6
  "license": "ISC",
7
- "main": "./src/index.ts",
8
- "module": "./src/index.ts",
7
+ "main": "./build/index.js",
8
+ "module": "./build/index.js",
9
9
  "files": [
10
- "./src"
10
+ "./build"
11
11
  ],
12
12
  "type": "module",
13
13
  "scripts": {
@@ -16,33 +16,34 @@
16
16
  "build": "rm -rf build && rollup -c"
17
17
  },
18
18
  "peerDependencies": {
19
- "next": "canary",
20
- "@ikas/storefront-config": "^4.0.0-alpha.9",
21
- "@ikas/storefront-providers": "^4.0.0-alpha.9",
22
- "@ikas/storefront-models": "^4.0.0-alpha.9",
23
- "@ikas/storefront-api": "^4.0.0-alpha.9",
24
- "@ikas/storefront-assets": "^4.0.0-alpha.9",
19
+ "next": "12.2.0",
20
+ "@ikas/storefront-config": "^4.0.0-beta.10",
21
+ "@ikas/storefront-providers": "^4.0.0-beta.10",
22
+ "@ikas/storefront-models": "^4.0.0-beta.10",
23
+ "@ikas/storefront-api": "^4.0.0-beta.10",
24
+ "@ikas/storefront-assets": "^4.0.0-beta.10",
25
25
  "axios": "^0.21.0",
26
26
  "lodash": "^4.17.21",
27
27
  "archiver": "^5.3.0",
28
28
  "cors": "^2.8.5"
29
29
  },
30
30
  "devDependencies": {
31
- "@ikas/storefront-cmd": "^4.0.0-alpha.9",
32
- "@ikas/storefront-config": "^4.0.0-alpha.9",
33
- "@ikas/storefront-providers": "^4.0.0-alpha.9",
34
- "@ikas/storefront-models": "^4.0.0-alpha.9",
35
- "@ikas/storefront-api": "^4.0.0-alpha.9",
36
- "@ikas/storefront-assets": "^4.0.0-alpha.9",
31
+ "@ikas/storefront-cmd": "^4.0.0-beta.10",
32
+ "@ikas/storefront-config": "^4.0.0-beta.10",
33
+ "@ikas/storefront-providers": "^4.0.0-beta.10",
34
+ "@ikas/storefront-models": "^4.0.0-beta.10",
35
+ "@ikas/storefront-api": "^4.0.0-beta.10",
36
+ "@ikas/storefront-assets": "^4.0.0-beta.10",
37
37
  "@rollup/plugin-node-resolve": "^13.3.0",
38
38
  "@rollup/plugin-commonjs": "^22.0.0",
39
39
  "@rollup/plugin-json": "^4.1.0",
40
+ "rollup-plugin-rename-node-modules": "^1.2.0",
40
41
  "@types/archiver": "^5.1.0",
41
42
  "@types/node": "^14.14.6",
42
43
  "@types/node-fetch": "^2.5.7",
43
44
  "@types/cors": "^2.8.9",
44
45
  "@types/lodash": "^4.14.168",
45
- "next": "canary",
46
+ "next": "12.2.0",
46
47
  "prettier": "^2.2.1",
47
48
  "rollup": "^2.75.6",
48
49
  "rollup-plugin-terser": "^7.0.2",
@@ -1,39 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { NextApiRequest, NextApiResponse } from "next";
4
- import { corsMiddleware } from "./middleware";
5
-
6
- export const getComponentDirs = async (
7
- req: NextApiRequest,
8
- res: NextApiResponse
9
- ) => {
10
- await corsMiddleware(req, res);
11
- const componentDirNames: string[] = await getComponentDirNames();
12
-
13
- res.statusCode = 200;
14
- res.setHeader("Content-Type", "application/json");
15
- res.json({
16
- componentDirNames: componentDirNames.filter(
17
- (name) => name !== "__generated__"
18
- ),
19
- });
20
- };
21
-
22
- export const config = {};
23
-
24
- function getComponentDirNames(): Promise<string[]> {
25
- return new Promise((resolve, reject) => {
26
- const componentsPath = path.join(process.cwd(), "src", "components");
27
-
28
- fs.readdir(componentsPath, function (err, files) {
29
- if (err) {
30
- return reject(err);
31
- }
32
- resolve(
33
- files.filter((file) =>
34
- fs.lstatSync(path.join(componentsPath, file)).isDirectory()
35
- )
36
- );
37
- });
38
- });
39
- }
@@ -1,22 +0,0 @@
1
- import { NextApiRequest, NextApiResponse } from "next";
2
- import { corsMiddleware } from "./middleware";
3
- import { ThemeJsonGenerator } from "@ikas/storefront-cmd";
4
-
5
- export const getTheme = async (req: NextApiRequest, res: NextApiResponse) => {
6
- try {
7
- await corsMiddleware(req, res);
8
- const theme = await ThemeJsonGenerator.getTheme();
9
-
10
- res.statusCode = 200;
11
- res.setHeader("Content-Type", "application/json");
12
- res.json({
13
- theme: theme || {},
14
- });
15
- } catch (err) {
16
- console.error(err);
17
- res.statusCode = 500;
18
- res.send(err);
19
- }
20
- };
21
-
22
- export const config = {};
@@ -1,24 +0,0 @@
1
- import { NextApiRequest, NextApiResponse } from "next";
2
- import Cors from "cors";
3
-
4
- const cors = Cors();
5
-
6
- export function runMiddleware(
7
- req: NextApiRequest,
8
- res: NextApiResponse,
9
- fn: any
10
- ) {
11
- return new Promise((resolve, reject) => {
12
- fn(req, res, (result: any) => {
13
- if (result instanceof Error) {
14
- return reject(result);
15
- }
16
-
17
- return resolve(result);
18
- });
19
- });
20
- }
21
-
22
- export function corsMiddleware(req: NextApiRequest, res: NextApiResponse) {
23
- return runMiddleware(req, res, cors);
24
- }
@@ -1,33 +0,0 @@
1
- import { NextApiRequest, NextApiResponse } from "next";
2
- import { corsMiddleware } from "./middleware";
3
- import { ThemeJsonGenerator } from "@ikas/storefront-cmd";
4
- import { ComponentImportsGenerator } from "@ikas/storefront-cmd";
5
- import { PageGenerator } from "@ikas/storefront-cmd";
6
- import { APIGenerator } from "@ikas/storefront-cmd";
7
- import { CustomDataTypesGenerator } from "@ikas/storefront-cmd";
8
-
9
- export const updateTheme = async (
10
- req: NextApiRequest,
11
- res: NextApiResponse
12
- ) => {
13
- await corsMiddleware(req, res);
14
- const themeJson = req.body;
15
-
16
- await ThemeJsonGenerator.generate(themeJson);
17
- await ComponentImportsGenerator.generate(themeJson);
18
- await PageGenerator.generate();
19
- await APIGenerator.generate();
20
- await CustomDataTypesGenerator.generate(themeJson);
21
-
22
- res.statusCode = 200;
23
- res.setHeader("Content-Type", "application/json");
24
- res.end();
25
- };
26
-
27
- export const config = {
28
- api: {
29
- bodyParser: {
30
- sizeLimit: "50mb",
31
- },
32
- },
33
- };
@@ -1,307 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import archiver from "archiver";
4
- import { NextApiRequest, NextApiResponse } from "next";
5
- import axios from "axios";
6
-
7
- //@ts-ignore
8
- import CheckoutEN from "@ikas/storefront-assets/checkout/en.js";
9
- //@ts-ignore
10
- import CheckoutTR from "@ikas/storefront-assets/checkout/tr.js";
11
-
12
- import { corsMiddleware } from "./middleware";
13
-
14
- export const uploadTheme = async (
15
- req: NextApiRequest,
16
- res: NextApiResponse
17
- ) => {
18
- await corsMiddleware(req, res);
19
- try {
20
- const theme = await getTheme();
21
-
22
- const localization = await readLocalizationFiles();
23
- const uploadUrl = await saveTheme(theme, localization);
24
-
25
- if (typeof uploadUrl === "string") {
26
- const zipDir = await archiveThemeCode();
27
- const stat = fs.statSync(zipDir);
28
- const success = await _uploadTheme(
29
- uploadUrl,
30
- fs.readFileSync(zipDir),
31
- stat.size
32
- );
33
- console.log(success);
34
- if (success) {
35
- buildTheme();
36
- }
37
- deleteThemeZip(zipDir);
38
- }
39
-
40
- res.statusCode = 200;
41
- res.setHeader("Content-Type", "application/json");
42
- res.json({ status: "ok" });
43
- } catch (err) {
44
- console.log(err);
45
- res.statusCode = 400;
46
- res.setHeader("Content-Type", "application/json");
47
- res.json({ status: "failed" });
48
- }
49
- };
50
-
51
- export const config = {};
52
-
53
- async function archiveThemeCode(): Promise<string> {
54
- const themePath = path.join(process.cwd());
55
-
56
- const filename = "theme.zip";
57
- const dirname = path.join(process.cwd(), filename);
58
- const output = fs.createWriteStream(dirname);
59
- const archive = archiver("zip", {
60
- zlib: {
61
- level: 9,
62
- },
63
- });
64
-
65
- archive.on("warning", function (err) {
66
- if (err.code !== "ENOENT") {
67
- throw err;
68
- }
69
- });
70
-
71
- archive.on("error", function (err) {
72
- throw err;
73
- });
74
-
75
- archive.pipe(output);
76
-
77
- const excludedDirs = ["node_modules", ".next", "out", ".git"];
78
- const files = fs.readdirSync(themePath);
79
-
80
- files.forEach((file) => {
81
- const filePath = path.join(themePath, file);
82
- const stat = fs.lstatSync(filePath);
83
-
84
- if (stat.isDirectory()) {
85
- if (excludedDirs.includes(file)) return;
86
- archive.directory(filePath, file);
87
- } else {
88
- archive.file(filePath, { name: file });
89
- }
90
- });
91
-
92
- await archive.finalize();
93
-
94
- return new Promise((resolve) => {
95
- setTimeout(() => {
96
- resolve(dirname);
97
- }, 2000);
98
- });
99
- }
100
-
101
- async function saveTheme(theme: any, localization: Record<string, any>) {
102
- try {
103
- const locales = Object.keys(localization);
104
- const defaultLocale = locales.some((l) => l === "en") ? "en" : locales[0];
105
- const config = await getStorefrontConfig();
106
-
107
- const response = await axios({
108
- method: "post",
109
- url: process.env.NEXT_PUBLIC_UPLOAD_GQL_URL!,
110
- headers: {
111
- "x-api-key": config.apiKey,
112
- "Content-Type": "application/json",
113
- },
114
- data: JSON.stringify({
115
- query: /* GraphQL */ `
116
- mutation saveTheme($saveThemeInput: SaveThemeInput!) {
117
- saveTheme(input: $saveThemeInput) {
118
- themeVersionId
119
- uploadUrl
120
- }
121
- }
122
- `,
123
- variables: {
124
- saveThemeInput: {
125
- id: config.themeId,
126
- themeJson: JSON.stringify(theme),
127
- locales: Object.entries(localization).map(
128
- ([locale, localeTranslations]) => ({
129
- isDefaultLocale: locale === defaultLocale,
130
- locale,
131
- localeJson: JSON.stringify(localeTranslations),
132
- })
133
- ),
134
- },
135
- },
136
- }),
137
- });
138
-
139
- // const response = await fetch(process.env.NEXT_PUBLIC_UPLOAD_GQL_URL!, {
140
- // method: "POST",
141
- // body: JSON.stringify({
142
- // query: /* GraphQL */ `
143
- // mutation saveTheme($saveThemeInput: SaveThemeInput!) {
144
- // saveTheme(input: $saveThemeInput) {
145
- // themeVersionId
146
- // uploadUrl
147
- // }
148
- // }
149
- // `,
150
- // variables: {
151
- // saveThemeInput: {
152
- // id: config.themeId,
153
- // themeJson: JSON.stringify(theme),
154
- // locales: Object.entries(localization).map(
155
- // ([locale, localeTranslations]) => ({
156
- // isDefaultLocale: locale === defaultLocale,
157
- // locale,
158
- // localeJson: JSON.stringify(localeTranslations),
159
- // })
160
- // ),
161
- // },
162
- // },
163
- // }),
164
- // headers: {
165
- // "x-api-key": config.apiKey,
166
- // "Content-Type": "application/json",
167
- // },
168
- // });
169
- const responseJSON = await response.data();
170
-
171
- if (responseJSON.data && responseJSON.data.saveTheme) {
172
- return responseJSON.data.saveTheme.uploadUrl as string;
173
- }
174
- } catch (err) {
175
- console.log(err);
176
- }
177
- }
178
-
179
- async function _uploadTheme(uploadUrl: string, file: Buffer, size: number) {
180
- const config = {
181
- headers: {
182
- "Content-Type": "application/zip",
183
- "Content-Length": size + "",
184
- },
185
- };
186
-
187
- try {
188
- const res = await axios.put(uploadUrl, file, config);
189
- return res.status === 200;
190
- } catch (err) {
191
- console.log(err);
192
- return false;
193
- }
194
- }
195
-
196
- async function buildTheme() {
197
- try {
198
- const config = await getStorefrontConfig();
199
- const response = await fetch(process.env.NEXT_PUBLIC_UPLOAD_GQL_URL!, {
200
- method: "POST",
201
- body: JSON.stringify({
202
- query: /* GraphQL */ `
203
- mutation buildTheme($buildThemeThemeId: String!) {
204
- buildTheme(themeId: $buildThemeThemeId)
205
- }
206
- `,
207
- variables: {
208
- buildThemeThemeId: config.themeId,
209
- },
210
- }),
211
- headers: {
212
- "x-api-key": config.apiKey,
213
- "Content-Type": "application/json",
214
- },
215
- });
216
- const responseJSON = await response.json();
217
- console.log(responseJSON);
218
- } catch (err) {
219
- console.log(err);
220
- }
221
- }
222
-
223
- function getTheme(): Promise<any> {
224
- return new Promise((resolve, reject) => {
225
- const themePath = path.join(process.cwd(), "src", "theme.json");
226
- fs.readFile(themePath, function (err, file) {
227
- if (err) {
228
- return reject(err);
229
- }
230
- resolve(JSON.parse(file.toString()));
231
- });
232
- });
233
- }
234
-
235
- function getStorefrontConfig(): Promise<Record<string, any>> {
236
- return new Promise((resolve, reject) => {
237
- const themePath = path.join(process.cwd(), "config.json");
238
- fs.readFile(themePath, function (err, file) {
239
- if (err) {
240
- return reject(err);
241
- }
242
- resolve(JSON.parse(file.toString()));
243
- });
244
- });
245
- }
246
-
247
- function deleteThemeZip(zipDir: string) {
248
- fs.unlinkSync(zipDir);
249
- }
250
-
251
- function readLocalizationFiles(): Promise<Record<string, any>> {
252
- return new Promise((resolve, reject) => {
253
- const localesPath = path.join(process.cwd(), "public", "locales");
254
- const stripExtension = (path: string) =>
255
- path.length ? path.split(".")[0] : path;
256
-
257
- fs.readdir(localesPath, function (err, files) {
258
- if (err) {
259
- return reject(err);
260
- }
261
-
262
- const localeDirs = files.filter((file) =>
263
- fs.lstatSync(path.join(localesPath, file)).isDirectory()
264
- );
265
-
266
- const locales: Record<string, any> = {};
267
- let hasError = false;
268
-
269
- localeDirs.forEach((locale) => {
270
- const localeDirPath = path.join(
271
- process.cwd(),
272
- "public",
273
- "locales",
274
- locale
275
- );
276
-
277
- locales[locale] = {};
278
-
279
- try {
280
- const localeFiles = fs.readdirSync(localeDirPath);
281
- localeFiles.forEach((localeFile) => {
282
- const file = fs.readFileSync(
283
- path.join(process.cwd(), "public", "locales", locale, localeFile)
284
- );
285
-
286
- const strippedLocale = stripExtension(locale).toLowerCase();
287
- const namespace = stripExtension(localeFile).toLowerCase();
288
-
289
- locales[strippedLocale][namespace] = JSON.parse(file.toString());
290
-
291
- if (strippedLocale === "tr") {
292
- locales[strippedLocale]["checkout-page"] = CheckoutTR;
293
- } else {
294
- locales[strippedLocale]["checkout-page"] = CheckoutEN;
295
- }
296
- });
297
- } catch (err) {
298
- console.error(err);
299
- hasError = true;
300
- }
301
- });
302
-
303
- if (hasError) reject(null);
304
- else resolve(locales);
305
- });
306
- });
307
- }
package/src/pages/404.tsx DELETED
@@ -1,18 +0,0 @@
1
- import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
- import { GetStaticProps } from "next";
3
- import { IkasNextPageDataProvider } from "../provider/page-data-next";
4
-
5
- export const getStaticProps: GetStaticProps = async (context) => {
6
- const props = await IkasNextPageDataProvider.getStaticProps(
7
- context,
8
- IkasThemeJsonPageType.NOT_FOUND
9
- );
10
-
11
- //@ts-ignore
12
- if (props.notFound)
13
- return {
14
- props: {},
15
- revalidate: 60,
16
- };
17
- else return props;
18
- };
@@ -1,18 +0,0 @@
1
- import { GetStaticPaths, GetStaticProps } from "next";
2
- import { IkasNextPageDataProvider } from "../../provider/page-data-next";
3
- import { IkasThemeJsonPageType } from "@ikas/storefront-models";
4
-
5
- export const getStaticPaths: GetStaticPaths = async () => {
6
- return {
7
- paths: [],
8
- fallback: "blocking",
9
- };
10
- };
11
-
12
- export const getStaticProps: GetStaticProps = async (context) => {
13
- return await IkasNextPageDataProvider.getStaticProps(context, undefined, [
14
- IkasThemeJsonPageType.BRAND,
15
- IkasThemeJsonPageType.CATEGORY,
16
- IkasThemeJsonPageType.PRODUCT,
17
- ]);
18
- };
@@ -1,10 +0,0 @@
1
- import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
- import { GetStaticProps } from "next";
3
- import { IkasNextPageDataProvider } from "../../provider/page-data-next";
4
-
5
- export const getStaticProps: GetStaticProps = async (context) => {
6
- return await IkasNextPageDataProvider.getStaticProps(
7
- context,
8
- IkasThemeJsonPageType.ADDRESSES
9
- );
10
- };
@@ -1,10 +0,0 @@
1
- import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
- import { GetStaticProps } from "next";
3
- import { IkasNextPageDataProvider } from "../../provider/page-data-next";
4
-
5
- export const getStaticProps: GetStaticProps = async (context) => {
6
- return await IkasNextPageDataProvider.getStaticProps(
7
- context,
8
- IkasThemeJsonPageType.FAVORITE_PRODUCTS
9
- );
10
- };
@@ -1,10 +0,0 @@
1
- import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
- import { GetStaticProps } from "next";
3
- import { IkasNextPageDataProvider } from "../../provider/page-data-next";
4
-
5
- export const getStaticProps: GetStaticProps = async (context) => {
6
- return await IkasNextPageDataProvider.getStaticProps(
7
- context,
8
- IkasThemeJsonPageType.FORGOT_PASSWORD
9
- );
10
- };
@@ -1,10 +0,0 @@
1
- import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
- import { GetStaticProps } from "next";
3
- import { IkasNextPageDataProvider } from "../../provider/page-data-next";
4
-
5
- export const getStaticProps: GetStaticProps = async (context) => {
6
- return await IkasNextPageDataProvider.getStaticProps(
7
- context,
8
- IkasThemeJsonPageType.ACCOUNT
9
- );
10
- };
@@ -1,10 +0,0 @@
1
- import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
- import { GetStaticProps } from "next";
3
- import { IkasNextPageDataProvider } from "../../provider/page-data-next";
4
-
5
- export const getStaticProps: GetStaticProps = async (context) => {
6
- return await IkasNextPageDataProvider.getStaticProps(
7
- context,
8
- IkasThemeJsonPageType.LOGIN
9
- );
10
- };
@@ -1,10 +0,0 @@
1
- import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
- import { GetServerSideProps } from "next";
3
- import { IkasNextPageDataProvider } from "../../../provider/page-data-next";
4
-
5
- export const getServerSideProps: GetServerSideProps = async (context) => {
6
- return await IkasNextPageDataProvider.getServerSideProps(
7
- context,
8
- IkasThemeJsonPageType.ORDER_DETAIL
9
- );
10
- };
@@ -1,10 +0,0 @@
1
- import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
- import { GetStaticProps } from "next";
3
- import { IkasNextPageDataProvider } from "../../../provider/page-data-next";
4
-
5
- export const getStaticProps: GetStaticProps = async (context) => {
6
- return await IkasNextPageDataProvider.getStaticProps(
7
- context,
8
- IkasThemeJsonPageType.ORDERS
9
- );
10
- };