@ikas/storefront-cmd 4.0.0-alpha.8 → 4.0.0-alpha.81

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/_virtual/_cloneBuffer.js +1 -0
  2. package/build/_virtual/_commonjsHelpers.js +1 -0
  3. package/build/_virtual/_nodeUtil.js +1 -0
  4. package/build/_virtual/isBuffer.js +1 -0
  5. package/build/ext/lodash/_DataView.js +1 -0
  6. package/build/ext/lodash/_Hash.js +1 -0
  7. package/build/ext/lodash/_ListCache.js +1 -0
  8. package/build/ext/lodash/_Map.js +1 -0
  9. package/build/ext/lodash/_MapCache.js +1 -0
  10. package/build/ext/lodash/_Promise.js +1 -0
  11. package/build/ext/lodash/_Set.js +1 -0
  12. package/build/ext/lodash/_SetCache.js +1 -0
  13. package/build/ext/lodash/_Stack.js +1 -0
  14. package/build/ext/lodash/_Symbol.js +1 -0
  15. package/build/ext/lodash/_Uint8Array.js +1 -0
  16. package/build/ext/lodash/_WeakMap.js +1 -0
  17. package/build/ext/lodash/_arrayEach.js +1 -0
  18. package/build/ext/lodash/_arrayFilter.js +1 -0
  19. package/build/ext/lodash/_arrayIncludes.js +1 -0
  20. package/build/ext/lodash/_arrayIncludesWith.js +1 -0
  21. package/build/ext/lodash/_arrayLikeKeys.js +1 -0
  22. package/build/ext/lodash/_arrayPush.js +1 -0
  23. package/build/ext/lodash/_assignValue.js +1 -0
  24. package/build/ext/lodash/_assocIndexOf.js +1 -0
  25. package/build/ext/lodash/_baseAssign.js +1 -0
  26. package/build/ext/lodash/_baseAssignIn.js +1 -0
  27. package/build/ext/lodash/_baseAssignValue.js +1 -0
  28. package/build/ext/lodash/_baseClone.js +1 -0
  29. package/build/ext/lodash/_baseCreate.js +1 -0
  30. package/build/ext/lodash/_baseFindIndex.js +1 -0
  31. package/build/ext/lodash/_baseGetAllKeys.js +1 -0
  32. package/build/ext/lodash/_baseGetTag.js +1 -0
  33. package/build/ext/lodash/_baseIndexOf.js +1 -0
  34. package/build/ext/lodash/_baseIsArguments.js +1 -0
  35. package/build/ext/lodash/_baseIsMap.js +1 -0
  36. package/build/ext/lodash/_baseIsNaN.js +1 -0
  37. package/build/ext/lodash/_baseIsNative.js +1 -0
  38. package/build/ext/lodash/_baseIsSet.js +1 -0
  39. package/build/ext/lodash/_baseIsTypedArray.js +1 -0
  40. package/build/ext/lodash/_baseKeys.js +1 -0
  41. package/build/ext/lodash/_baseKeysIn.js +1 -0
  42. package/build/ext/lodash/_baseTimes.js +1 -0
  43. package/build/ext/lodash/_baseUnary.js +1 -0
  44. package/build/ext/lodash/_baseUniq.js +1 -0
  45. package/build/ext/lodash/_cacheHas.js +1 -0
  46. package/build/ext/lodash/_cloneArrayBuffer.js +1 -0
  47. package/build/ext/lodash/_cloneBuffer.js +1 -0
  48. package/build/ext/lodash/_cloneDataView.js +1 -0
  49. package/build/ext/lodash/_cloneRegExp.js +1 -0
  50. package/build/ext/lodash/_cloneSymbol.js +1 -0
  51. package/build/ext/lodash/_cloneTypedArray.js +1 -0
  52. package/build/ext/lodash/_copyArray.js +1 -0
  53. package/build/ext/lodash/_copyObject.js +1 -0
  54. package/build/ext/lodash/_copySymbols.js +1 -0
  55. package/build/ext/lodash/_copySymbolsIn.js +1 -0
  56. package/build/ext/lodash/_coreJsData.js +1 -0
  57. package/build/ext/lodash/_createSet.js +1 -0
  58. package/build/ext/lodash/_defineProperty.js +1 -0
  59. package/build/ext/lodash/_freeGlobal.js +1 -0
  60. package/build/ext/lodash/_getAllKeys.js +1 -0
  61. package/build/ext/lodash/_getAllKeysIn.js +1 -0
  62. package/build/ext/lodash/_getMapData.js +1 -0
  63. package/build/ext/lodash/_getNative.js +1 -0
  64. package/build/ext/lodash/_getPrototype.js +1 -0
  65. package/build/ext/lodash/_getRawTag.js +1 -0
  66. package/build/ext/lodash/_getSymbols.js +1 -0
  67. package/build/ext/lodash/_getSymbolsIn.js +1 -0
  68. package/build/ext/lodash/_getTag.js +1 -0
  69. package/build/ext/lodash/_getValue.js +1 -0
  70. package/build/ext/lodash/_hashClear.js +1 -0
  71. package/build/ext/lodash/_hashDelete.js +1 -0
  72. package/build/ext/lodash/_hashGet.js +1 -0
  73. package/build/ext/lodash/_hashHas.js +1 -0
  74. package/build/ext/lodash/_hashSet.js +1 -0
  75. package/build/ext/lodash/_initCloneArray.js +1 -0
  76. package/build/ext/lodash/_initCloneByTag.js +1 -0
  77. package/build/ext/lodash/_initCloneObject.js +1 -0
  78. package/build/ext/lodash/_isIndex.js +1 -0
  79. package/build/ext/lodash/_isKeyable.js +1 -0
  80. package/build/ext/lodash/_isMasked.js +1 -0
  81. package/build/ext/lodash/_isPrototype.js +1 -0
  82. package/build/ext/lodash/_listCacheClear.js +1 -0
  83. package/build/ext/lodash/_listCacheDelete.js +1 -0
  84. package/build/ext/lodash/_listCacheGet.js +1 -0
  85. package/build/ext/lodash/_listCacheHas.js +1 -0
  86. package/build/ext/lodash/_listCacheSet.js +1 -0
  87. package/build/ext/lodash/_mapCacheClear.js +1 -0
  88. package/build/ext/lodash/_mapCacheDelete.js +1 -0
  89. package/build/ext/lodash/_mapCacheGet.js +1 -0
  90. package/build/ext/lodash/_mapCacheHas.js +1 -0
  91. package/build/ext/lodash/_mapCacheSet.js +1 -0
  92. package/build/ext/lodash/_nativeCreate.js +1 -0
  93. package/build/ext/lodash/_nativeKeys.js +1 -0
  94. package/build/ext/lodash/_nativeKeysIn.js +1 -0
  95. package/build/ext/lodash/_nodeUtil.js +1 -0
  96. package/build/ext/lodash/_objectToString.js +1 -0
  97. package/build/ext/lodash/_overArg.js +1 -0
  98. package/build/ext/lodash/_root.js +1 -0
  99. package/build/ext/lodash/_setCacheAdd.js +1 -0
  100. package/build/ext/lodash/_setCacheHas.js +1 -0
  101. package/build/ext/lodash/_setToArray.js +1 -0
  102. package/build/ext/lodash/_stackClear.js +1 -0
  103. package/build/ext/lodash/_stackDelete.js +1 -0
  104. package/build/ext/lodash/_stackGet.js +1 -0
  105. package/build/ext/lodash/_stackHas.js +1 -0
  106. package/build/ext/lodash/_stackSet.js +1 -0
  107. package/build/ext/lodash/_strictIndexOf.js +1 -0
  108. package/build/ext/lodash/_toSource.js +1 -0
  109. package/build/ext/lodash/cloneDeep.js +1 -0
  110. package/build/ext/lodash/eq.js +1 -0
  111. package/build/ext/lodash/isArguments.js +1 -0
  112. package/build/ext/lodash/isArray.js +1 -0
  113. package/build/ext/lodash/isArrayLike.js +1 -0
  114. package/build/ext/lodash/isBuffer.js +1 -0
  115. package/build/ext/lodash/isFunction.js +1 -0
  116. package/build/ext/lodash/isLength.js +1 -0
  117. package/build/ext/lodash/isMap.js +1 -0
  118. package/build/ext/lodash/isObject.js +1 -0
  119. package/build/ext/lodash/isObjectLike.js +1 -0
  120. package/build/ext/lodash/isSet.js +1 -0
  121. package/build/ext/lodash/isTypedArray.js +1 -0
  122. package/build/ext/lodash/keys.js +1 -0
  123. package/build/ext/lodash/keysIn.js +1 -0
  124. package/build/ext/lodash/noop.js +1 -0
  125. package/build/ext/lodash/stubArray.js +1 -0
  126. package/build/ext/lodash/stubFalse.js +1 -0
  127. package/build/ext/lodash/uniq.js +1 -0
  128. package/build/ext/tslib/tslib.es6.js +1 -0
  129. package/build/ikas.cjs +1 -2
  130. package/{src/index.ts → build/index.d.ts} +3 -4
  131. package/build/index.js +1 -0
  132. package/build/scripts/generators/api/index.d.ts +5 -0
  133. package/build/scripts/generators/api/index.js +1 -0
  134. package/build/scripts/generators/api/info.d.ts +12 -0
  135. package/build/scripts/generators/api/info.js +1 -0
  136. package/build/scripts/generators/components/index.d.ts +11 -0
  137. package/build/scripts/generators/components/index.js +1 -0
  138. package/build/scripts/generators/config/content.d.ts +61 -0
  139. package/build/scripts/generators/config/content.js +1 -0
  140. package/build/scripts/generators/config/index.d.ts +9 -0
  141. package/build/scripts/generators/config/index.js +1 -0
  142. package/{src/scripts/generators/index.ts → build/scripts/generators/index.d.ts} +6 -6
  143. package/build/scripts/generators/pages/index.d.ts +7 -0
  144. package/build/scripts/generators/pages/index.js +1 -0
  145. package/build/scripts/generators/pages/info.d.ts +14 -0
  146. package/build/scripts/generators/pages/info.js +1 -0
  147. package/build/scripts/generators/theme/index.d.ts +6 -0
  148. package/build/scripts/generators/theme/index.js +1 -0
  149. package/build/scripts/generators/types/index.d.ts +19 -0
  150. package/build/scripts/generators/types/index.js +1 -0
  151. package/build/scripts/ikas.d.ts +1 -0
  152. package/build/scripts/theme-build/index.d.ts +3 -0
  153. package/build/scripts/theme-build/index.js +1 -0
  154. package/build/utils/fs.d.ts +28 -0
  155. package/build/utils/fs.js +1 -0
  156. package/build/utils/helper.d.ts +2 -0
  157. package/build/utils/helper.js +1 -0
  158. package/package.json +7 -6
  159. package/src/scripts/generators/api/index.ts +0 -27
  160. package/src/scripts/generators/api/info.ts +0 -47
  161. package/src/scripts/generators/components/index.ts +0 -244
  162. package/src/scripts/generators/config/content.ts +0 -168
  163. package/src/scripts/generators/config/index.ts +0 -106
  164. package/src/scripts/generators/pages/index.ts +0 -102
  165. package/src/scripts/generators/pages/info.ts +0 -161
  166. package/src/scripts/generators/theme/index.ts +0 -63
  167. package/src/scripts/generators/types/index.ts +0 -520
  168. package/src/scripts/ikas.ts +0 -45
  169. package/src/scripts/theme-build/index.ts +0 -99
  170. package/src/utils/fs.ts +0 -93
  171. package/src/utils/helper.ts +0 -20
