create-adonisjs 2.1.1 → 2.2.1

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
@@ -13,6 +13,7 @@ You can use between one of the following official starter kits, or bring your ow
13
13
  - `api` : AdonisJS application tailored for building HTTP APIs.
14
14
  - `web` : AdonisJS application tailored for building server-side rendered applications.
15
15
  - `slim` : Smallest possible AdonisJS application. Still way more powerful and batteries included than a express application.
16
+ - `inertia`: AdonisJS application tailored for building applications using InertiaJS and your favorite frontend framework (Vue, React, Svelte, Solid).
16
17
 
17
18
  ## Usage
18
19
 
@@ -85,22 +86,22 @@ We are trying to detect the package manager used by your project. However, if yo
85
86
  npm init adonisjs -- --pkg="yarn"
86
87
  ```
87
88
 
88
- ### `--auth-guard` (Default: session)
89
+ ### `--auth-guard` (Default: Triggers prompt for selection)
89
90
 
90
91
  Specify a custom auth guard to use when using the `api` stater kit. One of the following options are allowed
91
92
 
92
- - `session` (Default)
93
+ - `session`
93
94
  - `access_tokens`
94
95
 
95
96
  ```sh
96
97
  npm init adonisjs -- --kit="api" --auth-guard="access_tokens"
