@dhis2/create-app 5.3.0-alpha.1 → 5.3.0-alpha.3

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.
Files changed (42) hide show
  1. package/package.json +1 -2
  2. package/src/index.js +46 -37
  3. package/src/utils/getPackageManager.js +15 -0
  4. package/templates/template-ts-dataelements/.prettierrc.mjs +10 -0
  5. package/templates/template-ts-dataelements/README.md +45 -0
  6. package/templates/template-ts-dataelements/d2.config.js +12 -0
  7. package/templates/template-ts-dataelements/eslint.config.mjs +13 -0
  8. package/templates/template-ts-dataelements/i18n/en.pot +42 -0
  9. package/templates/template-ts-dataelements/package.json +35 -0
  10. package/templates/template-ts-dataelements/pnpm-lock.yaml +12950 -0
  11. package/templates/template-ts-dataelements/pnpm-workspace.yaml +17 -0
  12. package/templates/template-ts-dataelements/src/App.module.css +22 -0
  13. package/templates/template-ts-dataelements/src/App.test.tsx +21 -0
  14. package/templates/template-ts-dataelements/src/App.tsx +95 -0
  15. package/templates/template-ts-dataelements/src/components/DataElementsList.module.css +9 -0
  16. package/templates/template-ts-dataelements/src/components/DataElementsList.tsx +132 -0
  17. package/templates/template-ts-dataelements/tsconfig.json +17 -0
  18. package/templates/template-ts-dataelements/types/global.d.ts +8 -0
  19. package/templates/template-ts-dataelements/types/modules.d.ts +4 -0
  20. package/templates/template-ts-dataelements/viteConfigExtensions.mts +15 -0
  21. package/templates/template-ts-dataelements-react-router/.prettierrc.mjs +10 -0
  22. package/templates/template-ts-dataelements-react-router/README.md +45 -0
  23. package/templates/template-ts-dataelements-react-router/d2.config.js +12 -0
  24. package/templates/template-ts-dataelements-react-router/eslint.config.mjs +13 -0
  25. package/templates/template-ts-dataelements-react-router/i18n/en.pot +39 -0
  26. package/templates/template-ts-dataelements-react-router/package.json +36 -0
  27. package/templates/template-ts-dataelements-react-router/pnpm-lock.yaml +12982 -0
  28. package/templates/template-ts-dataelements-react-router/pnpm-workspace.yaml +17 -0
  29. package/templates/template-ts-dataelements-react-router/src/App.module.css +61 -0
  30. package/templates/template-ts-dataelements-react-router/src/App.test.tsx +21 -0
  31. package/templates/template-ts-dataelements-react-router/src/App.tsx +94 -0
  32. package/templates/template-ts-dataelements-react-router/src/AppWrapper.tsx +31 -0
  33. package/templates/template-ts-dataelements-react-router/src/components/About.tsx +15 -0
  34. package/templates/template-ts-dataelements-react-router/src/components/AppMenu.tsx +31 -0
  35. package/templates/template-ts-dataelements-react-router/src/components/DataElementsList.module.css +9 -0
  36. package/templates/template-ts-dataelements-react-router/src/components/DataElementsList.tsx +132 -0
  37. package/templates/template-ts-dataelements-react-router/tsconfig.json +17 -0
  38. package/templates/template-ts-dataelements-react-router/types/global.d.ts +8 -0
  39. package/templates/template-ts-dataelements-react-router/types/modules.d.ts +4 -0
  40. package/templates/template-ts-dataelements-react-router/viteConfigExtensions.mts +15 -0
  41. package/templates/template-ts-dataelements-react-router.zip +0 -0
  42. package/templates/template-ts-dataelements.zip +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/create-app",
3
- "version": "5.3.0-alpha.1",
3
+ "version": "5.3.0-alpha.3",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -12,7 +12,6 @@
12
12
  "dependencies": {
13
13
  "@dhis2/cli-helpers-engine": "^3.2.2",
14
14
  "@inquirer/prompts": "^7.8.4",
15
- "decompress": "^4.2.1",
16
15
  "fast-glob": "^3.3.3",
17
16
  "fs-extra": "^11.3.3"
18
17
  },
package/src/index.js CHANGED
@@ -1,9 +1,10 @@
1
+ const { execSync } = require('child_process')
1
2
  const path = require('path')
2
- const { reporter, exec } = require('@dhis2/cli-helpers-engine')
3
+ const { reporter, exec, chalk } = require('@dhis2/cli-helpers-engine')
3
4
  const { input, select } = require('@inquirer/prompts')
4
- const decompress = require('decompress')
5
5
  const fg = require('fast-glob')
