Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove custom eslint from TS template #888

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ 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
13 changes: 7 additions & 6 deletions cli/config/templates/init-typescript/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { CustomDataProvider } from '@dhis2/app-runtime'
import React from 'react'
import ReactDOM from 'react-dom'
import { createRoot } from 'react-dom/client'
import App from './App'

it('renders without crashing', () => {
const div = document.createElement('div')
const container = document.createElement('div')

const data = {
resource: 'test',
}

ReactDOM.render(
const root = createRoot(container)
root.render(
<CustomDataProvider data={data}>
<App />
</CustomDataProvider>,
div
</CustomDataProvider>
)
ReactDOM.unmountComponentAtNode(div)

root.unmount()
})
17 changes: 0 additions & 17 deletions cli/config/templates/init-typescript/eslint.config.js

This file was deleted.

32 changes: 4 additions & 28 deletions cli/src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const handler = async ({ force, name, cwd, lib, typeScript }) => {
reporter.info('Installing @dhis2/cli-app-scripts...')
await exec({
cmd: 'yarn',
args: ['add', '--dev', '@dhis2/cli-app-scripts'],
args: ['add', '--dev', '@dhis2/cli-app-scripts@alpha'],
cwd: paths.base,
})
}
Expand Down Expand Up @@ -192,23 +192,18 @@ const handler = async ({ force, name, cwd, lib, typeScript }) => {
fs.copyFileSync(paths.initTSConfig, paths.tsConfig)

reporter.info('install TypeScript as a dev dependency')
// ToDO: restrict the major version of TS we install

await exec({
cmd: 'yarn',
args: ['add', 'typescript', '--dev'],
args: ['add', 'typescript@^5', '--dev'],
cwd: paths.base,
})

// install any other TS dependencies needed
reporter.info('install type definitions')
await exec({
cmd: 'yarn',
args: [
'add',
'@types/react @types/react-dom @types/jest',
'@types/eslint',
'--dev',
],
args: ['add', '@types/react @types/react-dom @types/jest', '--dev'],
cwd: paths.base,
})

Expand All @@ -230,25 +225,6 @@ const handler = async ({ force, name, cwd, lib, typeScript }) => {
paths.initModulesDeclaration,
path.join(typesDir, 'modules.d.ts')
)

// ToDO: make custom eslint config part of the template (and copy it)
// similar to: https://github.com/dhis2/data-exchange-app/pull/79/files#diff-e2954b558f2aa82baff0e30964490d12942e0e251c1aa56c3294de6ec67b7cf5
// install dependencies needed for eslint
// "@typescript-eslint/eslint-plugin"
// "@typescript-eslint/parser"

reporter.info('setting up eslint configuration')
await exec({
cmd: 'yarn',
args: ['add', 'eslint @eslint/js typescript-eslint', '--dev'],
cwd: paths.base,
})
// copy eslint config
fs.copyFileSync(paths.initEslint, paths.eslintConfig)

// ToDO: we're hardcoding running TS, we need to figure out how to pass the argument from the CLI

// ToDO: aim to have a TS project that runs with "yarn start" and "yarn build"
}

const extension = typeScript ? 'ts' : 'js'
Expand Down
8 changes: 2 additions & 6 deletions cli/src/lib/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ module.exports = (cwd = process.cwd(), { typeScript } = {}) => {
'../../config/templates/init-typescript/tsconfig.json'
),

initEslint: path.join(
__dirname,
'../../config/templates/init-typescript/eslint.config.js'
),
initGlobalDeclaration: path.join(
__dirname,
'../../config/templates/init-typescript/global.d.ts'
Expand All @@ -78,10 +74,10 @@ module.exports = (cwd = process.cwd(), { typeScript } = {}) => {
: '../../config/d2ConfigDefaults.js'
),
babelConfig: path.join(__dirname, '../../config/babel.config.js'),
jestConfigDefaults: path.join(__dirname, '../../config/jest.config.js'), // TODO: probably need a different jest.config for TS
jestConfigDefaults: path.join(__dirname, '../../config/jest.config.js'),

shellSource,
shellSourceEntrypoint: path.join(shellSource, 'src/App.jsx'), // TODO: double check the effect of having TS in shell folder
shellSourceEntrypoint: path.join(shellSource, 'src/App.jsx'),
shellSourcePublic: path.join(shellSource, 'public'),

// destination paths where we copy files to
Expand Down
Loading
Loading