97
98
  ```
98
99
 
99
- ### `--db` (Default: sqlite)
100
+ ### `--db` (Default: Triggers prompt for selection)
100
101
 
101
102
  Specify the database dialect to configure with Lucid. One of the following options are allowd.
102
103
 
103
- - `sqlite` (Default)
104
+ - `sqlite`
104
105
  - `mysql`
105
106
  - `mssql`
106
107
  - `postgres`
@@ -42,9 +42,17 @@ export declare class CreateNewApp extends BaseCommand {
42
42
  */
43
43
  db?: string;
44
44
  /**
45
- * Auth guard for auth package. Defaults to "session"
45
+ * Auth guard for auth package.
46
46
  */
47
47
  authGuard?: string;
48
+ /**
49
+ * Inertia adapter to use
50
+ */
51
+ adapter?: string;
52
+ /**
53
+ * Inertia adapter to use
54
+ */
55
+ ssr?: boolean;
48
56
  /**
49
57
  * Execute tasks in verbose mode. Defaults to false.
50
58
  */
@@ -23,6 +23,12 @@ import { BaseCommand, args, flags } from '@adonisjs/ace';
23
23
  import { basename, isAbsolute, join, relative } from 'node:path';
24
24
  import { copyFile, readFile, unlink, writeFile } from 'node:fs/promises';
25
25
  import { templates } from '../src/templates.js';
26
+ import { databases } from '../src/databases.js';
27
+ import { authGuards } from '../src/auth_guards.js';
28
+ import { adapters } from '../src/inertia_adapters.js';
29
+ const API_STARTER_KIT = 'github:adonisjs/api-starter-kit';
30
+ const WEB_STARTER_KIT = 'github:adonisjs/web-starter-kit';
31
+ const INERTIA_STARTER_KIT = 'github:adonisjs/inertia-starter-kit';
26
32
  /**
27
33
  * Creates a new AdonisJS application and configures it
28
34
  */
@@ -101,6 +107,47 @@ export class CreateNewApp extends BaseCommand {
101
107
  }
102
108
  }
103
109
  }
110
+ /**
111
+ * Prompt to select a database driver
112
+ */
113
+ async #promptForDatabaseDriver() {
114
+ if (!this.db) {
115
+ /**
116
+ * Display prompt when "db" flag is not used.
117
+ */
118
+ const database = await this.prompt.choice('Select the database driver you want to use', databases);
119
+ this.db = databases.find((t) => t.name === database).alias;
120
+ }
121
+ }
122
+ /**
123
+ * Prompt to select a auth guard
124
+ */
125
+ async #promptForAuthGuard() {
126
+ if (!this.authGuard) {
127
+ /**
128
+ * Display prompt when "authGuard" flag is not used.
129
+ */
130
+ const guard = await this.prompt.choice('Select the authentication guard you want to use', authGuards);
131
+ this.authGuard = authGuards.find((t) => t.name === guard).alias;
132
+ }
133
+ }
134
+ /**
135
+ * Prompt to select the Inertia adapter
136
+ */
137
+ async #promptForInertiaAdapter() {
138
+ if (!this.adapter) {
139
+ const adapter = await this.prompt.choice('Select the Inertia frontend adapter you want to use', adapters);
140
+ this.adapter = adapters.find((t) => t.name === adapter).alias;
141
+ }
142
+ }
143
+ /**
144
+ * Prompt to select the Inertia adapter
145
+ */
146
+ async #promptForInertiaSsr() {
147
+ if (this.ssr === undefined) {
148
+ this.ssr = await this.prompt.confirm('Do you want to setup server-side rendering with Inertia?');
149
+ }
150
+ }
104
151
  /**
105
152
  * Prompt to check if we should install dependencies?
106
153
  */
@@ -108,6 +155,7 @@ export class CreateNewApp extends BaseCommand {
108
155
  if (this.install === undefined) {
109
156
  this.install = await this.prompt.confirm(`Do you want us to install dependencies using "${this.packageManager}"?`, {
110
157
  default: true,
158
+ hint: "(If not, you'll need to configure guards and database manually)",
111
159
  });
112
160
  }
113
161
  }
@@ -192,7 +240,7 @@ export class CreateNewApp extends BaseCommand {
192
240
  * guard. This needs to be done, since the api starter kit does
193
241
  * not install the session package by default.
194
242
  */
195
- if (this.authGuard === 'session' && this.kit === 'github:adonisjs/api-starter-kit') {
243
+ if (this.authGuard === 'session' && this.kit === API_STARTER_KIT) {
196
244
  await this.#configureSession();
197
245
  }
198
246
  /**
@@ -204,6 +252,25 @@ export class CreateNewApp extends BaseCommand {
204
252
  }
205
253
  await this.#runBashCommand('node', argv);
206
254
  }
255
+ /**
256
+ * Configures the Inertia package
257
+ */
258
+ async #configureInertia() {
259
+ this.adapter = this.adapter || 'vue';
260
+ const argv = [
261
+ 'ace',
262
+ 'configure',
263
+ '@adonisjs/inertia',
264
+ '--adapter',
265
+ this.adapter,
266
+ this.ssr ? '--ssr' : '--no-ssr',
267
+ this.install ? '--install' : '--no-install',
268
+ ];
269
+ if (this.verbose) {
270
+ argv.push('--verbose');
271
+ }
272
+ await this.#runBashCommand('node', argv);
273
+ }
207
274
  /**
208
275
  * Main method
209
276
  */
@@ -218,6 +285,16 @@ export class CreateNewApp extends BaseCommand {
218
285
  */
219
286
  await this.#promptForDestination();
220
287
  await this.#promptForStarterKit();
288
+ if (this.kit === WEB_STARTER_KIT ||
289
+ this.kit === API_STARTER_KIT ||
290
+ this.kit === INERTIA_STARTER_KIT) {
291
+ await this.#promptForAuthGuard();
292
+ await this.#promptForDatabaseDriver();
293
+ }
294
+ if (this.kit === INERTIA_STARTER_KIT) {
295
+ await this.#promptForInertiaAdapter();
296
+ await this.#promptForInertiaSsr();
297
+ }
221
298
  await this.#promptForInstallingDeps();
222
299
  /**
223
300
  * Create tasks instance for displaying
@@ -225,19 +302,23 @@ export class CreateNewApp extends BaseCommand {
225
302
  */
226
303
  const tasks = this.ui.tasks({ verbose: this.verbose === true });
227
304
  /**
228
- * Configure lucid when using web or api starter kits
305
+ * Configure lucid when using our own starter kits
229
306
  * and installing dependencies
230
307
  */
231
- const configureLucid = (this.kit === 'github:adonisjs/web-starter-kit' ||
232
- this.kit === 'github:adonisjs/api-starter-kit') &&
308
+ const configureLucid = [WEB_STARTER_KIT, API_STARTER_KIT, INERTIA_STARTER_KIT].includes(this.kit || '') &&
309
+ this.db !== undefined &&
233
310
  this.install !== false;
234
311
  /**
235
- * Configure auth when using web or api starter kits
312
+ * Configure auth when using our own starter kits
236
313
  * and installing dependencies
237
314
  */
238
- const configureAuth = (this.kit === 'github:adonisjs/web-starter-kit' ||
239
- this.kit === 'github:adonisjs/api-starter-kit') &&
315
+ const configureAuth = [WEB_STARTER_KIT, API_STARTER_KIT, INERTIA_STARTER_KIT].includes(this.kit || '') &&
316
+ this.authGuard !== undefined &&
240
317
  this.install !== false;
318
+ /**
319
+ * Configure inertia when using our inertia starter kit
320
+ */
321
+ const configureInertia = this.kit === INERTIA_STARTER_KIT && this.db !== undefined && this.install !== false;
241
322
  tasks
242
323
  .add('Download starter kit', async (task) => {
243
324
  task.update(`Downloading "${this.kit}"`);
@@ -319,6 +400,25 @@ export class CreateNewApp extends BaseCommand {
319
400
  }
320
401
  return `Unable to configure "@adonisjs/auth"`;
321
402
  }
403
+ })
404
+ .addIf(configureInertia, 'Configure Inertia', async (task) => {
405
+ const spinner = this.logger.await('configuring @adonisjs/inertia', {
406
+ silent: this.verbose,
407
+ });
408
+ spinner.tap((line) => task.update(line));
409
+ spinner.start();
410
+ try {
411
+ await this.#configureInertia();
412
+ spinner.stop();
413
+ return 'Inertia configured';
414
+ }
415
+ catch (error) {
416
+ spinner.stop();
417
+ if (this.verbose) {
418
+ this.logger.fatal(error);
419
+ }
420
+ return `Unable to configure "@adonisjs/inertia"`;
421
+ }
322
422
  });
323
423
  await tasks.run();
324
424
  if (tasks.getState() === 'succeeded') {
@@ -364,15 +464,23 @@ __decorate([
364
464
  __decorate([
365
465
  flags.string({
366
466
  description: 'Define the database dialect to use with Lucid',
367
- default: 'sqlite',
368
467
  })
369
468
  ], CreateNewApp.prototype, "db", void 0);
370
469
  __decorate([
371
470
  flags.string({
372
471
  description: 'Define the authentication guard for the Auth package',
373
- default: 'session',
374
472
  })
375
473
  ], CreateNewApp.prototype, "authGuard", void 0);
474
+ __decorate([
475
+ flags.string({
476
+ description: 'Define the Inertia frontend adapter ( if using Inertia starter kit )',
477
+ })
478
+ ], CreateNewApp.prototype, "adapter", void 0);
479
+ __decorate([
480
+ flags.boolean({
481
+ description: 'Define if SSR is needed ( if using Inertia starter kit )',
482
+ })
483
+ ], CreateNewApp.prototype, "ssr", void 0);
376
484
  __decorate([
377
485
  flags.boolean({
378
486
  description: 'Execute tasks in verbose mode',
@@ -0,0 +1,12 @@
1
+ /**
2
+ * List of first party authentication guards
3
+ */
4
+ export declare const authGuards: ({
5
+ name: string;
6
+ alias: string;
7
+ hint: string;
8
+ } | {
9
+ name: string;
10
+ alias: undefined;
11
+ hint: string;
12
+ })[];
@@ -0,0 +1,28 @@
1
+ /*
2
+ * create-adonisjs
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ /**
10
+ * List of first party authentication guards
11
+ */
12
+ export const authGuards = [
13
+ {
14
+ name: 'Session',
15
+ alias: 'session',
16
+ hint: 'Authenticate users using cookies and session.',
17
+ },
18
+ {
19
+ name: 'Access Token',
20
+ alias: 'access_tokens',
21
+ hint: 'Authenticate clients using tokens.',
22
+ },
23
+ {
24
+ name: 'Skip',
25
+ alias: undefined,
26
+ hint: 'I want to configures guards by myself.',
27
+ },
28
+ ];
@@ -0,0 +1,12 @@
1
+ /**
2
+ * List of first party databases (lucid)
3
+ */
4
+ export declare const databases: ({
5
+ name: string;
6
+ alias: string;
7
+ hint?: undefined;
8
+ } | {
9
+ name: string;
10
+ hint: string;
11
+ alias: undefined;
12
+ })[];
@@ -0,0 +1,34 @@
1
+ /*
2
+ * create-adonisjs
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ /**
10
+ * List of first party databases (lucid)
11
+ */
12
+ export const databases = [
13
+ {
14
+ name: 'SQLite',
15
+ alias: 'sqlite',
16
+ },
17
+ {
18
+ name: 'MySQL / MariaDB',
19
+ alias: 'mysql',
20
+ },
21
+ {
22
+ name: 'PostgreSQL',
23
+ alias: 'postgres',
24
+ },
25
+ {
26
+ name: 'Microsoft SQL Server',
27
+ alias: 'mssql',
28
+ },
29
+ {
30
+ name: 'Skip',
31
+ hint: 'I want to configures the Lucid package by myself.',
32
+ alias: undefined,
33
+ },
34
+ ];
@@ -0,0 +1,12 @@
1
+ /**
2
+ * List of adapters for configuring Inertia
3
+ */
4
+ export declare const adapters: ({
5
+ name: string;
6
+ alias: string;
7
+ hint?: undefined;
8
+ } | {
9
+ name: string;
10
+ hint: string;
11
+ alias: undefined;
12
+ })[];
@@ -0,0 +1,34 @@
1
+ /*
2
+ * create-adonisjs
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ /**
10
+ * List of adapters for configuring Inertia
11
+ */
12
+ export const adapters = [
13
+ {
14
+ name: 'Vue 3',
15
+ alias: 'vue',
16
+ },
17
+ {
18
+ name: 'React',
19
+ alias: 'react',
20
+ },
21
+ {
22
+ name: 'Svelte',
23
+ alias: 'svelte',
24
+ },
25
+ {
26
+ name: 'Solid.js',
27
+ alias: 'solid',
28
+ },
29
+ {
30
+ name: 'Skip',
31
+ hint: 'I want to configure Inertia by myself.',
32
+ alias: undefined,
33
+ },
34
+ ];
@@ -28,4 +28,10 @@ export const templates = [
28
28
  hint: 'AdonisJS app tailored for creating JSON APIs',
29
29
  source: 'github:adonisjs/api-starter-kit',
30
30
  },
31
+ {
32
+ name: 'Inertia Starter Kit',
33
+ alias: 'inertia',
34
+ hint: 'AdonisJS app with Inertia.JS and your favorite frontend framework',
35
+ source: 'github:adonisjs/inertia-starter-kit',
36
+ },
31
37
  ];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-adonisjs",
3
3
  "description": "Scaffold new AdonisJS applications using starter kits",
4
- "version": "2.1.1",
4
+ "version": "2.2.1",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
7
7
  "files": [
@@ -30,35 +30,35 @@
30
30
  "test": "c8 npm run quick:test",
31
31
  "prebuild": "npm run lint && npm run clean",
32
32
  "build": "tsc",
33
- "release": "np",
33
+ "release": "release-it",
34
34
  "version": "npm run build",
35
35
  "prepublishOnly": "npm run build"
36
36
  },
37
37
  "devDependencies": {
38
- "@adonisjs/eslint-config": "^1.2.1",
39
- "@adonisjs/prettier-config": "^1.2.1",
40
- "@adonisjs/tsconfig": "^1.2.1",
41
- "@japa/assert": "^2.1.0",
42
- "@japa/file-system": "^2.2.0",
43
- "@japa/runner": "^3.1.1",
44
- "@swc/core": "^1.3.104",
45
- "@types/gradient-string": "^1.1.5",
46
- "@types/node": "^20.11.5",
38
+ "@adonisjs/eslint-config": "^1.3.0",
39
+ "@adonisjs/prettier-config": "^1.3.0",
40
+ "@adonisjs/tsconfig": "^1.3.0",
41
+ "@japa/assert": "^3.0.0",
42
+ "@japa/file-system": "^2.3.0",
43
+ "@japa/runner": "^3.1.4",
44
+ "@swc/core": "^1.4.16",
45
+ "@types/gradient-string": "^1.1.6",
46
+ "@types/node": "^20.12.7",
47
47
  "@types/which-pm-runs": "^1.0.2",
48
48
  "c8": "^9.1.0",
49
49
  "copyfiles": "^2.4.1",
50
50
  "del-cli": "^5.0.0",
51
51
  "eslint": "^8.56.0",
52
- "np": "^9.2.0",
53
- "prettier": "^3.2.4",
52
+ "prettier": "^3.2.5",
53
+ "release-it": "^17.2.0",
54
54
  "ts-node": "^10.9.2",
55
- "typescript": "^5.3.3"
55
+ "typescript": "^5.4.5"
56
56
  },
57
57
  "dependencies": {
58
58
  "@adonisjs/ace": "^13.0.0",
59
- "@antfu/install-pkg": "^0.3.1",
59
+ "@antfu/install-pkg": "^0.3.2",
60
60
  "execa": "^8.0.1",
61
- "giget": "^1.2.1",
61
+ "giget": "^1.2.3",
62
62
  "gradient-string": "^2.0.2",
63
63
  "which-pm-runs": "^1.1.0"
64
64
  },
@@ -87,12 +87,6 @@
87
87
  "access": "public",
88
88
  "tag": "latest"
89
89
  },
90
- "np": {
91
- "message": "chore(release): %s",
92
- "tag": "latest",
93
- "branch": "main",
94
- "anyBranch": false
95
- },
96
90
  "c8": {
97
91
  "reporter": [
98
92
  "text",
@@ -103,5 +97,22 @@
103
97
  "tmp/**",
104
98
  "bin/**"
105
99
  ]
100
+ },
101
+ "release-it": {
102
+ "git": {
103
+ "commitMessage": "chore(release): ${version}",
104
+ "tagAnnotation": "v${version}",
105
+ "tagName": "v${version}"
106
+ },
107
+ "hooks": {
108
+ "before:init": [
109
+ "npm test"
110
+ ]
111
+ },
112
+ "github": {
113
+ "release": true,
114
+ "releaseName": "v${version}",
115
+ "web": true
116
+ }
106
117
  }
107
118
  }