@ikas/storefront-cmd 4.0.0-alpha.48 → 4.0.0-alpha.49
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/build/_virtual/_cloneBuffer.js +1 -0
- package/build/_virtual/_commonjsHelpers.js +1 -0
- package/build/_virtual/_nodeUtil.js +1 -0
- package/build/_virtual/isBuffer.js +1 -0
- package/{src/index.ts → build/index.d.ts} +3 -4
- package/build/index.js +1 -0
- package/build/scripts/generators/api/index.d.ts +5 -0
- package/build/scripts/generators/api/index.js +1 -0
- package/build/scripts/generators/api/info.d.ts +12 -0
- package/build/scripts/generators/api/info.js +1 -0
- package/build/scripts/generators/components/index.d.ts +11 -0
- package/build/scripts/generators/components/index.js +1 -0
- package/build/scripts/generators/config/content.d.ts +58 -0
- package/build/scripts/generators/config/content.js +1 -0
- package/build/scripts/generators/config/index.d.ts +9 -0
- package/build/scripts/generators/config/index.js +1 -0
- package/{src/scripts/generators/index.ts → build/scripts/generators/index.d.ts} +6 -6
- package/build/scripts/generators/pages/index.d.ts +7 -0
- package/build/scripts/generators/pages/index.js +1 -0
- package/build/scripts/generators/pages/info.d.ts +14 -0
- package/build/scripts/generators/pages/info.js +1 -0
- package/build/scripts/generators/theme/index.d.ts +6 -0
- package/build/scripts/generators/theme/index.js +1 -0
- package/build/scripts/generators/types/index.d.ts +19 -0
- package/build/scripts/generators/types/index.js +1 -0
- package/build/scripts/ikas.d.ts +1 -0
- package/build/scripts/theme-build/index.d.ts +3 -0
- package/build/scripts/theme-build/index.js +1 -0
- package/build/utils/fs.d.ts +28 -0
- package/build/utils/fs.js +1 -0
- package/build/utils/helper.d.ts +2 -0
- package/build/utils/helper.js +1 -0
- package/package.json +6 -6
- package/src/scripts/generators/api/index.ts +0 -27
- package/src/scripts/generators/api/info.ts +0 -47
- package/src/scripts/generators/components/index.ts +0 -270
- package/src/scripts/generators/config/content.ts +0 -170
- package/src/scripts/generators/config/index.ts +0 -113
- package/src/scripts/generators/pages/index.ts +0 -102
- package/src/scripts/generators/pages/info.ts +0 -161
- package/src/scripts/generators/theme/index.ts +0 -63
- package/src/scripts/generators/types/index.ts +0 -526
- package/src/scripts/ikas.ts +0 -45
- package/src/scripts/theme-build/index.ts +0 -99
- package/src/utils/fs.ts +0 -93
- package/src/utils/helper.ts +0 -20
|
@@ -1,270 +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, 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
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
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
|
-
}`;
|
|
@@ -1,113 +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, 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,102 +0,0 @@
|
|
|
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(workingDir?: string) {
|
|
13
|
-
const pagesDir = path.join(workingDir || 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, workingDir));
|
|
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, workingDir)
|
|
28
|
-
: false;
|
|
29
|
-
const editorPageGenerateSuccess = editorPageInfo
|
|
30
|
-
? await PageGenerator.generatePageWithInfo(editorPageInfo, workingDir)
|
|
31
|
-
: false;
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
pagesGenerateSuccess &&
|
|
35
|
-
checkoutPageGenerateSuccess &&
|
|
36
|
-
editorPageGenerateSuccess
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static async generatePageWithInfo(pageInfo: PageInfo, workingDir?: string) {
|
|
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(workingDir || 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
|
-
}
|