create-adonisjs 1.0.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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ # The MIT License
2
+
3
+ Copyright (c) 2023
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # create-adonisjs
2
+
3
+ ![image](https://github.com/adonisjs/create-adonisjs/assets/8337858/97c07232-dd6b-415b-88e7-571941da21e3)
4
+
5
+
6
+ <br />
7
+
8
+ [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![snyk-image]][snyk-url]
9
+
10
+ ## Introduction
11
+ Scaffolding tool for AdonisJS applications. You can choose between 3 different starter kits :
12
+
13
+ - `api` : AdonisJS application tailored for building HTTP APIs.
14
+ - `web` : AdonisJS application tailored for building server-side rendered applications.
15
+ - `slim` : Smallest possible AdonisJS application. Still way more powerful and batteries included than a express application.
16
+
17
+ ## Usage
18
+
19
+ ```sh
20
+ # Using npm
21
+ npm init adonisjs
22
+
23
+ # Using yarn
24
+ yarn create adonisjs
25
+
26
+ # Using pnpm
27
+ pnpm create adonisjs
28
+ ```
29
+
30
+ ## Options
31
+
32
+ ### `destination`
33
+
34
+ You can pass the destination directory as the first argument to the command. For example:
35
+
36
+ ```sh
37
+ npm init adonisjs my-app
38
+ ```
39
+
40
+ 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.
42
+
43
+ ### `--kit`
44
+
45
+ If you have your own starter kit hosted on Gitlab/Github/Bitbucket, then you can pass it as follows:
46
+
47
+ ```sh
48
+ npm init adonisjs -- -K="github:github_user/repo"
49
+
50
+ # Download from GitLab
51
+ npm init adonisjs -- -K="gitlab:user/repo"
52
+
53
+ # Download from BitBucket
54
+ npm init adonisjs -- -K="bitbucket:user/repo"
55
+ ```
56
+
57
+ You can also pass specify the branch or tag name as follows:
58
+
59
+ ```sh
60
+ # Branch name
61
+ npm init adonisjs -- -K="github:github_user/repo#branch-name"
62
+
63
+ # Tag name
64
+ npm init adonisjs -- -K="github:github_user/repo#v1.0.0"
65
+ ```
66
+
67
+ ### `--token`
68
+
69
+ If you are using a custom starter kit hosted on a private repository, then you can pass the authentication token as follows:
70
+
71
+ ```sh
72
+ npm init adonisjs -- -K="github:github_user/repo" -t="github_token"
73
+ ```
74
+
75
+ ### Other options
76
+
77
+ | Option | Description |
78
+ |--------|-------------|
79
+ | `--skip-install` | Skip installing dependencies. |
80
+ | `--skip-git-init` | Skip initializing git repository. |
81
+
82
+ ## Contributing
83
+ 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
+
85
+ We encourage you to read the [contribution guide](https://github.com/adonisjs/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.
86
+
87
+ ## Code of Conduct
88
+ 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
+
90
+ ## License
91
+ create-adonisjs is open-sourced software licensed under the [MIT license](LICENSE.md).
92
+
93
+ [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
+
96
+ [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
+
99
+ [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
100
+
101
+ [license-url]: LICENSE.md
102
+ [license-image]: https://img.shields.io/github/license/adonisjs/create-adonisjs?style=for-the-badge
103
+
104
+ [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"
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { kernel } from '../index.js';
3
+ kernel.handle(process.argv.slice(2)).catch(console.error);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import { assert } from '@japa/assert';
2
+ import { processCLIArgs, configure, run } from '@japa/runner';
3
+ import { fileSystem } from '@japa/file-system';
4
+ /*
5
+ |--------------------------------------------------------------------------
6
+ | Configure tests
7
+ |--------------------------------------------------------------------------
8
+ |
9
+ | The configure method accepts the configuration to configure the Japa
10
+ | tests runner.
11
+ |
12
+ | The first method call "processCLIArgs" process the command line arguments
13
+ | and turns them into a config object. Using this method is not mandatory.
14
+ |
15
+ | Please consult japa.dev/runner-config for the config docs.
16
+ */
17
+ processCLIArgs(process.argv.slice(2));
18
+ configure({
19
+ files: ['tests/**/*.spec.ts'],
20
+ plugins: [assert(), fileSystem({ basePath: 'tmp', autoClean: true })],
21
+ timeout: 30 * 1000,
22
+ });
23
+ /*
24
+ |--------------------------------------------------------------------------
25
+ | Run tests
26
+ |--------------------------------------------------------------------------
27
+ |
28
+ | The following "run" method is required to execute all the tests.
29
+ |
30
+ */
31
+ run();
@@ -0,0 +1,2 @@
1
+ import { Kernel } from '@adonisjs/ace';
2
+ export declare const kernel: Kernel<typeof import("@adonisjs/ace").BaseCommand>;
package/build/index.js ADDED
@@ -0,0 +1,12 @@
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
+ import { Kernel } from '@adonisjs/ace';
10
+ import { InstallAdonis } from './src/install_adonis.js';
11
+ Kernel.defaultCommand = InstallAdonis;
12
+ export const kernel = Kernel.create();
@@ -0,0 +1,39 @@
1
+ import { BaseCommand } from '@adonisjs/ace';
2
+ export declare class InstallAdonis extends BaseCommand {
3
+ #private;
4
+ static commandName: string;
5
+ static description: string;
6
+ /**
7
+ * The directory where the project will be created
8
+ */
9
+ destination: string;
10
+ /**
11
+ * The starter kit to use
12
+ *
13
+ * @example
14
+ * --kit github_user/repo
15
+ * --kit gitlab_user/repo#develop
16
+ * --kit bitbucket_user/repo#2.0.0
17
+ */
18
+ kit?: string;
19
+ /**
20
+ * Authentication token to download private templates kit
21
+ */
22
+ token?: string;
23
+ /**
24
+ * Skip dependencies installation
25
+ */
26
+ skipInstall: boolean;
27
+ /**
28
+ * Skip git initialization
29
+ */
30
+ skipGitInit: boolean;
31
+ /**
32
+ * Execute the `run` method and catch errors
33
+ */
34
+ exec(): Promise<void>;
35
+ /**
36
+ * Main method
37
+ */
38
+ run(): Promise<void>;
39
+ }
@@ -0,0 +1,220 @@
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
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ };
15
+ import { copyFile, readFile, writeFile } from 'node:fs/promises';
16
+ import { existsSync } from 'node:fs';
17
+ import { join, relative } from 'node:path';
18
+ 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';
22
+ 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;
32
+ /**
33
+ * Whether or not dependencies were installed
34
+ */
35
+ #hasInstalledDependencies;
36
+ /**
37
+ * Print the title
38
+ */
39
+ #printTitle() {
40
+ const adonisGradient = gradient([
41
+ { color: '#5A45FF', pos: 0 },
42
+ { color: '#7c6dff', pos: 0.2 },
43
+ ]);
44
+ const title = Buffer.from('CiAgICBfX18gICAgICAgX18gICAgICAgICAgICBfICAgICAgICAgIF8gICAgIAogICAvICAgfCBfX19fLyAvX19fICBfX19fICAoXylfX19fICAgIChfKV9fX18KICAvIC98IHwvIF9fICAvIF9fIFwvIF9fIFwvIC8gX19fLyAgIC8gLyBfX18vCiAvIF9fXyAvIC9fLyAvIC9fLyAvIC8gLyAvIChfXyAgKSAgIC8gKF9fICApIAovXy8gIHxfXF9fLF8vXF9fX18vXy8gL18vXy9fX19fKF8pXy8gL19fX18vICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvX19fLyAgICAgICAg==', 'base64').toString();
45
+ 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('');
50
+ this.logger.log('');
51
+ }
52
+ /**
53
+ * Prompt for the destination directory
54
+ */
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
+ });
61
+ }
62
+ /**
63
+ * Prompt and download the selected template
64
+ */
65
+ 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;
71
+ }
72
+ const spinner = this.logger.await(`Downloading ${templateSource} template`).start();
73
+ try {
74
+ await downloadTemplate(templateSource, { dir: this.destination, auth: this.token });
75
+ spinner.update('Template downloaded successfully').stop();
76
+ }
77
+ catch (error) {
78
+ spinner.update('Failed to download template').stop();
79
+ throw error;
80
+ }
81
+ }
82
+ /**
83
+ * Install dependencies with the detected package manager
84
+ */
85
+ async #installDependencies() {
86
+ if (this.skipInstall)
87
+ 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)
95
+ return;
96
+ const spinner = this.logger.await(`Installing dependencies using ${pkgManager}`).start();
97
+ try {
98
+ await execa(pkgManager, ['install'], { cwd: this.destination });
99
+ spinner.update('Dependencies installed successfully').stop();
100
+ }
101
+ catch (error) {
102
+ spinner.stop();
103
+ this.error = `Failed to install dependencies :\n${error.stderr}`;
104
+ throw error;
105
+ }
106
+ }
107
+ /**
108
+ * Init git repository inside the destination directory
109
+ */
110
+ async #initGitRepo() {
111
+ if (this.skipGitInit)
112
+ return;
113
+ this.logger.log('');
114
+ const shouldInit = await this.prompt.confirm('Do you want to initialize a git repository?', {
115
+ default: true,
116
+ });
117
+ if (!shouldInit)
118
+ return;
119
+ try {
120
+ await execa('git', ['init'], { cwd: this.destination });
121
+ this.logger.success('Git repository initialized successfully');
122
+ }
123
+ catch (error) {
124
+ this.error = `Failed to initialize git repository :\n${error.stderr}`;
125
+ throw error;
126
+ }
127
+ }
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
+ /**
145
+ * Replace the package.json name with the destination directory name
146
+ */
147
+ async #replacePackageJsonName() {
148
+ const pkgJsonPath = join(this.destination, 'package.json');
149
+ const pkgJson = await readFile(pkgJsonPath, 'utf-8').then(JSON.parse);
150
+ pkgJson.name = relative(cwd(), this.destination);
151
+ await writeFile(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
152
+ }
153
+ /**
154
+ * If starter template has an `.env.example` file, then copy it to `.env`
155
+ */
156
+ async #copyEnvExampleFile() {
157
+ const envExamplePath = join(this.destination, '.env.example');
158
+ const hasEnvExample = existsSync(envExamplePath);
159
+ if (!hasEnvExample)
160
+ return;
161
+ const envPath = join(this.destination, '.env');
162
+ await copyFile(envExamplePath, envPath);
163
+ }
164
+ /**
165
+ * Generate a fresh app key
166
+ */
167
+ async #generateFreshAppKey() {
168
+ if (!this.#hasInstalledDependencies)
169
+ return;
170
+ try {
171
+ await execa('node', ['ace', 'generate:key'], { cwd: this.destination });
172
+ }
173
+ catch (error) {
174
+ this.logger.warning('Failed to generate app key : ' + error.stderr);
175
+ }
176
+ }
177
+ /**
178
+ * Execute the `run` method and catch errors
179
+ */
180
+ async exec() {
181
+ this.hydrate();
182
+ try {
183
+ await this.run();
184
+ }
185
+ catch (error) {
186
+ this.logger.fatal(this.error || error.message);
187
+ this.exitCode = 1;
188
+ }
189
+ }
190
+ /**
191
+ * Main method
192
+ */
193
+ async run() {
194
+ this.#detectedPkgManager = detectPackageManager()?.name || 'npm';
195
+ this.#printTitle();
196
+ await this.#promptDestination();
197
+ await this.#downloadTemplate();
198
+ await this.#installDependencies();
199
+ await this.#initGitRepo();
200
+ await this.#replacePackageJsonName();
201
+ await this.#copyEnvExampleFile();
202
+ await this.#generateFreshAppKey();
203
+ this.#printSuccessMessage();
204
+ }
205
+ }
206
+ __decorate([
207
+ args.string({ description: 'Destination directory', name: 'destination', required: false })
208
+ ], InstallAdonis.prototype, "destination", void 0);
209
+ __decorate([
210
+ flags.string({ description: 'Starter kit to use', name: 'kit', alias: 'K' })
211
+ ], InstallAdonis.prototype, "kit", void 0);
212
+ __decorate([
213
+ flags.string({ description: 'Authentication token', name: 'token', alias: 't' })
214
+ ], InstallAdonis.prototype, "token", void 0);
215
+ __decorate([
216
+ flags.boolean({ description: 'Skip dependencies installation', name: 'skip-install' })
217
+ ], InstallAdonis.prototype, "skipInstall", void 0);
218
+ __decorate([
219
+ flags.boolean({ description: 'Skip git initialization', name: 'skip-git-init' })
220
+ ], InstallAdonis.prototype, "skipGitInit", void 0);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * List of first party templates
3
+ */
4
+ export declare const templates: {
5
+ name: string;
6
+ hint: string;
7
+ source: string;
8
+ }[];
@@ -0,0 +1,23 @@
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 templates
11
+ */
12
+ export const templates = [
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',
22
+ },
23
+ ];
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
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
+ },
8
+ "main": "build/index.js",
9
+ "type": "module",
10
+ "files": [
11
+ "build/bin",
12
+ "build/src",
13
+ "build/index.d.ts",
14
+ "build/index.js"
15
+ ],
16
+ "bin": {
17
+ "create-adonisjs": "./build/bin/run.js"
18
+ },
19
+ "exports": {
20
+ ".": "./build/index.js"
21
+ },
22
+ "scripts": {
23
+ "clean": "del-cli build",
24
+ "typecheck": "tsc --noEmit",
25
+ "lint": "eslint . --ext=.ts",
26
+ "format": "prettier --write .",
27
+ "quick:test": "node --enable-source-maps --loader=ts-node/esm bin/test.ts",
28
+ "pretest": "npm run lint",
29
+ "test": "c8 npm run quick:test",
30
+ "prebuild": "npm run lint && npm run clean",
31
+ "build": "tsc",
32
+ "release": "np",
33
+ "version": "npm run build",
34
+ "prepublishOnly": "npm run build"
35
+ },
36
+ "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",
44
+ "@swc/core": "^1.3.68",
45
+ "@types/gradient-string": "^1.1.2",
46
+ "@types/node": "^20.3.3",
47
+ "@types/which-pm-runs": "^1.0.0",
48
+ "c8": "^8.0.0",
49
+ "copyfiles": "^2.4.1",
50
+ "del-cli": "^5.0.0",
51
+ "eslint": "^8.44.0",
52
+ "np": "^8.0.4",
53
+ "prettier": "^2.8.8",
54
+ "ts-node": "^10.9.1",
55
+ "typescript": "^5.1.6"
56
+ },
57
+ "dependencies": {
58
+ "@adonisjs/ace": "12.3.1-8",
59
+ "execa": "^7.1.1",
60
+ "giget": "^1.1.2",
61
+ "gradient-string": "^2.0.2",
62
+ "which-pm-runs": "^1.1.0"
63
+ },
64
+ "author": "julien-r44,virk",
65
+ "license": "MIT",
66
+ "keywords": [],
67
+ "eslintConfig": {
68
+ "extends": "@adonisjs/eslint-config/package"
69
+ },
70
+ "prettier": "@adonisjs/prettier-config",
71
+ "publishConfig": {
72
+ "access": "public",
73
+ "tag": "latest"
74
+ },
75
+ "np": {
76
+ "message": "chore(release): %s",
77
+ "tag": "latest",
78
+ "branch": "main",
79
+ "anyBranch": false
80
+ },
81
+ "c8": {
82
+ "reporter": [
83
+ "text",
84
+ "html"
85
+ ],
86
+ "exclude": [
87
+ "tests/**"
88
+ ]
89
+ }
90
+ }