create-adonisjs 2.1.0 → 2.2.0

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
 
@@ -46,8 +47,12 @@ This argument is optional and the command will prompt you to enter the directory
46
47
  If you want to use your own starter kit hosted on Github, Gitlab, or Bitbucket, you can use the `--kit` flag to define the repo URL.
47
48
 
48
49
  ```sh
50
+ # Download from GitHub
49
51
  npm init adonisjs -- --kit="github:github_user/repo"
50
52
 
53
+ # Github is the default provider, so if not specified, it will be assumed as github
54
+ npm init adonisjs -- --kit="github_user/repo"
55
+
51
56
  # Download from GitLab
52
57
  npm init adonisjs -- --kit="gitlab:user/repo"
53
58
 
@@ -81,22 +86,22 @@ We are trying to detect the package manager used by your project. However, if yo
81
86
  npm init adonisjs -- --pkg="yarn"
82
87
  ```
83
88
 
84
- ### `--auth-guard` (Default: session)
89
+ ### `--auth-guard` (Default: Triggers prompt for selection)
85
90
 
86
91
  Specify a custom auth guard to use when using the `api` stater kit. One of the following options are allowed
87
92
 
88
- - `session` (Default)
93
+ - `session`
89
94
  - `access_tokens`
90
95
 
91
96
  ```sh
92
97
  npm init adonisjs -- --kit="api" --auth-guard="access_tokens"
93
98
  ```
94
99
 
95
- ### `--db` (Default: sqlite)
100
+ ### `--db` (Default: Triggers prompt for selection)
96
101
 
97
102
  Specify the database dialect to configure with Lucid. One of the following options are allowd.
98
103
 
99
- - `sqlite` (Default)
104
+ - `sqlite`
100
105
  - `mysql`
101
106
  - `mssql`
102
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,23 +302,31 @@ 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}"`);
244
- await downloadTemplate(this.kit, { dir: this.destination, auth: this.token });
325
+ await downloadTemplate(this.kit, {
326
+ dir: this.destination,
327
+ auth: this.token,
328
+ registry: false,
329
+ });
245
330
  await this.#removeLockFile();
246
331
  return `Downloaded "${this.kit}"`;
247
332
  })
@@ -315,6 +400,25 @@ export class CreateNewApp extends BaseCommand {
315
400
  }
316
401
  return `Unable to configure "@adonisjs/auth"`;
317
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
+ }
318
422
  });
319
423
  await tasks.run();
320
424
  if (tasks.getState() === 'succeeded') {
@@ -360,15 +464,23 @@ __decorate([
360
464
  __decorate([
361
465
  flags.string({
362
466
  description: 'Define the database dialect to use with Lucid',
363
- default: 'sqlite',
364
467
  })
365
468
  ], CreateNewApp.prototype, "db", void 0);
366
469
  __decorate([
367
470
  flags.string({
368
471
  description: 'Define the authentication guard for the Auth package',
369
- default: 'session',
370
472
  })
371
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);
372
484
  __decorate([
373
485
  flags.boolean({
374
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.0",
4
+ "version": "2.2.0",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
7
7
  "files": [