6
6
  const fs = require('fs-extra')
7
+ const { default: getPackageManager } = require('./utils/getPackageManager')
7
8
 
8
9
  process.on('uncaughtException', (error) => {
9
10
  if (error instanceof Error && error.name === 'ExitPromptError') {
@@ -15,14 +16,15 @@ process.on('uncaughtException', (error) => {
15
16
  })
16
17
 
17
18
  const templates = {
19
+ templateRoot: path.join(__dirname, '../templates'),
18
20
  templateWithList: path.join(
19
21
  __dirname,
20
- '../templates/template-ts-dataelements.zip'
22
+ '../templates/template-ts-dataelements'
21
23
  ),
22
24
 
23
25
  templateWithReactRouter: path.join(
24
26
  __dirname,
25
- '../templates/template-ts-dataelements-react-router.zip'
27
+ '../templates/template-ts-dataelements-react-router'
26
28
  ),
27
29
  }
28
30
 
@@ -51,24 +53,17 @@ const commandHandler = {
51
53
  packageManager: {
52
54
  description: 'Package Manager',
53
55
  type: 'string',
54
- default: 'pnpm',
55
56
  alias: ['package', 'packagemanager'],
56
57
  },
57
58
  },
58
59
  }
60
+
59
61
  const getTemplateFile = (templateName) => {
60
62
  return templateName === 'react-router'
61
63
  ? templates.templateWithReactRouter
62
64
  : templates.templateWithList
63
65
  }
64
66
 
65
- const defaultOptions = {
66
- typeScript: true,
67
- templateName: 'basic',
68
- template: getTemplateFile('basic'),
69
- packageManager: 'pnpm',
70
- }
71
-
72
67
  const command = {
73
68
  command: '[app]',
74
69
  builder: (yargs) => {
@@ -77,11 +72,6 @@ const command = {
77
72
  handler: async (argv) => {
78
73
  let name = argv._[0] || argv.name
79
74
 
80
- const selectedOptions = {
81
- ...defaultOptions,
82
- }
83
-
84
- reporter.debug(`running "npm create @dhis2/app" (or npx) command"`)
85
75
  const useDefauls = argv.yes
86
76
 
87
77
  if (!name) {
@@ -94,10 +84,11 @@ const command = {
94
84
  reporter.log(`name of project: ${name}`)
95
85
  }
96
86
 
97
- selectedOptions.typeScript = argv.typescript
98
- selectedOptions.packageManager = argv.packageManager
99
- selectedOptions.templateName = argv.template
100
- selectedOptions.template = getTemplateFile(argv.template)
87
+ const selectedOptions = {
88
+ typeScript: argv.typescript,
89
+ packageManager: argv.packageManager ?? getPackageManager(),
90
+ templateName: argv.template,
91
+ }
101
92
 
102
93
  if (!useDefauls) {
103
94
  const packageManager = await select({
@@ -110,8 +101,6 @@ const command = {
110
101
  ],
111
102
  })
112
103
 
113
- // pnpm = packageManager === 'pnpm'
114
- // npm = packageManager === 'npm'
115
104
  selectedOptions.packageManager = packageManager
116
105
 
117
106
  const language = await select({
@@ -126,7 +115,7 @@ const command = {
126
115
  selectedOptions.typeScript = language === 'ts'
127
116
 
128
117
  const template = await select({
129
- message: 'Select a teamplate',
118
+ message: 'Select a template',
130
119
  default: 'ts',
131
120
  choices: [
132
121
  { name: 'Basic Template', value: 'basic' },
@@ -138,23 +127,15 @@ const command = {
138
127
  })
139
128
 
140
129
  selectedOptions.templateName = template
141
- selectedOptions.template = getTemplateFile(template)
142
130
  }
143
131
 
144
- // let pkgManager = 'yarn'
145
- // if (pnpm) {
146
- // pkgManager = 'pnpm'
147
- // } else if (npm) {
148
- // pkgManager = 'npm'
149
- // }
150
-
151
132
  reporter.info(
152
133
  `Initialising a new project using "${selectedOptions.packageManager}" as a package manager.`
153
134
  )
154
135
 
155
- if (selectedOptions.packageManager !== 'pnpm') {
136
+ if (selectedOptions.packageManager === 'yarn') {
156
137
  reporter.warn(
157
- 'We recommend using "pnpm" as a package manager for new projects. You can do so by passing the argument --pnpm (i.e. d2 app scripts init --pnpm). This will become the default in future versions of d2 CLI.'
138
+ 'We recommend using "pnpm" as a package manager for new projects. Yarn 1 will be deprecated in future versions of the CLI.'
158
139
  )
159
140
  }
160
141
  // create the folder where the template will be generated
@@ -168,9 +149,26 @@ const command = {
168
149
  process.exit(1)
169
150
  }
170
151
 
171
- reporter.info(`selected options: ${JSON.stringify(selectedOptions)}`)
152
+ reporter.info(`${chalk.cyan('Selected options:')}`)
153
+ for (const [x, y] of Object.entries(selectedOptions)) {
154
+ reporter.info(` ${x}: ${y}`)
155
+ }
172
156
 
173
- await decompress(selectedOptions.template, cwd)
157
+ try {
158
+ // Running git clean on templates folder
159
+ // This is useful in local development if you have built the templates for testing
160
+ // and want to make sure to delete d2 and node_modules folders before copying the template
161
+ execSync(`git clean -X -f -- ${templates.templateRoot}`, {
162
+ stdio: 'ignore',
163
+ })
164
+ reporter.debug('Successfully ran git clean')
165
+ } catch (err) {
166
+ reporter.debug(err)
167
+ }
168
+
169
+ reporter.info('Copying template files')
170
+ const templateFiles = getTemplateFile(selectedOptions.templateName)
171
+ fs.copySync(templateFiles, cwd)
174
172
 
175
173
  const paths = {
176
174
  base: cwd,
@@ -237,6 +235,8 @@ const command = {
237
235
 
238
236
  // copy correct lock file for npm/yarn
239
237
  if (!pnpm) {
238
+ // ? copying yarn.lock or package-lock speeds installation a bit
239
+ // ? but we could also just run "yarn install" and generate the lock file
240
240
  if (fs.existsSync(paths.pnpmLock)) {
241
241
  fs.removeSync(paths.pnpmLock)
242
242
  }
@@ -313,6 +313,8 @@ const command = {
313
313
  pipe: argv.debug,
314
314
  })
315
315
 
316
+ // ToDo: setup the formatting on CLI project properly and avoid running it on scaffolding
317
+ reporter.debug(`Running '${pkgManager} format' (prettier)`)
316
318
  await exec({
317
319
  cmd: pkgManager,
318
320
  args: npm ? ['run', 'format'] : ['format'],
@@ -320,7 +322,14 @@ const command = {
320
322
  pipe: argv.debug,
321
323
  })
322
324
 
323
- reporter.info('Done!')
325
+ reporter.info(`${chalk.greenBright('Done!')}`)
326
+
327
+ const cdCmd = name != '.' ? `cd ${name} && ` : ''
328
+ reporter.print(
329
+ `Run ${chalk.bold(
330
+ `${cdCmd}${pkgManager} start`
331
+ )} to launch your new DHIS2 application`
332
+ )
324
333
 
325
334
  return
326
335
  },
@@ -0,0 +1,15 @@
1
+ const getPackageManager = () => {
2
+ const userAgent = process.env.npm_config_user_agent || ''
3
+
4
+ if (userAgent.startsWith('yarn')) {
5
+ return 'yarn'
6
+ }
7
+
8
+ if (userAgent.startsWith('npm')) {
9
+ return 'npm'
10
+ }
11
+
12
+ return 'pnpm'
13
+ }
14
+
15
+ export default getPackageManager
@@ -0,0 +1,10 @@
1
+ import prettierConfig from '@dhis2/config-prettier'
2
+
3
+ /**
4
+ * @type {import("prettier").Config}
5
+ */
6
+ const config = {
7
+ ...prettierConfig,
8
+ }
9
+
10
+ export default config
@@ -0,0 +1,45 @@
1
+ This project was bootstrapped with [DHIS2 Application Platform](https://github.com/dhis2/app-platform).
2
+
3
+ ## Available Scripts
4
+
5
+ In the project directory, you can run:
6
+
7
+ ### `yarn start`
8
+
9
+ Runs the app in the development mode.<br />
10
+ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11
+
12
+ The page will reload if you make edits.<br />
13
+ You will also see any lint errors in the console.
14
+
15
+ ### `yarn test`
16
+
17
+ Launches the test runner and runs all available tests found in `/src`.<br />
18
+
19
+ See the section about [running tests](https://platform.dhis2.nu/#/scripts/test) for more information.
20
+
21
+ ### `yarn build`
22
+
23
+ Builds the app for production to the `build` folder.<br />
24
+ It correctly bundles React in production mode and optimizes the build for the best performance.
25
+
26
+ The build is minified and the filenames include the hashes.<br />
27
+ A deployable `.zip` file can be found in `build/bundle`!
28
+
29
+ See the section about [building](https://platform.dhis2.nu/#/scripts/build) for more information.
30
+
31
+ ### `yarn deploy`
32
+
33
+ Deploys the built app in the `build` folder to a running DHIS2 instance.<br />
34
+ This command will prompt you to enter a server URL as well as the username and password of a DHIS2 user with the App Management authority.<br/>
35
+ You must run `yarn build` before running `yarn deploy`.<br />
36
+
37
+ See the section about [deploying](https://platform.dhis2.nu/#/scripts/deploy) for more information.
38
+
39
+ ## Learn More
40
+
41
+ You can learn more about the platform in the [DHIS2 Application Platform Documentation](https://platform.dhis2.nu/).
42
+
43
+ You can learn more about the runtime in the [DHIS2 Application Runtime Documentation](https://runtime.dhis2.nu/).
44
+
45
+ To learn React, check out the [React documentation](https://reactjs.org/).
@@ -0,0 +1,12 @@
1
+ /** @type {import('@dhis2/cli-app-scripts').D2Config} */
2
+ const config = {
3
+ type: 'app',
4
+
5
+ entryPoints: {
6
+ app: './src/App.tsx',
7
+ },
8
+
9
+ viteConfigExtensions: './viteConfigExtensions.mts',
10
+ }
11
+
12
+ module.exports = config
@@ -0,0 +1,13 @@
1
+ import config from '@dhis2/config-eslint'
2
+ import { defineConfig } from 'eslint/config'
3
+ import { includeIgnoreFile } from '@eslint/compat'
4
+ import { fileURLToPath } from 'node:url'
5
+
6
+ const gitignorePath = fileURLToPath(new URL('.gitignore', import.meta.url))
7
+
8
+ export default defineConfig([
9
+ includeIgnoreFile(gitignorePath, 'Imported .gitignore patterns'),
10
+ {
11
+ extends: [config],
12
+ },
13
+ ])
@@ -0,0 +1,42 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: i18next-conv\n"
4
+ "MIME-Version: 1.0\n"
5
+ "Content-Type: text/plain; charset=utf-8\n"
6
+ "Content-Transfer-Encoding: 8bit\n"
7
+ "Plural-Forms: nplurals=2; plural=(n != 1)\n"
8
+ "POT-Creation-Date: 2026-01-03T10:11:58.219Z\n"
9
+ "PO-Revision-Date: 2026-01-03T10:11:58.220Z\n"
10
+
11
+ msgid "ERROR"
12
+ msgstr "ERROR"
13
+
14
+ msgid "Loading..."
15
+ msgstr "Loading..."
16
+
17
+ msgid "Hello {{name}}"
18
+ msgstr "Hello {{name}}"
19
+
20
+ msgid "Welcome to DHIS2 with TypeScript!"
21
+ msgstr "Welcome to DHIS2 with TypeScript!"
22
+
23
+ msgid "Error"
24
+ msgstr "Error"
25
+
26
+ msgid "Error loading the data elements"
27
+ msgstr "Error loading the data elements"
28
+
29
+ msgid "ID"
30
+ msgstr "ID"
31
+
32
+ msgid "Name"
33
+ msgstr "Name"
34
+
35
+ msgid "Domain"
36
+ msgstr "Domain"
37
+
38
+ msgid "Value Type"
39
+ msgstr "Value Type"
40
+
41
+ msgid "Created by"
42
+ msgstr "Created by"
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "{{template-name}}",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "license": "BSD-3-Clause",
6
+ "private": true,
7
+ "packageManager": "pnpm@10.13.1",
8
+ "scripts": {
9
+ "build": "d2-app-scripts build",
10
+ "start": "d2-app-scripts start",
11
+ "test": "d2-app-scripts test",
12
+ "deploy": "d2-app-scripts deploy",
13
+ "lint": "eslint && prettier -c .",
14
+ "format": "prettier . -w"
15
+ },
16
+ "dependencies": {
17
+ "@dhis2/app-runtime": "^3.15.1",
18
+ "@dhis2/ui": "^10.11.0",
19
+ "react": "^18.3.1",
20
+ "react-dom": "^18.3.1"
21
+ },
22
+ "devDependencies": {
23
+ "@dhis2/cli-app-scripts": "12.8.0-alpha.3",
24
+ "@dhis2/config-eslint": "^0.2.2",
25
+ "@dhis2/config-prettier": "^0.2.2",
26
+ "@eslint/compat": "^2.0.0",
27
+ "@types/jest": "^30.0.0",
28
+ "@types/react": "^19.2.7",
29
+ "@types/react-dom": "^19.2.3",
30
+ "eslint": "^9.39.2",
31
+ "prettier": "^3.7.4",
32
+ "typescript": "^5.9.3",
33
+ "vite": "^7.3.0"
34
+ }
35
+ }