-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create initial TS template (#868)
* feat: create initial TS template * fix: update start command to work with TS * fix: update init to accept command line arguments * fix: update makePaths to work when no options are passed * fix: update eslint rules for new template * fix: update init command to cater for TS project configurations - add custom declaration files for React and CSS modules - install relevant type definitions: react, jest, etc - add initial eslint config file * fix: move init files into templates directory - JS files reside in init dir - TS files reside init-typescript dir - Common dir contains files used by both templates, i.e. README.md, package.json and App.module.css files to reduce duplication - update eslintignore file with new file paths * fix: modify base eslint config and install eslint dependencies * fix: remove type from package.json * chore: dedupe yarn.lock --------- Co-authored-by: Diana Nanyanzi <diana@dhis2.org>
- Loading branch information
Showing
24 changed files
with
940 additions
and
1,478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
/cli/assets | ||
**/locales/index.js | ||
# These are to avoid lint errors like 'cannot find module App.jsx' | ||
cli/config/init/entrypoint.jsx | ||
cli/config/init/App.test.jsx | ||
cli/config/templates/init/entrypoint.jsx | ||
cli/config/templates/init/App.test.jsx | ||
cli/config/templates/init-typescript/entrypoint.tsx | ||
cli/config/templates/init-typescript/App.test.tsx | ||
cli/config/templates/init-typescript/global.d.ts | ||
cli/config/templates/init-typescript/modules.d.ts | ||
cli/config/templates/init-typescript/eslint.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const defaultsApp = { | ||
type: 'app', | ||
|
||
entryPoints: { | ||
app: './src/App.tsx', | ||
}, | ||
} | ||
|
||
const defaultsLib = { | ||
type: 'lib', | ||
|
||
entryPoints: { | ||
lib: './src/index.tsx', | ||
}, | ||
} | ||
|
||
const defaultsPWA = { | ||
pwa: { | ||
/** | ||
* If true, service worker is registered to perform offline caching | ||
* and use of cacheable sections & recording mode is enabled | ||
*/ | ||
enabled: false, | ||
caching: { | ||
/** | ||
* If true, don't cache requests to exteral domains in app shell. | ||
* Doesn't affect recording mode | ||
*/ | ||
omitExternalRequestsFromAppShell: false, | ||
/** Deprecated version of above */ | ||
omitExternalRequests: false, | ||
/** | ||
* Don't cache URLs matching patterns in this array in app shell. | ||
* Doesn't affect recording mode | ||
*/ | ||
patternsToOmitFromAppShell: [], | ||
/** Deprecated version of above */ | ||
patternsToOmit: [], | ||
/** | ||
* Don't cache URLs matching these patterns in recorded sections. | ||
* Can still be cached in app shell unless filtered there too. | ||
*/ | ||
patternsToOmitFromCacheableSections: [], | ||
/** | ||
* In addition to the contents of an app's 'build' folder, other | ||
* URLs can be precached by adding them to this list which will | ||
* add them to the precache manifest at build time. The format of | ||
* this list must match the Workbox precache list format: | ||
* https://developers.google.com/web/tools/workbox/modules/workbox-precaching#explanation_of_the_precache_list | ||
*/ | ||
additionalManifestEntries: [], | ||
/** | ||
* By default, all the contents of the `build` folder are added to | ||
* the precache to give the app the best chances of functioning | ||
* completely while offline. Developers may choose to omit some | ||
* of these files (for example, thousands of font or image files) | ||
* if they cause cache bloat and the app can work fine without | ||
* them precached. See LIBS-482 | ||
* | ||
* The globs should be relative to the public dir of the built app. | ||
* Used in injectPrecacheManifest.js | ||
*/ | ||
globsToOmitFromPrecache: [], | ||
}, | ||
}, | ||
} | ||
|
||
module.exports = { defaultsApp, defaultsLib, defaultsPWA } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.container { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: 1rem; | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { CustomDataProvider } from '@dhis2/app-runtime' | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import App from './App' | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div') | ||
|
||
const data = { | ||
resource: 'test', | ||
} | ||
|
||
ReactDOM.render( | ||
<CustomDataProvider data={data}> | ||
<App /> | ||
</CustomDataProvider>, | ||
div | ||
) | ||
ReactDOM.unmountComponentAtNode(div) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const config = { | ||
type: 'app', | ||
|
||
entryPoints: { | ||
app: './src/App.tsx', | ||
}, | ||
} | ||
|
||
module.exports = config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const config = { | ||
type: 'lib', | ||
|
||
entryPoints: { | ||
lib: './src/index.tsx', | ||
}, | ||
} | ||
|
||
module.exports = config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import i18n from '@dhis2/d2-i18n' | ||
import React, { FC } from 'react' | ||
import classes from './App.module.css' | ||
|
||
interface QueryResults { | ||
me: { | ||
name: string | ||
} | ||
} | ||
|
||
const query = { | ||
me: { | ||
resource: 'me', | ||
}, | ||
} | ||
|
||
const MyApp: FC = () => { | ||
const { error, loading, data } = useDataQuery<QueryResults>(query) | ||
|
||
if (error) { | ||
return <span>{i18n.t('ERROR')}</span> | ||
} | ||
|
||
if (loading) { | ||
return <span>{i18n.t('Loading...')}</span> | ||
} | ||
|
||
return ( | ||
<div className={classes.container}> | ||
<h1>{i18n.t('Hello {{name}}', { name: data?.me?.name })}</h1> | ||
<h3>{i18n.t('Welcome to DHIS2 with TypeScript!')}</h3> | ||
</div> | ||
) | ||
} | ||
|
||
export default MyApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import js from '@eslint/js' | ||
import tseslint from 'typescript-eslint' | ||
|
||
export default [ | ||
js.configs.recommended, | ||
...tseslint.configs.recommended, | ||
{ | ||
ignores: ['*.d.ts', 'd2.config.js'], | ||
}, | ||
{ | ||
files: ['**/*.{ts,tsx}'], | ||
languageOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'react' | ||
|
||
declare module 'react' { | ||
interface StyleHTMLAttributes<T> extends React.HTMLAttributes<T> { | ||
jsx?: boolean | ||
global?: boolean | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module '*.module.css' { | ||
const classes: { [key: string]: string } | ||
export default classes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"skipLibCheck": true, | ||
"allowJs": true, | ||
"jsx": "react", | ||
"esModuleInterop": true, | ||
"target": "ESNext", | ||
"module": "esnext", | ||
"moduleResolution": "node" | ||
}, | ||
"include": ["src", "types"] | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.