@@ -0,0 +1 @@
1
+ import{__awaiter as n,__generator as e}from'./../../ext/tslib/tslib.es6.js';import t from'./../../ext/lodash/cloneDeep.js';import"../generators/api/index.js";import{ComponentImportsGenerator as o}from"../generators/components/index.js";import{ConfigGenerator as i}from"../generators/config/index.js";import{PageGenerator as s}from"../generators/pages/index.js";import"../generators/theme/index.js";import{CustomDataTypesGenerator as r}from"../generators/types/index.js";function c(n,e){return!(!n.pages.some((function(n){return!e.pages.find((function(e){return e.id===n.id}))}))&&!e.pages.some((function(e){return!n.pages.find((function(n){return n.id===e.id}))})))||n.pages.some((function(n){var t,o,i=e.pages.find((function(e){return e.id===n.id})),s=n.components;(null===(t=n.specifications)||void 0===t?void 0:t.length)&&n.specifications.forEach((function(n){s.push.apply(s,n.components)}));var r=(null==i?void 0:i.components)||[];(null===(o=null==i?void 0:i.specifications)||void 0===o?void 0:o.length)&&i.specifications.forEach((function(n){r.push.apply(r,n.components)}));var c=s.filter((function(n){return!r.find((function(e){return n.componentId===e.componentId}))})),a=r.filter((function(n){return!s.find((function(e){return n.componentId===e.componentId}))}));return!!c.length||!!a.length}))}function a(c,a){return n(this,void 0,void 0,(function(){var n,p,u,f,m;return e(this,(function(e){switch(e.label){case 0:return n=t(c),(p={components:[],pages:[],customData:[],name:"",settings:{}}).components=n[0].components,p.customData=n[0].customData,n.forEach((function(n){n.pages.forEach((function(n){var e,t,o=p.pages.find((function(e){return e.type===n.type})),i=o||n;(e=i.components).push.apply(e,n.components),i.specifications||(i.specifications=[]),(t=i.specifications).push.apply(t,n.specifications||[]),o||p.pages.push(i)}))})),[4,o.generate(p,a)];case 1:return(m=e.sent())?[4,s.generate(a)]:[3,3];case 2:m=e.sent(),e.label=3;case 3:return(f=m)?[4,r.generate(p,a)]:[3,5];case 4:f=e.sent(),e.label=5;case 5:return(u=f)?[4,i.generate("prod",a)]:[3,7];case 6:u=e.sent(),e.label=7;case 7:return[2,u]}}))}))}export{a as generate,c as shouldDeploy};
@@ -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
+ export declare function sortObject(obj: Record<string, any>): Record<string, any>;
2
+ export declare function findAllByKey(obj: Record<string, any>, keyToFind: string): any;
@@ -0,0 +1 @@
1
+ function t(t){return Object.keys(t).sort().reduce((function(e,n){return e[n]=t[n],e}),{})}function e(t,n){return Object.entries(t||{}).reduce((function(t,r){var c=r[0],o=r[1];return c===n?t.concat(o):"object"==typeof o?t.concat(e(o,n)):t}),[])}export{e as findAllByKey,t as sortObject};
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@ikas/storefront-cmd",
3
- "version": "4.0.0-alpha.8",
3
+ "version": "4.0.0-alpha.81",
4
4
  "description": "Command line tool for ikas storefront themes.",
