@dhis2/create-app 5.2.0-alpha.14 → 5.2.0-alpha.19

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.
package/README.md CHANGED
@@ -1,4 +1,23 @@
1
- # create-app
1
+ # @dhis2/create-app
2
2
 
3
- > This package is part of the [@dhis2/cli](https://github.com/dhis2/cli)
4
- > commandline interface.
3
+ This package publishes a package that follows the convention of [npm create](https://docs.npmjs.com/cli/v11/commands/npm-init#synopsis).
4
+
5
+ This allows users to create a new DHIS2 web application by running the command:
6
+
7
+ ```sh
8
+ # with pnpm
9
+ pnpm create @dhis2/app project-name --yes
10
+ #
11
+ ```
12
+
13
+ ```sh
14
+ # with npm
15
+ npm create @dhis2/app -- --yes
16
+ # or npx @dhis2/create-app --yes
17
+ ```
18
+
19
+ By passing `--yes` argument, this will create a new DHIS2 web application using the default options without prompting (using `pnpm` as a package manager, and `TypeScript` as the language).
20
+
21
+ If you omit the `--yes` argument `pnpm create @dhis2/app project-name` then you will be prompted and guided through a wizard to choose your options.
22
+
23
+ You can run the commands in `debug` mode to get more verbose logs by passing the `--debug` option (`pnpm create @dhis2/app project-name --debug`).
package/bin/d2-create ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ const { makeEntryPoint } = require('@dhis2/cli-helpers-engine')
3
+
4
+ const command = require(`..`)
5
+
6
+ makeEntryPoint(command)
package/package.json CHANGED
@@ -1,19 +1,23 @@
1
1
  {
2
2
  "name": "@dhis2/create-app",
3
- "version": "5.2.0-alpha.14",
4
- "description": "D2 frontend application bootstrapping inspired by create-react-app",
5
- "main": "index.js",
6
- "repository": "https://github.com/dhis2/cli",
7
- "author": "Austin McGee <austin@dhis2.org>",
8
- "license": "BSD-3-Clause",
9
- "dependencies": {
10
- "@dhis2/cli-create": "5.2.0-alpha.14",
11
- "@dhis2/cli-helpers-engine": "^3.2.1"
3
+ "version": "5.2.0-alpha.19",
4
+ "description": "",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "d2-create": "bin/d2-create"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
12
11
  },
13
- "bin": "./bin/d2-create-app",
14
- "engines": {
15
- "node": ">=12"
12
+ "dependencies": {
13
+ "@dhis2/cli-app-scripts": "alpha",
14
+ "@dhis2/cli-helpers-engine": "^3.2.2",
15
+ "@inquirer/prompts": "^7.8.4"
16
16
  },
17
+ "private": false,
18
+ "keywords": [],
19
+ "author": "",
20
+ "license": "ISC",
17
21
  "publishConfig": {
18
22
  "access": "public"
19
23
  }
package/src/index.js ADDED
@@ -0,0 +1,104 @@
1
+ const initCommand = require('@dhis2/cli-app-scripts/init')
2
+ const { reporter, chalk } = require('@dhis2/cli-helpers-engine')
3
+ const { input, select } = require('@inquirer/prompts')
4
+
5
+ process.on('uncaughtException', (error) => {
6
+ if (error instanceof Error && error.name === 'ExitPromptError') {
7
+ console.log('👋 until next time!')
8
+ } else {
9
+ // Rethrow unknown errors
10
+ throw error
11
+ }
12
+ })
13
+
14
+ const commandHandler = {
15
+ command: '*', // default command
16
+ description: 'Initialize a new DHIS2 web application',
17
+ builder: {
18
+ yes: {
19
+ description:
20
+ 'Skips interactive setup questions, accepting default options to create the new app (TypeScript, pnpm)',
21
+ type: 'boolean',
22
+ default: false,
23
+ },
24
+ },
25
+ }
26
+
27
+ const command = {
28
+ command: '[app]',
29
+ builder: (yargs) => {
30
+ yargs.command(commandHandler)
31
+ },
32
+ handler: async (argv) => {
33
+ let name = argv._[0] || argv.name
34
+
35
+ reporter.debug(
36
+ `running "npm create @dhis2/app" (or npx) command which is an alias to "d2 app scripts init"`
37
+ )
38
+ const useDefauls = argv.yes
39
+
40
+ if (!name) {
41
+ name = await input({
42
+ type: 'input',
43
+ name: 'name',
44
+ message: 'What is the name of the project?',
45
+ required: true,
46
+ })
47
+ reporter.log(`name of project: ${name}`)
48
+ }
49
+
50
+ let pnpm = true
51
+ let npm = false
52
+ let typeScript = argv.typescript || true
53
+ if (!useDefauls) {
54
+ const packageManager = await select({
55
+ message: 'Select a package manager',
56
+ default: 'pnpm',
57
+ choices: [
58
+ { name: 'npm', value: 'npm' },
59
+ { name: 'pnpm', value: 'pnpm' },
60
+ { name: 'yarn 1 (legacy)', value: 'yarn' },
61
+ ],
62
+ })
63
+
64
+ pnpm = packageManager === 'pnpm'
65
+ npm = packageManager === 'npm'
66
+
67
+ const template = await select({
68
+ message: 'Select a template',
69
+ default: 'ts',
70
+ choices: [
71
+ { name: 'JavaScript', value: 'js' },
72
+ { name: 'TypeScript', value: 'ts' },
73
+ {
74
+ name: 'Custom (coming soon)',
75
+ disabled: true,
76
+ value: 'custom',
77
+ },
78
+ ],
79
+ })
80
+
81
+ typeScript = template === 'ts'
82
+ }
83
+
84
+ if (useDefauls) {
85
+ reporter.info(
86
+ chalk.greenBright(
87
+ `These default options will be used to create a new app: \n${chalk.greenBright(
88
+ '- Language: TypeScript\n- Package manager: pnpm'
89
+ )}`
90
+ )
91
+ )
92
+ }
93
+
94
+ await initCommand.handler({
95
+ ...argv,
96
+ pnpm,
97
+ npm,
98
+ typeScript,
99
+ name,
100
+ })
101
+ },
102
+ }
103
+
104
+ module.exports = command
package/bin/d2-create-app DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- const { makeEntryPoint, notifyOfUpdates } = require('@dhis2/cli-helpers-engine')
3
-
4
- const pkgJson = require('../package.json')
5
- const command = require(`..`)
6
-
7
- notifyOfUpdates(pkgJson)
8
- makeEntryPoint(command)
package/index.js DELETED
@@ -1,17 +0,0 @@
1
- const create = require('@dhis2/cli-create')
2
- const { groupGlobalOptions } = require('@dhis2/cli-helpers-engine')
3
-
4
- module.exports = {
5
- command: 'create [type]',
6
- desc: 'Create a new DHIS2 front-end app',
7
- builder: yargs => {
8
- groupGlobalOptions(yargs)
9
- yargs.option('silent')
10
- },
11
- handler: argv => {
12
- create.handler({
13
- ...argv,
14
- type: 'app',
15
- })
16
- },
17
- }