@ikas/storefront-cmd 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 (171) hide show
  1. package/build/ikas.cjs +2 -1
  2. package/package.json +6 -7
  3. package/{build/index.d.ts → src/index.ts} +4 -3
  4. package/src/scripts/generators/api/index.ts +27 -0
  5. package/src/scripts/generators/api/info.ts +47 -0
  6. package/src/scripts/generators/components/index.ts +244 -0
  7. package/src/scripts/generators/config/content.ts +168 -0
  8. package/src/scripts/generators/config/index.ts +106 -0
  9. package/{build/scripts/generators/index.d.ts → src/scripts/generators/index.ts} +6 -6
  10. package/src/scripts/generators/pages/index.ts +102 -0
  11. package/src/scripts/generators/pages/info.ts +161 -0
  12. package/src/scripts/generators/theme/index.ts +63 -0
  13. package/src/scripts/generators/types/index.ts +520 -0
  14. package/src/scripts/ikas.ts +45 -0
  15. package/src/scripts/theme-build/index.ts +99 -0
  16. package/src/utils/fs.ts +93 -0
  17. package/src/utils/helper.ts +20 -0
  18. package/build/_virtual/_cloneBuffer.js +0 -1
  19. package/build/_virtual/_commonjsHelpers.js +0 -1
  20. package/build/_virtual/_nodeUtil.js +0 -1
  21. package/build/_virtual/isBuffer.js +0 -1
  22. package/build/ext/lodash/_DataView.js +0 -1
  23. package/build/ext/lodash/_Hash.js +0 -1
  24. package/build/ext/lodash/_ListCache.js +0 -1
  25. package/build/ext/lodash/_Map.js +0 -1
  26. package/build/ext/lodash/_MapCache.js +0 -1
  27. package/build/ext/lodash/_Promise.js +0 -1
  28. package/build/ext/lodash/_Set.js +0 -1
  29. package/build/ext/lodash/_SetCache.js +0 -1
  30. package/build/ext/lodash/_Stack.js +0 -1
  31. package/build/ext/lodash/_Symbol.js +0 -1
  32. package/build/ext/lodash/_Uint8Array.js +0 -1
  33. package/build/ext/lodash/_WeakMap.js +0 -1
  34. package/build/ext/lodash/_arrayEach.js +0 -1
  35. package/build/ext/lodash/_arrayFilter.js +0 -1
  36. package/build/ext/lodash/_arrayIncludes.js +0 -1
  37. package/build/ext/lodash/_arrayIncludesWith.js +0 -1
  38. package/build/ext/lodash/_arrayLikeKeys.js +0 -1
  39. package/build/ext/lodash/_arrayPush.js +0 -1
  40. package/build/ext/lodash/_assignValue.js +0 -1
  41. package/build/ext/lodash/_assocIndexOf.js +0 -1
  42. package/build/ext/lodash/_baseAssign.js +0 -1
  43. package/build/ext/lodash/_baseAssignIn.js +0 -1
  44. package/build/ext/lodash/_baseAssignValue.js +0 -1
  45. package/build/ext/lodash/_baseClone.js +0 -1
  46. package/build/ext/lodash/_baseCreate.js +0 -1
  47. package/build/ext/lodash/_baseFindIndex.js +0 -1
  48. package/build/ext/lodash/_baseGetAllKeys.js +0 -1
  49. package/build/ext/lodash/_baseGetTag.js +0 -1
  50. package/build/ext/lodash/_baseIndexOf.js +0 -1
  51. package/build/ext/lodash/_baseIsArguments.js +0 -1
  52. package/build/ext/lodash/_baseIsMap.js +0 -1
  53. package/build/ext/lodash/_baseIsNaN.js +0 -1
  54. package/build/ext/lodash/_baseIsNative.js +0 -1
  55. package/build/ext/lodash/_baseIsSet.js +0 -1
  56. package/build/ext/lodash/_baseIsTypedArray.js +0 -1
  57. package/build/ext/lodash/_baseKeys.js +0 -1
  58. package/build/ext/lodash/_baseKeysIn.js +0 -1
  59. package/build/ext/lodash/_baseTimes.js +0 -1
  60. package/build/ext/lodash/_baseUnary.js +0 -1
  61. package/build/ext/lodash/_baseUniq.js +0 -1
  62. package/build/ext/lodash/_cacheHas.js +0 -1
  63. package/build/ext/lodash/_cloneArrayBuffer.js +0 -1
  64. package/build/ext/lodash/_cloneBuffer.js +0 -1
  65. package/build/ext/lodash/_cloneDataView.js +0 -1
  66. package/build/ext/lodash/_cloneRegExp.js +0 -1
  67. package/build/ext/lodash/_cloneSymbol.js +0 -1
  68. package/build/ext/lodash/_cloneTypedArray.js +0 -1
  69. package/build/ext/lodash/_copyArray.js +0 -1
  70. package/build/ext/lodash/_copyObject.js +0 -1
  71. package/build/ext/lodash/_copySymbols.js +0 -1
  72. package/build/ext/lodash/_copySymbolsIn.js +0 -1
  73. package/build/ext/lodash/_coreJsData.js +0 -1
  74. package/build/ext/lodash/_createSet.js +0 -1
  75. package/build/ext/lodash/_defineProperty.js +0 -1
  76. package/build/ext/lodash/_freeGlobal.js +0 -1
  77. package/build/ext/lodash/_getAllKeys.js +0 -1
  78. package/build/ext/lodash/_getAllKeysIn.js +0 -1
  79. package/build/ext/lodash/_getMapData.js +0 -1
  80. package/build/ext/lodash/_getNative.js +0 -1
  81. package/build/ext/lodash/_getPrototype.js +0 -1
  82. package/build/ext/lodash/_getRawTag.js +0 -1
  83. package/build/ext/lodash/_getSymbols.js +0 -1
  84. package/build/ext/lodash/_getSymbolsIn.js +0 -1
  85. package/build/ext/lodash/_getTag.js +0 -1
  86. package/build/ext/lodash/_getValue.js +0 -1
  87. package/build/ext/lodash/_hashClear.js +0 -1
  88. package/build/ext/lodash/_hashDelete.js +0 -1
  89. package/build/ext/lodash/_hashGet.js +0 -1
  90. package/build/ext/lodash/_hashHas.js +0 -1
  91. package/build/ext/lodash/_hashSet.js +0 -1
  92. package/build/ext/lodash/_initCloneArray.js +0 -1
  93. package/build/ext/lodash/_initCloneByTag.js +0 -1
  94. package/build/ext/lodash/_initCloneObject.js +0 -1
  95. package/build/ext/lodash/_isIndex.js +0 -1
  96. package/build/ext/lodash/_isKeyable.js +0 -1
  97. package/build/ext/lodash/_isMasked.js +0 -1
  98. package/build/ext/lodash/_isPrototype.js +0 -1
  99. package/build/ext/lodash/_listCacheClear.js +0 -1
  100. package/build/ext/lodash/_listCacheDelete.js +0 -1
  101. package/build/ext/lodash/_listCacheGet.js +0 -1
  102. package/build/ext/lodash/_listCacheHas.js +0 -1
  103. package/build/ext/lodash/_listCacheSet.js +0 -1
  104. package/build/ext/lodash/_mapCacheClear.js +0 -1
  105. package/build/ext/lodash/_mapCacheDelete.js +0 -1
  106. package/build/ext/lodash/_mapCacheGet.js +0 -1
  107. package/build/ext/lodash/_mapCacheHas.js +0 -1
  108. package/build/ext/lodash/_mapCacheSet.js +0 -1
  109. package/build/ext/lodash/_nativeCreate.js +0 -1
  110. package/build/ext/lodash/_nativeKeys.js +0 -1
  111. package/build/ext/lodash/_nativeKeysIn.js +0 -1
  112. package/build/ext/lodash/_nodeUtil.js +0 -1
  113. package/build/ext/lodash/_objectToString.js +0 -1
  114. package/build/ext/lodash/_overArg.js +0 -1
  115. package/build/ext/lodash/_root.js +0 -1
  116. package/build/ext/lodash/_setCacheAdd.js +0 -1
  117. package/build/ext/lodash/_setCacheHas.js +0 -1
  118. package/build/ext/lodash/_setToArray.js +0 -1
  119. package/build/ext/lodash/_stackClear.js +0 -1
  120. package/build/ext/lodash/_stackDelete.js +0 -1
  121. package/build/ext/lodash/_stackGet.js +0 -1
  122. package/build/ext/lodash/_stackHas.js +0 -1
  123. package/build/ext/lodash/_stackSet.js +0 -1
  124. package/build/ext/lodash/_strictIndexOf.js +0 -1
  125. package/build/ext/lodash/_toSource.js +0 -1
  126. package/build/ext/lodash/cloneDeep.js +0 -1
  127. package/build/ext/lodash/eq.js +0 -1
  128. package/build/ext/lodash/isArguments.js +0 -1
  129. package/build/ext/lodash/isArray.js +0 -1
  130. package/build/ext/lodash/isArrayLike.js +0 -1
  131. package/build/ext/lodash/isBuffer.js +0 -1
  132. package/build/ext/lodash/isFunction.js +0 -1
  133. package/build/ext/lodash/isLength.js +0 -1
  134. package/build/ext/lodash/isMap.js +0 -1
  135. package/build/ext/lodash/isObject.js +0 -1
  136. package/build/ext/lodash/isObjectLike.js +0 -1
  137. package/build/ext/lodash/isSet.js +0 -1
  138. package/build/ext/lodash/isTypedArray.js +0 -1
  139. package/build/ext/lodash/keys.js +0 -1
  140. package/build/ext/lodash/keysIn.js +0 -1
  141. package/build/ext/lodash/noop.js +0 -1
  142. package/build/ext/lodash/stubArray.js +0 -1
  143. package/build/ext/lodash/stubFalse.js +0 -1
  144. package/build/ext/lodash/uniq.js +0 -1
  145. package/build/ext/tslib/tslib.es6.js +0 -1
  146. package/build/index.js +0 -1
  147. package/build/scripts/generators/api/index.d.ts +0 -5
  148. package/build/scripts/generators/api/index.js +0 -1
  149. package/build/scripts/generators/api/info.d.ts +0 -12
  150. package/build/scripts/generators/api/info.js +0 -1
  151. package/build/scripts/generators/components/index.d.ts +0 -11
  152. package/build/scripts/generators/components/index.js +0 -1
  153. package/build/scripts/generators/config/content.d.ts +0 -61
  154. package/build/scripts/generators/config/content.js +0 -1
  155. package/build/scripts/generators/config/index.d.ts +0 -9
  156. package/build/scripts/generators/config/index.js +0 -1
  157. package/build/scripts/generators/pages/index.d.ts +0 -7
  158. package/build/scripts/generators/pages/index.js +0 -1
  159. package/build/scripts/generators/pages/info.d.ts +0 -14
  160. package/build/scripts/generators/pages/info.js +0 -1
  161. package/build/scripts/generators/theme/index.d.ts +0 -6
  162. package/build/scripts/generators/theme/index.js +0 -1
  163. package/build/scripts/generators/types/index.d.ts +0 -19
  164. package/build/scripts/generators/types/index.js +0 -1
  165. package/build/scripts/ikas.d.ts +0 -1
  166. package/build/scripts/theme-build/index.d.ts +0 -3
  167. package/build/scripts/theme-build/index.js +0 -1
  168. package/build/utils/fs.d.ts +0 -28
  169. package/build/utils/fs.js +0 -1
  170. package/build/utils/helper.d.ts +0 -2
  171. package/build/utils/helper.js +0 -1
