create-adonisjs 1.0.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'
package/build/bin/run.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  import { kernel } from '../index.js';
3
- kernel.handle(process.argv.slice(2)).catch(console.error);
3
+ kernel.handle(['create-adonisjs', ...process.argv.slice(2)]).catch(console.error);
@@ -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,17 +17,21 @@ 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
  /**
28
28
  * Skip git initialization
29
29
  */
30
30
  skipGitInit: boolean;
31
+ /**
32
+ * Package manager to use
33
+ */
34
+ packageManager: string;
31
35
  /**
32
36
  * Execute the `run` method and catch errors
33
37
  */
@@ -12,66 +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 {
26
- static commandName = 'install-adonisjs';
27
- static description = 'Install AdonisJS';
28
- /**
29
- * The detected package manager ( based on agent )
30
- */
31
- #detectedPkgManager;
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
+ static commandName = 'create-adonisjs';
27
+ static description = 'Create a new AdonisJS application using a starter kit';
32
28
  /**
33
29
  * Whether or not dependencies were installed
34
30
  */
35
- #hasInstalledDependencies;
31
+ #shouldInstallDependencies;
36
32
  /**
37
33
  * Print the title
38
34
  */
39
35
  #printTitle() {
40
- const adonisGradient = gradient([
41
- { color: '#5A45FF', pos: 0 },
42
- { color: '#7c6dff', pos: 0.2 },
43
- ]);
44
36
  const title = Buffer.from('CiAgICBfX18gICAgICAgX18gICAgICAgICAgICBfICAgICAgICAgIF8gICAgIAogICAvICAgfCBfX19fLyAvX19fICBfX19fICAoXylfX19fICAgIChfKV9fX18KICAvIC98IHwvIF9fICAvIF9fIFwvIF9fIFwvIC8gX19fLyAgIC8gLyBfX18vCiAvIF9fXyAvIC9fLyAvIC9fLyAvIC8gLyAvIChfXyAgKSAgIC8gKF9fICApIAovXy8gIHxfXF9fLF8vXF9fX18vXy8gL18vXy9fX19fKF8pXy8gL19fX18vICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvX19fLyAgICAgICAg==', 'base64').toString();
45
37
  this.logger.log('');
46
- this.logger.log(`${adonisGradient.multiline(title)}`);
47
- this.logger.log('');
48
- this.logger.log(this.colors.italic(` A fully-featured web\n framework for Node.js`));
49
- this.logger.log('');
38
+ this.logger.log(`${gradient.mind(title)}`);
50
39
  this.logger.log('');
51
40
  }
52
41
  /**
53
42
  * Prompt for the destination directory
54
43
  */
55
- async #promptDestination() {
56
- if (this.destination)
57
- return;
58
- this.destination = await this.prompt.ask('Where should we create the project?', {
59
- default: `./` + relative(cwd(), './my-adonisjs-app'),
60
- });
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
+ }
61
53
  }
62
54
  /**
63
55
  * Prompt and download the selected template
64
56
  */
65
57
  async #downloadTemplate() {
66
- this.logger.log('');
67
- let templateSource = this.kit;
68
- if (!templateSource) {
69
- const template = await this.prompt.choice('Which template do you want to use?', templates);
70
- 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;
71
61
  }
72
- const spinner = this.logger.await(`Downloading ${templateSource} template`).start();
62
+ const spinner = this.logger.await(`Downloading ${this.kit} template`).start();
73
63
  try {
74
- await downloadTemplate(templateSource, { dir: this.destination, auth: this.token });
64
+ await downloadTemplate(this.kit, { dir: this.destination, auth: this.token });
75
65
  spinner.update('Template downloaded successfully').stop();
76
66
  }
77
67
  catch (error) {
@@ -83,19 +73,18 @@ export class InstallAdonis extends BaseCommand {
83
73
  * Install dependencies with the detected package manager
84
74
  */
85
75
  async #installDependencies() {
86
- if (this.skipInstall)
76
+ if (this.skipInstall) {
87
77
  return;
88
- this.logger.log('');
89
- const pkgManager = this.#detectedPkgManager;
90
- this.#hasInstalledDependencies = await this.prompt.confirm('Do you want to install dependencies?', {
91
- hint: pkgManager + ' will be used',
92
- default: true,
93
- });
94
- 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) {
95
81
  return;
96
- const spinner = this.logger.await(`Installing dependencies using ${pkgManager}`).start();
82
+ }
83
+ const spinner = this.logger
84
+ .await(`Installing dependencies using ${this.packageManager}`)
85
+ .start();
97
86
  try {
98
- await execa(pkgManager, ['install'], { cwd: this.destination });
87
+ await execa(this.packageManager, ['install'], { cwd: this.destination });
99
88
  spinner.update('Dependencies installed successfully').stop();
100
89
  }
