Skip to content

Commit

Permalink
update create-app-demo sample
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Mar 24, 2021
1 parent 36d173f commit 00ecc0e
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/xarc-create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"prettier": "^2.2.1",
"prompts": "^2.3.2",
"run-verify": "^1.2.5",
"shcmd": "^0.7.9",
"shcmd": "^0.8.4",
"sinon": "^7.2.6",
"sinon-chai": "^3.3.0",
"webpack": "^4.41.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/xarc-create-app/template/_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ module.exports = (base, merge) => {
node: ">= 12",
npm: ">= 6",
},
prettier: {
printWidth: 100,
},
dependencies: {
"@babel/runtime": "^7.12.5",
"@xarc/app": "^9.0.3", // version will come from ../package.json
Expand All @@ -44,6 +47,7 @@ module.exports = (base, merge) => {
"@xarc/app-dev": "^9.0.3", // version will come from ../package.json
"@xarc/opt-postcss": "^1.0.0",
"@xarc/opt-stylus": "^1.0.0",
prettier: "^2.2.1",
"ts-node": "^9.1.1",
typescript: "^4.1.3",
},
Expand Down
2 changes: 1 addition & 1 deletion samples/create-app-demo/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
const { babelPresetFile } = require("@xarc/app-dev");

module.exports = {
presets: [babelPresetFile]
presets: [babelPresetFile],
};
4 changes: 4 additions & 0 deletions samples/create-app-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"node": ">= 12",
"npm": ">= 6"
},
"prettier": {
"printWidth": 100
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"@xarc/app": "^9.0.4",
Expand All @@ -42,6 +45,7 @@
"@xarc/app-dev": "^9.0.4",
"@xarc/opt-postcss": "^1.0.0",
"@xarc/opt-stylus": "^1.0.0",
"prettier": "^2.2.1",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
}
Expand Down
6 changes: 3 additions & 3 deletions samples/create-app-demo/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { declareSubApp, xarcV2 } from "@xarc/react";

export const home = declareSubApp({
name: "home",
getModule: () => import("./home")
getModule: () => import("./home"),
});

export const Demo2 = declareSubApp({
name: "demo2",
getModule: () => import("./demo2")
getModule: () => import("./demo2"),
});

export const Demo3 = declareSubApp({
name: "demo3",
getModule: () => import("./demo3")
getModule: () => import("./demo3"),
});

xarcV2.debug("app.tsx");
4 changes: 2 additions & 2 deletions samples/create-app-demo/src/demo1/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styles from "../styles/demo1.mod.styl";
// CSS module support for .css
import styles2 from "../styles/demo1.mod.css";