@@ -0,0 +1,244 @@
1
+ import path from "path";
2
+ import { createFile, deleteDirContent } from "../../../utils/fs";
3
+ import {
4
+ IkasThemeJson,
5
+ IkasThemeJsonComponent,
6
+ IkasThemeJsonPageType,
7
+ } from "@ikas/storefront-models";
8
+ import { CHECKOUT_COMPONENT_ID, PageInfo, PAGE_INFO } from "../pages/info";
9
+ import { findAllByKey } from "../../../utils/helper";
10
+
11
+ export class ComponentImportsGenerator {
12
+ static async generate(themeJson: IkasThemeJson) {
13
+ await deleteDirContent(
14
+ path.join(process.cwd(), "src", "components", "__generated__")
15
+ );
16
+
17
+ return (
18
+ (await ComponentImportsGenerator.generateAllPageComponentImportsFiles(
19
+ themeJson
20
+ )) &&
21
+ (await ComponentImportsGenerator.generateAllComponentImportsFileForEditor(
22
+ themeJson
23
+ ))
24
+ );
25
+ }
26
+
27
+ static async generateAllPageComponentImportsFiles(themeJson: IkasThemeJson) {
28
+ let isSuccess = true;
29
+
30
+ for (const pageInfo of PAGE_INFO) {
31
+ // const themeHasPage = themeJson.pages.some((page) =>
32
+ // pageInfo.pageTypes.includes(page.type)
33
+ // );
34
+ // if (themeHasPage) {
35
+ // }
36
+ isSuccess =
37
+ isSuccess &&
38
+ (await ComponentImportsGenerator.generatePageComponentImportsFileWithInfo(
39
+ pageInfo,
40
+ themeJson
41
+ ));
42
+ }
43
+
44
+ return isSuccess;
45
+ }
46
+
47
+ static async generatePageComponentImportsFileWithInfo(
48
+ pageInfo: PageInfo,
49
+ themeJson: IkasThemeJson
50
+ ) {
51
+ if (pageInfo.isCheckout || pageInfo.isEditor) return true;
52
+
53
+ try {
54
+ const components = themeJson.components;
55
+ const componentIds: string[] = [];
56
+
57
+ pageInfo.pageTypes.forEach((pageType) => {
58
+ const pages = themeJson.pages.filter((page) => page.type === pageType);
59
+
60
+ if (pages.length) {
61
+ pages.forEach((page) => {
62
+ const allPageComponents = page.components;
63
+ if (page.specifications?.length) {
64
+ page.specifications.forEach((specification) => {
65
+ allPageComponents.push(...specification.components);
66
+ });
67
+ }
68
+
69
+ componentIds.push(...allPageComponents.map((c) => c.componentId));
70
+
71
+ allPageComponents.forEach((pageComponent) => {
72
+ const component = components.find(
73
+ (c) => c.id === pageComponent.componentId
74
+ );
75
+ if (!component) return;
76
+
77
+ const nestedComponentIds = findAllByKey(
78
+ pageComponent.propValues,
79
+ "componentId"
80
+ ) as Array<any>;
81
+
82
+ componentIds.push(...nestedComponentIds);
83
+ });
84
+ });
85
+ }
86
+ });
87
+
88
+ const componentsInPage = components.filter(
89
+ (c) => componentIds.includes(c.id) && c.id !== CHECKOUT_COMPONENT_ID
90
+ );
91
+
92
+ return await ComponentImportsGenerator.generateComponentImportsFile(
93
+ componentsInPage,
94
+ pageInfo
95
+ );
96
+ } catch (err) {
97
+ console.error(err);
98
+ return false;
99
+ }
100
+ }
101
+
102
+ static generatePageComponentImportsFileWithType(
103
+ pageType: IkasThemeJsonPageType,
104
+ themeJson: IkasThemeJson
105
+ ) {
106
+ if (pageType === IkasThemeJsonPageType.CHECKOUT) return;
107
+
108
+ try {
109
+ const pageInfo = PAGE_INFO.find((pi) => pi.pageTypes.includes(pageType));
110
+ if (pageInfo) {
111
+ return ComponentImportsGenerator.generatePageComponentImportsFileWithInfo(
112
+ pageInfo,
113
+ themeJson
114
+ );
115
+ }
116
+ } catch (err) {
117
+ console.error(err);
118
+ }
119
+
120
+ return false;
121
+ }
122
+
123
+ static generateComponentImportsFile(
124
+ components: IkasThemeJsonComponent[],
125
+ pageInfo: PageInfo
126
+ ) {
127
+ try {
128
+ let fileStr = "";
129
+
130
+ components
131
+ .filter((c: any) => c.id !== "checkout")
132
+ .forEach((component: any, index: number) => {
133
+ fileStr += `import Component${index} from "src/components/${component.dir}";\r\n`;
134
+ });
135
+
136
+ fileStr += `
137
+ const Components = {
138
+ ${components.map(
139
+ (component: any, index: number) => `"${component.id}": Component${index}`
140
+ )}
141
+ };
142
+ `;
143
+
144
+ fileStr += "\r\n";
145
+ fileStr += "export default Components;";
146
+
147
+ return createFile(
148
+ path.join(process.cwd(), "src", "components", "__generated__", "pages"),
149
+ pageInfo.path.replace("tsx", "ts"),
150
+ fileStr
151
+ );
152
+ } catch (err) {
153
+ console.error(err);
154
+ return false;
155
+ }
156
+ }
157
+
158
+ static async generateAllComponentImportsFileForEditor(
159
+ themeJson: IkasThemeJson
160
+ ) {
161
+ try {
162
+ let fileStr = `import dynamic from "next/dynamic";\r\n`;
163
+ fileStr += `import { IkasEditorComponentLoader } from "@ikas/storefront";\r\n`;
164
+ fileStr += "\r\n";
165
+ fileStr += "\r\n";
166
+
167
+ const components = themeJson.components.filter(
168
+ (tc: any) => tc.id !== "checkout"
169
+ );
170
+
171
+ // Component imports
172
+ components
173
+ .filter((c: any) => c.id !== "checkout")
174
+ .forEach((component: any, index: number) => {
175
+ fileStr += `const Component${index} = dynamic(() => import("../${component.dir}"), { loading: () => <IkasEditorComponentLoader /> });\r\n`;
176
+ });
177
+
178
+ fileStr += "\r\n";
179
+ fileStr += `
180
+ const Components = {
181
+ ${components.map(
182
+ (component: any, index: number) => `"${component.id}": Component${index}`
183
+ )}
184
+ };
185
+ `;
186
+
187
+ fileStr += "\r\n";
188
+ fileStr += "export default Components;";
189
+
190
+ const generatedFolderPath = path.join(
191
+ process.cwd(),
192
+ "src",
193
+ "components",
194
+ "__generated__"
195
+ );
196
+
197
+ return await createFile(generatedFolderPath, "editor.tsx", fileStr);
198
+ } catch (err) {
199
+ console.error(err);
200
+ return false;
201
+ }
202
+ }
203
+
204
+ static async generateAllComponentImportsFile(themeJson: IkasThemeJson) {
205
+ try {
206
+ let fileStr = ``;
207
+
208
+ const components = themeJson.components.filter(
209
+ (tc: any) => tc.id !== "checkout"
210
+ );
211
+
212
+ // Component imports
213
+ components
214
+ .filter((c: any) => c.id !== "checkout")
215
+ .forEach((component: any, index: number) => {
216
+ fileStr += `import Component${index} from "../${component.dir}";\r\n`;
217
+ });
218
+
219
+ fileStr += "\r\n";
220
+ fileStr += `
221
+ const Components = {
222
+ ${components.map(
223
+ (component: any, index: number) => `"${component.id}": Component${index}`
224
+ )}
225
+ };
226
+ `;
227
+
228
+ fileStr += "\r\n";
229
+ fileStr += "export default Components;";
230
+
231
+ const generatedFolderPath = path.join(
232
+ process.cwd(),
233
+ "src",
234
+ "components",
235
+ "__generated__"
236
+ );
237
+
238
+ return await createFile(generatedFolderPath, "index.tsx", fileStr);
239
+ } catch (err) {
240
+ console.error(err);
241
+ return false;
242
+ }
243
+ }
244
+ }
@@ -0,0 +1,168 @@
1
+ export const DEPENDENCIES = {
2
+ next: "canary",
3
+ react: "17.0.2",
4
+ "react-dom": "17.0.2",
5
+ mobx: "^6.1.3",
6
+ axios: "^0.26.0",
7
+ lodash: "^4.17.20",
8
+ archiver: "^5.3.0",
9
+ cors: "^2.8.5",
10
+ "html-react-parser": "^1.4.0",
11
+ "mobx-react-lite": "^3.1.5",
12
+ "next-transpile-modules": "^9.0.0",
13
+ "@ikas/storefront": "^4.0.0-alpha.7",
14
+ "@ikas/storefront-api": "^4.0.0-alpha.7",
15
+ "@ikas/storefront-assets": "^4.0.0-alpha.7",
16
+ "@ikas/storefront-cmd": "^4.0.0-alpha.7",
17
+ "@ikas/storefront-config": "^4.0.0-alpha.7",
18
+ "@ikas/storefront-model-functions": "^4.0.0-alpha.7",
19
+ "@ikas/storefront-models": "^4.0.0-alpha.7",
20
+ "@ikas/storefront-next": "^4.0.0-alpha.7",
21
+ "@ikas/storefront-providers": "^4.0.0-alpha.7",
22
+ };
23
+
24
+ export const DEV_DEPENDENCIES = {
25
+ "@types/node": "^14.14.6",
26
+ "@types/react": "^17.0.2",
27
+ "@types/react-dom": "^17.0.2",
28
+ "@typescript-eslint/eslint-plugin": "^2.10.0",
29
+ "@typescript-eslint/parser": "^2.10.0",
30
+ eslint: "^6.6.0",
31
+ "eslint-config-react-app": "^5.2.1",
32
+ "eslint-loader": "3.0.3",
33
+ "eslint-plugin-flowtype": "4.6.0",
34
+ "eslint-plugin-import": "2.20.1",
35
+ "eslint-plugin-jsx-a11y": "6.2.3",
36
+ "eslint-plugin-react": "7.19.0",
37
+ "eslint-plugin-react-hooks": "^1.6.1",
38
+ sass: "^1.43.4",
39
+ typescript: "^4.5.2",
40
+ };
41
+
42
+ export const RESOLUTIONS = {
43
+ "@types/react": "17.0.2",
44
+ "@types/react-dom": "17.0.2",
45
+ };
46
+
47
+ export const SCRIPTS = {
48
+ upgradeDependencies:
49
+ "yarn upgrade @ikas/storefront @ikas/storefront-api @ikas/storefront-assets @ikas/storefront-cmd @ikas/storefront-config @ikas/storefront-model-functions @ikas/storefront-models @ikas/storefront-next @ikas/storefront-providers",
50
+ dev: "next dev -p 3333",
51
+ build: "next build",
52
+ start: "next start",
53
+ generate: "ikas --generate",
54
+ "prettier:all": "npx prettier@^2.1 './**/src/**/*.(ts|tsx|css|scss)' --write",
55
+ };
56
+
57
+ export const TS_CONFIG = `{
58
+ "compilerOptions": {
59
+ "target": "esnext",
60
+ "lib": [
61
+ "dom",
62
+ "dom.iterable",
63
+ "esnext"
64
+ ],
65
+ "allowJs": true,
66
+ "skipLibCheck": true,
67
+ "strict": true,
68
+ "forceConsistentCasingInFileNames": true,
69
+ "experimentalDecorators": true,
70
+ "noEmit": true,
71
+ "esModuleInterop": true,
72
+ "module": "esnext",
73
+ "moduleResolution": "node",
74
+ "resolveJsonModule": true,
75
+ "isolatedModules": true,
76
+ "jsx": "preserve",
77
+ "baseUrl": ".",
78
+ "useUnknownInCatchVariables": false,
79
+ "incremental": true
80
+ },
81
+ "typeRoots": [
82
+ "./node_modules/@types"
83
+ ],
84
+ "include": [
85
+ "next-env.d.ts",
86
+ "**/*.ts",
87
+ "**/*.tsx",
88
+ "**/typings/global.d.ts",
89
+ ],
90
+ "exclude": [
91
+ "node_modules",
92
+ "./src/pages/api",
93
+ ]
94
+ }`;
95
+
96
+ export const NEXT_CONFIG = `const withTM = require("next-transpile-modules")([
97
+ "@ikas/storefront",
98
+ "@ikas/storefront-api",
99
+ "@ikas/storefront-assets",
100
+ "@ikas/storefront-cmd",
101
+ "@ikas/storefront-config",
102
+ "@ikas/storefront-model-functions",
103
+ "@ikas/storefront-models",
104
+ "@ikas/storefront-next",
105
+ "@ikas/storefront-providers",
106
+ ]);
107
+
108
+ const config = {
109
+ i18n: {
110
+ defaultLocale: "en",
111
+ locales: ["en"],
112
+ localeDetection: false,
113
+ },
114
+ basePath: process.env.NEXTJS_BASE_PATH || "",
115
+
116
+ images: {
117
+ deviceSizes: [
118
+ 180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 1950, 2560, 3840,
119
+ ],
120
+ },
121
+
122
+ webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
123
+ if (!isServer) {
124
+ config.resolve.fallback.fs = false;
125
+ config.resolve.fallback.net = false;
126
+ config.resolve.fallback.encoding = false;
127
+ config.resolve.fallback.crypto = false;
128
+ config.resolve.fallback.assert = false;
129
+ config.resolve.fallback.stream = false;
130
+ config.module.rules = [
131
+ ...config.module.rules,
132
+ {
133
+ test: /@ikas/i,
134
+ sideEffects: false,
135
+ },
136
+ ];
137
+ }
138
+ return config;
139
+ },
140
+ };
141
+
142
+ module.exports = withTM(config);`;
143
+
144
+ export const DEV_ENV = `NEXT_PUBLIC_ENV=local
145
+ NEXT_PUBLIC_BASE_URL=https://api.myikas.dev/api/sf
146
+ NEXT_PUBLIC_IMG_BASE_URL=https://cdn.myikas.dev/
147
+ NEXT_PUBLIC_UPLOAD_GQL_URL=https://api.myikas.dev/api/admin/graphql
148
+ NEXT_PUBLIC_GQL_URL=https://api.myikas.dev/api/sf/graphql
149
+ `;
150
+
151
+ export const PROD_ENV = `NEXT_PUBLIC_ENV=local
152
+ NEXT_PUBLIC_BASE_URL=https://api.myikas.com/api/sf
153
+ NEXT_PUBLIC_IMG_BASE_URL=https://cdn.myikas.com/
154
+ NEXT_PUBLIC_UPLOAD_GQL_URL=https://api.myikas.com/api/admin/graphql
155
+ NEXT_PUBLIC_GQL_URL=https://api.myikas.com/api/sf/graphql
156
+ `;
157
+
158
+ export const BABEL_RC = `{
159
+ "presets": [
160
+ [
161
+ "next/babel",
162
+ {
163
+ "preset-react": { "throwIfNamespace": false },
164
+ }
165
+ ]
166
+ ],
167
+ "plugins": []
168
+ }`;
@@ -0,0 +1,106 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import { sortObject } from "../../../utils/helper";
4
+ import { createFile } from "../../../utils/fs";
5
+ import {
6
+ TS_CONFIG,
7
+ BABEL_RC,
8
+ NEXT_CONFIG,
9
+ DEPENDENCIES,
10
+ DEV_DEPENDENCIES,
11
+ RESOLUTIONS,
12
+ SCRIPTS,
13
+ DEV_ENV,
14
+ PROD_ENV,
15
+ } from "./content";
16
+
17
+ export type ENV = "dev" | "prod";
18
+
19
+ export class ConfigGenerator {
20
+ static async generate(env: ENV) {
21
+ return (
22
+ (await ConfigGenerator.generateTsConfig()) &&
23
+ (await ConfigGenerator.generateBabelRc()) &&
24
+ (await ConfigGenerator.generateNextConfig()) &&
25
+ (await ConfigGenerator.generatePackageJson()) &&
26
+ (await ConfigGenerator.generateEnv(env))
27
+ );
28
+ }
29
+
30
+ static generateTsConfig() {
31
+ return createFile(process.cwd(), "tsconfig.json", TS_CONFIG);
32
+ }
33
+
34
+ static generateBabelRc() {
35
+ return createFile(process.cwd(), ".babelrc", BABEL_RC);
36
+ }
37
+
38
+ static generateNextConfig() {
39
+ return createFile(process.cwd(), "next.config.js", NEXT_CONFIG);
40
+ }
41
+
42
+ static async generatePackageJson() {
43
+ try {
44
+ // const fs = await import("fs-extra");
45
+ const packageJsonPath = path.join(process.cwd(), "package.json");
46
+ const packageJsonBuffer = fs.readFileSync(packageJsonPath);
47
+
48
+ if (packageJsonBuffer.length) {
49
+ const packageJson = JSON.parse(packageJsonBuffer.toString());
50
+
51
+ const setDependencies = (type: "dev" | "normal") => {
52
+ const dependencies = type === "dev" ? DEV_DEPENDENCIES : DEPENDENCIES;
53
+ const dependenciesKey =
54
+ type === "dev" ? "devDependencies" : "dependencies";
55
+
56
+ if (
57
+ !packageJson[dependenciesKey] ||
58
+ typeof packageJson[dependenciesKey] !== "object"
59
+ ) {
60
+ packageJson[dependenciesKey] = dependencies;
61
+ } else {
62
+ packageJson[dependenciesKey] = {
63
+ ...packageJson[dependenciesKey],
64
+ ...dependencies,
65
+ };
66
+ }
67
+
68
+ const orderedDependencies = sortObject(packageJson[dependenciesKey]);
69
+
70
+ packageJson[dependenciesKey] = orderedDependencies;
71
+ };
72
+
73
+ setDependencies("dev");
74
+ setDependencies("normal");
75
+
76
+ if (!packageJson.scripts || typeof packageJson.scripts !== "object") {
77
+ packageJson.scripts = SCRIPTS;
78
+ } else {
79
+ packageJson.scripts = {
80
+ ...packageJson.scripts,
81
+ ...SCRIPTS,
82
+ };
83
+ }
84
+
85
+ packageJson.resolutions = {
86
+ ...packageJson.resolutions,
87
+ ...RESOLUTIONS,
88
+ };
89
+
90
+ return await createFile(
91
+ packageJsonPath,
92
+ "",
93
+ JSON.stringify(packageJson, null, 2)
94
+ );
95
+ }
96
+ } catch (err) {
97
+ console.error(err);
98
+ return false;
99
+ }
100
+ }
101
+
102
+ static generateEnv(env: ENV) {
103
+ const envFileContent = env === "dev" ? DEV_ENV : PROD_ENV;
104
+ return createFile(process.cwd(), ".env", envFileContent);
105
+ }
106
+ }
@@ -1,6 +1,6 @@
1
- export * from "./api";
2
- export * from "./components";
3
- export * from "./config";
4
- export * from "./pages";
5
- export * from "./theme";
6
- export * from "./types";
1
+ export * from "./api";
2
+ export * from "./components";
3
+ export * from "./config";
4
+ export * from "./pages";
5
+ export * from "./theme";
6
+ export * from "./types";
@@ -0,0 +1,102 @@
1
+ import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
+ import path from "path";
3
+ import { createFile, deleteDirContent } from "../../../utils/fs";
4
+ import {
5
+ PageInfo,
6
+ PAGE_INFO,
7
+ CHECKOUT_PAGE_CONTENT,
8
+ EDITOR_PAGE_CONTENT,
9
+ } from "./info";
10
+
11
+ export class PageGenerator {
12
+ static async generate() {
13
+ const pagesDir = path.join(process.cwd(), "src", "pages");
14
+ await deleteDirContent(pagesDir, ["_app.tsx", "_document.tsx", "api"]);
15
+
16
+ let pagesGenerateSuccess = true;
17
+ for (const pageInfo of PAGE_INFO) {
18
+ pagesGenerateSuccess =
19
+ pagesGenerateSuccess &&
20
+ (await PageGenerator.generatePageWithInfo(pageInfo));
21
+ }
22
+
23
+ const checkoutPageInfo = PAGE_INFO.find((pi) => pi.isCheckout);
24
+ const editorPageInfo = PAGE_INFO.find((pi) => pi.isEditor);
25
+
26
+ const checkoutPageGenerateSuccess = checkoutPageInfo
27
+ ? await PageGenerator.generatePageWithInfo(checkoutPageInfo)
28
+ : false;
29
+ const editorPageGenerateSuccess = editorPageInfo
30
+ ? await PageGenerator.generatePageWithInfo(editorPageInfo)
31
+ : false;
32
+
33
+ return (
34
+ pagesGenerateSuccess &&
35
+ checkoutPageGenerateSuccess &&
36
+ editorPageGenerateSuccess
37
+ );
38
+ }
39
+
40
+ static async generatePageWithInfo(pageInfo: PageInfo) {
41
+ try {
42
+ let fileStr = "";
43
+
44
+ if (pageInfo.isCheckout) {
45
+ fileStr = CHECKOUT_PAGE_CONTENT;
46
+ } else if (pageInfo.isEditor) {
47
+ fileStr = EDITOR_PAGE_CONTENT;
48
+ } else {
49
+ const providerName = pageInfo.pageComponentName + "Next";
50
+ const pageComponentImportStr = `import { ${pageInfo.pageComponentName} } from "@ikas/storefront";\r\n`;
51
+ const providerImportStr = `import { ${pageInfo.pageComponentName} as ${providerName} } from "@ikas/storefront-next";\r\n`;
52
+ const componentsImportStr = `import Components from "src/components/__generated__/pages/${pageInfo.path.replace(
53
+ ".tsx",
54
+ ""
55
+ )}";\r\n`;
56
+
57
+ const pageComponentStr = `
58
+ const PageComponent = ${pageInfo.pageComponentName}.default;
59
+
60
+ const Page = (props: any) => {
61
+ return <PageComponent components={Components} {...props} />;
62
+ };
63
+
64
+ export default Page;\r\n`;
65
+
66
+ const getStaticPathsStr = pageInfo.isDynamicSSG
67
+ ? `export const getStaticPaths = ${providerName}.getStaticPaths;\r\n`
68
+ : "";
69
+
70
+ const dataFetchingStr = pageInfo.isSSR
71
+ ? `export const getServerSideProps = ${providerName}.getServerSideProps;\r\n`
72
+ : `export const getStaticProps = ${providerName}.getStaticProps;\r\n`;
73
+
74
+ fileStr =
75
+ pageComponentImportStr +
76
+ providerImportStr +
77
+ componentsImportStr +
78
+ pageComponentStr +
79
+ getStaticPathsStr +
80
+ dataFetchingStr;
81
+ }
82
+
83
+ return await createFile(
84
+ path.join(process.cwd(), "src", "pages"),
85
+ pageInfo.path,
86
+ fileStr
87
+ );
88
+ } catch (err) {
89
+ console.error(err);
90
+ return false;
91
+ }
92
+ }
93
+
94
+ static async generatePageWithType(pageType: IkasThemeJsonPageType) {
95
+ const pageInfo = PAGE_INFO.find((pi) => pi.pageTypes.includes(pageType));
96
+ if (pageInfo) {
97
+ return await PageGenerator.generatePageWithInfo(pageInfo);
98
+ }
99
+
100
+ return false;
101
+ }
102
+ }