Skip to content

Commit

Permalink
feat: show off more features when initing a new app
Browse files Browse the repository at this point in the history
  • Loading branch information
amcgee committed Aug 27, 2019
1 parent 861844f commit 13cb4f1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
44 changes: 44 additions & 0 deletions cli/config/init.entrypoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react'
import { DataQuery } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'

const query = {
me: {
resource: 'me',
},
}

const MyApp = () => (
<div className="container">
<style jsx>{`
.container {
position: absolute;
top: 48px;
bottom: 0px;
left: 0px;
right: 0px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 1rem;
}
}`}</style>
<DataQuery query={query}>
{({ error, loading, data }) => {
if (error) return <span>ERROR</span>
if (loading) return <span>...</span>
return (
<>
<h1>
{i18n.t('Hello {{name}}', { name: data.me.name })}
</h1>
<h3>{i18n.t('Welcome to DHIS2!')}</h3>
</>
)
}}
</DataQuery>
</div>
)

export default MyApp
24 changes: 3 additions & 21 deletions cli/src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ const handler = async ({ force, name, cwd, lib }) => {

if (!fs.existsSync(paths.package)) {
reporter.info('No package.json found, creating one...')
// await exec({
// cmd: 'yarn',
// args: [
// 'init'
// ],
// cwd: target || cwd,
// stdio: 'inherit',
// pipe: true
// })

const pkg = require(path.join(
__dirname,
Expand All @@ -43,15 +34,6 @@ const handler = async ({ force, name, cwd, lib }) => {
fs.writeJSONSync(paths.package, pkg, {
spaces: 2,
})

// await exec({
// cmd: 'yarn',
// args: [
// 'install',
// '--pnp' // Let's be FANCY!
// ],
// cwd: paths.base
// })
}

reporter.info('Creating package scripts...')
Expand Down Expand Up @@ -140,9 +122,9 @@ const handler = async ({ force, name, cwd, lib }) => {
} else {
reporter.info(`Creating entrypoint ${chalk.bold(entrypoint)}`)
fs.mkdirpSync(path.join(paths.base, 'src'))
fs.writeFileSync(
path.join(paths.base, entrypoint),
"export default () => 'Welcome to DHIS2!'"
fs.copyFileSync(
path.join(__dirname, '../../config/init.entrypoint.js'),
path.join(paths.base, entrypoint)
)
}

Expand Down

0 comments on commit 13cb4f1

Please sign in to comment.