zmp-cli 3.8.3 → 3.9.1
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/create/templates/app-parameters.js +4 -2
- package/create/templates/copy-assets.js +0 -4
- package/create/templates/generate-recoil.js +56 -0
- package/create/templates/generate-store.js +2 -4
- package/create/templates/generate-styles.js +1 -10
- package/create/templates/react/components/user-card.jsx +3 -3
- package/create/templates/react/copy-assets.js +38 -22
- package/create/templates/react/generate-home-page.js +10 -15
- package/create/templates/react/generate-root.js +22 -32
- package/create/templates/react/generate-scripts.js +6 -14
- package/create/templates/react/pages/404.js +27 -0
- package/create/templates/react/pages/about.js +52 -0
- package/create/templates/react/pages/catalog.js +112 -0
- package/create/templates/react/pages/dynamic-route.js +80 -0
- package/create/templates/react/pages/form.js +152 -0
- package/create/templates/react/pages/index copy.js +17 -0
- package/create/templates/react/pages/index.js +17 -0
- package/create/templates/react/pages/settings.js +76 -0
- package/create/templates/react/pages/user.js +56 -0
- package/create/templates/react-typescript/_tsconfig.json +0 -1
- package/create/templates/react-typescript/components/app-items.js +1 -1
- package/create/templates/react-typescript/components/user-card.js +6 -12
- package/create/templates/react-typescript/copy-assets.js +17 -9
- package/create/templates/react-typescript/generate-home-page.js +9 -12
- package/create/templates/react-typescript/generate-root.js +41 -53
- package/create/templates/react-typescript/generate-scripts.js +6 -14
- package/create/templates/react-typescript/pages/about.js +2 -9
- package/create/templates/react-typescript/pages/catalog.js +52 -0
- package/create/templates/react-typescript/pages/form.js +81 -13
- package/create/templates/react-typescript/pages/settings.js +37 -0
- package/create/templates/react-typescript/pages/user.js +16 -11
- package/create/templates/vue/generate-scripts.js +5 -1
- package/create/utils/generate-package-json.js +11 -2
- package/create/utils/get-options.js +21 -1
- package/package.json +1 -1
- package/build/dist/index.dev.js +0 -185
- package/config/dist/index.dev.js +0 -52
- package/create/dist/index.dev.js +0 -300
- package/create/templates/common/tailwind/styles.css +0 -0
- package/create/templates/core/dist/copy-assets.dev.js +0 -85
- package/create/templates/core/dist/generate-home-page.dev.js +0 -24
- package/create/templates/core/dist/generate-routes.dev.js +0 -43
- package/create/templates/core/dist/generate-scripts.dev.js +0 -40
- package/create/templates/dist/app-parameters.dev.js +0 -21
- package/create/templates/dist/copy-assets.dev.js +0 -113
- package/create/templates/dist/create-folders.dev.js +0 -25
- package/create/templates/dist/generate-routes.dev.js +0 -15
- package/create/templates/dist/generate-zmp-custom.dev.js +0 -46
- package/create/templates/react/dist/copy-assets.dev.js +0 -64
- package/create/templates/react/dist/generate-home-page.dev.js +0 -23
- package/create/templates/react/dist/generate-root.dev.js +0 -33
- package/create/templates/react/dist/generate-routes.dev.js +0 -20
- package/create/templates/react/dist/generate-scripts.dev.js +0 -22
- package/create/templates/react/pages/404.jsx +0 -17
- package/create/templates/react/pages/about.jsx +0 -42
- package/create/templates/react/pages/catalog.jsx +0 -39
- package/create/templates/react/pages/dynamic-route.jsx +0 -70
- package/create/templates/react/pages/form-tabs.jsx +0 -64
- package/create/templates/react/pages/form.jsx +0 -61
- package/create/templates/react/pages/left-page-1.jsx +0 -17
- package/create/templates/react/pages/left-page-2.jsx +0 -16
- package/create/templates/react/pages/product.jsx +0 -25
- package/create/templates/react/pages/settings.jsx +0 -28
- package/create/templates/react/pages/user-tabs.jsx +0 -31
- package/create/templates/react/pages/user.jsx +0 -28
- package/create/templates/svelte/dist/copy-assets.dev.js +0 -55
- package/create/templates/svelte/dist/generate-home-page.dev.js +0 -23
- package/create/templates/svelte/dist/generate-root.dev.js +0 -35
- package/create/templates/svelte/dist/generate-routes.dev.js +0 -25
- package/create/templates/svelte/dist/generate-scripts.dev.js +0 -22
- package/create/templates/vue/dist/copy-assets.dev.js +0 -55
- package/create/templates/vue/dist/generate-home-page.dev.js +0 -23
- package/create/templates/vue/dist/generate-root.dev.js +0 -35
- package/create/templates/vue/dist/generate-routes.dev.js +0 -27
- package/create/templates/vue/dist/generate-scripts.dev.js +0 -22
- package/create/utils/dist/generate-app-config.dev.js +0 -29
- package/create/utils/dist/generate-gitignore.dev.js +0 -7
- package/create/utils/dist/generate-package-json.dev.js +0 -72
- package/deploy/dist/index.dev.js +0 -196
- package/deploy/utils/dist/upload-app.dev.js +0 -113
- package/dist/index.dev.js +0 -355
- package/login/dist/index.dev.js +0 -236
- package/login/utils/dist/get-options.dev.js +0 -66
- package/scripts/dist/release.dev.js +0 -105
- package/start/dist/index.dev.js +0 -247
- package/ui/dist/server.dev.js +0 -208
- package/utils/dist/constants.dev.js +0 -10
- package/utils/dist/error.dev.js +0 -18
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
const templateIf = require('../../utils/template-if');
|
|
1
2
|
const indent = require('../../utils/indent');
|
|
2
3
|
const appParameters = require('../app-parameters');
|
|
3
4
|
|
|
4
5
|
module.exports = (options) => {
|
|
5
|
-
const { theming, template } = options;
|
|
6
|
+
const { theming, template, stateManagement } = options;
|
|
6
7
|
// Views
|
|
7
8
|
let views = '';
|
|
8
9
|
if (
|
|
@@ -11,37 +12,37 @@ module.exports = (options) => {
|
|
|
11
12
|
template === 'blank'
|
|
12
13
|
) {
|
|
13
14
|
views = indent(
|
|
14
|
-
|
|
15
|
+
0,
|
|
16
|
+
`
|
|
17
|
+
{/* Your main view, should have "view-main" class */}
|
|
18
|
+
<View main className="safe-areas" url="/" />
|
|
15
19
|
`
|
|
16
|
-
{/* Your main view, should have "view-main" class */}
|
|
17
|
-
<View main className="safe-areas" url="/" />
|
|
18
|
-
`
|
|
19
20
|
).trim();
|
|
20
21
|
}
|
|
21
22
|
if (template === 'tabs') {
|
|
22
23
|
views = indent(
|
|
23
|
-
|
|
24
|
+
0,
|
|
24
25
|
`
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
{/* TabView container */}
|
|
27
|
+
<TabView className="safe-areas">
|
|
28
|
+
{/* Tabbar for switching Tab*/}
|
|
29
|
+
<Tabbar bottom id="app-tab-bar">
|
|
30
|
+
<Link tabLink="#view-home" iconZMP="zi-home" tabLinkActive>
|
|
31
|
+
Home
|
|
32
|
+
</Link>
|
|
33
|
+
<Link tabLink="#view-catalog" iconZMP="zi-list-1">
|
|
34
|
+
Catalog
|
|
35
|
+
</Link>
|
|
36
|
+
<Link tabLink="#view-settings" iconZMP="zi-setting">
|
|
37
|
+
Settings
|
|
38
|
+
</Link>
|
|
39
|
+
</Tabbar>
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
<View id="view-home" main tab tabActive url="/" />
|
|
42
|
+
<View id="view-catalog" name="catalog" tab url="/catalog/" />
|
|
43
|
+
<View id="view-settings" name="settings" tab url="/settings/" />
|
|
44
|
+
</TabView>
|
|
45
|
+
`
|
|
45
46
|
);
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -49,45 +50,32 @@ module.exports = (options) => {
|
|
|
49
50
|
0,
|
|
50
51
|
`
|
|
51
52
|
import React from 'react';
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
import {
|
|
56
|
-
zmp,
|
|
57
|
-
zmpready,
|
|
58
|
-
App,
|
|
59
|
-
View,
|
|
60
|
-
} from 'zmp-framework/react';
|
|
53
|
+
${['blank', 'single-view'].indexOf(template) >= 0
|
|
54
|
+
? `
|
|
55
|
+
import { App, View } from 'zmp-framework/react';
|
|
61
56
|
`.trim()
|
|
62
|
-
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
App,
|
|
67
|
-
TabView,
|
|
68
|
-
View,
|
|
69
|
-
Tabbar,
|
|
70
|
-
Link,
|
|
71
|
-
} from 'zmp-framework/react';
|
|
72
|
-
`.trim()
|
|
73
|
-
}
|
|
74
|
-
import store from '../store';
|
|
57
|
+
: `
|
|
58
|
+
import { App, TabView, View, Tabbar, Link } from 'zmp-framework/react';
|
|
59
|
+
`.trim()}
|
|
60
|
+
${templateIf(stateManagement === 'recoil', () => `import { RecoilRoot } from 'recoil';`, () => `import store from '../store';`)}
|
|
75
61
|
|
|
76
62
|
const MyApp = () => {
|
|
77
63
|
// ZMP Parameters
|
|
78
64
|
const zmpparams = {
|
|
79
|
-
|
|
65
|
+
${indent(8, appParameters(options))}
|
|
80
66
|
};
|
|
81
67
|
|
|
82
68
|
${`
|
|
83
|
-
return (
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
69
|
+
return (${stateManagement === 'recoil' ? `
|
|
70
|
+
<RecoilRoot>` : ''}
|
|
71
|
+
${indent(stateManagement === 'recoil' ? 2 : 0, `<App {...zmpparams} ${theming.darkTheme ? 'themeDark' : ''}>`)}
|
|
72
|
+
${indent(stateManagement === 'recoil' ? 12 : 10, views)}
|
|
73
|
+
${indent(stateManagement === 'recoil' ? 2 : 0, `</App>`)}${stateManagement === 'recoil' ? `
|
|
74
|
+
</RecoilRoot>` : ''}
|
|
87
75
|
);
|
|
88
76
|
`.trim()}
|
|
89
77
|
}
|
|
90
78
|
export default MyApp;
|
|
91
|
-
|
|
79
|
+
`
|
|
92
80
|
).trim();
|
|
93
81
|
};
|
|
@@ -11,7 +11,7 @@ module.exports = (options) => {
|
|
|
11
11
|
`
|
|
12
12
|
// Import React and ReactDOM
|
|
13
13
|
import React from 'react';
|
|
14
|
-
import
|
|
14
|
+
import { createRoot } from 'react-dom/client';
|
|
15
15
|
|
|
16
16
|
// Import ZMP
|
|
17
17
|
import ZMP from '${
|
|
@@ -19,16 +19,10 @@ module.exports = (options) => {
|
|
|
19
19
|
}';
|
|
20
20
|
|
|
21
21
|
// Import ZMP-React Plugin
|
|
22
|
-
import ZMPReact from 'zmp-framework/react'
|
|
22
|
+
import ZMPReact from 'zmp-framework/react';${includeTailwind ? `
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
() => `
|
|
27
|
-
// Import tailwind styles
|
|
28
|
-
import './css/styles.css';
|
|
29
|
-
`,
|
|
30
|
-
() => ''
|
|
31
|
-
)}
|
|
24
|
+
// Import tailwind styles
|
|
25
|
+
import './css/tailwind.css';` : ''}
|
|
32
26
|
|
|
33
27
|
// Import ZMP Styles
|
|
34
28
|
${templateIf(
|
|
@@ -64,10 +58,8 @@ module.exports = (options) => {
|
|
|
64
58
|
ZMP.use(ZMPReact)
|
|
65
59
|
|
|
66
60
|
// Mount React App
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
document.getElementById('app'),
|
|
70
|
-
);
|
|
61
|
+
const root = createRoot(document.getElementById('app')!);
|
|
62
|
+
root.render(React.createElement(App));
|
|
71
63
|
`
|
|
72
64
|
);
|
|
73
65
|
|
|
@@ -15,19 +15,12 @@ module.exports = (options) => {
|
|
|
15
15
|
return (
|
|
16
16
|
<Page name="about">
|
|
17
17
|
<NavbarBack title="About" />
|
|
18
|
-
<Box mt=
|
|
18
|
+
<Box mt="2">
|
|
19
19
|
<Card inset title="About My App">
|
|
20
20
|
<p>This is a demo ZMP App!</p>
|
|
21
21
|
</Card>
|
|
22
22
|
</Box>
|
|
23
|
-
<Box mb=
|
|
24
|
-
<Button
|
|
25
|
-
typeName="primary"
|
|
26
|
-
responsive
|
|
27
|
-
onClick={() => setActionSheetOpened(true)}
|
|
28
|
-
>
|
|
29
|
-
Back
|
|
30
|
-
</Button>
|
|
23
|
+
<Box mb="4">
|
|
31
24
|
<Button
|
|
32
25
|
typeName="secondary"
|
|
33
26
|
responsive
|
|
@@ -2,6 +2,58 @@ const indent = require('../../../utils/indent');
|
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line no-unused-vars
|
|
4
4
|
module.exports = (options) => {
|
|
5
|
+
if (options.stateManagement === 'recoil') {
|
|
6
|
+
return indent(
|
|
7
|
+
0,
|
|
8
|
+
`
|
|
9
|
+
import React from "react";
|
|
10
|
+
import { useRecoilState } from 'recoil';
|
|
11
|
+
import { Page, Title, List, ListItem, Box, Button } from 'zmp-framework/react';
|
|
12
|
+
import { productsState } from '../state';
|
|
13
|
+
|
|
14
|
+
const CatalogPage = () => {
|
|
15
|
+
const [products, setProducts] = useRecoilState(productsState)
|
|
16
|
+
|
|
17
|
+
const addProduct = () => {
|
|
18
|
+
setProducts(p => [
|
|
19
|
+
...p,
|
|
20
|
+
{
|
|
21
|
+
id: '4',
|
|
22
|
+
title: 'Apple iPhone 12',
|
|
23
|
+
description: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi tempora similique reiciendis, error nesciunt vero, blanditiis pariatur dolor, minima sed sapiente rerum, dolorem corrupti hic modi praesentium unde saepe perspiciatis.'
|
|
24
|
+
}
|
|
25
|
+
])
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Page name="catalog">
|
|
30
|
+
<Box m="0" p="4">
|
|
31
|
+
<Title>Catalog</Title>
|
|
32
|
+
<List>
|
|
33
|
+
{products.map((product) => (
|
|
34
|
+
<ListItem
|
|
35
|
+
key={product.id}
|
|
36
|
+
title={product.title}
|
|
37
|
+
link={\`/product/\${product.id}/\`}
|
|
38
|
+
/>
|
|
39
|
+
))}
|
|
40
|
+
</List>
|
|
41
|
+
{products.length === 3 && (
|
|
42
|
+
<Box>
|
|
43
|
+
<Button responsive typeName="secondary" onClick={addProduct}>
|
|
44
|
+
Add Product
|
|
45
|
+
</Button>
|
|
46
|
+
</Box>
|
|
47
|
+
)}
|
|
48
|
+
</Box>
|
|
49
|
+
</Page>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default CatalogPage;
|
|
54
|
+
`
|
|
55
|
+
).trim();
|
|
56
|
+
}
|
|
5
57
|
return indent(
|
|
6
58
|
0,
|
|
7
59
|
`
|
|
@@ -4,12 +4,83 @@ module.exports = (options) => {
|
|
|
4
4
|
const { template } = options;
|
|
5
5
|
const hideNavBar =
|
|
6
6
|
template === 'tabs'
|
|
7
|
-
? `
|
|
7
|
+
? `onPageBeforeIn={()=>{
|
|
8
8
|
//hide navbar
|
|
9
9
|
zmp.toolbar.hide('#app-tab-bar')
|
|
10
10
|
}}`
|
|
11
11
|
: '';
|
|
12
12
|
|
|
13
|
+
if (options.stateManagement === 'recoil') {
|
|
14
|
+
return indent(
|
|
15
|
+
0,
|
|
16
|
+
`
|
|
17
|
+
import React from 'react';
|
|
18
|
+
import { Button, Card, Input, Page, Box, zmp } from 'zmp-framework/react';
|
|
19
|
+
import { useRecoilState } from 'recoil';
|
|
20
|
+
import { userState } from '../state';
|
|
21
|
+
import NavbarBack from '../components/navbar-back';
|
|
22
|
+
|
|
23
|
+
const FormPage = () => {
|
|
24
|
+
const [user, setUser] = useRecoilState(userState)
|
|
25
|
+
|
|
26
|
+
const [form, setForm] = React.useState({ ...user });
|
|
27
|
+
const toast = React.useRef<any>(null)
|
|
28
|
+
|
|
29
|
+
const handleChangeInput = (field, value) => {
|
|
30
|
+
setForm({ ...form, [field]: value })
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const handleSubmit = () => {
|
|
34
|
+
if (!toast.current) {
|
|
35
|
+
toast.current = zmp.toast.create({
|
|
36
|
+
text: 'Saved',
|
|
37
|
+
position: 'bottom',
|
|
38
|
+
closeTimeout: 2000,
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
setUser(form);
|
|
42
|
+
toast.current.open()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Page
|
|
47
|
+
name="user-form"
|
|
48
|
+
${hideNavBar}
|
|
49
|
+
>
|
|
50
|
+
<NavbarBack title="Update user info" />
|
|
51
|
+
<Box>
|
|
52
|
+
<Card inset>
|
|
53
|
+
<Input
|
|
54
|
+
id="name"
|
|
55
|
+
label="Name"
|
|
56
|
+
type="text"
|
|
57
|
+
placeholder="Zalo"
|
|
58
|
+
value={form?.name}
|
|
59
|
+
onChange={(e) => handleChangeInput('name', e.target.value)}
|
|
60
|
+
/>
|
|
61
|
+
<Input
|
|
62
|
+
label="Avatar"
|
|
63
|
+
type="text"
|
|
64
|
+
placeholder="zalo@zalo.me"
|
|
65
|
+
value={form?.avatar}
|
|
66
|
+
onChange={(e) => handleChangeInput('avatar', e.target.value)}
|
|
67
|
+
/>
|
|
68
|
+
<Box mx="0" mt="4">
|
|
69
|
+
<Button responsive typeName="primary" onClick={handleSubmit}>
|
|
70
|
+
Submit
|
|
71
|
+
</Button>
|
|
72
|
+
</Box>
|
|
73
|
+
</Card>
|
|
74
|
+
</Box>
|
|
75
|
+
</Page>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default FormPage;
|
|
80
|
+
`
|
|
81
|
+
).trim();
|
|
82
|
+
}
|
|
83
|
+
|
|
13
84
|
return indent(
|
|
14
85
|
0,
|
|
15
86
|
`
|
|
@@ -22,10 +93,7 @@ module.exports = (options) => {
|
|
|
22
93
|
const FormPage = () => {
|
|
23
94
|
const user = useStore('user')
|
|
24
95
|
|
|
25
|
-
const [form, setForm] = React.useState({
|
|
26
|
-
displayName: user.displayName,
|
|
27
|
-
email: user.email,
|
|
28
|
-
});
|
|
96
|
+
const [form, setForm] = React.useState({ ...user });
|
|
29
97
|
const toast = React.useRef<any>(null)
|
|
30
98
|
|
|
31
99
|
const handleChangeInput = (field, value) => {
|
|
@@ -53,21 +121,21 @@ module.exports = (options) => {
|
|
|
53
121
|
<Box>
|
|
54
122
|
<Card inset>
|
|
55
123
|
<Input
|
|
56
|
-
id="
|
|
57
|
-
label="
|
|
124
|
+
id="name"
|
|
125
|
+
label="Name"
|
|
58
126
|
type="text"
|
|
59
127
|
placeholder="Zalo"
|
|
60
|
-
value={form?.
|
|
61
|
-
onChange={(e) => handleChangeInput('
|
|
128
|
+
value={form?.name}
|
|
129
|
+
onChange={(e) => handleChangeInput('name', e.target.value)}
|
|
62
130
|
/>
|
|
63
131
|
<Input
|
|
64
|
-
label="
|
|
132
|
+
label="Avatar"
|
|
65
133
|
type="text"
|
|
66
134
|
placeholder="zalo@zalo.me"
|
|
67
|
-
value={form?.
|
|
68
|
-
onChange={(e) => handleChangeInput('
|
|
135
|
+
value={form?.avatar}
|
|
136
|
+
onChange={(e) => handleChangeInput('avatar', e.target.value)}
|
|
69
137
|
/>
|
|
70
|
-
<Box mx=
|
|
138
|
+
<Box mx="0" mt="4">
|
|
71
139
|
<Button responsive typeName="primary" onClick={handleSubmit}>
|
|
72
140
|
Submit
|
|
73
141
|
</Button>
|
|
@@ -2,6 +2,43 @@ const indent = require('../../../utils/indent');
|
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line no-unused-vars
|
|
4
4
|
module.exports = (options) => {
|
|
5
|
+
if (options.stateManagement === 'recoil') {
|
|
6
|
+
return indent(
|
|
7
|
+
0,
|
|
8
|
+
`
|
|
9
|
+
import React from "react";
|
|
10
|
+
import { useRecoilValue } from 'recoil';
|
|
11
|
+
import {
|
|
12
|
+
Page,
|
|
13
|
+
List,
|
|
14
|
+
ListItem,
|
|
15
|
+
Title,
|
|
16
|
+
Box
|
|
17
|
+
} from "zmp-framework/react";
|
|
18
|
+
import UserCard from "../components/user-card";
|
|
19
|
+
import { userState } from '../state'
|
|
20
|
+
|
|
21
|
+
const SettingsPage = () => {
|
|
22
|
+
const user = useRecoilValue(userState);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Page name="settings">
|
|
26
|
+
<Box m="0" p="4">
|
|
27
|
+
<Title>Settings</Title>
|
|
28
|
+
<List className="m-0">
|
|
29
|
+
<ListItem link="/user/">
|
|
30
|
+
<UserCard user={user} />
|
|
31
|
+
</ListItem>
|
|
32
|
+
</List>
|
|
33
|
+
</Box>
|
|
34
|
+
</Page>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default SettingsPage;
|
|
39
|
+
`
|
|
40
|
+
).trim();
|
|
41
|
+
}
|
|
5
42
|
return indent(
|
|
6
43
|
0,
|
|
7
44
|
`
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
const indent = require('../../../utils/indent');
|
|
2
2
|
|
|
3
3
|
module.exports = (options) => {
|
|
4
|
-
const { template } = options;
|
|
4
|
+
const { template, stateManagement } = options;
|
|
5
5
|
const hideNavBar =
|
|
6
6
|
template === 'tabs'
|
|
7
|
-
? `
|
|
7
|
+
? `
|
|
8
|
+
onPageBeforeIn={()=>{
|
|
8
9
|
//hide navbar
|
|
9
10
|
zmp.toolbar.hide('#app-tab-bar')
|
|
10
11
|
}}`
|
|
11
12
|
: '';
|
|
12
|
-
const modules = ['Avatar', 'List', 'ListItem', 'Page', 'Title'
|
|
13
|
+
const modules = ['Avatar', 'List', 'ListItem', 'Page', 'Title'];
|
|
14
|
+
if (stateManagement === 'store') {
|
|
15
|
+
modules.push('useStore');
|
|
16
|
+
}
|
|
13
17
|
if (template === 'tabs') {
|
|
14
18
|
modules.push('zmp');
|
|
15
19
|
}
|
|
@@ -18,15 +22,16 @@ module.exports = (options) => {
|
|
|
18
22
|
`
|
|
19
23
|
import React from 'react'
|
|
20
24
|
import { ${modules.join(', ')} } from 'zmp-framework/react'
|
|
21
|
-
import NavbarBack from '../components/navbar-back'
|
|
25
|
+
import NavbarBack from '../components/navbar-back'${stateManagement === 'recoil' ? `
|
|
26
|
+
import { useRecoilValue } from 'recoil';
|
|
27
|
+
import { userState } from '../state';` : ''}
|
|
22
28
|
|
|
23
29
|
const UserPage = () => {
|
|
24
|
-
const user = useStore('user')
|
|
30
|
+
${stateManagement === 'recoil' ? 'const user = useRecoilValue(userState);' : `const user = useStore('user')`}
|
|
25
31
|
|
|
26
32
|
return (
|
|
27
33
|
<Page
|
|
28
|
-
name="user"
|
|
29
|
-
${hideNavBar}
|
|
34
|
+
name="user"${hideNavBar}
|
|
30
35
|
>
|
|
31
36
|
<NavbarBack
|
|
32
37
|
title="User info"
|
|
@@ -34,12 +39,12 @@ module.exports = (options) => {
|
|
|
34
39
|
labelRight="Edit"
|
|
35
40
|
/>
|
|
36
41
|
<div style={{ textAlign: 'center', marginTop: 32 }}>
|
|
37
|
-
<Avatar story online
|
|
38
|
-
<Title style={{ marginTop: 8 }}>{user.
|
|
42
|
+
<Avatar story online src={user.avatar.startsWith('http') ? user.avatar : null}>{user.avatar}</Avatar>
|
|
43
|
+
<Title style={{ marginTop: 8 }}>{user.name}</Title>
|
|
39
44
|
</div>
|
|
40
45
|
<List>
|
|
41
|
-
<ListItem title="Display name" after={user.
|
|
42
|
-
<ListItem title="
|
|
46
|
+
<ListItem title="Display name" after={user.name} />
|
|
47
|
+
<ListItem title="ID" after={user.id} />
|
|
43
48
|
</List>
|
|
44
49
|
</Page>
|
|
45
50
|
)
|
|
@@ -7,6 +7,7 @@ module.exports = (options) => {
|
|
|
7
7
|
cssPreProcessor,
|
|
8
8
|
theming,
|
|
9
9
|
customBuild,
|
|
10
|
+
includeTailwind
|
|
10
11
|
} = options;
|
|
11
12
|
|
|
12
13
|
let scripts = '';
|
|
@@ -19,7 +20,10 @@ module.exports = (options) => {
|
|
|
19
20
|
import ZMP from '${customBuild ? './zmp-custom.js' : 'zmp-framework/core/lite-bundle'}';
|
|
20
21
|
|
|
21
22
|
// Import ZMP-Vue Plugin
|
|
22
|
-
import ZMPVue, { registerComponents } from 'zmp-vue/bundle'
|
|
23
|
+
import ZMPVue, { registerComponents } from 'zmp-vue/bundle';${includeTailwind ? `
|
|
24
|
+
|
|
25
|
+
// Import tailwind styles
|
|
26
|
+
import './css/tailwind.css';` : ''}
|
|
23
27
|
|
|
24
28
|
// Import ZMP Styles
|
|
25
29
|
${templateIf(customBuild, () => `
|
|
@@ -2,7 +2,8 @@ const generateNpmScripts = require('./generate-npm-scripts');
|
|
|
2
2
|
const { generateTailWindScripts } = require('./generate-npm-scripts');
|
|
3
3
|
|
|
4
4
|
module.exports = function generatePackageJson(options) {
|
|
5
|
-
const { name, framework, cssPreProcessor, includeTailwind } =
|
|
5
|
+
const { name, framework, cssPreProcessor, includeTailwind, stateManagement } =
|
|
6
|
+
options;
|
|
6
7
|
|
|
7
8
|
// Dependencies
|
|
8
9
|
const dependencies = ['zmp-framework', 'zmp-sdk', 'swiper'];
|
|
@@ -15,17 +16,25 @@ module.exports = function generatePackageJson(options) {
|
|
|
15
16
|
'postcss@^8',
|
|
16
17
|
'postcss-cli@^8',
|
|
17
18
|
];
|
|
19
|
+
const recoilDependencies = ['recoil'];
|
|
18
20
|
|
|
19
21
|
if (framework === 'vue') {
|
|
20
22
|
dependencies.push(...dependenciesVue);
|
|
21
23
|
} else if (framework === 'react' || framework === 'react-typescript') {
|
|
22
24
|
dependencies.push(...dependenciesReact);
|
|
25
|
+
if (stateManagement === 'recoil') {
|
|
26
|
+
dependencies.push(...recoilDependencies);
|
|
27
|
+
}
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
if (framework === 'react-typescript') {
|
|
26
31
|
dependencies.push(...dependenciesReactTs);
|
|
27
32
|
}
|
|
28
|
-
const devDependencies = [
|
|
33
|
+
const devDependencies = [
|
|
34
|
+
'cross-env',
|
|
35
|
+
'postcss-preset-env@6.7.0',
|
|
36
|
+
'vite@2.6.14',
|
|
37
|
+
];
|
|
29
38
|
// CSS PreProcessor
|
|
30
39
|
if (cssPreProcessor === 'stylus') devDependencies.push(...['stylus']);
|
|
31
40
|
else if (cssPreProcessor === 'less') devDependencies.push(...['less']);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const inquirer = require('inquirer');
|
|
3
3
|
var chalk = require('chalk');
|
|
4
4
|
|
|
5
|
-
const moreOptionsText = chalk.italic(`\t- Including Tailwind CSS`);
|
|
5
|
+
const moreOptionsText = chalk.italic(`\t- Including Tailwind CSS\n\t- Including Recoil (React only)`);
|
|
6
6
|
const questions = [
|
|
7
7
|
{
|
|
8
8
|
type: 'list',
|
|
@@ -216,6 +216,23 @@ const questions = [
|
|
|
216
216
|
},
|
|
217
217
|
],
|
|
218
218
|
},
|
|
219
|
+
{
|
|
220
|
+
type: 'list',
|
|
221
|
+
name: 'stateManagement',
|
|
222
|
+
when: (opts) => opts.moreOptions && (opts.framework === 'react' || opts.framework === 'react-typescript'),
|
|
223
|
+
message: 'Which state management library would you like to use?',
|
|
224
|
+
default: 'store',
|
|
225
|
+
choices: [
|
|
226
|
+
{
|
|
227
|
+
name: 'ZMP Store (Redux pattern)',
|
|
228
|
+
value: 'store',
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: 'Recoil',
|
|
232
|
+
value: 'recoil',
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
},
|
|
219
236
|
];
|
|
220
237
|
|
|
221
238
|
module.exports = function getOptions() {
|
|
@@ -233,6 +250,9 @@ module.exports = function getOptions() {
|
|
|
233
250
|
};
|
|
234
251
|
options.customBuild = false;
|
|
235
252
|
options.includeTailwind = options.moreOptions && options.includeTailwind;
|
|
253
|
+
if (!options.stateManagement) {
|
|
254
|
+
options.stateManagement = 'store';
|
|
255
|
+
}
|
|
236
256
|
delete options.themingCustomColor;
|
|
237
257
|
delete options.themingColor;
|
|
238
258
|
delete options.themingIconFonts;
|