101
90
  catch (error) {
@@ -108,14 +97,15 @@ export class InstallAdonis extends BaseCommand {
108
97
  * Init git repository inside the destination directory
109
98
  */
110
99
  async #initGitRepo() {
111
- if (this.skipGitInit)
100
+ if (this.skipGitInit) {
112
101
  return;
113
- this.logger.log('');
102
+ }
114
103
  const shouldInit = await this.prompt.confirm('Do you want to initialize a git repository?', {
115
104
  default: true,
116
105
  });
117
- if (!shouldInit)
106
+ if (!shouldInit) {
118
107
  return;
108
+ }
119
109
  try {
120
110
  await execa('git', ['init'], { cwd: this.destination });
121
111
  this.logger.success('Git repository initialized successfully');
@@ -125,22 +115,6 @@ export class InstallAdonis extends BaseCommand {
125
115
  throw error;
126
116
  }
127
117
  }
128
- /**
129
- * Print the success message
130
- */
131
- #printSuccessMessage() {
132
- this.logger.log('');
133
- this.ui
134
- .sticker()
135
- .heading('Your AdonisJS project was created successfully !')
136
- .add(`1. ${this.colors.magenta('cd ' + relative(cwd(), this.destination))}`)
137
- .add(`2. ${this.colors.magenta(`${this.#detectedPkgManager} run dev`)}`)
138
- .add(`3. ${this.colors.magenta('Visit http://localhost:3333')}`)
139
- .add('')
140
- .add(`Have any questions? Join our Discord server: ${this.colors.magenta('https://discord.gg/vDcEjq6')}`)
141
- .render();
142
- this.logger.log('');
143
- }
144
118
  /**
145
119
  * Replace the package.json name with the destination directory name
146
120
  */
@@ -156,8 +130,9 @@ export class InstallAdonis extends BaseCommand {
156
130
  async #copyEnvExampleFile() {
157
131
  const envExamplePath = join(this.destination, '.env.example');
158
132
  const hasEnvExample = existsSync(envExamplePath);
159
- if (!hasEnvExample)
133
+ if (!hasEnvExample) {
160
134
  return;
135
+ }
161
136
  const envPath = join(this.destination, '.env');
162
137
  await copyFile(envExamplePath, envPath);
163
138
  }
@@ -165,8 +140,9 @@ export class InstallAdonis extends BaseCommand {
165
140
  * Generate a fresh app key
166
141
  */
167
142
  async #generateFreshAppKey() {
168
- if (!this.#hasInstalledDependencies)
143
+ if (!this.#shouldInstallDependencies) {
169
144
  return;
145
+ }
170
146
  try {
171
147
  await execa('node', ['ace', 'generate:key'], { cwd: this.destination });
172
148
  }
@@ -174,6 +150,31 @@ export class InstallAdonis extends BaseCommand {
174
150
  this.logger.warning('Failed to generate app key : ' + error.stderr);
175
151
  }
176
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
+ }
177
178
  /**
178
179
  * Execute the `run` method and catch errors
179
180
  */
@@ -191,30 +192,40 @@ export class InstallAdonis extends BaseCommand {
191
192
  * Main method
192
193
  */
193
194
  async run() {
194
- this.#detectedPkgManager = detectPackageManager()?.name || 'npm';
195
+ if (!this.packageManager) {
196
+ this.packageManager = detectPackageManager()?.name || 'npm';
197
+ }
195
198
  this.#printTitle();
196
- await this.#promptDestination();
199
+ await this.#setDestination();
197
200
  await this.#downloadTemplate();
198
201
  await this.#installDependencies();
199
202
  await this.#initGitRepo();
200
203
  await this.#replacePackageJsonName();
201
204
  await this.#copyEnvExampleFile();
202
205
  await this.#generateFreshAppKey();
206
+ await this.#removeReadmeFile();
203
207
  this.#printSuccessMessage();
204
208
  }
205
209
  }
206
210
  __decorate([
207
211
  args.string({ description: 'Destination directory', name: 'destination', required: false })
208
- ], InstallAdonis.prototype, "destination", void 0);
212
+ ], CreateNewApp.prototype, "destination", void 0);
209
213
  __decorate([
210
- flags.string({ description: 'Starter kit to use', name: 'kit', alias: 'K' })
211
- ], 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);
212
216
  __decorate([
213
- flags.string({ description: 'Authentication token', name: 'token', alias: 't' })
214
- ], 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);
215
223
  __decorate([
216
- flags.boolean({ description: 'Skip dependencies installation', name: 'skip-install' })
217
- ], InstallAdonis.prototype, "skipInstall", void 0);
224
+ flags.boolean({ description: 'Skip packages installation', name: 'skip-install' })
225
+ ], CreateNewApp.prototype, "skipInstall", void 0);
218
226
  __decorate([
219
227
  flags.boolean({ description: 'Skip git initialization', name: 'skip-git-init' })
220
- ], InstallAdonis.prototype, "skipGitInit", void 0);
228
+ ], CreateNewApp.prototype, "skipGitInit", void 0);
229
+ __decorate([
230
+ flags.string({ description: 'Explicitly define the package manager to npm', name: 'pkg' })
231
+ ], CreateNewApp.prototype, "packageManager", void 0);
package/build/index.js CHANGED
@@ -6,7 +6,16 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
- import { Kernel } from '@adonisjs/ace';
10
- import { InstallAdonis } from './src/install_adonis.js';
11
- Kernel.defaultCommand = InstallAdonis;
9
+ import { HelpCommand, Kernel } from '@adonisjs/ace';
10
+ import { CreateNewApp } from './commands/main.js';
11
+ Kernel.defaultCommand = CreateNewApp;
12
12
  export const kernel = Kernel.create();