5
5
  "author": "Umut Ozan Yıldırım",
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
  "sideEffects": false,
10
10
  "files": [
11
- "./src"
11
+ "./build"
12
12
  ],
13
13
  "bin": {
14
14
  "ikas": "./build/ikas.cjs"
@@ -24,13 +24,14 @@
24
24
  "lodash": "^4.17.21"
25
25
  },
26
26
  "devDependencies": {
27
- "@ikas/storefront-models": "^4.0.0-alpha.8",
27
+ "@ikas/storefront-models": "^4.0.0-alpha.81",
28
28
  "@rollup/plugin-commonjs": "^22.0.0",
29
29
  "@rollup/plugin-node-resolve": "^13.3.0",
30
30
  "rollup-plugin-typescript2": "^0.32.1",
31
31
  "rollup-plugin-peer-deps-external": "^2.2.4",
32
32
  "rollup-plugin-terser": "^7.0.2",
33
33
  "rollup-plugin-executable": "^1.6.3",
34
+ "rollup-plugin-rename-node-modules": "^1.2.0",
34
35
  "@types/command-line-args": "^5.2.0",
35
36
  "@types/lodash": "^4.14.182",
36
37
  "@types/node": "^14.14.6",
@@ -40,6 +41,6 @@
40
41
  "typescript-transform-paths": "^2.2.2"
41
42
  },
