@ikas/storefront-cmd 4.0.0-alpha.49 → 4.0.0-alpha.50
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.
- package/package.json +6 -6
- package/{build/index.d.ts → src/index.ts} +4 -3
- package/src/scripts/generators/api/index.ts +27 -0
- package/src/scripts/generators/api/info.ts +47 -0
- package/src/scripts/generators/components/index.ts +270 -0
- package/src/scripts/generators/config/content.ts +170 -0
- package/src/scripts/generators/config/index.ts +113 -0
- package/{build/scripts/generators/index.d.ts → src/scripts/generators/index.ts} +6 -6
- package/src/scripts/generators/pages/index.ts +102 -0
- package/src/scripts/generators/pages/info.ts +161 -0
- package/src/scripts/generators/theme/index.ts +63 -0
- package/src/scripts/generators/types/index.ts +526 -0
- package/src/scripts/ikas.ts +45 -0
- package/src/scripts/theme-build/index.ts +99 -0
- package/src/utils/fs.ts +93 -0
- package/src/utils/helper.ts +20 -0
- package/build/_virtual/_cloneBuffer.js +0 -1
- package/build/_virtual/_commonjsHelpers.js +0 -1
- package/build/_virtual/_nodeUtil.js +0 -1
- package/build/_virtual/isBuffer.js +0 -1
- package/build/index.js +0 -1
- package/build/scripts/generators/api/index.d.ts +0 -5
- package/build/scripts/generators/api/index.js +0 -1
- package/build/scripts/generators/api/info.d.ts +0 -12
- package/build/scripts/generators/api/info.js +0 -1
- package/build/scripts/generators/components/index.d.ts +0 -11
- package/build/scripts/generators/components/index.js +0 -1
- package/build/scripts/generators/config/content.d.ts +0 -58
- package/build/scripts/generators/config/content.js +0 -1
- package/build/scripts/generators/config/index.d.ts +0 -9
- package/build/scripts/generators/config/index.js +0 -1
- package/build/scripts/generators/pages/index.d.ts +0 -7
- package/build/scripts/generators/pages/index.js +0 -1
- package/build/scripts/generators/pages/info.d.ts +0 -14
- package/build/scripts/generators/pages/info.js +0 -1
- package/build/scripts/generators/theme/index.d.ts +0 -6
- package/build/scripts/generators/theme/index.js +0 -1
- package/build/scripts/generators/types/index.d.ts +0 -19
- package/build/scripts/generators/types/index.js +0 -1
- package/build/scripts/ikas.d.ts +0 -1
- package/build/scripts/theme-build/index.d.ts +0 -3
- package/build/scripts/theme-build/index.js +0 -1
- package/build/utils/fs.d.ts +0 -28
- package/build/utils/fs.js +0 -1
- package/build/utils/helper.d.ts +0 -2
- package/build/utils/helper.js +0 -1
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikas/storefront-cmd",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.50",
|
|
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": "./
|
|
8
|
-
"module": "./
|
|
7
|
+
"main": "./src/index.ts",
|
|
8
|
+
"module": "./src/index.ts",
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"files": [
|
|
11
|
-
"./
|
|
11
|
+
"./src"
|
|
12
12
|
],
|
|
13
13
|
"bin": {
|
|
14
14
|
"ikas": "./build/ikas.cjs"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"lodash": "^4.17.21"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@ikas/storefront-models": "^4.0.0-alpha.
|
|
27
|
+
"@ikas/storefront-models": "^4.0.0-alpha.50",
|
|
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",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"typescript-transform-paths": "^2.2.2"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@ikas/storefront-models": "^4.0.0-alpha.
|
|
43
|
+
"@ikas/storefront-models": "^4.0.0-alpha.50"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from "./scripts/generators";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export * from "./scripts/generators";
|
|
2
|
+
|
|
3
|
+
import * as ThemeBuild from "./scripts/theme-build";
|
|
4
|
+
export { ThemeBuild };
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,270 @@
|
|
|
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, workingDir?: string) {
|
|
13
|
+
await deleteDirContent(
|
|
14
|
+
path.join(
|
|
15
|
+
workingDir || process.cwd(),
|
|
16
|
+
"src",
|
|
17
|
+
"components",
|
|
18
|
+
"__generated__"
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
(await ComponentImportsGenerator.generateAllPageComponentImportsFiles(
|
|
24
|
+
themeJson,
|
|
25
|
+
workingDir
|
|
26
|
+
)) &&
|
|
27
|
+
(await ComponentImportsGenerator.generateAllComponentImportsFileForEditor(
|
|
28
|
+
themeJson,
|
|
29
|
+
workingDir
|
|
30
|
+
))
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static async generateAllPageComponentImportsFiles(
|
|
35
|
+
themeJson: IkasThemeJson,
|
|
36
|
+
workingDir?: string
|
|
37
|
+
) {
|
|
38
|
+
let isSuccess = true;
|
|
39
|
+
|
|
40
|
+
for (const pageInfo of PAGE_INFO) {
|
|
41
|
+
// const themeHasPage = themeJson.pages.some((page) =>
|
|
42
|
+
// pageInfo.pageTypes.includes(page.type)
|
|
43
|
+
// );
|
|
44
|
+
// if (themeHasPage) {
|
|
45
|
+
// }
|
|
46
|
+
isSuccess =
|
|
47
|
+
isSuccess &&
|
|
48
|
+
(await ComponentImportsGenerator.generatePageComponentImportsFileWithInfo(
|
|
49
|
+
pageInfo,
|
|
50
|
+
themeJson,
|
|
51
|
+
workingDir
|
|
52
|
+
));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return isSuccess;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static async generatePageComponentImportsFileWithInfo(
|
|
59
|
+
pageInfo: PageInfo,
|
|
60
|
+
themeJson: IkasThemeJson,
|
|
61
|
+
workingDir?: string
|
|
62
|
+
) {
|
|
63
|
+
if (pageInfo.isCheckout || pageInfo.isEditor) return true;
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const components = themeJson.components;
|
|
67
|
+
const componentIds: string[] = [];
|
|
68
|
+
|
|
69
|
+
pageInfo.pageTypes.forEach((pageType) => {
|
|
70
|
+
const pages = themeJson.pages.filter((page) => page.type === pageType);
|
|
71
|
+
|
|
72
|
+
if (pages.length) {
|
|
73
|
+
pages.forEach((page) => {
|
|
74
|
+
const allPageComponents = page.components;
|
|
75
|
+
if (page.specifications?.length) {
|
|
76
|
+
page.specifications.forEach((specification) => {
|
|
77
|
+
allPageComponents.push(...specification.components);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
componentIds.push(...allPageComponents.map((c) => c.componentId));
|
|
82
|
+
|
|
83
|
+
allPageComponents.forEach((pageComponent) => {
|
|
84
|
+
const component = components.find(
|
|
85
|
+
(c) => c.id === pageComponent.componentId
|
|
86
|
+
);
|
|
87
|
+
if (!component) return;
|
|
88
|
+
|
|
89
|
+
const nestedComponentIds = findAllByKey(
|
|
90
|
+
pageComponent.propValues,
|
|
91
|
+
"componentId"
|
|
92
|
+
) as Array<any>;
|
|
93
|
+
|
|
94
|
+
componentIds.push(...nestedComponentIds);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const componentsInPage = components.filter(
|
|
101
|
+
(c) => componentIds.includes(c.id) && c.id !== CHECKOUT_COMPONENT_ID
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return await ComponentImportsGenerator.generateComponentImportsFile(
|
|
105
|
+
componentsInPage,
|
|
106
|
+
pageInfo,
|
|
107
|
+
workingDir
|
|
108
|
+
);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
console.error(err);
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static generatePageComponentImportsFileWithType(
|
|
116
|
+
pageType: IkasThemeJsonPageType,
|
|
117
|
+
themeJson: IkasThemeJson,
|
|
118
|
+
workingDir?: string
|
|
119
|
+
) {
|
|
120
|
+
if (pageType === IkasThemeJsonPageType.CHECKOUT) return;
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
const pageInfo = PAGE_INFO.find((pi) => pi.pageTypes.includes(pageType));
|
|
124
|
+
if (pageInfo) {
|
|
125
|
+
return ComponentImportsGenerator.generatePageComponentImportsFileWithInfo(
|
|
126
|
+
pageInfo,
|
|
127
|
+
themeJson,
|
|
128
|
+
workingDir
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
console.error(err);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static generateComponentImportsFile(
|
|
139
|
+
components: IkasThemeJsonComponent[],
|
|
140
|
+
pageInfo: PageInfo,
|
|
141
|
+
workingDir?: string
|
|
142
|
+
) {
|
|
143
|
+
try {
|
|
144
|
+
let fileStr = "";
|
|
145
|
+
|
|
146
|
+
components
|
|
147
|
+
.filter((c: any) => c.id !== "checkout")
|
|
148
|
+
.forEach((component: any, index: number) => {
|
|
149
|
+
fileStr += `import Component${index} from "src/components/${component.dir}";\r\n`;
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
fileStr += `
|
|
153
|
+
const Components = {
|
|
154
|
+
${components.map(
|
|
155
|
+
(component: any, index: number) => `"${component.id}": Component${index}`
|
|
156
|
+
)}
|
|
157
|
+
};
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
fileStr += "\r\n";
|
|
161
|
+
fileStr += "export default Components;";
|
|
162
|
+
|
|
163
|
+
return createFile(
|
|
164
|
+
path.join(
|
|
165
|
+
workingDir || process.cwd(),
|
|
166
|
+
"src",
|
|
167
|
+
"components",
|
|
168
|
+
"__generated__",
|
|
169
|
+
"pages"
|
|
170
|
+
),
|
|
171
|
+
pageInfo.path.replace("tsx", "ts"),
|
|
172
|
+
fileStr
|
|
173
|
+
);
|
|
174
|
+
} catch (err) {
|
|
175
|
+
console.error(err);
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
static async generateAllComponentImportsFileForEditor(
|
|
181
|
+
themeJson: IkasThemeJson,
|
|
182
|
+
workingDir?: string
|
|
183
|
+
) {
|
|
184
|
+
try {
|
|
185
|
+
let fileStr = `import dynamic from "next/dynamic";\r\n`;
|
|
186
|
+
fileStr += `import { IkasEditorComponentLoader } from "@ikas/storefront";\r\n`;
|
|
187
|
+
fileStr += "\r\n";
|
|
188
|
+
fileStr += "\r\n";
|
|
189
|
+
|
|
190
|
+
const components = themeJson.components.filter(
|
|
191
|
+
(tc: any) => tc.id !== "checkout"
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// Component imports
|
|
195
|
+
components
|
|
196
|
+
.filter((c: any) => c.id !== "checkout")
|
|
197
|
+
.forEach((component: any, index: number) => {
|
|
198
|
+
fileStr += `const Component${index} = dynamic(() => import("../${component.dir}"), { loading: () => <IkasEditorComponentLoader /> });\r\n`;
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
fileStr += "\r\n";
|
|
202
|
+
fileStr += `
|
|
203
|
+
const Components = {
|
|
204
|
+
${components.map(
|
|
205
|
+
(component: any, index: number) => `"${component.id}": Component${index}`
|
|
206
|
+
)}
|
|
207
|
+
};
|
|
208
|
+
`;
|
|
209
|
+
|
|
210
|
+
fileStr += "\r\n";
|
|
211
|
+
fileStr += "export default Components;";
|
|
212
|
+
|
|
213
|
+
const generatedFolderPath = path.join(
|
|
214
|
+
workingDir || process.cwd(),
|
|
215
|
+
"src",
|
|
216
|
+
"components",
|
|
217
|
+
"__generated__"
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
return await createFile(generatedFolderPath, "editor.tsx", fileStr);
|
|
221
|
+
} catch (err) {
|
|
222
|
+
console.error(err);
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
static async generateAllComponentImportsFile(
|
|
228
|
+
themeJson: IkasThemeJson,
|
|
229
|
+
workingDir?: string
|
|
230
|
+
) {
|
|
231
|
+
try {
|
|
232
|
+
let fileStr = ``;
|
|
233
|
+
|
|
234
|
+
const components = themeJson.components.filter(
|
|
235
|
+
(tc: any) => tc.id !== "checkout"
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
// Component imports
|
|
239
|
+
components
|
|
240
|
+
.filter((c: any) => c.id !== "checkout")
|
|
241
|
+
.forEach((component: any, index: number) => {
|
|
242
|
+
fileStr += `import Component${index} from "../${component.dir}";\r\n`;
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
fileStr += "\r\n";
|
|
246
|
+
fileStr += `
|
|
247
|
+
const Components = {
|
|
248
|
+
${components.map(
|
|
249
|
+
(component: any, index: number) => `"${component.id}": Component${index}`
|
|
250
|
+
)}
|
|
251
|
+
};
|
|
252
|
+
`;
|
|
253
|
+
|
|
254
|
+
fileStr += "\r\n";
|
|
255
|
+
fileStr += "export default Components;";
|
|
256
|
+
|
|
257
|
+
const generatedFolderPath = path.join(
|
|
258
|
+
workingDir || process.cwd(),
|
|
259
|
+
"src",
|
|
260
|
+
"components",
|
|
261
|
+
"__generated__"
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
return await createFile(generatedFolderPath, "index.tsx", fileStr);
|
|
265
|
+
} catch (err) {
|
|
266
|
+
console.error(err);
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
export const DEPENDENCIES = {
|
|
2
|
+
next: "12.2.0",
|
|
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.48",
|
|
14
|
+
"@ikas/storefront-api": "^4.0.0-alpha.48",
|
|
15
|
+
"@ikas/storefront-assets": "^4.0.0-alpha.48",
|
|
16
|
+
"@ikas/storefront-cmd": "^4.0.0-alpha.48",
|
|
17
|
+
"@ikas/storefront-config": "^4.0.0-alpha.48",
|
|
18
|
+
"@ikas/storefront-model-functions": "^4.0.0-alpha.48",
|
|
19
|
+
"@ikas/storefront-models": "^4.0.0-alpha.48",
|
|
20
|
+
"@ikas/storefront-next": "^4.0.0-alpha.48",
|
|
21
|
+
"@ikas/storefront-providers": "^4.0.0-alpha.48",
|
|
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
|
+
"@types/cors": "^2.8.9",
|
|
29
|
+
"@types/archiver": "^5.1.0",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^2.10.0",
|
|
31
|
+
"@typescript-eslint/parser": "^2.10.0",
|
|
32
|
+
eslint: "^6.6.0",
|
|
33
|
+
"eslint-config-react-app": "^5.2.1",
|
|
34
|
+
"eslint-loader": "3.0.3",
|
|
35
|
+
"eslint-plugin-flowtype": "4.6.0",
|
|
36
|
+
"eslint-plugin-import": "2.20.1",
|
|
37
|
+
"eslint-plugin-jsx-a11y": "6.2.3",
|
|
38
|
+
"eslint-plugin-react": "7.19.0",
|
|
39
|
+
"eslint-plugin-react-hooks": "^1.6.1",
|
|
40
|
+
sass: "^1.43.4",
|
|
41
|
+
typescript: "^4.5.2",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const RESOLUTIONS = {
|
|
45
|
+
"@types/react": "17.0.2",
|
|
46
|
+
"@types/react-dom": "17.0.2",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const SCRIPTS = {
|
|
50
|
+
upgradeDependencies:
|
|
51
|
+
"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",
|
|
52
|
+
dev: "next dev -p 3333",
|
|
53
|
+
build: "next build",
|
|
54
|
+
start: "next start",
|
|
55
|
+
generate: "ikas --generate",
|
|
56
|
+
"prettier:all": "npx prettier@^2.1 './**/src/**/*.(ts|tsx|css|scss)' --write",
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const TS_CONFIG = `{
|
|
60
|
+
"compilerOptions": {
|
|
61
|
+
"target": "esnext",
|
|
62
|
+
"lib": [
|
|
63
|
+
"dom",
|
|
64
|
+
"dom.iterable",
|
|
65
|
+
"esnext"
|
|
66
|
+
],
|
|
67
|
+
"allowJs": true,
|
|
68
|
+
"skipLibCheck": true,
|
|
69
|
+
"strict": true,
|
|
70
|
+
"forceConsistentCasingInFileNames": true,
|
|
71
|
+
"experimentalDecorators": true,
|
|
72
|
+
"noEmit": true,
|
|
73
|
+
"esModuleInterop": true,
|
|
74
|
+
"module": "esnext",
|
|
75
|
+
"moduleResolution": "node",
|
|
76
|
+
"resolveJsonModule": true,
|
|
77
|
+
"isolatedModules": true,
|
|
78
|
+
"jsx": "preserve",
|
|
79
|
+
"baseUrl": ".",
|
|
80
|
+
"useUnknownInCatchVariables": false,
|
|
81
|
+
"incremental": true
|
|
82
|
+
},
|
|
83
|
+
"typeRoots": [
|
|
84
|
+
"./node_modules/@types"
|
|
85
|
+
],
|
|
86
|
+
"include": [
|
|
87
|
+
"next-env.d.ts",
|
|
88
|
+
"**/*.ts",
|
|
89
|
+
"**/*.tsx",
|
|
90
|
+
"**/typings/global.d.ts",
|
|
91
|
+
],
|
|
92
|
+
"exclude": [
|
|
93
|
+
"node_modules",
|
|
94
|
+
"./src/pages/api",
|
|
95
|
+
]
|
|
96
|
+
}`;
|
|
97
|
+
|
|
98
|
+
export const NEXT_CONFIG = `const withTM = require("next-transpile-modules")([
|
|
99
|
+
"@ikas/storefront",
|
|
100
|
+
"@ikas/storefront-api",
|
|
101
|
+
"@ikas/storefront-assets",
|
|
102
|
+
"@ikas/storefront-cmd",
|
|
103
|
+
"@ikas/storefront-config",
|
|
104
|
+
"@ikas/storefront-model-functions",
|
|
105
|
+
"@ikas/storefront-models",
|
|
106
|
+
"@ikas/storefront-next",
|
|
107
|
+
"@ikas/storefront-providers",
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
const config = {
|
|
111
|
+
i18n: {
|
|
112
|
+
defaultLocale: "en",
|
|
113
|
+
locales: ["en"],
|
|
114
|
+
localeDetection: false,
|
|
115
|
+
},
|
|
116
|
+
basePath: process.env.NEXTJS_BASE_PATH || "",
|
|
117
|
+
|
|
118
|
+
images: {
|
|
119
|
+
deviceSizes: [
|
|
120
|
+
180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 1950, 2560, 3840,
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
|
|
125
|
+
if (!isServer) {
|
|
126
|
+
config.resolve.fallback.fs = false;
|
|
127
|
+
config.resolve.fallback.net = false;
|
|
128
|
+
config.resolve.fallback.encoding = false;
|
|
129
|
+
config.resolve.fallback.crypto = false;
|
|
130
|
+
config.resolve.fallback.assert = false;
|
|
131
|
+
config.resolve.fallback.stream = false;
|
|
132
|
+
config.module.rules = [
|
|
133
|
+
...config.module.rules,
|
|
134
|
+
{
|
|
135
|
+
test: /@ikas/i,
|
|
136
|
+
sideEffects: false,
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
return config;
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
module.exports = withTM(config);`;
|
|
145
|
+
|
|
146
|
+
export const DEV_ENV = `NEXT_PUBLIC_ENV=local
|
|
147
|
+
NEXT_PUBLIC_BASE_URL=https://api.myikas.dev/api/sf
|
|
148
|
+
NEXT_PUBLIC_IMG_BASE_URL=https://cdn.myikas.dev/
|
|
149
|
+
NEXT_PUBLIC_UPLOAD_GQL_URL=https://api.myikas.dev/api/admin/graphql
|
|
150
|
+
NEXT_PUBLIC_GQL_URL=https://api.myikas.dev/api/sf/graphql
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
export const PROD_ENV = `NEXT_PUBLIC_ENV=local
|
|
154
|
+
NEXT_PUBLIC_BASE_URL=https://api.myikas.com/api/sf
|
|
155
|
+
NEXT_PUBLIC_IMG_BASE_URL=https://cdn.myikas.com/
|
|
156
|
+
NEXT_PUBLIC_UPLOAD_GQL_URL=https://api.myikas.com/api/admin/graphql
|
|
157
|
+
NEXT_PUBLIC_GQL_URL=https://api.myikas.com/api/sf/graphql
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
export const BABEL_RC = `{
|
|
161
|
+
"presets": [
|
|
162
|
+
[
|
|
163
|
+
"next/babel",
|
|
164
|
+
{
|
|
165
|
+
"preset-react": { "throwIfNamespace": false },
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
],
|
|
169
|
+
"plugins": []
|
|
170
|
+
}`;
|
|
@@ -0,0 +1,113 @@
|
|
|
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, workingDir?: string) {
|
|
21
|
+
return (
|
|
22
|
+
(await ConfigGenerator.generateTsConfig(workingDir)) &&
|
|
23
|
+
(await ConfigGenerator.generateBabelRc(workingDir)) &&
|
|
24
|
+
(await ConfigGenerator.generateNextConfig(workingDir)) &&
|
|
25
|
+
(await ConfigGenerator.generatePackageJson(workingDir)) &&
|
|
26
|
+
(await ConfigGenerator.generateEnv(env, workingDir))
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static generateTsConfig(workingDir?: string) {
|
|
31
|
+
return createFile(workingDir || process.cwd(), "tsconfig.json", TS_CONFIG);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static generateBabelRc(workingDir?: string) {
|
|
35
|
+
return createFile(workingDir || process.cwd(), ".babelrc", BABEL_RC);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static generateNextConfig(workingDir?: string) {
|
|
39
|
+
return createFile(
|
|
40
|
+
workingDir || process.cwd(),
|
|
41
|
+
"next.config.js",
|
|
42
|
+
NEXT_CONFIG
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static async generatePackageJson(workingDir?: string) {
|
|
47
|
+
try {
|
|
48
|
+
// const fs = await import("fs-extra");
|
|
49
|
+
const packageJsonPath = path.join(
|
|
50
|
+
workingDir || process.cwd(),
|
|
51
|
+
"package.json"
|
|
52
|
+
);
|
|
53
|
+
const packageJsonBuffer = fs.readFileSync(packageJsonPath);
|
|
54
|
+
|
|
55
|
+
if (packageJsonBuffer.length) {
|
|
56
|
+
const packageJson = JSON.parse(packageJsonBuffer.toString());
|
|
57
|
+
|
|
58
|
+
const setDependencies = (type: "dev" | "normal") => {
|
|
59
|
+
const dependencies = type === "dev" ? DEV_DEPENDENCIES : DEPENDENCIES;
|
|
60
|
+
const dependenciesKey =
|
|
61
|
+
type === "dev" ? "devDependencies" : "dependencies";
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
!packageJson[dependenciesKey] ||
|
|
65
|
+
typeof packageJson[dependenciesKey] !== "object"
|
|
66
|
+
) {
|
|
67
|
+
packageJson[dependenciesKey] = dependencies;
|
|
68
|
+
} else {
|
|
69
|
+
packageJson[dependenciesKey] = {
|
|
70
|
+
...packageJson[dependenciesKey],
|
|
71
|
+
...dependencies,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const orderedDependencies = sortObject(packageJson[dependenciesKey]);
|
|
76
|
+
|
|
77
|
+
packageJson[dependenciesKey] = orderedDependencies;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
setDependencies("dev");
|
|
81
|
+
setDependencies("normal");
|
|
82
|
+
|
|
83
|
+
if (!packageJson.scripts || typeof packageJson.scripts !== "object") {
|
|
84
|
+
packageJson.scripts = SCRIPTS;
|
|
85
|
+
} else {
|
|
86
|
+
packageJson.scripts = {
|
|
87
|
+
...packageJson.scripts,
|
|
88
|
+
...SCRIPTS,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
packageJson.resolutions = {
|
|
93
|
+
...packageJson.resolutions,
|
|
94
|
+
...RESOLUTIONS,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return await createFile(
|
|
98
|
+
packageJsonPath,
|
|
99
|
+
"",
|
|
100
|
+
JSON.stringify(packageJson, null, 2)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
console.error(err);
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static generateEnv(env: ENV, workingDir?: string) {
|
|
110
|
+
const envFileContent = env === "dev" ? DEV_ENV : PROD_ENV;
|
|
111
|
+
return createFile(workingDir || process.cwd(), ".env", envFileContent);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -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";
|