13
+ kernel.defineFlag('help', {
14
+ type: 'boolean',
15
+ description: HelpCommand.description,
16
+ });
17
+ kernel.on('help', async (command, $kernel, parsed) => {
18
+ parsed.args.unshift(command.commandName);
19
+ await new HelpCommand($kernel, parsed, kernel.ui, kernel.prompt).exec();
20
+ return $kernel.shortcircuit();
21
+ });
@@ -11,13 +11,18 @@
11
11
  */
12
12
  export const templates = [
13
13
  {
14
- name: 'Web Starter Kit',
15
- hint: 'for building web applications',
16
- source: 'github:adonisjs/web-starter-kit',
17
- },
18
- {
19
- name: 'API Starter Kit',
20
- hint: 'for building APIs',
21
- source: 'github:adonisjs/api-starter-kit',
14
+ name: 'Slim Starter Kit',
15
+ hint: 'A lean AdonisJS application with just the framework core',
16
+ source: 'github:adonisjs/slim-starter-kit',
22
17
  },
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
+ // },
23
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.0.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,23 +35,22 @@
34
35
  "prepublishOnly": "npm run build"
35
36
  },
36
37
  "devDependencies": {
37
- "@adonisjs/core": "^6.1.5-5",
38
- "@adonisjs/eslint-config": "^1.1.7",
39
- "@adonisjs/prettier-config": "^1.1.7",
40
- "@adonisjs/tsconfig": "^1.1.7",
41
- "@japa/assert": "2.0.0-1",
42
- "@japa/file-system": "2.0.0-1",
43
- "@japa/runner": "3.0.0-3",
38
+ "@adonisjs/eslint-config": "^1.1.8",
39
+ "@adonisjs/prettier-config": "^1.1.8",
40
+ "@adonisjs/tsconfig": "^1.1.8",
41
+ "@japa/assert": "^2.0.0-1",
42
+ "@japa/file-system": "^2.0.0-1",
43
+ "@japa/runner": "^3.0.0-5",
44
44
  "@swc/core": "^1.3.68",
45
45
  "@types/gradient-string": "^1.1.2",
46
- "@types/node": "^20.3.3",
46
+ "@types/node": "^20.4.1",
47
47
  "@types/which-pm-runs": "^1.0.0",
48
48
  "c8": "^8.0.0",
49
49
  "copyfiles": "^2.4.1",
50
50
  "del-cli": "^5.0.0",
51
- "eslint": "^8.44.0",
51
+ "eslint": "^8.45.0",
52
52
  "np": "^8.0.4",
53
- "prettier": "^2.8.8",
53
+ "prettier": "^3.0.0",
54
54
  "ts-node": "^10.9.1",
55
55
  "typescript": "^5.1.6"
56
56
  },
@@ -63,7 +63,10 @@
63
63
  },
64
64
  "author": "julien-r44,virk",
65
65
  "license": "MIT",
66
- "keywords": [],
66
+ "keywords": [
67
+ "adonisjs",
68
+ "create-adonisjs-app"
69
+ ],
67
70
  "eslintConfig": {
68
71
  "extends": "@adonisjs/eslint-config/package"
69
72
  },
@@ -84,7 +87,9 @@
84
87
  "html"
85
88
  ],
86
89
  "exclude": [
87
- "tests/**"
90
+ "tests/**",
91
+ "tmp/**",
92
+ "bin/**"
88
93
  ]
89
94
  }
90
95
  }