42
43
  "peerDependencies": {
43
- "@ikas/storefront-models": "^4.0.0-alpha.8"
44
+ "@ikas/storefront-models": "^4.0.0-alpha.81"
44
45
  }
45
46
  }
@@ -1,27 +0,0 @@
1
- import path from "path";
2
- import { createFile, deleteDirContent } from "../../../utils/fs";
3
-
4
- import { APIInfo, API_INFO } from "./info";
5
-
6
- export class APIGenerator {
7
- static async generate() {
8
- const apiDir = path.join(process.cwd(), "src", "pages", "api");
9
- await deleteDirContent(apiDir);
10
-
11
- let isSuccess = true;
12
-
13
- for (const info of API_INFO) {
14
- isSuccess = isSuccess && (await APIGenerator.generateAPI(info));
15
- }
16
-
17
- return isSuccess;
18
- }
19
-
20
- static generateAPI(apiInfo: APIInfo) {
21
- return createFile(
22
- path.join(process.cwd(), "src", "pages", "api"),
23
- apiInfo.fileName,
24
- apiInfo.content
25
- );
26
- }
27
- }
@@ -1,47 +0,0 @@
1
- export const GET_COMPONENT_DIRS_API_CONTENT = `import { IkasLocalThemeAPI } from "@ikas/storefront-next";
2
-
3
- export default IkasLocalThemeAPI.GetComponentDirs.getComponentDirs;
4
- export const config = IkasLocalThemeAPI.GetComponentDirs.config;
5
- `;
6
-
7
- export const GET_THEME_API_CONTENT = `import { IkasLocalThemeAPI } from "@ikas/storefront-next";
8
-
9
- export default IkasLocalThemeAPI.GetTheme.getTheme;
10
- export const config = IkasLocalThemeAPI.GetTheme.config;
11
- `;
12
-
13
- export const UPDATE_THEME_API_CONTENT = `import { IkasLocalThemeAPI } from "@ikas/storefront-next";
14
-
15
- export default IkasLocalThemeAPI.UpdateTheme.updateTheme;
16
- export const config = IkasLocalThemeAPI.UpdateTheme.config;
17
- `;
18
-
19
- export const UPLOAD_THEME_API_CONTENT = `import { IkasLocalThemeAPI } from "@ikas/storefront-next";
20
-
21
- export default IkasLocalThemeAPI.UploadTheme.uploadTheme;
22
- export const config = IkasLocalThemeAPI.UploadTheme.config;
23
- `;
24
-
25
- export const API_INFO = [
26
- {
27
- content: GET_COMPONENT_DIRS_API_CONTENT,
28
- fileName: "getComponentDirs.ts",
29
- },
30
- {
31
- content: GET_THEME_API_CONTENT,
32
- fileName: "getTheme.ts",
33
- },
34
- {
35
- content: UPDATE_THEME_API_CONTENT,
36
- fileName: "updateTheme.ts",
37
- },
38
- {
39
- content: UPLOAD_THEME_API_CONTENT,
40
- fileName: "uploadTheme.ts",
41
- },
42
- ];
43
-
44
- export type APIInfo = {
45
- content: string;
46
- fileName: string;
47
- };
@@ -1,244 +0,0 @@
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
- }
@@ -1,168 +0,0 @@
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
- }`;
@@ -1,106 +0,0 @@
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
- }