@ikas/storefront-cmd 4.0.0-alpha.10

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.
@@ -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,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
+ }
@@ -0,0 +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";
@@ -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(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
+ }
@@ -0,0 +1,161 @@
1
+ import { IkasThemeJsonPageType } from "@ikas/storefront-models";
2
+
3
+ export type PageInfo = {
4
+ path: string;
5
+ pageComponentName: string;
6
+ pageTypes: IkasThemeJsonPageType[];
7
+ isDynamicSSG?: boolean;
8
+ isSSR?: boolean;
9
+ isEditor?: boolean;
10
+ isCheckout?: boolean;
11
+ };
12
+
13
+ export const CHECKOUT_COMPONENT_ID = "checkout";
14
+
15
+ export const PAGE_INFO: PageInfo[] = [
16
+ {
17
+ path: "[slug]/index.tsx",
18
+ pageComponentName: "SlugPage",
19
+ pageTypes: [
20
+ IkasThemeJsonPageType.PRODUCT,
21
+ IkasThemeJsonPageType.CATEGORY,
22
+ IkasThemeJsonPageType.BRAND,
23
+ ],
24
+ isDynamicSSG: true,
25
+ },
26
+ {
27
+ path: "account/orders/[id].tsx",
28
+ pageComponentName: "OrderDetailPage",
29
+ pageTypes: [IkasThemeJsonPageType.ORDER_DETAIL],
30
+ isSSR: true,
31
+ },
32
+ {
33
+ path: "account/orders/index.tsx",
34
+ pageComponentName: "OrdersPage",
35
+ pageTypes: [IkasThemeJsonPageType.ORDERS],
36
+ },
37
+ {
38
+ path: "account/addresses.tsx",
39
+ pageComponentName: "AddressesPage",
40
+ pageTypes: [IkasThemeJsonPageType.ADDRESSES],
41
+ },
42
+ {
43
+ path: "account/favorite-products.tsx",
44
+ pageComponentName: "FavoriteProductsPage",
45
+ pageTypes: [IkasThemeJsonPageType.FAVORITE_PRODUCTS],
46
+ },
47
+ {
48
+ path: "account/forgot-password.tsx",
49
+ pageComponentName: "ForgotPasswordPage",
50
+ pageTypes: [IkasThemeJsonPageType.FORGOT_PASSWORD],
51
+ },
52
+ {
53
+ path: "account/index.tsx",
54
+ pageComponentName: "AccountPage",
55
+ pageTypes: [IkasThemeJsonPageType.ACCOUNT],
56
+ },
57
+ {
58
+ path: "account/login.tsx",
59
+ pageComponentName: "LoginPage",
60
+ pageTypes: [IkasThemeJsonPageType.LOGIN],
61
+ },
62
+ {
63
+ path: "account/raffles.tsx",
64
+ pageComponentName: "AccountRafflesPage",
65
+ pageTypes: [IkasThemeJsonPageType.RAFFLE_ACCOUNT],
66
+ },
67
+ {
68
+ path: "account/recover-password.tsx",
69
+ pageComponentName: "RecoverPasswordPage",
70
+ pageTypes: [IkasThemeJsonPageType.RECOVER_PASSWORD],
71
+ },
72
+ {
73
+ path: "account/register.tsx",
74
+ pageComponentName: "RegisterPage",
75
+ pageTypes: [IkasThemeJsonPageType.REGISTER],
76
+ },
77
+ {
78
+ path: "blog/[slug].tsx",
79
+ pageComponentName: "BlogSlugPage",
80
+ pageTypes: [
81
+ IkasThemeJsonPageType.BLOG,
82
+ IkasThemeJsonPageType.BLOG_CATEGORY,
83
+ ],
84
+ isDynamicSSG: true,
85
+ },
86
+ {
87
+ path: "blog/index.tsx",
88
+ pageComponentName: "BlogPage",
89
+ pageTypes: [IkasThemeJsonPageType.BLOG_INDEX],
90
+ },
91
+ {
92
+ path: "pages/[slug].tsx",
93
+ pageComponentName: "CustomPage",
94
+ pageTypes: [IkasThemeJsonPageType.CUSTOM],
95
+ isDynamicSSG: true,
96
+ },
97
+ {
98
+ path: "raffle/[slug].tsx",
99
+ pageComponentName: "RafflePage",
100
+ pageTypes: [IkasThemeJsonPageType.RAFFLE_DETAIL],
101
+ isDynamicSSG: true,
102
+ },
103
+ {
104
+ path: "raffle/index.tsx",
105
+ pageComponentName: "RafflesPage",
106
+ pageTypes: [IkasThemeJsonPageType.RAFFLE],
107
+ },
108
+ {
109
+ path: "404.tsx",
110
+ pageComponentName: "NotFoundPage",
111
+ pageTypes: [IkasThemeJsonPageType.NOT_FOUND],
112
+ },
113
+ {
114
+ path: "cart.tsx",
115
+ pageComponentName: "CartPage",
116
+ pageTypes: [IkasThemeJsonPageType.CART],
117
+ },
118
+ {
119
+ path: "index.tsx",
120
+ pageComponentName: "IndexPage",
121
+ pageTypes: [IkasThemeJsonPageType.INDEX],
122
+ },
123
+ {
124
+ path: "search.tsx",
125
+ pageComponentName: "SearchPage",
126
+ pageTypes: [IkasThemeJsonPageType.SEARCH],
127
+ },
128
+ {
129
+ path: "checkout.tsx",
130
+ pageComponentName: "CheckoutPage",
131
+ pageTypes: [],
132
+ isCheckout: true,
133
+ },
134
+ {
135
+ path: "editor.tsx",
136
+ pageComponentName: "EditorPage",
137
+ pageTypes: [],
138
+ isEditor: true,
139
+ },
140
+ ];
141
+
142
+ export const CHECKOUT_PAGE_CONTENT = `import { CheckoutPage } from "@ikas/storefront";
143
+ import { CheckoutPage as CheckoutPageNext } from "@ikas/storefront-next";
144
+
145
+ export default CheckoutPage.default;
146
+ export const getStaticProps = CheckoutPageNext.getStaticProps;
147
+ `;
148
+
149
+ export const EDITOR_PAGE_CONTENT = `import { EditorPage } from "@ikas/storefront";
150
+ import { EditorPage as EditorPageNext } from "@ikas/storefront-next";
151
+ import Components from "../components/__generated__/editor";
152
+
153
+ const PageComponent = EditorPage.default;
154
+
155
+ const Page = (props: any) => {
156
+ return <PageComponent components={Components} {...props} />;
157
+ };
158
+
159
+ export default Page;
160
+ export const getStaticProps = EditorPageNext.getStaticProps;
161
+ `;
@@ -0,0 +1,63 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import { createFile } from "../../../utils/fs";
4
+ import {
5
+ IkasThemeJson,
6
+ IkasThemeJsonPageType,
7
+ IkasThemeJsonStockPreference,
8
+ } from "@ikas/storefront-models";
9
+
10
+ export class ThemeJsonGenerator {
11
+ static generate(themeJson: IkasThemeJson) {
12
+ return createFile(
13
+ path.join(process.cwd(), "src", "theme.json"),
14
+ "",
15
+ JSON.stringify(themeJson, null, 2)
16
+ );
17
+ }
18
+
19
+ static generateInitialThemeJsonFile() {
20
+ const themeJson: IkasThemeJson = {
21
+ pages: [],
22
+ components: [],
23
+ name: "My Theme",
24
+ customData: [],
25
+ settings: {
26
+ colors: [],
27
+ favicon: {
28
+ id: null,
29
+ },
30
+ fontFamily: {
31
+ name: null,
32
+ variants: null,
33
+ },
34
+ stockPreference: IkasThemeJsonStockPreference.SHOW_ALL,
35
+ },
36
+ };
37
+
38
+ themeJson.pages.push({
39
+ id: "1",
40
+ components: [],
41
+ canonicals: null,
42
+ description: null,
43
+ disableIndex: null,
44
+ name: null,
45
+ pageTitle: null,
46
+ slug: null,
47
+ specifications: [],
48
+ type: IkasThemeJsonPageType.INDEX,
49
+ });
50
+
51
+ return ThemeJsonGenerator.generate(themeJson);
52
+ }
53
+
54
+ static async getTheme() {
55
+ try {
56
+ const themePath = path.join(process.cwd(), "src", "theme.json");
57
+ const fileBuffer = fs.readFileSync(themePath);
58
+ return fileBuffer.length ? JSON.parse(fileBuffer.toString()) : null;
59
+ } catch (err) {
60
+ console.error(err);
61
+ }
62
+ }
63
+ }