@ikas/storefront-next 4.0.0-alpha.59 → 4.0.0-alpha.60

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 (187) hide show
  1. package/package.json +15 -15
  2. package/src/api/getComponentDirs.ts +39 -0
  3. package/src/api/getTheme.ts +22 -0
  4. package/{build/api/index.d.ts → src/api/index.ts} +14 -11
  5. package/src/api/middleware.ts +24 -0
  6. package/src/api/updateTheme.ts +33 -0
  7. package/src/api/uploadTheme.ts +311 -0
  8. package/{build/index.d.ts → src/index.ts} +4 -4
  9. package/src/pages/404.tsx +18 -0
  10. package/src/pages/[slug]/index.tsx +18 -0
  11. package/src/pages/account/addresses.tsx +10 -0
  12. package/src/pages/account/favorite-products.tsx +10 -0
  13. package/src/pages/account/forgot-password.tsx +10 -0
  14. package/src/pages/account/index.tsx +10 -0
  15. package/src/pages/account/login.tsx +10 -0
  16. package/src/pages/account/orders/[id].tsx +10 -0
  17. package/src/pages/account/orders/index.tsx +10 -0
  18. package/src/pages/account/raffles.tsx +10 -0
  19. package/src/pages/account/recover-password.tsx +10 -0
  20. package/src/pages/account/register.tsx +10 -0
  21. package/src/pages/blog/[slug].tsx +17 -0
  22. package/src/pages/blog/index.tsx +10 -0
  23. package/src/pages/cart.tsx +10 -0
  24. package/src/pages/checkout.tsx +10 -0
  25. package/src/pages/editor.tsx +11 -0
  26. package/src/pages/home.tsx +10 -0
  27. package/{build/pages/index.d.ts → src/pages/index.ts} +22 -22
  28. package/src/pages/pages/[slug].tsx +72 -0
  29. package/src/pages/raffle/[slug].tsx +17 -0
  30. package/src/pages/raffle/index.tsx +10 -0
  31. package/src/pages/search.tsx +10 -0
  32. package/src/provider/page-data-next.ts +608 -0
  33. package/src/utils/fs.ts +93 -0
  34. package/src/utils/google-fonts.ts +52 -0
  35. package/src/utils/i18n.ts +86 -0
  36. package/build/api/getComponentDirs.d.ts +0 -3
  37. package/build/api/getComponentDirs.js +0 -1
  38. package/build/api/getTheme.d.ts +0 -3
  39. package/build/api/getTheme.js +0 -1
  40. package/build/api/index.js +0 -1
  41. package/build/api/middleware.d.ts +0 -3
  42. package/build/api/middleware.js +0 -1
  43. package/build/api/updateTheme.d.ts +0 -9
  44. package/build/api/updateTheme.js +0 -1
  45. package/build/api/uploadTheme.d.ts +0 -3
  46. package/build/api/uploadTheme.js +0 -1
  47. package/build/ext/tslib/tslib.es6.js +0 -1
  48. package/build/index.js +0 -1
  49. package/build/packages/cmd/build/_virtual/_cloneBuffer.js +0 -1
  50. package/build/packages/cmd/build/_virtual/_commonjsHelpers.js +0 -1
  51. package/build/packages/cmd/build/_virtual/_nodeUtil.js +0 -1
  52. package/build/packages/cmd/build/_virtual/isBuffer.js +0 -1
  53. package/build/packages/cmd/build/ext/lodash/_DataView.js +0 -1
  54. package/build/packages/cmd/build/ext/lodash/_Hash.js +0 -1
  55. package/build/packages/cmd/build/ext/lodash/_ListCache.js +0 -1
  56. package/build/packages/cmd/build/ext/lodash/_Map.js +0 -1
  57. package/build/packages/cmd/build/ext/lodash/_MapCache.js +0 -1
  58. package/build/packages/cmd/build/ext/lodash/_Promise.js +0 -1
  59. package/build/packages/cmd/build/ext/lodash/_Set.js +0 -1
  60. package/build/packages/cmd/build/ext/lodash/_SetCache.js +0 -1
  61. package/build/packages/cmd/build/ext/lodash/_Symbol.js +0 -1
  62. package/build/packages/cmd/build/ext/lodash/_Uint8Array.js +0 -1
  63. package/build/packages/cmd/build/ext/lodash/_WeakMap.js +0 -1
  64. package/build/packages/cmd/build/ext/lodash/_arrayIncludes.js +0 -1
  65. package/build/packages/cmd/build/ext/lodash/_arrayIncludesWith.js +0 -1
  66. package/build/packages/cmd/build/ext/lodash/_arrayLikeKeys.js +0 -1
  67. package/build/packages/cmd/build/ext/lodash/_assocIndexOf.js +0 -1
  68. package/build/packages/cmd/build/ext/lodash/_baseClone.js +0 -1
  69. package/build/packages/cmd/build/ext/lodash/_baseFindIndex.js +0 -1
  70. package/build/packages/cmd/build/ext/lodash/_baseGetTag.js +0 -1
  71. package/build/packages/cmd/build/ext/lodash/_baseIndexOf.js +0 -1
  72. package/build/packages/cmd/build/ext/lodash/_baseIsArguments.js +0 -1
  73. package/build/packages/cmd/build/ext/lodash/_baseIsNaN.js +0 -1
  74. package/build/packages/cmd/build/ext/lodash/_baseIsNative.js +0 -1
  75. package/build/packages/cmd/build/ext/lodash/_baseUniq.js +0 -1
  76. package/build/packages/cmd/build/ext/lodash/_cacheHas.js +0 -1
  77. package/build/packages/cmd/build/ext/lodash/_cloneBuffer.js +0 -1
  78. package/build/packages/cmd/build/ext/lodash/_cloneSymbol.js +0 -1
  79. package/build/packages/cmd/build/ext/lodash/_coreJsData.js +0 -1
  80. package/build/packages/cmd/build/ext/lodash/_createSet.js +0 -1
  81. package/build/packages/cmd/build/ext/lodash/_defineProperty.js +0 -1
  82. package/build/packages/cmd/build/ext/lodash/_freeGlobal.js +0 -1
  83. package/build/packages/cmd/build/ext/lodash/_getMapData.js +0 -1
  84. package/build/packages/cmd/build/ext/lodash/_getNative.js +0 -1
  85. package/build/packages/cmd/build/ext/lodash/_getRawTag.js +0 -1
  86. package/build/packages/cmd/build/ext/lodash/_getTag.js +0 -1
  87. package/build/packages/cmd/build/ext/lodash/_getValue.js +0 -1
  88. package/build/packages/cmd/build/ext/lodash/_hashClear.js +0 -1
  89. package/build/packages/cmd/build/ext/lodash/_hashDelete.js +0 -1
  90. package/build/packages/cmd/build/ext/lodash/_hashGet.js +0 -1
  91. package/build/packages/cmd/build/ext/lodash/_hashHas.js +0 -1
  92. package/build/packages/cmd/build/ext/lodash/_hashSet.js +0 -1
  93. package/build/packages/cmd/build/ext/lodash/_isKeyable.js +0 -1
  94. package/build/packages/cmd/build/ext/lodash/_isMasked.js +0 -1
  95. package/build/packages/cmd/build/ext/lodash/_listCacheClear.js +0 -1
  96. package/build/packages/cmd/build/ext/lodash/_listCacheDelete.js +0 -1
  97. package/build/packages/cmd/build/ext/lodash/_listCacheGet.js +0 -1
  98. package/build/packages/cmd/build/ext/lodash/_listCacheHas.js +0 -1
  99. package/build/packages/cmd/build/ext/lodash/_listCacheSet.js +0 -1
  100. package/build/packages/cmd/build/ext/lodash/_mapCacheClear.js +0 -1
  101. package/build/packages/cmd/build/ext/lodash/_mapCacheDelete.js +0 -1
  102. package/build/packages/cmd/build/ext/lodash/_mapCacheGet.js +0 -1
  103. package/build/packages/cmd/build/ext/lodash/_mapCacheHas.js +0 -1
  104. package/build/packages/cmd/build/ext/lodash/_mapCacheSet.js +0 -1
  105. package/build/packages/cmd/build/ext/lodash/_nativeCreate.js +0 -1
  106. package/build/packages/cmd/build/ext/lodash/_nodeUtil.js +0 -1
  107. package/build/packages/cmd/build/ext/lodash/_objectToString.js +0 -1
  108. package/build/packages/cmd/build/ext/lodash/_root.js +0 -1
  109. package/build/packages/cmd/build/ext/lodash/_setCacheAdd.js +0 -1
  110. package/build/packages/cmd/build/ext/lodash/_setCacheHas.js +0 -1
  111. package/build/packages/cmd/build/ext/lodash/_setToArray.js +0 -1
  112. package/build/packages/cmd/build/ext/lodash/_strictIndexOf.js +0 -1
  113. package/build/packages/cmd/build/ext/lodash/_toSource.js +0 -1
  114. package/build/packages/cmd/build/ext/lodash/eq.js +0 -1
  115. package/build/packages/cmd/build/ext/lodash/isArguments.js +0 -1
  116. package/build/packages/cmd/build/ext/lodash/isBuffer.js +0 -1
  117. package/build/packages/cmd/build/ext/lodash/isFunction.js +0 -1
  118. package/build/packages/cmd/build/ext/lodash/isMap.js +0 -1
  119. package/build/packages/cmd/build/ext/lodash/isObject.js +0 -1
  120. package/build/packages/cmd/build/ext/lodash/isObjectLike.js +0 -1
  121. package/build/packages/cmd/build/ext/lodash/isSet.js +0 -1
  122. package/build/packages/cmd/build/ext/lodash/isTypedArray.js +0 -1
  123. package/build/packages/cmd/build/ext/lodash/noop.js +0 -1
  124. package/build/packages/cmd/build/ext/lodash/stubFalse.js +0 -1
  125. package/build/packages/cmd/build/ext/lodash/uniq.js +0 -1
  126. package/build/packages/cmd/build/ext/tslib/tslib.es6.js +0 -1
  127. package/build/packages/cmd/build/scripts/generators/api/index.js +0 -1
  128. package/build/packages/cmd/build/scripts/generators/api/info.js +0 -1
  129. package/build/packages/cmd/build/scripts/generators/components/index.js +0 -1
  130. package/build/packages/cmd/build/scripts/generators/pages/index.js +0 -1
  131. package/build/packages/cmd/build/scripts/generators/pages/info.js +0 -1
  132. package/build/packages/cmd/build/scripts/generators/theme/index.js +0 -1
  133. package/build/packages/cmd/build/scripts/generators/types/index.js +0 -1
  134. package/build/packages/cmd/build/utils/fs.js +0 -1
  135. package/build/packages/cmd/build/utils/helper.js +0 -1
  136. package/build/pages/404.d.ts +0 -2
  137. package/build/pages/404.js +0 -1
  138. package/build/pages/[slug]/index.d.ts +0 -3
  139. package/build/pages/_slug_/index.js +0 -1
  140. package/build/pages/account/addresses.d.ts +0 -2
  141. package/build/pages/account/addresses.js +0 -1
  142. package/build/pages/account/favorite-products.d.ts +0 -2
  143. package/build/pages/account/favorite-products.js +0 -1
  144. package/build/pages/account/forgot-password.d.ts +0 -2
  145. package/build/pages/account/forgot-password.js +0 -1
  146. package/build/pages/account/index.d.ts +0 -2
  147. package/build/pages/account/index.js +0 -1
  148. package/build/pages/account/login.d.ts +0 -2
  149. package/build/pages/account/login.js +0 -1
  150. package/build/pages/account/orders/[id].d.ts +0 -2
  151. package/build/pages/account/orders/_id_.js +0 -1
  152. package/build/pages/account/orders/index.d.ts +0 -2
  153. package/build/pages/account/orders/index.js +0 -1
  154. package/build/pages/account/raffles.d.ts +0 -2
  155. package/build/pages/account/raffles.js +0 -1
  156. package/build/pages/account/recover-password.d.ts +0 -2
  157. package/build/pages/account/recover-password.js +0 -1
  158. package/build/pages/account/register.d.ts +0 -2
  159. package/build/pages/account/register.js +0 -1
  160. package/build/pages/blog/[slug].d.ts +0 -3
  161. package/build/pages/blog/_slug_.js +0 -1
  162. package/build/pages/blog/index.d.ts +0 -2
  163. package/build/pages/blog/index.js +0 -1
  164. package/build/pages/cart.d.ts +0 -2
  165. package/build/pages/cart.js +0 -1
  166. package/build/pages/checkout.d.ts +0 -2
  167. package/build/pages/checkout.js +0 -1
  168. package/build/pages/editor.d.ts +0 -2
  169. package/build/pages/editor.js +0 -1
  170. package/build/pages/home.d.ts +0 -2
  171. package/build/pages/home.js +0 -1
  172. package/build/pages/pages/[slug].d.ts +0 -3
  173. package/build/pages/pages/_slug_.js +0 -1
  174. package/build/pages/raffle/[slug].d.ts +0 -3
  175. package/build/pages/raffle/_slug_.js +0 -1
  176. package/build/pages/raffle/index.d.ts +0 -2
  177. package/build/pages/raffle/index.js +0 -1
  178. package/build/pages/search.d.ts +0 -2
  179. package/build/pages/search.js +0 -1
  180. package/build/provider/page-data-next.d.ts +0 -93
  181. package/build/provider/page-data-next.js +0 -1
  182. package/build/utils/fs.d.ts +0 -28
  183. package/build/utils/fs.js +0 -1
  184. package/build/utils/google-fonts.d.ts +0 -2
  185. package/build/utils/google-fonts.js +0 -1
  186. package/build/utils/i18n.d.ts +0 -9
  187. package/build/utils/i18n.js +0 -1
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@ikas/storefront-next",
3
- "version": "4.0.0-alpha.59",
3
+ "version": "4.0.0-alpha.60",
4
4
  "description": "Next.js specific functions for ikas storefront themes.",
