create-adonisjs 1.1.0 → 1.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
@@ -1,14 +1,13 @@
1
1
  # create-adonisjs
2
-
3
- ![image](https://github.com/adonisjs/create-adonisjs/assets/8337858/97c07232-dd6b-415b-88e7-571941da21e3)
4
-
2
+ Scaffold a new AdonisJS application using starter kits
5
3
 
6
4
  <br />
7
5
 
8
6
  [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![snyk-image]][snyk-url]
9
7
 
10
- ## Introduction
11
- Scaffolding tool for AdonisJS applications. You can choose between 3 different starter kits :
8
+ ## Starter kits
9
+
10
+ You can use between one of the following official starter kits, or bring your own using the `--kit` flag.
12
11
 
13
12
  - `api` : AdonisJS application tailored for building HTTP APIs.
14
13
  - `web` : AdonisJS application tailored for building server-side rendered applications.
@@ -38,11 +37,12 @@ npm init adonisjs my-app
38
37
  ```
39
38
 
40
39
  This argument is optional and the command will prompt you to enter the directory name if not provided.
41
- Note that the directory must be empty otherwise the command will fail.
40
+
41
+ > **Note** - The directory must be empty otherwise the command will fail.
42
42
 
43
43
  ### `--kit`
44
44
 
45
- If you have your own starter kit hosted on Gitlab/Github/Bitbucket, then you can pass it as follows:
45
+ 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.
46
46
 
47
47
  ```sh
48
48
  npm init adonisjs -- -K="github:github_user/repo"
@@ -72,34 +72,41 @@ If you are using a custom starter kit hosted on a private repository, then you c
72
72
  npm init adonisjs -- -K="github:github_user/repo" -t="github_token"
73
73
  ```
74
74
 
75
+ ### `--pkg`
76
+
77
+ We are trying to detect the package manager used by your project. However, if you want to force a specific package manager, then you can pass it as follows:
78
+
79
+ ```sh
80
+ npm init adonisjs -- --pkg="yarn"
81
+ ```
82
+
75
83
  ### Other options
76
84
 
77
- | Option | Description |
78
- |--------|-------------|
79
- | `--skip-install` | Skip installing dependencies. |
85
+ | Option | Description |
86
+ | ----------------- | --------------------------------- |
87
+ | `--skip-install` | Skip installing dependencies. |
80
88
  | `--skip-git-init` | Skip initializing git repository. |
81
89
 
82
90
  ## Contributing
91
+
83
92
  One of the primary goals of AdonisJS is to have a vibrant community of users and contributors who believes in the principles of the framework.
84
93
 
85
94
  We encourage you to read the [contribution guide](https://github.com/adonisjs/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.
86
95
 
87
96
  ## Code of Conduct
97
+
88
98
  In order to ensure that the AdonisJS community is welcoming to all, please review and abide by the [Code of Conduct](https://github.com/adonisjs/.github/blob/main/docs/CODE_OF_CONDUCT.md).
89
99
 
90
100
  ## License
101
+
91
102
  create-adonisjs is open-sourced software licensed under the [MIT license](LICENSE.md).
92
103
 
93
104
  [gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/create-adonisjs/test.yml?style=for-the-badge
94
- [gh-workflow-url]: https://github.com/adonisjs/create-adonisjs/actions/workflows/test.yml "Github action"
95
-
105
+ [gh-workflow-url]: https://github.com/adonisjs/create-adonisjs/actions/workflows/test.yml 'Github action'
96
106
  [npm-image]: https://img.shields.io/npm/v/@adonisjs/create-adonisjs/latest.svg?style=for-the-badge&logo=npm
97
- [npm-url]: https://www.npmjs.com/package/@adonisjs/create-adonisjs/v/latest "npm"
98
-
107
+ [npm-url]: https://www.npmjs.com/package/@adonisjs/create-adonisjs/v/latest 'npm'
99
108
  [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
100
-
101
109
  [license-url]: LICENSE.md
102
110
  [license-image]: https://img.shields.io/github/license/adonisjs/create-adonisjs?style=for-the-badge
103
-
104
111
  [snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/create-adonisjs?label=Snyk%20Vulnerabilities&style=for-the-badge
105
- [snyk-url]: https://snyk.io/test/github/adonisjs/create-adonisjs?targetFile=package.json "snyk"
112
+ [snyk-url]: https://snyk.io/test/github/adonisjs/create-adonisjs?targetFile=package.json 'snyk'
@@ -1,5 +1,5 @@
1
1
  import { BaseCommand } from '@adonisjs/ace';
2
- export declare class InstallAdonis extends BaseCommand {
2
+ export declare class CreateNewApp extends BaseCommand {
3
3
  #private;
4
4
  static commandName: string;
5
5
  static description: string;
@@ -17,11 +17,11 @@ export declare class InstallAdonis extends BaseCommand {
17
17
  */
18
18
  kit?: string;
19
19
  /**
20
- * Authentication token to download private templates kit
20
+ * Authentication token to download private templates
21
21
  */
22
22
  token?: string;
23
23
  /**
24
- * Skip dependencies installation
24
+ * Skip packages installation
25
25
  */
26
26
  skipInstall: boolean;
27
27
  /**
@@ -12,61 +12,56 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
12
12
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
13
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14
14
  };
15
- import { copyFile, readFile, writeFile } from 'node:fs/promises';
16
- import { existsSync } from 'node:fs';
17
- import { join, relative } from 'node:path';
15
+ import { execa } from 'execa';
18
16
  import { cwd } from 'node:process';
19
- import { BaseCommand, args, flags } from '@adonisjs/ace';
20
- import detectPackageManager from 'which-pm-runs';
21
- import { downloadTemplate } from 'giget';
17
+ import { existsSync } from 'node:fs';
22
18
  import gradient from 'gradient-string';
23
- import { execa } from 'execa';
24
- import { templates } from './templates.js';
25
- export class InstallAdonis extends BaseCommand {
19
+ import { downloadTemplate } from 'giget';
20
+ import { isAbsolute, join, relative } from 'node:path';
21
+ import detectPackageManager from 'which-pm-runs';
22
+ import { BaseCommand, args, flags } from '@adonisjs/ace';
23
+ import { copyFile, readFile, unlink, writeFile } from 'node:fs/promises';
24
+ import { templates } from '../src/templates.js';
25
+ export class CreateNewApp extends BaseCommand {
26
26
  static commandName = 'create-adonisjs';
27
- static description = 'Install AdonisJS';
27
+ static description = 'Create a new AdonisJS application using a starter kit';
28
28
  /**
29
29
  * Whether or not dependencies were installed
30
30
  */
31
- #hasInstalledDependencies;
31
+ #shouldInstallDependencies;
32
32
  /**
33
33
  * Print the title
34
34
  */
35
35
  #printTitle() {
36
- const adonisGradient = gradient([
37
- { color: '#5A45FF', pos: 0 },
38
- { color: '#7c6dff', pos: 0.2 },
39
- ]);
40
36
  const title = Buffer.from('CiAgICBfX18gICAgICAgX18gICAgICAgICAgICBfICAgICAgICAgIF8gICAgIAogICAvICAgfCBfX19fLyAvX19fICBfX19fICAoXylfX19fICAgIChfKV9fX18KICAvIC98IHwvIF9fICAvIF9fIFwvIF9fIFwvIC8gX19fLyAgIC8gLyBfX18vCiAvIF9fXyAvIC9fLyAvIC9fLyAvIC8gLyAvIChfXyAgKSAgIC8gKF9fICApIAovXy8gIHxfXF9fLF8vXF9fX18vXy8gL18vXy9fX19fKF8pXy8gL19fX18vICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvX19fLyAgICAgICAg==', 'base64').toString();
41
37
  this.logger.log('');
42
- this.logger.log(`${adonisGradient.multiline(title)}`);
43
- this.logger.log('');
44
- this.logger.log(this.colors.italic(` A fully-featured web\n framework for Node.js`));
45
- this.logger.log('');
38
+ this.logger.log(`${gradient.mind(title)}`);
46
39
  this.logger.log('');
47
40
  }
48
41
  /**
49
42
  * Prompt for the destination directory
50
43
  */
51
- async #promptDestination() {
52
- if (this.destination)
53
- return;
54
- this.destination = await this.prompt.ask('Where should we create the project?', {
55
- default: `./` + relative(cwd(), './my-adonisjs-app'),
56
- });
44
+ async #setDestination() {
45
+ if (!this.destination) {
46
+ this.destination = await this.prompt.ask('Where should we create the project?', {
47
+ default: `./` + relative(cwd(), './my-adonisjs-app'),
48
+ result(dir) {
49
+ return isAbsolute(dir) ? dir : join(cwd(), dir);
50
+ },
51
+ });
52
+ }
57
53
  }
58
54
  /**
59
55
  * Prompt and download the selected template
60
56
  */
61
57
  async #downloadTemplate() {
62
- let templateSource = this.kit;
63
- if (!templateSource) {
64
- const template = await this.prompt.choice('Which template do you want to use?', templates);
65
- templateSource = templates.find((t) => t.name === template).source;
58
+ if (!this.kit) {
59
+ const template = await this.prompt.choice('Select the template you want to use', templates);
60
+ this.kit = templates.find((t) => t.name === template).source;
66
61
  }
67
- const spinner = this.logger.await(`Downloading ${templateSource} template`).start();
62
+ const spinner = this.logger.await(`Downloading ${this.kit} template`).start();
68
63
  try {
69
- await downloadTemplate(templateSource, { dir: this.destination, auth: this.token });
64
+ await downloadTemplate(this.kit, { dir: this.destination, auth: this.token });
70
65
  spinner.update('Template downloaded successfully').stop();
71
66
  }
72
67
  catch (error) {
@@ -78,11 +73,13 @@ export class InstallAdonis extends BaseCommand {
78
73
  * Install dependencies with the detected package manager
79
74
  */
80
75
  async #installDependencies() {
81
- if (this.skipInstall)
76
+ if (this.skipInstall) {
82
77
  return;
83
- this.#hasInstalledDependencies = await this.prompt.confirm('Do you want to install dependencies?', { hint: this.packageManager + ' will be used', default: true });
84
- if (!this.#hasInstalledDependencies)
78
+ }
79
+ this.#shouldInstallDependencies = await this.prompt.confirm('Do you want to install dependencies?', { hint: this.packageManager + ' will be used', default: true });
80
+ if (!this.#shouldInstallDependencies) {
85
81
  return;
82
+ }
86
83
  const spinner = this.logger
87
84
  .await(`Installing dependencies using ${this.packageManager}`)
88
85
  .start();
@@ -100,13 +97,15 @@ export class InstallAdonis extends BaseCommand {
100
97
  * Init git repository inside the destination directory
101
98
  */
102
99
  async #initGitRepo() {
103
- if (this.skipGitInit)
100
+ if (this.skipGitInit) {
104
101
  return;
102
+ }
105
103
  const shouldInit = await this.prompt.confirm('Do you want to initialize a git repository?', {
106
104
  default: true,
107
105
  });
108
- if (!shouldInit)
106
+ if (!shouldInit) {
109
107
  return;
108
+ }
110
109
  try {
111
110
  await execa('git', ['init'], { cwd: this.destination });
112
111
  this.logger.success('Git repository initialized successfully');
@@ -116,22 +115,6 @@ export class InstallAdonis extends BaseCommand {
116
115
  throw error;
117
116
  }
118
117
  }
119
- /**
120
- * Print the success message
121
- */
122
- #printSuccessMessage() {
123
- this.logger.log('');
124
- this.ui
125
- .sticker()
126
- .heading('Your AdonisJS project was created successfully !')
127
- .add(`1. ${this.colors.magenta('cd ' + relative(cwd(), this.destination))}`)
128
- .add(`2. ${this.colors.magenta(`${this.packageManager} run dev`)}`)
129
- .add(`3. ${this.colors.magenta('Visit http://localhost:3333')}`)
130
- .add('')
131
- .add(`Have any questions?`)
132
- .add(`Join our Discord server: ${this.colors.magenta('https://discord.gg/vDcEjq6')}`)
133
- .render();
134
- }
135
118
  /**
136
119
  * Replace the package.json name with the destination directory name
137
120
  */
@@ -147,8 +130,9 @@ export class InstallAdonis extends BaseCommand {
147
130
  async #copyEnvExampleFile() {
148
131
  const envExamplePath = join(this.destination, '.env.example');
149
132
  const hasEnvExample = existsSync(envExamplePath);
150
- if (!hasEnvExample)
133
+ if (!hasEnvExample) {
151
134
  return;
135
+ }
152
136
  const envPath = join(this.destination, '.env');
153
137
  await copyFile(envExamplePath, envPath);
154
138
  }
@@ -156,8 +140,9 @@ export class InstallAdonis extends BaseCommand {
156
140
  * Generate a fresh app key
157
141
  */
158
142
  async #generateFreshAppKey() {
159
- if (!this.#hasInstalledDependencies)
143
+ if (!this.#shouldInstallDependencies) {
160
144
  return;
145
+ }
161
146
  try {
162
147
  await execa('node', ['ace', 'generate:key'], { cwd: this.destination });
163
148
  }
@@ -165,6 +150,31 @@ export class InstallAdonis extends BaseCommand {
165
150
  this.logger.warning('Failed to generate app key : ' + error.stderr);
166
151
  }
167
152
  }
153
+ /**
154
+ * Optionally removes readme file
155
+ */
156
+ async #removeReadmeFile() {
157
+ try {
158
+ await unlink(join(this.destination, 'README.md'));
159
+ }
160
+ catch { }
161
+ }
162
+ /**
163
+ * Print the success message
164
+ */
165
+ #printSuccessMessage() {
166
+ this.logger.log('');
167
+ this.ui
168
+ .instructions()
169
+ .heading('Your AdonisJS project has been created successfully!')
170
+ .add(this.colors.cyan('cd ' + relative(cwd(), this.destination)))
171
+ .add(this.colors.cyan(`${this.packageManager} run dev`))
172
+ .add(this.colors.cyan('Open http://localhost:3333'))
173
+ .add('')
174
+ .add(`Have any questions?`)
175
+ .add(`Join our Discord server - ${this.colors.yellow('https://discord.gg/vDcEjq6')}`)
176
+ .render();
177
+ }
168
178
  /**
169
179
  * Execute the `run` method and catch errors
170
180
  */
@@ -186,31 +196,36 @@ export class InstallAdonis extends BaseCommand {
186
196
  this.packageManager = detectPackageManager()?.name || 'npm';
187
197
  }
188
198
  this.#printTitle();
189
- await this.#promptDestination();
199
+ await this.#setDestination();
190
200
  await this.#downloadTemplate();
191
201
  await this.#installDependencies();
192
202
  await this.#initGitRepo();
193
203
  await this.#replacePackageJsonName();
194
204
  await this.#copyEnvExampleFile();
195
205
  await this.#generateFreshAppKey();
206
+ await this.#removeReadmeFile();
196
207
  this.#printSuccessMessage();
197
208
  }
198
209
  }
199
210
  __decorate([
200
211
  args.string({ description: 'Destination directory', name: 'destination', required: false })
201
- ], InstallAdonis.prototype, "destination", void 0);
212
+ ], CreateNewApp.prototype, "destination", void 0);
202
213
  __decorate([
203
- flags.string({ description: 'Starter kit to use', name: 'kit', alias: 'K' })
204
- ], InstallAdonis.prototype, "kit", void 0);
214
+ flags.string({ description: 'Define path to a custom git repository', name: 'kit', alias: 'K' })
215
+ ], CreateNewApp.prototype, "kit", void 0);
205
216
  __decorate([
206
- flags.string({ description: 'Authentication token', name: 'token', alias: 't' })
207
- ], InstallAdonis.prototype, "token", void 0);
217
+ flags.string({
218
+ description: 'Pass the authentication token to download private repositories',
219
+ name: 'token',
220
+ alias: 't',
221
+ })
222
+ ], CreateNewApp.prototype, "token", void 0);
208
223
  __decorate([
209
- flags.boolean({ description: 'Skip dependencies installation', name: 'skip-install' })
210
- ], InstallAdonis.prototype, "skipInstall", void 0);
224
+ flags.boolean({ description: 'Skip packages installation', name: 'skip-install' })
225
+ ], CreateNewApp.prototype, "skipInstall", void 0);
211
226
  __decorate([
212
227
  flags.boolean({ description: 'Skip git initialization', name: 'skip-git-init' })
213
- ], InstallAdonis.prototype, "skipGitInit", void 0);
228
+ ], CreateNewApp.prototype, "skipGitInit", void 0);
214
229
  __decorate([
215
- flags.string({ description: 'Force a package manager to be used', name: 'package-manager' })
216
- ], InstallAdonis.prototype, "packageManager", void 0);
230
+ flags.string({ description: 'Explicitly define the package manager to npm', name: 'pkg' })
231
+ ], CreateNewApp.prototype, "packageManager", void 0);
package/build/index.js CHANGED
@@ -7,8 +7,8 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { HelpCommand, Kernel } from '@adonisjs/ace';
10
- import { InstallAdonis } from './src/install_adonis.js';
11
- Kernel.defaultCommand = InstallAdonis;
10
+ import { CreateNewApp } from './commands/main.js';
11
+ Kernel.defaultCommand = CreateNewApp;
12
12
  export const kernel = Kernel.create();
13
13
  kernel.defineFlag('help', {
14
14
  type: 'boolean',
@@ -12,17 +12,17 @@
12
12
  export const templates = [
13
13
  {
14
14
  name: 'Slim Starter Kit',
15
- hint: 'Smallest possible AdonisJS application with just the core and Japa',
15
+ hint: 'A lean AdonisJS application with just the framework core',
16
16
  source: 'github:adonisjs/slim-starter-kit',
17
17
  },
18
- {
19
- name: 'Web Starter Kit',
20
- hint: 'for building web applications',
21
- source: 'github:adonisjs/web-starter-kit',
22
- },
23
- {
24
- name: 'API Starter Kit',
25
- hint: 'for building APIs',
26
- source: 'github:adonisjs/api-starter-kit',
27
- },
18
+ // {
19
+ // name: 'Web Starter Kit',
20
+ // hint: 'Everything you need to build a server render app',
21
+ // source: 'github:adonisjs/web-starter-kit',
22
+ // },
23
+ // {
24
+ // name: 'API Starter Kit',
25
+ // hint: 'AdonisJS app tailored for creating JSON APIs',
26
+ // source: 'github:adonisjs/api-starter-kit',
27
+ // },
28
28
  ];
package/package.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "name": "create-adonisjs",
3
- "description": "Scaffolding tool to create AdonisJS 6 projects",
4
- "version": "1.1.0",
5
- "engines": {
6
- "node": ">=18.16.0"
7
- },
3
+ "description": "Scaffold new AdonisJS applications using starter kits",
4
+ "version": "1.2.0",
8
5
  "main": "build/index.js",
9
6
  "type": "module",
10
7
  "files": [
11
8
  "build/bin",
9
+ "build/commands",
12
10
  "build/src",
13
11
  "build/index.d.ts",
14
12
  "build/index.js"
@@ -19,6 +17,9 @@
19
17
  "exports": {
20
18
  ".": "./build/index.js"
21
19
  },
20
+ "engines": {
21
+ "node": ">=18.16.0"
22
+ },
22
23
  "scripts": {
23
24
  "clean": "del-cli build",
24
25
  "typecheck": "tsc --noEmit",
@@ -34,9 +35,9 @@
34
35
  "prepublishOnly": "npm run build"
35
36
  },
36
37
  "devDependencies": {
37
- "@adonisjs/eslint-config": "^1.1.7",
38
- "@adonisjs/prettier-config": "^1.1.7",
39
- "@adonisjs/tsconfig": "^1.1.7",
38
+ "@adonisjs/eslint-config": "^1.1.8",
39
+ "@adonisjs/prettier-config": "^1.1.8",
40
+ "@adonisjs/tsconfig": "^1.1.8",
40
41
  "@japa/assert": "^2.0.0-1",
41
42
  "@japa/file-system": "^2.0.0-1",
42
43
  "@japa/runner": "^3.0.0-5",
@@ -47,9 +48,9 @@
47
48
  "c8": "^8.0.0",
48
49
  "copyfiles": "^2.4.1",
49
50
  "del-cli": "^5.0.0",
50
- "eslint": "^8.44.0",
51
+ "eslint": "^8.45.0",
51
52
  "np": "^8.0.4",
52
- "prettier": "^2.8.8",
53
+ "prettier": "^3.0.0",
53
54
  "ts-node": "^10.9.1",
54
55
  "typescript": "^5.1.6"
55
56
  },
@@ -62,7 +63,10 @@
62
63
  },
63
64
  "author": "julien-r44,virk",
64
65
  "license": "MIT",
65
- "keywords": [],
66
+ "keywords": [
67
+ "adonisjs",
68
+ "create-adonisjs-app"
69
+ ],
66
70
  "eslintConfig": {
67
71
  "extends": "@adonisjs/eslint-config/package"
68
72
  },
@@ -83,7 +87,9 @@
83
87
  "html"
84
88
  ],
85
89
  "exclude": [
86
- "tests/**"
90
+ "tests/**",
91
+ "tmp/**",
92
+ "bin/**"
87
93
  ]
88
94
  }
89
95
  }