const Demo1 = props => {
const Demo1 = (props) => {
return (
<div style={{ padding: "5px", border: "solid", marginLeft: "15%", marginRight: "15%" }}>
<p className={styles.demo1}>subapp demo1 (.styl css module blue color)</p>
Expand All @@ -19,5 +19,5 @@ const Demo1 = props => {
};

export const subapp: ReactSubApp = {
Component: Demo1
Component: Demo1,
};
20 changes: 10 additions & 10 deletions samples/create-app-demo/src/demo2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ export { reduxReducers } from "./reducers";

const incNumber = () => {
return {
type: "INC_NUMBER"
type: "INC_NUMBER",
};
};

const decNumber = () => {
return {
type: "DEC_NUMBER"
type: "DEC_NUMBER",
};
};

const Demo2 = props => {
const Demo2 = (props) => {
const { value, dispatch } = props;

return (
Expand All @@ -33,7 +33,7 @@ const Demo2 = props => {
marginTop: "15px",
border: "solid",
marginLeft: "15%",
marginRight: "15%"
marginRight: "15%",
}}
>
<h2>subapp demo2 with Redux</h2>
Expand All @@ -45,20 +45,20 @@ const Demo2 = props => {
);
};

const mapStateToProps = state => {
const mapStateToProps = (state) => {
return { value: state.number.value };
};

export const subapp: ReactSubApp = {
Component: connect(mapStateToProps, dispatch => ({ dispatch }))(Demo2),
Component: connect(mapStateToProps, (dispatch) => ({ dispatch }))(Demo2),
wantFeatures: [
reduxFeature({
React,
shareStore: true,
reducers: true, // true => read the reduxReducers export from this file
prepare: async initialState => {
prepare: async (initialState) => {
return { initialState: initialState || { number: { value: 999 } } };
}
})
]
},
}),
],
};
6 changes: 3 additions & 3 deletions samples/create-app-demo/src/demo2/reducers.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const number = (store = { value: 0 }, action) => {
if (action.type === "INC_NUMBER") {
return {
value: store.value + 1
value: store.value + 1,
};
} else if (action.type === "DEC_NUMBER") {
return {
value: store.value - 1
value: store.value - 1,
};
}

return store;
};

export const reduxReducers = {
number
number,
};
8 changes: 4 additions & 4 deletions samples/create-app-demo/src/demo3/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Demo3 = () => {
marginTop: "15px",
border: "solid",
marginLeft: "15%",
marginRight: "15%"
marginRight: "15%",
}}
>
<h2>subapp demo3 with react-query</h2>
Expand All @@ -38,7 +38,7 @@ export const subapp: ReactSubApp = {
wantFeatures: [
reactQueryFeature({
React,
serverModule: require.resolve("./react-query-fetch")
})
]
serverModule: require.resolve("./react-query-fetch"),
}),
],
};
4 changes: 2 additions & 2 deletions samples/create-app-demo/src/demo3/react-query-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const maxDelay = 50;
export const demo3QueryFn = async ({ queryKey }) => {
const delay = Math.floor(Math.random() * maxDelay);

return new Promise(resolve => {
return new Promise((resolve) => {
setTimeout(resolve, delay);
}).then(() => {
return { msg: "react-query", queryKey, delay };
Expand All @@ -17,6 +17,6 @@ export const prefetchQuery = async ({ queryClient, ssrData }) => {

return {
queryClient,
dehydratedState: dehydrate(queryClient)
dehydratedState: dehydrate(queryClient),
};
};
10 changes: 5 additions & 5 deletions samples/create-app-demo/src/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { message } from "./message";
export const Demo1 = createDynamicComponent(
{
name: "demo1",
getModule: () => import("../demo1")
getModule: () => import("../demo1"),
},
{ ssr: true }
);

const Home = props => {
const Home = (props) => {
return (
<div style={{ textAlign: "center" }}>
<h1>
Expand All @@ -30,7 +30,7 @@ export const subapp: ReactSubApp = {
Component: Home,
wantFeatures: [
staticPropsFeature({
serverModule: require.resolve("./static-props")
})
]
serverModule: require.resolve("./static-props"),
}),
],
};
2 changes: 1 addition & 1 deletion samples/create-app-demo/src/home/static-props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const maxDelay = 50;

export async function getStaticProps() {
const delay = Math.floor(Math.random() * maxDelay);
return new Promise(resolve => {
return new Promise((resolve) => {
return setTimeout(
() => resolve({ props: { message: "Hello from static props", delay } }),
delay
Expand Down
8 changes: 4 additions & 4 deletions samples/create-app-demo/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const connection: ConnectionConfig = {
host: process.env.HOST || "localhost",
// The env APP_SERVER_PORT allows Electrode X to control app's listening port during dev
// to serve both static assets and app under a unified proxy port
port: parseInt(process.env.APP_SERVER_PORT || process.env.PORT || "3000")
port: parseInt(process.env.APP_SERVER_PORT || process.env.PORT || "3000"),
};

//
Expand All @@ -19,8 +19,8 @@ const plugins: PluginsConfig = {
*/
"@xarc/app-dev": {
priority: -1,
enable: Boolean(process.env.WEBPACK_DEV)
}
enable: Boolean(process.env.WEBPACK_DEV),
},
};

/**
Expand All @@ -37,5 +37,5 @@ export const config: ElectrodeServerConfig = {
// don't start fastify server automatically so app can setup routes
deferStart: true,
connection,
plugins
plugins,
};
4 changes: 2 additions & 2 deletions samples/create-app-demo/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { config } from "./config";
export async function start() {
await loadRuntimeSupport({
isomorphicCdnOptions: {
prodOnly: true
}
prodOnly: true,
},
});

const server = await electrodeServer(config);
Expand Down
8 changes: 4 additions & 4 deletions samples/create-app-demo/src/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export function setupRoutes(server) {
subApps: [
{ name: home.name, ssr: true },
{ name: Demo2.name, ssr: true },
{ name: Demo3.name, ssr: true }
{ name: Demo3.name, ssr: true },
],
prodAssetData: {
cdnMap: "config/assets.json"
}
cdnMap: "config/assets.json",
},
});

server.route({
Expand All @@ -35,6 +35,6 @@ export function setupRoutes(server) {
} catch (error) {
reply.send(error.stack);
}
}
},
});
}
8 changes: 4 additions & 4 deletions samples/create-app-demo/xrun-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ xrun.updateEnv(
* In dev mode, a proxy server listens at `PORT` and forward requests to
* to actual node.js app server and webpack dev server.
*/
PORT: 3000
PORT: 3000,
/**
* In dev mode, `APP_SERVER_PORT` sets the proxy forward port for the
* node.js app server. If it's not defined or `0`, then a randomly available
Expand All @@ -26,14 +26,14 @@ xrun.updateEnv(
},
{
// do not override any env flag already set in process.env
override: false
override: false,
}
);

loadDevTasks(xrun, {
// options to customize features
webpackOptions: {
// enable CSS module for files other than `.mod.css`
cssModuleSupport: "byModExt"
}
cssModuleSupport: "byModExt",
},
});

0 comments on commit 00ecc0e

Please sign in to comment.