@adonisjs-ecommerce-core/create 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.
Files changed (3) hide show
  1. package/README.md +83 -0
  2. package/dist/index.js +231 -0
  3. package/package.json +58 -0
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # create-adoniscommerce
2
+
3
+ Create a new AdonisCommerce e-commerce application with a single command.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ # Using npx (recommended)
9
+ npx create-adoniscommerce my-store
10
+
11
+ # Using pnpm
12
+ pnpm create adoniscommerce my-store
13
+
14
+ # Using yarn
15
+ yarn create adoniscommerce my-store
16
+
17
+ # Using npm
18
+ npm create adoniscommerce my-store
19
+ ```
20
+
21
+ ## Options
22
+
23
+ ```bash
24
+ npx create-adoniscommerce <project-name> [options]
25
+
26
+ Options:
27
+ -t, --template <name> Template to use (default: "default")
28
+ --npm Use npm as package manager
29
+ --yarn Use yarn as package manager
30
+ --pnpm Use pnpm as package manager (default)
31
+ --no-git Skip git initialization
32
+ --no-install Skip dependency installation
33
+ --docker Initialize with Docker setup
34
+ -V, --version Output the version number
35
+ -h, --help Display help
36
+ ```
37
+
38
+ ## Examples
39
+
40
+ ```bash
41
+ # Create with Docker support
42
+ npx create-adoniscommerce my-store --docker
43
+
44
+ # Create without git initialization
45
+ npx create-adoniscommerce my-store --no-git
46
+
47
+ # Create using npm instead of pnpm
48
+ npx create-adoniscommerce my-store --npm
49
+ ```
50
+
51
+ ## What's Included
52
+
53
+ - ๐Ÿ›๏ธ Full e-commerce storefront
54
+ - ๐Ÿ”ง Admin panel for management
55
+ - ๐Ÿ—„๏ธ PostgreSQL database with 55+ migrations
56
+ - โšก Redis for caching and sessions
57
+ - ๐Ÿณ Docker development environment
58
+ - ๐Ÿงช E2E tests with Puppeteer
59
+
60
+ ## After Creation
61
+
62
+ ```bash
63
+ cd my-store
64
+
65
+ # With Docker (recommended)
66
+ make docker-dev
67
+ make docker-db-reset
68
+
69
+ # Without Docker
70
+ pnpm dev
71
+ ```
72
+
73
+ Visit:
74
+ - **App:** http://localhost:3333
75
+ - **Admin:** http://localhost:3333/admin (admin@example.com / admin123)
76
+
77
+ ## Documentation
78
+
79
+ Full documentation: https://github.com/haliltoma/adonisjs-ecommerce-core
80
+
81
+ ## License
82
+
83
+ MIT
package/dist/index.js ADDED
@@ -0,0 +1,231 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { program } from "commander";
5
+ import prompts from "prompts";
6
+ import chalk from "chalk";
7
+ import ora from "ora";
8
+ import fs from "fs-extra";
9
+ import path from "path";
10
+ import { execSync } from "child_process";
11
+ import validatePackageName from "validate-npm-package-name";
12
+ var TEMPLATE_REPO = "github:haliltoma/adonisjs-ecommerce-core/templates/default";
13
+ var VERSION = "1.0.0";
14
+ async function main() {
15
+ console.log();
16
+ console.log(chalk.bold.cyan("\u{1F6D2} Create AdonisJS E-Commerce"));
17
+ console.log(chalk.gray("Modern e-commerce platform with AdonisJS 6 + React"));
18
+ console.log();
19
+ program.name("create-adonisjs-ecommerce-core").description("Create a new AdonisJS E-Commerce application").version(VERSION).argument("[project-name]", "Name of the project").option("-t, --template <name>", "Template to use", "default").option("--npm", "Use npm as package manager").option("--yarn", "Use yarn as package manager").option("--pnpm", "Use pnpm as package manager").option("--no-git", "Skip git initialization").option("--no-install", "Skip dependency installation").option("--docker", "Initialize with Docker setup").action(async (projectName, options) => {
20
+ try {
21
+ const config = await getProjectConfig(projectName, options);
22
+ await createProject(config);
23
+ } catch (error) {
24
+ if (error instanceof Error && error.message === "cancelled") {
25
+ console.log(chalk.yellow("\n\u2716 Operation cancelled"));
26
+ process.exit(0);
27
+ }
28
+ throw error;
29
+ }
30
+ });
31
+ program.parse();
32
+ }
33
+ async function getProjectConfig(projectNameArg, cliOptions) {
34
+ let packageManager = "pnpm";
35
+ if (cliOptions.npm) packageManager = "npm";
36
+ else if (cliOptions.yarn) packageManager = "yarn";
37
+ else if (cliOptions.pnpm) packageManager = "pnpm";
38
+ const questions = [];
39
+ if (!projectNameArg) {
40
+ questions.push({
41
+ type: "text",
42
+ name: "projectName",
43
+ message: "Project name:",
44
+ initial: "my-store",
45
+ validate: (value) => {
46
+ const result = validatePackageName(value);
47
+ if (result.validForNewPackages) return true;
48
+ return result.errors?.[0] || "Invalid project name";
49
+ }
50
+ });
51
+ }
52
+ if (!cliOptions.npm && !cliOptions.yarn && !cliOptions.pnpm) {
53
+ questions.push({
54
+ type: "select",
55
+ name: "packageManager",
56
+ message: "Package manager:",
57
+ choices: [
58
+ { title: "pnpm (recommended)", value: "pnpm" },
59
+ { title: "npm", value: "npm" },
60
+ { title: "yarn", value: "yarn" }
61
+ ],
62
+ initial: 0
63
+ });
64
+ }
65
+ if (cliOptions.docker === void 0) {
66
+ questions.push({
67
+ type: "confirm",
68
+ name: "docker",
69
+ message: "Set up Docker environment?",
70
+ initial: true
71
+ });
72
+ }
73
+ const answers = await prompts(questions, {
74
+ onCancel: () => {
75
+ throw new Error("cancelled");
76
+ }
77
+ });
78
+ return {
79
+ projectName: projectNameArg || answers.projectName,
80
+ packageManager: answers.packageManager || packageManager,
81
+ git: cliOptions.git !== false,
82
+ install: cliOptions.install !== false,
83
+ docker: cliOptions.docker ?? answers.docker ?? true
84
+ };
85
+ }
86
+ async function createProject(config) {
87
+ const targetDir = path.resolve(process.cwd(), config.projectName);
88
+ if (fs.existsSync(targetDir)) {
89
+ const { overwrite } = await prompts({
90
+ type: "confirm",
91
+ name: "overwrite",
92
+ message: `Directory ${chalk.cyan(config.projectName)} already exists. Overwrite?`,
93
+ initial: false
94
+ });
95
+ if (!overwrite) {
96
+ console.log(chalk.yellow("\u2716 Operation cancelled"));
97
+ process.exit(0);
98
+ }
99
+ await fs.remove(targetDir);
100
+ }
101
+ console.log();
102
+ const spinner = ora("Creating project...").start();
103
+ try {
104
+ spinner.text = "Downloading template...";
105
+ const degit = (await import("degit")).default;
106
+ const emitter = degit(TEMPLATE_REPO, {
107
+ cache: false,
108
+ force: true,
109
+ verbose: false
110
+ });
111
+ await emitter.clone(targetDir);
112
+ spinner.text = "Configuring project...";
113
+ const packageJsonPath = path.join(targetDir, "package.json");
114
+ const packageJson = await fs.readJson(packageJsonPath);
115
+ packageJson.name = config.projectName;
116
+ packageJson.version = "0.0.1";
117
+ packageJson.private = true;
118
+ await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
119
+ const envDockerPath = path.join(targetDir, ".env.docker");
120
+ const envPath = path.join(targetDir, ".env");
121
+ if (await fs.pathExists(envDockerPath)) {
122
+ await fs.copy(envDockerPath, envPath);
123
+ const appKey = generateAppKey();
124
+ let envContent = await fs.readFile(envPath, "utf-8");
125
+ envContent = envContent.replace(
126
+ /APP_KEY=.*/,
127
+ `APP_KEY=${appKey}`
128
+ );
129
+ await fs.writeFile(envPath, envContent);
130
+ }
131
+ if (!config.docker) {
132
+ const dockerFiles = [
133
+ "Dockerfile",
134
+ "Dockerfile.dev",
135
+ "docker-compose.yml",
136
+ "docker-compose.prod.yml",
137
+ ".dockerignore",
138
+ ".env.docker",
139
+ ".env.docker.prod",
140
+ "docker"
141
+ ];
142
+ for (const file of dockerFiles) {
143
+ const filePath = path.join(targetDir, file);
144
+ if (await fs.pathExists(filePath)) {
145
+ await fs.remove(filePath);
146
+ }
147
+ }
148
+ const pkgJson = await fs.readJson(packageJsonPath);
149
+ const scripts = pkgJson.scripts || {};
150
+ Object.keys(scripts).forEach((key) => {
151
+ if (key.startsWith("docker:")) {
152
+ delete scripts[key];
153
+ }
154
+ });
155
+ pkgJson.scripts = scripts;
156
+ await fs.writeJson(packageJsonPath, pkgJson, { spaces: 2 });
157
+ }
158
+ spinner.succeed("Project created");
159
+ if (config.git) {
160
+ spinner.start("Initializing git...");
161
+ try {
162
+ execSync("git init", { cwd: targetDir, stdio: "ignore" });
163
+ execSync("git add -A", { cwd: targetDir, stdio: "ignore" });
164
+ execSync('git commit -m "Initial commit from @adonisjs-ecommerce-core/create"', {
165
+ cwd: targetDir,
166
+ stdio: "ignore"
167
+ });
168
+ spinner.succeed("Git initialized");
169
+ } catch {
170
+ spinner.warn("Git initialization failed");
171
+ }
172
+ }
173
+ if (config.install) {
174
+ spinner.start("Installing dependencies...");
175
+ try {
176
+ const installCmd = getInstallCommand(config.packageManager);
177
+ execSync(installCmd, { cwd: targetDir, stdio: "ignore" });
178
+ spinner.succeed("Dependencies installed");
179
+ } catch {
180
+ spinner.warn("Dependency installation failed. Run install manually.");
181
+ }
182
+ }
183
+ console.log();
184
+ console.log(chalk.green("\u2714 Project created successfully!"));
185
+ console.log();
186
+ console.log("Next steps:");
187
+ console.log();
188
+ console.log(chalk.cyan(` cd ${config.projectName}`));
189
+ if (!config.install) {
190
+ console.log(chalk.cyan(` ${config.packageManager} install`));
191
+ }
192
+ if (config.docker) {
193
+ console.log();
194
+ console.log(chalk.gray(" # Start with Docker (recommended):"));
195
+ console.log(chalk.cyan(" make docker-dev"));
196
+ console.log(chalk.cyan(" make docker-db-reset"));
197
+ console.log();
198
+ console.log(chalk.gray(" # Or without Docker:"));
199
+ }
200
+ console.log(chalk.cyan(` ${config.packageManager === "npm" ? "npm run" : config.packageManager} dev`));
201
+ console.log();
202
+ console.log(chalk.gray(" Documentation: https://github.com/haliltoma/adonisjs-ecommerce-core"));
203
+ console.log();
204
+ } catch (error) {
205
+ spinner.fail("Failed to create project");
206
+ throw error;
207
+ }
208
+ }
209
+ function getInstallCommand(pm) {
210
+ switch (pm) {
211
+ case "yarn":
212
+ return "yarn install";
213
+ case "npm":
214
+ return "npm install";
215
+ case "pnpm":
216
+ default:
217
+ return "pnpm install";
218
+ }
219
+ }
220
+ function generateAppKey() {
221
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
222
+ let key = "";
223
+ for (let i = 0; i < 32; i++) {
224
+ key += chars.charAt(Math.floor(Math.random() * chars.length));
225
+ }
226
+ return key;
227
+ }
228
+ main().catch((error) => {
229
+ console.error(chalk.red("Error:"), error.message);
230
+ process.exit(1);
231
+ });
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@adonisjs-ecommerce-core/create",
3
+ "version": "1.0.0",
4
+ "description": "Create a new AdonisJS E-Commerce application",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "create-adonisjs-ecommerce-core": "dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsup src/index.ts --format esm --clean",
15
+ "dev": "tsup src/index.ts --format esm --watch",
16
+ "prepublishOnly": "pnpm build"
17
+ },
18
+ "keywords": [
19
+ "adonisjs",
20
+ "ecommerce",
21
+ "create",
22
+ "scaffold",
23
+ "react",
24
+ "inertia",
25
+ "typescript"
26
+ ],
27
+ "author": "",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/haliltoma/adonisjs-ecommerce-core.git",
32
+ "directory": "packages/create"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "homepage": "https://github.com/haliltoma/adonisjs-ecommerce-core#readme",
38
+ "engines": {
39
+ "node": ">=18.0.0"
40
+ },
41
+ "dependencies": {
42
+ "chalk": "^5.3.0",
43
+ "commander": "^12.1.0",
44
+ "degit": "^2.8.4",
45
+ "fs-extra": "^11.2.0",
46
+ "ora": "^8.1.0",
47
+ "prompts": "^2.4.2",
48
+ "validate-npm-package-name": "^5.0.1"
49
+ },
50
+ "devDependencies": {
51
+ "@types/fs-extra": "^11.0.4",
52
+ "@types/node": "^22.15.18",
53
+ "@types/prompts": "^2.4.9",
54
+ "@types/validate-npm-package-name": "^4.0.2",
55
+ "tsup": "^8.3.5",
56
+ "typescript": "^5.8.0"
57
+ }
58
+ }