@ikas/storefront-next 4.0.0-alpha.78 → 4.0.0-alpha.8

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 +17 -18
  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 +307 -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 +618 -0
  33. package/src/utils/fs.ts +93 -0
  34. package/src/utils/google-fonts.ts +52 -0
  35. package/src/utils/i18n.ts +80 -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 -94
  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.78",
3
+ "version": "4.0.0-alpha.8",
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": {
@@ -16,34 +16,33 @@
16
16
  "build": "rm -rf build && rollup -c"
17
17
  },
18
18
  "peerDependencies": {
19
- "next": "12.2.0",
20
- "@ikas/storefront-config": "^4.0.0-alpha.78",
21
- "@ikas/storefront-providers": "^4.0.0-alpha.78",
22
- "@ikas/storefront-models": "^4.0.0-alpha.78",
23
- "@ikas/storefront-api": "^4.0.0-alpha.78",
24
- "@ikas/storefront-assets": "^4.0.0-alpha.78",
19
+ "next": "canary",
20
+ "@ikas/storefront-config": "^4.0.0-alpha.8",
21
+ "@ikas/storefront-providers": "^4.0.0-alpha.8",
22
+ "@ikas/storefront-models": "^4.0.0-alpha.8",
23
+ "@ikas/storefront-api": "^4.0.0-alpha.8",
24
+ "@ikas/storefront-assets": "^4.0.0-alpha.8",
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.78",
32
- "@ikas/storefront-config": "^4.0.0-alpha.78",
33
- "@ikas/storefront-providers": "^4.0.0-alpha.78",
34
- "@ikas/storefront-models": "^4.0.0-alpha.78",
35
- "@ikas/storefront-api": "^4.0.0-alpha.78",
36
- "@ikas/storefront-assets": "^4.0.0-alpha.78",
31
+ "@ikas/storefront-cmd": "^4.0.0-alpha.8",
32
+ "@ikas/storefront-config": "^4.0.0-alpha.8",
33
+ "@ikas/storefront-providers": "^4.0.0-alpha.8",
34
+ "@ikas/storefront-models": "^4.0.0-alpha.8",
35
+ "@ikas/storefront-api": "^4.0.0-alpha.8",
36
+ "@ikas/storefront-assets": "^4.0.0-alpha.8",
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",
41
40
  "@types/archiver": "^5.1.0",
42
41
  "@types/node": "^14.14.6",
43
42
  "@types/node-fetch": "^2.5.7",
44
43
  "@types/cors": "^2.8.9",
45
44
  "@types/lodash": "^4.14.168",
46
- "next": "12.2.0",
45
+ "next": "canary",
47
46
  "prettier": "^2.2.1",
48
47
  "rollup": "^2.75.6",
49
48
  "rollup-plugin-terser": "^7.0.2",
@@ -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,307 @@
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
+ }
@@ -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
+ };