5
5
  "author": "Umut Ozan Yıldırım",
6
6
  "license": "ISC",
7
- "main": "./build/index.js",
8
- "module": "./build/index.js",
7
+ "main": "./src/index.ts",
8
+ "module": "./src/index.ts",
9
9
  "files": [
10
- "./build"
10
+ "./src"
11
11
  ],
12
12
  "type": "module",
13
13
  "scripts": {
@@ -17,23 +17,23 @@
17
17
  },
18
18
  "peerDependencies": {
19
19
  "next": "12.2.0",
20
- "@ikas/storefront-config": "^4.0.0-alpha.59",
21
- "@ikas/storefront-providers": "^4.0.0-alpha.59",
22
- "@ikas/storefront-models": "^4.0.0-alpha.59",
23
- "@ikas/storefront-api": "^4.0.0-alpha.59",
24
- "@ikas/storefront-assets": "^4.0.0-alpha.59",
20
+ "@ikas/storefront-config": "^4.0.0-alpha.60",
21
+ "@ikas/storefront-providers": "^4.0.0-alpha.60",
22
+ "@ikas/storefront-models": "^4.0.0-alpha.60",
23
+ "@ikas/storefront-api": "^4.0.0-alpha.60",
24
+ "@ikas/storefront-assets": "^4.0.0-alpha.60",
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.59",
32
- "@ikas/storefront-config": "^4.0.0-alpha.59",
33
- "@ikas/storefront-providers": "^4.0.0-alpha.59",
34
- "@ikas/storefront-models": "^4.0.0-alpha.59",
35
- "@ikas/storefront-api": "^4.0.0-alpha.59",
36
- "@ikas/storefront-assets": "^4.0.0-alpha.59",
31
+ "@ikas/storefront-cmd": "^4.0.0-alpha.60",
32
+ "@ikas/storefront-config": "^4.0.0-alpha.60",
33
+ "@ikas/storefront-providers": "^4.0.0-alpha.60",
34
+ "@ikas/storefront-models": "^4.0.0-alpha.60",
35
+ "@ikas/storefront-api": "^4.0.0-alpha.60",
36
+ "@ikas/storefront-assets": "^4.0.0-alpha.60",
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",
@@ -0,0 +1,39 @@
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
+ }
@@ -0,0 +1,22 @@
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,11 +1,14 @@
1
- import * as GetComponentDirs from "./getComponentDirs";
2
- import * as GetTheme from "./getTheme";
3
- import * as UpdateTheme from "./updateTheme";
4
- import * as UploadTheme from "./uploadTheme";
5
- declare const IkasLocalThemeAPI: {
6
- GetComponentDirs: typeof GetComponentDirs;
7
- GetTheme: typeof GetTheme;
8
- UpdateTheme: typeof UpdateTheme;
9
- UploadTheme: typeof UploadTheme;
10
- };
11
- export { IkasLocalThemeAPI };
1
+ // API
2
+ import * as GetComponentDirs from "./getComponentDirs";
3
+ import * as GetTheme from "./getTheme";
4
+ import * as UpdateTheme from "./updateTheme";
5
+ import * as UploadTheme from "./uploadTheme";
6
+
7
+ const IkasLocalThemeAPI = {
8
+ GetComponentDirs,
9
+ GetTheme,
10
+ UpdateTheme,
11
+ UploadTheme,
12
+ };
13
+
14
+ export { IkasLocalThemeAPI };
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,33 @@
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
+ };
@@ -0,0 +1,311 @@
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 CheckoutDE from "@ikas/storefront-assets/checkout/de.js";
9
+ //@ts-ignore
10
+ import CheckoutEN from "@ikas/storefront-assets/checkout/en.js";
11
+ //@ts-ignore
12
+ import CheckoutTR from "@ikas/storefront-assets/checkout/tr.js";
13
+
14
+ import { corsMiddleware } from "./middleware";
15
+
16
+ export const uploadTheme = async (
17
+ req: NextApiRequest,
18
+ res: NextApiResponse
19
+ ) => {
20
+ await corsMiddleware(req, res);
21
+ try {
22
+ const theme = await getTheme();
23
+
24
+ const localization = await readLocalizationFiles();
25
+ const uploadUrl = await saveTheme(theme, localization);
26
+
27
+ if (typeof uploadUrl === "string") {
28
+ const zipDir = await archiveThemeCode();
29
+ const stat = fs.statSync(zipDir);
30
+ const success = await _uploadTheme(
31
+ uploadUrl,
32
+ fs.readFileSync(zipDir),
33
+ stat.size
34
+ );
35
+ console.log(success);
36
+ if (success) {
37
+ buildTheme();
38
+ }
39
+ deleteThemeZip(zipDir);
40
+ }
41
+
42
+ res.statusCode = 200;
43
+ res.setHeader("Content-Type", "application/json");
44
+ res.json({ status: "ok" });
45
+ } catch (err) {
46
+ console.log(err);
47
+ res.statusCode = 400;
48
+ res.setHeader("Content-Type", "application/json");
49
+ res.json({ status: "failed" });
50
+ }
51
+ };
52
+
53
+ export const config = {};
54
+
55
+ async function archiveThemeCode(): Promise<string> {
56
+ const themePath = path.join(process.cwd());
57
+
58
+ const filename = "theme.zip";
59
+ const dirname = path.join(process.cwd(), filename);
60
+ const output = fs.createWriteStream(dirname);
61
+ const archive = archiver("zip", {
62
+ zlib: {
63
+ level: 9,
64
+ },
65
+ });
66
+
67
+ archive.on("warning", function (err) {
68
+ if (err.code !== "ENOENT") {
69
+ throw err;
70
+ }
71
+ });
72
+
73
+ archive.on("error", function (err) {
74
+ throw err;
75
+ });
76
+
77
+ archive.pipe(output);
78
+
79
+ const excludedDirs = ["node_modules", ".next", "out", ".git"];
80
+ const files = fs.readdirSync(themePath);
81
+
82
+ files.forEach((file) => {
83
+ const filePath = path.join(themePath, file);
84
+ const stat = fs.lstatSync(filePath);
85
+
86
+ if (stat.isDirectory()) {
87
+ if (excludedDirs.includes(file)) return;
88
+ archive.directory(filePath, file);
89
+ } else {
90
+ archive.file(filePath, { name: file });
91
+ }
92
+ });
93
+
94
+ await archive.finalize();
95
+
96
+ return new Promise((resolve) => {
97
+ setTimeout(() => {
98
+ resolve(dirname);
99
+ }, 2000);
100
+ });
101
+ }
102
+
103
+ async function saveTheme(theme: any, localization: Record<string, any>) {
104
+ try {
105
+ const locales = Object.keys(localization);
106
+ const defaultLocale = locales.some((l) => l === "en") ? "en" : locales[0];
107
+ const config = await getStorefrontConfig();
108
+
109
+ const response = await axios({
110
+ method: "post",
111
+ url: process.env.NEXT_PUBLIC_UPLOAD_GQL_URL!,
112
+ headers: {
113
+ "x-api-key": config.apiKey,
114
+ "Content-Type": "application/json",
115
+ },
116
+ data: JSON.stringify({
117
+ query: /* GraphQL */ `
118
+ mutation saveTheme($saveThemeInput: SaveThemeInput!) {
119
+ saveTheme(input: $saveThemeInput) {
120
+ themeVersionId
121
+ uploadUrl
122
+ }
123
+ }
124
+ `,
125
+ variables: {
126
+ saveThemeInput: {
127
+ id: config.themeId,
128
+ themeJson: JSON.stringify(theme),
129
+ locales: Object.entries(localization).map(
130
+ ([locale, localeTranslations]) => ({
131
+ isDefaultLocale: locale === defaultLocale,
132
+ locale,
133
+ localeJson: JSON.stringify(localeTranslations),
134
+ })
135
+ ),
136
+ },
137
+ },
138
+ }),
139
+ });
140
+
141
+ // const response = await fetch(process.env.NEXT_PUBLIC_UPLOAD_GQL_URL!, {
142
+ // method: "POST",
143
+ // body: JSON.stringify({
144
+ // query: /* GraphQL */ `
145
+ // mutation saveTheme($saveThemeInput: SaveThemeInput!) {
146
+ // saveTheme(input: $saveThemeInput) {
147
+ // themeVersionId
148
+ // uploadUrl
149
+ // }
150
+ // }
151
+ // `,
152
+ // variables: {
153
+ // saveThemeInput: {
154
+ // id: config.themeId,
155
+ // themeJson: JSON.stringify(theme),
156
+ // locales: Object.entries(localization).map(
157
+ // ([locale, localeTranslations]) => ({
158
+ // isDefaultLocale: locale === defaultLocale,
159
+ // locale,
160
+ // localeJson: JSON.stringify(localeTranslations),
161
+ // })
162
+ // ),
163
+ // },
164
+ // },
165
+ // }),
166
+ // headers: {
167
+ // "x-api-key": config.apiKey,
168
+ // "Content-Type": "application/json",
169
+ // },
170
+ // });
171
+ const responseJSON = await response.data;
172
+
173
+ if (responseJSON.data && responseJSON.data.saveTheme) {
174
+ return responseJSON.data.saveTheme.uploadUrl as string;
175
+ }
176
+ } catch (err) {
177
+ console.log(err);
178
+ }
179
+ }
180
+
181
+ async function _uploadTheme(uploadUrl: string, file: Buffer, size: number) {
182
+ const config = {
183
+ headers: {
184
+ "Content-Type": "application/zip",
185
+ "Content-Length": size + "",
186
+ },
187
+ };
188
+
189
+ try {
190
+ const res = await axios.put(uploadUrl, file, config);
191
+ return res.status === 200;
192
+ } catch (err) {
193
+ console.log(err);
194
+ return false;
195
+ }
196
+ }
197
+
198
+ async function buildTheme() {
199
+ try {
200
+ const config = await getStorefrontConfig();
201
+ const response = await fetch(process.env.NEXT_PUBLIC_UPLOAD_GQL_URL!, {
202
+ method: "POST",
203
+ body: JSON.stringify({
204
+ query: /* GraphQL */ `
205
+ mutation buildTheme($buildThemeThemeId: String!) {
206
+ buildTheme(themeId: $buildThemeThemeId)
207
+ }
208
+ `,
209
+ variables: {
210
+ buildThemeThemeId: config.themeId,
211
+ },
212
+ }),
213
+ headers: {
214
+ "x-api-key": config.apiKey,
215
+ "Content-Type": "application/json",
216
+ },
217
+ });
218
+ const responseJSON = await response.json();
219
+ console.log(responseJSON);
220
+ } catch (err) {
221
+ console.log(err);
222
+ }
223
+ }
224
+
225
+ function getTheme(): Promise<any> {
226
+ return new Promise((resolve, reject) => {
227
+ const themePath = path.join(process.cwd(), "src", "theme.json");
228
+ fs.readFile(themePath, function (err, file) {
229
+ if (err) {
230
+ return reject(err);
231
+ }
232
+ resolve(JSON.parse(file.toString()));
233
+ });
234
+ });
235
+ }
236
+
237
+ function getStorefrontConfig(): Promise<Record<string, any>> {
238
+ return new Promise((resolve, reject) => {
239
+ const themePath = path.join(process.cwd(), "config.json");
240
+ fs.readFile(themePath, function (err, file) {
241
+ if (err) {
242
+ return reject(err);
243
+ }
244
+ resolve(JSON.parse(file.toString()));
245
+ });
246
+ });
247
+ }
248
+
249
+ function deleteThemeZip(zipDir: string) {
250
+ fs.unlinkSync(zipDir);
251
+ }
252
+
253
+ function readLocalizationFiles(): Promise<Record<string, any>> {
254
+ return new Promise((resolve, reject) => {
255
+ const localesPath = path.join(process.cwd(), "public", "locales");
256
+ const stripExtension = (path: string) =>
257
+ path.length ? path.split(".")[0] : path;
258
+
259
+ fs.readdir(localesPath, function (err, files) {
260
+ if (err) {
261
+ return reject(err);
262
+ }
263
+
264
+ const localeDirs = files.filter((file) =>
265
+ fs.lstatSync(path.join(localesPath, file)).isDirectory()
266
+ );
267
+
268
+ const locales: Record<string, any> = {};
269
+ let hasError = false;
270
+
271
+ localeDirs.forEach((locale) => {
272
+ const localeDirPath = path.join(
273
+ process.cwd(),
274
+ "public",
275
+ "locales",
276
+ locale
277
+ );
278
+
279
+ locales[locale] = {};
280
+
281
+ try {
282
+ const localeFiles = fs.readdirSync(localeDirPath);
283
+ localeFiles.forEach((localeFile) => {
284
+ const file = fs.readFileSync(
285
+ path.join(process.cwd(), "public", "locales", locale, localeFile)
286
+ );
287
+
288
+ const strippedLocale = stripExtension(locale).toLowerCase();
289
+ const namespace = stripExtension(localeFile).toLowerCase();
290
+
291
+ locales[strippedLocale][namespace] = JSON.parse(file.toString());
292
+
293
+ if (strippedLocale === "tr") {
294
+ locales[strippedLocale]["checkout-page"] = CheckoutTR;
295
+ } else if (strippedLocale === "de") {
296
+ locales[strippedLocale]["checkout-page"] = CheckoutDE;
297
+ } else {
298
+ locales[strippedLocale]["checkout-page"] = CheckoutEN;
299
+ }
300
+ });
301
+ } catch (err) {
302
+ console.error(err);
303
+ hasError = true;
304
+ }
305
+ });
306
+
307
+ if (hasError) reject(null);
308
+ else resolve(locales);
309
+ });
310
+ });
311
+ }
@@ -1,4 +1,4 @@
1
- export * from "./api";
2
- export * from "./pages";
3
- export * from "./provider/page-data-next";
4
- export { getGoogleFontHref } from "./utils/google-fonts";
1
+ export * from "./api";
2
+ export * from "./pages";
3
+ export * from "./provider/page-data-next";
4
+ export { getGoogleFontHref } from "./utils/google-fonts";
@@ -0,0 +1,18 @@
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
+ };
@@ -0,0 +1,18 @@
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
+ };
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,10 @@
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.RAFFLE_ACCOUNT
9
+ );
10
+ };
@@ -0,0 +1,10 @@
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.RECOVER_PASSWORD
9
+ );
10
+ };
@@ -0,0 +1,10 @@
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.REGISTER
9
+ );
10
+ };